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/surface/completion_queue.cc | 222 +++++++++++++------------------ 1 file changed, 94 insertions(+), 128 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 21664f03c8..8abcb70d25 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -58,13 +58,12 @@ typedef struct { bool can_listen; size_t (*size)(void); void (*init)(grpc_pollset *pollset, gpr_mu **mu); - grpc_error *(*kick)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, + grpc_error *(*kick)(grpc_pollset *pollset, grpc_pollset_worker *specific_worker); - grpc_error *(*work)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, - grpc_pollset_worker **worker, grpc_millis deadline); - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, - grpc_closure *closure); - void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset); + grpc_error *(*work)(grpc_pollset *pollset, grpc_pollset_worker **worker, + grpc_millis deadline); + void (*shutdown)(grpc_pollset *pollset, grpc_closure *closure); + void (*destroy)(grpc_pollset *pollset); } cq_poller_vtable; typedef struct non_polling_worker { @@ -90,14 +89,12 @@ static void non_polling_poller_init(grpc_pollset *pollset, gpr_mu **mu) { *mu = &npp->mu; } -static void non_polling_poller_destroy(grpc_exec_ctx *exec_ctx, - grpc_pollset *pollset) { +static void non_polling_poller_destroy(grpc_pollset *pollset) { non_polling_poller *npp = (non_polling_poller *)pollset; gpr_mu_destroy(&npp->mu); } -static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, - grpc_pollset *pollset, +static grpc_error *non_polling_poller_work(grpc_pollset *pollset, grpc_pollset_worker **worker, grpc_millis deadline) { non_polling_poller *npp = (non_polling_poller *)pollset; @@ -122,7 +119,7 @@ static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, npp->root = w.next; if (&w == npp->root) { if (npp->shutdown) { - GRPC_CLOSURE_SCHED(exec_ctx, npp->shutdown, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(npp->shutdown, GRPC_ERROR_NONE); } npp->root = NULL; } @@ -135,8 +132,7 @@ static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, } static grpc_error *non_polling_poller_kick( - grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, - grpc_pollset_worker *specific_worker) { + grpc_pollset *pollset, grpc_pollset_worker *specific_worker) { non_polling_poller *p = (non_polling_poller *)pollset; if (specific_worker == NULL) specific_worker = (grpc_pollset_worker *)p->root; if (specific_worker != NULL) { @@ -149,14 +145,13 @@ static grpc_error *non_polling_poller_kick( return GRPC_ERROR_NONE; } -static void non_polling_poller_shutdown(grpc_exec_ctx *exec_ctx, - grpc_pollset *pollset, +static void non_polling_poller_shutdown(grpc_pollset *pollset, grpc_closure *closure) { non_polling_poller *p = (non_polling_poller *)pollset; GPR_ASSERT(closure != NULL); p->shutdown = closure; if (p->root == NULL) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } else { non_polling_worker *w = p->root; do { @@ -183,13 +178,11 @@ typedef struct cq_vtable { grpc_cq_completion_type cq_completion_type; size_t data_size; void (*init)(void *data); - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq); + void (*shutdown)(grpc_completion_queue *cq); void (*destroy)(void *data); bool (*begin_op)(grpc_completion_queue *cq, void *tag); - void (*end_op)(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, void *tag, - grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg, - grpc_cq_completion *storage), + void (*end_op)(grpc_completion_queue *cq, void *tag, grpc_error *error, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage); grpc_event (*next)(grpc_completion_queue *cq, gpr_timespec deadline, void *reserved); @@ -274,31 +267,23 @@ struct grpc_completion_queue { }; /* Forward declarations */ -static void cq_finish_shutdown_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq); -static void cq_finish_shutdown_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq); -static void cq_shutdown_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq); -static void cq_shutdown_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq); +static void cq_finish_shutdown_next(grpc_completion_queue *cq); +static void cq_finish_shutdown_pluck(grpc_completion_queue *cq); +static void cq_shutdown_next(grpc_completion_queue *cq); +static void cq_shutdown_pluck(grpc_completion_queue *cq); static bool cq_begin_op_for_next(grpc_completion_queue *cq, void *tag); static bool cq_begin_op_for_pluck(grpc_completion_queue *cq, void *tag); -static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq, void *tag, +static void cq_end_op_for_next(grpc_completion_queue *cq, void *tag, grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, - void *done_arg, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage); -static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq, void *tag, +static void cq_end_op_for_pluck(grpc_completion_queue *cq, void *tag, grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, - void *done_arg, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage); @@ -342,8 +327,7 @@ grpc_tracer_flag grpc_cq_event_timeout_trace = gpr_free(_ev); \ } -static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *cq, - grpc_error *error); +static void on_pollset_shutdown_done(void *cq, grpc_error *error); static void cq_event_queue_init(grpc_cq_event_queue *q) { gpr_mpscq_init(&q->queue); @@ -362,23 +346,23 @@ static bool cq_event_queue_push(grpc_cq_event_queue *q, grpc_cq_completion *c) { static grpc_cq_completion *cq_event_queue_pop(grpc_cq_event_queue *q) { grpc_cq_completion *c = NULL; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; if (gpr_spinlock_trylock(&q->queue_lock)) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); bool is_empty = false; c = (grpc_cq_completion *)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); gpr_spinlock_unlock(&q->queue_lock); if (c == NULL && !is_empty) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(); } } else { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); if (c) { gpr_atm_no_barrier_fetch_add(&q->num_queue_items, -1); @@ -409,9 +393,9 @@ grpc_completion_queue *grpc_completion_queue_create_internal( const cq_poller_vtable *poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_CQS_CREATED(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + ExecCtx _local_exec_ctx; + GRPC_STATS_INC_CQS_CREATED(); + grpc_exec_ctx_finish(); cq = (grpc_completion_queue *)gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + @@ -493,15 +477,14 @@ void grpc_cq_internal_ref(grpc_completion_queue *cq) { gpr_ref(&cq->owning_refs); } -static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { +static void on_pollset_shutdown_done(void *arg, grpc_error *error) { grpc_completion_queue *cq = (grpc_completion_queue *)arg; - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "pollset_destroy"); + GRPC_CQ_INTERNAL_UNREF(cq, "pollset_destroy"); } #ifndef NDEBUG -void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, - const char *reason, const char *file, int line) { +void grpc_cq_internal_unref(grpc_completion_queue *cq, const char *reason, + const char *file, int line) { if (GRPC_TRACER_ON(grpc_trace_cq_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -509,12 +492,11 @@ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, reason); } #else -void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq) { +void grpc_cq_internal_unref(grpc_completion_queue *cq) { #endif if (gpr_unref(&cq->owning_refs)) { cq->vtable->destroy(DATA_FROM_CQ(cq)); - cq->poller_vtable->destroy(exec_ctx, POLLSET_FROM_CQ(cq)); + cq->poller_vtable->destroy(POLLSET_FROM_CQ(cq)); #ifndef NDEBUG gpr_free(cq->outstanding_tags); #endif @@ -595,11 +577,9 @@ bool grpc_cq_begin_op(grpc_completion_queue *cq, void *tag) { /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_NEXT) */ -static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq, void *tag, +static void cq_end_op_for_next(grpc_completion_queue *cq, void *tag, grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, - void *done_arg, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage) { GPR_TIMER_BEGIN("cq_end_op_for_next", 0); @@ -609,9 +589,9 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_next(=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 7, (&exec_ctx, cq, tag, errmsg, done, done_arg, storage)); if (GRPC_TRACER_ON(grpc_trace_operation_failures) && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); @@ -643,7 +623,7 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, if (is_first) { gpr_mu_lock(cq->mu); grpc_error *kick_error = - cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), NULL); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), NULL); gpr_mu_unlock(cq->mu); if (kick_error != GRPC_ERROR_NONE) { @@ -655,17 +635,17 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } } else { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_atm_rel_store(&cqd->pending_events, 0); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } GPR_TIMER_END("cq_end_op_for_next", 0); @@ -676,11 +656,9 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_PLUCK) */ -static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq, void *tag, +static void cq_end_op_for_pluck(grpc_completion_queue *cq, void *tag, grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, - void *done_arg, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage) { cq_pluck_data *cqd = (cq_pluck_data *)DATA_FROM_CQ(cq); @@ -693,9 +671,9 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_pluck(=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 7, (&exec_ctx, cq, tag, errmsg, done, done_arg, storage)); if (GRPC_TRACER_ON(grpc_trace_operation_failures) && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); @@ -717,7 +695,7 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, cqd->completed_tail = storage; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(exec_ctx, cq); + cq_finish_shutdown_pluck(cq); gpr_mu_unlock(cq->mu); } else { grpc_pollset_worker *pluck_worker = NULL; @@ -729,7 +707,7 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, } grpc_error *kick_error = - cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), pluck_worker); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), pluck_worker); gpr_mu_unlock(cq->mu); @@ -746,12 +724,10 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(error); } -void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, - void *tag, grpc_error *error, - void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg, - grpc_cq_completion *storage), +void grpc_cq_end_op(grpc_completion_queue *cq, void *tag, grpc_error *error, + void (*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage) { - cq->vtable->end_op(exec_ctx, cq, tag, error, done, done_arg, storage); + cq->vtable->end_op(cq, tag, error, done, done_arg, storage); } typedef struct { @@ -763,7 +739,7 @@ typedef struct { bool first_loop; } cq_is_finished_arg; -static bool cq_is_next_finished(grpc_exec_ctx *exec_ctx, void *arg) { +static bool cq_is_next_finished(void *arg) { cq_is_finished_arg *a = (cq_is_finished_arg *)arg; grpc_completion_queue *cq = a->cq; cq_next_data *cqd = (cq_next_data *)DATA_FROM_CQ(cq); @@ -786,7 +762,7 @@ static bool cq_is_next_finished(grpc_exec_ctx *exec_ctx, void *arg) { return true; } } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); + return !a->first_loop && a->deadline < grpc_exec_ctx_now(); } #ifndef NDEBUG @@ -841,8 +817,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, NULL, NULL, true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); + ExecCtx _local_exec_ctx(0, cq_is_next_finished, &is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; @@ -852,7 +827,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } @@ -862,7 +837,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } else { /* If c == NULL it means either the queue is empty OR in an transient @@ -892,8 +867,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, break; } - if (!is_finished_arg.first_loop && - grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { + if (!is_finished_arg.first_loop && grpc_exec_ctx_now() >= deadline_millis) { memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; dump_pending_tags(cq); @@ -903,8 +877,8 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, /* The main polling work happens in grpc_pollset_work */ gpr_mu_lock(cq->mu); cq->num_polls++; - grpc_error *err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), - NULL, iteration_deadline); + grpc_error *err = + cq->poller_vtable->work(POLLSET_FROM_CQ(cq), NULL, iteration_deadline); gpr_mu_unlock(cq->mu); if (err != GRPC_ERROR_NONE) { @@ -923,13 +897,13 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, if (cq_event_queue_num_items(&cqd->queue) > 0 && gpr_atm_acq_load(&cqd->pending_events) > 0) { gpr_mu_lock(cq->mu); - cq->poller_vtable->kick(&exec_ctx, POLLSET_FROM_CQ(cq), NULL); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), NULL); gpr_mu_unlock(cq->mu); } GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "next"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CQ_INTERNAL_UNREF(cq, "next"); + grpc_exec_ctx_finish(); GPR_ASSERT(is_finished_arg.stolen_completion == NULL); GPR_TIMER_END("grpc_completion_queue_next", 0); @@ -943,19 +917,16 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, - Must be called only once in completion queue's lifetime - grpc_completion_queue_shutdown() MUST have been called before calling this function */ -static void cq_finish_shutdown_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq) { +static void cq_finish_shutdown_next(grpc_completion_queue *cq) { cq_next_data *cqd = (cq_next_data *)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0); - cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), - &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); } -static void cq_shutdown_next(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq) { +static void cq_shutdown_next(grpc_completion_queue *cq) { cq_next_data *cqd = (cq_next_data *)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -968,7 +939,7 @@ static void cq_shutdown_next(grpc_exec_ctx *exec_ctx, gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); return; } cqd->shutdown_called = true; @@ -976,10 +947,10 @@ static void cq_shutdown_next(grpc_exec_ctx *exec_ctx, * cq_begin_op_for_next and and cq_end_op_for_next functions which read/write * on this counter without necessarily holding a lock on cq */ if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, @@ -1012,7 +983,7 @@ static void del_plucker(grpc_completion_queue *cq, void *tag, GPR_UNREACHABLE_CODE(return ); } -static bool cq_is_pluck_finished(grpc_exec_ctx *exec_ctx, void *arg) { +static bool cq_is_pluck_finished(void *arg) { cq_is_finished_arg *a = (cq_is_finished_arg *)arg; grpc_completion_queue *cq = a->cq; cq_pluck_data *cqd = (cq_pluck_data *)DATA_FROM_CQ(cq); @@ -1041,7 +1012,7 @@ static bool cq_is_pluck_finished(grpc_exec_ctx *exec_ctx, void *arg) { } gpr_mu_unlock(cq->mu); } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); + return !a->first_loop && a->deadline < grpc_exec_ctx_now(); } static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, @@ -1078,8 +1049,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, NULL, tag, true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); + ExecCtx _local_exec_ctx(0, cq_is_pluck_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cq->mu); @@ -1088,7 +1058,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } prev = &cqd->completed_head; @@ -1103,7 +1073,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); goto done; } prev = c; @@ -1126,8 +1096,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, dump_pending_tags(cq); break; } - if (!is_finished_arg.first_loop && - grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { + if (!is_finished_arg.first_loop && grpc_exec_ctx_now() >= deadline_millis) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); memset(&ret, 0, sizeof(ret)); @@ -1136,8 +1105,8 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, break; } cq->num_polls++; - grpc_error *err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), - &worker, deadline_millis); + grpc_error *err = + cq->poller_vtable->work(POLLSET_FROM_CQ(cq), &worker, deadline_millis); if (err != GRPC_ERROR_NONE) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); @@ -1155,8 +1124,8 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, } done: GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "pluck"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CQ_INTERNAL_UNREF(cq, "pluck"); + grpc_exec_ctx_finish(); GPR_ASSERT(is_finished_arg.stolen_completion == NULL); GPR_TIMER_END("grpc_completion_queue_pluck", 0); @@ -1169,22 +1138,19 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag, return cq->vtable->pluck(cq, tag, deadline, reserved); } -static void cq_finish_shutdown_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq) { +static void cq_finish_shutdown_pluck(grpc_completion_queue *cq) { cq_pluck_data *cqd = (cq_pluck_data *)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown)); gpr_atm_no_barrier_store(&cqd->shutdown, 1); - cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), - &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); } /* NOTE: This function is almost exactly identical to cq_shutdown_next() but * merging them is a bit tricky and probably not worth it */ -static void cq_shutdown_pluck(grpc_exec_ctx *exec_ctx, - grpc_completion_queue *cq) { +static void cq_shutdown_pluck(grpc_completion_queue *cq) { cq_pluck_data *cqd = (cq_pluck_data *)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -1197,25 +1163,25 @@ static void cq_shutdown_pluck(grpc_exec_ctx *exec_ctx, gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); return; } cqd->shutdown_called = true; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(exec_ctx, cq); + cq_finish_shutdown_pluck(cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); } /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue *cq) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); - cq->vtable->shutdown(&exec_ctx, cq); - grpc_exec_ctx_finish(&exec_ctx); + cq->vtable->shutdown(cq); + grpc_exec_ctx_finish(); GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } @@ -1224,9 +1190,9 @@ void grpc_completion_queue_destroy(grpc_completion_queue *cq) { GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "destroy"); - grpc_exec_ctx_finish(&exec_ctx); + ExecCtx _local_exec_ctx; + GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); + grpc_exec_ctx_finish(); GPR_TIMER_END("grpc_completion_queue_destroy", 0); } -- cgit v1.2.3 From 75122c23578e24417dcf64081c737571a9fc2dbc Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 13 Nov 2017 15:37:58 -0800 Subject: Address some PR comments --- .../ext/filters/client_channel/backup_poller.cc | 6 +- .../filters/client_channel/channel_connectivity.cc | 6 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 8 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 2 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 14 +- .../resolver/dns/native/dns_resolver.cc | 2 +- src/core/ext/filters/client_channel/subchannel.cc | 2 +- .../ext/filters/client_channel/subchannel_index.cc | 36 ++--- src/core/ext/filters/max_age/max_age_filter.cc | 6 +- .../chttp2/client/insecure/channel_create.cc | 2 +- .../chttp2/client/insecure/channel_create_posix.cc | 2 - .../chttp2/client/secure/secure_channel_create.cc | 1 - .../ext/transport/chttp2/server/chttp2_server.cc | 6 +- .../chttp2/server/insecure/server_chttp2.cc | 2 +- .../chttp2/server/insecure/server_chttp2_posix.cc | 1 - .../chttp2/server/secure/server_secure_chttp2.cc | 2 +- .../transport/chttp2/transport/chttp2_transport.cc | 10 +- .../ext/transport/chttp2/transport/flow_control.cc | 4 +- .../ext/transport/chttp2/transport/frame_ping.cc | 2 +- .../transport/chttp2/transport/hpack_encoder.cc | 2 +- src/core/ext/transport/chttp2/transport/parsing.cc | 2 +- src/core/ext/transport/chttp2/transport/writing.cc | 2 +- .../transport/cronet/transport/cronet_transport.cc | 8 -- src/core/ext/transport/inproc/inproc_transport.cc | 3 - src/core/lib/backoff/backoff.cc | 4 +- .../lib/compression/stream_compression_gzip.cc | 8 +- src/core/lib/debug/stats.h | 2 +- src/core/lib/iomgr/block_annotate.h | 23 ++-- src/core/lib/iomgr/combiner.cc | 49 ++++--- src/core/lib/iomgr/endpoint_pair_posix.cc | 1 - src/core/lib/iomgr/endpoint_pair_windows.cc | 2 +- src/core/lib/iomgr/error.cc | 6 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 24 ++-- src/core/lib/iomgr/ev_epollex_linux.cc | 10 +- src/core/lib/iomgr/ev_epollsig_linux.cc | 8 +- src/core/lib/iomgr/ev_poll_posix.cc | 10 +- src/core/lib/iomgr/exec_ctx.cc | 98 ++++---------- src/core/lib/iomgr/exec_ctx.h | 148 ++++++++++----------- src/core/lib/iomgr/executor.cc | 11 +- src/core/lib/iomgr/iocp_windows.cc | 10 +- src/core/lib/iomgr/iomgr.cc | 11 +- src/core/lib/iomgr/iomgr_uv.cc | 1 - src/core/lib/iomgr/load_file.cc | 2 +- src/core/lib/iomgr/pollset_uv.cc | 4 +- src/core/lib/iomgr/pollset_windows.cc | 8 +- src/core/lib/iomgr/resolve_address_posix.cc | 4 +- src/core/lib/iomgr/resolve_address_uv.cc | 2 +- src/core/lib/iomgr/resolve_address_windows.cc | 2 +- src/core/lib/iomgr/resource_quota.cc | 2 - src/core/lib/iomgr/tcp_client_uv.cc | 3 +- src/core/lib/iomgr/tcp_posix.cc | 2 +- src/core/lib/iomgr/tcp_server_uv.cc | 12 +- src/core/lib/iomgr/tcp_uv.cc | 5 - src/core/lib/iomgr/timer_generic.cc | 8 +- src/core/lib/iomgr/timer_manager.cc | 11 +- src/core/lib/iomgr/timer_uv.cc | 5 +- src/core/lib/security/context/security_context.cc | 3 +- src/core/lib/security/credentials/credentials.cc | 3 - .../google_default/google_default_credentials.cc | 9 +- .../security/credentials/iam/iam_credentials.cc | 2 +- .../security/credentials/jwt/jwt_credentials.cc | 2 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 6 +- .../credentials/oauth2/oauth2_credentials.cc | 11 +- .../credentials/plugin/plugin_credentials.cc | 6 +- .../lib/security/transport/security_handshaker.cc | 1 - .../lib/security/transport/server_auth_filter.cc | 1 - src/core/lib/slice/slice.cc | 1 - src/core/lib/slice/slice_buffer.cc | 2 - src/core/lib/surface/alarm.cc | 4 +- src/core/lib/surface/byte_buffer.cc | 1 - src/core/lib/surface/byte_buffer_reader.cc | 4 +- src/core/lib/surface/call.cc | 7 +- src/core/lib/surface/call_details.cc | 1 - src/core/lib/surface/channel.cc | 9 +- src/core/lib/surface/channel_ping.cc | 1 - src/core/lib/surface/completion_queue.cc | 138 ++++++++++--------- src/core/lib/surface/init.cc | 5 +- src/core/lib/surface/lame_client.cc | 2 +- src/core/lib/surface/server.cc | 15 +-- src/core/lib/transport/bdp_estimator.cc | 2 +- src/core/lib/transport/status_conversion.cc | 4 +- src/core/lib/transport/transport.cc | 2 +- src/cpp/common/channel_arguments.cc | 3 +- test/core/backoff/backoff_test.cc | 51 ++++--- test/core/bad_client/bad_client.cc | 9 +- test/core/channel/channel_args_test.cc | 4 - test/core/channel/channel_stack_test.cc | 3 +- test/core/channel/minimal_stack_is_minimal_test.cc | 2 - test/core/client_channel/lb_policies_test.cc | 2 - test/core/client_channel/parse_address_test.cc | 3 - .../resolvers/dns_resolver_connectivity_test.cc | 6 +- .../client_channel/resolvers/dns_resolver_test.cc | 3 - .../client_channel/resolvers/fake_resolver_test.cc | 8 +- .../resolvers/sockaddr_resolver_test.cc | 4 +- test/core/client_channel/uri_fuzzer_test.cc | 2 +- test/core/client_channel/uri_parser_test.cc | 8 +- test/core/compression/algorithm_test.cc | 2 - test/core/compression/message_compress_test.cc | 9 +- test/core/debug/stats_test.cc | 3 - test/core/end2end/bad_server_response_test.cc | 2 +- test/core/end2end/connection_refused_test.cc | 1 - test/core/end2end/fixtures/h2_census.cc | 2 - test/core/end2end/fixtures/h2_compress.cc | 3 - test/core/end2end/fixtures/h2_fd.cc | 4 - test/core/end2end/fixtures/h2_full+workarounds.cc | 1 - test/core/end2end/fixtures/h2_load_reporting.cc | 1 - test/core/end2end/fixtures/h2_oauth2.cc | 1 - test/core/end2end/fixtures/h2_sockpair+trace.cc | 4 - test/core/end2end/fixtures/h2_sockpair.cc | 3 - test/core/end2end/fixtures/h2_sockpair_1byte.cc | 3 - test/core/end2end/fixtures/h2_ssl.cc | 1 - test/core/end2end/fixtures/h2_ssl_proxy.cc | 2 - test/core/end2end/fixtures/http_proxy_fixture.cc | 15 +-- test/core/end2end/fuzzers/api_fuzzer.cc | 10 +- test/core/end2end/fuzzers/client_fuzzer.cc | 2 +- test/core/end2end/fuzzers/server_fuzzer.cc | 2 +- test/core/end2end/h2_ssl_cert_test.cc | 1 - test/core/end2end/tests/cancel_after_accept.cc | 1 - test/core/end2end/tests/cancel_after_round_trip.cc | 1 - test/core/end2end/tests/compressed_payload.cc | 3 - test/core/end2end/tests/load_reporting_hook.cc | 1 - test/core/end2end/tests/max_message_length.cc | 2 - .../tests/stream_compression_compressed_payload.cc | 3 - .../end2end/tests/stream_compression_payload.cc | 1 - .../stream_compression_ping_pong_streaming.cc | 1 - .../end2end/tests/workaround_cronet_compression.cc | 2 - test/core/http/httpcli_test.cc | 6 +- test/core/http/httpscli_test.cc | 6 +- test/core/iomgr/combiner_test.cc | 11 +- test/core/iomgr/endpoint_pair_test.cc | 3 +- test/core/iomgr/endpoint_tests.cc | 16 +-- test/core/iomgr/ev_epollsig_linux_test.cc | 23 ++-- test/core/iomgr/fd_conservation_posix_test.cc | 3 +- test/core/iomgr/fd_posix_test.cc | 16 +-- test/core/iomgr/pollset_set_test.cc | 32 ++--- test/core/iomgr/resolve_address_posix_test.cc | 11 +- test/core/iomgr/resolve_address_test.cc | 33 ++--- test/core/iomgr/resource_quota_test.cc | 86 +++++------- test/core/iomgr/tcp_client_posix_test.cc | 13 +- test/core/iomgr/tcp_client_uv_test.cc | 11 +- test/core/iomgr/tcp_posix_test.cc | 20 +-- test/core/iomgr/tcp_server_posix_test.cc | 11 +- test/core/iomgr/tcp_server_uv_test.cc | 9 +- test/core/iomgr/timer_list_test.cc | 28 ++-- test/core/iomgr/udp_server_test.cc | 13 +- test/core/security/credentials_test.cc | 46 ++----- test/core/security/json_token_test.cc | 4 +- test/core/security/jwt_verifier_test.cc | 20 +-- test/core/security/oauth2_utils.cc | 4 +- .../security/print_google_default_creds_token.cc | 4 +- test/core/security/secure_endpoint_test.cc | 8 +- test/core/security/ssl_server_fuzzer.cc | 8 +- test/core/security/verify_jwt.cc | 4 +- test/core/slice/b64_test.cc | 5 +- test/core/slice/slice_hash_table_test.cc | 3 - test/core/surface/byte_buffer_reader_test.cc | 1 - test/core/surface/channel_create_test.cc | 1 - test/core/surface/completion_queue_test.cc | 4 - .../surface/completion_queue_threading_test.cc | 3 - test/core/surface/concurrent_connectivity_test.cc | 7 +- test/core/surface/lame_client_test.cc | 2 - .../num_external_connectivity_watchers_test.cc | 1 - test/core/surface/secure_channel_create_test.cc | 3 - test/core/surface/sequential_connectivity_test.cc | 1 - test/core/transport/bdp_estimator_test.cc | 3 +- test/core/transport/byte_stream_test.cc | 5 - test/core/transport/chttp2/bin_decoder_test.cc | 2 - test/core/transport/chttp2/hpack_encoder_test.cc | 1 - .../transport/chttp2/hpack_parser_fuzzer_test.cc | 2 +- test/core/transport/chttp2/hpack_parser_test.cc | 3 - test/core/transport/chttp2/hpack_table_test.cc | 5 +- test/core/transport/connectivity_state_test.cc | 14 +- test/core/transport/metadata_test.cc | 15 +-- test/core/transport/status_conversion_test.cc | 2 +- test/core/util/port_server_client.cc | 18 +-- test/core/util/test_tcp_server.cc | 5 +- test/cpp/end2end/client_lb_end2end_test.cc | 1 - test/cpp/end2end/grpclb_end2end_test.cc | 1 - test/cpp/grpclb/grpclb_test.cc | 1 - test/cpp/microbenchmarks/bm_call_create.cc | 7 +- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 20 ++- test/cpp/microbenchmarks/bm_chttp2_transport.cc | 13 +- test/cpp/microbenchmarks/bm_closure.cc | 65 +++++---- test/cpp/microbenchmarks/bm_cq.cc | 6 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 2 +- test/cpp/microbenchmarks/bm_error.cc | 6 +- test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 2 +- test/cpp/microbenchmarks/bm_metadata.cc | 26 ++-- test/cpp/microbenchmarks/bm_pollset.cc | 12 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 2 - test/cpp/naming/resolver_component_test.cc | 6 +- test/cpp/performance/writes_per_rpc_test.cc | 2 - 192 files changed, 700 insertions(+), 1091 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 1b42f5d6a0..dbdcd53ef5 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -112,10 +112,10 @@ static void run_poller(void* arg, grpc_error* error) { backup_poller_shutdown_unref(p); return; } - grpc_error* err = grpc_pollset_work(p->pollset, NULL, grpc_exec_ctx_now()); + grpc_error* err = grpc_pollset_work(p->pollset, NULL, ExecCtx::Get()->Now()); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); - grpc_timer_init(&p->polling_timer, grpc_exec_ctx_now() + g_poll_interval_ms, + grpc_timer_init(&p->polling_timer, ExecCtx::Get()->Now() + g_poll_interval_ms, &p->run_poller_closure); } @@ -137,7 +137,7 @@ void grpc_client_channel_start_backup_polling( GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); grpc_timer_init(&g_poller->polling_timer, - grpc_exec_ctx_now() + g_poll_interval_ms, + ExecCtx::Get()->Now() + g_poll_interval_ms, &g_poller->run_poller_closure); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 3069e66775..0ceedb9f86 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -41,14 +41,14 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( if (client_channel_elem->filter == &grpc_client_channel_filter) { state = grpc_client_channel_check_connectivity_state(client_channel_elem, try_to_connect); - grpc_exec_ctx_finish(); + return state; } gpr_log(GPR_ERROR, "grpc_channel_check_connectivity_state called on something that is " "not a client channel, but '%s'", client_channel_elem->filter->name); - grpc_exec_ctx_finish(); + return GRPC_CHANNEL_SHUTDOWN; } @@ -241,6 +241,4 @@ void grpc_channel_watch_connectivity_state( } else { abort(); } - - grpc_exec_ctx_finish(); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index d4c58fb1e0..63cf417c4e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -1122,7 +1122,7 @@ static void start_picking_locked(glb_lb_policy* glb_policy) { if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { grpc_millis deadline = - grpc_exec_ctx_now() + glb_policy->lb_fallback_timeout_ms; + ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); GRPC_CLOSURE_INIT(&glb_policy->lb_on_fallback, lb_on_fallback_timer_locked, glb_policy, @@ -1271,7 +1271,7 @@ static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); if (timeout > 0) { gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", @@ -1297,7 +1297,7 @@ static void send_client_load_report_locked(void* arg, grpc_error* error); static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = - grpc_exec_ctx_now() + glb_policy->client_stats_report_interval; + ExecCtx::Get()->Now() + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, send_client_load_report_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); @@ -1392,7 +1392,7 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now() + glb_policy->lb_call_timeout_ms; + : ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 77d790aa38..f0543964ae 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -265,7 +265,7 @@ static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index c57fac61a4..925223d189 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -101,18 +101,7 @@ static void grpc_ares_request_unref(grpc_ares_request* r) { request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - if (exec_ctx == NULL) { - /* A new exec_ctx is created here, as the c-ares interface does not - provide one in ares_host_callback. It's safe to schedule on_done with - the newly created exec_ctx, since the caller has been warned not to - acquire locks in on_done. ares_dns_resolver is using combiner to - protect resources needed by on_done. */ - ExecCtx _local_exec_ctx; - GRPC_CLOSURE_SCHED(r->on_done, r->error); - grpc_exec_ctx_finish(); - } else { - GRPC_CLOSURE_SCHED(r->on_done, r->error); - } + GRPC_CLOSURE_SCHED(r->on_done, r->error); gpr_mu_destroy(&r->mu); grpc_ares_ev_driver_destroy(r->ev_driver); gpr_free(r); @@ -263,7 +252,6 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, } } grpc_ares_request_unref(r); - grpc_exec_ctx_finish(); } static const char g_service_config_attribute_prefix[] = "grpc_config="; diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 4463673e1f..10404ec4ef 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -163,7 +163,7 @@ static void dns_on_resolved_locked(void* arg, grpc_error* error) { } else { grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(); + grpc_millis timeout = next_try - ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index c8583687d5..98f96b5750 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -458,7 +458,7 @@ static void maybe_start_connecting_locked(grpc_subchannel* c) { GPR_ASSERT(!c->have_alarm); c->have_alarm = true; const grpc_millis time_til_next = - c->backoff_result.next_attempt_start_time - grpc_exec_ctx_now(); + c->backoff_result.next_attempt_start_time - ExecCtx::Get()->Now(); if (time_til_next <= 0) { gpr_log(GPR_INFO, "Retry immediately"); } else { diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index cb8e480734..fbab57769c 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -132,10 +132,8 @@ void grpc_subchannel_index_shutdown(void) { void grpc_subchannel_index_unref(void) { if (gpr_unref(&g_refcount)) { - ExecCtx _local_exec_ctx; gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index, exec_ctx); - grpc_exec_ctx_finish(); + gpr_avl_unref(g_subchannel_index, ExecCtx::Get()); } } @@ -145,12 +143,12 @@ grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx), "index_find"); - gpr_avl_unref(index, exec_ctx); + (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()), "index_find"); + gpr_avl_unref(index, ExecCtx::Get()); return c; } @@ -166,11 +164,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + c = (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); if (c != NULL) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -180,8 +178,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } else { // no -> update the avl and compare/swap gpr_avl updated = gpr_avl_add( - gpr_avl_ref(index, exec_ctx), subchannel_key_copy(key), - GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), exec_ctx); + gpr_avl_ref(index, ExecCtx::Get()), subchannel_key_copy(key), + GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), + ExecCtx::Get()); // it may happen (but it's expected to be unlikely) // that some other thread has changed the index: @@ -193,9 +192,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); + gpr_avl_unref(updated, ExecCtx::Get()); } - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, ExecCtx::Get()); } if (need_to_unref_constructed) { @@ -212,21 +211,22 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); gpr_mu_unlock(&g_mu); // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel* c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + grpc_subchannel* c = + (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); if (c != constructed) { - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, ExecCtx::Get()); break; } // compare and swap the update (some other thread may have // mutated the index behind us) gpr_avl updated = - gpr_avl_remove(gpr_avl_ref(index, exec_ctx), key, exec_ctx); + gpr_avl_remove(gpr_avl_ref(index, ExecCtx::Get()), key, ExecCtx::Get()); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -235,8 +235,8 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(updated, ExecCtx::Get()); + gpr_avl_unref(index, ExecCtx::Get()); } } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 1b9ce3b996..015a3ce124 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -100,7 +100,7 @@ static void decrease_call_count(channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); grpc_timer_init(&chand->max_idle_timer, - grpc_exec_ctx_now() + chand->max_connection_idle, + ExecCtx::Get()->Now() + chand->max_connection_idle, &chand->close_max_idle_channel); } } @@ -121,7 +121,7 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); grpc_timer_init(&chand->max_age_timer, - grpc_exec_ctx_now() + chand->max_connection_age, + ExecCtx::Get()->Now() + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(NULL); @@ -141,7 +141,7 @@ static void start_max_age_grace_timer_after_goaway_op(void* arg, grpc_timer_init(&chand->max_age_grace_timer, chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now() + chand->max_connection_age_grace, + : ExecCtx::Get()->Now() + chand->max_connection_age_grace, &chand->force_close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index e7741f97d4..3afca884ca 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -95,7 +95,7 @@ grpc_channel* grpc_insecure_channel_create(const char* target, new_args); // Clean up. grpc_channel_args_destroy(new_args); - grpc_exec_ctx_finish(); + return channel != NULL ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index 37e6f1f30d..b0eff1c992 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -60,8 +60,6 @@ grpc_channel* grpc_insecure_channel_create_from_fd( grpc_channel_args_destroy(final_args); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); - return channel != NULL ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index a5da71a67c..bebc38c248 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -211,7 +211,6 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, new_args); // Clean up. grpc_channel_args_destroy(new_args); - grpc_exec_ctx_finish(); } return channel != NULL ? channel : grpc_lame_client_channel_create( diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 6eb1e3491c..bbcfb1b195 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -132,7 +132,7 @@ static void on_accept(void* arg, grpc_endpoint* tcp, connection_state->handshake_mgr); // TODO(roth): We should really get this timeout value from channel // args instead of hard-coding it. - const grpc_millis deadline = grpc_exec_ctx_now() + 120 * GPR_MS_PER_SEC; + const grpc_millis deadline = ExecCtx::Get()->Now() + 120 * GPR_MS_PER_SEC; grpc_handshake_manager_do_handshake(connection_state->handshake_mgr, tcp, state->args, deadline, acceptor, on_handshake_done, connection_state); @@ -161,10 +161,10 @@ static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { gpr_mu_unlock(&state->mu); // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); if (destroy_done != NULL) { destroy_done->cb(destroy_done->cb_arg, GRPC_ERROR_REF(error)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } grpc_channel_args_destroy(state->args); gpr_mu_destroy(&state->mu); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index d7aad110b9..6cbb26a349 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -39,6 +39,6 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { GRPC_ERROR_UNREF(err); } - grpc_exec_ctx_finish(); + return port_num; } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index 57a8316a58..e5419e5e6e 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -61,7 +61,6 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, grpc_server_setup_transport(server, transport, NULL, server_args); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } #else // !GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index dc7da96210..aeae8f42e3 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -76,7 +76,7 @@ done: if (sc != NULL) { GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "server"); } - grpc_exec_ctx_finish(); + if (err != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index ecf3cf69ef..e49e26fc35 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -530,7 +530,7 @@ static void init_transport(grpc_chttp2_transport* t, t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - grpc_exec_ctx_now() + t->keepalive_time, + ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } else { /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no @@ -2585,14 +2585,14 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { } else { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - grpc_exec_ctx_now() + t->keepalive_time, + ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } else if (error == GRPC_ERROR_CANCELLED) { /* The keepalive ping timer may be cancelled by bdp */ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - grpc_exec_ctx_now() + t->keepalive_time, + ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping"); @@ -2602,7 +2602,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(&t->keepalive_watchdog_timer, - grpc_exec_ctx_now() + t->keepalive_time, + ExecCtx::Get()->Now() + t->keepalive_time, &t->keepalive_watchdog_fired_locked); } @@ -2614,7 +2614,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_timer_cancel(&t->keepalive_watchdog_timer); GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - grpc_exec_ctx_now() + t->keepalive_time, + ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 1609fa0532..e54d59b5fa 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -160,7 +160,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, .set_min_control_value(-1) .set_max_control_value(25) .set_integral_range(10)), - last_pid_update_(grpc_exec_ctx_now()) {} + last_pid_update_(ExecCtx::Get()->Now()) {} uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); @@ -306,7 +306,7 @@ double TransportFlowControl::TargetLogBdp() { } double TransportFlowControl::SmoothLogBdp(double value) { - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); double bdp_error = value - pid_controller_.last_control_value(); const double dt = (double)(now - last_pid_update_) * 1e-3; last_pid_update_ = now; diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 1b0dc0dfaa..60172be9cb 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -89,7 +89,7 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, grpc_chttp2_ack_ping(t, p->opaque_8bytes); } else { if (!t->is_client) { - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_recv_state.last_ping_recv_time + t->ping_policy.min_recv_ping_interval_without_data; diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index e225a0244a..efb6e54ce7 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -570,7 +570,7 @@ static void deadline_enc(grpc_chttp2_hpack_compressor* c, grpc_millis deadline, framer_state* st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem mdelem; - grpc_http2_encode_timeout(deadline - grpc_exec_ctx_now(), timeout_str); + grpc_http2_encode_timeout(deadline - ExecCtx::Get()->Now(), timeout_str); mdelem = grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_TIMEOUT, grpc_slice_from_copied_string(timeout_str)); hpack_enc(c, mdelem, st); diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 5731e9ff78..f7f83c9aee 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -436,7 +436,7 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (timeout != GRPC_MILLIS_INF_FUTURE) { grpc_chttp2_incoming_metadata_buffer_set_deadline( - &s->metadata_buffer[0], grpc_exec_ctx_now() + timeout); + &s->metadata_buffer[0], ExecCtx::Get()->Now() + timeout); } GRPC_MDELEM_UNREF(md); } else { diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index ec83633472..4f76c2eb23 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -68,7 +68,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { } return; } - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_state.last_ping_sent_time + t->ping_policy.min_sent_ping_interval_without_data; diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index bff0fb36ad..3411acc563 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -417,7 +417,6 @@ static void on_failed(bidirectional_stream* stream, int net_error) { gpr_mu_unlock(&s->mu); execute_from_storage(s); GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); - grpc_exec_ctx_finish(); } /* @@ -444,7 +443,6 @@ static void on_canceled(bidirectional_stream* stream) { gpr_mu_unlock(&s->mu); execute_from_storage(s); GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); - grpc_exec_ctx_finish(); } /* @@ -463,7 +461,6 @@ static void on_succeeded(bidirectional_stream* stream) { gpr_mu_unlock(&s->mu); execute_from_storage(s); GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); - grpc_exec_ctx_finish(); } /* @@ -492,7 +489,6 @@ static void on_stream_ready(bidirectional_stream* stream) { } gpr_mu_unlock(&s->mu); execute_from_storage(s); - grpc_exec_ctx_finish(); } /* @@ -548,7 +544,6 @@ static void on_response_headers_received( } gpr_mu_unlock(&s->mu); execute_from_storage(s); - grpc_exec_ctx_finish(); } /* @@ -566,7 +561,6 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { s->state.state_callback_received[OP_SEND_MESSAGE] = true; gpr_mu_unlock(&s->mu); execute_from_storage(s); - grpc_exec_ctx_finish(); } /* @@ -608,7 +602,6 @@ static void on_read_completed(bidirectional_stream* stream, char* data, gpr_mu_unlock(&s->mu); execute_from_storage(s); } - grpc_exec_ctx_finish(); } /* @@ -666,7 +659,6 @@ static void on_response_trailers_received( gpr_mu_unlock(&s->mu); execute_from_storage(s); } - grpc_exec_ctx_finish(); } /* diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 1c7f2873d1..a79b2b26b0 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -1107,7 +1107,6 @@ void grpc_inproc_transport_init(void) { grpc_slice_unref_internal(auth_tmp); g_fake_auth_value = grpc_slice_from_static_string("inproc-fail"); - grpc_exec_ctx_finish(); } static const grpc_transport_vtable inproc_vtable = { @@ -1182,7 +1181,6 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, grpc_channel_args_destroy(client_args); // Now finish scheduled operations - grpc_exec_ctx_finish(); return channel; } @@ -1194,5 +1192,4 @@ void grpc_inproc_transport_shutdown(void) { grpc_slice_unref_internal(g_fake_path_value); grpc_slice_unref_internal(g_fake_auth_key); grpc_slice_unref_internal(g_fake_auth_value); - grpc_exec_ctx_finish(); } diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index e6c55f420d..b75ce79d46 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -36,7 +36,7 @@ grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff) { backoff->current_backoff = backoff->initial_backoff; const grpc_millis initial_timeout = GPR_MAX(backoff->initial_backoff, backoff->min_connect_timeout); - const grpc_millis now = grpc_exec_ctx_now(); + const grpc_millis now = ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + initial_timeout, now + backoff->current_backoff}; return result; @@ -67,7 +67,7 @@ grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff) { backoff->min_connect_timeout); const grpc_millis next_timeout = GPR_MIN( (grpc_millis)(backoff->current_backoff + jitter), backoff->max_backoff); - const grpc_millis now = grpc_exec_ctx_now(); + const grpc_millis now = ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + current_timeout, now + next_timeout}; return result; diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 4d5d0955ce..3fae3490ce 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -58,7 +58,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, if (r < 0 && r != Z_BUF_ERROR) { gpr_log(GPR_ERROR, "zlib error (%d)", r); grpc_slice_unref_internal(slice_out); - grpc_exec_ctx_finish(); + return false; } else if (r == Z_STREAM_END && ctx->flate == inflate) { eoc = true; @@ -89,7 +89,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, default: gpr_log(GPR_ERROR, "zlib error (%d)", r); grpc_slice_unref_internal(slice_out); - grpc_exec_ctx_finish(); + return false; } } else if (flush == Z_FINISH) { @@ -105,7 +105,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, default: gpr_log(GPR_ERROR, "zlib error (%d)", r); grpc_slice_unref_internal(slice_out); - grpc_exec_ctx_finish(); + return false; } } @@ -121,7 +121,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, } max_output_size -= (slice_size - ctx->zs.avail_out); } - grpc_exec_ctx_finish(); + if (end_of_context) { *end_of_context = eoc; } diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index 1c2826506c..24b0084130 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -35,7 +35,7 @@ typedef struct grpc_stats_data { extern grpc_stats_data* grpc_stats_per_cpu_storage; #define GRPC_THREAD_STATS_DATA() \ - (&grpc_stats_per_cpu_storage[(exec_ctx)->starting_cpu]) + (&grpc_stats_per_cpu_storage[ExecCtx::Get()->starting_cpu()]) #define GRPC_STATS_INC_COUNTER(ctr) \ (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1)) diff --git a/src/core/lib/iomgr/block_annotate.h b/src/core/lib/iomgr/block_annotate.h index 9db3cf0199..7783da0c14 100644 --- a/src/core/lib/iomgr/block_annotate.h +++ b/src/core/lib/iomgr/block_annotate.h @@ -19,6 +19,8 @@ #ifndef GRPC_CORE_LIB_IOMGR_BLOCK_ANNOTATE_H #define GRPC_CORE_LIB_IOMGR_BLOCK_ANNOTATE_H +#include "src/core/lib/iomgr/exec_ctx.h" + #ifdef __cplusplus extern "C" { #endif @@ -39,25 +41,18 @@ void gpr_thd_end_blocking_region(); do { \ gpr_thd_start_blocking_region(); \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ - do { \ - gpr_thd_end_blocking_region(); \ - } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX() \ - do { \ - gpr_thd_end_blocking_region(); \ - grpc_exec_ctx_invalidate_now(); \ +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + gpr_thd_end_blocking_region(); \ + ExecCtx::Get()->InvalidateNow(); \ } while (0) #else #define GRPC_SCHEDULING_START_BLOCKING_REGION \ do { \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ - do { \ - } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX() \ - do { \ - grpc_exec_ctx_invalidate_now(); \ +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + ExecCtx::Get()->InvalidateNow(); \ } while (0) #endif diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index b1b8fffdca..c9f5448630 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -128,20 +128,24 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { } static void push_last_on_exec_ctx(grpc_combiner* lock) { - lock->next_combiner_on_this_exec_ctx = NULL; - if (exec_ctx->active_combiner == NULL) { - exec_ctx->active_combiner = exec_ctx->last_combiner = lock; + lock->next_combiner_on_this_exec_ctx = nullptr; + if (ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { + ExecCtx::Get()->combiner_data()->active_combiner = + ExecCtx::Get()->combiner_data()->last_combiner = lock; } else { - exec_ctx->last_combiner->next_combiner_on_this_exec_ctx = lock; - exec_ctx->last_combiner = lock; + ExecCtx::Get() + ->combiner_data() + ->last_combiner->next_combiner_on_this_exec_ctx = lock; + ExecCtx::Get()->combiner_data()->last_combiner = lock; } } static void push_first_on_exec_ctx(grpc_combiner* lock) { - lock->next_combiner_on_this_exec_ctx = exec_ctx->active_combiner; - exec_ctx->active_combiner = lock; + lock->next_combiner_on_this_exec_ctx = + ExecCtx::Get()->combiner_data()->active_combiner; + ExecCtx::Get()->combiner_data()->active_combiner = lock; if (lock->next_combiner_on_this_exec_ctx == NULL) { - exec_ctx->last_combiner = lock; + ExecCtx::Get()->combiner_data()->last_combiner = lock; } } @@ -161,7 +165,7 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(); GPR_TIMER_MARK("combiner.initiated", 0); gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, - (gpr_atm)exec_ctx); + (gpr_atm)ExecCtx::Get()); // first element on this list: add it to the list of combiner locks // executing within this exec_ctx push_last_on_exec_ctx(lock); @@ -170,7 +174,7 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { // offload for one or two actions, and that's fine gpr_atm initiator = gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null); - if (initiator != 0 && initiator != (gpr_atm)exec_ctx) { + if (initiator != 0 && initiator != (gpr_atm)ExecCtx::Get()) { gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } @@ -182,10 +186,12 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { } static void move_next() { - exec_ctx->active_combiner = - exec_ctx->active_combiner->next_combiner_on_this_exec_ctx; - if (exec_ctx->active_combiner == NULL) { - exec_ctx->last_combiner = NULL; + ExecCtx::Get()->combiner_data()->active_combiner = + ExecCtx::Get() + ->combiner_data() + ->active_combiner->next_combiner_on_this_exec_ctx; + if (ExecCtx::Get()->combiner_data()->active_combiner == NULL) { + ExecCtx::Get()->combiner_data()->last_combiner = NULL; } } @@ -203,7 +209,7 @@ static void queue_offload(grpc_combiner* lock) { bool grpc_combiner_continue_exec_ctx() { GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0); - grpc_combiner* lock = exec_ctx->active_combiner; + grpc_combiner* lock = ExecCtx::Get()->combiner_data()->active_combiner; if (lock == NULL) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); return false; @@ -217,10 +223,11 @@ bool grpc_combiner_continue_exec_ctx() { "contended=%d " "exec_ctx_ready_to_finish=%d " "time_to_execute_final_list=%d", - lock, contended, grpc_exec_ctx_ready_to_finish(), + lock, contended, + ExecCtx::Get()->IsReadyToFinish(), lock->time_to_execute_final_list)); - if (contended && grpc_exec_ctx_ready_to_finish() && + if (contended && ExecCtx::Get()->IsReadyToFinish() && grpc_executor_is_threaded()) { GPR_TIMER_MARK("offload_from_finished_exec_ctx", 0); // this execution context wants to move on: schedule remaining work to be @@ -326,11 +333,11 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(closure, finally_scheduler); - GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, - "C:%p grpc_combiner_execute_finally c=%p; ac=%p", - lock, closure, exec_ctx->active_combiner)); + GRPC_COMBINER_TRACE( + gpr_log(GPR_DEBUG, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, + closure, ExecCtx::Get()->combiner_data()->active_combiner)); GPR_TIMER_BEGIN("combiner.execute_finally", 0); - if (exec_ctx->active_combiner != lock) { + if (ExecCtx::Get()->combiner_data()->active_combiner != lock) { GPR_TIMER_MARK("slowpath", 0); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(enqueue_finally, closure, grpc_combiner_scheduler(lock)), diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 696ac6942f..1a281322a8 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -65,7 +65,6 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name, "socketpair-client"); gpr_free(final_name); - grpc_exec_ctx_finish(); return p; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index d464617097..e0f211cdf9 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -77,7 +77,7 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( channel_args, "endpoint:server"); p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server"), channel_args, "endpoint:client"); - grpc_exec_ctx_finish(); + return p; } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index ce8b538773..157f12a36d 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -157,11 +157,7 @@ static void unref_errs(grpc_error* err) { } } -static void unref_slice(grpc_slice slice) { - ExecCtx _local_exec_ctx; - grpc_slice_unref_internal(slice); - grpc_exec_ctx_finish(); -} +static void unref_slice(grpc_slice slice) { grpc_slice_unref_internal(slice); } static void unref_strs(grpc_error* err) { for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) { diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 31f51df15d..2b486887b8 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -554,7 +554,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(); + grpc_millis delta = millis - ExecCtx::Get()->Now(); if (delta > INT_MAX) { return INT_MAX; } else if (delta < 0) { @@ -630,7 +630,7 @@ static grpc_error* do_epoll_wait(grpc_pollset* ps, grpc_millis deadline) { timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(); + GRPC_SCHEDULING_END_BLOCKING_REGION; } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); @@ -743,7 +743,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker, KICKED); } } - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); } if (GRPC_TRACER_ON(grpc_polling_trace)) { @@ -848,7 +848,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, /* Make sure we appear kicked */ SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, - &exec_ctx->closure_list); + ExecCtx::Get()->closure_list()); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { if (worker->next != worker && worker->next->state == UNKICKED) { if (GRPC_TRACER_ON(grpc_polling_trace)) { @@ -859,9 +859,9 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker->next, DESIGNATED_POLLER); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&worker->next->cv); - if (grpc_exec_ctx_has_work()) { + if (ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } else { @@ -892,12 +892,12 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, found_worker = check_neighborhood_for_available_poller(neighborhood); gpr_mu_unlock(&neighborhood->mu); } - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } - } else if (grpc_exec_ctx_has_work()) { + } else if (ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } if (worker->initialized_cv) { @@ -948,9 +948,9 @@ static grpc_error* pollset_work(grpc_pollset* ps, process_epoll_events() returns very quickly: It just queues the work on exec_ctx but does not execute it (the actual exectution or more - accurately grpc_exec_ctx_flush() happens in end_worker() AFTER selecting - a designated poller). So we are not waiting long periods without a - designated poller */ + accurately ExecCtx::Get()->Flush() happens in end_worker() AFTER + selecting a designated poller). So we are not waiting long periods + without a designated poller */ if (gpr_atm_acq_load(&g_epoll_set.cursor) == gpr_atm_acq_load(&g_epoll_set.num_events)) { append_error(&error, do_epoll_wait(ps, deadline), err_desc); diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 0979a45270..385b5f68d0 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -682,7 +682,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(); + grpc_millis delta = millis - ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -804,7 +804,7 @@ static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) { r = epoll_wait(p->epfd, p->events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(); + GRPC_SCHEDULING_END_BLOCKING_REGION; } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); @@ -902,7 +902,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->pollable_obj, worker); } } - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); } else { gpr_mu_unlock(&pollset->mu); } @@ -970,7 +970,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR " kwp=%d pollable=%p", - pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(), deadline, + pollset, worker_hdl, WORKER_PTR, ExecCtx::Get()->Now(), deadline, pollset->kicked_without_poller, pollset->active_pollable); } static const char* err_desc = "pollset_work"; @@ -990,7 +990,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, &error, pollable_process_events(pollset, WORKER_PTR->pollable_obj, false), err_desc); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_tls_set(&g_current_thread_pollset, 0); gpr_tls_set(&g_current_thread_worker, 0); } diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index c42a609fee..a9b094a2fa 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -1090,7 +1090,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(); + grpc_millis delta = millis - ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -1220,7 +1220,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, GRPC_STATS_INC_SYSCALL_POLL(); ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms, sig_mask); - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(); + GRPC_SCHEDULING_END_BLOCKING_REGION; if (ep_rv < 0) { if (errno != EINTR) { gpr_asprintf(&err_msg, @@ -1350,7 +1350,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, pollset_work_and_unlock(pollset, &worker, timeout_ms, &g_orig_sigmask, &error); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); @@ -1373,7 +1373,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, finish_shutdown_locked(pollset); gpr_mu_unlock(&pollset->po.mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); } diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index c7189950f0..cab4f7547c 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -976,7 +976,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, GRPC_SCHEDULING_START_BLOCKING_REGION; GRPC_STATS_INC_SYSCALL_POLL(); r = grpc_poll_function(pfds, pfd_count, timeout); - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(); + GRPC_SCHEDULING_END_BLOCKING_REGION; if (GRPC_TRACER_ON(grpc_polling_trace)) { gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); @@ -1040,7 +1040,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, worker list, which means nobody could ask us to re-evaluate polling). */ done: if (!locked) { - queued_work |= grpc_exec_ctx_flush(); + queued_work |= ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); locked = 1; } @@ -1074,7 +1074,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); finish_shutdown(pollset); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * pollset_work. @@ -1083,7 +1083,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, } else if (!grpc_closure_list_empty(pollset->idle_jobs)) { GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } @@ -1110,7 +1110,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { static int poll_deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) return -1; if (deadline == 0) return 0; - grpc_millis n = deadline - grpc_exec_ctx_now(); + grpc_millis n = deadline - ExecCtx::Get()->Now(); if (n < 0) return 0; if (n > INT_MAX) return -1; return (int)n; diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index c10d1e60f0..fe5a0e7e2d 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -27,45 +27,19 @@ thread_local ExecCtx* exec_ctx = nullptr; -ExecCtx::ExecCtx() - : closure_list(GRPC_CLOSURE_LIST_INIT), - active_combiner(nullptr), - last_combiner(nullptr), - flags(GRPC_EXEC_CTX_FLAG_IS_FINISHED), - starting_cpu(gpr_cpu_current_cpu()), - check_ready_to_finish_arg(nullptr), - check_ready_to_finish(nullptr), - now_is_valid(false), - now(0), - last_exec_ctx(exec_ctx) { - exec_ctx = this; -} - -ExecCtx::ExecCtx(uintptr_t fl, bool (*finish_check)(void* arg), - void* finish_check_arg) - : closure_list(GRPC_CLOSURE_LIST_INIT), - active_combiner(nullptr), - last_combiner(nullptr), - flags(fl), - starting_cpu(gpr_cpu_current_cpu()), - check_ready_to_finish_arg(finish_check_arg), - check_ready_to_finish(finish_check), - now_is_valid(false), - now(0), - last_exec_ctx(exec_ctx) { - exec_ctx = this; -} - +ExecCtx::ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { exec_ctx = this; } +ExecCtx::ExecCtx(uintptr_t fl) : flags_(fl) { exec_ctx = this; } ExecCtx::~ExecCtx() { GPR_ASSERT(exec_ctx == this); - grpc_exec_ctx_finish(); - exec_ctx = last_exec_ctx; + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + Flush(); + exec_ctx = last_exec_ctx_; } -bool grpc_exec_ctx_ready_to_finish() { - if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { - if (exec_ctx->check_ready_to_finish(exec_ctx->check_ready_to_finish_arg)) { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; +bool ExecCtx::IsReadyToFinish() { + if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { + if (CheckReadyToFinish()) { + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; return true; } return false; @@ -74,21 +48,7 @@ bool grpc_exec_ctx_ready_to_finish() { } } -bool grpc_never_ready_to_finish(void* arg_ignored) { return false; } - -bool grpc_always_ready_to_finish(void* arg_ignored) { return true; } - -bool grpc_exec_ctx_has_work() { - return exec_ctx->active_combiner != NULL || - !grpc_closure_list_empty(exec_ctx->closure_list); -} - -void grpc_exec_ctx_finish() { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - grpc_exec_ctx_flush(); -} - -static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { +void exec_ctx_run(grpc_closure* closure, grpc_error* error) { #ifndef NDEBUG closure->scheduled = false; if (GRPC_TRACER_ON(grpc_trace_closure)) { @@ -107,13 +67,13 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { GRPC_ERROR_UNREF(error); } -bool grpc_exec_ctx_flush() { +bool ExecCtx::Flush() { bool did_something = 0; GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); for (;;) { - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { - grpc_closure* c = exec_ctx->closure_list.head; - exec_ctx->closure_list.head = exec_ctx->closure_list.tail = NULL; + if (!grpc_closure_list_empty(closure_list_)) { + grpc_closure* c = closure_list_.head; + closure_list_.head = closure_list_.tail = NULL; while (c != NULL) { grpc_closure* next = c->next_data.next; grpc_error* error = c->error_data.error; @@ -125,13 +85,13 @@ bool grpc_exec_ctx_flush() { break; } } - GPR_ASSERT(exec_ctx->active_combiner == NULL); + GPR_ASSERT(combiner_data_.active_combiner == nullptr); GPR_TIMER_END("grpc_exec_ctx_flush", 0); return did_something; } -static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { - grpc_closure_list_append(&exec_ctx->closure_list, closure, error); +void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { + grpc_closure_list_append(exec_ctx->closure_list(), closure, error); } static gpr_timespec @@ -139,7 +99,7 @@ static gpr_timespec // last enum value in // gpr_clock_type -void grpc_exec_ctx_global_init(void) { +void ExecCtx::GlobalInit(void) { for (int i = 0; i < GPR_TIMESPAN; i++) { g_start_time[i] = gpr_now((gpr_clock_type)i); } @@ -147,7 +107,7 @@ void grpc_exec_ctx_global_init(void) { g_start_time[GPR_TIMESPAN] = gpr_time_0(GPR_TIMESPAN); } -void grpc_exec_ctx_global_shutdown(void) {} +void ExecCtx::GlobalShutdown(void) {} static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time[ts.clock_type]); @@ -168,16 +128,6 @@ static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { return (gpr_atm)x; } -grpc_millis grpc_exec_ctx_now() { - if (!exec_ctx->now_is_valid) { - exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); - exec_ctx->now_is_valid = true; - } - return exec_ctx->now; -} - -void grpc_exec_ctx_invalidate_now() { exec_ctx->now_is_valid = false; } - gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock_type) { // special-case infinities as grpc_millis can be 32bit on some platforms @@ -204,6 +154,16 @@ grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) { return timespec_to_atm_round_up(ts); } +grpc_millis ExecCtx::Now() { + if (!now_is_valid_) { + now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); + now_is_valid_ = true; + } + return now_; +} + +ExecCtx* ExecCtx::Get() { return exec_ctx; } + static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index a80bcbbc0d..a71e43e178 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -66,95 +66,81 @@ typedef struct grpc_combiner grpc_combiner; * - Instances are always passed as the first argument to a function that * takes it, and always as a pointer (grpc_exec_ctx is never copied). */ -struct grpc_exec_ctx { - grpc_closure_list closure_list; - /** currently active combiner: updated only via combiner.c */ - grpc_combiner* active_combiner; - /** last active combiner in the active combiner list */ - grpc_combiner* last_combiner; - uintptr_t flags; - unsigned starting_cpu; - void* check_ready_to_finish_arg; - bool (*check_ready_to_finish)(void* arg); - - bool now_is_valid; - grpc_millis now; - const char* creator; -}; - -extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; - -bool grpc_exec_ctx_has_work(); - -/** Flush any work that has been enqueued onto this grpc_exec_ctx. - * Caller must guarantee that no interfering locks are held. - * Returns true if work was performed, false otherwise. */ -bool grpc_exec_ctx_flush(); -/** Finish any pending work for a grpc_exec_ctx. Must be called before - * the instance is destroyed, or work may be lost. */ -void grpc_exec_ctx_finish(); -/** Returns true if we'd like to leave this execution context as soon as - possible: useful for deciding whether to do something more or not depending - on outside context */ -bool grpc_exec_ctx_ready_to_finish(); -/** A finish check that is never ready to finish */ -bool grpc_never_ready_to_finish(void* arg_ignored); -/** A finish check that is always ready to finish */ -bool grpc_always_ready_to_finish(void* arg_ignored); - -void grpc_exec_ctx_global_init(void); - -void grpc_exec_ctx_global_init(void); -void grpc_exec_ctx_global_shutdown(void); - -grpc_millis grpc_exec_ctx_now(); -void grpc_exec_ctx_invalidate_now(); -gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); -grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); -grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); - -inline grpc_exec_ctx make_exec_ctx(grpc_exec_ctx r) { - grpc_exec_ctx_flush(); - return r; -} - class ExecCtx { public: ExecCtx(); - ExecCtx(uintptr_t fl, bool (*finish_check)(void* arg), - void* finish_check_arg); + ExecCtx(uintptr_t fl); ~ExecCtx(); - grpc_closure_list closure_list; - /** currently active combiner: updated only via combiner.c */ - grpc_combiner* active_combiner; - /** last active combiner in the active combiner list */ - grpc_combiner* last_combiner; - uintptr_t flags; - unsigned starting_cpu; - void* check_ready_to_finish_arg; - bool (*check_ready_to_finish)(void* arg); - - bool now_is_valid; - grpc_millis now; - - private: - ExecCtx* last_exec_ctx; -}; + unsigned starting_cpu() const { return starting_cpu_; } + + struct CombinerData { + /* currently active combiner: updated only via combiner.c */ + grpc_combiner* active_combiner; + /* last active combiner in the active combiner list */ + grpc_combiner* last_combiner; + }; + + /** Only to be used by grpc-combiner code */ + CombinerData* combiner_data() { return &combiner_data_; } + + grpc_closure_list* closure_list() { return &closure_list_; } + + bool HasWork() { + return combiner_data_.active_combiner != NULL || + !grpc_closure_list_empty(closure_list_); + } + + /** Flush any work that has been enqueued onto this grpc_exec_ctx. + * Caller must guarantee that no interfering locks are held. + * Returns true if work was performed, false otherwise. */ + bool Flush(); + + /** Returns true if we'd like to leave this execution context as soon as +possible: useful for deciding whether to do something more or not depending +on outside context */ + bool IsReadyToFinish(); -extern thread_local ExecCtx* exec_ctx; + grpc_millis Now(); -/* initializer for grpc_exec_ctx: - * prefer to use GRPC_EXEC_CTX_INIT whenever possible */ -#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \ - make_exec_ctx(grpc_exec_ctx{GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, \ - gpr_cpu_current_cpu(), finish_check_arg, \ - finish_check, false, 0, __PRETTY_FUNCTION__}) + void InvalidateNow() { now_is_valid_ = false; } -/* initialize an execution context at the top level of an API call into grpc - (this is safe to use elsewhere, though possibly not as efficient) */ -#define GRPC_EXEC_CTX_INIT \ - GRPC_EXEC_CTX_INITIALIZER(GRPC_EXEC_CTX_FLAG_IS_FINISHED, NULL, NULL) + void SetNow(grpc_millis new_val) { + now_ = new_val; + now_is_valid_ = true; + } + + uintptr_t flags() { return flags_; } + + /** Finish any pending work for a grpc_exec_ctx. Must be called before + * the instance is destroyed, or work may be lost. */ + void Finish(); + + static void GlobalInit(void); + + static void GlobalShutdown(void); + + static ExecCtx* Get(); + + protected: + virtual bool CheckReadyToFinish() { return false; } + + grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; + CombinerData combiner_data_ = {nullptr, nullptr}; + uintptr_t flags_; + unsigned starting_cpu_ = gpr_cpu_current_cpu(); + + bool now_is_valid_ = false; + grpc_millis now_ = 0; + + ExecCtx* last_exec_ctx_ = Get(); +}; + +extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; + +gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index f764d915ff..bf8805a2cd 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -78,7 +78,7 @@ static size_t run_closures(grpc_closure_list list) { GRPC_ERROR_UNREF(error); c = next; n++; - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } return n; @@ -145,7 +145,7 @@ static void executor_thread(void* arg) { thread_state* ts = (thread_state*)arg; gpr_tls_set(&g_this_thread_state, (intptr_t)ts); - ExecCtx _local_exec_ctx(0, grpc_never_ready_to_finish, NULL); + ExecCtx _local_exec_ctx; size_t subtract_depth = 0; for (;;) { @@ -175,10 +175,9 @@ static void executor_thread(void* arg) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); } - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); subtract_depth = run_closures(exec); } - grpc_exec_ctx_finish(); } static void executor_push(grpc_closure* closure, grpc_error* error, @@ -201,12 +200,12 @@ static void executor_push(grpc_closure* closure, grpc_error* error, gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p inline", closure); #endif } - grpc_closure_list_append(&exec_ctx->closure_list, closure, error); + grpc_closure_list_append(ExecCtx::Get()->closure_list(), closure, error); return; } thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state); if (ts == NULL) { - ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)]; + ts = &g_thread_state[GPR_HASH_POINTER(ExecCtx::Get(), cur_thread_count)]; } else { GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(); } diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 8f15f5e6cc..1686bf2872 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -46,7 +46,7 @@ static DWORD deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return INFINITE; } - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); if (deadline < now) return 0; grpc_millis timeout = deadline - now; if (timeout > std::numeric_limits::max()) return INFINITE; @@ -65,7 +65,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key, &overlapped, deadline_to_millis_timeout(deadline)); - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } @@ -118,16 +118,16 @@ void grpc_iocp_flush(void) { do { work_status = grpc_iocp_work(GRPC_MILLIS_INF_PAST); - } while (work_status == GRPC_IOCP_WORK_KICK || grpc_exec_ctx_flush()); + } while (work_status == GRPC_IOCP_WORK_KICK || ExecCtx::Get()->Flush()); } void grpc_iocp_shutdown(void) { ExecCtx _local_exec_ctx; while (gpr_atm_acq_load(&g_custom_events)) { grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + GPR_ASSERT(CloseHandle(g_iocp)); } diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 01d9964cc8..a1add4a303 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -49,7 +49,7 @@ void grpc_iomgr_init() { g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); - grpc_exec_ctx_global_init(); + ExecCtx::GlobalInit(); grpc_executor_init(); grpc_timer_list_init(); g_root_object.next = g_root_object.prev = &g_root_object; @@ -98,11 +98,10 @@ void grpc_iomgr_shutdown() { } last_warning_time = gpr_now(GPR_CLOCK_REALTIME); } - exec_ctx->now_is_valid = true; - exec_ctx->now = GRPC_MILLIS_INF_FUTURE; + ExecCtx::Get()->SetNow(GRPC_MILLIS_INF_FUTURE); if (grpc_timer_check(NULL) == GRPC_TIMERS_FIRED) { gpr_mu_unlock(&g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_iomgr_platform_flush(); gpr_mu_lock(&g_mu); continue; @@ -137,14 +136,14 @@ void grpc_iomgr_shutdown() { gpr_mu_unlock(&g_mu); grpc_timer_list_shutdown(); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* ensure all threads have left g_mu */ gpr_mu_lock(&g_mu); gpr_mu_unlock(&g_mu); grpc_iomgr_platform_shutdown(); - grpc_exec_ctx_global_shutdown(); + ExecCtx::GlobalShutdown(); grpc_network_status_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index 4dda970286..2ab414252a 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -34,7 +34,6 @@ void grpc_iomgr_platform_init(void) { grpc_register_tracer(&grpc_tcp_trace); grpc_executor_set_threading(false); g_init_thread = gpr_thd_currentid(); - grpc_exec_ctx_finish(); } void grpc_iomgr_platform_flush(void) {} void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc index 97e448fb32..feef65cc34 100644 --- a/src/core/lib/iomgr/load_file.cc +++ b/src/core/lib/iomgr/load_file.cc @@ -73,6 +73,6 @@ end: GRPC_ERROR_UNREF(error); error = error_out; } - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; return error; } diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index 7028876297..a68ad4a6e3 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -124,7 +124,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, GRPC_UV_ASSERT_SAME_THREAD(); gpr_mu_unlock(&grpc_polling_mu); if (grpc_pollset_work_run_loop) { - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); if (deadline >= now) { timeout = deadline - now; } else { @@ -143,7 +143,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, } } if (!grpc_closure_list_empty(exec_ctx->closure_list)) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } gpr_mu_lock(&grpc_polling_mu); return GRPC_ERROR_NONE; diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index dd019b1ec3..5ff3e7cb3a 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -129,7 +129,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, g_active_poller = &worker; gpr_mu_unlock(&grpc_polling_mu); grpc_iocp_work(deadline); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); pollset->is_iocp_worker = 0; g_active_poller = NULL; @@ -160,10 +160,10 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, while (!worker.kicked) { if (gpr_cv_wait(&worker.cv, &grpc_polling_mu, grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); break; } - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); } } else { pollset->kicked_without_pollers = 0; @@ -171,7 +171,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, done: if (!grpc_closure_list_empty(exec_ctx->closure_list)) { gpr_mu_unlock(&grpc_polling_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); } if (added_worker) { diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 3795c3f75e..80a1a45cc0 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -81,7 +81,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; if (s != 0) { /* Retry if well-known service name is recognized */ @@ -90,7 +90,7 @@ static grpc_error* blocking_resolve_address_impl( if (strcmp(port, svc[i][0]) == 0) { GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, svc[i][1], &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; break; } } diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc index 038926af07..ffd70c4f35 100644 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ b/src/core/lib/iomgr/resolve_address_uv.cc @@ -131,7 +131,7 @@ static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, original error probably has more interesting information */ error = handle_addrinfo_result(status, res, r->addresses); GRPC_CLOSURE_SCHED(r->on_done, error); - grpc_exec_ctx_finish(); + gpr_free(r->hints); gpr_free(r->host); gpr_free(r->port); diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index 15f3fd9f1a..4e2bc7b5ca 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -87,7 +87,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; if (s != 0) { error = GRPC_WSA_ERROR(WSAGetLastError(), "getaddrinfo"); goto done; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index b58ae1cb21..8fee585f4b 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -624,7 +624,6 @@ void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { void grpc_resource_quota_unref(grpc_resource_quota* resource_quota) { ExecCtx _local_exec_ctx; grpc_resource_quota_unref_internal(resource_quota); - grpc_exec_ctx_finish(); } grpc_resource_quota* grpc_resource_quota_ref_internal( @@ -656,7 +655,6 @@ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, (gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size)); GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_SCHED(&a->closure, GRPC_ERROR_NONE); - grpc_exec_ctx_finish(); } size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) { diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 2a127993a2..7454b01445 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -105,11 +105,10 @@ static void uv_tc_on_connect(uv_connect_t* req, int status) { } done = (--connect->refs == 0); if (done) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); uv_tcp_connect_cleanup(connect); } GRPC_CLOSURE_SCHED(closure, error); - grpc_exec_ctx_finish(); } static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 697281d8b1..de3dabd7fc 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -130,7 +130,7 @@ static void run_poller(void* bp, grpc_error* error_ignored) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); } gpr_mu_lock(p->pollset_mu); - grpc_millis deadline = grpc_exec_ctx_now() + 13 * GPR_MS_PER_SEC; + grpc_millis deadline = ExecCtx::Get()->Now() + 13 * GPR_MS_PER_SEC; GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 8d5387fe6e..9db2cbe58d 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -142,7 +142,6 @@ static void handle_close_callback(uv_handle_t* handle) { if (sp->server->open_ports == 0 && sp->server->shutdown) { finish_shutdown(sp->server); } - grpc_exec_ctx_finish(); } static void close_listener(grpc_tcp_listener* sp) { @@ -177,14 +176,8 @@ void grpc_tcp_server_unref(grpc_tcp_server* s) { /* Complete shutdown_starting work before destroying. */ ExecCtx _local_exec_ctx; GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); - if (exec_ctx == NULL) { - grpc_exec_ctx_flush(); - tcp_server_destroy(s); - grpc_exec_ctx_finish(); - } else { - grpc_exec_ctx_finish(); - tcp_server_destroy(s); - } + ExecCtx::Get()->Flush(); + tcp_server_destroy(s); } } @@ -255,7 +248,6 @@ static void on_connect(uv_stream_t* server, int status) { } else { sp->has_pending_connection = true; } - grpc_exec_ctx_finish(); } static grpc_error* add_socket_to_server(grpc_tcp_server* s, uv_tcp_t* handle, diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 571c1d6f9a..3ea9674840 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -115,7 +115,6 @@ static void uv_close_callback(uv_handle_t* handle) { ExecCtx _local_exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; TCP_UNREF(tcp, "destroy"); - grpc_exec_ctx_finish(); } static grpc_slice alloc_read_slice(grpc_resource_user* resource_user) { @@ -130,7 +129,6 @@ static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, (void)suggested_size; buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slice); buf->len = GRPC_SLICE_LENGTH(tcp->read_slice); - grpc_exec_ctx_finish(); } static void read_callback(uv_stream_t* stream, ssize_t nread, @@ -174,7 +172,6 @@ static void read_callback(uv_stream_t* stream, ssize_t nread, error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"); } GRPC_CLOSURE_SCHED(cb, error); - grpc_exec_ctx_finish(); } static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, @@ -224,7 +221,6 @@ static void write_callback(uv_write_t* req, int status) { grpc_resource_user_free(tcp->resource_user, sizeof(uv_buf_t) * tcp->write_slices->count); GRPC_CLOSURE_SCHED(cb, error); - grpc_exec_ctx_finish(); } static void uv_endpoint_write(grpc_endpoint* ep, @@ -384,7 +380,6 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, uv_unref((uv_handle_t*)handle); #endif - grpc_exec_ctx_finish(); return &tcp->base; } diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index e7fe12b07b..d5e6066f35 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -249,7 +249,7 @@ void grpc_timer_list_init() { g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; gpr_mu_init(&g_shared_mutables.mu); - g_shared_mutables.min_timer = grpc_exec_ctx_now(); + g_shared_mutables.min_timer = ExecCtx::Get()->Now(); gpr_tls_init(&g_last_seen_min_timer); gpr_tls_set(&g_last_seen_min_timer, 0); grpc_register_tracer(&grpc_timer_trace); @@ -341,7 +341,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, - deadline, grpc_exec_ctx_now(), closure, closure->cb); + deadline, ExecCtx::Get()->Now(), closure, closure->cb); } if (!g_shared_mutables.initialized) { @@ -354,7 +354,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, gpr_mu_lock(&shard->mu); timer->pending = true; - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); if (deadline <= now) { timer->pending = false; GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); @@ -607,7 +607,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, grpc_timer_check_result grpc_timer_check(grpc_millis* next) { // prelude - grpc_millis now = grpc_exec_ctx_now(); + grpc_millis now = ExecCtx::Get()->Now(); /* fetch from a thread-local first: this avoids contention on a globally mutable cacheline in the common case */ diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 499fc73748..69adb673d8 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -101,7 +101,6 @@ void grpc_timer_manager_tick() { ExecCtx _local_exec_ctx; grpc_millis next = GRPC_MILLIS_INF_FUTURE; grpc_timer_check(&next); - grpc_exec_ctx_finish(); } static void run_some_timers() { @@ -126,7 +125,7 @@ static void run_some_timers() { if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -179,7 +178,7 @@ static bool wait_until(grpc_millis next) { g_timed_waiter_deadline = next; if (GRPC_TRACER_ON(grpc_timer_check_trace)) { - grpc_millis wait_time = next - grpc_exec_ctx_now(); + grpc_millis wait_time = next - ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -224,7 +223,7 @@ static bool wait_until(grpc_millis next) { static void timer_main_loop() { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); // check timer state, updates next to the next time to run a check switch (grpc_timer_check(&next)) { case GRPC_TIMERS_FIRED: @@ -274,9 +273,9 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - ExecCtx _local_exec_ctx(0, grpc_never_ready_to_finish, NULL); + ExecCtx _local_exec_ctx; timer_main_loop(); - grpc_exec_ctx_finish(); + timer_thread_cleanup((completed_thread*)completed_thread_ptr); } diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 94601d99af..6edd4169f1 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -51,7 +51,6 @@ void run_expired_timer(uv_timer_t* handle) { timer->pending = 0; GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); stop_uv_timer(handle); - grpc_exec_ctx_finish(); } void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, @@ -60,13 +59,13 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, uv_timer_t* uv_timer; GRPC_UV_ASSERT_SAME_THREAD(); timer->closure = closure; - if (deadline <= grpc_exec_ctx_now()) { + if (deadline <= ExecCtx::Get()->Now()) { timer->pending = 0; GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); return; } timer->pending = 1; - timeout = (uint64_t)(deadline - grpc_exec_ctx_now()); + timeout = (uint64_t)(deadline - ExecCtx::Get()->Now()); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); uv_timer->data = timer; diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 1d708c997c..9b58b3657f 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -57,7 +57,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials_unref(ctx->creds); ctx->creds = grpc_call_credentials_ref(creds); } - grpc_exec_ctx_finish(); + return GRPC_CALL_OK; } @@ -95,7 +95,6 @@ void grpc_client_security_context_destroy(void* ctx) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); - grpc_exec_ctx_finish(); } /* --- grpc_server_security_context --- */ diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 20c4ae70fb..6a272653f8 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -74,7 +74,6 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) { GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); ExecCtx _local_exec_ctx; grpc_channel_credentials_unref(creds); - grpc_exec_ctx_finish(); } grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { @@ -97,7 +96,6 @@ void grpc_call_credentials_release(grpc_call_credentials* creds) { GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); ExecCtx _local_exec_ctx; grpc_call_credentials_unref(creds); - grpc_exec_ctx_finish(); } bool grpc_call_credentials_get_request_metadata( @@ -213,7 +211,6 @@ void grpc_server_credentials_release(grpc_server_credentials* creds) { GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); ExecCtx _local_exec_ctx; grpc_server_credentials_unref(creds); - grpc_exec_ctx_finish(); } grpc_security_status grpc_server_credentials_create_security_connector( diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 897b9d7520..03ec4bc3b3 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -114,13 +114,13 @@ static int is_stack_running_on_compute_engine() { grpc_resource_quota_create("google_default_credentials"); grpc_httpcli_get( &context, &detector.pollent, resource_quota, &request, - grpc_exec_ctx_now() + max_detection_delay, + ExecCtx::Get()->Now() + max_detection_delay, GRPC_CLOSURE_CREATE(on_compute_engine_detection_http_response, &detector, grpc_schedule_on_exec_ctx), &detector.response); grpc_resource_quota_unref_internal(resource_quota); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ @@ -144,7 +144,7 @@ static int is_stack_running_on_compute_engine() { grpc_pollset_shutdown(grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); g_polling_mu = NULL; - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); grpc_http_response_destroy(&detector.response); @@ -285,7 +285,7 @@ end: } else { GRPC_ERROR_UNREF(error); } - grpc_exec_ctx_finish(); + return result; } @@ -299,7 +299,6 @@ void grpc_flush_cached_google_default_credentials(void) { } compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); - grpc_exec_ctx_finish(); } /* -- Well known credentials path. -- */ diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 07938ec67e..4d9da0cbe3 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -77,6 +77,6 @@ grpc_call_credentials* grpc_google_iam_credentials_create( grpc_slice_from_copied_string(authority_selector)); grpc_credentials_mdelem_array_add(&c->md_array, md); GRPC_MDELEM_UNREF(md); - grpc_exec_ctx_finish(); + return &c->base; } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 1d43ee6e03..ccc3f4aeed 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -185,6 +185,6 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_auth_json_key_create_from_string(json_key), token_lifetime); - grpc_exec_ctx_finish(); + return creds; } diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index eaa2078787..5246e1f985 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -358,7 +358,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( ctx->signed_data = grpc_slice_from_copied_buffer(signed_jwt, signed_jwt_len); ctx->user_data = user_data; ctx->user_cb = cb; - grpc_exec_ctx_finish(); + return ctx; } @@ -702,7 +702,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) { resource_quota = grpc_resource_quota_create("jwt_verifier"); grpc_httpcli_get( &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, - grpc_exec_ctx_now() + grpc_jwt_verifier_max_delay, + ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, GRPC_CLOSURE_CREATE(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx), &ctx->responses[HTTP_RESPONSE_KEYS]); grpc_resource_quota_unref_internal(resource_quota); @@ -828,7 +828,7 @@ static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); grpc_httpcli_get(&ctx->verifier->http_ctx, &ctx->pollent, resource_quota, - &req, grpc_exec_ctx_now() + grpc_jwt_verifier_max_delay, + &req, ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, http_cb, &ctx->responses[rsp_idx]); grpc_resource_quota_unref_internal(resource_quota); gpr_free(req.host); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index bae9692938..b653705609 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -216,8 +216,9 @@ static void on_oauth2_token_fetcher_http_response(void* user_data, gpr_mu_lock(&c->mu); c->token_fetch_pending = false; c->access_token_md = GRPC_MDELEM_REF(access_token_md); - c->token_expiration = - status == GRPC_CREDENTIALS_OK ? grpc_exec_ctx_now() + token_lifetime : 0; + c->token_expiration = status == GRPC_CREDENTIALS_OK + ? ExecCtx::Get()->Now() + token_lifetime + : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; c->pending_requests = NULL; @@ -255,7 +256,7 @@ static bool oauth2_token_fetcher_get_request_metadata( grpc_mdelem cached_access_token_md = GRPC_MDNULL; gpr_mu_lock(&c->mu); if (!GRPC_MDISNULL(c->access_token_md) && - (c->token_expiration - grpc_exec_ctx_now() > refresh_threshold)) { + (c->token_expiration - ExecCtx::Get()->Now() > refresh_threshold)) { cached_access_token_md = GRPC_MDELEM_REF(c->access_token_md); } if (!GRPC_MDISNULL(cached_access_token_md)) { @@ -287,7 +288,7 @@ static bool oauth2_token_fetcher_get_request_metadata( c->fetch_func(grpc_credentials_metadata_request_create(creds), &c->httpcli_context, &c->pollent, on_oauth2_token_fetcher_http_response, - grpc_exec_ctx_now() + refresh_threshold); + ExecCtx::Get()->Now() + refresh_threshold); } return false; } @@ -517,7 +518,7 @@ grpc_call_credentials* grpc_access_token_credentials_create( c->access_token_md = grpc_mdelem_from_slices( grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(token_md_value)); - grpc_exec_ctx_finish(); + gpr_free(token_md_value); return &c->base; } diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 064666a7d0..025d024617 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -116,9 +116,8 @@ static void plugin_md_request_metadata_ready(void* request, grpc_status_code status, const char* error_details) { /* called from application code */ - ExecCtx _local_exec_ctx( - GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, - NULL, NULL); + ExecCtx _local_exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { @@ -141,7 +140,6 @@ static void plugin_md_request_metadata_ready(void* request, r->creds, r); } gpr_free(r); - grpc_exec_ctx_finish(); } static bool plugin_get_request_metadata(grpc_call_credentials* creds, diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index cb20401409..4ed2ec55bd 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -266,7 +266,6 @@ static void on_handshake_next_done_grpc_wrapper( } else { gpr_mu_unlock(&h->mu); } - grpc_exec_ctx_finish(); } static grpc_error* do_handshaker_next_locked( diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 5f21a2933b..86817076f8 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -141,7 +141,6 @@ static void on_md_processing_done( } grpc_metadata_array_destroy(&calld->md); GRPC_CALL_STACK_UNREF(calld->owning_call, "server_auth_metadata"); - grpc_exec_ctx_finish(); } static void cancel_call(void* arg, grpc_error* error) { diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 3b3b2e4f05..6e1554d471 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -69,7 +69,6 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { void grpc_slice_unref(grpc_slice slice) { ExecCtx _local_exec_ctx; grpc_slice_unref_internal(slice); - grpc_exec_ctx_finish(); } /* grpc_slice_from_static_string support structure - a refcount that does diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 6774269972..4bc54c303f 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -75,7 +75,6 @@ void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(sb); - grpc_exec_ctx_finish(); } uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { @@ -175,7 +174,6 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { ExecCtx _local_exec_ctx; grpc_slice_buffer_reset_and_unref_internal(sb); - grpc_exec_ctx_finish(); } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 395ffd393c..7aee100f3f 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -51,7 +51,7 @@ static void alarm_unref(grpc_alarm* alarm) { if (alarm->cq != NULL) { GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); } - grpc_exec_ctx_finish(); + gpr_free(alarm); } } @@ -126,13 +126,11 @@ void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, GPR_ASSERT(grpc_cq_begin_op(cq, tag)); grpc_timer_init(&alarm->alarm, grpc_timespec_to_millis_round_up(deadline), &alarm->on_alarm); - grpc_exec_ctx_finish(); } void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { ExecCtx _local_exec_ctx; grpc_timer_cancel(&alarm->alarm); - grpc_exec_ctx_finish(); } void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved) { diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index f3c10797f3..6a9b13bb41 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -78,7 +78,6 @@ void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { break; } gpr_free(bb); - grpc_exec_ctx_finish(); } size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) { diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index fb66829baa..9a9e26ecdc 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -70,7 +70,7 @@ int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, reader->current.index = 0; break; } - grpc_exec_ctx_finish(); + return 1; } @@ -118,6 +118,6 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) { grpc_slice_unref_internal(in_slice); GPR_ASSERT(bytes_read <= input_size); } - grpc_exec_ctx_finish(); + return out_slice; } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 5e1c0badd0..bbb7a39e29 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -595,7 +595,7 @@ void grpc_call_unref(grpc_call* c) { grpc_call_combiner_set_notify_on_cancel(&c->call_combiner, NULL); } GRPC_CALL_INTERNAL_UNREF(c, "destroy"); - grpc_exec_ctx_finish(); + GPR_TIMER_END("grpc_call_unref", 0); } @@ -604,7 +604,7 @@ grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { GPR_ASSERT(!reserved); ExecCtx _local_exec_ctx; cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); - grpc_exec_ctx_finish(); + return GRPC_CALL_OK; } @@ -659,7 +659,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, 4, (c, (int)status, description, reserved)); GPR_ASSERT(reserved == NULL); cancel_with_status(c, STATUS_FROM_API_OVERRIDE, status, description); - grpc_exec_ctx_finish(); + return GRPC_CALL_OK; } @@ -2048,7 +2048,6 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, err = call_start_batch(call, ops, nops, tag, 0); } - grpc_exec_ctx_finish(); return err; } diff --git a/src/core/lib/surface/call_details.cc b/src/core/lib/surface/call_details.cc index 01b19abefb..03ce7f88fb 100644 --- a/src/core/lib/surface/call_details.cc +++ b/src/core/lib/surface/call_details.cc @@ -37,5 +37,4 @@ void grpc_call_details_destroy(grpc_call_details* cd) { ExecCtx _local_exec_ctx; grpc_slice_unref_internal(cd->method); grpc_slice_unref_internal(cd->host); - grpc_exec_ctx_finish(); } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index dc1fc1632e..7725351f74 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -252,7 +252,6 @@ void grpc_channel_get_info(grpc_channel* channel, grpc_channel_element* elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); elem->filter->get_channel_info(elem, channel_info); - grpc_exec_ctx_finish(); } static grpc_call* grpc_channel_create_call_internal( @@ -305,7 +304,7 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, grpc_timespec_to_millis_round_up(deadline)); - grpc_exec_ctx_finish(); + return call; } @@ -344,7 +343,7 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, rc->next = channel->registered_calls; channel->registered_calls = rc; gpr_mu_unlock(&channel->registered_call_mu); - grpc_exec_ctx_finish(); + return rc; } @@ -370,7 +369,7 @@ grpc_call* grpc_channel_create_registered_call( channel, parent_call, propagation_mask, completion_queue, NULL, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), grpc_timespec_to_millis_round_up(deadline)); - grpc_exec_ctx_finish(); + return call; } @@ -416,8 +415,6 @@ void grpc_channel_destroy(grpc_channel* channel) { elem->filter->start_transport_op(elem, op); GRPC_CHANNEL_INTERNAL_UNREF(channel, "channel"); - - grpc_exec_ctx_finish(); } grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel) { diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index 0966a8d967..06cdbf6c73 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -60,5 +60,4 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, op->bind_pollset = grpc_cq_pollset(cq); GPR_ASSERT(grpc_cq_begin_op(cq, tag)); top_elem->filter->start_transport_op(top_elem, op); - grpc_exec_ctx_finish(); } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index b69d40534d..0b0a8d070d 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -124,7 +124,7 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset, while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline_ts)) ; - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); if (&w == npp->root) { npp->root = w.next; if (&w == npp->root) { @@ -371,7 +371,6 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, gpr_mu_unlock(cq->mu); GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } - grpc_exec_ctx_finish(); } gpr_tls_set(&g_cached_event, (intptr_t)0); gpr_tls_set(&g_cached_cq, (intptr_t)0); @@ -412,8 +411,6 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(); } - grpc_exec_ctx_finish(); - if (c) { gpr_atm_no_barrier_fetch_add(&q->num_queue_items, -1); } @@ -445,7 +442,6 @@ grpc_completion_queue* grpc_completion_queue_create_internal( ExecCtx _local_exec_ctx; GRPC_STATS_INC_CQS_CREATED(); - grpc_exec_ctx_finish(); cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + @@ -639,9 +635,9 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_next(=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_next(cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 6, (cq, tag, errmsg, done, done_arg, storage)); if (GRPC_TRACER_ON(grpc_trace_operation_failures) && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); @@ -726,9 +722,9 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_pluck(=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_pluck(cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 6, (cq, tag, errmsg, done, done_arg, storage)); if (GRPC_TRACER_ON(grpc_trace_operation_failures) && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); @@ -794,31 +790,40 @@ typedef struct { bool first_loop; } cq_is_finished_arg; -static bool cq_is_next_finished(void* arg) { - cq_is_finished_arg* a = (cq_is_finished_arg*)arg; - grpc_completion_queue* cq = a->cq; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == NULL); +class ExecCtxNext : public ExecCtx { + public: + ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} - gpr_atm current_last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); + bool CheckReadyToFinish() override { + cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + grpc_completion_queue* cq = a->cq; + cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + GPR_ASSERT(a->stolen_completion == NULL); - if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { - a->last_seen_things_queued_ever = + gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - /* Pop a cq_completion from the queue. Returns NULL if the queue is empty - * might return NULL in some cases even if the queue is not empty; but - * that - * is ok and doesn't affect correctness. Might effect the tail latencies a - * bit) */ - a->stolen_completion = cq_event_queue_pop(&cqd->queue); - if (a->stolen_completion != NULL) { - return true; + if (current_last_seen_things_queued_ever != + a->last_seen_things_queued_ever) { + a->last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); + + /* Pop a cq_completion from the queue. Returns NULL if the queue is empty + * might return NULL in some cases even if the queue is not empty; but + * that + * is ok and doesn't affect correctness. Might effect the tail latencies a + * bit) */ + a->stolen_completion = cq_event_queue_pop(&cqd->queue); + if (a->stolen_completion != NULL) { + return true; + } } + return !a->first_loop && a->deadline < ExecCtx::Get()->Now(); } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(); -} + + private: + void* check_ready_to_finish_arg_; +}; #ifndef NDEBUG static void dump_pending_tags(grpc_completion_queue* cq) { @@ -873,7 +878,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, NULL, NULL, true}; - ExecCtx _local_exec_ctx(0, cq_is_next_finished, &is_finished_arg); + ExecCtxNext _local_exec_ctx(&is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; @@ -923,7 +928,8 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, break; } - if (!is_finished_arg.first_loop && grpc_exec_ctx_now() >= deadline_millis) { + if (!is_finished_arg.first_loop && + ExecCtx::Get()->Now() >= deadline_millis) { memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; dump_pending_tags(cq); @@ -959,7 +965,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); GRPC_CQ_INTERNAL_UNREF(cq, "next"); - grpc_exec_ctx_finish(); + GPR_ASSERT(is_finished_arg.stolen_completion == NULL); GPR_TIMER_END("grpc_completion_queue_next", 0); @@ -1039,37 +1045,46 @@ static void del_plucker(grpc_completion_queue* cq, void* tag, GPR_UNREACHABLE_CODE(return ); } -static bool cq_is_pluck_finished(void* arg) { - cq_is_finished_arg* a = (cq_is_finished_arg*)arg; - grpc_completion_queue* cq = a->cq; - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); +class ExecCtxPluck : public ExecCtx { + public: + ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} - GPR_ASSERT(a->stolen_completion == NULL); - gpr_atm current_last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); - if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { - gpr_mu_lock(cq->mu); - a->last_seen_things_queued_ever = + bool CheckReadyToFinish() override { + cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + grpc_completion_queue* cq = a->cq; + cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + + GPR_ASSERT(a->stolen_completion == NULL); + gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - grpc_cq_completion* c; - grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != - &cqd->completed_head) { - if (c->tag == a->tag) { - prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); - if (c == cqd->completed_tail) { - cqd->completed_tail = prev; + if (current_last_seen_things_queued_ever != + a->last_seen_things_queued_ever) { + gpr_mu_lock(cq->mu); + a->last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); + grpc_cq_completion* c; + grpc_cq_completion* prev = &cqd->completed_head; + while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != + &cqd->completed_head) { + if (c->tag == a->tag) { + prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); + if (c == cqd->completed_tail) { + cqd->completed_tail = prev; + } + gpr_mu_unlock(cq->mu); + a->stolen_completion = c; + return true; } - gpr_mu_unlock(cq->mu); - a->stolen_completion = c; - return true; + prev = c; } - prev = c; + gpr_mu_unlock(cq->mu); } - gpr_mu_unlock(cq->mu); + return !a->first_loop && a->deadline < ExecCtx::Get()->Now(); } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(); -} + + private: + void* check_ready_to_finish_arg_; +}; static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved) { @@ -1106,7 +1121,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, NULL, tag, true}; - ExecCtx _local_exec_ctx(0, cq_is_pluck_finished, &is_finished_arg); + ExecCtxPluck _local_exec_ctx(&is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cq->mu); @@ -1153,7 +1168,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, dump_pending_tags(cq); break; } - if (!is_finished_arg.first_loop && grpc_exec_ctx_now() >= deadline_millis) { + if (!is_finished_arg.first_loop && + ExecCtx::Get()->Now() >= deadline_millis) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); memset(&ret, 0, sizeof(ret)); @@ -1182,7 +1198,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, done: GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); GRPC_CQ_INTERNAL_UNREF(cq, "pluck"); - grpc_exec_ctx_finish(); + GPR_ASSERT(is_finished_arg.stolen_completion == NULL); GPR_TIMER_END("grpc_completion_queue_pluck", 0); @@ -1238,7 +1254,7 @@ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); cq->vtable->shutdown(cq); - grpc_exec_ctx_finish(); + GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } @@ -1249,7 +1265,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { ExecCtx _local_exec_ctx; GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); - grpc_exec_ctx_finish(); + GPR_TIMER_END("grpc_completion_queue_destroy", 0); } diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 66c8c3b6da..20e17a7f60 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -168,14 +168,14 @@ void grpc_init(void) { grpc_iomgr_start(); } gpr_mu_unlock(&g_init_mu); - grpc_exec_ctx_finish(); + GRPC_API_TRACE("grpc_init(void)", 0, ()); } void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); - ExecCtx _local_exec_ctx(0, grpc_never_ready_to_finish, NULL); + ExecCtx _local_exec_ctx; gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_executor_shutdown(); @@ -194,7 +194,6 @@ void grpc_shutdown(void) { grpc_stats_shutdown(); } gpr_mu_unlock(&g_init_mu); - grpc_exec_ctx_finish(); } int grpc_is_initialized(void) { diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 5cd8c1fd89..da081e68cb 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -169,6 +169,6 @@ grpc_channel* grpc_lame_client_channel_create(const char* target, auto chand = reinterpret_cast(elem->channel_data); chand->error_code = error_code; chand->error_message = error_message; - grpc_exec_ctx_finish(); + return channel; } diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 6e3ce005a2..0d4435d556 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -1047,8 +1047,6 @@ void grpc_server_start(grpc_server* server) { GRPC_CLOSURE_CREATE(start_listeners, server, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)), GRPC_ERROR_NONE); - - grpc_exec_ctx_finish(); } void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, @@ -1188,7 +1186,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, NULL, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); gpr_mu_unlock(&server->mu_global); - goto done; + return; } server->shutdown_tags = (shutdown_tag*)gpr_realloc( server->shutdown_tags, @@ -1198,7 +1196,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, sdt->cq = cq; if (gpr_atm_acq_load(&server->shutdown_flag)) { gpr_mu_unlock(&server->mu_global); - goto done; + return; } server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME); @@ -1225,9 +1223,6 @@ void grpc_server_shutdown_and_notify(grpc_server* server, channel_broadcaster_shutdown(&broadcaster, true /* send_goaway */, GRPC_ERROR_NONE); - -done: - grpc_exec_ctx_finish(); } void grpc_server_cancel_all_calls(grpc_server* server) { @@ -1243,7 +1238,6 @@ void grpc_server_cancel_all_calls(grpc_server* server) { channel_broadcaster_shutdown( &broadcaster, false /* send_goaway */, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls")); - grpc_exec_ctx_finish(); } void grpc_server_destroy(grpc_server* server) { @@ -1265,7 +1259,6 @@ void grpc_server_destroy(grpc_server* server) { gpr_mu_unlock(&server->mu_global); server_unref(server); - grpc_exec_ctx_finish(); } void grpc_server_add_listener(grpc_server* server, void* arg, @@ -1368,7 +1361,7 @@ grpc_call_error grpc_server_request_call( rc->initial_metadata = initial_metadata; error = queue_call_request(server, cq_idx, rc); done: - grpc_exec_ctx_finish(); + return error; } @@ -1425,7 +1418,7 @@ grpc_call_error grpc_server_request_registered_call( rc->data.registered.optional_payload = optional_payload; error = queue_call_request(server, cq_idx, rc); done: - grpc_exec_ctx_finish(); + return error; } diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 47d65870d1..4e279b4d94 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -79,7 +79,7 @@ grpc_millis BdpEstimator::CompletePing() { } ping_state_ = PingState::UNSCHEDULED; accumulator_ = 0; - return grpc_exec_ctx_now() + inter_ping_delay_; + return ExecCtx::Get()->Now() + inter_ping_delay_; } } // namespace grpc_core diff --git a/src/core/lib/transport/status_conversion.cc b/src/core/lib/transport/status_conversion.cc index fd7764f2db..61470b8c78 100644 --- a/src/core/lib/transport/status_conversion.cc +++ b/src/core/lib/transport/status_conversion.cc @@ -46,8 +46,8 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, case GRPC_HTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ - return grpc_exec_ctx_now() > deadline ? GRPC_STATUS_DEADLINE_EXCEEDED - : GRPC_STATUS_CANCELLED; + return ExecCtx::Get()->Now() > deadline ? GRPC_STATUS_DEADLINE_EXCEEDED + : GRPC_STATUS_CANCELLED; case GRPC_HTTP2_ENHANCE_YOUR_CALM: return GRPC_STATUS_RESOURCE_EXHAUSTED; case GRPC_HTTP2_INADEQUATE_SECURITY: diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 6f31bd07f9..ca80a7404d 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -62,7 +62,7 @@ void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { void grpc_stream_unref(grpc_stream_refcount* refcount) { #endif if (gpr_unref(&refcount->refs)) { - if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { + if (ExecCtx::Get()->flags() & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { /* Ick. The thread we're running on MAY be owned (indirectly) by a call-stack. If that's the case, destroying the call-stack MAY try to destroy the diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 79e4aee4e2..0bcfac2845 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -73,7 +73,6 @@ ChannelArguments::~ChannelArguments() { it->value.pointer.vtable->destroy(it->value.pointer.p); } } - grpc_exec_ctx_finish(); } void ChannelArguments::Swap(ChannelArguments& other) { @@ -106,7 +105,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { replaced = true; } } - grpc_exec_ctx_finish(); + if (!replaced) { args_.push_back(mutator_arg); } diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 4e32298da4..739ab86bb2 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -34,19 +34,18 @@ static void test_constant_backoff(void) { min_connect_timeout, max_backoff); ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == initial_backoff); for (int i = 0; i < 10000; i++) { next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == initial_backoff); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(); } static void test_min_connect(void) { @@ -62,13 +61,12 @@ static void test_min_connect(void) { grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_exec_ctx_now() == + GPR_ASSERT(next.current_deadline - ExecCtx::Get()->Now() == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_exec_ctx_now() == + GPR_ASSERT(next.next_attempt_start_time - ExecCtx::Get()->Now() == initial_backoff); - grpc_exec_ctx_finish(); } static void test_no_jitter_backoff(void) { @@ -83,48 +81,46 @@ static void test_no_jitter_backoff(void) { // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) ExecCtx _local_exec_ctx; - exec_ctx->now = 0; - exec_ctx->now_is_valid = true; + ExecCtx::Get()->SetNow(0); grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); - grpc_exec_ctx_finish(); } static void test_jitter_backoff(void) { @@ -142,9 +138,9 @@ static void test_jitter_backoff(void) { ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - grpc_exec_ctx_now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == initial_backoff); grpc_millis expected_next_lower_bound = @@ -157,7 +153,7 @@ static void test_jitter_backoff(void) { // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_exec_ctx_now(); + next_deadlines.current_deadline - ExecCtx::Get()->Now(); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -166,9 +162,8 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - exec_ctx->now = next_deadlines.current_deadline; + ExecCtx::Get()->SetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index c7e074ae6f..bc9e65089c 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -60,7 +60,6 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { ExecCtx _local_exec_ctx; grpc_server_setup_transport(a->server, transport, NULL, grpc_server_get_channel_args(a->server)); - grpc_exec_ctx_finish(); } static void read_done(void* arg, grpc_error* error) { @@ -118,7 +117,6 @@ void grpc_run_bad_client_test( transport = grpc_create_chttp2_transport(NULL, sfd.server, 0); server_setup_transport(&a, transport); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); /* Bind everything into the same pollset */ grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); @@ -137,7 +135,6 @@ void grpc_run_bad_client_test( /* Write data */ grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure); - grpc_exec_ctx_finish(); /* Await completion, unless the request is large and write may not finish * before the peer shuts down. */ @@ -150,7 +147,7 @@ void grpc_run_bad_client_test( grpc_endpoint_shutdown( sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); grpc_endpoint_destroy(sfd.client); - grpc_exec_ctx_finish(); + sfd.client = NULL; } @@ -170,7 +167,7 @@ void grpc_run_bad_client_test( GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, grpc_schedule_on_exec_ctx); grpc_endpoint_read(sfd.client, &incoming, &read_done_closure); - grpc_exec_ctx_finish(); + do { GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); GPR_ASSERT(grpc_completion_queue_next( @@ -188,7 +185,6 @@ void grpc_run_bad_client_test( grpc_endpoint_shutdown( sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); grpc_endpoint_destroy(sfd.client); - grpc_exec_ctx_finish(); } GPR_ASSERT( @@ -203,6 +199,5 @@ void grpc_run_bad_client_test( grpc_completion_queue_destroy(a.cq); grpc_slice_buffer_destroy_internal(&outgoing); - grpc_exec_ctx_finish(); grpc_shutdown(); } diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index 03b1cbf265..f0393b0f40 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -56,7 +56,6 @@ static void test_create(void) { 0); grpc_channel_args_destroy(ch_args); - grpc_exec_ctx_finish(); } static void test_set_compression_algorithm(void) { @@ -71,7 +70,6 @@ static void test_set_compression_algorithm(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER); grpc_channel_args_destroy(ch_args); - grpc_exec_ctx_finish(); } static void test_compression_algorithm_states(void) { @@ -123,7 +121,6 @@ static void test_compression_algorithm_states(void) { } grpc_channel_args_destroy(ch_args); - grpc_exec_ctx_finish(); } static void test_set_socket_mutator(void) { @@ -139,7 +136,6 @@ static void test_set_socket_mutator(void) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ch_args); - grpc_exec_ctx_finish(); } } diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index 0433758905..66ee2948b1 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -138,13 +138,12 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*channel_data == 1); GRPC_CALL_STACK_UNREF(call_stack, "done"); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(*channel_data == 2); GRPC_CHANNEL_STACK_UNREF(channel_stack, "done"); grpc_slice_unref_internal(path); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index f35557324f..dd3c70a261 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -128,7 +128,6 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); GPR_ASSERT(grpc_channel_init_create_stack( builder, (grpc_channel_stack_type)channel_stack_type)); - grpc_exec_ctx_finish(); } // build up our expectation list @@ -213,7 +212,6 @@ static int check_stack(const char* file, int line, const char* transport_name, ExecCtx _local_exec_ctx; grpc_channel_stack_builder_destroy(builder); grpc_channel_args_destroy(channel_args); - grpc_exec_ctx_finish(); } return result; diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index aabe8dea3c..5b412cc622 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -653,7 +653,6 @@ static void test_get_channel_info() { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); @@ -1025,7 +1024,6 @@ int main(int argc, char** argv) { test_ping(); test_get_channel_info(); - grpc_exec_ctx_finish(); grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 17725ba5ff..597a1212c1 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -43,7 +43,6 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } #else /* GRPC_HAVE_UNIX_SOCKET */ @@ -68,7 +67,6 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, GPR_ASSERT(ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } static void test_grpc_parse_ipv6(const char* uri_text, const char* host, @@ -88,7 +86,6 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index e2823a4501..c7a0e029f2 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -106,7 +106,6 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { ExecCtx _local_exec_ctx; grpc_timer_check(NULL); - grpc_exec_ctx_finish(); } return false; } @@ -154,7 +153,7 @@ int main(int argc, char** argv) { call_resolver_next_after_locking( resolver, &result, GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(wait_loop(5, &ev1)); GPR_ASSERT(result == NULL); @@ -163,14 +162,13 @@ int main(int argc, char** argv) { call_resolver_next_after_locking( resolver, &result, GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(wait_loop(30, &ev2)); GPR_ASSERT(result != NULL); grpc_channel_args_destroy(result); GRPC_RESOLVER_UNREF(resolver, "test"); GRPC_COMBINER_UNREF(g_combiner, "test"); - grpc_exec_ctx_finish(); grpc_shutdown(); gpr_mu_destroy(&g_mu); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 8b40360263..33916b59ec 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -42,7 +42,6 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { GPR_ASSERT(resolver != NULL); GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } static void test_fails(grpc_resolver_factory* factory, const char* string) { @@ -59,7 +58,6 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == NULL); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { @@ -84,7 +82,6 @@ int main(int argc, char** argv) { { ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); - grpc_exec_ctx_finish(); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index ec49558f87..9a1971561c 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -109,7 +109,7 @@ static void test_fake_resolver() { results); grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != NULL); @@ -144,7 +144,7 @@ static void test_fake_resolver() { results_update); grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, on_resolution); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != NULL); @@ -153,14 +153,14 @@ static void test_fake_resolver() { memset(&on_res_arg, 0, sizeof(on_res_arg)); grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL); GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); - grpc_exec_ctx_finish(); + grpc_fake_resolver_response_generator_unref(response_generator); } diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index dbc8a965d5..70b3cbf5b7 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -63,7 +63,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); - grpc_exec_ctx_finish(); + grpc_uri_destroy(uri); } @@ -81,7 +81,6 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == NULL); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { @@ -114,7 +113,6 @@ int main(int argc, char** argv) { { ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); - grpc_exec_ctx_finish(); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index 805becad18..6c1e8cb137 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -38,7 +38,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if ((x = grpc_uri_parse(s, 1))) { grpc_uri_destroy(x); } - grpc_exec_ctx_finish(); + gpr_free(s); return 0; } diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 591c642f4e..024c30faee 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -36,14 +36,13 @@ static void test_succeeds(const char* uri_text, const char* scheme, GPR_ASSERT(0 == strcmp(path, uri->path)); GPR_ASSERT(0 == strcmp(query, uri->query)); GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - grpc_exec_ctx_finish(); + grpc_uri_destroy(uri); } static void test_fails(const char* uri_text) { ExecCtx _local_exec_ctx; GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); - grpc_exec_ctx_finish(); } static void test_query_parts() { @@ -77,7 +76,7 @@ static void test_query_parts() { GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "")); GPR_ASSERT(0 == strcmp("frag", uri->fragment)); - grpc_exec_ctx_finish(); + grpc_uri_destroy(uri); } { @@ -96,7 +95,6 @@ static void test_query_parts() { GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); - grpc_exec_ctx_finish(); grpc_uri_destroy(uri); } { @@ -114,7 +112,7 @@ static void test_query_parts() { GPR_ASSERT(NULL == uri->query_parts); GPR_ASSERT(NULL == uri->query_parts_values); GPR_ASSERT(0 == strcmp("", uri->fragment)); - grpc_exec_ctx_finish(); + grpc_uri_destroy(uri); } } diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index dea8e33030..9ae6363d97 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -53,7 +53,6 @@ static void test_algorithm_mesh(void) { GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); grpc_slice_unref_internal(mdstr); GRPC_MDELEM_UNREF(mdelem); - grpc_exec_ctx_finish(); } /* test failure */ @@ -84,7 +83,6 @@ static void test_algorithm_failure(void) { static_cast(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)), grpc_empty_slice())); grpc_slice_unref_internal(mdstr); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index d642e056d8..a5dfdc884f 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -72,7 +72,6 @@ static void assert_passthrough(grpc_slice value, { ExecCtx _local_exec_ctx; was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); - grpc_exec_ctx_finish(); } GPR_ASSERT(input.count > 0); @@ -94,7 +93,6 @@ static void assert_passthrough(grpc_slice value, ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_msg_decompress( was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); - grpc_exec_ctx_finish(); } final = grpc_slice_merge(output.slices, output.count); @@ -158,7 +156,7 @@ static void test_tiny_data_compress(void) { GPR_ASSERT(0 == grpc_msg_compress(static_cast(i), &input, &output)); - grpc_exec_ctx_finish(); + GPR_ASSERT(1 == output.count); } @@ -189,7 +187,6 @@ static void test_bad_decompression_data_crc(void) { /* try (and fail) to decompress the corrupted compresed buffer */ GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); - grpc_exec_ctx_finish(); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&corrupted); @@ -210,7 +207,6 @@ static void test_bad_decompression_data_trailing_garbage(void) { /* try (and fail) to decompress the invalid compresed buffer */ ExecCtx _local_exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); - grpc_exec_ctx_finish(); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -228,7 +224,6 @@ static void test_bad_decompression_data_stream(void) { /* try (and fail) to decompress the invalid compresed buffer */ ExecCtx _local_exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); - grpc_exec_ctx_finish(); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -253,7 +248,6 @@ static void test_bad_compression_algorithm(void) { GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_compressed); - grpc_exec_ctx_finish(); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -279,7 +273,6 @@ static void test_bad_decompression_algorithm(void) { GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_decompressed); - grpc_exec_ctx_finish(); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 8401618670..c7aaf68dd3 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -51,7 +51,6 @@ TEST(StatsTest, IncCounters) { ExecCtx _local_exec_ctx; GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); - grpc_exec_ctx_finish(); EXPECT_EQ(snapshot.delta().counters[i], 1); } @@ -62,7 +61,6 @@ TEST(StatsTest, IncSpecificCounter) { ExecCtx _local_exec_ctx; GRPC_STATS_INC_SYSCALL_POLL(); - grpc_exec_ctx_finish(); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); } @@ -96,7 +94,6 @@ TEST_P(HistogramTest, IncHistogram) { ExecCtx _local_exec_ctx; grpc_stats_inc_histogram[kHistogram](j); - grpc_exec_ctx_finish(); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 9ae3d3cfbf..5e7e12643e 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -290,7 +290,7 @@ static void run_test(const char* response_payload, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); grpc_endpoint_destroy(state.tcp); cleanup_rpc(); - grpc_exec_ctx_finish(); + test_tcp_server_destroy(&test_server); grpc_shutdown(); diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index 677e315112..1372c5a746 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -133,7 +133,6 @@ static void run_test(bool wait_for_ready, bool use_service_config) { { ExecCtx _local_exec_ctx; if (args != NULL) grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } grpc_shutdown(); diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index c3c3e961e7..a43d963c54 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -76,7 +76,6 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); - grpc_exec_ctx_finish(); } } @@ -93,7 +92,6 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } grpc_server_register_completion_queue(f->server, f->cq, NULL); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index f520b48fa3..3f9a87d0fc 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -68,7 +68,6 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, if (ffd->client_args_compression != NULL) { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ffd->client_args_compression); - grpc_exec_ctx_finish(); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( client_args, GRPC_COMPRESS_GZIP); @@ -83,7 +82,6 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, if (ffd->server_args_compression != NULL) { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ffd->server_args_compression); - grpc_exec_ctx_finish(); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( server_args, GRPC_COMPRESS_GZIP); @@ -104,7 +102,6 @@ void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { grpc_channel_args_destroy(ffd->server_args_compression); gpr_free(ffd->localaddr); gpr_free(ffd); - grpc_exec_ctx_finish(); } /* All test configurations */ diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 48e1b313fd..99bced8651 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -75,8 +75,6 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, f->client = grpc_insecure_channel_create_from_fd( "fixture_client", sfd->fd_pair[0], client_args); GPR_ASSERT(f->client); - - grpc_exec_ctx_finish(); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, @@ -90,8 +88,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_server_start(f->server); grpc_server_add_insecure_channel_from_fd(f->server, NULL, sfd->fd_pair[1]); - - grpc_exec_ctx_finish(); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index 563e1e1ac2..e98df083f2 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -90,7 +90,6 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); grpc_channel_args_destroy(server_args_new); - grpc_exec_ctx_finish(); } void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 74b5983364..84eb9e4513 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -79,7 +79,6 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } grpc_server_register_completion_queue(f->server, f->cq, NULL); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 8ff7cb304c..9ffc5b7b7e 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -160,7 +160,6 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_args_destroy(new_client_args); grpc_channel_credentials_release(ssl_creds); grpc_call_credentials_release(oauth2_creds); - grpc_exec_ctx_finish(); } static int fail_server_auth_check(grpc_channel_args* server_args) { diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 391de0bd0b..9e87a22962 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -55,7 +55,6 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(); } typedef struct { @@ -98,7 +97,6 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, client_setup_transport(&cs, transport); GPR_ASSERT(f->client); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, @@ -113,7 +111,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, transport = grpc_create_chttp2_transport(server_args, sfd->server, 0); server_setup_transport(f, transport); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { @@ -143,7 +140,6 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); grpc_init(); - grpc_exec_ctx_finish(); GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 4e7eb3dbb8..fa69ad84cf 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -49,7 +49,6 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(); } typedef struct { @@ -92,7 +91,6 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, client_setup_transport(&cs, transport); GPR_ASSERT(f->client); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, @@ -107,7 +105,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, transport = grpc_create_chttp2_transport(server_args, sfd->server, 0); server_setup_transport(f, transport); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index cfa32d4a27..a12d60575b 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -49,7 +49,6 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(); } typedef struct { @@ -103,7 +102,6 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, client_setup_transport(&cs, transport); GPR_ASSERT(f->client); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, @@ -118,7 +116,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, transport = grpc_create_chttp2_transport(server_args, sfd->server, 0); server_setup_transport(f, transport); grpc_chttp2_transport_start_reading(transport, NULL); - grpc_exec_ctx_finish(); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index ac555d9ee8..c137cec8b9 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -112,7 +112,6 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); - grpc_exec_ctx_finish(); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index 66c5b167e1..0c130d6ae1 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -68,7 +68,6 @@ static grpc_channel* create_proxy_client(const char* target, { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); - grpc_exec_ctx_finish(); } return channel; } @@ -150,7 +149,6 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); - grpc_exec_ctx_finish(); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index b3ec44d77b..73a3e2c444 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -391,7 +391,7 @@ static void on_read_request_done(void* arg, grpc_error* error) { GPR_ASSERT(resolved_addresses->naddrs >= 1); // Connect to requested address. // The connection callback inherits our reference to conn. - const grpc_millis deadline = grpc_exec_ctx_now() + 10 * GPR_MS_PER_SEC; + const grpc_millis deadline = ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, conn->pollset_set, NULL, &resolved_addresses->addrs[0], deadline); @@ -449,13 +449,13 @@ static void thread_main(void* arg) { gpr_ref(&proxy->users); grpc_pollset_worker* worker = NULL; gpr_mu_lock(proxy->mu); - GRPC_LOG_IF_ERROR("grpc_pollset_work", - grpc_pollset_work(proxy->pollset, &worker, - grpc_exec_ctx_now() + GPR_MS_PER_SEC)); + GRPC_LOG_IF_ERROR( + "grpc_pollset_work", + grpc_pollset_work(proxy->pollset, &worker, + ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } while (!gpr_unref(&proxy->users)); - grpc_exec_ctx_finish(); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( @@ -489,7 +489,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(proxy->pollset, &proxy->mu); grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); - grpc_exec_ctx_finish(); + // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); @@ -516,7 +516,6 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { grpc_schedule_on_exec_ctx)); GRPC_COMBINER_UNREF(proxy->combiner, "test"); gpr_free(proxy); - grpc_exec_ctx_finish(); } const char* grpc_end2end_http_proxy_get_proxy_name( diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 1d6a40c7e3..1d22ba3a42 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -411,7 +411,7 @@ void my_resolve_address(const char* addr, const char* default_port, r->addrs = addresses; r->lb_addrs = NULL; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(), + &r->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } @@ -428,7 +428,7 @@ grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, r->addrs = NULL; r->lb_addrs = lb_addrs; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(), + &r->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); return NULL; } @@ -488,7 +488,7 @@ static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, fc->ep = ep; fc->deadline = deadline; grpc_timer_init( - &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(), + &fc->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx)); } @@ -745,7 +745,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { { ExecCtx _local_exec_ctx; grpc_executor_set_threading(false); - grpc_exec_ctx_finish(); } grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; @@ -840,7 +839,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } gpr_free(target_uri); gpr_free(target); @@ -868,7 +866,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } grpc_server_register_completion_queue(g_server, cq, NULL); grpc_server_start(g_server); @@ -1197,7 +1194,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } gpr_free(target_uri); gpr_free(target); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index 219c42847e..95ed2fcdac 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -111,7 +111,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_event ev; while (1) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); switch (ev.type) { case GRPC_QUEUE_TIMEOUT: diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index d7295f4c83..21778c0a67 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -78,7 +78,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_event ev; while (1) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); switch (ev.type) { case GRPC_QUEUE_TIMEOUT: diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index 850d6516f2..e0da548a75 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -183,7 +183,6 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; { \ ExecCtx _local_exec_ctx; \ grpc_channel_args_destroy(new_client_args); \ - grpc_exec_ctx_finish(); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index fcf30f0cc6..ffafb1f1e9 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -247,7 +247,6 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, if (args != NULL) { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index b63491c7d2..7e20487f8b 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -279,7 +279,6 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, if (args != NULL) { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); - grpc_exec_ctx_finish(); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index a85fdf2662..f04addbe9e 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -132,7 +132,6 @@ static void request_for_disabled_algorithm( ExecCtx _local_exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(); } f = begin_test(config, test_name, client_args, server_args); @@ -260,7 +259,6 @@ static void request_for_disabled_algorithm( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } end_test(&f); @@ -539,7 +537,6 @@ static void request_with_payload_template( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } end_test(&f); diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index 670610f37f..6ce22d77c6 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -302,7 +302,6 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(lr_server_args); - grpc_exec_ctx_finish(); } config.tear_down_data(&f); } diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index 0200517de3..f884d8b11f 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -176,7 +176,6 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, ExecCtx _local_exec_ctx; if (client_args != NULL) grpc_channel_args_destroy(client_args); if (server_args != NULL) grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } cqv = cq_verifier_create(f.cq); @@ -367,7 +366,6 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, ExecCtx _local_exec_ctx; if (client_args != NULL) grpc_channel_args_destroy(client_args); if (server_args != NULL) grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } cqv = cq_verifier_create(f.cq); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 6100d604d2..cec46305bd 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -132,7 +132,6 @@ static void request_for_disabled_algorithm( ExecCtx _local_exec_ctx; server_args = grpc_channel_args_stream_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(); } f = begin_test(config, test_name, client_args, server_args); @@ -261,7 +260,6 @@ static void request_for_disabled_algorithm( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } end_test(&f); @@ -547,7 +545,6 @@ static void request_with_payload_template( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } end_test(&f); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 42318ffbc8..c304c990d7 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -280,7 +280,6 @@ static void test_invoke_request_response_with_payload( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index 5fb6a7e46f..f4b737d7a3 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -276,7 +276,6 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index f38a51a5b7..100f393b8e 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -150,7 +150,6 @@ static void request_with_payload_template( arg.value.string = user_agent_override; client_args = grpc_channel_args_copy_and_add(client_args_old, &arg, 1); grpc_channel_args_destroy(client_args_old); - grpc_exec_ctx_finish(); } f = begin_test(config, test_name, client_args, server_args); @@ -352,7 +351,6 @@ static void request_with_payload_template( ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); - grpc_exec_ctx_finish(); } end_test(&f); diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 85e4bc8a0e..dfa328360d 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -88,7 +88,7 @@ static void test_get(int port) { "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -127,7 +127,7 @@ static void test_post(int port) { "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -196,7 +196,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index d948bb5e31..ff082e8367 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -89,7 +89,7 @@ static void test_get(int port) { "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -129,7 +129,7 @@ static void test_post(int port) { "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -199,7 +199,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 9fc1890c97..df8d55f1f6 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -30,7 +30,6 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); - grpc_exec_ctx_finish(); } static void set_event_to_true(void* value, grpc_error* error) { @@ -47,11 +46,10 @@ static void test_execute_one(void) { GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != NULL); GRPC_COMBINER_UNREF(lock, "test_execute_one"); - grpc_exec_ctx_finish(); } typedef struct { @@ -84,7 +82,7 @@ static void execute_many_loop(void* a) { GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE( check_one, c, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } // sleep for a little bit, to test a combiner draining and another thread // picking it up @@ -93,7 +91,6 @@ static void execute_many_loop(void* a) { GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_finish(); } static void test_execute_many(void) { @@ -117,7 +114,6 @@ static void test_execute_many(void) { } ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(lock, "test_execute_many"); - grpc_exec_ctx_finish(); } static gpr_event got_in_finally; @@ -142,11 +138,10 @@ static void test_execute_finally(void) { GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&got_in_finally, grpc_timeout_seconds_to_deadline(5)) != NULL); GRPC_COMBINER_UNREF(lock, "test_execute_finally"); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index bddeadd329..72833a8dbe 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -45,7 +45,6 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( f.server_ep = p.server; grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); - grpc_exec_ctx_finish(); return f; } @@ -69,7 +68,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 10e80fc71b..5c156ef524 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -213,7 +213,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, even when bytes_written is unsigned. */ state.bytes_written -= state.current_write_size; read_and_write_test_write_handler(&state, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read); @@ -225,24 +225,23 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_endpoint_shutdown( state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); } - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = NULL; - GPR_ASSERT(grpc_exec_ctx_now() < deadline); + GPR_ASSERT(ExecCtx::Get()->Now() < deadline); GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); end_test(config); grpc_slice_buffer_destroy_internal(&state.outgoing); grpc_slice_buffer_destroy_internal(&state.incoming); grpc_endpoint_destroy(state.read_ep); grpc_endpoint_destroy(state.write_ep); - grpc_exec_ctx_finish(); } static void inc_on_failure(void* arg, grpc_error* error) { @@ -253,16 +252,16 @@ static void inc_on_failure(void* arg, grpc_error* error) { } static void wait_for_fail_count(int* fail_count, int want_fail_count) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); - while (grpc_exec_ctx_now() < deadline && *fail_count < want_fail_count) { + while (ExecCtx::Get()->Now() < deadline && *fail_count < want_fail_count) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(*fail_count == want_fail_count); @@ -303,7 +302,6 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_endpoint_destroy(f.client_ep); grpc_endpoint_destroy(f.server_ep); - grpc_exec_ctx_finish(); } void grpc_endpoint_tests(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 5dd28eac9c..5c71bc6152 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -77,11 +77,11 @@ static void test_fd_cleanup(test_fd* tfds, int num_fds) { for (i = 0; i < num_fds; i++) { grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_fd_orphan(tfds[i].fd, NULL, &release_fd, false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(release_fd == tfds[i].inner_fd); close(tfds[i].inner_fd); @@ -110,7 +110,7 @@ static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_free(pollsets[i].pollset); } } @@ -168,32 +168,32 @@ static void test_add_fd_to_pollset() { /* == Step 1 == */ for (i = 0; i <= 2; i++) { grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } for (i = 3; i <= 4; i++) { grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } for (i = 5; i <= 7; i++) { grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } /* == Step 2 == */ for (i = 0; i <= 1; i++) { grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } /* == Step 3 == */ grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* == Step 4 == */ grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* All polling islands are merged at this point */ @@ -212,7 +212,6 @@ static void test_add_fd_to_pollset() { test_fd_cleanup(tfds, NUM_FDS); test_pollset_cleanup(pollsets, NUM_POLLSETS); - grpc_exec_ctx_finish(); } #undef NUM_FDS @@ -239,7 +238,6 @@ static void test_threading_loop(void* arg) { "pollset_work", grpc_pollset_work(shared->pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(shared->mu); - grpc_exec_ctx_finish(); } } @@ -279,7 +277,6 @@ static void test_threading(void) { shared.wakeup_desc, GRPC_CLOSURE_INIT(&shared.on_wakeup, test_threading_wakeup, &shared, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(); } GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", grpc_wakeup_fd_wakeup(shared.wakeup_fd))); @@ -296,7 +293,6 @@ static void test_threading(void) { grpc_pollset_shutdown(shared.pollset, GRPC_CLOSURE_CREATE(destroy_pollset, shared.pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(); } gpr_free(shared.pollset); } @@ -318,7 +314,6 @@ int main(int argc, char** argv) { poll_strategy); } - grpc_exec_ctx_finish(); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index a5f6d33998..7f3420269e 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -45,12 +45,11 @@ int main(int argc, char** argv) { p = grpc_iomgr_create_endpoint_pair("test", NULL); grpc_endpoint_destroy(p.client); grpc_endpoint_destroy(p.server); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } grpc_resource_quota_unref(resource_quota); - grpc_exec_ctx_finish(); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index 9bf16923cb..d22cb5f4f6 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -252,7 +252,7 @@ static void server_wait_and_shutdown(server* sv) { "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -367,7 +367,7 @@ static void client_wait_and_shutdown(client* cl) { "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -386,7 +386,7 @@ static void test_grpc_fd(void) { port = server_start(&sv); client_init(&cl); client_start(&cl, port); - grpc_exec_ctx_finish(); + client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); @@ -469,7 +469,7 @@ static void test_grpc_fd_change(void) { "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); @@ -493,7 +493,7 @@ static void test_grpc_fd_change(void) { "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ @@ -501,7 +501,7 @@ static void test_grpc_fd_change(void) { gpr_mu_unlock(g_mu); grpc_fd_orphan(em_fd, NULL, NULL, false /* already_closed */, "d"); - grpc_exec_ctx_finish(); + destroy_change_data(&a); destroy_change_data(&b); close(sv[1]); @@ -523,9 +523,9 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_free(g_pollset); - grpc_exec_ctx_finish(); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index ba794ca192..e9b46f59e3 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -84,7 +84,7 @@ static void cleanup_test_pollsets(test_pollset* pollsets, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(pollsets[i].ps, &destroyed); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_free(pollsets[i].ps); pollsets[i].ps = NULL; } @@ -129,7 +129,7 @@ static void cleanup_test_fds(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also * calls close() on the underlying fd. In our case, we are using @@ -138,7 +138,7 @@ static void cleanup_test_fds(test_fd* tfds, const int num_fds) { * underlying fd, call it with a non-NULL 'release_fd' parameter */ grpc_fd_orphan(tfds[i].fd, NULL, &release_fd, false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); } @@ -236,7 +236,7 @@ static void pollset_set_test_basic() { grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Test that if any FD in the above structure is readable, it is observable by * doing grpc_pollset_work on any pollset @@ -259,10 +259,10 @@ static void pollset_set_test_basic() { grpc_pollset_work(pollsets[i].ps, &worker, deadline)); gpr_mu_unlock(pollsets[i].mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } /* Test tear down */ @@ -270,19 +270,18 @@ static void pollset_set_test_basic() { grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(pollsets, num_ps); cleanup_test_pollset_sets(pollset_sets, num_pss); - grpc_exec_ctx_finish(); } /* Same FD added multiple times to the pollset_set tree */ @@ -338,10 +337,10 @@ void pollset_set_test_dup_fds() { GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(pollset.ps, &worker, deadline)); gpr_mu_unlock(pollset.mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Tear down */ grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); @@ -350,12 +349,11 @@ void pollset_set_test_dup_fds() { grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(&pollset, num_ps); cleanup_test_pollset_sets(pollset_sets, num_pss); - grpc_exec_ctx_finish(); } /* Pollset_set with an empty pollset */ @@ -406,21 +404,20 @@ void pollset_set_test_empty_pollset() { GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(pollsets[0].ps, &worker, deadline)); gpr_mu_unlock(pollsets[0].mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Tear down */ grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(pollsets, num_ps); cleanup_test_pollset_sets(&pollset_set, num_pss); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { @@ -442,7 +439,6 @@ int main(int argc, char** argv) { poll_strategy); } - grpc_exec_ctx_finish(); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index d06777d86f..9870d7aa73 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -67,7 +67,7 @@ void args_finish(args_struct* args) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(args->pollset, &do_nothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -86,7 +86,7 @@ static void actually_poll(void* argsp) { if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(); + grpc_millis time_left = deadline - ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = NULL; @@ -94,10 +94,9 @@ static void actually_poll(void* argsp) { GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(); } static void poll_pollset_until_request_done(args_struct* args) { @@ -130,7 +129,6 @@ static void test_unix_socket(void) { GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_unix_socket_path_name_too_long(void) { @@ -153,7 +151,6 @@ static void test_unix_socket_path_name_too_long(void) { &args.addrs); gpr_free(path_name); args_finish(&args); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { @@ -163,7 +160,7 @@ int main(int argc, char** argv) { test_unix_socket(); test_unix_socket_path_name_too_long(); grpc_executor_shutdown(); - grpc_exec_ctx_finish(); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index 1eb753dc85..dbc825884d 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -63,7 +63,7 @@ void args_finish(args_struct* args) { grpc_pollset_shutdown(args->pollset, &do_nothing_cb); gpr_mu_unlock(args->mu); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -81,7 +81,7 @@ static void poll_pollset_until_request_done(args_struct* args) { if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(); + grpc_millis time_left = deadline - ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = NULL; @@ -89,10 +89,9 @@ static void poll_pollset_until_request_done(args_struct* args) { GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(); } static void must_succeed(void* argsp, grpc_error* err) { @@ -123,10 +122,9 @@ static void test_localhost(void) { "localhost:1", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_default_port(void) { @@ -137,10 +135,9 @@ static void test_default_port(void) { "localhost", "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_non_numeric_default_port(void) { @@ -151,10 +148,9 @@ static void test_non_numeric_default_port(void) { "localhost", "https", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_missing_default_port(void) { @@ -165,10 +161,9 @@ static void test_missing_default_port(void) { "localhost", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_ipv6_with_port(void) { @@ -179,10 +174,9 @@ static void test_ipv6_with_port(void) { "[2001:db8::1]:1", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } static void test_ipv6_without_port(void) { @@ -200,10 +194,9 @@ static void test_ipv6_without_port(void) { kCases[i], "80", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } } @@ -221,10 +214,9 @@ static void test_invalid_ip_addresses(void) { kCases[i], NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } } @@ -241,10 +233,9 @@ static void test_unparseable_hostports(void) { kCases[i], "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); - grpc_exec_ctx_finish(); } } @@ -261,7 +252,7 @@ int main(int argc, char** argv) { test_invalid_ip_addresses(); test_unparseable_hostports(); grpc_executor_shutdown(); - grpc_exec_ctx_finish(); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index bee9373ff6..40beadc5d6 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -86,7 +86,6 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { static void destroy_user(grpc_resource_user* usr) { ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); - grpc_exec_ctx_finish(); } static void test_no_op(void) { @@ -120,12 +119,10 @@ static void test_instant_alloc_then_free(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); - grpc_exec_ctx_finish(); } { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -141,7 +138,6 @@ static void test_instant_alloc_free_pair(void) { ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -158,14 +154,13 @@ static void test_simple_async_alloc(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); } { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -182,7 +177,7 @@ static void test_async_alloc_blocked_by_size(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL); } @@ -192,7 +187,6 @@ static void test_async_alloc_blocked_by_size(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -209,7 +203,7 @@ static void test_scavenge(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -217,14 +211,13 @@ static void test_scavenge(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr1, 1024); - grpc_exec_ctx_finish(); } { gpr_event ev; gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -232,7 +225,6 @@ static void test_scavenge(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -250,7 +242,7 @@ static void test_scavenge_blocked(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -259,14 +251,14 @@ static void test_scavenge_blocked(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL); } { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr1, 1024); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -274,7 +266,6 @@ static void test_scavenge_blocked(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -292,7 +283,7 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -303,14 +294,13 @@ static void test_blocked_until_scheduled_reclaim(void) { ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(); } { gpr_event ev; gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -320,7 +310,6 @@ static void test_blocked_until_scheduled_reclaim(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -338,7 +327,7 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -349,14 +338,13 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(); } { gpr_event ev; gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -366,7 +354,6 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -384,7 +371,7 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -395,14 +382,13 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(); } { gpr_event ev; gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -412,7 +398,6 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -434,7 +419,7 @@ static void test_unused_reclaim_is_cancelled(void) { usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( usr, true, make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -465,7 +450,7 @@ static void test_benign_reclaim_is_preferred(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -476,7 +461,7 @@ static void test_benign_reclaim_is_preferred(void) { usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( usr, true, make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -489,7 +474,7 @@ static void test_benign_reclaim_is_preferred(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -501,7 +486,6 @@ static void test_benign_reclaim_is_preferred(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -526,7 +510,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; @@ -537,7 +521,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( usr, true, make_reclaimer(usr, 512, set_event(&destructive_done))); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -550,7 +534,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { gpr_event_init(&ev); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -562,7 +546,6 @@ static void test_multiple_reclaims_can_be_triggered(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -582,18 +565,15 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); - grpc_exec_ctx_finish(); } { ExecCtx _local_exec_ctx; grpc_resource_quota_unref(q); grpc_resource_user_unref(usr); - grpc_exec_ctx_finish(); } { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } } @@ -616,7 +596,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -626,7 +606,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event_init(&allocated); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, @@ -636,7 +616,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -644,7 +624,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_seconds_to_deadline(5)) != NULL); } @@ -663,7 +643,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event_init(&allocated); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != NULL); } @@ -674,7 +654,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_milliseconds_to_deadline(100)) == NULL); @@ -684,7 +664,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event_init(&allocated); ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_done, @@ -694,7 +674,6 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); - grpc_exec_ctx_finish(); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -719,14 +698,13 @@ static void test_one_slice(void) { const int start_allocs = num_allocs; ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(); + assert_counter_becomes(&num_allocs, start_allocs + 1); } { ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -752,21 +730,19 @@ static void test_one_slice_deleted_late(void) { const int start_allocs = num_allocs; ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(); + assert_counter_becomes(&num_allocs, start_allocs + 1); } { ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); { ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } } @@ -796,7 +772,7 @@ static void test_negative_rq_free_pool(void) { const int start_allocs = num_allocs; ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(); + assert_counter_becomes(&num_allocs, start_allocs + 1); } @@ -809,14 +785,12 @@ static void test_negative_rq_free_pool(void) { { ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); - grpc_exec_ctx_finish(); } grpc_resource_quota_unref(q); { ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 7fad3b08be..abefecba33 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -56,7 +56,7 @@ static void finish_connection() { ExecCtx _local_exec_ctx; GPR_ASSERT( GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); - grpc_exec_ctx_finish(); + gpr_mu_unlock(g_mu); } @@ -127,13 +127,11 @@ void test_succeeds(void) { grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(); } void test_fails(void) { @@ -177,12 +175,11 @@ void test_fails(void) { break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); } static void destroy_pollset(void* p, grpc_error* error) { @@ -198,7 +195,7 @@ int main(int argc, char** argv) { g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); grpc_pollset_set_add_pollset(g_pollset_set, g_pollset); - grpc_exec_ctx_finish(); + test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); @@ -206,7 +203,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index dd98fb2275..0355896b85 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -121,7 +121,7 @@ void test_succeeds(void) { grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -129,8 +129,6 @@ void test_succeeds(void) { uv_close((uv_handle_t*)svr_handle, close_cb); gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(); } void test_fails(void) { @@ -175,12 +173,11 @@ void test_fails(void) { break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); } static void destroy_pollset(void* p, grpc_error* error) { @@ -194,14 +191,14 @@ int main(int argc, char** argv) { grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); - grpc_exec_ctx_finish(); + test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index e4126fb05a..678e1c3638 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -193,7 +193,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); @@ -201,7 +201,6 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_destroy_internal(&state.incoming); grpc_endpoint_destroy(ep); - grpc_exec_ctx_finish(); } /* Write to a socket until it fills up, then read from it using the grpc_tcp @@ -244,7 +243,7 @@ static void large_read_test(size_t slice_size) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); @@ -252,7 +251,6 @@ static void large_read_test(size_t slice_size) { grpc_slice_buffer_destroy_internal(&state.incoming); grpc_endpoint_destroy(ep); - grpc_exec_ctx_finish(); } struct write_socket_state { @@ -316,7 +314,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(10))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + do { bytes_read = read(fd, buf, bytes_left > read_size ? read_size : bytes_left); @@ -385,7 +383,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -393,7 +391,6 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_destroy_internal(&outgoing); grpc_endpoint_destroy(ep); gpr_free(slices); - grpc_exec_ctx_finish(); } void on_fd_released(void* arg, grpc_error* errors) { @@ -453,7 +450,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR, state.read_bytes, state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); @@ -461,7 +458,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_destroy_internal(&state.incoming); grpc_tcp_destroy_and_release_fd(ep, &fd, &fd_released_cb); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker* worker = NULL; @@ -472,7 +469,6 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); - grpc_exec_ctx_finish(); written_bytes = fill_socket_partial(sv[0], num_bytes); drain_socket_blocking(fd, written_bytes, written_bytes); @@ -528,8 +524,6 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); - grpc_exec_ctx_finish(); - return f; } @@ -553,7 +547,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 3707634c29..1c3f4490d5 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -167,7 +167,6 @@ static void test_no_op(void) { grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_start(void) { @@ -177,7 +176,6 @@ static void test_no_op_with_start(void) { LOG_TEST("test_no_op_with_start"); grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_port(void) { @@ -197,7 +195,6 @@ static void test_no_op_with_port(void) { port > 0); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_port_and_start(void) { @@ -219,7 +216,6 @@ static void test_no_op_with_port_and_start(void) { grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static grpc_error* tcp_connect(const test_addr* remote, @@ -247,7 +243,7 @@ static grpc_error* tcp_connect(const test_addr* remote, return GRPC_OS_ERROR(errno, "connect"); } gpr_log(GPR_DEBUG, "wait"); - while (g_nconnects == nconnects_before && deadline > grpc_exec_ctx_now()) { + while (g_nconnects == nconnects_before && deadline > ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = NULL; grpc_error* err; if ((err = grpc_pollset_work(g_pollset, &worker, deadline)) != @@ -257,7 +253,7 @@ static grpc_error* tcp_connect(const test_addr* remote, return err; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -413,7 +409,6 @@ static void test_connect(size_t num_connects, GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 0) >= 0); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); @@ -489,7 +484,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(dst_addrs); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index 2a0ada225c..50042af37f 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -119,7 +119,6 @@ static void test_no_op(void) { grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_start(void) { @@ -129,7 +128,6 @@ static void test_no_op_with_start(void) { LOG_TEST("test_no_op_with_start"); grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_port(void) { @@ -149,7 +147,6 @@ static void test_no_op_with_port(void) { port > 0); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void test_no_op_with_port_and_start(void) { @@ -171,7 +168,6 @@ static void test_no_op_with_port_and_start(void) { grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); } static void connect_cb(uv_connect_t* req, int status) { @@ -205,7 +201,7 @@ static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up(deadline)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -277,7 +273,6 @@ static void test_connect(unsigned n) { GPR_ASSERT(weak_ref.server != NULL); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); @@ -305,7 +300,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 07dfec168c..7281f55b85 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -52,7 +52,7 @@ static void add_test(void) { grpc_timer_check_trace.value = 1; memset(cb_called, 0, sizeof(cb_called)); - grpc_millis start = grpc_exec_ctx_now(); + grpc_millis start = ExecCtx::Get()->Now(); /* 10 ms timers. will expire in the current epoch */ for (i = 0; i < 10; i++) { @@ -69,32 +69,32 @@ static void add_test(void) { } /* collect timers. Only the first batch should be ready. */ - exec_ctx->now = start + 500; + ExecCtx::Get()->SetNow(start + 500); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(); + for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx->now = start + 600; + ExecCtx::Get()->SetNow(start + 600); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY); - grpc_exec_ctx_finish(); + for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the timers */ - exec_ctx->now = start + 1500; + ExecCtx::Get()->SetNow(start + 1500); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(); + for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx->now = start + 1600; + ExecCtx::Get()->SetNow(start + 1600); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); @@ -102,7 +102,6 @@ static void add_test(void) { } grpc_timer_list_shutdown(); - grpc_exec_ctx_finish(); } /* Cleaning up a list with pending timers. */ @@ -112,8 +111,7 @@ void destruction_test(void) { gpr_log(GPR_INFO, "destruction_test"); - exec_ctx->now_is_valid = true; - exec_ctx->now = 0; + ExecCtx::Get()->SetNow(0); grpc_timer_list_init(); grpc_timer_trace.value = 1; grpc_timer_check_trace.value = 1; @@ -134,18 +132,18 @@ void destruction_test(void) { grpc_timer_init( &timers[4], 1, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)4, grpc_schedule_on_exec_ctx)); - exec_ctx->now = 2; + ExecCtx::Get()->SetNow(2); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(); + GPR_ASSERT(1 == cb_called[4][1]); grpc_timer_cancel(&timers[0]); grpc_timer_cancel(&timers[3]); - grpc_exec_ctx_finish(); + GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); grpc_timer_list_shutdown(); - grpc_exec_ctx_finish(); + GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); } diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index c079dbf716..47e5cf0254 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -130,7 +130,6 @@ static void test_no_op(void) { ExecCtx _local_exec_ctx; grpc_udp_server* s = grpc_udp_server_create(NULL); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); } static void test_no_op_with_start(void) { @@ -139,7 +138,6 @@ static void test_no_op_with_start(void) { LOG_TEST("test_no_op_with_start"); grpc_udp_server_start(s, NULL, 0, NULL); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); } static void test_no_op_with_port(void) { @@ -157,7 +155,6 @@ static void test_no_op_with_port(void) { on_fd_orphaned)); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); @@ -188,7 +185,7 @@ static void test_no_op_with_port_and_socket_factory(void) { GPR_ASSERT(socket_factory->number_of_bind_calls == 1); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); + grpc_socket_factory_unref(&socket_factory->base); /* The server had a single FD, which should have been orphaned. */ @@ -212,7 +209,6 @@ static void test_no_op_with_port_and_start(void) { grpc_udp_server_start(s, NULL, 0, NULL); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ @@ -264,12 +260,12 @@ static void test_receive(int number_of_clients) { (socklen_t)resolved_addr.len) == 0); GPR_ASSERT(5 == write(clifd, "hello", 5)); while (g_number_of_reads == number_of_reads_before && - deadline > grpc_exec_ctx_now()) { + deadline > ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1); @@ -280,7 +276,6 @@ static void test_receive(int number_of_clients) { gpr_mu_unlock(g_mu); grpc_udp_server_destroy(s, NULL); - grpc_exec_ctx_finish(); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ @@ -313,7 +308,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + gpr_free(g_pollset); grpc_shutdown(); return 0; diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index c03ae5c584..029171c931 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -154,7 +154,6 @@ static void test_empty_md_array(void) { GPR_ASSERT(md_array.md == NULL); GPR_ASSERT(md_array.size == 0); grpc_credentials_mdelem_array_destroy(&md_array); - grpc_exec_ctx_finish(); } static void test_add_to_empty_md_array(void) { @@ -170,7 +169,6 @@ static void test_add_to_empty_md_array(void) { GPR_ASSERT(grpc_mdelem_eq(md, md_array.md[0])); GRPC_MDELEM_UNREF(md); grpc_credentials_mdelem_array_destroy(&md_array); - grpc_exec_ctx_finish(); } static void test_add_abunch_to_md_array(void) { @@ -190,7 +188,6 @@ static void test_add_abunch_to_md_array(void) { } GRPC_MDELEM_UNREF(md); grpc_credentials_mdelem_array_destroy(&md_array); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { @@ -208,7 +205,6 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) { 0); GRPC_MDELEM_UNREF(token_md); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { @@ -221,7 +217,6 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { @@ -233,7 +228,6 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { @@ -249,7 +243,6 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { @@ -264,7 +257,6 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { @@ -280,7 +272,6 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( @@ -296,7 +287,6 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(); } typedef struct { @@ -402,7 +392,6 @@ static void test_google_iam_creds(void) { NULL}; run_request_metadata_test(creds, auth_md_ctx, state); grpc_call_credentials_unref(creds); - grpc_exec_ctx_finish(); } static void test_access_token_creds(void) { @@ -417,7 +406,6 @@ static void test_access_token_creds(void) { GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); run_request_metadata_test(creds, auth_md_ctx, state); grpc_call_credentials_unref(creds); - grpc_exec_ctx_finish(); } static grpc_security_status check_channel_oauth2_create_security_connector( @@ -448,7 +436,6 @@ static void test_channel_oauth2_composite_creds(void) { channel_oauth2_creds, NULL, NULL, NULL, &new_args) == GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_creds); - grpc_exec_ctx_finish(); } static void test_oauth2_google_iam_composite_creds(void) { @@ -484,7 +471,6 @@ static void test_oauth2_google_iam_composite_creds(void) { GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); run_request_metadata_test(composite_creds, auth_md_ctx, state); grpc_call_credentials_unref(composite_creds); - grpc_exec_ctx_finish(); } static grpc_security_status @@ -533,7 +519,6 @@ static void test_channel_oauth2_google_iam_composite_creds(void) { GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_iam_creds); - grpc_exec_ctx_finish(); } static void validate_compute_engine_http_request( @@ -598,7 +583,7 @@ static void test_compute_engine_creds_success(void) { grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -606,11 +591,10 @@ static void test_compute_engine_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); - grpc_exec_ctx_finish(); } static void test_compute_engine_creds_failure(void) { @@ -628,7 +612,6 @@ static void test_compute_engine_creds_failure(void) { run_request_metadata_test(creds, auth_md_ctx, state); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); - grpc_exec_ctx_finish(); } static void validate_refresh_token_http_request( @@ -689,7 +672,7 @@ static void test_refresh_token_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -697,11 +680,10 @@ static void test_refresh_token_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); - grpc_exec_ctx_finish(); } static void test_refresh_token_creds_failure(void) { @@ -719,7 +701,6 @@ static void test_refresh_token_creds_failure(void) { run_request_metadata_test(creds, auth_md_ctx, state); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); - grpc_exec_ctx_finish(); } static void validate_jwt_encode_and_sign_params( @@ -824,7 +805,7 @@ static void test_jwt_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -832,7 +813,7 @@ static void test_jwt_creds_success(void) { grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ @@ -841,13 +822,12 @@ static void test_jwt_creds_success(void) { auth_md_ctx.service_url = other_test_service_url; grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); run_request_metadata_test(creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); gpr_free(json_key_string); gpr_free(expected_md_value); grpc_jwt_encode_and_sign_set_override(NULL); - grpc_exec_ctx_finish(); } static void test_jwt_creds_signing_failure(void) { @@ -867,7 +847,6 @@ static void test_jwt_creds_signing_failure(void) { gpr_free(json_key_string); grpc_call_credentials_unref(creds); grpc_jwt_encode_and_sign_set_override(NULL); - grpc_exec_ctx_finish(); } static void set_google_default_creds_env_var_with_file_contents( @@ -902,7 +881,6 @@ static void test_google_default_creds_auth_key(void) { 0); grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(); } static void test_google_default_creds_refresh_token(void) { @@ -920,7 +898,6 @@ static void test_google_default_creds_refresh_token(void) { "32555999999.apps.googleusercontent.com") == 0); grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(); } static int default_creds_gce_detection_httpcli_get_success_override( @@ -968,7 +945,7 @@ static void test_google_default_creds_gce(void) { grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); run_request_metadata_test(creds->call_creds, auth_md_ctx, state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); /* Check that we get a cached creds if we call grpc_google_default_credentials_create again. @@ -984,7 +961,6 @@ static void test_google_default_creds_gce(void) { grpc_channel_credentials_unref(&creds->base); grpc_httpcli_set_override(NULL, NULL); grpc_override_well_known_credentials_path_getter(NULL); - grpc_exec_ctx_finish(); } static int default_creds_gce_detection_httpcli_get_failure_override( @@ -1094,7 +1070,7 @@ static void test_metadata_plugin_success(void) { run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); grpc_call_credentials_unref(creds); - grpc_exec_ctx_finish(); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } @@ -1122,7 +1098,7 @@ static void test_metadata_plugin_failure(void) { run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); grpc_call_credentials_unref(creds); - grpc_exec_ctx_finish(); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } @@ -1167,8 +1143,6 @@ static void test_channel_creds_duplicate_without_call_creds(void) { grpc_channel_credentials_unref(channel_creds); grpc_channel_credentials_unref(composite_creds); - - grpc_exec_ctx_finish(); } typedef struct { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 7052925944..9eac2b9254 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -224,7 +224,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_free(b64); *scratchpad = decoded; grpc_slice_unref(slice); - grpc_exec_ctx_finish(); + return json; } @@ -348,8 +348,6 @@ static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, grpc_slice_unref_internal(sig); if (key != NULL) EVP_PKEY_free(key); if (md_ctx != NULL) EVP_MD_CTX_destroy(md_ctx); - - grpc_exec_ctx_finish(); } static char* service_account_creds_jwt_encode_and_sign( diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index 16fad9d45e..7485aa10b4 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -220,7 +220,6 @@ static void test_claims_success(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_OK); grpc_jwt_claims_destroy(claims); - grpc_exec_ctx_finish(); } static void test_expired_claims_failure(void) { @@ -247,7 +246,6 @@ static void test_expired_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE); grpc_jwt_claims_destroy(claims); - grpc_exec_ctx_finish(); } static void test_invalid_claims_failure(void) { @@ -256,7 +254,6 @@ static void test_invalid_claims_failure(void) { (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == NULL); - grpc_exec_ctx_finish(); } static void test_bad_audience_claims_failure(void) { @@ -271,7 +268,6 @@ static void test_bad_audience_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == GRPC_JWT_VERIFIER_BAD_AUDIENCE); grpc_jwt_claims_destroy(claims); - grpc_exec_ctx_finish(); } static void test_bad_subject_claims_failure(void) { @@ -286,7 +282,6 @@ static void test_bad_subject_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_BAD_SUBJECT); grpc_jwt_claims_destroy(claims); - grpc_exec_ctx_finish(); } static char* json_key_str(const char* last_part) { @@ -371,7 +366,7 @@ static void test_jwt_verifier_google_email_issuer_success(void) { grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, on_verification_success, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_free(jwt); grpc_httpcli_set_override(NULL, NULL); } @@ -404,7 +399,7 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, on_verification_success, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_free(jwt); grpc_httpcli_set_override(NULL, NULL); } @@ -451,7 +446,7 @@ static void test_jwt_verifier_url_issuer_success(void) { grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, on_verification_success, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_free(jwt); grpc_httpcli_set_override(NULL, NULL); } @@ -491,7 +486,7 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { on_verification_key_retrieval_error, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_free(jwt); grpc_httpcli_set_override(NULL, NULL); } @@ -514,7 +509,7 @@ static void test_jwt_verifier_bad_json_key(void) { on_verification_key_retrieval_error, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_free(jwt); grpc_httpcli_set_override(NULL, NULL); } @@ -528,7 +523,6 @@ static void corrupt_jwt_sig(char* jwt) { { ExecCtx _local_exec_ctx; sig = grpc_base64_decode(last_dot + 1, 1); - grpc_exec_ctx_finish(); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); sig_bytes = GRPC_SLICE_START_PTR(sig); @@ -568,7 +562,7 @@ static void test_jwt_verifier_bad_signature(void) { (void*)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + grpc_httpcli_set_override(NULL, NULL); } @@ -597,7 +591,7 @@ static void test_jwt_verifier_bad_format(void) { on_verification_bad_format, (void*)expected_user_data); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + grpc_httpcli_set_override(NULL, NULL); } diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 6104c7e9dd..f4a52aaba0 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -92,7 +92,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( on_oauth2_response(&request, error); GRPC_ERROR_UNREF(error); } - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(request.mu); while (!request.is_done) { @@ -108,7 +108,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_pollset_shutdown(grpc_polling_entity_pollset(&request.pops), &do_nothing_closure); - grpc_exec_ctx_finish(); + gpr_free(grpc_polling_entity_pollset(&request.pops)); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 6ea51658e1..6153e8a9cb 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -111,13 +111,11 @@ int main(int argc, char** argv) { GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); - grpc_exec_ctx_finish(); - grpc_channel_credentials_release(creds); gpr_free(grpc_polling_entity_pollset(&sync.pops)); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index a72329d504..a49bf1a0b4 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -115,7 +115,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( f.server_ep = grpc_secure_endpoint_create(fake_write_protector, fake_write_zero_copy_protector, tcp.server, NULL, 0); - grpc_exec_ctx_finish(); + return f; } @@ -178,7 +178,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_slice_buffer_init(&incoming); GRPC_CLOSURE_INIT(&done_closure, inc_call_ctr, &n, grpc_schedule_on_exec_ctx); grpc_endpoint_read(f.client_ep, &incoming, &done_closure); - grpc_exec_ctx_finish(); + GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); @@ -189,7 +189,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { f.server_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); grpc_endpoint_destroy(f.client_ep); grpc_endpoint_destroy(f.server_ep); - grpc_exec_ctx_finish(); + grpc_slice_unref_internal(s); grpc_slice_buffer_destroy_internal(&incoming); @@ -215,7 +215,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index 3ee7738ea8..84a42546c6 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -83,7 +83,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_security_status status = grpc_server_credentials_create_security_connector(creds, &sc); GPR_ASSERT(status == GRPC_SECURITY_OK); - grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(); + grpc_millis deadline = GPR_MS_PER_SEC + ExecCtx::Get()->Now(); struct handshake_state state; state.done_callback_called = false; @@ -92,7 +92,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_handshake_manager_do_handshake( handshake_mgr, mock_endpoint, NULL /* channel_args */, deadline, NULL /* acceptor */, on_handshake_done, &state); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); // If the given string happens to be part of the correct client hello, the // server will wait for more data. Explicitly fail the server by shutting down @@ -100,7 +100,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (!state.done_callback_called) { grpc_endpoint_shutdown( mock_endpoint, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GPR_ASSERT(state.done_callback_called); @@ -111,7 +111,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(cert_slice); grpc_slice_unref(key_slice); grpc_slice_unref(ca_slice); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_shutdown(); if (leak_check) { diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index fce1e9d8de..f3e8966625 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -106,7 +106,7 @@ int main(int argc, char** argv) { grpc_pollset_work(sync.pollset, &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); @@ -114,7 +114,7 @@ int main(int argc, char** argv) { gpr_free(sync.pollset); grpc_jwt_verifier_destroy(verifier); - grpc_exec_ctx_finish(); + gpr_cmdline_destroy(cl); grpc_shutdown(); return !sync.success; diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 3f1de9bc12..5ed9910740 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -51,7 +51,7 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { GRPC_SLICE_LENGTH(hello_slice)) == 0); grpc_slice_unref_internal(hello_slice); - grpc_exec_ctx_finish(); + gpr_free(hello_b64); } @@ -72,7 +72,6 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { sizeof(orig) - i)); grpc_slice_unref_internal(orig_decoded); gpr_free(b64); - grpc_exec_ctx_finish(); } } @@ -128,7 +127,6 @@ static void test_url_safe_unsafe_mismatch_failure(void) { GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); grpc_slice_unref_internal(orig_decoded); - grpc_exec_ctx_finish(); } static void test_rfc4648_test_vectors(void) { @@ -199,7 +197,6 @@ static void test_unpadded_decode(void) { decoded = grpc_base64_decode("", 0); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded)); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index b5b9c1bb73..89fc33a7bf 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -121,7 +121,6 @@ static void test_slice_hash_table() { // Clean up. ExecCtx _local_exec_ctx; grpc_slice_hash_table_unref(table); - grpc_exec_ctx_finish(); } static int value_cmp_fn(void* a, void* b) { @@ -150,7 +149,6 @@ static void test_slice_hash_table_eq() { ExecCtx _local_exec_ctx; grpc_slice_hash_table_unref(table_a); grpc_slice_hash_table_unref(table_b); - grpc_exec_ctx_finish(); } static void test_slice_hash_table_not_eq() { @@ -229,7 +227,6 @@ static void test_slice_hash_table_not_eq() { grpc_slice_hash_table_unref(table_f); grpc_slice_hash_table_unref(table_g); grpc_slice_hash_table_unref(table_h); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index 0ac4018a9e..1f3a83efe6 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -134,7 +134,6 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, { ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); - grpc_exec_ctx_finish(); } buffer = grpc_raw_compressed_byte_buffer_create(sliceb_out.slices, diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index 516a55275a..ece06e4968 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -39,7 +39,6 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx_finish(); grpc_channel_destroy(chan); } diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index f014738f4c..39aedeba02 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -151,7 +151,6 @@ static void test_cq_end_op(void) { GPR_ASSERT(ev.success); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(); } } @@ -193,7 +192,6 @@ static void test_cq_tls_cache_full(void) { GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(); } } @@ -221,7 +219,6 @@ static void test_cq_tls_cache_empty(void) { GPR_ASSERT( grpc_completion_queue_thread_local_cache_flush(cc, &res_tag, &ok) == 0); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(); } } @@ -322,7 +319,6 @@ static void test_pluck(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(); } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 43e90029bc..6625e7e09f 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -116,7 +116,6 @@ static void test_too_many_plucks(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(); } #define TEST_THREAD_EVENTS 10000 @@ -165,12 +164,10 @@ static void producer_thread(void* arg) { static_cast( gpr_malloc(sizeof(grpc_cq_completion)))); opt->events_triggered++; - grpc_exec_ctx_finish(); } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); gpr_event_set(&opt->on_finished, (void*)(intptr_t)1); - grpc_exec_ctx_finish(); } static void consumer_thread(void* arg) { diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 62fb58dcbc..b3999b481f 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -134,7 +134,7 @@ void bad_server_thread(void* vargs) { gpr_mu_lock(args->mu); while (gpr_atm_acq_load(&args->stop) == 0) { - grpc_millis deadline = grpc_exec_ctx_now() + 100; + grpc_millis deadline = ExecCtx::Get()->Now() + 100; grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( @@ -143,15 +143,13 @@ void bad_server_thread(void* vargs) { gpr_atm_rel_store(&args->stop, 1); } gpr_mu_unlock(args->mu); - grpc_exec_ctx_finish(); + gpr_mu_lock(args->mu); } gpr_mu_unlock(args->mu); grpc_tcp_server_unref(s); - grpc_exec_ctx_finish(); - gpr_free(args->addr); } @@ -228,7 +226,6 @@ int run_concurrent_connectivity_test() { grpc_pollset_shutdown(args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(); grpc_shutdown(); return 0; diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 7104d2e30a..dd14a03577 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -54,13 +54,11 @@ void test_transport_op(grpc_channel* channel) { op->connectivity_state = &state; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); elem->filter->start_transport_op(elem, op); - grpc_exec_ctx_finish(); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, NULL, grpc_schedule_on_exec_ctx); op = grpc_make_transport_op(&transport_op_cb); elem->filter->start_transport_op(elem, op); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index e7cde7e39b..bf51dac6dd 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -180,7 +180,6 @@ static grpc_channel* secure_test_create_channel(const char* addr) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); - grpc_exec_ctx_finish(); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index 9a4ac1f0bd..dd9f907652 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -40,7 +40,6 @@ void test_unknown_scheme_target(void) { ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); grpc_channel_credentials_unref(creds); - grpc_exec_ctx_finish(); } void test_security_connector_already_in_arg(void) { @@ -57,7 +56,6 @@ void test_security_connector_already_in_arg(void) { GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); - grpc_exec_ctx_finish(); } void test_null_creds(void) { @@ -67,7 +65,6 @@ void test_null_creds(void) { GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index f88124e4ae..aae418cedb 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -158,7 +158,6 @@ static grpc_channel* secure_test_create_channel(const char* addr) { { ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); - grpc_exec_ctx_finish(); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index ca29b82616..4d41ece875 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -66,9 +66,8 @@ void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { } gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1, GPR_TIMESPAN))); - grpc_exec_ctx_invalidate_now(); + ExecCtx::Get()->InvalidateNow(); estimator->CompletePing(); - grpc_exec_ctx_finish(); } void AddSample(BdpEstimator* estimator, int64_t sample) { diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index af6abaeeed..12a933f332 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -66,7 +66,6 @@ static void test_slice_buffer_stream_basic(void) { // Clean up. grpc_byte_stream_destroy(&stream.base); grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } static void test_slice_buffer_stream_shutdown(void) { @@ -109,7 +108,6 @@ static void test_slice_buffer_stream_shutdown(void) { // Clean up. grpc_byte_stream_destroy(&stream.base); grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } // @@ -153,7 +151,6 @@ static void test_caching_byte_stream_basic(void) { grpc_byte_stream_destroy(&stream.base); grpc_byte_stream_cache_destroy(&cache); grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } static void test_caching_byte_stream_reset(void) { @@ -200,7 +197,6 @@ static void test_caching_byte_stream_reset(void) { grpc_byte_stream_destroy(&stream.base); grpc_byte_stream_cache_destroy(&cache); grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } static void test_caching_byte_stream_shared_cache(void) { @@ -254,7 +250,6 @@ static void test_caching_byte_stream_shared_cache(void) { grpc_byte_stream_destroy(&stream2.base); grpc_byte_stream_cache_destroy(&cache); grpc_slice_buffer_destroy_internal(&buffer); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 663ccf189b..3d463c40a5 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -129,7 +129,5 @@ int main(int argc, char** argv) { EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); - grpc_exec_ctx_finish(); - return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index e1bfcc5b37..fe4538339e 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -261,7 +261,6 @@ static void run_test(void (*test)(), const char* name) { grpc_chttp2_hpack_compressor_init(&g_compressor); test(); grpc_chttp2_hpack_compressor_destroy(&g_compressor); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index d2199ca706..feb27fc0ff 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -43,7 +43,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( &parser, grpc_slice_from_static_buffer(data, size))); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_exec_ctx_finish(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 0a3cbf84ad..69a13108f9 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -65,7 +65,6 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); - grpc_exec_ctx_finish(); } for (i = 0; i < nslices; i++) { @@ -204,8 +203,6 @@ static void test_vectors(grpc_slice_split_mode mode) { "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); grpc_chttp2_hpack_parser_destroy(&parser); - - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index 68682f1991..fd5604d857 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -113,7 +113,6 @@ static void test_static_lookup(void) { assert_index(&tbl, 61, "www-authenticate", ""); grpc_chttp2_hptbl_destroy(&tbl); - grpc_exec_ctx_finish(); } static void test_many_additions(void) { @@ -148,7 +147,6 @@ static void test_many_additions(void) { } grpc_chttp2_hptbl_destroy(&tbl); - grpc_exec_ctx_finish(); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, @@ -159,7 +157,7 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); GRPC_MDELEM_UNREF(md); - grpc_exec_ctx_finish(); + return r; } @@ -266,7 +264,6 @@ static void test_find(void) { GPR_ASSERT(r.has_value == 0); grpc_chttp2_hptbl_destroy(&tbl); - grpc_exec_ctx_finish(); } int main(int argc, char** argv) { diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 92bf1ba903..8ddd8bb2df 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -66,7 +66,6 @@ static void test_check(void) { GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); GPR_ASSERT(error == GRPC_ERROR_NONE); grpc_connectivity_state_destroy(&tracker); - grpc_exec_ctx_finish(); } static void test_subscribe_then_unsubscribe(void) { @@ -80,16 +79,15 @@ static void test_subscribe_then_unsubscribe(void) { grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, closure)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_notify_on_state_change(&tracker, NULL, closure); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 1); grpc_connectivity_state_destroy(&tracker); - grpc_exec_ctx_finish(); } static void test_subscribe_then_destroy(void) { @@ -103,11 +101,11 @@ static void test_subscribe_then_destroy(void) { grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, closure)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_destroy(&tracker); - grpc_exec_ctx_finish(); + GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } @@ -123,11 +121,11 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( &tracker, &state, closure)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_destroy(&tracker); - grpc_exec_ctx_finish(); + GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 4bc5672958..3d7034e4ce 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -80,7 +80,7 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { GRPC_MDELEM_UNREF(m1); GRPC_MDELEM_UNREF(m2); GRPC_MDELEM_UNREF(m3); - grpc_exec_ctx_finish(); + grpc_shutdown(); } @@ -103,7 +103,7 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); } - grpc_exec_ctx_finish(); + grpc_shutdown(); } @@ -138,7 +138,7 @@ static void test_create_many_persistant_metadata(void) { for (i = 0; i < MANY; i++) { GRPC_MDELEM_UNREF(created[i]); } - grpc_exec_ctx_finish(); + grpc_shutdown(); gpr_free(created); @@ -169,7 +169,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys, GPR_ASSERT(a.payload == b.payload); GPR_ASSERT(a.payload == c.payload); } - grpc_exec_ctx_finish(); + grpc_shutdown(); } @@ -209,7 +209,7 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { GRPC_MDELEM_UNREF(a); GRPC_MDELEM_UNREF(b); GRPC_MDELEM_UNREF(c); - grpc_exec_ctx_finish(); + grpc_shutdown(); } @@ -259,7 +259,6 @@ static void test_things_stick_around(void) { } } - grpc_exec_ctx_finish(); grpc_shutdown(); gpr_free(strs); gpr_free(shuf); @@ -284,7 +283,7 @@ static void test_user_data_works(void) { grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); GRPC_MDELEM_UNREF(md); - grpc_exec_ctx_finish(); + grpc_shutdown(); } @@ -340,7 +339,6 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { intern_value); } - grpc_exec_ctx_finish(); grpc_shutdown(); } @@ -366,7 +364,6 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { GRPC_MDELEM_UNREF(q); } - grpc_exec_ctx_finish(); grpc_shutdown(); } diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 44e961310a..16ecd076a3 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -26,7 +26,7 @@ do { \ ExecCtx _local_exec_ctx; \ GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ - grpc_exec_ctx_finish(); \ + \ } while (0) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 2cabd560ee..4e68ee3744 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -85,19 +85,19 @@ void grpc_free_port_using_server(int port) { grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/free"); grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now() + 30 * GPR_MS_PER_SEC, + ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); grpc_resource_quota_unref_internal(resource_quota); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&pr.pops), &worker, - grpc_exec_ctx_now() + GPR_MS_PER_SEC))) { + ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.done = 1; } } @@ -106,7 +106,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_context_destroy(&context); grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), shutdown_closure); - grpc_exec_ctx_finish(); + gpr_free(path); grpc_http_response_destroy(&rsp); @@ -167,7 +167,7 @@ static void got_port_from_server(void* arg, grpc_error* error) { grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/pick_retry"); grpc_httpcli_get(pr->ctx, &pr->pops, resource_quota, &req, - grpc_exec_ctx_now() + 30 * GPR_MS_PER_SEC, + ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, pr, grpc_schedule_on_exec_ctx), &pr->response); @@ -217,18 +217,18 @@ int grpc_pick_port_using_server(void) { grpc_resource_quota_create("port_server_client/pick"); grpc_httpcli_get( &context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now() + 30 * GPR_MS_PER_SEC, + ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), &pr.response); grpc_resource_quota_unref_internal(resource_quota); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (pr.port == -1) { grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&pr.pops), &worker, - grpc_exec_ctx_now() + GPR_MS_PER_SEC))) { + ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.port = 0; } } @@ -238,7 +238,7 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context_destroy(&context); grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), shutdown_closure); - grpc_exec_ctx_finish(); + grpc_shutdown(); return pr.port; diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index 79178a7cbd..7e17ff1f53 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -72,8 +72,6 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_tcp_server_start(server->tcp_server, &server->pollset, 1, server->on_connect, server->cb_data); gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port); - - grpc_exec_ctx_finish(); } void test_tcp_server_poll(test_tcp_server* server, int seconds) { @@ -85,7 +83,6 @@ void test_tcp_server_poll(test_tcp_server* server, int seconds) { GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(server->pollset, &worker, deadline)); gpr_mu_unlock(server->mu); - grpc_exec_ctx_finish(); } static void do_nothing(void* arg, grpc_error* error) {} @@ -109,7 +106,7 @@ void test_tcp_server_destroy(test_tcp_server* server) { grpc_pollset_shutdown(server->pollset, GRPC_CLOSURE_CREATE(finish_pollset, server->pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(); + gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index df2ed0ecd0..4cf39eab48 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -133,7 +133,6 @@ class ClientLbEnd2endTest : public ::testing::Test { fake_result); grpc_channel_args_destroy(fake_result); grpc_lb_addresses_destroy(addresses); - grpc_exec_ctx_finish(); } void ResetStub(const grpc::string& lb_policy_name = "") { diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 62d7094d4c..962d5a7e68 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -470,7 +470,6 @@ class GrpclbEnd2endTest : public ::testing::Test { grpc_fake_resolver_response_generator_set_response(response_generator_, &fake_result); grpc_lb_addresses_destroy(addresses); - grpc_exec_ctx_finish(); } const std::vector GetBackendPorts(const size_t start_index = 0) const { diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index c2c6c0b337..6f6dd3c4df 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -603,7 +603,6 @@ static void setup_client(const server_fixture* lb_server, grpc_channel_credentials_unref(fake_creds); grpc_channel_args_destroy(args); grpc_fake_resolver_response_generator_unref(response_generator); - grpc_exec_ctx_finish(); } static void teardown_client(client_fixture* cf) { diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index eac1c753c7..47b984bc28 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -534,7 +534,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { ? &dummy_transport::dummy_transport : nullptr, "CHANNEL", channel_stack))); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_call_stack* call_stack = static_cast(gpr_zalloc(channel_stack->call_stack_size)); grpc_millis deadline = GRPC_MILLIS_INF_FUTURE; @@ -558,7 +558,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { typename TestOp::Op op(&test_op_data, call_stack); grpc_call_stack_destroy(call_stack, &final_info, NULL); op.Finish(); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); // recreate arena every 64k iterations to avoid oom if (0 == (state.iterations() & 0xffff)) { gpr_arena_destroy(call_args.arena); @@ -567,7 +567,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { } gpr_arena_destroy(call_args.arena); grpc_channel_stack_destroy(channel_stack); - grpc_exec_ctx_finish(); + gpr_free(channel_stack); gpr_free(call_stack); @@ -693,7 +693,6 @@ class IsolatedCallFixture : public TrackCounters { { ExecCtx _local_exec_ctx; channel_ = grpc_channel_create_with_builder(builder, GRPC_CLIENT_CHANNEL); - grpc_exec_ctx_finish(); } cq_ = grpc_completion_queue_create_for_next(NULL); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index d6fb3cd369..f822f095a7 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -55,9 +55,9 @@ static void BM_HpackEncoderInitDestroy(benchmark::State& state) { while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); grpc_chttp2_hpack_compressor_destroy(&c); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_HpackEncoderInitDestroy); @@ -65,7 +65,7 @@ BENCHMARK(BM_HpackEncoderInitDestroy); static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { TrackCounters track_counters; ExecCtx _local_exec_ctx; - grpc_millis saved_now = grpc_exec_ctx_now(); + grpc_millis saved_now = ExecCtx::Get()->Now(); grpc_metadata_batch b; grpc_metadata_batch_init(&b); @@ -87,12 +87,11 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { }; grpc_chttp2_encode_header(&c, NULL, 0, &b, &hopt, &outbuf); grpc_slice_buffer_reset_and_unref_internal(&outbuf); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } grpc_metadata_batch_destroy(&b); grpc_chttp2_hpack_compressor_destroy(&c); grpc_slice_buffer_destroy_internal(&outbuf); - grpc_exec_ctx_finish(); std::ostringstream label; label << "framing_bytes/iter:" @@ -145,12 +144,11 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { } } grpc_slice_buffer_reset_and_unref_internal(&outbuf); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } grpc_metadata_batch_destroy(&b); grpc_chttp2_hpack_compressor_destroy(&c); grpc_slice_buffer_destroy_internal(&outbuf); - grpc_exec_ctx_finish(); std::ostringstream label; label << "framing_bytes/iter:" @@ -432,9 +430,9 @@ static void BM_HpackParserInitDestroy(benchmark::State& state) { while (state.KeepRunning()) { grpc_chttp2_hpack_parser_init(&p); grpc_chttp2_hpack_parser_destroy(&p); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_HpackParserInitDestroy); @@ -460,12 +458,12 @@ static void BM_HpackParserParseHeader(benchmark::State& state) { for (auto slice : benchmark_slices) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); } - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } for (auto slice : init_slices) grpc_slice_unref(slice); for (auto slice : benchmark_slices) grpc_slice_unref(slice); grpc_chttp2_hpack_parser_destroy(&p); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index 3a3547141d..f6e4c2bcc4 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -136,12 +136,9 @@ class Fixture { FlushExecCtx(); } - void FlushExecCtx() { grpc_exec_ctx_flush(); } + void FlushExecCtx() { ExecCtx::Get()->Flush(); } - ~Fixture() { - grpc_transport_destroy(t_); - grpc_exec_ctx_finish(); - } + ~Fixture() { grpc_transport_destroy(t_); } grpc_chttp2_transport* chttp2_transport() { return reinterpret_cast(t_); @@ -152,7 +149,6 @@ class Fixture { private: DummyEndpoint* ep_; - ExecCtx _local_exec_ctx; grpc_transport* t_; }; @@ -261,6 +257,7 @@ class Stream { static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; + ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -306,6 +303,7 @@ class RepresentativeClientInitialMetadata { template static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; + ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -356,6 +354,7 @@ BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; + ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -388,6 +387,7 @@ std::vector> done_events; static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; + ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr(new Stream(&f)); s->Init(state); @@ -517,6 +517,7 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; + ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index 0e25c3d235..ce8a054515 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -35,7 +35,6 @@ static void BM_NoOpExecCtx(benchmark::State& state) { TrackCounters track_counters; while (state.KeepRunning()) { ExecCtx _local_exec_ctx; - grpc_exec_ctx_finish(); } track_counters.Finish(state); } @@ -45,9 +44,9 @@ static void BM_WellFlushed(benchmark::State& state) { TrackCounters track_counters; ExecCtx _local_exec_ctx; while (state.KeepRunning()) { - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_WellFlushed); @@ -75,7 +74,7 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { &c, DoNothing, NULL, grpc_combiner_scheduler(combiner))); } GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAgainstCombiner); @@ -87,9 +86,9 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureRunOnExecCtx); @@ -102,7 +101,7 @@ static void BM_ClosureCreateAndRun(benchmark::State& state) { GRPC_CLOSURE_CREATE(DoNothing, NULL, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureCreateAndRun); @@ -116,7 +115,7 @@ static void BM_ClosureInitAndRun(benchmark::State& state) { GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAndRun); @@ -128,9 +127,9 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnExecCtx); @@ -145,9 +144,9 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnExecCtx); @@ -165,9 +164,9 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnExecCtx); @@ -183,7 +182,7 @@ static void BM_AcquireMutex(benchmark::State& state) { DoNothing(NULL, GRPC_ERROR_NONE); gpr_mu_unlock(&mu); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_AcquireMutex); @@ -202,7 +201,7 @@ static void BM_TryAcquireMutex(benchmark::State& state) { abort(); } } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_TryAcquireMutex); @@ -217,7 +216,7 @@ static void BM_AcquireSpinlock(benchmark::State& state) { DoNothing(NULL, GRPC_ERROR_NONE); gpr_spinlock_unlock(&mu); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_AcquireSpinlock); @@ -235,7 +234,7 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) { abort(); } } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_TryAcquireSpinlock); @@ -248,10 +247,10 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnCombiner); @@ -267,10 +266,10 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnCombiner); @@ -289,10 +288,10 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnCombiner); @@ -309,11 +308,11 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner1, "finished"); GRPC_COMBINER_UNREF(combiner2, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnTwoCombiners); @@ -336,11 +335,11 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c4, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner1, "finished"); GRPC_COMBINER_UNREF(combiner2, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched4OnTwoCombiners); @@ -379,7 +378,7 @@ static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { ExecCtx _local_exec_ctx; Rescheduler r(state, grpc_schedule_on_exec_ctx); r.ScheduleFirst(); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnExecCtx); @@ -390,9 +389,9 @@ static void BM_ClosureReschedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_scheduler(combiner)); r.ScheduleFirst(); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombiner); @@ -403,9 +402,9 @@ static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_finally_scheduler(combiner)); r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner)); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); GRPC_COMBINER_UNREF(combiner, "finished"); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombinerFinally); diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index 6d36e61cff..9fb603213a 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -84,7 +84,7 @@ static void BM_Pass1Cpp(benchmark::State& state) { GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag)); grpc_cq_end_op(c_cq, &dummy_tag, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); - grpc_exec_ctx_finish(); + void* tag; bool ok; cq.Next(&tag, &ok); @@ -104,7 +104,7 @@ static void BM_Pass1Core(benchmark::State& state) { GPR_ASSERT(grpc_cq_begin_op(cq, NULL)); grpc_cq_end_op(cq, NULL, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); - grpc_exec_ctx_finish(); + grpc_completion_queue_next(cq, deadline, NULL); } grpc_completion_queue_destroy(cq); @@ -123,7 +123,7 @@ static void BM_Pluck1Core(benchmark::State& state) { GPR_ASSERT(grpc_cq_begin_op(cq, NULL)); grpc_cq_end_op(cq, NULL, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); - grpc_exec_ctx_finish(); + grpc_completion_queue_pluck(cq, NULL, deadline, NULL); } grpc_completion_queue_destroy(cq); diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 41e616a6ef..0cd9a2c361 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -76,7 +76,7 @@ static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, NULL, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; } diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index 3f85e351f5..8dc98ab923 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -253,7 +253,7 @@ static void BM_ErrorGetStatus(benchmark::State& state) { grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice, NULL); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } @@ -267,7 +267,7 @@ static void BM_ErrorGetStatusCode(benchmark::State& state) { grpc_error_get_status(fixture.error(), fixture.deadline(), &status, NULL, NULL); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } @@ -281,7 +281,7 @@ static void BM_ErrorHttpError(benchmark::State& state) { grpc_error_get_status(fixture.error(), fixture.deadline(), NULL, NULL, &error); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 74e99982ce..191c93c58d 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -183,7 +183,7 @@ class TrickledCHTTP2 : public EndpointPairFixture { grpc_trickle_endpoint_trickle(endpoint_pair_.client); size_t server_backlog = grpc_trickle_endpoint_trickle(endpoint_pair_.server); - grpc_exec_ctx_finish(); + if (update_stats) { UpdateStats((grpc_chttp2_transport*)client_transport_, &client_stats_, client_backlog); diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc index 5d89e0d3c6..07fcf6af99 100644 --- a/test/cpp/microbenchmarks/bm_metadata.cc +++ b/test/cpp/microbenchmarks/bm_metadata.cc @@ -94,7 +94,7 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) { while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlices); @@ -107,7 +107,7 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) { while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -125,7 +125,7 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex( GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } GRPC_MDELEM_UNREF(seed); - grpc_exec_ctx_finish(); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -140,7 +140,7 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) { while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -157,7 +157,7 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore( GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlicesWithBackingStore); @@ -173,7 +173,7 @@ static void BM_MetadataFromInternedSlicesWithBackingStore( GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -191,7 +191,7 @@ static void BM_MetadataFromInternedKeyWithBackingStore( GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -205,7 +205,7 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) { while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -220,7 +220,7 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed( while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } - grpc_exec_ctx_finish(); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -237,7 +237,7 @@ static void BM_MetadataRefUnrefExternal(benchmark::State& state) { GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } GRPC_MDELEM_UNREF(el); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefExternal); @@ -256,7 +256,7 @@ static void BM_MetadataRefUnrefInterned(benchmark::State& state) { GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } GRPC_MDELEM_UNREF(el); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefInterned); @@ -270,7 +270,7 @@ static void BM_MetadataRefUnrefAllocated(benchmark::State& state) { GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } GRPC_MDELEM_UNREF(el); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefAllocated); @@ -283,7 +283,7 @@ static void BM_MetadataRefUnrefStatic(benchmark::State& state) { GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } GRPC_MDELEM_UNREF(el); - grpc_exec_ctx_finish(); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefStatic); diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index 3da8e16788..7ddca45eca 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -60,9 +60,9 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { gpr_mu_lock(mu); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(); + gpr_free(ps); track_counters.Finish(state); } @@ -124,7 +124,7 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(); + gpr_free(ps); track_counters.Finish(state); } @@ -143,7 +143,7 @@ static void BM_PollAddFd(benchmark::State& state) { grpc_fd* fd = grpc_fd_create(wakeup_fd.read_fd, "xxx"); while (state.KeepRunning()) { grpc_pollset_add_fd(ps, fd); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); } grpc_fd_orphan(fd, NULL, NULL, false /* already_closed */, "xxx"); grpc_closure shutdown_ps_closure; @@ -152,7 +152,7 @@ static void BM_PollAddFd(benchmark::State& state) { gpr_mu_lock(mu); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(); + gpr_free(ps); track_counters.Finish(state); } @@ -248,7 +248,7 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(); + grpc_wakeup_fd_destroy(&wakeup_fd); gpr_free(ps); track_counters.Finish(state); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 24b74b9d37..075064eca7 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -205,8 +205,6 @@ class EndpointPairFixture : public BaseFixture { channel_ = CreateChannelInternal("", channel); } - - grpc_exec_ctx_finish(); } virtual ~EndpointPairFixture() { diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 836cc676c2..8ba8be0ea4 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -171,7 +171,7 @@ void ArgsFinish(ArgsStruct* args) { grpc_pollset_shutdown(args->pollset, &DoNothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() grpc_channel_args_destroy(args->channel_args); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); GRPC_COMBINER_UNREF(args->lock, NULL); @@ -202,7 +202,6 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { grpc_timespec_to_millis_round_up( NSecondDeadline(1)))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_finish(); } gpr_event_set(&args->ev, (void*)1); } @@ -295,11 +294,10 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecords) { (void*)&args, grpc_combiner_scheduler(args.lock)); grpc_resolver_next_locked(resolver, &args.channel_args, &on_resolver_result_changed); - grpc_exec_ctx_flush(); + ExecCtx::Get()->Flush(); PollPollsetUntilRequestDone(&args); GRPC_RESOLVER_UNREF(resolver, NULL); ArgsFinish(&args); - grpc_exec_ctx_finish(); } } // namespace diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index b05da25e1d..b9514e6306 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -120,8 +120,6 @@ class EndpointPairFixture { channel_ = CreateChannelInternal("", channel); } - - grpc_exec_ctx_finish(); } virtual ~EndpointPairFixture() { -- cgit v1.2.3 From 6c26b16fe06b1cc75b4dac372f4f51f6b7d1bfc0 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 14 Nov 2017 18:11:22 -0800 Subject: Move ExecCtx to grpc_core namespace. Make exec_ctx a private static in ExecCtx and some minor changes --- .../ext/filters/client_channel/backup_poller.cc | 8 +- .../filters/client_channel/channel_connectivity.cc | 4 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 9 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 2 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 2 +- .../resolver/dns/native/dns_resolver.cc | 2 +- src/core/ext/filters/client_channel/subchannel.cc | 3 +- .../ext/filters/client_channel/subchannel_index.cc | 39 +++---- src/core/ext/filters/max_age/max_age_filter.cc | 20 ++-- .../chttp2/client/insecure/channel_create.cc | 2 +- .../chttp2/client/insecure/channel_create_posix.cc | 2 +- .../chttp2/client/secure/secure_channel_create.cc | 2 +- .../ext/transport/chttp2/server/chttp2_server.cc | 7 +- .../chttp2/server/insecure/server_chttp2.cc | 2 +- .../chttp2/server/insecure/server_chttp2_posix.cc | 2 +- .../chttp2/server/secure/server_secure_chttp2.cc | 2 +- .../transport/chttp2/transport/chttp2_transport.cc | 10 +- .../ext/transport/chttp2/transport/flow_control.cc | 4 +- .../ext/transport/chttp2/transport/frame_ping.cc | 2 +- .../transport/chttp2/transport/hpack_encoder.cc | 3 +- src/core/ext/transport/chttp2/transport/parsing.cc | 2 +- src/core/ext/transport/chttp2/transport/writing.cc | 2 +- .../cronet/client/secure/cronet_channel_create.cc | 2 +- .../transport/cronet/transport/cronet_transport.cc | 16 +-- src/core/ext/transport/inproc/inproc_transport.cc | 6 +- src/core/lib/backoff/backoff.cc | 4 +- .../lib/compression/stream_compression_gzip.cc | 2 +- src/core/lib/debug/stats.h | 2 +- src/core/lib/iomgr/block_annotate.h | 14 +-- src/core/lib/iomgr/combiner.cc | 43 ++++---- src/core/lib/iomgr/endpoint_pair_posix.cc | 2 +- src/core/lib/iomgr/endpoint_pair_windows.cc | 2 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 20 ++-- src/core/lib/iomgr/ev_epollex_linux.cc | 10 +- src/core/lib/iomgr/ev_epollsig_linux.cc | 6 +- src/core/lib/iomgr/ev_poll_posix.cc | 8 +- src/core/lib/iomgr/exec_ctx.cc | 109 +++++++++----------- src/core/lib/iomgr/exec_ctx.h | 68 +++++++++++-- src/core/lib/iomgr/executor.cc | 12 ++- src/core/lib/iomgr/iocp_windows.cc | 13 +-- src/core/lib/iomgr/iomgr.cc | 10 +- src/core/lib/iomgr/iomgr_uv.cc | 2 +- src/core/lib/iomgr/pollset_uv.cc | 4 +- src/core/lib/iomgr/pollset_windows.cc | 8 +- src/core/lib/iomgr/resolve_address_uv.cc | 2 +- src/core/lib/iomgr/resource_quota.cc | 4 +- src/core/lib/iomgr/tcp_client_uv.cc | 4 +- src/core/lib/iomgr/tcp_posix.cc | 2 +- src/core/lib/iomgr/tcp_server_uv.cc | 8 +- src/core/lib/iomgr/tcp_uv.cc | 10 +- src/core/lib/iomgr/timer_generic.cc | 8 +- src/core/lib/iomgr/timer_manager.cc | 10 +- src/core/lib/iomgr/timer_uv.cc | 6 +- src/core/lib/security/context/security_context.cc | 4 +- src/core/lib/security/credentials/credentials.cc | 6 +- .../google_default/google_default_credentials.cc | 10 +- .../security/credentials/iam/iam_credentials.cc | 2 +- .../security/credentials/jwt/jwt_credentials.cc | 2 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 11 +- .../credentials/oauth2/oauth2_credentials.cc | 9 +- .../credentials/plugin/plugin_credentials.cc | 4 +- .../lib/security/transport/security_handshaker.cc | 2 +- .../lib/security/transport/server_auth_filter.cc | 2 +- src/core/lib/slice/slice.cc | 2 +- src/core/lib/slice/slice_buffer.cc | 4 +- src/core/lib/surface/alarm.cc | 6 +- src/core/lib/surface/byte_buffer.cc | 2 +- src/core/lib/surface/byte_buffer_reader.cc | 4 +- src/core/lib/surface/call.cc | 8 +- src/core/lib/surface/call_details.cc | 2 +- src/core/lib/surface/channel.cc | 10 +- src/core/lib/surface/channel_ping.cc | 2 +- src/core/lib/surface/completion_queue.cc | 24 ++--- src/core/lib/surface/init.cc | 4 +- src/core/lib/surface/lame_client.cc | 2 +- src/core/lib/surface/server.cc | 12 +-- src/core/lib/transport/bdp_estimator.cc | 2 +- src/core/lib/transport/status_conversion.cc | 5 +- src/core/lib/transport/transport.cc | 3 +- src/cpp/common/channel_arguments.cc | 4 +- test/core/backoff/backoff_test.cc | 60 ++++++----- test/core/bad_client/bad_client.cc | 4 +- test/core/channel/channel_args_test.cc | 8 +- test/core/channel/channel_stack_test.cc | 4 +- test/core/channel/minimal_stack_is_minimal_test.cc | 4 +- test/core/client_channel/lb_policies_test.cc | 4 +- test/core/client_channel/parse_address_test.cc | 6 +- .../resolvers/dns_resolver_connectivity_test.cc | 8 +- .../client_channel/resolvers/dns_resolver_test.cc | 6 +- .../client_channel/resolvers/fake_resolver_test.cc | 8 +- .../resolvers/sockaddr_resolver_test.cc | 6 +- test/core/client_channel/uri_fuzzer_test.cc | 2 +- test/core/client_channel/uri_parser_test.cc | 10 +- test/core/compression/algorithm_test.cc | 4 +- test/core/compression/message_compress_test.cc | 16 +-- test/core/debug/stats_test.cc | 6 +- test/core/end2end/bad_server_response_test.cc | 2 +- test/core/end2end/connection_refused_test.cc | 2 +- test/core/end2end/fixtures/h2_census.cc | 4 +- test/core/end2end/fixtures/h2_compress.cc | 6 +- test/core/end2end/fixtures/h2_fd.cc | 4 +- test/core/end2end/fixtures/h2_full+workarounds.cc | 2 +- test/core/end2end/fixtures/h2_load_reporting.cc | 2 +- test/core/end2end/fixtures/h2_oauth2.cc | 2 +- test/core/end2end/fixtures/h2_sockpair+trace.cc | 8 +- test/core/end2end/fixtures/h2_sockpair.cc | 6 +- test/core/end2end/fixtures/h2_sockpair_1byte.cc | 6 +- test/core/end2end/fixtures/h2_ssl.cc | 2 +- test/core/end2end/fixtures/h2_ssl_proxy.cc | 4 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 13 +-- test/core/end2end/fuzzers/api_fuzzer.cc | 14 +-- test/core/end2end/fuzzers/client_fuzzer.cc | 4 +- test/core/end2end/fuzzers/server_fuzzer.cc | 4 +- test/core/end2end/h2_ssl_cert_test.cc | 2 +- test/core/end2end/tests/cancel_after_accept.cc | 2 +- test/core/end2end/tests/cancel_after_round_trip.cc | 2 +- test/core/end2end/tests/compressed_payload.cc | 6 +- test/core/end2end/tests/load_reporting_hook.cc | 2 +- test/core/end2end/tests/max_message_length.cc | 4 +- .../tests/stream_compression_compressed_payload.cc | 6 +- .../end2end/tests/stream_compression_payload.cc | 2 +- .../stream_compression_ping_pong_streaming.cc | 2 +- .../end2end/tests/workaround_cronet_compression.cc | 4 +- test/core/http/httpcli_test.cc | 6 +- test/core/http/httpscli_test.cc | 6 +- test/core/iomgr/combiner_test.cc | 16 +-- test/core/iomgr/endpoint_pair_test.cc | 4 +- test/core/iomgr/endpoint_tests.cc | 19 ++-- test/core/iomgr/ev_epollsig_linux_test.cc | 28 +++--- test/core/iomgr/fd_conservation_posix_test.cc | 4 +- test/core/iomgr/fd_posix_test.cc | 12 +-- test/core/iomgr/pollset_set_test.cc | 36 +++---- test/core/iomgr/resolve_address_posix_test.cc | 14 +-- test/core/iomgr/resolve_address_test.cc | 42 ++++---- test/core/iomgr/resource_quota_test.cc | 112 ++++++++++----------- test/core/iomgr/tcp_client_posix_test.cc | 12 +-- test/core/iomgr/tcp_client_uv_test.cc | 10 +- test/core/iomgr/tcp_posix_test.cc | 18 ++-- test/core/iomgr/tcp_server_posix_test.cc | 15 +-- test/core/iomgr/tcp_server_uv_test.cc | 12 +-- test/core/iomgr/timer_list_test.cc | 18 ++-- test/core/iomgr/udp_server_test.cc | 18 ++-- test/core/security/credentials_test.cc | 70 ++++++------- test/core/security/json_token_test.cc | 4 +- test/core/security/jwt_verifier_test.cc | 26 ++--- test/core/security/oauth2_utils.cc | 4 +- .../security/print_google_default_creds_token.cc | 4 +- test/core/security/secure_endpoint_test.cc | 6 +- test/core/security/ssl_server_fuzzer.cc | 10 +- test/core/security/verify_jwt.cc | 4 +- test/core/slice/b64_test.cc | 8 +- test/core/slice/slice_hash_table_test.cc | 6 +- test/core/surface/byte_buffer_reader_test.cc | 2 +- test/core/surface/channel_create_test.cc | 2 +- test/core/surface/completion_queue_test.cc | 8 +- .../surface/completion_queue_threading_test.cc | 4 +- test/core/surface/concurrent_connectivity_test.cc | 6 +- test/core/surface/lame_client_test.cc | 2 +- .../num_external_connectivity_watchers_test.cc | 2 +- test/core/surface/secure_channel_create_test.cc | 6 +- test/core/surface/sequential_connectivity_test.cc | 2 +- test/core/transport/bdp_estimator_test.cc | 4 +- test/core/transport/byte_stream_test.cc | 10 +- test/core/transport/chttp2/bin_decoder_test.cc | 2 +- test/core/transport/chttp2/hpack_encoder_test.cc | 2 +- .../transport/chttp2/hpack_parser_fuzzer_test.cc | 2 +- test/core/transport/chttp2/hpack_parser_test.cc | 4 +- test/core/transport/chttp2/hpack_table_test.cc | 8 +- test/core/transport/connectivity_state_test.cc | 16 +-- test/core/transport/metadata_test.cc | 18 ++-- test/core/transport/status_conversion_test.cc | 2 +- test/core/util/port_server_client.cc | 24 +++-- test/core/util/test_tcp_server.cc | 6 +- test/cpp/end2end/client_lb_end2end_test.cc | 2 +- test/cpp/end2end/grpclb_end2end_test.cc | 2 +- test/cpp/grpclb/grpclb_test.cc | 2 +- test/cpp/microbenchmarks/bm_call_create.cc | 8 +- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 22 ++-- test/cpp/microbenchmarks/bm_chttp2_transport.cc | 12 +-- test/cpp/microbenchmarks/bm_closure.cc | 66 ++++++------ test/cpp/microbenchmarks/bm_cq.cc | 6 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 2 +- test/cpp/microbenchmarks/bm_error.cc | 6 +- test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 2 +- test/cpp/microbenchmarks/bm_metadata.cc | 26 ++--- test/cpp/microbenchmarks/bm_pollset.cc | 12 +-- test/cpp/microbenchmarks/fullstack_fixtures.h | 2 +- test/cpp/naming/resolver_component_test.cc | 8 +- test/cpp/performance/writes_per_rpc_test.cc | 2 +- 189 files changed, 943 insertions(+), 882 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index dbdcd53ef5..ea9fb2cae1 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -112,10 +112,12 @@ static void run_poller(void* arg, grpc_error* error) { backup_poller_shutdown_unref(p); return; } - grpc_error* err = grpc_pollset_work(p->pollset, NULL, ExecCtx::Get()->Now()); + grpc_error* err = + grpc_pollset_work(p->pollset, NULL, grpc_core::ExecCtx::Get()->Now()); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); - grpc_timer_init(&p->polling_timer, ExecCtx::Get()->Now() + g_poll_interval_ms, + grpc_timer_init(&p->polling_timer, + grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, &p->run_poller_closure); } @@ -137,7 +139,7 @@ void grpc_client_channel_start_backup_polling( GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); grpc_timer_init(&g_poller->polling_timer, - ExecCtx::Get()->Now() + g_poll_interval_ms, + grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, &g_poller->run_poller_closure); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 0ceedb9f86..c949e52bd4 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -33,7 +33,7 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( /* forward through to the underlying client channel */ grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_connectivity_state state; GRPC_API_TRACE( "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, @@ -198,7 +198,7 @@ void grpc_channel_watch_connectivity_state( gpr_timespec deadline, grpc_completion_queue* cq, void* tag) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 63cf417c4e..e757777aec 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -1122,7 +1122,7 @@ static void start_picking_locked(glb_lb_policy* glb_policy) { if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { grpc_millis deadline = - ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; + grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); GRPC_CLOSURE_INIT(&glb_policy->lb_on_fallback, lb_on_fallback_timer_locked, glb_policy, @@ -1271,7 +1271,7 @@ static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); - grpc_millis timeout = next_try - ExecCtx::Get()->Now(); + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); if (timeout > 0) { gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", @@ -1297,7 +1297,8 @@ static void send_client_load_report_locked(void* arg, grpc_error* error); static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = - ExecCtx::Get()->Now() + glb_policy->client_stats_report_interval; + grpc_core::ExecCtx::Get()->Now() + + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, send_client_load_report_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); @@ -1392,7 +1393,7 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE - : ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; + : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index f0543964ae..5ac5d37a54 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -265,7 +265,7 @@ static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - ExecCtx::Get()->Now(); + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 925223d189..06af5bf0b2 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -213,7 +213,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, static void on_srv_query_done_cb(void* arg, int status, int timeouts, unsigned char* abuf, int alen) { grpc_ares_request* r = (grpc_ares_request*)arg; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { gpr_log(GPR_DEBUG, "on_query_srv_done_cb ARES_SUCCESS"); diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 10404ec4ef..82cd28fb2b 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -163,7 +163,7 @@ static void dns_on_resolved_locked(void* arg, grpc_error* error) { } else { grpc_millis next_try = grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - ExecCtx::Get()->Now(); + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 98f96b5750..61adb984f3 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -458,7 +458,8 @@ static void maybe_start_connecting_locked(grpc_subchannel* c) { GPR_ASSERT(!c->have_alarm); c->have_alarm = true; const grpc_millis time_til_next = - c->backoff_result.next_attempt_start_time - ExecCtx::Get()->Now(); + c->backoff_result.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now(); if (time_til_next <= 0) { gpr_log(GPR_INFO, "Retry immediately"); } else { diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index fbab57769c..b7b7472aff 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -133,7 +133,7 @@ void grpc_subchannel_index_shutdown(void) { void grpc_subchannel_index_unref(void) { if (gpr_unref(&g_refcount)) { gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index, ExecCtx::Get()); + gpr_avl_unref(g_subchannel_index, grpc_core::ExecCtx::Get()); } } @@ -143,12 +143,13 @@ grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()), "index_find"); - gpr_avl_unref(index, ExecCtx::Get()); + (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()), + "index_find"); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); return c; } @@ -164,11 +165,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); + c = (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); if (c != NULL) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -177,10 +178,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, need_to_unref_constructed = true; } else { // no -> update the avl and compare/swap - gpr_avl updated = gpr_avl_add( - gpr_avl_ref(index, ExecCtx::Get()), subchannel_key_copy(key), - GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), - ExecCtx::Get()); + gpr_avl updated = + gpr_avl_add(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), + subchannel_key_copy(key), + GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), + grpc_core::ExecCtx::Get()); // it may happen (but it's expected to be unlikely) // that some other thread has changed the index: @@ -192,9 +194,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, ExecCtx::Get()); + gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); } - gpr_avl_unref(index, ExecCtx::Get()); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); } if (need_to_unref_constructed) { @@ -211,22 +213,23 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); // Check to see if this key still refers to the previously // registered subchannel grpc_subchannel* c = - (grpc_subchannel*)gpr_avl_get(index, key, ExecCtx::Get()); + (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); if (c != constructed) { - gpr_avl_unref(index, ExecCtx::Get()); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); break; } // compare and swap the update (some other thread may have // mutated the index behind us) gpr_avl updated = - gpr_avl_remove(gpr_avl_ref(index, ExecCtx::Get()), key, ExecCtx::Get()); + gpr_avl_remove(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), key, + grpc_core::ExecCtx::Get()); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -235,8 +238,8 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, ExecCtx::Get()); - gpr_avl_unref(index, ExecCtx::Get()); + gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); } } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 015a3ce124..f89e8c730d 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -99,9 +99,10 @@ static void increase_call_count(channel_data* chand) { static void decrease_call_count(channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); - grpc_timer_init(&chand->max_idle_timer, - ExecCtx::Get()->Now() + chand->max_connection_idle, - &chand->close_max_idle_channel); + grpc_timer_init( + &chand->max_idle_timer, + grpc_core::ExecCtx::Get()->Now() + chand->max_connection_idle, + &chand->close_max_idle_channel); } } @@ -121,7 +122,7 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); grpc_timer_init(&chand->max_age_timer, - ExecCtx::Get()->Now() + chand->max_connection_age, + grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(NULL); @@ -138,11 +139,12 @@ static void start_max_age_grace_timer_after_goaway_op(void* arg, gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); - grpc_timer_init(&chand->max_age_grace_timer, - chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE - ? GRPC_MILLIS_INF_FUTURE - : ExecCtx::Get()->Now() + chand->max_connection_age_grace, - &chand->force_close_max_age_channel); + grpc_timer_init( + &chand->max_age_grace_timer, + chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE + ? GRPC_MILLIS_INF_FUTURE + : grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age_grace, + &chand->force_close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_age_grace_timer_after_goaway_op"); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 3afca884ca..fec61281c3 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -80,7 +80,7 @@ static grpc_client_channel_factory client_channel_factory = { grpc_channel* grpc_insecure_channel_create(const char* target, const grpc_channel_args* args, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index b0eff1c992..c713ce1960 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -37,7 +37,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, (target, fd, args)); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index bebc38c248..a328126263 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -190,7 +190,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, const char* target, const grpc_channel_args* args, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index bbcfb1b195..97b6ad38de 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -132,7 +132,8 @@ static void on_accept(void* arg, grpc_endpoint* tcp, connection_state->handshake_mgr); // TODO(roth): We should really get this timeout value from channel // args instead of hard-coding it. - const grpc_millis deadline = ExecCtx::Get()->Now() + 120 * GPR_MS_PER_SEC; + const grpc_millis deadline = + grpc_core::ExecCtx::Get()->Now() + 120 * GPR_MS_PER_SEC; grpc_handshake_manager_do_handshake(connection_state->handshake_mgr, tcp, state->args, deadline, acceptor, on_handshake_done, connection_state); @@ -161,10 +162,10 @@ static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { gpr_mu_unlock(&state->mu); // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); if (destroy_done != NULL) { destroy_done->cb(destroy_done->cb_arg, GRPC_ERROR_REF(error)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } grpc_channel_args_destroy(state->args); gpr_mu_destroy(&state->mu); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 6cbb26a349..826886c961 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -26,7 +26,7 @@ #include "src/core/lib/surface/server.h" int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; int port_num = 0; GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2, (server, addr)); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index e5419e5e6e..11b3d710df 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -38,7 +38,7 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, void* reserved, int fd) { GPR_ASSERT(reserved == NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; char* name; gpr_asprintf(&name, "fd:%d", fd); diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index aeae8f42e3..827f0020bb 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -36,7 +36,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_server_credentials* creds) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_error* err = GRPC_ERROR_NONE; grpc_server_security_connector* sc = NULL; int port_num = 0; diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index e49e26fc35..a2861dfd6f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -530,7 +530,7 @@ static void init_transport(grpc_chttp2_transport* t, t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - ExecCtx::Get()->Now() + t->keepalive_time, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } else { /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no @@ -2585,14 +2585,14 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { } else { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - ExecCtx::Get()->Now() + t->keepalive_time, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } else if (error == GRPC_ERROR_CANCELLED) { /* The keepalive ping timer may be cancelled by bdp */ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - ExecCtx::Get()->Now() + t->keepalive_time, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping"); @@ -2602,7 +2602,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(&t->keepalive_watchdog_timer, - ExecCtx::Get()->Now() + t->keepalive_time, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->keepalive_watchdog_fired_locked); } @@ -2614,7 +2614,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_timer_cancel(&t->keepalive_watchdog_timer); GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, - ExecCtx::Get()->Now() + t->keepalive_time, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index e54d59b5fa..14f089859e 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -160,7 +160,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, .set_min_control_value(-1) .set_max_control_value(25) .set_integral_range(10)), - last_pid_update_(ExecCtx::Get()->Now()) {} + last_pid_update_(grpc_core::ExecCtx::Get()->Now()) {} uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); @@ -306,7 +306,7 @@ double TransportFlowControl::TargetLogBdp() { } double TransportFlowControl::SmoothLogBdp(double value) { - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); double bdp_error = value - pid_controller_.last_control_value(); const double dt = (double)(now - last_pid_update_) * 1e-3; last_pid_update_ = now; diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 60172be9cb..298a56721a 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -89,7 +89,7 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, grpc_chttp2_ack_ping(t, p->opaque_8bytes); } else { if (!t->is_client) { - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_recv_state.last_ping_recv_time + t->ping_policy.min_recv_ping_interval_without_data; diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index efb6e54ce7..2f9849c09a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -570,7 +570,8 @@ static void deadline_enc(grpc_chttp2_hpack_compressor* c, grpc_millis deadline, framer_state* st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem mdelem; - grpc_http2_encode_timeout(deadline - ExecCtx::Get()->Now(), timeout_str); + grpc_http2_encode_timeout(deadline - grpc_core::ExecCtx::Get()->Now(), + timeout_str); mdelem = grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_TIMEOUT, grpc_slice_from_copied_string(timeout_str)); hpack_enc(c, mdelem, st); diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index f7f83c9aee..f73b498d40 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -436,7 +436,7 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (timeout != GRPC_MILLIS_INF_FUTURE) { grpc_chttp2_incoming_metadata_buffer_set_deadline( - &s->metadata_buffer[0], ExecCtx::Get()->Now() + timeout); + &s->metadata_buffer[0], grpc_core::ExecCtx::Get()->Now() + timeout); } GRPC_MDELEM_UNREF(md); } else { diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 4f76c2eb23..ddcac45d83 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -68,7 +68,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { } return; } - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_state.last_ping_sent_time + t->ping_policy.min_sent_ping_interval_without_data; diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc index f634627f03..8e1dcc542e 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc @@ -49,6 +49,6 @@ GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( grpc_transport* ct = grpc_create_cronet_transport(engine, target, args, reserved); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; return grpc_channel_create(target, args, GRPC_CLIENT_DIRECT_CHANNEL, ct); } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 3411acc563..971071e387 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -398,7 +398,7 @@ static void execute_from_storage(stream_obj* s) { */ static void on_failed(bidirectional_stream* stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -424,7 +424,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) { */ static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -450,7 +450,7 @@ static void on_canceled(bidirectional_stream* stream) { */ static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -468,7 +468,7 @@ static void on_succeeded(bidirectional_stream* stream) { */ static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); @@ -498,7 +498,7 @@ static void on_response_headers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* headers, const char* negotiated_protocol) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); stream_obj* s = (stream_obj*)stream->annotation; @@ -550,7 +550,7 @@ static void on_response_headers_received( Cronet callback */ static void on_write_completed(bidirectional_stream* stream, const char* data) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); @@ -568,7 +568,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { */ static void on_read_completed(bidirectional_stream* stream, char* data, int count) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); @@ -610,7 +610,7 @@ static void on_read_completed(bidirectional_stream* stream, char* data, static void on_response_trailers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* trailers) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); stream_obj* s = (stream_obj*)stream->annotation; diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index a79b2b26b0..e303f5ac0d 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -1091,7 +1091,7 @@ static grpc_endpoint* get_endpoint(grpc_transport* t) { return NULL; } static void do_nothing(void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, NULL, grpc_schedule_on_exec_ctx); g_empty_slice = grpc_slice_from_static_buffer(NULL, 0); @@ -1155,7 +1155,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, GRPC_API_TRACE("grpc_inproc_channel_create(server=%p, args=%p)", 2, (server, args)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; const grpc_channel_args* server_args = grpc_server_get_channel_args(server); @@ -1186,7 +1186,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, } void grpc_inproc_transport_shutdown(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_unref_internal(g_empty_slice); grpc_slice_unref_internal(g_fake_path_key); grpc_slice_unref_internal(g_fake_path_value); diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index b75ce79d46..da3b9b1b2d 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -36,7 +36,7 @@ grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff) { backoff->current_backoff = backoff->initial_backoff; const grpc_millis initial_timeout = GPR_MAX(backoff->initial_backoff, backoff->min_connect_timeout); - const grpc_millis now = ExecCtx::Get()->Now(); + const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + initial_timeout, now + backoff->current_backoff}; return result; @@ -67,7 +67,7 @@ grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff) { backoff->min_connect_timeout); const grpc_millis next_timeout = GPR_MIN( (grpc_millis)(backoff->current_backoff + jitter), backoff->max_backoff); - const grpc_millis now = ExecCtx::Get()->Now(); + const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + current_timeout, now + next_timeout}; return result; diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 3fae3490ce..4aaef4e128 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -40,7 +40,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, /* Full flush is not allowed when inflating. */ GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; int r; bool eoc = false; size_t original_max_output_size = max_output_size; diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index 24b0084130..6b36f67172 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -35,7 +35,7 @@ typedef struct grpc_stats_data { extern grpc_stats_data* grpc_stats_per_cpu_storage; #define GRPC_THREAD_STATS_DATA() \ - (&grpc_stats_per_cpu_storage[ExecCtx::Get()->starting_cpu()]) + (&grpc_stats_per_cpu_storage[grpc_core::ExecCtx::Get()->starting_cpu()]) #define GRPC_STATS_INC_COUNTER(ctr) \ (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1)) diff --git a/src/core/lib/iomgr/block_annotate.h b/src/core/lib/iomgr/block_annotate.h index 7783da0c14..55bde3eaac 100644 --- a/src/core/lib/iomgr/block_annotate.h +++ b/src/core/lib/iomgr/block_annotate.h @@ -41,18 +41,18 @@ void gpr_thd_end_blocking_region(); do { \ gpr_thd_start_blocking_region(); \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION \ - do { \ - gpr_thd_end_blocking_region(); \ - ExecCtx::Get()->InvalidateNow(); \ +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + gpr_thd_end_blocking_region(); \ + grpc_core::ExecCtx::Get()->InvalidateNow(); \ } while (0) #else #define GRPC_SCHEDULING_START_BLOCKING_REGION \ do { \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION \ - do { \ - ExecCtx::Get()->InvalidateNow(); \ +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + grpc_core::ExecCtx::Get()->InvalidateNow(); \ } while (0) #endif diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index c9f5448630..6cc4eef1d8 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -129,23 +129,23 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { static void push_last_on_exec_ctx(grpc_combiner* lock) { lock->next_combiner_on_this_exec_ctx = nullptr; - if (ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { - ExecCtx::Get()->combiner_data()->active_combiner = - ExecCtx::Get()->combiner_data()->last_combiner = lock; + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } else { - ExecCtx::Get() + grpc_core::ExecCtx::Get() ->combiner_data() ->last_combiner->next_combiner_on_this_exec_ctx = lock; - ExecCtx::Get()->combiner_data()->last_combiner = lock; + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } } static void push_first_on_exec_ctx(grpc_combiner* lock) { lock->next_combiner_on_this_exec_ctx = - ExecCtx::Get()->combiner_data()->active_combiner; - ExecCtx::Get()->combiner_data()->active_combiner = lock; + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = lock; if (lock->next_combiner_on_this_exec_ctx == NULL) { - ExecCtx::Get()->combiner_data()->last_combiner = lock; + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } } @@ -165,7 +165,7 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(); GPR_TIMER_MARK("combiner.initiated", 0); gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, - (gpr_atm)ExecCtx::Get()); + (gpr_atm)grpc_core::ExecCtx::Get()); // first element on this list: add it to the list of combiner locks // executing within this exec_ctx push_last_on_exec_ctx(lock); @@ -174,7 +174,7 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { // offload for one or two actions, and that's fine gpr_atm initiator = gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null); - if (initiator != 0 && initiator != (gpr_atm)ExecCtx::Get()) { + if (initiator != 0 && initiator != (gpr_atm)grpc_core::ExecCtx::Get()) { gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } @@ -186,12 +186,12 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { } static void move_next() { - ExecCtx::Get()->combiner_data()->active_combiner = - ExecCtx::Get() + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = + grpc_core::ExecCtx::Get() ->combiner_data() ->active_combiner->next_combiner_on_this_exec_ctx; - if (ExecCtx::Get()->combiner_data()->active_combiner == NULL) { - ExecCtx::Get()->combiner_data()->last_combiner = NULL; + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == NULL) { + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = NULL; } } @@ -209,7 +209,8 @@ static void queue_offload(grpc_combiner* lock) { bool grpc_combiner_continue_exec_ctx() { GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0); - grpc_combiner* lock = ExecCtx::Get()->combiner_data()->active_combiner; + grpc_combiner* lock = + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; if (lock == NULL) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); return false; @@ -224,10 +225,10 @@ bool grpc_combiner_continue_exec_ctx() { "exec_ctx_ready_to_finish=%d " "time_to_execute_final_list=%d", lock, contended, - ExecCtx::Get()->IsReadyToFinish(), + grpc_core::ExecCtx::Get()->IsReadyToFinish(), lock->time_to_execute_final_list)); - if (contended && ExecCtx::Get()->IsReadyToFinish() && + if (contended && grpc_core::ExecCtx::Get()->IsReadyToFinish() && grpc_executor_is_threaded()) { GPR_TIMER_MARK("offload_from_finished_exec_ctx", 0); // this execution context wants to move on: schedule remaining work to be @@ -333,11 +334,11 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(closure, finally_scheduler); - GRPC_COMBINER_TRACE( - gpr_log(GPR_DEBUG, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, - closure, ExecCtx::Get()->combiner_data()->active_combiner)); + GRPC_COMBINER_TRACE(gpr_log( + GPR_DEBUG, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, + closure, grpc_core::ExecCtx::Get()->combiner_data()->active_combiner)); GPR_TIMER_BEGIN("combiner.execute_finally", 0); - if (ExecCtx::Get()->combiner_data()->active_combiner != lock) { + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner != lock) { GPR_TIMER_MARK("slowpath", 0); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(enqueue_finally, closure, grpc_combiner_scheduler(lock)), diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 1a281322a8..65db4a9675 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -54,7 +54,7 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name, char* final_name; create_sockets(sv); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_asprintf(&final_name, "%s:client", name); p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name), args, diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index e0f211cdf9..afd91c9932 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -72,7 +72,7 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( SOCKET sv[2]; grpc_endpoint_pair p; create_sockets(sv); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; p.client = grpc_tcp_create(grpc_winsocket_create(sv[1], "endpoint:client"), channel_args, "endpoint:server"); p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server"), diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 2b486887b8..f22fb82797 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -554,7 +554,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) { return INT_MAX; } else if (delta < 0) { @@ -743,7 +743,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker, KICKED); } } - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); } if (GRPC_TRACER_ON(grpc_polling_trace)) { @@ -848,7 +848,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, /* Make sure we appear kicked */ SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, - ExecCtx::Get()->closure_list()); + grpc_core::ExecCtx::Get()->closure_list()); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { if (worker->next != worker && worker->next->state == UNKICKED) { if (GRPC_TRACER_ON(grpc_polling_trace)) { @@ -859,9 +859,9 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker->next, DESIGNATED_POLLER); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&worker->next->cv); - if (ExecCtx::Get()->HasWork()) { + if (grpc_core::ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } else { @@ -892,12 +892,12 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, found_worker = check_neighborhood_for_available_poller(neighborhood); gpr_mu_unlock(&neighborhood->mu); } - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } - } else if (ExecCtx::Get()->HasWork()) { + } else if (grpc_core::ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } if (worker->initialized_cv) { @@ -948,8 +948,8 @@ static grpc_error* pollset_work(grpc_pollset* ps, process_epoll_events() returns very quickly: It just queues the work on exec_ctx but does not execute it (the actual exectution or more - accurately ExecCtx::Get()->Flush() happens in end_worker() AFTER - selecting a designated poller). So we are not waiting long periods + accurately grpc_core::ExecCtx::Get()->Flush() happens in end_worker() + AFTER selecting a designated poller). So we are not waiting long periods without a designated poller */ if (gpr_atm_acq_load(&g_epoll_set.cursor) == gpr_atm_acq_load(&g_epoll_set.num_events)) { diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 385b5f68d0..5b4edd1e74 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -682,7 +682,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -902,7 +902,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->pollable_obj, worker); } } - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); } else { gpr_mu_unlock(&pollset->mu); } @@ -970,8 +970,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset, gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR " kwp=%d pollable=%p", - pollset, worker_hdl, WORKER_PTR, ExecCtx::Get()->Now(), deadline, - pollset->kicked_without_poller, pollset->active_pollable); + pollset, worker_hdl, WORKER_PTR, grpc_core::ExecCtx::Get()->Now(), + deadline, pollset->kicked_without_poller, pollset->active_pollable); } static const char* err_desc = "pollset_work"; grpc_error* error = GRPC_ERROR_NONE; @@ -990,7 +990,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, &error, pollable_process_events(pollset, WORKER_PTR->pollable_obj, false), err_desc); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_tls_set(&g_current_thread_pollset, 0); gpr_tls_set(&g_current_thread_worker, 0); } diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index a9b094a2fa..4ded7c0211 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -1090,7 +1090,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -1350,7 +1350,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, pollset_work_and_unlock(pollset, &worker, timeout_ms, &g_orig_sigmask, &error); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); @@ -1373,7 +1373,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, finish_shutdown_locked(pollset); gpr_mu_unlock(&pollset->po.mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); } diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index cab4f7547c..b6546aa4b4 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -1040,7 +1040,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, worker list, which means nobody could ask us to re-evaluate polling). */ done: if (!locked) { - queued_work |= ExecCtx::Get()->Flush(); + queued_work |= grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); locked = 1; } @@ -1074,7 +1074,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); finish_shutdown(pollset); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * pollset_work. @@ -1083,7 +1083,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, } else if (!grpc_closure_list_empty(pollset->idle_jobs)) { GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); gpr_mu_unlock(&pollset->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } @@ -1110,7 +1110,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { static int poll_deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) return -1; if (deadline == 0) return 0; - grpc_millis n = deadline - ExecCtx::Get()->Now(); + grpc_millis n = deadline - grpc_core::ExecCtx::Get()->Now(); if (n < 0) return 0; if (n > INT_MAX) return -1; return (int)n; diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index fe5a0e7e2d..de71c1cf9c 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -25,29 +25,6 @@ #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/profiling/timers.h" -thread_local ExecCtx* exec_ctx = nullptr; - -ExecCtx::ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { exec_ctx = this; } -ExecCtx::ExecCtx(uintptr_t fl) : flags_(fl) { exec_ctx = this; } -ExecCtx::~ExecCtx() { - GPR_ASSERT(exec_ctx == this); - flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - Flush(); - exec_ctx = last_exec_ctx_; -} - -bool ExecCtx::IsReadyToFinish() { - if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { - if (CheckReadyToFinish()) { - flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - return true; - } - return false; - } else { - return true; - } -} - void exec_ctx_run(grpc_closure* closure, grpc_error* error) { #ifndef NDEBUG closure->scheduled = false; @@ -67,48 +44,16 @@ void exec_ctx_run(grpc_closure* closure, grpc_error* error) { GRPC_ERROR_UNREF(error); } -bool ExecCtx::Flush() { - bool did_something = 0; - GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); - for (;;) { - if (!grpc_closure_list_empty(closure_list_)) { - grpc_closure* c = closure_list_.head; - closure_list_.head = closure_list_.tail = NULL; - while (c != NULL) { - grpc_closure* next = c->next_data.next; - grpc_error* error = c->error_data.error; - did_something = true; - exec_ctx_run(c, error); - c = next; - } - } else if (!grpc_combiner_continue_exec_ctx()) { - break; - } - } - GPR_ASSERT(combiner_data_.active_combiner == nullptr); - GPR_TIMER_END("grpc_exec_ctx_flush", 0); - return did_something; -} - -void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { - grpc_closure_list_append(exec_ctx->closure_list(), closure, error); -} - static gpr_timespec g_start_time[GPR_TIMESPAN + 1]; // assumes GPR_TIMESPAN is the // last enum value in // gpr_clock_type -void ExecCtx::GlobalInit(void) { - for (int i = 0; i < GPR_TIMESPAN; i++) { - g_start_time[i] = gpr_now((gpr_clock_type)i); - } - // allows uniform treatment in conversion functions - g_start_time[GPR_TIMESPAN] = gpr_time_0(GPR_TIMESPAN); +void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { + grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure, + error); } -void ExecCtx::GlobalShutdown(void) {} - static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time[ts.clock_type]); double x = @@ -154,6 +99,47 @@ grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) { return timespec_to_atm_round_up(ts); } +static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { + exec_ctx_run, exec_ctx_sched, "exec_ctx"}; +static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; +grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; + +namespace grpc_core { +thread_local ExecCtx* ExecCtx::exec_ctx_ = nullptr; + +bool ExecCtx::Flush() { + bool did_something = 0; + GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); + for (;;) { + if (!grpc_closure_list_empty(closure_list_)) { + grpc_closure* c = closure_list_.head; + closure_list_.head = closure_list_.tail = NULL; + while (c != NULL) { + grpc_closure* next = c->next_data.next; + grpc_error* error = c->error_data.error; + did_something = true; + exec_ctx_run(c, error); + c = next; + } + } else if (!grpc_combiner_continue_exec_ctx()) { + break; + } + } + GPR_ASSERT(combiner_data_.active_combiner == nullptr); + GPR_TIMER_END("grpc_exec_ctx_flush", 0); + return did_something; +} + +void ExecCtx::GlobalInit(void) { + for (int i = 0; i < GPR_TIMESPAN; i++) { + g_start_time[i] = gpr_now((gpr_clock_type)i); + } + // allows uniform treatment in conversion functions + g_start_time[GPR_TIMESPAN] = gpr_time_0(GPR_TIMESPAN); +} + +void ExecCtx::GlobalShutdown(void) {} + grpc_millis ExecCtx::Now() { if (!now_is_valid_) { now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); @@ -162,9 +148,4 @@ grpc_millis ExecCtx::Now() { return now_; } -ExecCtx* ExecCtx::Get() { return exec_ctx; } - -static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { - exec_ctx_run, exec_ctx_sched, "exec_ctx"}; -static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; -grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; +} // namespace grpc_core diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index a71e43e178..7b8da2f0af 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -46,6 +46,7 @@ typedef struct grpc_combiner grpc_combiner; should be given to not delete said call/channel from this exec_ctx */ #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 +namespace grpc_core { /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -68,10 +69,25 @@ typedef struct grpc_combiner grpc_combiner; */ class ExecCtx { public: - ExecCtx(); - ExecCtx(uintptr_t fl); - ~ExecCtx(); + /** Default Constructor */ + ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { exec_ctx_ = this; } + + /** Parameterised Constructor */ + ExecCtx(uintptr_t fl) : flags_(fl) { exec_ctx_ = this; } + + /** Destructor */ + ~ExecCtx() { + GPR_ASSERT(exec_ctx_ == this); + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + Flush(); + exec_ctx_ = last_exec_ctx_; + } + + /** Disallow copy and assignment operators */ + ExecCtx(const ExecCtx&) = delete; + ExecCtx& operator=(const ExecCtx&) = delete; + /** Return starting_cpu */ unsigned starting_cpu() const { return starting_cpu_; } struct CombinerData { @@ -84,8 +100,13 @@ class ExecCtx { /** Only to be used by grpc-combiner code */ CombinerData* combiner_data() { return &combiner_data_; } + /** Return pointer to grpc_closure_list */ grpc_closure_list* closure_list() { return &closure_list_; } + /** Return flags */ + uintptr_t flags() { return flags_; } + + /** Checks if there is work to be done */ bool HasWork() { return combiner_data_.active_combiner != NULL || !grpc_closure_list_empty(closure_list_); @@ -99,32 +120,59 @@ class ExecCtx { /** Returns true if we'd like to leave this execution context as soon as possible: useful for deciding whether to do something more or not depending on outside context */ - bool IsReadyToFinish(); + bool IsReadyToFinish() { + if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { + if (CheckReadyToFinish()) { + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + return true; + } + return false; + } else { + return true; + } + } + /** Returns the stored current time relative to start if valid, + * otherwise refreshes the stored time, sets it valid and returns the new + * value */ grpc_millis Now(); + /** Invalidates the stored time value. A new time value will be set on calling + * Now() */ void InvalidateNow() { now_is_valid_ = false; } - void SetNow(grpc_millis new_val) { - now_ = new_val; + /** To be used only by shutdown code in iomgr */ + void SetNowIomgrShutdown() { + now_ = GRPC_MILLIS_INF_FUTURE; now_is_valid_ = true; } - uintptr_t flags() { return flags_; } + /** To be used only for testing. + * Sets the now value + */ + void TestOnlySetNow(grpc_millis new_val) { + now_ = new_val; + now_is_valid_ = true; + } /** Finish any pending work for a grpc_exec_ctx. Must be called before * the instance is destroyed, or work may be lost. */ void Finish(); + /** Global initialization for ExecCtx. Called by iomgr */ static void GlobalInit(void); + /** Global shutdown for ExecCtx. Called by iomgr */ static void GlobalShutdown(void); - static ExecCtx* Get(); + /** Gets pointer to current exec_ctx */ + static ExecCtx* Get() { return exec_ctx_; } protected: + /** Check if ready to finish */ virtual bool CheckReadyToFinish() { return false; } + private: grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; CombinerData combiner_data_ = {nullptr, nullptr}; uintptr_t flags_; @@ -133,8 +181,10 @@ on outside context */ bool now_is_valid_ = false; grpc_millis now_ = 0; - ExecCtx* last_exec_ctx_ = Get(); + static thread_local ExecCtx* exec_ctx_; + ExecCtx* last_exec_ctx_ = exec_ctx_; }; +} // namespace grpc_core extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index bf8805a2cd..4db298c1c5 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -78,7 +78,7 @@ static size_t run_closures(grpc_closure_list list) { GRPC_ERROR_UNREF(error); c = next; n++; - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } return n; @@ -145,7 +145,7 @@ static void executor_thread(void* arg) { thread_state* ts = (thread_state*)arg; gpr_tls_set(&g_this_thread_state, (intptr_t)ts); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; size_t subtract_depth = 0; for (;;) { @@ -175,7 +175,7 @@ static void executor_thread(void* arg) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); } - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); subtract_depth = run_closures(exec); } } @@ -200,12 +200,14 @@ static void executor_push(grpc_closure* closure, grpc_error* error, gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p inline", closure); #endif } - grpc_closure_list_append(ExecCtx::Get()->closure_list(), closure, error); + grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), + closure, error); return; } thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state); if (ts == NULL) { - ts = &g_thread_state[GPR_HASH_POINTER(ExecCtx::Get(), cur_thread_count)]; + ts = &g_thread_state[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(), + cur_thread_count)]; } else { GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(); } diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 1686bf2872..f5c6297438 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -46,7 +46,7 @@ static DWORD deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return INFINITE; } - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline < now) return 0; grpc_millis timeout = deadline - now; if (timeout > std::numeric_limits::max()) return INFINITE; @@ -65,7 +65,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key, &overlapped, deadline_to_millis_timeout(deadline)); - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } @@ -113,19 +113,20 @@ void grpc_iocp_kick(void) { } void grpc_iocp_flush(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_iocp_work_status work_status; do { work_status = grpc_iocp_work(GRPC_MILLIS_INF_PAST); - } while (work_status == GRPC_IOCP_WORK_KICK || ExecCtx::Get()->Flush()); + } while (work_status == GRPC_IOCP_WORK_KICK || + grpc_core::ExecCtx::Get()->Flush()); } void grpc_iocp_shutdown(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (gpr_atm_acq_load(&g_custom_events)) { grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GPR_ASSERT(CloseHandle(g_iocp)); diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index a1add4a303..9c74b5d1c3 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -49,7 +49,7 @@ void grpc_iomgr_init() { g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); - ExecCtx::GlobalInit(); + grpc_core::ExecCtx::GlobalInit(); grpc_executor_init(); grpc_timer_list_init(); g_root_object.next = g_root_object.prev = &g_root_object; @@ -98,10 +98,10 @@ void grpc_iomgr_shutdown() { } last_warning_time = gpr_now(GPR_CLOCK_REALTIME); } - ExecCtx::Get()->SetNow(GRPC_MILLIS_INF_FUTURE); + grpc_core::ExecCtx::Get()->SetNowIomgrShutdown(); if (grpc_timer_check(NULL) == GRPC_TIMERS_FIRED) { gpr_mu_unlock(&g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_iomgr_platform_flush(); gpr_mu_lock(&g_mu); continue; @@ -136,14 +136,14 @@ void grpc_iomgr_shutdown() { gpr_mu_unlock(&g_mu); grpc_timer_list_shutdown(); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* ensure all threads have left g_mu */ gpr_mu_lock(&g_mu); gpr_mu_unlock(&g_mu); grpc_iomgr_platform_shutdown(); - ExecCtx::GlobalShutdown(); + grpc_core::ExecCtx::GlobalShutdown(); grpc_network_status_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index 2ab414252a..5823bb7ec2 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -29,7 +29,7 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_global_init(); grpc_register_tracer(&grpc_tcp_trace); grpc_executor_set_threading(false); diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index a68ad4a6e3..89d28a0f9d 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -124,7 +124,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, GRPC_UV_ASSERT_SAME_THREAD(); gpr_mu_unlock(&grpc_polling_mu); if (grpc_pollset_work_run_loop) { - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline >= now) { timeout = deadline - now; } else { @@ -143,7 +143,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, } } if (!grpc_closure_list_empty(exec_ctx->closure_list)) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } gpr_mu_lock(&grpc_polling_mu); return GRPC_ERROR_NONE; diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 5ff3e7cb3a..81e1d009ca 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -129,7 +129,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, g_active_poller = &worker; gpr_mu_unlock(&grpc_polling_mu); grpc_iocp_work(deadline); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); pollset->is_iocp_worker = 0; g_active_poller = NULL; @@ -160,10 +160,10 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, while (!worker.kicked) { if (gpr_cv_wait(&worker.cv, &grpc_polling_mu, grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); break; } - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); } } else { pollset->kicked_without_pollers = 0; @@ -171,7 +171,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, done: if (!grpc_closure_list_empty(exec_ctx->closure_list)) { gpr_mu_unlock(&grpc_polling_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); } if (added_worker) { diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc index ffd70c4f35..54adf9b9f6 100644 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ b/src/core/lib/iomgr/resolve_address_uv.cc @@ -114,7 +114,7 @@ static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { request* r = (request*)req->data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_error* error; int retry_status; char* port = r->port; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 8fee585f4b..11cb5ddbee 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -622,7 +622,7 @@ void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { /* Public API */ void grpc_resource_quota_unref(grpc_resource_quota* resource_quota) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_quota_unref_internal(resource_quota); } @@ -647,7 +647,7 @@ double grpc_resource_quota_get_memory_pressure( /* Public API */ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t size) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a)); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota); a->size = (int64_t)size; diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 7454b01445..0bf3a043df 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -76,7 +76,7 @@ static void uv_tc_on_alarm(void* acp, grpc_error* error) { static void uv_tc_on_connect(uv_connect_t* req, int status) { grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_error* error = GRPC_ERROR_NONE; int done; grpc_closure* closure = connect->closure; @@ -105,7 +105,7 @@ static void uv_tc_on_connect(uv_connect_t* req, int status) { } done = (--connect->refs == 0); if (done) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); uv_tcp_connect_cleanup(connect); } GRPC_CLOSURE_SCHED(closure, error); diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index de3dabd7fc..04d4440f9e 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -130,7 +130,7 @@ static void run_poller(void* bp, grpc_error* error_ignored) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); } gpr_mu_lock(p->pollset_mu); - grpc_millis deadline = ExecCtx::Get()->Now() + 13 * GPR_MS_PER_SEC; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 13 * GPR_MS_PER_SEC; GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 9db2cbe58d..daa7afe95f 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -137,7 +137,7 @@ static void finish_shutdown(grpc_tcp_server* s) { static void handle_close_callback(uv_handle_t* handle) { grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; sp->server->open_ports--; if (sp->server->open_ports == 0 && sp->server->shutdown) { finish_shutdown(sp->server); @@ -174,9 +174,9 @@ void grpc_tcp_server_unref(grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); if (gpr_unref(&s->refs)) { /* Complete shutdown_starting work before destroying. */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); tcp_server_destroy(s); } } @@ -223,7 +223,7 @@ static void finish_accept(grpc_tcp_listener* sp) { static void on_connect(uv_stream_t* server, int status) { grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (status < 0) { switch (status) { diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 3ea9674840..742ab9a754 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -112,7 +112,7 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif static void uv_close_callback(uv_handle_t* handle) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; TCP_UNREF(tcp, "destroy"); } @@ -124,7 +124,7 @@ static grpc_slice alloc_read_slice(grpc_resource_user* resource_user) { static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; (void)suggested_size; buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slice); @@ -135,7 +135,7 @@ static void read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { grpc_slice sub; grpc_error* error; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp* tcp = (grpc_tcp*)stream->data; grpc_closure* cb = tcp->read_cb; if (nread == 0) { @@ -204,7 +204,7 @@ static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, static void write_callback(uv_write_t* req, int status) { grpc_tcp* tcp = (grpc_tcp*)req->data; grpc_error* error; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure* cb = tcp->write_cb; tcp->write_cb = NULL; TCP_UNREF(tcp, "write"); @@ -355,7 +355,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, grpc_resource_quota* resource_quota, char* peer_string) { grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (GRPC_TRACER_ON(grpc_tcp_trace)) { gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index d5e6066f35..ae82701676 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -249,7 +249,7 @@ void grpc_timer_list_init() { g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; gpr_mu_init(&g_shared_mutables.mu); - g_shared_mutables.min_timer = ExecCtx::Get()->Now(); + g_shared_mutables.min_timer = grpc_core::ExecCtx::Get()->Now(); gpr_tls_init(&g_last_seen_min_timer); gpr_tls_set(&g_last_seen_min_timer, 0); grpc_register_tracer(&grpc_timer_trace); @@ -341,7 +341,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, - deadline, ExecCtx::Get()->Now(), closure, closure->cb); + deadline, grpc_core::ExecCtx::Get()->Now(), closure, closure->cb); } if (!g_shared_mutables.initialized) { @@ -354,7 +354,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, gpr_mu_lock(&shard->mu); timer->pending = true; - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline <= now) { timer->pending = false; GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); @@ -607,7 +607,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, grpc_timer_check_result grpc_timer_check(grpc_millis* next) { // prelude - grpc_millis now = ExecCtx::Get()->Now(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); /* fetch from a thread-local first: this avoids contention on a globally mutable cacheline in the common case */ diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 69adb673d8..6a43f4fadb 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -98,7 +98,7 @@ static void start_timer_thread_and_unlock(void) { } void grpc_timer_manager_tick() { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_millis next = GRPC_MILLIS_INF_FUTURE; grpc_timer_check(&next); } @@ -125,7 +125,7 @@ static void run_some_timers() { if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -178,7 +178,7 @@ static bool wait_until(grpc_millis next) { g_timed_waiter_deadline = next; if (GRPC_TRACER_ON(grpc_timer_check_trace)) { - grpc_millis wait_time = next - ExecCtx::Get()->Now(); + grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -223,7 +223,7 @@ static bool wait_until(grpc_millis next) { static void timer_main_loop() { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); // check timer state, updates next to the next time to run a check switch (grpc_timer_check(&next)) { case GRPC_TIMERS_FIRED: @@ -273,7 +273,7 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; timer_main_loop(); timer_thread_cleanup((completed_thread*)completed_thread_ptr); diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 6edd4169f1..1432eba51e 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -45,7 +45,7 @@ static void stop_uv_timer(uv_timer_t* handle) { void run_expired_timer(uv_timer_t* handle) { grpc_timer* timer = (grpc_timer*)handle->data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(timer->pending); timer->pending = 0; @@ -59,13 +59,13 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, uv_timer_t* uv_timer; GRPC_UV_ASSERT_SAME_THREAD(); timer->closure = closure; - if (deadline <= ExecCtx::Get()->Now()) { + if (deadline <= grpc_core::ExecCtx::Get()->Now()) { timer->pending = 0; GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); return; } timer->pending = 1; - timeout = (uint64_t)(deadline - ExecCtx::Get()->Now()); + timeout = (uint64_t)(deadline - grpc_core::ExecCtx::Get()->Now()); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); uv_timer->data = timer; diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 9b58b3657f..570db78882 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -38,7 +38,7 @@ grpc_tracer_flag grpc_trace_auth_context_refcount = grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_client_security_context* ctx = NULL; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); @@ -87,7 +87,7 @@ grpc_client_security_context* grpc_client_security_context_create(void) { } void grpc_client_security_context_destroy(void* ctx) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_client_security_context* c = (grpc_client_security_context*)ctx; grpc_call_credentials_unref(c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 6a272653f8..5181f7f260 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -72,7 +72,7 @@ void grpc_channel_credentials_unref(grpc_channel_credentials* creds) { void grpc_channel_credentials_release(grpc_channel_credentials* creds) { GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_credentials_unref(creds); } @@ -94,7 +94,7 @@ void grpc_call_credentials_unref(grpc_call_credentials* creds) { void grpc_call_credentials_release(grpc_call_credentials* creds) { GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_call_credentials_unref(creds); } @@ -209,7 +209,7 @@ void grpc_server_credentials_unref(grpc_server_credentials* creds) { void grpc_server_credentials_release(grpc_server_credentials* creds) { GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_server_credentials_unref(creds); } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 03ec4bc3b3..a8991943b0 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -114,13 +114,13 @@ static int is_stack_running_on_compute_engine() { grpc_resource_quota_create("google_default_credentials"); grpc_httpcli_get( &context, &detector.pollent, resource_quota, &request, - ExecCtx::Get()->Now() + max_detection_delay, + grpc_core::ExecCtx::Get()->Now() + max_detection_delay, GRPC_CLOSURE_CREATE(on_compute_engine_detection_http_response, &detector, grpc_schedule_on_exec_ctx), &detector.response); grpc_resource_quota_unref_internal(resource_quota); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ @@ -144,7 +144,7 @@ static int is_stack_running_on_compute_engine() { grpc_pollset_shutdown(grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); g_polling_mu = NULL; - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); grpc_http_response_destroy(&detector.response); @@ -220,7 +220,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ()); @@ -290,7 +290,7 @@ end: } void grpc_flush_cached_google_default_credentials(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); if (default_credentials != NULL) { diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 4d9da0cbe3..9f3a86877b 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -54,7 +54,7 @@ static grpc_call_credentials_vtable iam_vtable = { grpc_call_credentials* grpc_google_iam_credentials_create( const char* token, const char* authority_selector, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index ccc3f4aeed..3facce1798 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -181,7 +181,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( gpr_free(clean_json); } GPR_ASSERT(reserved == NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_auth_json_key_create_from_string(json_key), token_lifetime); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 5246e1f985..dd0d206b01 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -347,7 +347,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( grpc_jwt_claims* claims, const char* audience, grpc_slice signature, const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx)); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); @@ -702,7 +702,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) { resource_quota = grpc_resource_quota_create("jwt_verifier"); grpc_httpcli_get( &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, - ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, + grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, GRPC_CLOSURE_CREATE(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx), &ctx->responses[HTTP_RESPONSE_KEYS]); grpc_resource_quota_unref_internal(resource_quota); @@ -827,9 +827,10 @@ static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { channel. This would allow us to cancel an authentication query when under extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); - grpc_httpcli_get(&ctx->verifier->http_ctx, &ctx->pollent, resource_quota, - &req, ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, - http_cb, &ctx->responses[rsp_idx]); + grpc_httpcli_get( + &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, http_cb, + &ctx->responses[rsp_idx]); grpc_resource_quota_unref_internal(resource_quota); gpr_free(req.host); gpr_free(req.http.path); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index b653705609..71be15a46e 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -217,7 +217,7 @@ static void on_oauth2_token_fetcher_http_response(void* user_data, c->token_fetch_pending = false; c->access_token_md = GRPC_MDELEM_REF(access_token_md); c->token_expiration = status == GRPC_CREDENTIALS_OK - ? ExecCtx::Get()->Now() + token_lifetime + ? grpc_core::ExecCtx::Get()->Now() + token_lifetime : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; @@ -256,7 +256,8 @@ static bool oauth2_token_fetcher_get_request_metadata( grpc_mdelem cached_access_token_md = GRPC_MDNULL; gpr_mu_lock(&c->mu); if (!GRPC_MDISNULL(c->access_token_md) && - (c->token_expiration - ExecCtx::Get()->Now() > refresh_threshold)) { + (c->token_expiration - grpc_core::ExecCtx::Get()->Now() > + refresh_threshold)) { cached_access_token_md = GRPC_MDELEM_REF(c->access_token_md); } if (!GRPC_MDISNULL(cached_access_token_md)) { @@ -288,7 +289,7 @@ static bool oauth2_token_fetcher_get_request_metadata( c->fetch_func(grpc_credentials_metadata_request_create(creds), &c->httpcli_context, &c->pollent, on_oauth2_token_fetcher_http_response, - ExecCtx::Get()->Now() + refresh_threshold); + grpc_core::ExecCtx::Get()->Now() + refresh_threshold); } return false; } @@ -514,7 +515,7 @@ grpc_call_credentials* grpc_access_token_credentials_create( gpr_ref_init(&c->base.refcount, 1); char* token_md_value; gpr_asprintf(&token_md_value, "Bearer %s", access_token); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; c->access_token_md = grpc_mdelem_from_slices( grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(token_md_value)); diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 025d024617..7634cadc3a 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -116,8 +116,8 @@ static void plugin_md_request_metadata_ready(void* request, grpc_status_code status, const char* error_details) { /* called from application code */ - ExecCtx _local_exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | - GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); + grpc_core::ExecCtx _local_exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 4ed2ec55bd..0df3375d34 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -255,7 +255,7 @@ static void on_handshake_next_done_grpc_wrapper( security_handshaker* h = (security_handshaker*)user_data; // This callback will be invoked by TSI in a non-grpc thread, so it's // safe to create our own exec_ctx here. - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_mu_lock(&h->mu); grpc_error* error = on_handshake_next_done_locked( h, result, bytes_to_send, bytes_to_send_size, handshaker_result); diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 86817076f8..5f5ff7c09c 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -118,7 +118,7 @@ static void on_md_processing_done( grpc_status_code status, const char* error_details) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // If the call was not cancelled while we were in flight, process the result. if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_DONE)) { diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 6e1554d471..3604bb77a8 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -67,7 +67,7 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { /* Public API */ void grpc_slice_unref(grpc_slice slice) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_unref_internal(slice); } diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 4bc54c303f..0a4d48f114 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -73,7 +73,7 @@ void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(sb); } @@ -172,7 +172,7 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer_reset_and_unref_internal(sb); } diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 7aee100f3f..8dcfb1ddb5 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -47,7 +47,7 @@ static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } static void alarm_unref(grpc_alarm* alarm) { if (gpr_unref(&alarm->refs)) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (alarm->cq != NULL) { GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); } @@ -117,7 +117,7 @@ grpc_alarm* grpc_alarm_create(void* reserved) { void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, gpr_timespec deadline, void* tag, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CQ_INTERNAL_REF(cq, "alarm"); alarm->cq = cq; @@ -129,7 +129,7 @@ void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, } void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_timer_cancel(&alarm->alarm); } diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index 6a9b13bb41..03097c6896 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -71,7 +71,7 @@ grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { if (!bb) return; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; switch (bb->type) { case GRPC_BB_RAW: grpc_slice_buffer_destroy_internal(&bb->data.raw.slice_buffer); diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index 9a9e26ecdc..c5f8df3dda 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -42,7 +42,7 @@ static int is_compressed(grpc_byte_buffer* buffer) { int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer decompressed_slices_buffer; reader->buffer_in = buffer; switch (reader->buffer_in->type) { @@ -110,7 +110,7 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) { grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size); uint8_t* const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { const size_t slice_length = GRPC_SLICE_LENGTH(in_slice); memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length); diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index bbb7a39e29..cb858785f2 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -561,7 +561,7 @@ void grpc_call_unref(grpc_call* c) { if (!gpr_unref(&c->ext_ref)) return; child_call* cc = c->child; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_TIMER_BEGIN("grpc_call_unref", 0); GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c)); @@ -602,7 +602,7 @@ void grpc_call_unref(grpc_call* c) { grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); GPR_ASSERT(!reserved); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); return GRPC_CALL_OK; @@ -652,7 +652,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, grpc_status_code status, const char* description, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE( "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", @@ -2034,7 +2034,7 @@ done_with_error: grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* tag, void* reserved) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_call_error err; GRPC_API_TRACE( diff --git a/src/core/lib/surface/call_details.cc b/src/core/lib/surface/call_details.cc index 03ce7f88fb..7d81ba9e22 100644 --- a/src/core/lib/surface/call_details.cc +++ b/src/core/lib/surface/call_details.cc @@ -34,7 +34,7 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_unref_internal(cd->method); grpc_slice_unref_internal(cd->host); } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 7725351f74..80ba47676e 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -248,7 +248,7 @@ char* grpc_channel_get_target(grpc_channel* channel) { void grpc_channel_get_info(grpc_channel* channel, const grpc_channel_info* channel_info) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); elem->filter->get_channel_info(elem, channel_info); @@ -296,7 +296,7 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel, grpc_slice method, const grpc_slice* host, gpr_timespec deadline, void* reserved) { GPR_ASSERT(!reserved); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_call* call = grpc_channel_create_call_internal( channel, parent_call, propagation_mask, cq, NULL, grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), @@ -329,7 +329,7 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; rc->path = grpc_mdelem_from_slices( GRPC_MDSTR_PATH, @@ -364,7 +364,7 @@ grpc_call* grpc_channel_create_registered_call( registered_call_handle, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_call* call = grpc_channel_create_call_internal( channel, parent_call, propagation_mask, completion_queue, NULL, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), @@ -407,7 +407,7 @@ static void destroy_channel(void* arg, grpc_error* error) { void grpc_channel_destroy(grpc_channel* channel) { grpc_transport_op* op = grpc_make_transport_op(NULL); grpc_channel_element* elem; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel)); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Destroyed"); diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index 06cdbf6c73..545b8fe6ee 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -51,7 +51,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(reserved == NULL); pr->tag = tag; pr->cq = cq; diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 0b0a8d070d..24c502881a 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -124,7 +124,7 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset, while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline_ts)) ; - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); if (&w == npp->root) { npp->root = w.next; if (&w == npp->root) { @@ -359,7 +359,7 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, if (storage != NULL && (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; *ok = (storage->next & (uintptr_t)(1)) == 1; storage->done(storage->done_arg, storage); ret = 1; @@ -395,7 +395,7 @@ static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { grpc_cq_completion* c = NULL; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (gpr_spinlock_trylock(&q->queue_lock)) { GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); @@ -440,7 +440,7 @@ grpc_completion_queue* grpc_completion_queue_create_internal( const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_STATS_INC_CQS_CREATED(); cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + @@ -790,7 +790,7 @@ typedef struct { bool first_loop; } cq_is_finished_arg; -class ExecCtxNext : public ExecCtx { +class ExecCtxNext : public grpc_core::ExecCtx { public: ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} @@ -818,7 +818,7 @@ class ExecCtxNext : public ExecCtx { return true; } } - return !a->first_loop && a->deadline < ExecCtx::Get()->Now(); + return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); } private: @@ -929,7 +929,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, } if (!is_finished_arg.first_loop && - ExecCtx::Get()->Now() >= deadline_millis) { + grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; dump_pending_tags(cq); @@ -1045,7 +1045,7 @@ static void del_plucker(grpc_completion_queue* cq, void* tag, GPR_UNREACHABLE_CODE(return ); } -class ExecCtxPluck : public ExecCtx { +class ExecCtxPluck : public grpc_core::ExecCtx { public: ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} @@ -1079,7 +1079,7 @@ class ExecCtxPluck : public ExecCtx { } gpr_mu_unlock(cq->mu); } - return !a->first_loop && a->deadline < ExecCtx::Get()->Now(); + return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); } private: @@ -1169,7 +1169,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } if (!is_finished_arg.first_loop && - ExecCtx::Get()->Now() >= deadline_millis) { + grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); memset(&ret, 0, sizeof(ret)); @@ -1250,7 +1250,7 @@ static void cq_shutdown_pluck(grpc_completion_queue* cq) { /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); cq->vtable->shutdown(cq); @@ -1263,7 +1263,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); GPR_TIMER_END("grpc_completion_queue_destroy", 0); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 20e17a7f60..fdbf926f77 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -116,7 +116,7 @@ void grpc_init(void) { int i; gpr_once_init(&g_basic_init, do_basic_init); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); @@ -175,7 +175,7 @@ void grpc_init(void) { void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_executor_shutdown(); diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index da081e68cb..3bbdd21285 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -156,7 +156,7 @@ extern "C" const grpc_channel_filter grpc_lame_filter = { grpc_channel* grpc_lame_client_channel_create(const char* target, grpc_status_code error_code, const char* error_message) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_element* elem; grpc_channel* channel = grpc_channel_create(target, NULL, GRPC_CLIENT_LAME_CHANNEL, NULL); diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 0d4435d556..835e495495 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -1022,7 +1022,7 @@ static void start_listeners(void* s, grpc_error* error) { void grpc_server_start(grpc_server* server) { size_t i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server)); @@ -1168,7 +1168,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, listener* l; shutdown_tag* sdt; channel_broadcaster broadcaster; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3, (server, cq, tag)); @@ -1227,7 +1227,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, void grpc_server_cancel_all_calls(grpc_server* server) { channel_broadcaster broadcaster; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server)); @@ -1242,7 +1242,7 @@ void grpc_server_cancel_all_calls(grpc_server* server) { void grpc_server_destroy(grpc_server* server) { listener* l; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server)); @@ -1324,7 +1324,7 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( @@ -1371,7 +1371,7 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); registered_method* rm = (registered_method*)rmp; GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 4e279b4d94..d2b6e5db25 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -79,7 +79,7 @@ grpc_millis BdpEstimator::CompletePing() { } ping_state_ = PingState::UNSCHEDULED; accumulator_ = 0; - return ExecCtx::Get()->Now() + inter_ping_delay_; + return grpc_core::ExecCtx::Get()->Now() + inter_ping_delay_; } } // namespace grpc_core diff --git a/src/core/lib/transport/status_conversion.cc b/src/core/lib/transport/status_conversion.cc index 61470b8c78..46cba4292b 100644 --- a/src/core/lib/transport/status_conversion.cc +++ b/src/core/lib/transport/status_conversion.cc @@ -46,8 +46,9 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, case GRPC_HTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ - return ExecCtx::Get()->Now() > deadline ? GRPC_STATUS_DEADLINE_EXCEEDED - : GRPC_STATUS_CANCELLED; + return grpc_core::ExecCtx::Get()->Now() > deadline + ? GRPC_STATUS_DEADLINE_EXCEEDED + : GRPC_STATUS_CANCELLED; case GRPC_HTTP2_ENHANCE_YOUR_CALM: return GRPC_STATUS_RESOURCE_EXHAUSTED; case GRPC_HTTP2_INADEQUATE_SECURITY: diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index ca80a7404d..ed2f02de55 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -62,7 +62,8 @@ void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { void grpc_stream_unref(grpc_stream_refcount* refcount) { #endif if (gpr_unref(&refcount->refs)) { - if (ExecCtx::Get()->flags() & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { + if (grpc_core::ExecCtx::Get()->flags() & + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { /* Ick. The thread we're running on MAY be owned (indirectly) by a call-stack. If that's the case, destroying the call-stack MAY try to destroy the diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 0bcfac2845..82d687c530 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -67,7 +67,7 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } ChannelArguments::~ChannelArguments() { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == GRPC_ARG_POINTER) { it->value.pointer.vtable->destroy(it->value.pointer.p); @@ -95,7 +95,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { } grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator); bool replaced = false; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 739ab86bb2..76a9f39c35 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -32,19 +32,23 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); for (int i = 0; i < 10000; i++) { next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } } @@ -57,15 +61,15 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == initial_backoff); } @@ -80,45 +84,45 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - ExecCtx _local_exec_ctx; - ExecCtx::Get()->SetNow(0); + grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); } @@ -136,11 +140,13 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); grpc_millis expected_next_lower_bound = @@ -153,7 +159,7 @@ static void test_jitter_backoff(void) { // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - ExecCtx::Get()->Now(); + next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -162,7 +168,7 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index bc9e65089c..b7c9404638 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -57,7 +57,7 @@ static void done_write(void* arg, grpc_error* error) { static void server_setup_transport(void* ts, grpc_transport* transport) { thd_args* a = (thd_args*)ts; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_server_setup_transport(a->server, transport, NULL, grpc_server_get_channel_args(a->server)); } @@ -80,7 +80,7 @@ void grpc_run_bad_client_test( grpc_slice_from_copied_buffer(client_payload, client_payload_length); grpc_slice_buffer outgoing; grpc_closure done_write_closure; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_completion_queue* shutdown_cq; if (client_payload_length < 4 * 1024) { diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index f0393b0f40..eb2654e6a9 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -26,7 +26,7 @@ #include "test/core/util/test_config.h" static void test_create(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_arg arg_int; grpc_arg arg_string; @@ -59,7 +59,7 @@ static void test_create(void) { } static void test_set_compression_algorithm(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args* ch_args; ch_args = @@ -73,7 +73,7 @@ static void test_set_compression_algorithm(void) { } static void test_compression_algorithm_states(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; unsigned states_bitset; size_t i; @@ -134,7 +134,7 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ch_args); } } diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index 66ee2948b1..21d7e89cb0 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -95,7 +95,7 @@ static void test_create_channel_stack(void) { grpc_channel_args chan_args; int* channel_data; int* call_data; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; @@ -138,7 +138,7 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*channel_data == 1); GRPC_CALL_STACK_UNREF(call_stack, "done"); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(*channel_data == 2); GRPC_CHANNEL_STACK_UNREF(channel_stack, "done"); diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index dd3c70a261..5aab969276 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -124,7 +124,7 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_transport(builder, &fake_transport); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); GPR_ASSERT(grpc_channel_init_create_stack( builder, (grpc_channel_stack_type)channel_stack_type)); @@ -209,7 +209,7 @@ static int check_stack(const char* file, int line, const char* transport_name, gpr_free(expect); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_stack_builder_destroy(builder); grpc_channel_args_destroy(channel_args); } diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 5b412cc622..88e12ed8e1 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,7 +651,7 @@ static void test_get_channel_info() { grpc_channel_args* args = grpc_channel_args_copy_and_add(NULL, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } // Ensures that resolver returns. @@ -958,7 +958,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 597a1212c1..8f88083045 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -33,7 +33,7 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; @@ -53,7 +53,7 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) {} static void test_grpc_parse_ipv4(const char* uri_text, const char* host, unsigned short port) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -71,7 +71,7 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, static void test_grpc_parse_ipv6(const char* uri_text, const char* host, unsigned short port, uint32_t scope_id) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index c7a0e029f2..1f00d9ab43 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -104,7 +104,7 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_timer_check(NULL); } return false; @@ -146,14 +146,14 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolver* resolver = create_resolver("dns:test"); gpr_event ev1; gpr_event_init(&ev1); call_resolver_next_after_locking( resolver, &result, GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(wait_loop(5, &ev1)); GPR_ASSERT(result == NULL); @@ -162,7 +162,7 @@ int main(int argc, char** argv) { call_resolver_next_after_locking( resolver, &result, GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(wait_loop(30, &ev2)); GPR_ASSERT(result != NULL); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 33916b59ec..e8900ab1bb 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,7 +28,7 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -45,7 +45,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { } static void test_fails(grpc_resolver_factory* factory, const char* string) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -80,7 +80,7 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index 9a1971561c..1595313f36 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -72,7 +72,7 @@ void on_resolution_cb(void* arg, grpc_error* error) { } static void test_fake_resolver() { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = @@ -109,7 +109,7 @@ static void test_fake_resolver() { results); grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != NULL); @@ -144,7 +144,7 @@ static void test_fake_resolver() { results_update); grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, on_resolution); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != NULL); @@ -153,7 +153,7 @@ static void test_fake_resolver() { memset(&on_res_arg, 0, sizeof(on_res_arg)); grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL); diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index 70b3cbf5b7..7584901813 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -41,7 +41,7 @@ void on_resolution_cb(void* arg, grpc_error* error) { } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -68,7 +68,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { } static void test_fails(grpc_resolver_factory* factory, const char* string) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -111,7 +111,7 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index 6c1e8cb137..484676e472 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -33,7 +33,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { memcpy(s, data, size); s[size] = 0; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* x; if ((x = grpc_uri_parse(s, 1))) { grpc_uri_destroy(x); diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 024c30faee..61418ae7d8 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -28,7 +28,7 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); @@ -41,13 +41,13 @@ static void test_succeeds(const char* uri_text, const char* scheme, } static void test_fails(const char* uri_text) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); } static void test_query_parts() { { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); @@ -81,7 +81,7 @@ static void test_query_parts() { } { /* test the current behavior of multiple query part values */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); @@ -99,7 +99,7 @@ static void test_query_parts() { } { /* empty query */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; const char* uri_text = "http://foo/path"; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index 9ae6363d97..a6fc55e682 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -39,7 +39,7 @@ static void test_algorithm_mesh(void) { grpc_compression_algorithm parsed; grpc_slice mdstr; grpc_mdelem mdelem; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); GPR_ASSERT(grpc_compression_algorithm_parse( @@ -61,7 +61,7 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index a5dfdc884f..0145b4f402 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -70,7 +70,7 @@ static void assert_passthrough(grpc_slice value, grpc_split_slices_to_buffer(uncompressed_split_mode, &value, 1, &input); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); } GPR_ASSERT(input.count > 0); @@ -90,7 +90,7 @@ static void assert_passthrough(grpc_slice value, grpc_split_slice_buffer(compressed_split_mode, &compressed_raw, &compressed); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_msg_decompress( was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); } @@ -152,7 +152,7 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(0 == grpc_msg_compress(static_cast(i), &input, &output)); @@ -176,7 +176,7 @@ static void test_bad_decompression_data_crc(void) { grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* compress it */ grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ @@ -205,7 +205,7 @@ static void test_bad_decompression_data_trailing_garbage(void) { "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13)); /* try (and fail) to decompress the invalid compresed buffer */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); @@ -222,7 +222,7 @@ static void test_bad_decompression_data_stream(void) { grpc_slice_from_copied_buffer("\x78\xda\xff\xff", 4)); /* try (and fail) to decompress the invalid compresed buffer */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); @@ -239,7 +239,7 @@ static void test_bad_compression_algorithm(void) { grpc_slice_buffer_add( &input, grpc_slice_from_copied_string("Never gonna give you up")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; was_compressed = grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_compressed); @@ -263,7 +263,7 @@ static void test_bad_decompression_algorithm(void) { grpc_slice_buffer_add(&input, grpc_slice_from_copied_string( "I'm not really compressed but it doesn't matter")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; was_decompressed = grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index c7aaf68dd3..a3bb44f496 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -49,7 +49,7 @@ TEST(StatsTest, IncCounters) { for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { Snapshot snapshot; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); EXPECT_EQ(snapshot.delta().counters[i], 1); @@ -59,7 +59,7 @@ TEST(StatsTest, IncCounters) { TEST(StatsTest, IncSpecificCounter) { Snapshot snapshot; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_STATS_INC_SYSCALL_POLL(); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); @@ -92,7 +92,7 @@ TEST_P(HistogramTest, IncHistogram) { for (auto j : test_values) { Snapshot snapshot; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_stats_inc_histogram[kHistogram](j); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 5e7e12643e..bb192267c7 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -269,7 +269,7 @@ static void run_test(const char* response_payload, grpc_status_code expected_status, const char* expected_detail) { test_tcp_server test_server; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_event ev; grpc_init(); diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index 1372c5a746..2c4163ea02 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -131,7 +131,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_metadata_array_destroy(&trailing_metadata_recv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (args != NULL) grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index a43d963c54..885b2b22b9 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -74,7 +74,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); GPR_ASSERT(f->client); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); } } @@ -90,7 +90,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, NULL); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index 3f9a87d0fc..6fea4d40e0 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -66,7 +66,7 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->client_args_compression != NULL) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ffd->client_args_compression); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( @@ -80,7 +80,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->server_args_compression != NULL) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( @@ -95,7 +95,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, } void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); grpc_channel_args_destroy(ffd->client_args_compression); diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 99bced8651..62cc0f6f8f 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -68,7 +68,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->client); @@ -79,7 +79,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, NULL); diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index e98df083f2..074ba289c9 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -71,7 +71,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { int i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; fullstack_fixture_data* ffd = static_cast(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 84eb9e4513..846319285e 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -77,7 +77,7 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, NULL); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 9ffc5b7b7e..b648a1be4d 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -143,7 +143,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 9e87a22962..c18f815f9f 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -50,7 +50,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, @@ -87,7 +87,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -101,7 +101,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); @@ -126,7 +126,7 @@ static grpc_end2end_test_config configs[] = { int main(int argc, char** argv) { size_t i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* force tracing on, with a value to force many code paths in trace.c to be taken */ diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index fa69ad84cf..6c34dbba6f 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -44,7 +44,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, @@ -81,7 +81,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -95,7 +95,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index a12d60575b..909a2db8aa 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -44,7 +44,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, NULL, @@ -92,7 +92,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -106,7 +106,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index c137cec8b9..ea8286c9e7 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -110,7 +110,7 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index 0c130d6ae1..d50cd5c9e3 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -66,7 +66,7 @@ static grpc_channel* create_proxy_client(const char* target, grpc_secure_channel_create(ssl_creds, target, new_client_args, NULL); grpc_channel_credentials_release(ssl_creds); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); } return channel; @@ -147,7 +147,7 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 73a3e2c444..698282d990 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -391,7 +391,8 @@ static void on_read_request_done(void* arg, grpc_error* error) { GPR_ASSERT(resolved_addresses->naddrs >= 1); // Connect to requested address. // The connection callback inherits our reference to conn. - const grpc_millis deadline = ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; + const grpc_millis deadline = + grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, conn->pollset_set, NULL, &resolved_addresses->addrs[0], deadline); @@ -444,7 +445,7 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; do { gpr_ref(&proxy->users); grpc_pollset_worker* worker = NULL; @@ -452,15 +453,15 @@ static void thread_main(void* arg) { GRPC_LOG_IF_ERROR( "grpc_pollset_work", grpc_pollset_work(proxy->pollset, &worker, - ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } while (!gpr_unref(&proxy->users)); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -505,7 +506,7 @@ static void destroy_pollset(void* arg, grpc_error* error) { void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_thd_join(proxy->thd); grpc_tcp_server_shutdown_listeners(proxy->server); grpc_tcp_server_unref(proxy->server); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 1d22ba3a42..3fb6d0fdb6 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -411,7 +411,7 @@ void my_resolve_address(const char* addr, const char* default_port, r->addrs = addresses; r->lb_addrs = NULL; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } @@ -428,7 +428,7 @@ grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, r->addrs = NULL; r->lb_addrs = lb_addrs; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); return NULL; } @@ -488,7 +488,7 @@ static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, fc->ep = ep; fc->deadline = deadline; grpc_timer_init( - &fc->timer, GPR_MS_PER_SEC + ExecCtx::Get()->Now(), + &fc->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx)); } @@ -743,7 +743,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_timer_manager_set_threading(false); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_executor_set_threading(false); } grpc_resolve_address = my_resolve_address; @@ -837,7 +837,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_insecure_channel_create(target_uri, args, NULL); GPR_ASSERT(g_channel != NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } gpr_free(target_uri); @@ -864,7 +864,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_server = grpc_server_create(args, NULL); GPR_ASSERT(g_server != NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } grpc_server_register_completion_queue(g_server, cq, NULL); @@ -1192,7 +1192,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_secure_channel_create(creds, target_uri, args, NULL); GPR_ASSERT(g_channel != NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } gpr_free(target_uri); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index 95ed2fcdac..318e8129d0 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -43,7 +43,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_executor_set_threading(false); grpc_resource_quota* resource_quota = @@ -111,7 +111,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_event ev; while (1) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); switch (ev.type) { case GRPC_QUEUE_TIMEOUT: diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 21778c0a67..dca3ff498e 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -41,7 +41,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_executor_set_threading(false); grpc_resource_quota* resource_quota = @@ -78,7 +78,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_event ev; while (1) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); switch (ev.type) { case GRPC_QUEUE_TIMEOUT: diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index e0da548a75..97c0692711 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -181,7 +181,7 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ { \ - ExecCtx _local_exec_ctx; \ + grpc_core::ExecCtx _local_exec_ctx; \ grpc_channel_args_destroy(new_client_args); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index ffafb1f1e9..45ea2b9906 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -245,7 +245,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_unref(s); if (args != NULL) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index 7e20487f8b..231aa7abbc 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -277,7 +277,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_unref(s); if (args != NULL) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index f04addbe9e..aa3523a987 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -129,7 +129,7 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_compression_algorithm(NULL, GRPC_COMPRESS_NONE); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); } @@ -256,7 +256,7 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } @@ -534,7 +534,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index 6ce22d77c6..34c046d364 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -300,7 +300,7 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { &trailing_lr_metadata); end_test(&f); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(lr_server_args); } config.tear_down_data(&f); diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index f884d8b11f..808cf470e1 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -173,7 +173,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, f = begin_test(config, "test_max_request_message_length", client_args, server_args); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (client_args != NULL) grpc_channel_args_destroy(client_args); if (server_args != NULL) grpc_channel_args_destroy(server_args); } @@ -363,7 +363,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, f = begin_test(config, "test_max_response_message_length", client_args, server_args); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; if (client_args != NULL) grpc_channel_args_destroy(client_args); if (server_args != NULL) grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index cec46305bd..d118aceeb1 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -129,7 +129,7 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_stream_compression_algorithm( NULL, GRPC_STREAM_COMPRESS_NONE); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; server_args = grpc_channel_args_stream_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); } @@ -257,7 +257,7 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } @@ -542,7 +542,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index c304c990d7..6bd1e99ca1 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -277,7 +277,7 @@ static void test_invoke_request_response_with_payload( end_test(&f); config.tear_down_data(&f); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index f4b737d7a3..2504c791e6 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -273,7 +273,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, end_test(&f); config.tear_down_data(&f); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index 100f393b8e..723d3274e2 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -142,7 +142,7 @@ static void request_with_payload_template( NULL, default_server_channel_compression_algorithm); if (user_agent_override) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args* client_args_old = client_args; grpc_arg arg; arg.key = const_cast(GRPC_ARG_PRIMARY_USER_AGENT_STRING); @@ -348,7 +348,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index dfa328360d..4f9421e6d4 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -60,7 +60,7 @@ static void on_finish(void* arg, grpc_error* error) { static void test_get(int port) { grpc_httpcli_request req; char* host; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -99,7 +99,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -142,7 +142,7 @@ static void destroy_pops(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_subprocess* server; char* me = argv[0]; char* lslash = strrchr(me, '/'); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index ff082e8367..fb69fc97d1 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -60,7 +60,7 @@ static void on_finish(void* arg, grpc_error* error) { static void test_get(int port) { grpc_httpcli_request req; char* host; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -100,7 +100,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -144,7 +144,7 @@ static void destroy_pops(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_subprocess* server; char* me = argv[0]; char* lslash = strrchr(me, '/'); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index df8d55f1f6..cf2bc0ce06 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -28,7 +28,7 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); } @@ -42,11 +42,11 @@ static void test_execute_one(void) { grpc_combiner* lock = grpc_combiner_create(); gpr_event done; gpr_event_init(&done); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != NULL); GRPC_COMBINER_UNREF(lock, "test_execute_one"); @@ -72,7 +72,7 @@ static void check_one(void* a, grpc_error* error) { static void execute_many_loop(void* a) { thd_args* args = static_cast(a); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; size_t n = 1; for (size_t i = 0; i < 10; i++) { for (size_t j = 0; j < 10000; j++) { @@ -82,7 +82,7 @@ static void execute_many_loop(void* a) { GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE( check_one, c, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } // sleep for a little bit, to test a combiner draining and another thread // picking it up @@ -112,7 +112,7 @@ static void test_execute_many(void) { gpr_inf_future(GPR_CLOCK_REALTIME)) != NULL); gpr_thd_join(thds[i]); } - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_COMBINER_UNREF(lock, "test_execute_many"); } @@ -133,12 +133,12 @@ static void test_execute_finally(void) { gpr_log(GPR_DEBUG, "test_execute_finally"); grpc_combiner* lock = grpc_combiner_create(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_event_init(&got_in_finally); GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&got_in_finally, grpc_timeout_seconds_to_deadline(5)) != NULL); GRPC_COMBINER_UNREF(lock, "test_execute_finally"); diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 72833a8dbe..658971b9fb 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -32,7 +32,7 @@ static void clean_up(void) {} static grpc_endpoint_test_fixture create_fixture_endpoint_pair( size_t slice_size) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_test_fixture f; grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); @@ -59,7 +59,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 5c156ef524..e000eb289b 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -173,7 +173,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, struct read_and_write_test_state state; grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, @@ -213,7 +213,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, even when bytes_written is unsigned. */ state.bytes_written -= state.current_write_size; read_and_write_test_write_handler(&state, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read); @@ -225,17 +225,17 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_endpoint_shutdown( state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); } - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = NULL; - GPR_ASSERT(ExecCtx::Get()->Now() < deadline); + GPR_ASSERT(grpc_core::ExecCtx::Get()->Now() < deadline); GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); end_test(config); grpc_slice_buffer_destroy_internal(&state.outgoing); @@ -252,16 +252,17 @@ static void inc_on_failure(void* arg, grpc_error* error) { } static void wait_for_fail_count(int* fail_count, int want_fail_count) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); - while (ExecCtx::Get()->Now() < deadline && *fail_count < want_fail_count) { + while (grpc_core::ExecCtx::Get()->Now() < deadline && + *fail_count < want_fail_count) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(*fail_count == want_fail_count); @@ -276,7 +277,7 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_slice_buffer slice_buffer; grpc_slice_buffer_init(&slice_buffer); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 5c71bc6152..8aa68c6f6f 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -77,11 +77,11 @@ static void test_fd_cleanup(test_fd* tfds, int num_fds) { for (i = 0; i < num_fds; i++) { grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_fd_orphan(tfds[i].fd, NULL, &release_fd, false /* already_closed */, "test_fd_cleanup"); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(release_fd == tfds[i].inner_fd); close(tfds[i].inner_fd); @@ -110,7 +110,7 @@ static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].pollset); } } @@ -130,7 +130,7 @@ static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { #define NUM_POLLSETS 4 static void test_add_fd_to_pollset() { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; test_fd tfds[NUM_FDS]; int fds[NUM_FDS]; test_pollset pollsets[NUM_POLLSETS]; @@ -168,32 +168,32 @@ static void test_add_fd_to_pollset() { /* == Step 1 == */ for (i = 0; i <= 2; i++) { grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 3; i <= 4; i++) { grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 5; i <= 7; i++) { grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 2 == */ for (i = 0; i <= 1; i++) { grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 3 == */ grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* == Step 4 == */ grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* All polling islands are merged at this point */ @@ -231,7 +231,7 @@ static __thread int thread_wakeups = 0; static void test_threading_loop(void* arg) { threading_shared* shared = static_cast(arg); while (thread_wakeups < 1000000) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_worker* worker; gpr_mu_lock(shared->mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( @@ -271,7 +271,7 @@ static void test_threading(void) { shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup"); shared.wakeups = 0; { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); grpc_fd_notify_on_read( shared.wakeup_desc, @@ -286,7 +286,7 @@ static void test_threading(void) { fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); grpc_fd_orphan(shared.wakeup_desc, NULL, NULL, false /* already_closed */, "done"); @@ -301,7 +301,7 @@ int main(int argc, char** argv) { const char* poll_strategy = NULL; grpc_test_init(argc, argv); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epollsig") == 0) { diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index 7f3420269e..11e664d8ff 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -31,7 +31,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* set max # of file descriptors to a low value, and verify we can create and destroy many more than this number @@ -45,7 +45,7 @@ int main(int argc, char** argv) { p = grpc_iomgr_create_endpoint_pair("test", NULL); grpc_endpoint_destroy(p.client); grpc_endpoint_destroy(p.server); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } grpc_resource_quota_unref(resource_quota); diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index d22cb5f4f6..160cfd4e99 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -246,7 +246,7 @@ static int server_start(server* sv) { static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", @@ -362,7 +362,7 @@ static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker* worker = NULL; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); @@ -380,7 +380,7 @@ static void test_grpc_fd(void) { server sv; client cl; int port; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; server_init(&sv); port = server_start(&sv); @@ -436,7 +436,7 @@ static void test_grpc_fd_change(void) { ssize_t result; grpc_closure first_closure; grpc_closure second_closure; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CLOSURE_INIT(&first_closure, first_read_callback, &a, grpc_schedule_on_exec_ctx); @@ -513,7 +513,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); @@ -523,7 +523,7 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(g_pollset, &destroyed); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(g_pollset); grpc_shutdown(); diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index e9b46f59e3..bc9aafd5bd 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -84,7 +84,7 @@ static void cleanup_test_pollsets(test_pollset* pollsets, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(pollsets[i].ps, &destroyed); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].ps); pollsets[i].ps = NULL; } @@ -129,7 +129,7 @@ static void cleanup_test_fds(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also * calls close() on the underlying fd. In our case, we are using @@ -138,7 +138,7 @@ static void cleanup_test_fds(test_fd* tfds, const int num_fds) { * underlying fd, call it with a non-NULL 'release_fd' parameter */ grpc_fd_orphan(tfds[i].fd, NULL, &release_fd, false /* already_closed */, "test_fd_cleanup"); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); } @@ -199,7 +199,7 @@ static void pollset_set_test_basic() { * | * +---> FD9 (Added after PS2 is added to PSS0) */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -236,7 +236,7 @@ static void pollset_set_test_basic() { grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Test that if any FD in the above structure is readable, it is observable by * doing grpc_pollset_work on any pollset @@ -259,10 +259,10 @@ static void pollset_set_test_basic() { grpc_pollset_work(pollsets[i].ps, &worker, deadline)); gpr_mu_unlock(pollsets[i].mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } /* Test tear down */ @@ -270,14 +270,14 @@ static void pollset_set_test_basic() { grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(pollsets, num_ps); @@ -301,7 +301,7 @@ void pollset_set_test_dup_fds() { * | +--> FD2 * +---> FD1 */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -337,10 +337,10 @@ void pollset_set_test_dup_fds() { GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(pollset.ps, &worker, deadline)); gpr_mu_unlock(pollset.mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); @@ -349,7 +349,7 @@ void pollset_set_test_dup_fds() { grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(&pollset, num_ps); @@ -371,7 +371,7 @@ void pollset_set_test_empty_pollset() { * | * +---> FD2 */ - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -404,16 +404,16 @@ void pollset_set_test_empty_pollset() { GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(pollsets[0].ps, &worker, deadline)); gpr_mu_unlock(pollsets[0].mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); verify_readable_and_reset(tfds, num_fds); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); cleanup_test_fds(tfds, num_fds); cleanup_test_pollsets(pollsets, num_ps); @@ -421,7 +421,7 @@ void pollset_set_test_empty_pollset() { } int main(int argc, char** argv) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); const char* poll_strategy = grpc_get_poll_strategy_name(); diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 9870d7aa73..4da5cd7a1f 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -67,7 +67,7 @@ void args_finish(args_struct* args) { grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(args->pollset, &do_nothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -79,14 +79,14 @@ static grpc_millis n_sec_deadline(int seconds) { static void actually_poll(void* argsp) { args_struct* args = static_cast(argsp); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - ExecCtx::Get()->Now(); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = NULL; @@ -94,7 +94,7 @@ static void actually_poll(void* argsp) { GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, n_sec_deadline(1))); gpr_mu_unlock(args->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); } @@ -120,7 +120,7 @@ static void must_fail(void* argsp, grpc_error* err) { } static void test_unix_socket(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); poll_pollset_until_request_done(&args); @@ -132,7 +132,7 @@ static void test_unix_socket(void) { } static void test_unix_socket_path_name_too_long(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); const char prefix[] = "unix:/path/name"; @@ -156,7 +156,7 @@ static void test_unix_socket_path_name_too_long(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; test_unix_socket(); test_unix_socket_path_name_too_long(); grpc_executor_shutdown(); diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index dbc825884d..035d99cf5e 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -63,7 +63,7 @@ void args_finish(args_struct* args) { grpc_pollset_shutdown(args->pollset, &do_nothing_cb); gpr_mu_unlock(args->mu); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -74,14 +74,14 @@ static grpc_millis n_sec_deadline(int seconds) { } static void poll_pollset_until_request_done(args_struct* args) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - ExecCtx::Get()->Now(); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = NULL; @@ -89,7 +89,7 @@ static void poll_pollset_until_request_done(args_struct* args) { GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, n_sec_deadline(1))); gpr_mu_unlock(args->mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); } @@ -115,66 +115,66 @@ static void must_fail(void* argsp, grpc_error* err) { } static void test_localhost(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( "localhost:1", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } static void test_default_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( "localhost", "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } static void test_non_numeric_default_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( "localhost", "https", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } static void test_missing_default_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( "localhost", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } static void test_ipv6_with_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( "[2001:db8::1]:1", NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } @@ -187,14 +187,14 @@ static void test_ipv6_without_port(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( kCases[i], "80", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } @@ -207,14 +207,14 @@ static void test_invalid_ip_addresses(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( kCases[i], NULL, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } @@ -226,14 +226,14 @@ static void test_unparseable_hostports(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( kCases[i], "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); args_finish(&args); } @@ -242,7 +242,7 @@ static void test_unparseable_hostports(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; test_localhost(); test_default_port(); test_non_numeric_default_port(); diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index 40beadc5d6..c4f6886836 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -84,7 +84,7 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { } static void destroy_user(grpc_resource_user* usr) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); } @@ -117,11 +117,11 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -135,7 +135,7 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); grpc_resource_user_free(usr, 1024); } @@ -152,14 +152,14 @@ static void test_simple_async_alloc(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -175,7 +175,7 @@ static void test_async_alloc_blocked_by_size(void) { gpr_event ev; gpr_event_init(&ev); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait( @@ -185,7 +185,7 @@ static void test_async_alloc_blocked_by_size(void) { GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL); ; { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -201,7 +201,7 @@ static void test_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -209,13 +209,13 @@ static void test_scavenge(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr1, 1024); } { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -223,7 +223,7 @@ static void test_scavenge(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -240,7 +240,7 @@ static void test_scavenge_blocked(void) { gpr_event ev; { gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -249,14 +249,14 @@ static void test_scavenge_blocked(void) { } { gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr1, 1024); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -264,7 +264,7 @@ static void test_scavenge_blocked(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -281,7 +281,7 @@ static void test_blocked_until_scheduled_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -291,14 +291,14 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -308,7 +308,7 @@ static void test_blocked_until_scheduled_reclaim(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -325,7 +325,7 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -335,14 +335,14 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -352,7 +352,7 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -369,7 +369,7 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -379,14 +379,14 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -396,7 +396,7 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -414,7 +414,7 @@ static void test_unused_reclaim_is_cancelled(void) { gpr_event destructive_done; gpr_event_init(&destructive_done); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -448,7 +448,7 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -456,7 +456,7 @@ static void test_benign_reclaim_is_preferred(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -472,7 +472,7 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&benign_done, @@ -484,7 +484,7 @@ static void test_benign_reclaim_is_preferred(void) { NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -508,7 +508,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -516,7 +516,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -532,7 +532,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); GPR_ASSERT(gpr_event_wait(&benign_done, @@ -544,7 +544,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -563,16 +563,16 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_quota_unref(q); grpc_resource_user_unref(usr); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } } @@ -593,7 +593,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event reclaimer_cancelled; gpr_event_init(&reclaimer_cancelled); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); @@ -604,7 +604,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { gpr_event allocated; gpr_event_init(&allocated); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); GPR_ASSERT(gpr_event_wait(&allocated, @@ -614,7 +614,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, @@ -622,7 +622,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( NULL); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, @@ -641,7 +641,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); GPR_ASSERT(gpr_event_wait(&allocated, @@ -651,7 +651,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event reclaimer_done; gpr_event_init(&reclaimer_done); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); @@ -662,7 +662,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); GPR_ASSERT(gpr_event_wait(&allocated, @@ -672,7 +672,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { } } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_free(usr, 1024); } destroy_user(usr); @@ -696,14 +696,14 @@ static void test_one_slice(void) { { const int start_allocs = num_allocs; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } destroy_user(usr); @@ -728,20 +728,20 @@ static void test_one_slice_deleted_late(void) { { const int start_allocs = num_allocs; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } } @@ -770,7 +770,7 @@ static void test_negative_rq_free_pool(void) { { const int start_allocs = num_allocs; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); assert_counter_becomes(&num_allocs, start_allocs + 1); @@ -783,13 +783,13 @@ static void test_negative_rq_free_pool(void) { GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index abefecba33..d736d08a45 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -53,7 +53,7 @@ static grpc_millis test_deadline(void) { static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT( GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); @@ -83,7 +83,7 @@ void test_succeeds(void) { int r; int connections_complete_before; grpc_closure done; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -127,7 +127,7 @@ void test_succeeds(void) { grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -139,7 +139,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -175,7 +175,7 @@ void test_fails(void) { break; } gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -188,7 +188,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset_set = grpc_pollset_set_create(); diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index 0355896b85..344478ea97 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -87,7 +87,7 @@ void test_succeeds(void) { uv_tcp_t* svr_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); int connections_complete_before; grpc_closure done; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -121,7 +121,7 @@ void test_succeeds(void) { grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -136,7 +136,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -173,7 +173,7 @@ void test_fails(void) { break; } gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -186,7 +186,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index 678e1c3638..c12e695fb6 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -162,7 +162,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, num_bytes, slice_size); @@ -212,7 +212,7 @@ static void large_read_test(size_t slice_size) { ssize_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -300,7 +300,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { int flags; int current = 0; int i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -347,7 +347,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_closure write_done_closure; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, @@ -410,7 +410,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure fd_released_cb; int fd_released_done = 0; GRPC_CLOSURE_INIT(&fd_released_cb, &on_fd_released, &fd_released_done, @@ -450,7 +450,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR, state.read_bytes, state.target_read_bytes); gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); @@ -458,7 +458,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_destroy_internal(&state.incoming); grpc_tcp_destroy_and_release_fd(ep, &fd, &fd_released_cb); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker* worker = NULL; @@ -506,7 +506,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( size_t slice_size) { int sv[2]; grpc_endpoint_test_fixture f; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; create_sockets(sv); grpc_resource_quota* resource_quota = @@ -537,7 +537,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 1c3f4490d5..7b3219320e 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -163,14 +163,14 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, } static void test_no_op(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); @@ -179,7 +179,7 @@ static void test_no_op_with_start(void) { } static void test_no_op_with_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -198,7 +198,7 @@ static void test_no_op_with_port(void) { } static void test_no_op_with_port_and_start(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -243,7 +243,8 @@ static grpc_error* tcp_connect(const test_addr* remote, return GRPC_OS_ERROR(errno, "connect"); } gpr_log(GPR_DEBUG, "wait"); - while (g_nconnects == nconnects_before && deadline > ExecCtx::Get()->Now()) { + while (g_nconnects == nconnects_before && + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = NULL; grpc_error* err; if ((err = grpc_pollset_work(g_pollset, &worker, deadline)) != @@ -281,7 +282,7 @@ static grpc_error* tcp_connect(const test_addr* remote, static void test_connect(size_t num_connects, const grpc_channel_args* channel_args, test_addrs* dst_addrs, bool test_dst_addrs) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = @@ -420,7 +421,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_arg chan_args[1]; chan_args[0].type = GRPC_ARG_INTEGER; chan_args[0].key = const_cast(GRPC_ARG_EXPAND_WILDCARD_ADDRS); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index 50042af37f..07b1fb1579 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -115,14 +115,14 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, } static void test_no_op(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); @@ -131,7 +131,7 @@ static void test_no_op_with_start(void) { } static void test_no_op_with_port(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -150,7 +150,7 @@ static void test_no_op_with_port(void) { } static void test_no_op_with_port_and_start(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -214,7 +214,7 @@ static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, /* Tests a tcp server with multiple ports. */ static void test_connect(unsigned n) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -284,7 +284,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 7281f55b85..537733150f 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -43,7 +43,7 @@ static void cb(void* arg, grpc_error* error) { static void add_test(void) { int i; grpc_timer timers[20]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "add_test"); @@ -52,7 +52,7 @@ static void add_test(void) { grpc_timer_check_trace.value = 1; memset(cb_called, 0, sizeof(cb_called)); - grpc_millis start = ExecCtx::Get()->Now(); + grpc_millis start = grpc_core::ExecCtx::Get()->Now(); /* 10 ms timers. will expire in the current epoch */ for (i = 0; i < 10; i++) { @@ -69,7 +69,7 @@ static void add_test(void) { } /* collect timers. Only the first batch should be ready. */ - ExecCtx::Get()->SetNow(start + 500); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 500); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); for (i = 0; i < 20; i++) { @@ -77,7 +77,7 @@ static void add_test(void) { GPR_ASSERT(cb_called[i][0] == 0); } - ExecCtx::Get()->SetNow(start + 600); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 600); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { @@ -86,7 +86,7 @@ static void add_test(void) { } /* collect the rest of the timers */ - ExecCtx::Get()->SetNow(start + 1500); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1500); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); for (i = 0; i < 30; i++) { @@ -94,7 +94,7 @@ static void add_test(void) { GPR_ASSERT(cb_called[i][0] == 0); } - ExecCtx::Get()->SetNow(start + 1600); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1600); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); @@ -107,11 +107,11 @@ static void add_test(void) { /* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "destruction_test"); - ExecCtx::Get()->SetNow(0); + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); grpc_timer_list_init(); grpc_timer_trace.value = 1; grpc_timer_check_trace.value = 1; @@ -132,7 +132,7 @@ void destruction_test(void) { grpc_timer_init( &timers[4], 1, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)4, grpc_schedule_on_exec_ctx)); - ExecCtx::Get()->SetNow(2); + grpc_core::ExecCtx::Get()->TestOnlySetNow(2); GPR_ASSERT(grpc_timer_check(NULL) == GRPC_TIMERS_FIRED); GPR_ASSERT(1 == cb_called[4][1]); diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 47e5cf0254..0afd836744 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -127,13 +127,13 @@ static test_socket_factory* test_socket_factory_create(void) { } static void test_no_op(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_udp_server* s = grpc_udp_server_create(NULL); grpc_udp_server_destroy(s, NULL); } static void test_no_op_with_start(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_udp_server* s = grpc_udp_server_create(NULL); LOG_TEST("test_no_op_with_start"); grpc_udp_server_start(s, NULL, 0, NULL); @@ -142,7 +142,7 @@ static void test_no_op_with_start(void) { static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(NULL); @@ -162,7 +162,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; @@ -194,7 +194,7 @@ static void test_no_op_with_port_and_socket_factory(void) { static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(NULL); @@ -216,7 +216,7 @@ static void test_no_op_with_port_and_start(void) { } static void test_receive(int number_of_clients) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int clifd, svrfd; @@ -260,12 +260,12 @@ static void test_receive(int number_of_clients) { (socklen_t)resolved_addr.len) == 0); GPR_ASSERT(5 == write(clifd, "hello", 5)); while (g_number_of_reads == number_of_reads_before && - deadline > ExecCtx::Get()->Now()) { + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1); @@ -291,7 +291,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 029171c931..639f4e5056 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -148,7 +148,7 @@ static grpc_httpcli_response http_response(int status, const char* body) { /* -- Tests. -- */ static void test_empty_md_array(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); GPR_ASSERT(md_array.md == NULL); @@ -157,7 +157,7 @@ static void test_empty_md_array(void) { } static void test_add_to_empty_md_array(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; @@ -172,7 +172,7 @@ static void test_add_to_empty_md_array(void) { } static void test_add_abunch_to_md_array(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; @@ -191,7 +191,7 @@ static void test_add_abunch_to_md_array(void) { } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -208,7 +208,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) { } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -220,7 +220,7 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, ""); @@ -231,7 +231,7 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -246,7 +246,7 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, @@ -260,7 +260,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -276,7 +276,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -378,7 +378,7 @@ static void run_request_metadata_test(grpc_call_credentials* creds, } static void test_google_iam_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -395,7 +395,7 @@ static void test_google_iam_creds(void) { } static void test_access_token_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); @@ -419,7 +419,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector( } static void test_channel_oauth2_composite_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { NULL, check_channel_oauth2_create_security_connector, NULL}; @@ -439,7 +439,7 @@ static void test_channel_oauth2_composite_creds(void) { } static void test_oauth2_google_iam_composite_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -492,7 +492,7 @@ check_channel_oauth2_google_iam_create_security_connector( } static void test_channel_oauth2_google_iam_composite_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { NULL, check_channel_oauth2_google_iam_create_security_connector, NULL}; @@ -569,7 +569,7 @@ static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, } static void test_compute_engine_creds_success(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_call_credentials* creds = @@ -583,7 +583,7 @@ static void test_compute_engine_creds_success(void) { grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -591,14 +591,14 @@ static void test_compute_engine_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); } static void test_compute_engine_creds_failure(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -658,7 +658,7 @@ static int refresh_token_httpcli_post_failure( } static void test_refresh_token_creds_success(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, NULL, @@ -672,7 +672,7 @@ static void test_refresh_token_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -680,14 +680,14 @@ static void test_refresh_token_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); grpc_httpcli_set_override(NULL, NULL); } static void test_refresh_token_creds_failure(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -790,7 +790,7 @@ static void test_jwt_creds_lifetime(void) { static void test_jwt_creds_success(void) { char* json_key_string = test_json_key_str(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, NULL, NULL}; char* expected_md_value; @@ -805,7 +805,7 @@ static void test_jwt_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = @@ -813,7 +813,7 @@ static void test_jwt_creds_success(void) { grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ @@ -822,7 +822,7 @@ static void test_jwt_creds_success(void) { auth_md_ctx.service_url = other_test_service_url; grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); run_request_metadata_test(creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_call_credentials_unref(creds); gpr_free(json_key_string); @@ -832,7 +832,7 @@ static void test_jwt_creds_success(void) { static void test_jwt_creds_signing_failure(void) { char* json_key_string = test_json_key_str(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, NULL, NULL}; request_metadata_state* state = make_request_metadata_state( @@ -863,7 +863,7 @@ static void set_google_default_creds_env_var_with_file_contents( } static void test_google_default_creds_auth_key(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_service_account_jwt_access_credentials* jwt; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); @@ -884,7 +884,7 @@ static void test_google_default_creds_auth_key(void) { } static void test_google_default_creds_refresh_token(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_google_refresh_token_credentials* refresh; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); @@ -919,7 +919,7 @@ static int default_creds_gce_detection_httpcli_get_success_override( static char* null_well_known_creds_path_getter(void) { return NULL; } static void test_google_default_creds_gce(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; request_metadata_state* state = @@ -945,7 +945,7 @@ static void test_google_default_creds_gce(void) { grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); run_request_metadata_test(creds->call_creds, auth_md_ctx, state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); /* Check that we get a cached creds if we call grpc_google_default_credentials_create again. @@ -1054,7 +1054,7 @@ static void plugin_destroy(void* state) { static void test_metadata_plugin_success(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, NULL, NULL}; request_metadata_state* md_state = make_request_metadata_state( @@ -1077,7 +1077,7 @@ static void test_metadata_plugin_success(void) { static void test_metadata_plugin_failure(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, NULL, NULL}; char* expected_error; @@ -1119,7 +1119,7 @@ static void test_get_well_known_google_credentials_file_path(void) { } static void test_channel_creds_duplicate_without_call_creds(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_credentials* channel_creds = grpc_fake_transport_security_credentials_create(); diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 9eac2b9254..a139f3776f 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -206,7 +206,7 @@ static void test_parse_json_key_failure_no_private_key(void) { static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, char** scratchpad) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; char* b64; char* decoded; grpc_json* json; @@ -326,7 +326,7 @@ static void check_jwt_claim(grpc_json* claim, const char* expected_audience, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, const char* signed_data, size_t signed_data_size) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); EVP_PKEY* key = EVP_PKEY_new(); diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index 7485aa10b4..55e28e6eb2 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -209,7 +209,7 @@ static void test_claims_success(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != NULL); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); @@ -231,7 +231,7 @@ static void test_expired_claims_failure(void) { gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != NULL); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); @@ -252,7 +252,7 @@ static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == NULL); } @@ -262,7 +262,7 @@ static void test_bad_audience_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != NULL); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == @@ -276,7 +276,7 @@ static void test_bad_subject_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != NULL); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == @@ -350,7 +350,7 @@ static void on_verification_success(void* user_data, } static void test_jwt_verifier_google_email_issuer_success(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -383,7 +383,7 @@ static int httpcli_get_custom_keys_for_email( } static void test_jwt_verifier_custom_email_issuer_success(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -430,7 +430,7 @@ static int httpcli_get_openid_config(const grpc_httpcli_request* request, } static void test_jwt_verifier_url_issuer_success(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -469,7 +469,7 @@ static int httpcli_get_bad_json(const grpc_httpcli_request* request, } static void test_jwt_verifier_url_issuer_bad_config(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -492,7 +492,7 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { } static void test_jwt_verifier_bad_json_key(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -521,7 +521,7 @@ static void corrupt_jwt_sig(char* jwt) { char* last_dot = strrchr(jwt, '.'); GPR_ASSERT(last_dot != NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; sig = grpc_base64_decode(last_dot + 1, 1); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); @@ -543,7 +543,7 @@ static void on_verification_bad_signature(void* user_data, } static void test_jwt_verifier_bad_signature(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); char* jwt = NULL; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -583,7 +583,7 @@ static void on_verification_bad_format(void* user_data, } static void test_jwt_verifier_bad_format(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(NULL, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index f4a52aaba0..e24ccbc107 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -69,7 +69,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials* creds) { oauth2_request request; memset(&request, 0, sizeof(request)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", NULL, NULL}; @@ -92,7 +92,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( on_oauth2_response(&request, error); GRPC_ERROR_UNREF(error); } - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(request.mu); while (!request.is_done) { diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 6153e8a9cb..29201afe40 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -62,7 +62,7 @@ static void on_metadata_response(void* arg, grpc_error* error) { int main(int argc, char** argv) { int result = 0; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; synchronizer sync; grpc_channel_credentials* creds = NULL; const char* service_url = "https://test.foo.google.com/Foo"; @@ -111,7 +111,7 @@ int main(int argc, char** argv) { GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index a49bf1a0b4..7cee0dd3fe 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -38,7 +38,7 @@ static grpc_pollset* g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, grpc_slice* leftover_slices, size_t leftover_nslices, bool use_zero_copy_protector) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; tsi_frame_protector* fake_read_protector = tsi_create_fake_frame_protector(NULL); tsi_frame_protector* fake_write_protector = @@ -170,7 +170,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_slice_buffer incoming; grpc_slice s = grpc_slice_from_copied_string("hello world 12345678900987654321"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; int n = 0; grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); @@ -202,7 +202,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_test_init(argc, argv); grpc_init(); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index 84a42546c6..b9198279e3 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -55,7 +55,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resource_quota* resource_quota = grpc_resource_quota_create("ssl_server_fuzzer"); @@ -83,7 +83,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_security_status status = grpc_server_credentials_create_security_connector(creds, &sc); GPR_ASSERT(status == GRPC_SECURITY_OK); - grpc_millis deadline = GPR_MS_PER_SEC + ExecCtx::Get()->Now(); + grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(); struct handshake_state state; state.done_callback_called = false; @@ -92,7 +92,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_handshake_manager_do_handshake( handshake_mgr, mock_endpoint, NULL /* channel_args */, deadline, NULL /* acceptor */, on_handshake_done, &state); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); // If the given string happens to be part of the correct client hello, the // server will wait for more data. Explicitly fail the server by shutting down @@ -100,7 +100,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (!state.done_callback_called) { grpc_endpoint_shutdown( mock_endpoint, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GPR_ASSERT(state.done_callback_called); @@ -111,7 +111,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(cert_slice); grpc_slice_unref(key_slice); grpc_slice_unref(ca_slice); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_shutdown(); if (leak_check) { diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index f3e8966625..c4c3541d19 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -76,7 +76,7 @@ int main(int argc, char** argv) { gpr_cmdline* cl; const char* jwt = NULL; const char* aud = NULL; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_init(); cl = gpr_cmdline_create("JWT verifier tool"); @@ -106,7 +106,7 @@ int main(int argc, char** argv) { grpc_pollset_work(sync.pollset, &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 5ed9910740..08a5770b2a 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -44,7 +44,7 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char* hello = "hello"; char* hello_b64 = grpc_base64_encode(hello, strlen(hello), url_safe, multiline); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello)); GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello, @@ -64,7 +64,7 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { /* Try all the different paddings. */ for (i = 0; i < 3; i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline); orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i)); @@ -115,7 +115,7 @@ static void test_url_safe_unsafe_mismatch_failure(void) { int url_safe = 1; for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); orig_decoded = grpc_base64_decode(b64, !url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); @@ -164,7 +164,7 @@ static void test_rfc4648_test_vectors(void) { static void test_unpadded_decode(void) { grpc_slice decoded; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; decoded = grpc_base64_decode("Zm9vYmFy", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0); diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index 89fc33a7bf..ea00688af0 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -119,7 +119,7 @@ static void test_slice_hash_table() { check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); // Clean up. - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_hash_table_unref(table); } @@ -146,7 +146,7 @@ static void test_slice_hash_table_eq() { create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_hash_table_unref(table_a); grpc_slice_hash_table_unref(table_b); } @@ -217,7 +217,7 @@ static void test_slice_hash_table_not_eq() { create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_slice_hash_table_unref(table_a); grpc_slice_hash_table_unref(table_b_larger); grpc_slice_hash_table_unref(table_b_smaller); diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index 1f3a83efe6..f9ce98da21 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -132,7 +132,7 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, memset(GRPC_SLICE_START_PTR(input_slice), 'a', input_size); grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); } diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index ece06e4968..3e7dd311db 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -35,7 +35,7 @@ void test_unknown_scheme_target(void) { chan = grpc_insecure_channel_create("blah://blah", NULL, NULL); GPR_ASSERT(chan != NULL); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index 39aedeba02..e38b087a4b 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -136,7 +136,7 @@ static void test_cq_end_op(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); @@ -170,7 +170,7 @@ static void test_cq_tls_cache_full(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - ExecCtx _local_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx _local_exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); @@ -208,7 +208,7 @@ static void test_cq_tls_cache_empty(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - ExecCtx _local_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx _local_exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); @@ -289,7 +289,7 @@ static void test_pluck(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_PLUCK; for (size_t pidx = 0; pidx < GPR_ARRAY_SIZE(polling_types); pidx++) { - ExecCtx _local_exec_ctx; // reset exec_ctx + grpc_core::ExecCtx _local_exec_ctx; // reset exec_ctx attr.cq_polling_type = polling_types[pidx]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 6625e7e09f..0c818e0281 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -80,7 +80,7 @@ static void test_too_many_plucks(void) { gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; gpr_thd_options thread_options = gpr_thd_options_default(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); @@ -142,7 +142,7 @@ static void free_completion(void* arg, grpc_cq_completion* completion) { static void producer_thread(void* arg) { test_thread_options* opt = static_cast(arg); int i; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_INFO, "producer %d started", opt->id); gpr_event_set(&opt->on_started, (void*)(intptr_t)1); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index b3999b481f..18d7f2f985 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -115,7 +115,7 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, void bad_server_thread(void* vargs) { struct server_thread_args* args = (struct server_thread_args*)vargs; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int port; @@ -134,7 +134,7 @@ void bad_server_thread(void* vargs) { gpr_mu_lock(args->mu); while (gpr_atm_acq_load(&args->stop) == 0) { - grpc_millis deadline = ExecCtx::Get()->Now() + 100; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 100; grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( @@ -222,7 +222,7 @@ int run_concurrent_connectivity_test() { gpr_atm_rel_store(&args.stop, 1); gpr_thd_join(server); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_pollset_shutdown(args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, grpc_schedule_on_exec_ctx)); diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index dd14a03577..54d55bf440 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -44,7 +44,7 @@ void test_transport_op(grpc_channel* channel) { grpc_transport_op* op; grpc_channel_element* elem; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, grpc_schedule_on_exec_ctx); diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index bf51dac6dd..59fecf2d50 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -178,7 +178,7 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index dd9f907652..14afa6f18e 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -37,7 +37,7 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); grpc_channel_credentials_unref(creds); } @@ -54,7 +54,7 @@ void test_security_connector_already_in_arg(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } @@ -63,7 +63,7 @@ void test_null_creds(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index aae418cedb..5ad9ce65d1 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -156,7 +156,7 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, NULL); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index 4d41ece875..168807adde 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -58,7 +58,7 @@ namespace { void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { estimator->AddIncomingBytes(1234567); inc_time(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; estimator->SchedulePing(); estimator->StartPing(); for (size_t i = 0; i < n; i++) { @@ -66,7 +66,7 @@ void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { } gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1, GPR_TIMESPAN))); - ExecCtx::Get()->InvalidateNow(); + grpc_core::ExecCtx::Get()->InvalidateNow(); estimator->CompletePing(); } diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 12a933f332..08dd91e4ec 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -36,7 +36,7 @@ static void not_called_closure(void* arg, grpc_error* error) { static void test_slice_buffer_stream_basic(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_basic"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -70,7 +70,7 @@ static void test_slice_buffer_stream_basic(void) { static void test_slice_buffer_stream_shutdown(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_shutdown"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -116,7 +116,7 @@ static void test_slice_buffer_stream_shutdown(void) { static void test_caching_byte_stream_basic(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_basic"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -155,7 +155,7 @@ static void test_caching_byte_stream_basic(void) { static void test_caching_byte_stream_reset(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_reset"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -201,7 +201,7 @@ static void test_caching_byte_stream_reset(void) { static void test_caching_byte_stream_shared_cache(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_shared_cache"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 3d463c40a5..897d3008b9 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -76,7 +76,7 @@ static grpc_slice base64_decode_with_length(const char* s, s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); int main(int argc, char** argv) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which takes encoded base64 strings without pad chars, but output length is diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index fe4538339e..91e2ca376e 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -257,7 +257,7 @@ static void test_interned_key_indexed() { static void run_test(void (*test)(), const char* name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hpack_compressor_init(&g_compressor); test(); grpc_chttp2_hpack_compressor_destroy(&g_compressor); diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index feb27fc0ff..0dfd5ecc2d 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -37,7 +37,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hpack_parser_init(&parser); parser.on_header = onhdr; GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 69a13108f9..1bd3644fab 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -62,7 +62,7 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); } @@ -79,7 +79,7 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index fd5604d857..97e1a02621 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -44,7 +44,7 @@ static void assert_index(const grpc_chttp2_hptbl* tbl, uint32_t idx, } static void test_static_lookup(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hptbl tbl; grpc_chttp2_hptbl_init(&tbl); @@ -123,7 +123,7 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 100000; i++) { @@ -152,7 +152,7 @@ static void test_many_additions(void) { static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, const char* key, const char* value) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem md = grpc_mdelem_from_slices( grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); @@ -162,7 +162,7 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, } static void test_find(void) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 8ddd8bb2df..0ccf7ba288 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -57,7 +57,7 @@ static void test_connectivity_state_name(void) { static void test_check(void) { grpc_connectivity_state_tracker tracker; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_error* error; gpr_log(GPR_DEBUG, "test_check"); grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -73,17 +73,17 @@ static void test_subscribe_then_unsubscribe(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, closure)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_notify_on_state_change(&tracker, NULL, closure); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 1); @@ -95,13 +95,13 @@ static void test_subscribe_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, closure)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_destroy(&tracker); @@ -115,13 +115,13 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( &tracker, &state, closure)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 0); grpc_connectivity_state_destroy(&tracker); diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 3d7034e4ce..e5bdc5901d 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -60,7 +60,7 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; m1 = grpc_mdelem_from_slices( maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); @@ -95,7 +95,7 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, intern_keys, intern_values); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); @@ -117,7 +117,7 @@ static void test_create_many_persistant_metadata(void) { gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); @@ -151,7 +151,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys, intern_keys, intern_values); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( a = grpc_mdelem_from_slices( @@ -178,7 +178,7 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem a, b, c; a = grpc_mdelem_from_slices( maybe_intern(grpc_slice_from_static_string("a"), intern_keys), @@ -225,7 +225,7 @@ static void test_things_stick_around(void) { gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); @@ -271,7 +271,7 @@ static void test_user_data_works(void) { gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; ud1 = static_cast(gpr_malloc(sizeof(int))); *ud1 = 1; ud2 = static_cast(gpr_malloc(sizeof(int))); @@ -322,7 +322,7 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", intern_key, intern_value); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; uint8_t binary_value[BUFFER_SIZE] = {0}; for (uint8_t i = 0; i < BUFFER_SIZE; i++) { @@ -346,7 +346,7 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, dup_value); grpc_init(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 16ecd076a3..2a192e04ef 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -24,7 +24,7 @@ GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) #define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ do { \ - ExecCtx _local_exec_ctx; \ + grpc_core::ExecCtx _local_exec_ctx; \ GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ \ } while (0) diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 4e68ee3744..8e61145a26 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -62,7 +62,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_response rsp; freereq pr; char* path; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure* shutdown_closure; grpc_init(); @@ -85,19 +85,20 @@ void grpc_free_port_using_server(int port) { grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/free"); grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, - ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); grpc_resource_quota_unref_internal(resource_quota); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(grpc_polling_entity_pollset(&pr.pops), &worker, - ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.done = 1; } } @@ -167,7 +168,7 @@ static void got_port_from_server(void* arg, grpc_error* error) { grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/pick_retry"); grpc_httpcli_get(pr->ctx, &pr->pops, resource_quota, &req, - ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, pr, grpc_schedule_on_exec_ctx), &pr->response); @@ -193,7 +194,7 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure* shutdown_closure; grpc_init(); @@ -217,18 +218,19 @@ int grpc_pick_port_using_server(void) { grpc_resource_quota_create("port_server_client/pick"); grpc_httpcli_get( &context, &pr.pops, resource_quota, &req, - ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), &pr.response); grpc_resource_quota_unref_internal(resource_quota); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (pr.port == -1) { grpc_pollset_worker* worker = NULL; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(grpc_polling_entity_pollset(&pr.pops), &worker, - ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.port = 0; } } diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index 7e17ff1f53..6418a7dfaa 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -55,7 +55,7 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int port_added; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; addr->sin_family = AF_INET; addr->sin_port = htons((uint16_t)port); @@ -76,7 +76,7 @@ void test_tcp_server_start(test_tcp_server* server, int port) { void test_tcp_server_poll(test_tcp_server* server, int seconds) { grpc_pollset_worker* worker = NULL; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); @@ -91,7 +91,7 @@ static void finish_pollset(void* arg, grpc_error* error) { } void test_tcp_server_destroy(test_tcp_server* server) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; grpc_tcp_server_unref(server->tcp_server); diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 4cf39eab48..d428985034 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -112,7 +112,7 @@ class ClientLbEnd2endTest : public ::testing::Test { } void SetNextResolution(const std::vector& ports) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(ports.size(), NULL); for (size_t i = 0; i < ports.size(); ++i) { char* lb_uri_str; diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 962d5a7e68..c5c53b8b8a 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -451,7 +451,7 @@ class GrpclbEnd2endTest : public ::testing::Test { }; void SetNextResolution(const std::vector& address_data) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 6f6dd3c4df..31103d9696 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -558,7 +558,7 @@ static void perform_request(client_fixture* cf) { #define BALANCERS_NAME "lb.name" static void setup_client(const server_fixture* lb_server, const server_fixture* backends, client_fixture* cf) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; char* expected_target_names = NULL; const char* backends_name = lb_server->servers_hostport; diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 47b984bc28..bb76a2e762 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -521,7 +521,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { label << " #has_dummy_filter"; } - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; size_t channel_size = grpc_channel_stack_size( filters.size() == 0 ? NULL : &filters[0], filters.size()); grpc_channel_stack* channel_stack = @@ -534,7 +534,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { ? &dummy_transport::dummy_transport : nullptr, "CHANNEL", channel_stack))); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_call_stack* call_stack = static_cast(gpr_zalloc(channel_stack->call_stack_size)); grpc_millis deadline = GRPC_MILLIS_INF_FUTURE; @@ -558,7 +558,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { typename TestOp::Op op(&test_op_data, call_stack); grpc_call_stack_destroy(call_stack, &final_info, NULL); op.Finish(); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); // recreate arena every 64k iterations to avoid oom if (0 == (state.iterations() & 0xffff)) { gpr_arena_destroy(call_args.arena); @@ -691,7 +691,7 @@ class IsolatedCallFixture : public TrackCounters { GPR_ASSERT(grpc_channel_stack_builder_append_filter( builder, &isolated_call_filter::isolated_call_filter, NULL, NULL)); { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; channel_ = grpc_channel_create_with_builder(builder, GRPC_CLIENT_CHANNEL); } cq_ = grpc_completion_queue_create_for_next(NULL); diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index f822f095a7..d4f78e60b7 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -50,12 +50,12 @@ static grpc_slice MakeSlice(std::vector bytes) { static void BM_HpackEncoderInitDestroy(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hpack_compressor c; while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); grpc_chttp2_hpack_compressor_destroy(&c); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -64,8 +64,8 @@ BENCHMARK(BM_HpackEncoderInitDestroy); static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; - grpc_millis saved_now = ExecCtx::Get()->Now(); + grpc_core::ExecCtx _local_exec_ctx; + grpc_millis saved_now = grpc_core::ExecCtx::Get()->Now(); grpc_metadata_batch b; grpc_metadata_batch_init(&b); @@ -87,7 +87,7 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { }; grpc_chttp2_encode_header(&c, NULL, 0, &b, &hopt, &outbuf); grpc_slice_buffer_reset_and_unref_internal(&outbuf); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } grpc_metadata_batch_destroy(&b); grpc_chttp2_hpack_compressor_destroy(&c); @@ -108,7 +108,7 @@ BENCHMARK(BM_HpackEncoderEncodeDeadline); template static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; static bool logged_representative_output = false; grpc_metadata_batch b; @@ -144,7 +144,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { } } grpc_slice_buffer_reset_and_unref_internal(&outbuf); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } grpc_metadata_batch_destroy(&b); grpc_chttp2_hpack_compressor_destroy(&c); @@ -425,12 +425,12 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, static void BM_HpackParserInitDestroy(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_chttp2_hpack_parser p; while (state.KeepRunning()) { grpc_chttp2_hpack_parser_init(&p); grpc_chttp2_hpack_parser_destroy(&p); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -444,7 +444,7 @@ static void UnrefHeader(void* user_data, grpc_mdelem md) { template static void BM_HpackParserParseHeader(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; std::vector init_slices = Fixture::GetInitSlices(); std::vector benchmark_slices = Fixture::GetBenchmarkSlices(); grpc_chttp2_hpack_parser p; @@ -458,7 +458,7 @@ static void BM_HpackParserParseHeader(benchmark::State& state) { for (auto slice : benchmark_slices) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); } - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } for (auto slice : init_slices) grpc_slice_unref(slice); for (auto slice : benchmark_slices) grpc_slice_unref(slice); diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index f6e4c2bcc4..caccde0cd9 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -136,7 +136,7 @@ class Fixture { FlushExecCtx(); } - void FlushExecCtx() { ExecCtx::Get()->Flush(); } + void FlushExecCtx() { grpc_core::ExecCtx::Get()->Flush(); } ~Fixture() { grpc_transport_destroy(t_); } @@ -257,7 +257,7 @@ class Stream { static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -303,7 +303,7 @@ class RepresentativeClientInitialMetadata { template static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -354,7 +354,7 @@ BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -387,7 +387,7 @@ std::vector> done_events; static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr(new Stream(&f)); s->Init(state); @@ -517,7 +517,7 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index ce8a054515..64925fd3f9 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -34,7 +34,7 @@ auto& force_library_initialization = Library::get(); static void BM_NoOpExecCtx(benchmark::State& state) { TrackCounters track_counters; while (state.KeepRunning()) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; } track_counters.Finish(state); } @@ -42,9 +42,9 @@ BENCHMARK(BM_NoOpExecCtx); static void BM_WellFlushed(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -68,7 +68,7 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { TrackCounters track_counters; grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { benchmark::DoNotOptimize(GRPC_CLOSURE_INIT( &c, DoNothing, NULL, grpc_combiner_scheduler(combiner))); @@ -83,10 +83,10 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -95,7 +95,7 @@ BENCHMARK(BM_ClosureRunOnExecCtx); static void BM_ClosureCreateAndRun(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( GRPC_CLOSURE_CREATE(DoNothing, NULL, grpc_schedule_on_exec_ctx), @@ -108,7 +108,7 @@ BENCHMARK(BM_ClosureCreateAndRun); static void BM_ClosureInitAndRun(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure c; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( @@ -124,10 +124,10 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -140,11 +140,11 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, NULL, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_schedule_on_exec_ctx); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -159,12 +159,12 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, NULL, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c3, DoNothing, NULL, grpc_schedule_on_exec_ctx); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } track_counters.Finish(state); @@ -176,7 +176,7 @@ static void BM_AcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { gpr_mu_lock(&mu); DoNothing(NULL, GRPC_ERROR_NONE); @@ -192,7 +192,7 @@ static void BM_TryAcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { if (gpr_mu_trylock(&mu)) { DoNothing(NULL, GRPC_ERROR_NONE); @@ -210,7 +210,7 @@ static void BM_AcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { gpr_spinlock_lock(&mu); DoNothing(NULL, GRPC_ERROR_NONE); @@ -225,7 +225,7 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { if (gpr_spinlock_trylock(&mu)) { DoNothing(NULL, GRPC_ERROR_NONE); @@ -244,10 +244,10 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_combiner_scheduler(combiner)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); @@ -262,11 +262,11 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, NULL, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); @@ -283,12 +283,12 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, NULL, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c3, DoNothing, NULL, grpc_combiner_scheduler(combiner)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner, "finished"); @@ -304,11 +304,11 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, NULL, grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner2)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner1, "finished"); GRPC_COMBINER_UNREF(combiner2, "finished"); @@ -329,13 +329,13 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner2)); GRPC_CLOSURE_INIT(&c3, DoNothing, NULL, grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c4, DoNothing, NULL, grpc_combiner_scheduler(combiner2)); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c4, GRPC_ERROR_NONE); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } GRPC_COMBINER_UNREF(combiner1, "finished"); GRPC_COMBINER_UNREF(combiner2, "finished"); @@ -375,7 +375,7 @@ class Rescheduler { static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; Rescheduler r(state, grpc_schedule_on_exec_ctx); r.ScheduleFirst(); @@ -385,11 +385,11 @@ BENCHMARK(BM_ClosureReschedOnExecCtx); static void BM_ClosureReschedOnCombiner(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_scheduler(combiner)); r.ScheduleFirst(); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GRPC_COMBINER_UNREF(combiner, "finished"); track_counters.Finish(state); @@ -398,11 +398,11 @@ BENCHMARK(BM_ClosureReschedOnCombiner); static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_finally_scheduler(combiner)); r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner)); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); GRPC_COMBINER_UNREF(combiner, "finished"); track_counters.Finish(state); diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index 9fb603213a..85248ef91a 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -80,7 +80,7 @@ static void BM_Pass1Cpp(benchmark::State& state) { while (state.KeepRunning()) { grpc_cq_completion completion; DummyTag dummy_tag; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag)); grpc_cq_end_op(c_cq, &dummy_tag, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); @@ -100,7 +100,7 @@ static void BM_Pass1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, NULL)); grpc_cq_end_op(cq, NULL, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); @@ -119,7 +119,7 @@ static void BM_Pluck1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, NULL)); grpc_cq_end_op(cq, NULL, GRPC_ERROR_NONE, DoneWithCompletionOnStack, NULL, &completion); diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 0cd9a2c361..aeeba0963f 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -76,7 +76,7 @@ static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, NULL, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; } diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index 8dc98ab923..d6dba1d82f 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -246,7 +246,7 @@ template static void BM_ErrorGetStatus(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { grpc_status_code status; grpc_slice slice; @@ -261,7 +261,7 @@ template static void BM_ErrorGetStatusCode(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { grpc_status_code status; grpc_error_get_status(fixture.error(), fixture.deadline(), &status, NULL, @@ -275,7 +275,7 @@ template static void BM_ErrorHttpError(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { grpc_http2_error_code error; grpc_error_get_status(fixture.error(), fixture.deadline(), NULL, NULL, diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 191c93c58d..7b04909ee1 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -177,7 +177,7 @@ class TrickledCHTTP2 : public EndpointPairFixture { } void Step(bool update_stats) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; inc_time(); size_t client_backlog = grpc_trickle_endpoint_trickle(endpoint_pair_.client); diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc index 07fcf6af99..3a00db7a13 100644 --- a/test/cpp/microbenchmarks/bm_metadata.cc +++ b/test/cpp/microbenchmarks/bm_metadata.cc @@ -90,7 +90,7 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } @@ -103,7 +103,7 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } @@ -119,7 +119,7 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex( TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem seed = grpc_mdelem_create(k, v, NULL); while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); @@ -136,7 +136,7 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } @@ -152,7 +152,7 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -168,7 +168,7 @@ static void BM_MetadataFromInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); char backing_store[sizeof(grpc_mdelem_data)]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -186,7 +186,7 @@ static void BM_MetadataFromInternedKeyWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -201,7 +201,7 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_200; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } @@ -216,7 +216,7 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed( TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_GZIP; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, NULL)); } @@ -229,7 +229,7 @@ BENCHMARK(BM_MetadataFromStaticMetadataStringsNotIndexed); static void BM_MetadataRefUnrefExternal(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem el = grpc_mdelem_create( grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), reinterpret_cast(backing_store)); @@ -245,7 +245,7 @@ BENCHMARK(BM_MetadataRefUnrefExternal); static void BM_MetadataRefUnrefInterned(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); grpc_mdelem el = grpc_mdelem_create( @@ -263,7 +263,7 @@ BENCHMARK(BM_MetadataRefUnrefInterned); static void BM_MetadataRefUnrefAllocated(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem el = grpc_mdelem_create(grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), NULL); while (state.KeepRunning()) { @@ -277,7 +277,7 @@ BENCHMARK(BM_MetadataRefUnrefAllocated); static void BM_MetadataRefUnrefStatic(benchmark::State& state) { TrackCounters track_counters; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_mdelem el = grpc_mdelem_create(GRPC_MDSTR_STATUS, GRPC_MDSTR_200, NULL); while (state.KeepRunning()) { GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index 7ddca45eca..59ee937fe4 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -50,7 +50,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { size_t ps_sz = grpc_pollset_size(); grpc_pollset* ps = static_cast(gpr_malloc(ps_sz)); gpr_mu* mu; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); @@ -60,7 +60,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { gpr_mu_lock(mu); grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } gpr_free(ps); @@ -114,7 +114,7 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_mu_lock(mu); while (state.KeepRunning()) { GRPC_ERROR_UNREF(grpc_pollset_work(ps, NULL, 0)); @@ -136,14 +136,14 @@ static void BM_PollAddFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_wakeup_fd wakeup_fd; GPR_ASSERT( GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&wakeup_fd))); grpc_fd* fd = grpc_fd_create(wakeup_fd.read_fd, "xxx"); while (state.KeepRunning()) { grpc_pollset_add_fd(ps, fd); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); } grpc_fd_orphan(fd, NULL, NULL, false /* already_closed */, "xxx"); grpc_closure shutdown_ps_closure; @@ -218,7 +218,7 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_wakeup_fd wakeup_fd; GRPC_ERROR_UNREF(grpc_wakeup_fd_init(&wakeup_fd)); grpc_fd* wakeup = grpc_fd_create(wakeup_fd.read_fd, "wakeup_read"); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 075064eca7..4efcafa8e1 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -166,7 +166,7 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* add server endpoint to server_ * */ diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 8ba8be0ea4..ca8c26092a 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -171,7 +171,7 @@ void ArgsFinish(ArgsStruct* args) { grpc_pollset_shutdown(args->pollset, &DoNothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() grpc_channel_args_destroy(args->channel_args); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); GRPC_COMBINER_UNREF(args->lock, NULL); @@ -195,7 +195,7 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { time_left.tv_sec, time_left.tv_nsec); GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0); grpc_pollset_worker* worker = NULL; - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; gpr_mu_lock(args->mu); GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, @@ -274,7 +274,7 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) { } TEST(ResolverComponentTest, TestResolvesRelevantRecords) { - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; ArgsStruct args; ArgsInit(&args); args.expected_addrs = ParseExpectedAddrs(FLAGS_expected_addrs); @@ -294,7 +294,7 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecords) { (void*)&args, grpc_combiner_scheduler(args.lock)); grpc_resolver_next_locked(resolver, &args.channel_args, &on_resolver_result_changed); - ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); PollPollsetUntilRequestDone(&args); GRPC_RESOLVER_UNREF(resolver, NULL); ArgsFinish(&args); diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index b9514e6306..ae658ff87c 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -82,7 +82,7 @@ class EndpointPairFixture { ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; /* add server endpoint to server_ */ { -- cgit v1.2.3 From c354269ba7bd1f6dfe9c86ba18f38fc8e346dcfc Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 29 Nov 2017 19:07:44 -0800 Subject: Remove _ prefixed variable names --- .../filters/client_channel/channel_connectivity.cc | 4 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 2 +- .../chttp2/client/insecure/channel_create.cc | 2 +- .../chttp2/client/insecure/channel_create_posix.cc | 2 +- .../chttp2/client/secure/secure_channel_create.cc | 2 +- .../chttp2/server/insecure/server_chttp2.cc | 2 +- .../chttp2/server/insecure/server_chttp2_posix.cc | 2 +- .../chttp2/server/secure/server_secure_chttp2.cc | 2 +- .../cronet/client/secure/cronet_channel_create.cc | 2 +- .../transport/cronet/transport/cronet_transport.cc | 16 +-- src/core/ext/transport/inproc/inproc_transport.cc | 6 +- .../lib/compression/stream_compression_gzip.cc | 2 +- src/core/lib/iomgr/endpoint_pair_posix.cc | 2 +- src/core/lib/iomgr/endpoint_pair_windows.cc | 2 +- src/core/lib/iomgr/executor.cc | 2 +- src/core/lib/iomgr/iocp_windows.cc | 4 +- src/core/lib/iomgr/iomgr.cc | 2 +- src/core/lib/iomgr/iomgr_uv.cc | 2 +- src/core/lib/iomgr/resolve_address_uv.cc | 2 +- src/core/lib/iomgr/resource_quota.cc | 4 +- src/core/lib/iomgr/tcp_client_uv.cc | 2 +- src/core/lib/iomgr/tcp_server_uv.cc | 6 +- src/core/lib/iomgr/tcp_uv.cc | 10 +- src/core/lib/iomgr/timer_manager.cc | 4 +- src/core/lib/iomgr/timer_uv.cc | 2 +- src/core/lib/security/context/security_context.cc | 4 +- src/core/lib/security/credentials/credentials.cc | 6 +- .../google_default/google_default_credentials.cc | 4 +- .../security/credentials/iam/iam_credentials.cc | 2 +- .../security/credentials/jwt/jwt_credentials.cc | 2 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 2 +- .../credentials/oauth2/oauth2_credentials.cc | 2 +- .../credentials/plugin/plugin_credentials.cc | 4 +- .../lib/security/transport/security_handshaker.cc | 2 +- .../lib/security/transport/server_auth_filter.cc | 2 +- src/core/lib/slice/slice.cc | 2 +- src/core/lib/slice/slice_buffer.cc | 4 +- src/core/lib/surface/alarm.cc | 6 +- src/core/lib/surface/byte_buffer.cc | 2 +- src/core/lib/surface/byte_buffer_reader.cc | 4 +- src/core/lib/surface/call.cc | 8 +- src/core/lib/surface/call_details.cc | 2 +- src/core/lib/surface/channel.cc | 10 +- src/core/lib/surface/channel_ping.cc | 2 +- src/core/lib/surface/completion_queue.cc | 14 +-- src/core/lib/surface/init.cc | 2 +- src/core/lib/surface/lame_client.cc | 2 +- src/core/lib/surface/server.cc | 12 +-- src/cpp/common/channel_arguments.cc | 4 +- .../CoreCronetEnd2EndTests.mm | 2 +- test/core/backoff/backoff_test.cc | 8 +- test/core/bad_client/bad_client.cc | 4 +- test/core/channel/channel_args_test.cc | 8 +- test/core/channel/channel_stack_test.cc | 2 +- test/core/channel/minimal_stack_is_minimal_test.cc | 4 +- test/core/client_channel/lb_policies_test.cc | 4 +- test/core/client_channel/parse_address_test.cc | 6 +- .../resolvers/dns_resolver_connectivity_test.cc | 4 +- .../client_channel/resolvers/dns_resolver_test.cc | 6 +- .../client_channel/resolvers/fake_resolver_test.cc | 2 +- .../resolvers/sockaddr_resolver_test.cc | 6 +- test/core/client_channel/uri_fuzzer_test.cc | 2 +- test/core/client_channel/uri_parser_test.cc | 10 +- test/core/compression/algorithm_test.cc | 4 +- test/core/compression/message_compress_test.cc | 16 +-- test/core/debug/stats_test.cc | 6 +- test/core/end2end/bad_server_response_test.cc | 2 +- test/core/end2end/connection_refused_test.cc | 2 +- test/core/end2end/fixtures/h2_census.cc | 4 +- test/core/end2end/fixtures/h2_compress.cc | 6 +- test/core/end2end/fixtures/h2_fd.cc | 4 +- test/core/end2end/fixtures/h2_full+workarounds.cc | 2 +- test/core/end2end/fixtures/h2_load_reporting.cc | 2 +- test/core/end2end/fixtures/h2_oauth2.cc | 2 +- test/core/end2end/fixtures/h2_sockpair+trace.cc | 6 +- test/core/end2end/fixtures/h2_sockpair.cc | 6 +- test/core/end2end/fixtures/h2_sockpair_1byte.cc | 6 +- test/core/end2end/fixtures/h2_ssl.cc | 2 +- test/core/end2end/fixtures/h2_ssl_proxy.cc | 4 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 6 +- test/core/end2end/fuzzers/api_fuzzer.cc | 8 +- test/core/end2end/fuzzers/client_fuzzer.cc | 2 +- test/core/end2end/fuzzers/server_fuzzer.cc | 2 +- test/core/end2end/h2_ssl_cert_test.cc | 2 +- test/core/end2end/tests/cancel_after_accept.cc | 2 +- test/core/end2end/tests/cancel_after_round_trip.cc | 2 +- test/core/end2end/tests/compressed_payload.cc | 6 +- test/core/end2end/tests/load_reporting_hook.cc | 2 +- test/core/end2end/tests/max_message_length.cc | 4 +- .../tests/stream_compression_compressed_payload.cc | 6 +- .../end2end/tests/stream_compression_payload.cc | 2 +- .../stream_compression_ping_pong_streaming.cc | 2 +- .../end2end/tests/workaround_cronet_compression.cc | 4 +- test/core/http/httpcli_test.cc | 6 +- test/core/http/httpscli_test.cc | 6 +- test/core/iomgr/combiner_test.cc | 10 +- test/core/iomgr/endpoint_pair_test.cc | 4 +- test/core/iomgr/endpoint_tests.cc | 4 +- test/core/iomgr/ev_epollsig_linux_test.cc | 10 +- test/core/iomgr/fd_conservation_posix_test.cc | 2 +- test/core/iomgr/fd_posix_test.cc | 10 +- test/core/iomgr/pollset_set_test.cc | 8 +- test/core/iomgr/resolve_address_posix_test.cc | 8 +- test/core/iomgr/resolve_address_test.cc | 20 ++-- test/core/iomgr/resource_quota_test.cc | 112 ++++++++++----------- test/core/iomgr/tcp_client_posix_test.cc | 8 +- test/core/iomgr/tcp_client_uv_test.cc | 6 +- test/core/iomgr/tcp_posix_test.cc | 14 +-- test/core/iomgr/tcp_server_posix_test.cc | 12 +-- test/core/iomgr/tcp_server_uv_test.cc | 12 +-- test/core/iomgr/timer_list_test.cc | 4 +- test/core/iomgr/udp_server_test.cc | 14 +-- test/core/security/credentials_test.cc | 54 +++++----- test/core/security/json_token_test.cc | 4 +- test/core/security/jwt_verifier_test.cc | 26 ++--- test/core/security/oauth2_utils.cc | 2 +- .../security/print_google_default_creds_token.cc | 2 +- test/core/security/secure_endpoint_test.cc | 6 +- test/core/security/ssl_server_fuzzer.cc | 2 +- test/core/security/verify_jwt.cc | 2 +- test/core/slice/b64_test.cc | 8 +- test/core/slice/slice_hash_table_test.cc | 6 +- test/core/surface/byte_buffer_reader_test.cc | 2 +- test/core/surface/channel_create_test.cc | 2 +- test/core/surface/completion_queue_test.cc | 8 +- .../surface/completion_queue_threading_test.cc | 4 +- test/core/surface/concurrent_connectivity_test.cc | 4 +- test/core/surface/lame_client_test.cc | 2 +- .../num_external_connectivity_watchers_test.cc | 2 +- test/core/surface/secure_channel_create_test.cc | 6 +- test/core/surface/sequential_connectivity_test.cc | 2 +- test/core/transport/bdp_estimator_test.cc | 2 +- test/core/transport/byte_stream_test.cc | 10 +- test/core/transport/chttp2/bin_decoder_test.cc | 2 +- test/core/transport/chttp2/hpack_encoder_test.cc | 2 +- .../transport/chttp2/hpack_parser_fuzzer_test.cc | 2 +- test/core/transport/chttp2/hpack_parser_test.cc | 4 +- test/core/transport/chttp2/hpack_table_test.cc | 8 +- test/core/transport/connectivity_state_test.cc | 8 +- test/core/transport/metadata_test.cc | 18 ++-- test/core/transport/status_conversion_test.cc | 2 +- test/core/util/port_server_client.cc | 4 +- test/core/util/test_tcp_server.cc | 6 +- test/cpp/end2end/client_lb_end2end_test.cc | 2 +- test/cpp/end2end/grpclb_end2end_test.cc | 2 +- test/cpp/grpclb/grpclb_test.cc | 2 +- test/cpp/microbenchmarks/bm_call_create.cc | 4 +- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 10 +- test/cpp/microbenchmarks/bm_chttp2_transport.cc | 10 +- test/cpp/microbenchmarks/bm_closure.cc | 42 ++++---- test/cpp/microbenchmarks/bm_cq.cc | 6 +- test/cpp/microbenchmarks/bm_error.cc | 6 +- test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 2 +- test/cpp/microbenchmarks/bm_metadata.cc | 26 ++--- test/cpp/microbenchmarks/bm_pollset.cc | 8 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 2 +- test/cpp/naming/resolver_component_test.cc | 4 +- test/cpp/performance/writes_per_rpc_test.cc | 2 +- 158 files changed, 497 insertions(+), 497 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 1d5386643a..20693ba419 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -33,7 +33,7 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( /* forward through to the underlying client channel */ grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_connectivity_state state; GRPC_API_TRACE( "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, @@ -198,7 +198,7 @@ void grpc_channel_watch_connectivity_state( gpr_timespec deadline, grpc_completion_queue* cq, void* tag) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index d4b7f0b6c9..3a870b2d06 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -213,7 +213,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, static void on_srv_query_done_cb(void* arg, int status, int timeouts, unsigned char* abuf, int alen) { grpc_ares_request* r = (grpc_ares_request*)arg; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { gpr_log(GPR_DEBUG, "on_query_srv_done_cb ARES_SUCCESS"); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 9cf7bf884b..6a1b70964d 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -80,7 +80,7 @@ static grpc_client_channel_factory client_channel_factory = { grpc_channel* grpc_insecure_channel_create(const char* target, const grpc_channel_args* args, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index bdd8d93bd3..6236551e24 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -37,7 +37,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, (target, fd, args)); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index e0264cadc5..27c5b96a4c 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -190,7 +190,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, const char* target, const grpc_channel_args* args, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 826886c961..52c42d056c 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -26,7 +26,7 @@ #include "src/core/lib/surface/server.h" int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; int port_num = 0; GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2, (server, addr)); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index 56789ab53d..210939e6af 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -38,7 +38,7 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, void* reserved, int fd) { GPR_ASSERT(reserved == nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; char* name; gpr_asprintf(&name, "fd:%d", fd); diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index 7b426c18fb..723af97ff0 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -36,7 +36,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_server_credentials* creds) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_error* err = GRPC_ERROR_NONE; grpc_server_security_connector* sc = nullptr; int port_num = 0; diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc index 8e1dcc542e..40a30e4a31 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc @@ -49,6 +49,6 @@ GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( grpc_transport* ct = grpc_create_cronet_transport(engine, target, args, reserved); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; return grpc_channel_create(target, args, GRPC_CLIENT_DIRECT_CHANNEL, ct); } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index f9f47a4a12..c9fd94176b 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -398,7 +398,7 @@ static void execute_from_storage(stream_obj* s) { */ static void on_failed(bidirectional_stream* stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -424,7 +424,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) { */ static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -450,7 +450,7 @@ static void on_canceled(bidirectional_stream* stream) { */ static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -468,7 +468,7 @@ static void on_succeeded(bidirectional_stream* stream) { */ static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); @@ -498,7 +498,7 @@ static void on_response_headers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* headers, const char* negotiated_protocol) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); stream_obj* s = (stream_obj*)stream->annotation; @@ -550,7 +550,7 @@ static void on_response_headers_received( Cronet callback */ static void on_write_completed(bidirectional_stream* stream, const char* data) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); @@ -568,7 +568,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { */ static void on_read_completed(bidirectional_stream* stream, char* data, int count) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); @@ -610,7 +610,7 @@ static void on_read_completed(bidirectional_stream* stream, char* data, static void on_response_trailers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* trailers) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); stream_obj* s = (stream_obj*)stream->annotation; diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 18e77b9b1c..d816a5d1a7 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -1096,7 +1096,7 @@ static grpc_endpoint* get_endpoint(grpc_transport* t) { return nullptr; } static void do_nothing(void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, nullptr, grpc_schedule_on_exec_ctx); g_empty_slice = grpc_slice_from_static_buffer(nullptr, 0); @@ -1160,7 +1160,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, GRPC_API_TRACE("grpc_inproc_channel_create(server=%p, args=%p)", 2, (server, args)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; const grpc_channel_args* server_args = grpc_server_get_channel_args(server); @@ -1191,7 +1191,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, } void grpc_inproc_transport_shutdown(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_unref_internal(g_empty_slice); grpc_slice_unref_internal(g_fake_path_key); grpc_slice_unref_internal(g_fake_path_value); diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 6c4397759f..9d829b31db 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -40,7 +40,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, /* Full flush is not allowed when inflating. */ GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; int r; bool eoc = false; size_t original_max_output_size = max_output_size; diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 65db4a9675..0b4aefd1b7 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -54,7 +54,7 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name, char* final_name; create_sockets(sv); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_asprintf(&final_name, "%s:client", name); p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name), args, diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index afd91c9932..cc07ac0708 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -72,7 +72,7 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( SOCKET sv[2]; grpc_endpoint_pair p; create_sockets(sv); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; p.client = grpc_tcp_create(grpc_winsocket_create(sv[1], "endpoint:client"), channel_args, "endpoint:server"); p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server"), diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index d2fb772765..d9b0c1daf0 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -143,7 +143,7 @@ static void executor_thread(void* arg) { thread_state* ts = (thread_state*)arg; gpr_tls_set(&g_this_thread_state, (intptr_t)ts); - grpc_core::ExecCtx _local_exec_ctx(0); + grpc_core::ExecCtx exec_ctx(0); size_t subtract_depth = 0; for (;;) { diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index f5c6297438..0b6e6823b3 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -113,7 +113,7 @@ void grpc_iocp_kick(void) { } void grpc_iocp_flush(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_iocp_work_status work_status; do { @@ -123,7 +123,7 @@ void grpc_iocp_flush(void) { } void grpc_iocp_shutdown(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (gpr_atm_acq_load(&g_custom_events)) { grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); grpc_core::ExecCtx::Get()->Flush(); diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 27e9376272..dacf08ea9e 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -46,7 +46,7 @@ static int g_shutdown; static grpc_iomgr_object g_root_object; void grpc_iomgr_init() { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index 95b06e2ca5..9614c2e664 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -29,7 +29,7 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_global_init(); grpc_executor_set_threading(false); diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc index 54adf9b9f6..3eab04f3de 100644 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ b/src/core/lib/iomgr/resolve_address_uv.cc @@ -114,7 +114,7 @@ static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { request* r = (request*)req->data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_error* error; int retry_status; char* port = r->port; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 55d559c466..cabe28e4e6 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -621,7 +621,7 @@ void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { /* Public API */ void grpc_resource_quota_unref(grpc_resource_quota* resource_quota) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_quota_unref_internal(resource_quota); } @@ -646,7 +646,7 @@ double grpc_resource_quota_get_memory_pressure( /* Public API */ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t size) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a)); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota); a->size = (int64_t)size; diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 0ba074500b..0cb688cf16 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -76,7 +76,7 @@ static void uv_tc_on_alarm(void* acp, grpc_error* error) { static void uv_tc_on_connect(uv_connect_t* req, int status) { grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_error* error = GRPC_ERROR_NONE; int done; grpc_closure* closure = connect->closure; diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 2181b12b23..55f16126b6 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -137,7 +137,7 @@ static void finish_shutdown(grpc_tcp_server* s) { static void handle_close_callback(uv_handle_t* handle) { grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; sp->server->open_ports--; if (sp->server->open_ports == 0 && sp->server->shutdown) { finish_shutdown(sp->server); @@ -174,7 +174,7 @@ void grpc_tcp_server_unref(grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); if (gpr_unref(&s->refs)) { /* Complete shutdown_starting work before destroying. */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); grpc_core::ExecCtx::Get()->Flush(); tcp_server_destroy(s); @@ -223,7 +223,7 @@ static void finish_accept(grpc_tcp_listener* sp) { static void on_connect(uv_stream_t* server, int status) { grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (status < 0) { switch (status) { diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index d41ddaf428..2c26b60511 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -111,14 +111,14 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif static void uv_close_callback(uv_handle_t* handle) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; TCP_UNREF(tcp, "destroy"); } static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; (void)suggested_size; /* Before calling uv_read_start, we allocate a buffer with exactly one slice @@ -151,7 +151,7 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { static void read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { grpc_error* error; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)stream->data; grpc_slice_buffer garbage; if (nread == 0) { @@ -228,7 +228,7 @@ static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, static void write_callback(uv_write_t* req, int status) { grpc_tcp* tcp = (grpc_tcp*)req->data; grpc_error* error; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure* cb = tcp->write_cb; tcp->write_cb = NULL; TCP_UNREF(tcp, "write"); @@ -372,7 +372,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, grpc_resource_quota* resource_quota, char* peer_string) { grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 0e1fa0c049..e11e9156c3 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -98,7 +98,7 @@ static void start_timer_thread_and_unlock(void) { } void grpc_timer_manager_tick() { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_millis next = GRPC_MILLIS_INF_FUTURE; grpc_timer_check(&next); } @@ -273,7 +273,7 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - grpc_core::ExecCtx _local_exec_ctx(0); + grpc_core::ExecCtx exec_ctx(0); timer_main_loop(); timer_thread_cleanup((completed_thread*)completed_thread_ptr); diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 879890603c..5d238da089 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -42,7 +42,7 @@ static void stop_uv_timer(uv_timer_t* handle) { void run_expired_timer(uv_timer_t* handle) { grpc_timer* timer = (grpc_timer*)handle->data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(timer->pending); timer->pending = 0; diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index d4efdac583..0371027994 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -36,7 +36,7 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount( grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_client_security_context* ctx = nullptr; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); @@ -85,7 +85,7 @@ grpc_client_security_context* grpc_client_security_context_create(void) { } void grpc_client_security_context_destroy(void* ctx) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_client_security_context* c = (grpc_client_security_context*)ctx; grpc_call_credentials_unref(c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index d8a98fa3f0..48b459e1be 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -72,7 +72,7 @@ void grpc_channel_credentials_unref(grpc_channel_credentials* creds) { void grpc_channel_credentials_release(grpc_channel_credentials* creds) { GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials_unref(creds); } @@ -94,7 +94,7 @@ void grpc_call_credentials_unref(grpc_call_credentials* creds) { void grpc_call_credentials_release(grpc_call_credentials* creds) { GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_call_credentials_unref(creds); } @@ -211,7 +211,7 @@ void grpc_server_credentials_unref(grpc_server_credentials* creds) { void grpc_server_credentials_release(grpc_server_credentials* creds) { GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_server_credentials_unref(creds); } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 072dffe035..03d52850d9 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -221,7 +221,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ()); @@ -291,7 +291,7 @@ end: } void grpc_flush_cached_google_default_credentials(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); if (default_credentials != nullptr) { diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 3b01137ed9..75acb2a58e 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -54,7 +54,7 @@ static grpc_call_credentials_vtable iam_vtable = { grpc_call_credentials* grpc_google_iam_credentials_create( const char* token, const char* authority_selector, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 3eaedeea4e..2404e860e4 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -181,7 +181,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( gpr_free(clean_json); } GPR_ASSERT(reserved == nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_auth_json_key_create_from_string(json_key), token_lifetime); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index dc67a20e6f..39339f07d7 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -347,7 +347,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( grpc_jwt_claims* claims, const char* audience, grpc_slice signature, const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx)); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 0fe368d3f2..e243ea52c6 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -515,7 +515,7 @@ grpc_call_credentials* grpc_access_token_credentials_create( gpr_ref_init(&c->base.refcount, 1); char* token_md_value; gpr_asprintf(&token_md_value, "Bearer %s", access_token); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; c->access_token_md = grpc_mdelem_from_slices( grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(token_md_value)); diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index a75ae033b9..203ba58c67 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -115,8 +115,8 @@ static void plugin_md_request_metadata_ready(void* request, grpc_status_code status, const char* error_details) { /* called from application code */ - grpc_core::ExecCtx _local_exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | - GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); + grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (grpc_plugin_credentials_trace.enabled()) { diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 25a1e59ace..7623fbfd5b 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -271,7 +271,7 @@ static void on_handshake_next_done_grpc_wrapper( security_handshaker* h = (security_handshaker*)user_data; // This callback will be invoked by TSI in a non-grpc thread, so it's // safe to create our own exec_ctx here. - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(&h->mu); grpc_error* error = on_handshake_next_done_locked( h, result, bytes_to_send, bytes_to_send_size, handshaker_result); diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 3566ddf64e..73653f2a66 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -118,7 +118,7 @@ static void on_md_processing_done( grpc_status_code status, const char* error_details) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // If the call was not cancelled while we were in flight, process the result. if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_DONE)) { diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 7ac6204716..1eb15290eb 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -67,7 +67,7 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { /* Public API */ void grpc_slice_unref(grpc_slice slice) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_unref_internal(slice); } diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index dbe8d48343..33ec2af683 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -73,7 +73,7 @@ void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer_destroy_internal(sb); } @@ -172,7 +172,7 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer_reset_and_unref_internal(sb); } diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 9a13a7b323..f6ea016c33 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -45,7 +45,7 @@ static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } static void alarm_unref(grpc_alarm* alarm) { if (gpr_unref(&alarm->refs)) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (alarm->cq != nullptr) { GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); } @@ -115,7 +115,7 @@ grpc_alarm* grpc_alarm_create(void* reserved) { void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, gpr_timespec deadline, void* tag, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CQ_INTERNAL_REF(cq, "alarm"); alarm->cq = cq; @@ -127,7 +127,7 @@ void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, } void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_timer_cancel(&alarm->alarm); } diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index b706f5ba9b..e4c2a4a4c2 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -71,7 +71,7 @@ grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { if (!bb) return; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; switch (bb->type) { case GRPC_BB_RAW: grpc_slice_buffer_destroy_internal(&bb->data.raw.slice_buffer); diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index c5f8df3dda..81a48e95fc 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -42,7 +42,7 @@ static int is_compressed(grpc_byte_buffer* buffer) { int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer decompressed_slices_buffer; reader->buffer_in = buffer; switch (reader->buffer_in->type) { @@ -110,7 +110,7 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) { grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size); uint8_t* const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { const size_t slice_length = GRPC_SLICE_LENGTH(in_slice); memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length); diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index e4c8f01505..a457aaa7a2 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -560,7 +560,7 @@ void grpc_call_unref(grpc_call* c) { if (!gpr_unref(&c->ext_ref)) return; child_call* cc = c->child; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_TIMER_BEGIN("grpc_call_unref", 0); GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c)); @@ -601,7 +601,7 @@ void grpc_call_unref(grpc_call* c) { grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); return GRPC_CALL_OK; @@ -651,7 +651,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, grpc_status_code status, const char* description, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", @@ -2038,7 +2038,7 @@ done_with_error: grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* tag, void* reserved) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_call_error err; GRPC_API_TRACE( diff --git a/src/core/lib/surface/call_details.cc b/src/core/lib/surface/call_details.cc index 7d81ba9e22..cd0b14586a 100644 --- a/src/core/lib/surface/call_details.cc +++ b/src/core/lib/surface/call_details.cc @@ -34,7 +34,7 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_unref_internal(cd->method); grpc_slice_unref_internal(cd->host); } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index b44096fc32..cf5e8c2150 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -248,7 +248,7 @@ char* grpc_channel_get_target(grpc_channel* channel) { void grpc_channel_get_info(grpc_channel* channel, const grpc_channel_info* channel_info) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); elem->filter->get_channel_info(elem, channel_info); @@ -296,7 +296,7 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel, grpc_slice method, const grpc_slice* host, gpr_timespec deadline, void* reserved) { GPR_ASSERT(!reserved); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_call* call = grpc_channel_create_call_internal( channel, parent_call, propagation_mask, cq, nullptr, grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), @@ -329,7 +329,7 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; rc->path = grpc_mdelem_from_slices( GRPC_MDSTR_PATH, @@ -364,7 +364,7 @@ grpc_call* grpc_channel_create_registered_call( registered_call_handle, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_call* call = grpc_channel_create_call_internal( channel, parent_call, propagation_mask, completion_queue, nullptr, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), @@ -407,7 +407,7 @@ static void destroy_channel(void* arg, grpc_error* error) { void grpc_channel_destroy(grpc_channel* channel) { grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel)); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Destroyed"); diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index c44307df8d..616ba9e0ac 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -51,7 +51,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(reserved == nullptr); pr->tag = tag; pr->cq = cq; diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 958318f814..12385b7130 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -353,7 +353,7 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, if (storage != nullptr && (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; *ok = (storage->next & (uintptr_t)(1)) == 1; storage->done(storage->done_arg, storage); ret = 1; @@ -389,7 +389,7 @@ static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { grpc_cq_completion* c = nullptr; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (gpr_spinlock_trylock(&q->queue_lock)) { GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); @@ -434,7 +434,7 @@ grpc_completion_queue* grpc_completion_queue_create_internal( const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_STATS_INC_CQS_CREATED(); cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + @@ -868,7 +868,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, nullptr, nullptr, true}; - ExecCtxNext _local_exec_ctx(&is_finished_arg); + ExecCtxNext exec_ctx(&is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; @@ -1111,7 +1111,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, nullptr, tag, true}; - ExecCtxPluck _local_exec_ctx(&is_finished_arg); + ExecCtxPluck exec_ctx(&is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != nullptr) { gpr_mu_unlock(cq->mu); @@ -1240,7 +1240,7 @@ static void cq_shutdown_pluck(grpc_completion_queue* cq) { /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); cq->vtable->shutdown(cq); @@ -1253,7 +1253,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); GPR_TIMER_END("grpc_completion_queue_destroy", 0); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index e6ff475a90..f96d8eba6c 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -157,7 +157,7 @@ void grpc_shutdown(void) { gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { { - grpc_core::ExecCtx _local_exec_ctx(0); + grpc_core::ExecCtx exec_ctx(0); { grpc_executor_shutdown(); grpc_timer_manager_set_threading( diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index d79f9a9ab2..011f5eae8b 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -154,7 +154,7 @@ extern "C" const grpc_channel_filter grpc_lame_filter = { grpc_channel* grpc_lame_client_channel_create(const char* target, grpc_status_code error_code, const char* error_message) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem; grpc_channel* channel = grpc_channel_create(target, nullptr, GRPC_CLIENT_LAME_CHANNEL, nullptr); diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index e003b5410b..e9c92b04dc 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -1015,7 +1015,7 @@ static void start_listeners(void* s, grpc_error* error) { void grpc_server_start(grpc_server* server) { size_t i; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server)); @@ -1161,7 +1161,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, listener* l; shutdown_tag* sdt; channel_broadcaster broadcaster; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3, (server, cq, tag)); @@ -1220,7 +1220,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, void grpc_server_cancel_all_calls(grpc_server* server) { channel_broadcaster broadcaster; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server)); @@ -1235,7 +1235,7 @@ void grpc_server_cancel_all_calls(grpc_server* server) { void grpc_server_destroy(grpc_server* server) { listener* l; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server)); @@ -1317,7 +1317,7 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( @@ -1364,7 +1364,7 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); registered_method* rm = (registered_method*)rmp; GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 82d687c530..f198413498 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -67,7 +67,7 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } ChannelArguments::~ChannelArguments() { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == GRPC_ARG_POINTER) { it->value.pointer.vtable->destroy(it->value.pointer.p); @@ -95,7 +95,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { } grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator); bool replaced = false; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm index 7a09e8f395..d130971364 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm @@ -110,7 +110,7 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void cronet_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; stream_engine *cronetEngine = [Cronet getGlobalEngine]; grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args); diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 2cd97d8055..d3115fe1dd 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -33,7 +33,7 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now() == @@ -62,7 +62,7 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. @@ -85,7 +85,7 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx::Get()->TestOnlySetNow(0); grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == @@ -141,7 +141,7 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now() == diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 267933ff62..f63a32ea5b 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -57,7 +57,7 @@ static void done_write(void* arg, grpc_error* error) { static void server_setup_transport(void* ts, grpc_transport* transport) { thd_args* a = (thd_args*)ts; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_server_setup_transport(a->server, transport, nullptr, grpc_server_get_channel_args(a->server)); } @@ -80,7 +80,7 @@ void grpc_run_bad_client_test( grpc_slice_from_copied_buffer(client_payload, client_payload_length); grpc_slice_buffer outgoing; grpc_closure done_write_closure; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_completion_queue* shutdown_cq; if (client_payload_length < 4 * 1024) { diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index 99a6566a1c..4a8195e984 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -26,7 +26,7 @@ #include "test/core/util/test_config.h" static void test_create(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_arg arg_int; grpc_arg arg_string; @@ -59,7 +59,7 @@ static void test_create(void) { } static void test_set_compression_algorithm(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* ch_args; ch_args = @@ -73,7 +73,7 @@ static void test_set_compression_algorithm(void) { } static void test_compression_algorithm_states(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; unsigned states_bitset; size_t i; @@ -134,7 +134,7 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(ch_args); } } diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index 93ddd0fee5..ef43facd6e 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -95,7 +95,7 @@ static void test_create_channel_stack(void) { grpc_channel_args chan_args; int* channel_data; int* call_data; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index 2373bc6329..3495f603e4 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -125,7 +125,7 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_transport(builder, &fake_transport); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); GPR_ASSERT(grpc_channel_init_create_stack( builder, (grpc_channel_stack_type)channel_stack_type)); @@ -210,7 +210,7 @@ static int check_stack(const char* file, int line, const char* transport_name, gpr_free(expect); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_stack_builder_destroy(builder); grpc_channel_args_destroy(channel_args); } diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 590f934657..847ea0066b 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,7 +651,7 @@ static void test_get_channel_info() { grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } // Ensures that resolver returns. @@ -958,7 +958,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 21c86d01f1..6d56961d84 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -34,7 +34,7 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; @@ -54,7 +54,7 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) {} static void test_grpc_parse_ipv4(const char* uri_text, const char* host, unsigned short port) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -72,7 +72,7 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, static void test_grpc_parse_ipv6(const char* uri_text, const char* host, unsigned short port, uint32_t scope_id) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index f6d7731a6d..18a795fbcb 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -105,7 +105,7 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_timer_check(nullptr); } return false; @@ -148,7 +148,7 @@ int main(int argc, char** argv) { grpc_channel_args* result = (grpc_channel_args*)1; { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolver* resolver = create_resolver("dns:test"); gpr_event ev1; gpr_event_init(&ev1); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 63d1287521..80667908ef 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,7 +28,7 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -45,7 +45,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -80,7 +80,7 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index ecfe43f9b7..d85cbb1d03 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -72,7 +72,7 @@ void on_resolution_cb(void* arg, grpc_error* error) { } static void test_fake_resolver() { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index f3711c151e..4d16a77924 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -41,7 +41,7 @@ void on_resolution_cb(void* arg, grpc_error* error) { } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -68,7 +68,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; @@ -111,7 +111,7 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index 8f1f5e2eda..ee38453166 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -37,7 +37,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* x; if ((x = grpc_uri_parse(s, 1))) { grpc_uri_destroy(x); diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 33cf82d17c..254bfddfb3 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -29,7 +29,7 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); @@ -42,13 +42,13 @@ static void test_succeeds(const char* uri_text, const char* scheme, } static void test_fails(const char* uri_text) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(nullptr == grpc_uri_parse(uri_text, 0)); } static void test_query_parts() { { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); @@ -82,7 +82,7 @@ static void test_query_parts() { } { /* test the current behavior of multiple query part values */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); @@ -100,7 +100,7 @@ static void test_query_parts() { } { /* empty query */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path"; grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index b0613c4b7d..9e811e9af1 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -39,7 +39,7 @@ static void test_algorithm_mesh(void) { grpc_compression_algorithm parsed; grpc_slice mdstr; grpc_mdelem mdelem; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); GPR_ASSERT(grpc_compression_algorithm_parse( @@ -61,7 +61,7 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 0145b4f402..6ca07b70c4 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -70,7 +70,7 @@ static void assert_passthrough(grpc_slice value, grpc_split_slices_to_buffer(uncompressed_split_mode, &value, 1, &input); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); } GPR_ASSERT(input.count > 0); @@ -90,7 +90,7 @@ static void assert_passthrough(grpc_slice value, grpc_split_slice_buffer(compressed_split_mode, &compressed_raw, &compressed); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_msg_decompress( was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); } @@ -152,7 +152,7 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(0 == grpc_msg_compress(static_cast(i), &input, &output)); @@ -176,7 +176,7 @@ static void test_bad_decompression_data_crc(void) { grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* compress it */ grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ @@ -205,7 +205,7 @@ static void test_bad_decompression_data_trailing_garbage(void) { "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); @@ -222,7 +222,7 @@ static void test_bad_decompression_data_stream(void) { grpc_slice_from_copied_buffer("\x78\xda\xff\xff", 4)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); @@ -239,7 +239,7 @@ static void test_bad_compression_algorithm(void) { grpc_slice_buffer_add( &input, grpc_slice_from_copied_string("Never gonna give you up")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; was_compressed = grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_compressed); @@ -263,7 +263,7 @@ static void test_bad_decompression_algorithm(void) { grpc_slice_buffer_add(&input, grpc_slice_from_copied_string( "I'm not really compressed but it doesn't matter")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; was_decompressed = grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 1623e7c8a4..e60e54b2fd 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -49,7 +49,7 @@ TEST(StatsTest, IncCounters) { for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { Snapshot snapshot; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); EXPECT_EQ(snapshot.delta().counters[i], 1); @@ -59,7 +59,7 @@ TEST(StatsTest, IncCounters) { TEST(StatsTest, IncSpecificCounter) { Snapshot snapshot; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_STATS_INC_SYSCALL_POLL(); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); @@ -92,7 +92,7 @@ TEST_P(HistogramTest, IncHistogram) { for (auto j : test_values) { Snapshot snapshot; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_stats_inc_histogram[kHistogram](j); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index b65ba522ac..1ce0dc5bf8 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -269,7 +269,7 @@ static void run_test(const char* response_payload, grpc_status_code expected_status, const char* expected_detail) { test_tcp_server test_server; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_event ev; grpc_init(); diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index 9904c1384c..ca6d17e7c8 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -133,7 +133,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_metadata_array_destroy(&trailing_metadata_recv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (args != nullptr) grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index 60aafc3b94..75c80aa1ff 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -75,7 +75,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); } } @@ -91,7 +91,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index 040c041f38..5b9181586c 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -66,7 +66,7 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->client_args_compression != nullptr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(ffd->client_args_compression); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( @@ -80,7 +80,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->server_args_compression != nullptr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( @@ -95,7 +95,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, } void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); grpc_channel_args_destroy(ffd->client_args_compression); diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 85f5061ee8..9157ab04d0 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -68,7 +68,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->client); @@ -79,7 +79,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index 2f9a9d4c4b..237841d185 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -72,7 +72,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { int i; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; fullstack_fixture_data* ffd = static_cast(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 61853740ab..fda5f4b052 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -78,7 +78,7 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 40ca2a77fb..5fed4434de 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -143,7 +143,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr); grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 574b755539..447bb91d0c 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -50,7 +50,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, nullptr, @@ -87,7 +87,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -101,7 +101,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 304d0dd1fa..c1f8ee0b64 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -44,7 +44,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, nullptr, @@ -81,7 +81,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -95,7 +95,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 0b5ae3abe4..55b847bdae 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -44,7 +44,7 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); grpc_server_setup_transport(f->server, transport, nullptr, @@ -92,7 +92,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; @@ -106,7 +106,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index 4d6fed14e0..9a0680c40e 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -110,7 +110,7 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index aee1388a56..5ddbdefc8c 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -66,7 +66,7 @@ static grpc_channel* create_proxy_client(const char* target, grpc_secure_channel_create(ssl_creds, target, new_client_args, nullptr); grpc_channel_credentials_release(ssl_creds); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(new_client_args); } return channel; @@ -147,7 +147,7 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index c49a866a6c..539bbe4134 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -457,7 +457,7 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; do { gpr_ref(&proxy->users); grpc_pollset_worker* worker = nullptr; @@ -473,7 +473,7 @@ static void thread_main(void* arg) { grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -518,7 +518,7 @@ static void destroy_pollset(void* arg, grpc_error* error) { void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_thd_join(proxy->thd); grpc_tcp_server_shutdown_listeners(proxy->server); grpc_tcp_server_unref(proxy->server); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index ce916bd341..40e9f33ff1 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -748,7 +748,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_timer_manager_set_threading(false); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_executor_set_threading(false); } grpc_resolve_address = my_resolve_address; @@ -842,7 +842,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_insecure_channel_create(target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } gpr_free(target_uri); @@ -869,7 +869,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_server = grpc_server_create(args, nullptr); GPR_ASSERT(g_server != nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } grpc_server_register_completion_queue(g_server, cq, nullptr); @@ -1199,7 +1199,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_secure_channel_create(creds, target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } gpr_free(target_uri); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index e2fb13936a..2d3fc7a074 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -44,7 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (leak_check) grpc_memory_counters_init(); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_executor_set_threading(false); grpc_resource_quota* resource_quota = diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 4506ff5c0b..db25160e2b 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -42,7 +42,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (leak_check) grpc_memory_counters_init(); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_executor_set_threading(false); grpc_resource_quota* resource_quota = diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index 177731669e..d50d1f4d81 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -181,7 +181,7 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ { \ - grpc_core::ExecCtx _local_exec_ctx; \ + grpc_core::ExecCtx exec_ctx; \ grpc_channel_args_destroy(new_client_args); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 5ce45b4c61..f59caf7e35 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -245,7 +245,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index 9bd92b06e3..b10b93978d 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -278,7 +278,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(args); } diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index 93a06c9dfc..944edc7a70 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -129,7 +129,7 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); } @@ -256,7 +256,7 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } @@ -537,7 +537,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index 13e3af7ac5..e056bd547b 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -300,7 +300,7 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { &trailing_lr_metadata); end_test(&f); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(lr_server_args); } config.tear_down_data(&f); diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index 06243be75b..e581f1fc20 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -173,7 +173,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, f = begin_test(config, "test_max_request_message_length", client_args, server_args); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (client_args != nullptr) grpc_channel_args_destroy(client_args); if (server_args != nullptr) grpc_channel_args_destroy(server_args); } @@ -363,7 +363,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, f = begin_test(config, "test_max_response_message_length", client_args, server_args); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; if (client_args != nullptr) grpc_channel_args_destroy(client_args); if (server_args != nullptr) grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 4f09df25db..ec3050ad45 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -129,7 +129,7 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_stream_compression_algorithm( nullptr, GRPC_STREAM_COMPRESS_NONE); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_stream_compression_algorithm_set_state( &server_args, algorithm_to_disable, false); } @@ -257,7 +257,7 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } @@ -545,7 +545,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 6a8c9cdcb2..b95e6528cd 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -277,7 +277,7 @@ static void test_invoke_request_response_with_payload( end_test(&f); config.tear_down_data(&f); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index 3e1a532af5..2a8799ee67 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -275,7 +275,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, end_test(&f); config.tear_down_data(&f); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index 8c5c9e834f..d4decce0aa 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -142,7 +142,7 @@ static void request_with_payload_template( nullptr, default_server_channel_compression_algorithm); if (user_agent_override) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* client_args_old = client_args; grpc_arg arg; arg.key = const_cast(GRPC_ARG_PRIMARY_USER_AGENT_STRING); @@ -350,7 +350,7 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(client_args); grpc_channel_args_destroy(server_args); } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index ed5c03558f..259e3aa463 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -60,7 +60,7 @@ static void on_finish(void* arg, grpc_error* error) { static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -99,7 +99,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -146,7 +146,7 @@ int main(int argc, char** argv) { grpc_init(); { grpc_closure destroyed; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; char* me = argv[0]; char* lslash = strrchr(me, '/'); char* args[4]; diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index 418afb6992..adf69f1b16 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -60,7 +60,7 @@ static void on_finish(void* arg, grpc_error* error) { static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -100,7 +100,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -195,7 +195,7 @@ int main(int argc, char** argv) { test_post(port); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_httpcli_context_destroy(&g_context); GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, grpc_schedule_on_exec_ctx); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index faa5c3dcbc..cbcbe7feff 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -28,7 +28,7 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); } @@ -42,7 +42,7 @@ static void test_execute_one(void) { grpc_combiner* lock = grpc_combiner_create(); gpr_event done; gpr_event_init(&done); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); @@ -72,7 +72,7 @@ static void check_one(void* a, grpc_error* error) { static void execute_many_loop(void* a) { thd_args* args = static_cast(a); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; size_t n = 1; for (size_t i = 0; i < 10; i++) { for (size_t j = 0; j < 10000; j++) { @@ -112,7 +112,7 @@ static void test_execute_many(void) { gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr); gpr_thd_join(thds[i]); } - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_COMBINER_UNREF(lock, "test_execute_many"); } @@ -133,7 +133,7 @@ static void test_execute_finally(void) { gpr_log(GPR_DEBUG, "test_execute_finally"); grpc_combiner* lock = grpc_combiner_create(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_event_init(&got_in_finally); GRPC_CLOSURE_SCHED( GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index d895a270ad..90dd40d9c4 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -32,7 +32,7 @@ static void clean_up(void) {} static grpc_endpoint_test_fixture create_fixture_endpoint_pair( size_t slice_size) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_test_fixture f; grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); @@ -62,7 +62,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); grpc_endpoint_tests(configs[0], g_pollset, g_mu); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index c011ab96d9..8ccae52067 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -173,7 +173,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, struct read_and_write_test_state state; grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, @@ -277,7 +277,7 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_slice_buffer slice_buffer; grpc_slice_buffer_init(&slice_buffer); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 45c96ce12d..750bbf89d4 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -130,7 +130,7 @@ static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { #define NUM_POLLSETS 4 static void test_add_fd_to_pollset() { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; test_fd tfds[NUM_FDS]; int fds[NUM_FDS]; test_pollset pollsets[NUM_POLLSETS]; @@ -231,7 +231,7 @@ static __thread int thread_wakeups = 0; static void test_threading_loop(void* arg) { threading_shared* shared = static_cast(arg); while (thread_wakeups < 1000000) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; gpr_mu_lock(shared->mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( @@ -271,7 +271,7 @@ static void test_threading(void) { shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup"); shared.wakeups = 0; { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); grpc_fd_notify_on_read( shared.wakeup_desc, @@ -286,7 +286,7 @@ static void test_threading(void) { fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); grpc_fd_orphan(shared.wakeup_desc, nullptr, nullptr, false /* already_closed */, "done"); @@ -302,7 +302,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index f4c8e5a21f..aaa14010f8 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -32,7 +32,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* set max # of file descriptors to a low value, and verify we can create and destroy many more than this number diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index 8eda76cf9b..cf75517538 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -246,7 +246,7 @@ static int server_start(server* sv) { static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", @@ -362,7 +362,7 @@ static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); @@ -380,7 +380,7 @@ static void test_grpc_fd(void) { server sv; client cl; int port; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; server_init(&sv); port = server_start(&sv); @@ -436,7 +436,7 @@ static void test_grpc_fd_change(void) { ssize_t result; grpc_closure first_closure; grpc_closure second_closure; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&first_closure, first_read_callback, &a, grpc_schedule_on_exec_ctx); @@ -516,7 +516,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); test_grpc_fd(); diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index cf9c82b482..f27079134b 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -199,7 +199,7 @@ static void pollset_set_test_basic() { * | * +---> FD9 (Added after PS2 is added to PSS0) */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -301,7 +301,7 @@ void pollset_set_test_dup_fds() { * | +--> FD2 * +---> FD1 */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -371,7 +371,7 @@ void pollset_set_test_empty_pollset() { * | * +---> FD2 */ - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -424,7 +424,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; const char* poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != nullptr && diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 45a5e5a0b1..d37d79fed3 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -81,7 +81,7 @@ static void actually_poll(void* argsp) { args_struct* args = static_cast(argsp); grpc_millis deadline = n_sec_deadline(10); while (true) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; @@ -120,7 +120,7 @@ static void must_fail(void* argsp, grpc_error* err) { } static void test_unix_socket(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); poll_pollset_until_request_done(&args); @@ -132,7 +132,7 @@ static void test_unix_socket(void) { } static void test_unix_socket_path_name_too_long(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); const char prefix[] = "unix:/path/name"; @@ -158,7 +158,7 @@ int main(int argc, char** argv) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; test_unix_socket(); test_unix_socket_path_name_too_long(); } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index e6986f332b..a0dc484f3e 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -74,7 +74,7 @@ static grpc_millis n_sec_deadline(int seconds) { } static void poll_pollset_until_request_done(args_struct* args) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; @@ -115,7 +115,7 @@ static void must_fail(void* argsp, grpc_error* err) { } static void test_localhost(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -128,7 +128,7 @@ static void test_localhost(void) { } static void test_default_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -141,7 +141,7 @@ static void test_default_port(void) { } static void test_non_numeric_default_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -154,7 +154,7 @@ static void test_non_numeric_default_port(void) { } static void test_missing_default_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -167,7 +167,7 @@ static void test_missing_default_port(void) { } static void test_ipv6_with_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -187,7 +187,7 @@ static void test_ipv6_without_port(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -207,7 +207,7 @@ static void test_invalid_ip_addresses(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -226,7 +226,7 @@ static void test_unparseable_hostports(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; args_struct args; args_init(&args); grpc_resolve_address( @@ -243,7 +243,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; test_localhost(); test_default_port(); test_non_numeric_default_port(); diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index 7d793937b2..ae26f72701 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -84,7 +84,7 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { } static void destroy_user(grpc_resource_user* usr) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_unref(usr); } @@ -117,11 +117,11 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -135,7 +135,7 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); grpc_resource_user_free(usr, 1024); } @@ -152,14 +152,14 @@ static void test_simple_async_alloc(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -175,7 +175,7 @@ static void test_async_alloc_blocked_by_size(void) { gpr_event ev; gpr_event_init(&ev); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( @@ -186,7 +186,7 @@ static void test_async_alloc_blocked_by_size(void) { nullptr); ; { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -202,7 +202,7 @@ static void test_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -210,13 +210,13 @@ static void test_scavenge(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr1, 1024); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -224,7 +224,7 @@ static void test_scavenge(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -241,7 +241,7 @@ static void test_scavenge_blocked(void) { gpr_event ev; { gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -250,14 +250,14 @@ static void test_scavenge_blocked(void) { } { gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr1, 1024); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -265,7 +265,7 @@ static void test_scavenge_blocked(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -282,7 +282,7 @@ static void test_blocked_until_scheduled_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -292,14 +292,14 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -309,7 +309,7 @@ static void test_blocked_until_scheduled_reclaim(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -326,7 +326,7 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -336,14 +336,14 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -353,7 +353,7 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); @@ -370,7 +370,7 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -380,14 +380,14 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, @@ -397,7 +397,7 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -415,7 +415,7 @@ static void test_unused_reclaim_is_cancelled(void) { gpr_event destructive_done; gpr_event_init(&destructive_done); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -449,7 +449,7 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -457,7 +457,7 @@ static void test_benign_reclaim_is_preferred(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -473,7 +473,7 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, @@ -485,7 +485,7 @@ static void test_benign_reclaim_is_preferred(void) { nullptr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -509,7 +509,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -517,7 +517,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( @@ -533,7 +533,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&ev)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, @@ -545,7 +545,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -564,16 +564,16 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_quota_unref(q); grpc_resource_user_unref(usr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } } @@ -594,7 +594,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event reclaimer_cancelled; gpr_event_init(&reclaimer_cancelled); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); grpc_core::ExecCtx::Get()->Flush(); @@ -605,7 +605,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&allocated, @@ -615,7 +615,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( nullptr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_unref(usr); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, @@ -623,7 +623,7 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( nullptr); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, @@ -643,7 +643,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&allocated, @@ -653,7 +653,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event reclaimer_done; gpr_event_init(&reclaimer_done); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); grpc_core::ExecCtx::Get()->Flush(); @@ -664,7 +664,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&allocated, @@ -675,7 +675,7 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { } } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_free(usr, 1024); } destroy_user(usr); @@ -699,14 +699,14 @@ static void test_one_slice(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } destroy_user(usr); @@ -731,20 +731,20 @@ static void test_one_slice_deleted_late(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } } @@ -773,7 +773,7 @@ static void test_negative_rq_free_pool(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); @@ -786,13 +786,13 @@ static void test_negative_rq_free_pool(void) { GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer_destroy_internal(&buffer); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 0cdf30590e..40a050ed9f 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -53,7 +53,7 @@ static grpc_millis test_deadline(void) { static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT( GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); @@ -83,7 +83,7 @@ void test_succeeds(void) { int r; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -139,7 +139,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -192,7 +192,7 @@ int main(int argc, char** argv) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset_set = grpc_pollset_set_create(); g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index 344478ea97..0c6250ed7f 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -87,7 +87,7 @@ void test_succeeds(void) { uv_tcp_t* svr_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -136,7 +136,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -186,7 +186,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index b42fb588eb..f4acba8302 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -163,7 +163,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, num_bytes, slice_size); @@ -213,7 +213,7 @@ static void large_read_test(size_t slice_size) { ssize_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -301,7 +301,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { int flags; int current = 0; int i; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -348,7 +348,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_closure write_done_closure; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, @@ -411,7 +411,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure fd_released_cb; int fd_released_done = 0; GRPC_CLOSURE_INIT(&fd_released_cb, &on_fd_released, &fd_released_done, @@ -507,7 +507,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( size_t slice_size) { int sv[2]; grpc_endpoint_test_fixture f; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; create_sockets(sv); grpc_resource_quota* resource_quota = @@ -541,7 +541,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); grpc_endpoint_tests(configs[0], g_pollset, g_mu); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 28fc3601ad..3c9ca2109e 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -163,14 +163,14 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, } static void test_no_op(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_start"); @@ -179,7 +179,7 @@ static void test_no_op_with_start(void) { } static void test_no_op_with_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -198,7 +198,7 @@ static void test_no_op_with_port(void) { } static void test_no_op_with_port_and_start(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -282,7 +282,7 @@ static grpc_error* tcp_connect(const test_addr* remote, static void test_connect(size_t num_connects, const grpc_channel_args* channel_args, test_addrs* dst_addrs, bool test_dst_addrs) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = @@ -436,7 +436,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index 07b1fb1579..35d62b51b7 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -115,14 +115,14 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, } static void test_no_op(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); @@ -131,7 +131,7 @@ static void test_no_op_with_start(void) { } static void test_no_op_with_port(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -150,7 +150,7 @@ static void test_no_op_with_port(void) { } static void test_no_op_with_port_and_start(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; @@ -214,7 +214,7 @@ static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, /* Tests a tcp server with multiple ports. */ static void test_connect(unsigned n) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -284,7 +284,7 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 7ab4c4415c..deb8c4d87e 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -45,7 +45,7 @@ static void cb(void* arg, grpc_error* error) { static void add_test(void) { int i; grpc_timer timers[20]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "add_test"); @@ -109,7 +109,7 @@ static void add_test(void) { /* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "destruction_test"); diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 379c50c09d..7f662f0683 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -127,13 +127,13 @@ static test_socket_factory* test_socket_factory_create(void) { } static void test_no_op(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); grpc_udp_server_destroy(s, nullptr); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_start"); grpc_udp_server_start(s, nullptr, 0, nullptr); @@ -142,7 +142,7 @@ static void test_no_op_with_start(void) { static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -162,7 +162,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; @@ -194,7 +194,7 @@ static void test_no_op_with_port_and_socket_factory(void) { static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -216,7 +216,7 @@ static void test_no_op_with_port_and_start(void) { } static void test_receive(int number_of_clients) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int clifd, svrfd; @@ -294,7 +294,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 7d0a24a459..ecc61928f5 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -148,7 +148,7 @@ static grpc_httpcli_response http_response(int status, const char* body) { /* -- Tests. -- */ static void test_empty_md_array(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); GPR_ASSERT(md_array.md == nullptr); @@ -157,7 +157,7 @@ static void test_empty_md_array(void) { } static void test_add_to_empty_md_array(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; @@ -172,7 +172,7 @@ static void test_add_to_empty_md_array(void) { } static void test_add_abunch_to_md_array(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; @@ -191,7 +191,7 @@ static void test_add_abunch_to_md_array(void) { } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -208,7 +208,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) { } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -220,7 +220,7 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, ""); @@ -231,7 +231,7 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -246,7 +246,7 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, @@ -260,7 +260,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -276,7 +276,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -378,7 +378,7 @@ static void run_request_metadata_test(grpc_call_credentials* creds, } static void test_google_iam_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -395,7 +395,7 @@ static void test_google_iam_creds(void) { } static void test_access_token_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); @@ -419,7 +419,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector( } static void test_channel_oauth2_composite_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_create_security_connector, nullptr}; @@ -439,7 +439,7 @@ static void test_channel_oauth2_composite_creds(void) { } static void test_oauth2_google_iam_composite_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -492,7 +492,7 @@ check_channel_oauth2_google_iam_create_security_connector( } static void test_channel_oauth2_google_iam_composite_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_google_iam_create_security_connector, @@ -570,7 +570,7 @@ static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, } static void test_compute_engine_creds_success(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_call_credentials* creds = @@ -599,7 +599,7 @@ static void test_compute_engine_creds_success(void) { } static void test_compute_engine_creds_failure(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -659,7 +659,7 @@ static int refresh_token_httpcli_post_failure( } static void test_refresh_token_creds_success(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, @@ -688,7 +688,7 @@ static void test_refresh_token_creds_success(void) { } static void test_refresh_token_creds_failure(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -791,7 +791,7 @@ static void test_jwt_creds_lifetime(void) { static void test_jwt_creds_success(void) { char* json_key_string = test_json_key_str(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_md_value; @@ -833,7 +833,7 @@ static void test_jwt_creds_success(void) { static void test_jwt_creds_signing_failure(void) { char* json_key_string = test_json_key_str(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* state = make_request_metadata_state( @@ -865,7 +865,7 @@ static void set_google_default_creds_env_var_with_file_contents( } static void test_google_default_creds_auth_key(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_service_account_jwt_access_credentials* jwt; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); @@ -886,7 +886,7 @@ static void test_google_default_creds_auth_key(void) { } static void test_google_default_creds_refresh_token(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_google_refresh_token_credentials* refresh; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); @@ -921,7 +921,7 @@ static int default_creds_gce_detection_httpcli_get_success_override( static char* null_well_known_creds_path_getter(void) { return nullptr; } static void test_google_default_creds_gce(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; request_metadata_state* state = @@ -1056,7 +1056,7 @@ static void plugin_destroy(void* state) { static void test_metadata_plugin_success(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* md_state = make_request_metadata_state( @@ -1079,7 +1079,7 @@ static void test_metadata_plugin_success(void) { static void test_metadata_plugin_failure(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_error; @@ -1121,7 +1121,7 @@ static void test_get_well_known_google_credentials_file_path(void) { } static void test_channel_creds_duplicate_without_call_creds(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* channel_creds = grpc_fake_transport_security_credentials_create(); diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 57e2f4c978..aac9cc0029 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -207,7 +207,7 @@ static void test_parse_json_key_failure_no_private_key(void) { static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, char** scratchpad) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; char* b64; char* decoded; grpc_json* json; @@ -327,7 +327,7 @@ static void check_jwt_claim(grpc_json* claim, const char* expected_audience, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, const char* signed_data, size_t signed_data_size) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); EVP_PKEY* key = EVP_PKEY_new(); diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index ec14fec697..e219260b1d 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -209,7 +209,7 @@ static void test_claims_success(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); @@ -231,7 +231,7 @@ static void test_expired_claims_failure(void) { gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); @@ -252,7 +252,7 @@ static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); } @@ -262,7 +262,7 @@ static void test_bad_audience_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == @@ -276,7 +276,7 @@ static void test_bad_subject_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == @@ -350,7 +350,7 @@ static void on_verification_success(void* user_data, } static void test_jwt_verifier_google_email_issuer_success(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -383,7 +383,7 @@ static int httpcli_get_custom_keys_for_email( } static void test_jwt_verifier_custom_email_issuer_success(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -430,7 +430,7 @@ static int httpcli_get_openid_config(const grpc_httpcli_request* request, } static void test_jwt_verifier_url_issuer_success(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -469,7 +469,7 @@ static int httpcli_get_bad_json(const grpc_httpcli_request* request, } static void test_jwt_verifier_url_issuer_bad_config(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -492,7 +492,7 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { } static void test_jwt_verifier_bad_json_key(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -521,7 +521,7 @@ static void corrupt_jwt_sig(char* jwt) { char* last_dot = strrchr(jwt, '.'); GPR_ASSERT(last_dot != nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; sig = grpc_base64_decode(last_dot + 1, 1); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); @@ -543,7 +543,7 @@ static void on_verification_bad_signature(void* user_data, } static void test_jwt_verifier_bad_signature(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -583,7 +583,7 @@ static void on_verification_bad_format(void* user_data, } static void test_jwt_verifier_bad_format(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 7551d7df85..0d3a1279af 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -69,7 +69,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials* creds) { oauth2_request request; memset(&request, 0, sizeof(request)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index 7089b9808a..b3742f58a8 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -62,7 +62,7 @@ static void on_metadata_response(void* arg, grpc_error* error) { int main(int argc, char** argv) { int result = 0; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; synchronizer sync; grpc_channel_credentials* creds = nullptr; const char* service_url = "https://test.foo.google.com/Foo"; diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index c8f4f32538..38c78fed42 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -38,7 +38,7 @@ static grpc_pollset* g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, grpc_slice* leftover_slices, size_t leftover_nslices, bool use_zero_copy_protector) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; tsi_frame_protector* fake_read_protector = tsi_create_fake_frame_protector(nullptr); tsi_frame_protector* fake_write_protector = @@ -172,7 +172,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_slice_buffer incoming; grpc_slice s = grpc_slice_from_copied_string("hello world 12345678900987654321"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; int n = 0; grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); @@ -209,7 +209,7 @@ int main(int argc, char** argv) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); grpc_endpoint_tests(configs[0], g_pollset, g_mu); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index 9cf73fa871..7056cfe581 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -56,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (leak_check) grpc_memory_counters_init(); grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resource_quota* resource_quota = grpc_resource_quota_create("ssl_server_fuzzer"); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index 1bd92bbc97..e039970c67 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -76,7 +76,7 @@ int main(int argc, char** argv) { gpr_cmdline* cl; const char* jwt = nullptr; const char* aud = nullptr; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_init(); cl = gpr_cmdline_create("JWT verifier tool"); diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index e0c7ed361d..94785fd1e2 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -45,7 +45,7 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char* hello = "hello"; char* hello_b64 = grpc_base64_encode(hello, strlen(hello), url_safe, multiline); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello)); GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello, @@ -65,7 +65,7 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { /* Try all the different paddings. */ for (i = 0; i < 3; i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline); orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i)); @@ -116,7 +116,7 @@ static void test_url_safe_unsafe_mismatch_failure(void) { int url_safe = 1; for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); orig_decoded = grpc_base64_decode(b64, !url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); @@ -165,7 +165,7 @@ static void test_rfc4648_test_vectors(void) { static void test_unpadded_decode(void) { grpc_slice decoded; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; decoded = grpc_base64_decode("Zm9vYmFy", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0); diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index 1cbb241a98..9fad9a614e 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -119,7 +119,7 @@ static void test_slice_hash_table() { check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); // Clean up. - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_hash_table_unref(table); } @@ -146,7 +146,7 @@ static void test_slice_hash_table_eq() { create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_hash_table_unref(table_a); grpc_slice_hash_table_unref(table_b); } @@ -217,7 +217,7 @@ static void test_slice_hash_table_not_eq() { create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_slice_hash_table_unref(table_a); grpc_slice_hash_table_unref(table_b_larger); grpc_slice_hash_table_unref(table_b_smaller); diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index b762fed941..94a8615b3c 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -132,7 +132,7 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, memset(GRPC_SLICE_START_PTR(input_slice), 'a', input_size); grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); } diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index 65fac9daa3..37247f89d0 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -35,7 +35,7 @@ void test_unknown_scheme_target(void) { chan = grpc_insecure_channel_create("blah://blah", nullptr, nullptr); GPR_ASSERT(chan != nullptr); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index 3452f78a3b..fefbb3c185 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -137,7 +137,7 @@ static void test_cq_end_op(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -172,7 +172,7 @@ static void test_cq_tls_cache_full(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx _local_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -212,7 +212,7 @@ static void test_cq_tls_cache_empty(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx _local_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -293,7 +293,7 @@ static void test_pluck(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_PLUCK; for (size_t pidx = 0; pidx < GPR_ARRAY_SIZE(polling_types); pidx++) { - grpc_core::ExecCtx _local_exec_ctx; // reset exec_ctx + grpc_core::ExecCtx exec_ctx; // reset exec_ctx attr.cq_polling_type = polling_types[pidx]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 8867ba88c3..ba9491fc41 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -80,7 +80,7 @@ static void test_too_many_plucks(void) { gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; gpr_thd_options thread_options = gpr_thd_options_default(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); @@ -158,7 +158,7 @@ static void producer_thread(void* arg) { gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_cq_end_op(opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, free_completion, nullptr, static_cast( diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index f21086847b..0bebac216a 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -117,7 +117,7 @@ static void on_connect(void* vargs, grpc_endpoint* tcp, void bad_server_thread(void* vargs) { struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int port; @@ -225,7 +225,7 @@ int run_concurrent_connectivity_test() { gpr_atm_rel_store(&args.stop, 1); gpr_thd_join(server); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_pollset_shutdown( args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, grpc_schedule_on_exec_ctx)); diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 258ee6a831..4bf40569e6 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -44,7 +44,7 @@ void test_transport_op(grpc_channel* channel) { grpc_transport_op* op; grpc_channel_element* elem; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, grpc_schedule_on_exec_ctx); diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index 4052f19f51..9cdd299ae3 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -178,7 +178,7 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index 62c2d92885..fa22cd6873 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -37,7 +37,7 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); grpc_channel_credentials_unref(creds); } @@ -55,7 +55,7 @@ void test_security_connector_already_in_arg(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } @@ -65,7 +65,7 @@ void test_null_creds(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index e7ae97908c..b2d9b428f0 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -156,7 +156,7 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index 168807adde..fb7fc4cab2 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -58,7 +58,7 @@ namespace { void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { estimator->AddIncomingBytes(1234567); inc_time(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; estimator->SchedulePing(); estimator->StartPing(); for (size_t i = 0; i < n; i++) { diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index a0dbc79158..2aab6e9262 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -37,7 +37,7 @@ static void not_called_closure(void* arg, grpc_error* error) { static void test_slice_buffer_stream_basic(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_basic"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -71,7 +71,7 @@ static void test_slice_buffer_stream_basic(void) { static void test_slice_buffer_stream_shutdown(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_shutdown"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -117,7 +117,7 @@ static void test_slice_buffer_stream_shutdown(void) { static void test_caching_byte_stream_basic(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_basic"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -156,7 +156,7 @@ static void test_caching_byte_stream_basic(void) { static void test_caching_byte_stream_reset(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_reset"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -202,7 +202,7 @@ static void test_caching_byte_stream_reset(void) { static void test_caching_byte_stream_shared_cache(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_shared_cache"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 4b65d7d3ca..6d70a4261b 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -79,7 +79,7 @@ static grpc_slice base64_decode_with_length(const char* s, int main(int argc, char** argv) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which takes encoded base64 strings without pad chars, but output length is diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index 2772aef3c4..d2dbd4a798 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -257,7 +257,7 @@ static void test_interned_key_indexed() { static void run_test(void (*test)(), const char* name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_compressor_init(&g_compressor); test(); grpc_chttp2_hpack_compressor_destroy(&g_compressor); diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index dcec8b2230..9a195daee0 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -38,7 +38,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_chttp2_hpack_parser parser; { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_parser_init(&parser); parser.on_header = onhdr; GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 52900c5419..9d3456a873 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -62,7 +62,7 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); } @@ -79,7 +79,7 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index 97e1a02621..3f3cb2ee9d 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -44,7 +44,7 @@ static void assert_index(const grpc_chttp2_hptbl* tbl, uint32_t idx, } static void test_static_lookup(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; grpc_chttp2_hptbl_init(&tbl); @@ -123,7 +123,7 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 100000; i++) { @@ -152,7 +152,7 @@ static void test_many_additions(void) { static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, const char* key, const char* value) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem md = grpc_mdelem_from_slices( grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); @@ -162,7 +162,7 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, } static void test_find(void) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index e1bc0c4eb7..f5894599e5 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -58,7 +58,7 @@ static void test_connectivity_state_name(void) { static void test_check(void) { grpc_connectivity_state_tracker tracker; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_error* error; gpr_log(GPR_DEBUG, "test_check"); grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -74,7 +74,7 @@ static void test_subscribe_then_unsubscribe(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -96,7 +96,7 @@ static void test_subscribe_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -117,7 +117,7 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 70d557b128..5c52ae8d5f 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -60,7 +60,7 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; m1 = grpc_mdelem_from_slices( maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); @@ -95,7 +95,7 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); @@ -117,7 +117,7 @@ static void test_create_many_persistant_metadata(void) { gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); @@ -151,7 +151,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( a = grpc_mdelem_from_slices( @@ -178,7 +178,7 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; a = grpc_mdelem_from_slices( maybe_intern(grpc_slice_from_static_string("a"), intern_keys), @@ -225,7 +225,7 @@ static void test_things_stick_around(void) { gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); @@ -271,7 +271,7 @@ static void test_user_data_works(void) { gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; ud1 = static_cast(gpr_malloc(sizeof(int))); *ud1 = 1; ud2 = static_cast(gpr_malloc(sizeof(int))); @@ -322,7 +322,7 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", intern_key, intern_value); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; uint8_t binary_value[BUFFER_SIZE] = {0}; for (uint8_t i = 0; i < BUFFER_SIZE; i++) { @@ -346,7 +346,7 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, dup_value); grpc_init(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 2a192e04ef..1ed6ccfba6 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -24,7 +24,7 @@ GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) #define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ do { \ - grpc_core::ExecCtx _local_exec_ctx; \ + grpc_core::ExecCtx exec_ctx; \ GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ \ } while (0) diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 705286c6d4..7e76c8063f 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -62,7 +62,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_response rsp; freereq pr; char* path; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure* shutdown_closure; grpc_init(); @@ -198,7 +198,7 @@ int grpc_pick_port_using_server(void) { grpc_init(); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index b94297adda..5f6af4e707 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -55,7 +55,7 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int port_added; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; addr->sin_family = AF_INET; addr->sin_port = htons((uint16_t)port); @@ -76,7 +76,7 @@ void test_tcp_server_start(test_tcp_server* server, int port) { void test_tcp_server_poll(test_tcp_server* server, int seconds) { grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); @@ -91,7 +91,7 @@ static void finish_pollset(void* arg, grpc_error* error) { } void test_tcp_server_destroy(test_tcp_server* server) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; grpc_tcp_server_unref(server->tcp_server); diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index f2f3cc3425..e6e6e71f42 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -112,7 +112,7 @@ class ClientLbEnd2endTest : public ::testing::Test { } void SetNextResolution(const std::vector& ports) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(ports.size(), nullptr); for (size_t i = 0; i < ports.size(); ++i) { diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index c5c53b8b8a..48cdd433b2 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -451,7 +451,7 @@ class GrpclbEnd2endTest : public ::testing::Test { }; void SetNextResolution(const std::vector& address_data) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 792c82639c..fd455c4c9a 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -562,7 +562,7 @@ static void perform_request(client_fixture* cf) { #define BALANCERS_NAME "lb.name" static void setup_client(const server_fixture* lb_server, const server_fixture* backends, client_fixture* cf) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; char* expected_target_names = nullptr; const char* backends_name = lb_server->servers_hostport; diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index b17f79613a..5c2c38c27d 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -521,7 +521,7 @@ static void BM_IsolatedFilter(benchmark::State& state) { label << " #has_dummy_filter"; } - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; size_t channel_size = grpc_channel_stack_size( filters.size() == 0 ? nullptr : &filters[0], filters.size()); grpc_channel_stack* channel_stack = @@ -692,7 +692,7 @@ class IsolatedCallFixture : public TrackCounters { builder, &isolated_call_filter::isolated_call_filter, nullptr, nullptr)); { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; channel_ = grpc_channel_create_with_builder(builder, GRPC_CLIENT_CHANNEL); } cq_ = grpc_completion_queue_create_for_next(nullptr); diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 6b6b441d93..4b7310389c 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -50,7 +50,7 @@ static grpc_slice MakeSlice(std::vector bytes) { static void BM_HpackEncoderInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_compressor c; while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); @@ -64,7 +64,7 @@ BENCHMARK(BM_HpackEncoderInitDestroy); static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_millis saved_now = grpc_core::ExecCtx::Get()->Now(); grpc_metadata_batch b; @@ -108,7 +108,7 @@ BENCHMARK(BM_HpackEncoderEncodeDeadline); template static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; static bool logged_representative_output = false; grpc_metadata_batch b; @@ -425,7 +425,7 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, static void BM_HpackParserInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_parser p; while (state.KeepRunning()) { grpc_chttp2_hpack_parser_init(&p); @@ -444,7 +444,7 @@ static void UnrefHeader(void* user_data, grpc_mdelem md) { template static void BM_HpackParserParseHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; std::vector init_slices = Fixture::GetInitSlices(); std::vector benchmark_slices = Fixture::GetBenchmarkSlices(); grpc_chttp2_hpack_parser p; diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index 044417830f..43bbbad880 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -257,7 +257,7 @@ class Stream { static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -303,7 +303,7 @@ class RepresentativeClientInitialMetadata { template static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -354,7 +354,7 @@ BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -387,7 +387,7 @@ std::vector> done_events; static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr(new Stream(&f)); s->Init(state); @@ -517,7 +517,7 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index f28093ae17..4d5a82c3f6 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -34,7 +34,7 @@ auto& force_library_initialization = Library::get(); static void BM_NoOpExecCtx(benchmark::State& state) { TrackCounters track_counters; while (state.KeepRunning()) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; } track_counters.Finish(state); } @@ -42,7 +42,7 @@ BENCHMARK(BM_NoOpExecCtx); static void BM_WellFlushed(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_core::ExecCtx::Get()->Flush(); } @@ -68,7 +68,7 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { TrackCounters track_counters; grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { benchmark::DoNotOptimize(GRPC_CLOSURE_INIT( &c, DoNothing, nullptr, grpc_combiner_scheduler(combiner))); @@ -83,7 +83,7 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE); grpc_core::ExecCtx::Get()->Flush(); @@ -95,7 +95,7 @@ BENCHMARK(BM_ClosureRunOnExecCtx); static void BM_ClosureCreateAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( GRPC_CLOSURE_CREATE(DoNothing, nullptr, grpc_schedule_on_exec_ctx), @@ -108,7 +108,7 @@ BENCHMARK(BM_ClosureCreateAndRun); static void BM_ClosureInitAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure c; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( @@ -124,7 +124,7 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); grpc_core::ExecCtx::Get()->Flush(); @@ -140,7 +140,7 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -159,7 +159,7 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -176,7 +176,7 @@ static void BM_AcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { gpr_mu_lock(&mu); DoNothing(nullptr, GRPC_ERROR_NONE); @@ -192,7 +192,7 @@ static void BM_TryAcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { if (gpr_mu_trylock(&mu)) { DoNothing(nullptr, GRPC_ERROR_NONE); @@ -210,7 +210,7 @@ static void BM_AcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { gpr_spinlock_lock(&mu); DoNothing(nullptr, GRPC_ERROR_NONE); @@ -225,7 +225,7 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { if (gpr_spinlock_trylock(&mu)) { DoNothing(nullptr, GRPC_ERROR_NONE); @@ -244,7 +244,7 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); grpc_core::ExecCtx::Get()->Flush(); @@ -262,7 +262,7 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -283,7 +283,7 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -306,7 +306,7 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -335,7 +335,7 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c4, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); @@ -381,7 +381,7 @@ class Rescheduler { static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; Rescheduler r(state, grpc_schedule_on_exec_ctx); r.ScheduleFirst(); @@ -391,7 +391,7 @@ BENCHMARK(BM_ClosureReschedOnExecCtx); static void BM_ClosureReschedOnCombiner(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_scheduler(combiner)); r.ScheduleFirst(); @@ -404,7 +404,7 @@ BENCHMARK(BM_ClosureReschedOnCombiner); static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_finally_scheduler(combiner)); r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner)); diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index 16f451d98f..97242598f1 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -81,7 +81,7 @@ static void BM_Pass1Cpp(benchmark::State& state) { while (state.KeepRunning()) { grpc_cq_completion completion; DummyTag dummy_tag; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag)); grpc_cq_end_op(c_cq, &dummy_tag, GRPC_ERROR_NONE, DoneWithCompletionOnStack, nullptr, &completion); @@ -101,7 +101,7 @@ static void BM_Pass1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, nullptr, &completion); @@ -120,7 +120,7 @@ static void BM_Pluck1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, nullptr, &completion); diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index fd888a5a40..d12f475a49 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -246,7 +246,7 @@ template static void BM_ErrorGetStatus(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_status_code status; grpc_slice slice; @@ -261,7 +261,7 @@ template static void BM_ErrorGetStatusCode(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_status_code status; grpc_error_get_status(fixture.error(), fixture.deadline(), &status, nullptr, @@ -275,7 +275,7 @@ template static void BM_ErrorHttpError(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_http2_error_code error; grpc_error_get_status(fixture.error(), fixture.deadline(), nullptr, nullptr, diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 23ca750307..0212cdddf8 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -177,7 +177,7 @@ class TrickledCHTTP2 : public EndpointPairFixture { } void Step(bool update_stats) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; inc_time(); size_t client_backlog = grpc_trickle_endpoint_trickle(endpoint_pair_.client); diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc index 62c9a2e335..f1e7890fc0 100644 --- a/test/cpp/microbenchmarks/bm_metadata.cc +++ b/test/cpp/microbenchmarks/bm_metadata.cc @@ -90,7 +90,7 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } @@ -103,7 +103,7 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } @@ -119,7 +119,7 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex( TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem seed = grpc_mdelem_create(k, v, nullptr); while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); @@ -136,7 +136,7 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } @@ -152,7 +152,7 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -168,7 +168,7 @@ static void BM_MetadataFromInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -186,7 +186,7 @@ static void BM_MetadataFromInternedKeyWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create( k, v, reinterpret_cast(backing_store))); @@ -201,7 +201,7 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_200; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } @@ -216,7 +216,7 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed( TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_GZIP; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } @@ -229,7 +229,7 @@ BENCHMARK(BM_MetadataFromStaticMetadataStringsNotIndexed); static void BM_MetadataRefUnrefExternal(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem el = grpc_mdelem_create( grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), reinterpret_cast(backing_store)); @@ -245,7 +245,7 @@ BENCHMARK(BM_MetadataRefUnrefExternal); static void BM_MetadataRefUnrefInterned(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); grpc_mdelem el = grpc_mdelem_create( @@ -263,7 +263,7 @@ BENCHMARK(BM_MetadataRefUnrefInterned); static void BM_MetadataRefUnrefAllocated(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem el = grpc_mdelem_create(grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), nullptr); @@ -278,7 +278,7 @@ BENCHMARK(BM_MetadataRefUnrefAllocated); static void BM_MetadataRefUnrefStatic(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_mdelem el = grpc_mdelem_create(GRPC_MDSTR_STATUS, GRPC_MDSTR_200, nullptr); while (state.KeepRunning()) { diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index 9a859b51ea..d9d5164cce 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -50,7 +50,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { size_t ps_sz = grpc_pollset_size(); grpc_pollset* ps = static_cast(gpr_malloc(ps_sz)); gpr_mu* mu; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); @@ -114,7 +114,7 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(mu); while (state.KeepRunning()) { GRPC_ERROR_UNREF(grpc_pollset_work(ps, nullptr, 0)); @@ -136,7 +136,7 @@ static void BM_PollAddFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_wakeup_fd wakeup_fd; GPR_ASSERT( GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&wakeup_fd))); @@ -218,7 +218,7 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; grpc_wakeup_fd wakeup_fd; GRPC_ERROR_UNREF(grpc_wakeup_fd_init(&wakeup_fd)); grpc_fd* wakeup = grpc_fd_create(wakeup_fd.read_fd, "wakeup_read"); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 1520282009..ab0a696e3d 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -166,7 +166,7 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* add server endpoint to server_ * */ diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 3bd1df9429..3481d9d1aa 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -196,7 +196,7 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { time_left.tv_sec, time_left.tv_nsec); GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0); grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(args->mu); GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, @@ -275,7 +275,7 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) { } TEST(ResolverComponentTest, TestResolvesRelevantRecords) { - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; ArgsStruct args; ArgsInit(&args); args.expected_addrs = ParseExpectedAddrs(FLAGS_expected_addrs); diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index c5d29469b2..1711eef303 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -82,7 +82,7 @@ class EndpointPairFixture { ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx exec_ctx; /* add server endpoint to server_ */ { -- cgit v1.2.3 From 54961bb9e16f84d193077277f7d2d8269f57a411 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 4 Dec 2017 12:50:27 -0800 Subject: Change the code to use MONOTONIC clocks when calling gpr_cv_wait (condition varialbes in linux support MONOTONIC clock type) --- src/core/lib/iomgr/ev_epoll1_linux.cc | 2 +- src/core/lib/iomgr/ev_poll_posix.cc | 8 ++++---- src/core/lib/iomgr/executor.cc | 2 +- src/core/lib/iomgr/iomgr.cc | 5 +++-- src/core/lib/iomgr/timer_manager.cc | 4 ++-- src/core/lib/surface/completion_queue.cc | 2 +- src/core/lib/surface/server.cc | 2 +- test/core/support/cpu_test.cc | 2 +- test/core/support/sync_test.cc | 12 ++++++------ test/cpp/util/cli_call.cc | 4 ++-- 10 files changed, 22 insertions(+), 21 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 0dda1d924c..a52bedeb7a 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -753,7 +753,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } if (gpr_cv_wait(&worker->cv, &pollset->mu, - grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME)) && + grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)) && worker->state == UNKICKED) { /* If gpr_cv_wait returns true (i.e a timeout), pretend that the worker received a kick */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 8659559f78..43a63c5255 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -1494,7 +1494,7 @@ static void run_poll(void* args) { decref_poll_result(result); // Leave this polling thread alive for a grace period to do another poll() // op - gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME); + gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC); deadline = gpr_time_add(deadline, thread_grace); pargs->trigger_set = 0; gpr_cv_wait(&pargs->trigger, &g_cvfds.mu, deadline); @@ -1549,9 +1549,9 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { } } - gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME); + gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC); if (timeout < 0) { - deadline = gpr_inf_future(GPR_CLOCK_REALTIME); + deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); } else { deadline = gpr_time_add(deadline, gpr_time_from_millis(timeout, GPR_TIMESPAN)); @@ -1654,7 +1654,7 @@ static void global_cv_fd_table_shutdown() { // Not doing so will result in reported memory leaks if (!gpr_unref(&g_cvfds.pollcount)) { int res = gpr_cv_wait(&g_cvfds.shutdown_cv, &g_cvfds.mu, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(3, GPR_TIMESPAN))); GPR_ASSERT(res == 0); } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index d8a195f010..cca59e7a52 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -158,7 +158,7 @@ static void executor_thread(void* arg) { ts->depth -= subtract_depth; while (grpc_closure_list_empty(ts->elems) && !ts->shutdown) { ts->queued_long_job = false; - gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } if (ts->shutdown) { if (executor_trace.enabled()) { diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index e077b35014..bdedd85041 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -117,8 +117,9 @@ void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) { dump_objects("LEAKED"); abort(); } - gpr_timespec short_deadline = gpr_time_add( - gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); + gpr_timespec short_deadline = + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_millis(100, GPR_TIMESPAN)); if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) { if (g_root_object.next != &g_root_object) { diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index dac74aea24..b68088e4bd 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -193,7 +193,7 @@ static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { } gpr_cv_wait(&g_cv_wait, &g_mu, - grpc_millis_to_timespec(next, GPR_CLOCK_REALTIME)); + grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC)); if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "wait ended: was_timed:%d kicked:%d", @@ -319,7 +319,7 @@ static void stop_threads(void) { gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count); } while (g_thread_count > 0) { - gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count); } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 98d7e35943..dfb5b5bf29 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -118,7 +118,7 @@ static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, } w.kicked = false; gpr_timespec deadline_ts = - grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME); + grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC); while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline_ts)) ; diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 0f8a057f31..e88e1ee161 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -1213,7 +1213,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, gpr_mu_lock(&server->mu_global); while (server->starting) { gpr_cv_wait(&server->starting_cv, &server->mu_global, - gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_inf_future(GPR_CLOCK_MONOTONIC)); } /* stay locked, and gather up some stuff to do */ diff --git a/test/core/support/cpu_test.cc b/test/core/support/cpu_test.cc index 1783ec3c60..770b074d47 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/support/cpu_test.cc @@ -114,7 +114,7 @@ static void cpu_test(void) { } gpr_mu_lock(&ct.mu); while (!ct.is_done) { - gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&ct.mu); fprintf(stderr, "Saw cores ["); diff --git a/test/core/support/sync_test.cc b/test/core/support/sync_test.cc index 86e78ce0b5..c882488243 100644 --- a/test/core/support/sync_test.cc +++ b/test/core/support/sync_test.cc @@ -73,7 +73,7 @@ void queue_append(queue* q, int x) { corresponding condition variable. The predicate must be on state protected by the lock. */ while (q->length == N) { - gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } if (q->length == 0) { /* Wake threads blocked in queue_remove(). */ /* It's normal to use gpr_cv_broadcast() or gpr_signal() while @@ -197,7 +197,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { static void test_wait(struct test* m) { gpr_mu_lock(&m->mu); while (m->done != 0) { - gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&m->mu); } @@ -297,7 +297,7 @@ static void inc_by_turns(void* v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_mu_lock(&m->mu); while ((m->counter % m->threads) != id) { - gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } m->counter++; gpr_cv_broadcast(&m->cv); @@ -314,7 +314,7 @@ static void inc_with_1ms_delay(void* v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; gpr_mu_lock(&m->mu); - deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_micros(1000, GPR_TIMESPAN)); while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) { } @@ -370,14 +370,14 @@ static void consumer(void* v /*=m*/) { int64_t i; int value; for (i = 0; i != n; i++) { - queue_remove(&m->q, &value, gpr_inf_future(GPR_CLOCK_REALTIME)); + queue_remove(&m->q, &value, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_lock(&m->mu); m->counter = n; gpr_mu_unlock(&m->mu); GPR_ASSERT( !queue_remove(&m->q, &value, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_micros(1000000, GPR_TIMESPAN)))); mark_thread_done(m); } diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index c3220efa54..4f1a20c727 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -126,7 +126,7 @@ void CliCall::WriteAndWait(const grpc::string& request) { call_->Write(send_buffer, tag(2)); write_done_ = false; while (!write_done_) { - gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&write_mu_); } @@ -136,7 +136,7 @@ void CliCall::WritesDoneAndWait() { call_->WritesDone(tag(4)); write_done_ = false; while (!write_done_) { - gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_cv_wait(&write_cv_, &write_mu_, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&write_mu_); } -- cgit v1.2.3 From ad4d2dde0052efbbf49d64b0843c45f0381cfeb3 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 6 Dec 2017 09:05:05 -0800 Subject: Revert "All instances of exec_ctx being passed around in src/core removed" --- include/grpc++/support/channel_arguments.h | 2 +- include/grpc/impl/codegen/grpc_types.h | 2 +- include/grpc/impl/codegen/slice.h | 2 +- include/grpc/slice_buffer.h | 3 +- include/grpc/support/tls.h | 6 - include/grpc/support/tls_gcc.h | 5 - include/grpc/support/tls_msvc.h | 9 - include/grpc/support/tls_pthread.h | 9 - .../ext/filters/client_channel/backup_poller.cc | 47 +- .../ext/filters/client_channel/backup_poller.h | 4 +- .../filters/client_channel/channel_connectivity.cc | 52 +- .../ext/filters/client_channel/client_channel.cc | 409 ++++---- .../ext/filters/client_channel/client_channel.h | 8 +- .../client_channel/client_channel_factory.cc | 23 +- .../client_channel/client_channel_factory.h | 19 +- .../client_channel/client_channel_plugin.cc | 13 +- src/core/ext/filters/client_channel/connector.cc | 13 +- src/core/ext/filters/client_channel/connector.h | 14 +- .../client_channel/http_connect_handshaker.cc | 84 +- src/core/ext/filters/client_channel/http_proxy.cc | 18 +- src/core/ext/filters/client_channel/lb_policy.cc | 79 +- src/core/ext/filters/client_channel/lb_policy.h | 80 +- .../grpclb/client_load_reporting_filter.cc | 27 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 434 ++++---- .../lb_policy/grpclb/grpclb_channel.cc | 6 +- .../lb_policy/grpclb/grpclb_channel.h | 4 +- .../lb_policy/grpclb/grpclb_channel_secure.cc | 10 +- .../lb_policy/pick_first/pick_first.cc | 190 ++-- .../lb_policy/round_robin/round_robin.cc | 140 +-- .../client_channel/lb_policy/subchannel_list.cc | 54 +- .../client_channel/lb_policy/subchannel_list.h | 18 +- .../filters/client_channel/lb_policy_factory.cc | 15 +- .../ext/filters/client_channel/lb_policy_factory.h | 11 +- .../filters/client_channel/lb_policy_registry.cc | 4 +- .../filters/client_channel/lb_policy_registry.h | 2 +- .../ext/filters/client_channel/proxy_mapper.cc | 14 +- src/core/ext/filters/client_channel/proxy_mapper.h | 14 +- .../client_channel/proxy_mapper_registry.cc | 30 +- .../filters/client_channel/proxy_mapper_registry.h | 6 +- src/core/ext/filters/client_channel/resolver.cc | 24 +- src/core/ext/filters/client_channel/resolver.h | 31 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 94 +- .../resolver/dns/c_ares/grpc_ares_ev_driver.h | 6 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 52 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 70 +- .../resolver/dns/c_ares/grpc_ares_wrapper.h | 12 +- .../dns/c_ares/grpc_ares_wrapper_fallback.cc | 20 +- .../resolver/dns/native/dns_resolver.cc | 90 +- .../client_channel/resolver/fake/fake_resolver.cc | 52 +- .../client_channel/resolver/fake/fake_resolver.h | 2 +- .../resolver/sockaddr/sockaddr_resolver.cc | 55 +- .../ext/filters/client_channel/resolver_factory.cc | 5 +- .../ext/filters/client_channel/resolver_factory.h | 6 +- .../filters/client_channel/resolver_registry.cc | 27 +- .../ext/filters/client_channel/resolver_registry.h | 7 +- src/core/ext/filters/client_channel/subchannel.cc | 239 +++-- src/core/ext/filters/client_channel/subchannel.h | 75 +- .../ext/filters/client_channel/subchannel_index.cc | 63 +- .../ext/filters/client_channel/subchannel_index.h | 12 +- src/core/ext/filters/client_channel/uri_parser.cc | 28 +- src/core/ext/filters/client_channel/uri_parser.h | 3 +- src/core/ext/filters/deadline/deadline_filter.cc | 112 +- src/core/ext/filters/deadline/deadline_filter.h | 10 +- .../ext/filters/http/client/http_client_filter.cc | 125 ++- src/core/ext/filters/http/http_filters_plugin.cc | 6 +- .../message_compress/message_compress_filter.cc | 126 ++- .../ext/filters/http/server/http_server_filter.cc | 118 ++- .../load_reporting/server_load_reporting_filter.cc | 33 +- .../load_reporting/server_load_reporting_plugin.cc | 2 +- src/core/ext/filters/max_age/max_age_filter.cc | 101 +- .../filters/message_size/message_size_filter.cc | 36 +- .../workaround_cronet_compression_filter.cc | 23 +- .../transport/chttp2/client/chttp2_connector.cc | 70 +- .../chttp2/client/insecure/channel_create.cc | 32 +- .../chttp2/client/insecure/channel_create_posix.cc | 16 +- .../chttp2/client/secure/secure_channel_create.cc | 51 +- .../ext/transport/chttp2/server/chttp2_server.cc | 108 +- .../ext/transport/chttp2/server/chttp2_server.h | 3 +- .../chttp2/server/insecure/server_chttp2.cc | 6 +- .../chttp2/server/insecure/server_chttp2_posix.cc | 17 +- .../chttp2/server/secure/server_secure_chttp2.cc | 11 +- .../ext/transport/chttp2/transport/bin_decoder.cc | 14 +- .../ext/transport/chttp2/transport/bin_decoder.h | 5 +- .../ext/transport/chttp2/transport/bin_encoder.h | 2 +- .../transport/chttp2/transport/chttp2_transport.cc | 1088 +++++++++++--------- .../transport/chttp2/transport/chttp2_transport.h | 7 +- .../ext/transport/chttp2/transport/flow_control.cc | 15 +- .../ext/transport/chttp2/transport/flow_control.h | 7 +- .../ext/transport/chttp2/transport/frame_data.cc | 62 +- .../ext/transport/chttp2/transport/frame_data.h | 7 +- .../ext/transport/chttp2/transport/frame_goaway.cc | 5 +- .../ext/transport/chttp2/transport/frame_goaway.h | 3 +- .../ext/transport/chttp2/transport/frame_ping.cc | 11 +- .../ext/transport/chttp2/transport/frame_ping.h | 2 +- .../transport/chttp2/transport/frame_rst_stream.cc | 5 +- .../transport/chttp2/transport/frame_rst_stream.h | 3 +- .../transport/chttp2/transport/frame_settings.cc | 5 +- .../transport/chttp2/transport/frame_settings.h | 3 +- .../chttp2/transport/frame_window_update.cc | 16 +- .../chttp2/transport/frame_window_update.h | 8 +- .../transport/chttp2/transport/hpack_encoder.cc | 144 +-- .../ext/transport/chttp2/transport/hpack_encoder.h | 6 +- .../ext/transport/chttp2/transport/hpack_parser.cc | 546 ++++++---- .../ext/transport/chttp2/transport/hpack_parser.h | 17 +- .../ext/transport/chttp2/transport/hpack_table.cc | 32 +- .../ext/transport/chttp2/transport/hpack_table.h | 13 +- .../chttp2/transport/incoming_metadata.cc | 19 +- .../transport/chttp2/transport/incoming_metadata.h | 9 +- src/core/ext/transport/chttp2/transport/internal.h | 106 +- src/core/ext/transport/chttp2/transport/parsing.cc | 185 ++-- src/core/ext/transport/chttp2/transport/writing.cc | 121 +-- .../cronet/client/secure/cronet_channel_create.cc | 5 +- .../transport/cronet/transport/cronet_transport.cc | 173 ++-- src/core/ext/transport/inproc/inproc_transport.cc | 342 +++--- src/core/lib/backoff/backoff.cc | 10 +- src/core/lib/backoff/backoff.h | 6 +- src/core/lib/channel/channel_args.cc | 16 +- src/core/lib/channel/channel_args.h | 9 +- src/core/lib/channel/channel_stack.cc | 46 +- src/core/lib/channel/channel_stack.h | 64 +- src/core/lib/channel/channel_stack_builder.cc | 25 +- src/core/lib/channel/channel_stack_builder.h | 11 +- src/core/lib/channel/connected_channel.cc | 57 +- src/core/lib/channel/connected_channel.h | 3 +- src/core/lib/channel/handshaker.cc | 77 +- src/core/lib/channel/handshaker.h | 33 +- src/core/lib/channel/handshaker_factory.cc | 12 +- src/core/lib/channel/handshaker_factory.h | 12 +- src/core/lib/channel/handshaker_registry.cc | 22 +- src/core/lib/channel/handshaker_registry.h | 5 +- src/core/lib/compression/message_compress.cc | 42 +- src/core/lib/compression/message_compress.h | 6 +- .../lib/compression/stream_compression_gzip.cc | 20 +- src/core/lib/debug/stats.cc | 6 +- src/core/lib/debug/stats.h | 20 +- src/core/lib/debug/stats_data.cc | 201 ++-- src/core/lib/debug/stats_data.h | 540 +++++----- src/core/lib/http/httpcli.cc | 127 ++- src/core/lib/http/httpcli.h | 27 +- src/core/lib/http/httpcli_security_connector.cc | 55 +- src/core/lib/iomgr/block_annotate.h | 19 +- src/core/lib/iomgr/call_combiner.cc | 31 +- src/core/lib/iomgr/call_combiner.h | 40 +- src/core/lib/iomgr/closure.h | 58 +- src/core/lib/iomgr/combiner.cc | 128 +-- src/core/lib/iomgr/combiner.h | 12 +- src/core/lib/iomgr/endpoint.cc | 36 +- src/core/lib/iomgr/endpoint.h | 41 +- src/core/lib/iomgr/endpoint_pair_posix.cc | 7 +- src/core/lib/iomgr/endpoint_pair_windows.cc | 10 +- src/core/lib/iomgr/error.cc | 6 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 196 ++-- src/core/lib/iomgr/ev_epollex_linux.cc | 238 +++-- src/core/lib/iomgr/ev_epollsig_linux.cc | 180 ++-- src/core/lib/iomgr/ev_poll_posix.cc | 199 ++-- src/core/lib/iomgr/ev_posix.cc | 80 +- src/core/lib/iomgr/ev_posix.h | 72 +- src/core/lib/iomgr/exec_ctx.cc | 124 ++- src/core/lib/iomgr/exec_ctx.h | 182 +--- src/core/lib/iomgr/executor.cc | 58 +- src/core/lib/iomgr/executor.h | 6 +- src/core/lib/iomgr/fork_posix.cc | 17 +- src/core/lib/iomgr/iocp_windows.cc | 30 +- src/core/lib/iomgr/iocp_windows.h | 3 +- src/core/lib/iomgr/iomgr.cc | 115 +-- src/core/lib/iomgr/iomgr.h | 6 +- src/core/lib/iomgr/iomgr_uv.cc | 5 +- src/core/lib/iomgr/lockfree_event.cc | 15 +- src/core/lib/iomgr/lockfree_event.h | 6 +- src/core/lib/iomgr/polling_entity.cc | 16 +- src/core/lib/iomgr/polling_entity.h | 6 +- src/core/lib/iomgr/pollset.h | 9 +- src/core/lib/iomgr/pollset_set.h | 15 +- src/core/lib/iomgr/pollset_set_uv.cc | 15 +- src/core/lib/iomgr/pollset_set_windows.cc | 15 +- src/core/lib/iomgr/pollset_uv.cc | 17 +- src/core/lib/iomgr/pollset_windows.cc | 29 +- src/core/lib/iomgr/resolve_address.h | 3 +- src/core/lib/iomgr/resolve_address_posix.cc | 20 +- src/core/lib/iomgr/resolve_address_uv.cc | 15 +- src/core/lib/iomgr/resolve_address_windows.cc | 15 +- src/core/lib/iomgr/resource_quota.cc | 182 ++-- src/core/lib/iomgr/resource_quota.h | 25 +- src/core/lib/iomgr/socket_factory_posix.cc | 2 +- src/core/lib/iomgr/socket_mutator.cc | 2 +- src/core/lib/iomgr/socket_windows.cc | 19 +- src/core/lib/iomgr/socket_windows.h | 9 +- src/core/lib/iomgr/tcp_client.h | 3 +- src/core/lib/iomgr/tcp_client_posix.cc | 64 +- src/core/lib/iomgr/tcp_client_posix.h | 3 +- src/core/lib/iomgr/tcp_client_uv.cc | 37 +- src/core/lib/iomgr/tcp_client_windows.cc | 45 +- src/core/lib/iomgr/tcp_posix.cc | 262 ++--- src/core/lib/iomgr/tcp_posix.h | 7 +- src/core/lib/iomgr/tcp_server.h | 15 +- src/core/lib/iomgr/tcp_server_posix.cc | 64 +- src/core/lib/iomgr/tcp_server_uv.cc | 57 +- src/core/lib/iomgr/tcp_server_windows.cc | 58 +- src/core/lib/iomgr/tcp_uv.cc | 99 +- src/core/lib/iomgr/tcp_windows.cc | 93 +- src/core/lib/iomgr/tcp_windows.h | 2 +- src/core/lib/iomgr/timer.h | 13 +- src/core/lib/iomgr/timer_generic.cc | 47 +- src/core/lib/iomgr/timer_manager.cc | 30 +- src/core/lib/iomgr/timer_uv.cc | 26 +- src/core/lib/iomgr/udp_server.cc | 83 +- src/core/lib/iomgr/udp_server.h | 17 +- src/core/lib/security/context/security_context.cc | 17 +- .../credentials/composite/composite_credentials.cc | 51 +- src/core/lib/security/credentials/credentials.cc | 73 +- src/core/lib/security/credentials/credentials.h | 59 +- .../security/credentials/credentials_metadata.cc | 4 +- .../security/credentials/fake/fake_credentials.cc | 36 +- .../google_default/google_default_credentials.cc | 58 +- .../security/credentials/iam/iam_credentials.cc | 22 +- .../security/credentials/jwt/jwt_credentials.cc | 34 +- .../lib/security/credentials/jwt/jwt_credentials.h | 3 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 126 ++- .../lib/security/credentials/jwt/jwt_verifier.h | 14 +- .../credentials/oauth2/oauth2_credentials.cc | 102 +- .../credentials/oauth2/oauth2_credentials.h | 7 +- .../credentials/plugin/plugin_credentials.cc | 51 +- .../security/credentials/ssl/ssl_credentials.cc | 21 +- .../lib/security/transport/client_auth_filter.cc | 85 +- src/core/lib/security/transport/lb_targets_info.cc | 4 +- src/core/lib/security/transport/secure_endpoint.cc | 120 ++- .../lib/security/transport/security_connector.cc | 144 +-- .../lib/security/transport/security_connector.h | 53 +- .../lib/security/transport/security_handshaker.cc | 189 ++-- .../lib/security/transport/security_handshaker.h | 3 +- .../lib/security/transport/server_auth_filter.cc | 55 +- src/core/lib/slice/b64.cc | 11 +- src/core/lib/slice/b64.h | 7 +- src/core/lib/slice/slice.cc | 17 +- src/core/lib/slice/slice_buffer.cc | 27 +- src/core/lib/slice/slice_hash_table.cc | 12 +- src/core/lib/slice/slice_hash_table.h | 6 +- src/core/lib/slice/slice_intern.cc | 7 +- src/core/lib/slice/slice_internal.h | 11 +- src/core/lib/surface/alarm.cc | 25 +- src/core/lib/surface/byte_buffer.cc | 5 +- src/core/lib/surface/byte_buffer_reader.cc | 16 +- src/core/lib/surface/call.cc | 429 ++++---- src/core/lib/surface/call.h | 24 +- src/core/lib/surface/call_details.cc | 7 +- src/core/lib/surface/channel.cc | 115 ++- src/core/lib/surface/channel.h | 27 +- src/core/lib/surface/channel_init.cc | 5 +- src/core/lib/surface/channel_init.h | 6 +- src/core/lib/surface/channel_ping.cc | 14 +- src/core/lib/surface/completion_queue.cc | 328 +++--- src/core/lib/surface/completion_queue.h | 21 +- src/core/lib/surface/init.cc | 51 +- src/core/lib/surface/init_secure.cc | 4 +- src/core/lib/surface/lame_client.cc | 53 +- src/core/lib/surface/server.cc | 322 +++--- src/core/lib/surface/server.h | 15 +- src/core/lib/transport/bdp_estimator.cc | 4 +- src/core/lib/transport/bdp_estimator.h | 2 +- src/core/lib/transport/byte_stream.cc | 62 +- src/core/lib/transport/byte_stream.h | 27 +- src/core/lib/transport/connectivity_state.cc | 22 +- src/core/lib/transport/connectivity_state.h | 10 +- src/core/lib/transport/error_utils.cc | 10 +- src/core/lib/transport/error_utils.h | 5 +- src/core/lib/transport/metadata.cc | 40 +- src/core/lib/transport/metadata.h | 20 +- src/core/lib/transport/metadata_batch.cc | 79 +- src/core/lib/transport/metadata_batch.h | 42 +- src/core/lib/transport/service_config.cc | 24 +- src/core/lib/transport/service_config.h | 8 +- src/core/lib/transport/static_metadata.cc | 2 +- src/core/lib/transport/status_conversion.cc | 5 +- src/core/lib/transport/status_conversion.h | 3 +- src/core/lib/transport/transport.cc | 84 +- src/core/lib/transport/transport.h | 33 +- src/core/lib/transport/transport_impl.h | 27 +- src/core/tsi/fake_transport_security.cc | 17 +- src/core/tsi/transport_security.h | 2 +- src/core/tsi/transport_security_grpc.cc | 29 +- src/core/tsi/transport_security_grpc.h | 22 +- src/cpp/common/channel_arguments.cc | 11 +- src/cpp/common/channel_filter.cc | 29 +- src/cpp/common/channel_filter.h | 62 +- .../CoreCronetEnd2EndTests.mm | 5 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 2 +- test/core/backoff/backoff_test.cc | 99 +- test/core/bad_client/bad_client.cc | 49 +- test/core/bad_client/tests/badreq.cc | 4 - test/core/bad_client/tests/connection_prefix.cc | 3 - .../core/bad_client/tests/head_of_line_blocking.cc | 3 - test/core/bad_client/tests/headers.cc | 2 - .../bad_client/tests/initial_settings_frame.cc | 2 - .../bad_client/tests/server_registered_method.cc | 2 - test/core/bad_client/tests/simple_request.cc | 4 - test/core/bad_client/tests/unknown_frame.cc | 2 - test/core/bad_client/tests/window_overflow.cc | 3 - test/core/channel/channel_args_test.cc | 26 +- test/core/channel/channel_stack_builder_test.cc | 24 +- test/core/channel/channel_stack_test.cc | 45 +- test/core/channel/minimal_stack_is_minimal_test.cc | 15 +- test/core/client_channel/lb_policies_test.cc | 14 +- test/core/client_channel/parse_address_test.cc | 19 +- .../resolvers/dns_resolver_connectivity_test.cc | 85 +- .../client_channel/resolvers/dns_resolver_test.cc | 21 +- .../client_channel/resolvers/fake_resolver_test.cc | 54 +- .../resolvers/sockaddr_resolver_test.cc | 28 +- test/core/client_channel/uri_fuzzer_test.cc | 19 +- test/core/client_channel/uri_parser_test.cc | 31 +- test/core/compression/algorithm_test.cc | 12 +- test/core/compression/message_compress_test.cc | 62 +- test/core/debug/stats_test.cc | 15 +- test/core/end2end/bad_server_response_test.cc | 37 +- test/core/end2end/connection_refused_test.cc | 5 +- test/core/end2end/fixtures/h2_census.cc | 10 +- test/core/end2end/fixtures/h2_compress.cc | 17 +- test/core/end2end/fixtures/h2_fd.cc | 8 +- test/core/end2end/fixtures/h2_full+workarounds.cc | 5 +- test/core/end2end/fixtures/h2_load_reporting.cc | 5 +- test/core/end2end/fixtures/h2_oauth2.cc | 7 +- test/core/end2end/fixtures/h2_sockpair+trace.cc | 35 +- test/core/end2end/fixtures/h2_sockpair.cc | 33 +- test/core/end2end/fixtures/h2_sockpair_1byte.cc | 33 +- test/core/end2end/fixtures/h2_ssl.cc | 5 +- test/core/end2end/fixtures/h2_ssl_proxy.cc | 10 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 192 ++-- test/core/end2end/fuzzers/api_fuzzer.cc | 83 +- test/core/end2end/fuzzers/client_fuzzer.cc | 210 ++-- test/core/end2end/fuzzers/server_fuzzer.cc | 135 ++- test/core/end2end/goaway_server_test.cc | 28 +- test/core/end2end/h2_ssl_cert_test.cc | 5 +- test/core/end2end/tests/cancel_after_accept.cc | 5 +- test/core/end2end/tests/cancel_after_round_trip.cc | 5 +- test/core/end2end/tests/compressed_payload.cc | 19 +- test/core/end2end/tests/filter_call_init_fails.cc | 19 +- test/core/end2end/tests/filter_causes_close.cc | 24 +- test/core/end2end/tests/filter_latency.cc | 18 +- test/core/end2end/tests/load_reporting_hook.cc | 5 +- test/core/end2end/tests/max_message_length.cc | 18 +- .../tests/stream_compression_compressed_payload.cc | 19 +- .../end2end/tests/stream_compression_payload.cc | 7 +- .../stream_compression_ping_pong_streaming.cc | 7 +- .../end2end/tests/workaround_cronet_compression.cc | 12 +- .../handshake/readahead_handshaker_server_ssl.cc | 24 +- test/core/http/format_request_test.cc | 2 - test/core/http/httpcli_test.cc | 146 +-- test/core/http/httpscli_test.cc | 52 +- test/core/http/parser_test.cc | 3 - test/core/http/request_fuzzer.cc | 3 - test/core/http/response_fuzzer.cc | 3 - test/core/iomgr/combiner_test.cc | 51 +- test/core/iomgr/endpoint_pair_test.cc | 29 +- test/core/iomgr/endpoint_tests.cc | 99 +- test/core/iomgr/ev_epollsig_linux_test.cc | 109 +- test/core/iomgr/fd_conservation_posix_test.cc | 37 +- test/core/iomgr/fd_posix_test.cc | 156 +-- test/core/iomgr/load_file_test.cc | 3 - test/core/iomgr/pollset_set_test.cc | 245 ++--- test/core/iomgr/resolve_address_posix_test.cc | 65 +- test/core/iomgr/resolve_address_test.cc | 153 +-- test/core/iomgr/resource_quota_test.cc | 354 ++++--- test/core/iomgr/tcp_client_posix_test.cc | 83 +- test/core/iomgr/tcp_client_uv_test.cc | 62 +- test/core/iomgr/tcp_posix_test.cc | 153 +-- test/core/iomgr/tcp_server_posix_test.cc | 183 ++-- test/core/iomgr/tcp_server_uv_test.cc | 90 +- test/core/iomgr/timer_list_test.cc | 75 +- test/core/iomgr/udp_server_test.cc | 105 +- test/core/nanopb/fuzzer_response.cc | 3 - test/core/nanopb/fuzzer_serverlist.cc | 3 - test/core/security/credentials_test.cc | 303 +++--- test/core/security/json_token_test.cc | 16 +- test/core/security/jwt_verifier_test.cc | 146 +-- test/core/security/oauth2_utils.cc | 30 +- .../security/print_google_default_creds_token.cc | 22 +- test/core/security/secure_endpoint_test.cc | 67 +- test/core/security/ssl_server_fuzzer.cc | 124 ++- test/core/security/verify_jwt.cc | 23 +- test/core/slice/b64_test.cc | 46 +- test/core/slice/percent_decode_fuzzer.cc | 3 - test/core/slice/percent_encode_fuzzer.cc | 3 - test/core/slice/percent_encoding_test.cc | 3 - test/core/slice/slice_buffer_test.cc | 3 - test/core/slice/slice_hash_table_test.cc | 39 +- test/core/slice/slice_string_helpers_test.cc | 3 - test/core/slice/slice_test.cc | 2 - test/core/surface/byte_buffer_reader_test.cc | 8 +- test/core/surface/channel_create_test.cc | 3 +- test/core/surface/completion_queue_test.cc | 39 +- .../surface/completion_queue_threading_test.cc | 19 +- test/core/surface/concurrent_connectivity_test.cc | 41 +- test/core/surface/lame_client_test.cc | 13 +- .../num_external_connectivity_watchers_test.cc | 5 +- test/core/surface/secure_channel_create_test.cc | 17 +- test/core/surface/sequential_connectivity_test.cc | 5 +- test/core/transport/bdp_estimator_test.cc | 7 +- test/core/transport/byte_stream_test.cc | 113 +- test/core/transport/chttp2/bin_decoder_test.cc | 158 +-- test/core/transport/chttp2/bin_encoder_test.cc | 3 - test/core/transport/chttp2/hpack_encoder_test.cc | 91 +- .../transport/chttp2/hpack_parser_fuzzer_test.cc | 19 +- test/core/transport/chttp2/hpack_parser_test.cc | 41 +- test/core/transport/chttp2/hpack_table_test.cc | 72 +- .../core/transport/chttp2/settings_timeout_test.cc | 55 +- test/core/transport/chttp2/varint_test.cc | 3 - test/core/transport/connectivity_state_test.cc | 51 +- test/core/transport/metadata_test.cc | 137 +-- test/core/transport/status_conversion_test.cc | 11 +- test/core/transport/stream_owned_slice_test.cc | 5 +- test/core/util/mock_endpoint.cc | 36 +- test/core/util/mock_endpoint.h | 3 +- test/core/util/one_corpus_entry_fuzzer.cc | 8 - test/core/util/passthru_endpoint.cc | 45 +- test/core/util/port_server_client.cc | 130 +-- test/core/util/reconnect_server.cc | 6 +- test/core/util/test_tcp_server.cc | 36 +- test/core/util/trickle_endpoint.cc | 56 +- test/core/util/trickle_endpoint.h | 3 +- test/cpp/client/client_channel_stress_test.cc | 11 +- test/cpp/common/channel_arguments_test.cc | 5 +- test/cpp/common/channel_filter_test.cc | 4 +- test/cpp/end2end/client_lb_end2end_test.cc | 13 +- test/cpp/end2end/filter_end2end_test.cc | 7 +- test/cpp/end2end/grpclb_end2end_test.cc | 11 +- test/cpp/grpclb/grpclb_api_test.cc | 6 +- test/cpp/grpclb/grpclb_test.cc | 17 +- test/cpp/microbenchmarks/bm_call_create.cc | 139 +-- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 136 +-- test/cpp/microbenchmarks/bm_chttp2_transport.cc | 270 ++--- test/cpp/microbenchmarks/bm_closure.cc | 196 ++-- test/cpp/microbenchmarks/bm_cq.cc | 26 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 22 +- test/cpp/microbenchmarks/bm_error.cc | 24 +- test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 8 +- test/cpp/microbenchmarks/bm_metadata.cc | 115 ++- test/cpp/microbenchmarks/bm_pollset.cc | 53 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 27 +- test/cpp/naming/resolver_component_test.cc | 50 +- test/cpp/performance/writes_per_rpc_test.cc | 24 +- test/cpp/server/server_builder_test.cc | 7 +- test/cpp/util/byte_buffer_test.cc | 6 +- test/cpp/util/slice_test.cc | 6 +- tools/codegen/core/gen_static_metadata.py | 2 +- tools/codegen/core/gen_stats_data.py | 24 +- 444 files changed, 12454 insertions(+), 10022 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h index c9879d8a28..9dc505f008 100644 --- a/include/grpc++/support/channel_arguments.h +++ b/include/grpc++/support/channel_arguments.h @@ -122,7 +122,7 @@ class ChannelArguments { /// Default pointer argument operations. struct PointerVtableMembers { static void* Copy(void* in) { return in; } - static void Destroy(void* in) {} + static void Destroy(grpc_exec_ctx* exec_ctx, void* in) {} static int Compare(void* a, void* b) { if (a < b) return -1; if (a > b) return 1; diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index fcbc8ac5a1..77844aa2af 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -85,7 +85,7 @@ typedef enum { typedef struct grpc_arg_pointer_vtable { void* (*copy)(void* p); - void (*destroy)(void* p); + void (*destroy)(grpc_exec_ctx* exec_ctx, void* p); int (*cmp)(void* p, void* q); } grpc_arg_pointer_vtable; diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index ad026b685e..11997fcb56 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -43,7 +43,7 @@ typedef struct grpc_slice grpc_slice; typedef struct grpc_slice_refcount_vtable { void (*ref)(void*); - void (*unref)(void*); + void (*unref)(grpc_exec_ctx* exec_ctx, void*); int (*eq)(grpc_slice a, grpc_slice b); uint32_t (*hash)(grpc_slice slice); } grpc_slice_refcount_vtable; diff --git a/include/grpc/slice_buffer.h b/include/grpc/slice_buffer.h index 30833d02db..6510c151b3 100644 --- a/include/grpc/slice_buffer.h +++ b/include/grpc/slice_buffer.h @@ -67,7 +67,8 @@ GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, grpc_slice_buffer* dst); /** move the first n bytes of src into dst (copying them) */ -GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, +GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* src, size_t n, void* dst); /** take the first slice in the slice buffer */ GPRAPI grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* src); diff --git a/include/grpc/support/tls.h b/include/grpc/support/tls.h index 4c9e79b6cf..8519a8350b 100644 --- a/include/grpc/support/tls.h +++ b/include/grpc/support/tls.h @@ -32,12 +32,6 @@ GPR_TLS_DECL(foo); Thread locals always have static scope. - Declaring a thread local class variable 'foo': - GPR_TLS_CLASS_DECL(foo); - - Defining the thread local class variable: - GPR_TLS_CLASS_DEF(foo); - Initializing a thread local (must be done at library initialization time): gpr_tls_init(&foo); diff --git a/include/grpc/support/tls_gcc.h b/include/grpc/support/tls_gcc.h index b44f0f1c8c..1b91d22be1 100644 --- a/include/grpc/support/tls_gcc.h +++ b/include/grpc/support/tls_gcc.h @@ -33,11 +33,6 @@ struct gpr_gcc_thread_local { #define GPR_TLS_DECL(name) \ static __thread struct gpr_gcc_thread_local name = {0} -#define GPR_TLS_CLASS_DECL(name) \ - static __thread struct gpr_gcc_thread_local name - -#define GPR_TLS_CLASS_DEF(name) __thread struct gpr_gcc_thread_local name = {0} - #define gpr_tls_init(tls) \ do { \ } while (0) diff --git a/include/grpc/support/tls_msvc.h b/include/grpc/support/tls_msvc.h index 68a411f5d4..e5f2205fc1 100644 --- a/include/grpc/support/tls_msvc.h +++ b/include/grpc/support/tls_msvc.h @@ -26,18 +26,9 @@ struct gpr_msvc_thread_local { intptr_t value; }; -/** Use GPR_TLS_DECL to declare tls static variables outside a class */ #define GPR_TLS_DECL(name) \ static __declspec(thread) struct gpr_msvc_thread_local name = {0} -/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DECL(name) \ - static __declspec(thread) struct gpr_msvc_thread_local name - -#define GPR_TLS_CLASS_DEF(name) \ - __declspec(thread) struct gpr_msvc_thread_local name = {0} - #define gpr_tls_init(tls) \ do { \ } while (0) diff --git a/include/grpc/support/tls_pthread.h b/include/grpc/support/tls_pthread.h index 249c8b16f8..fb0edd8e74 100644 --- a/include/grpc/support/tls_pthread.h +++ b/include/grpc/support/tls_pthread.h @@ -29,17 +29,8 @@ struct gpr_pthread_thread_local { pthread_key_t key; }; -/** Use GPR_TLS_DECL to declare tls static variables outside a class */ #define GPR_TLS_DECL(name) static struct gpr_pthread_thread_local name = {0} -/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DECL(name) static struct gpr_pthread_thread_local name - -/** Use GPR_TLS_CLASS_DEF to declare tls static variable members of a class. - * GPR_TLS_CLASS_DEF needs to be called to define this member. */ -#define GPR_TLS_CLASS_DEF(name) struct gpr_pthread_thread_local name = {0} - #define gpr_tls_init(tls) GPR_ASSERT(0 == pthread_key_create(&(tls)->key, NULL)) #define gpr_tls_destroy(tls) pthread_key_delete((tls)->key) #define gpr_tls_get(tls) ((intptr_t)pthread_getspecific((tls)->key)) diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 339a79b0fb..ed437d255c 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -69,19 +69,20 @@ static void init_globals() { gpr_free(env); } -static void backup_poller_shutdown_unref(backup_poller* p) { +static void backup_poller_shutdown_unref(grpc_exec_ctx* exec_ctx, + backup_poller* p) { if (gpr_unref(&p->shutdown_refs)) { - grpc_pollset_destroy(p->pollset); + grpc_pollset_destroy(exec_ctx, p->pollset); gpr_free(p->pollset); gpr_free(p); } } -static void done_poller(void* arg, grpc_error* error) { - backup_poller_shutdown_unref((backup_poller*)arg); +static void done_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + backup_poller_shutdown_unref(exec_ctx, (backup_poller*)arg); } -static void g_poller_unref() { +static void g_poller_unref(grpc_exec_ctx* exec_ctx) { if (gpr_unref(&g_poller->refs)) { gpr_mu_lock(&g_poller_mu); backup_poller* p = g_poller; @@ -89,40 +90,40 @@ static void g_poller_unref() { gpr_mu_unlock(&g_poller_mu); gpr_mu_lock(p->pollset_mu); p->shutting_down = true; - grpc_pollset_shutdown( - p->pollset, GRPC_CLOSURE_INIT(&p->shutdown_closure, done_poller, p, - grpc_schedule_on_exec_ctx)); + grpc_pollset_shutdown(exec_ctx, p->pollset, + GRPC_CLOSURE_INIT(&p->shutdown_closure, done_poller, + p, grpc_schedule_on_exec_ctx)); gpr_mu_unlock(p->pollset_mu); - grpc_timer_cancel(&p->polling_timer); + grpc_timer_cancel(exec_ctx, &p->polling_timer); } } -static void run_poller(void* arg, grpc_error* error) { +static void run_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { backup_poller* p = (backup_poller*)arg; if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("run_poller", GRPC_ERROR_REF(error)); } - backup_poller_shutdown_unref(p); + backup_poller_shutdown_unref(exec_ctx, p); return; } gpr_mu_lock(p->pollset_mu); if (p->shutting_down) { gpr_mu_unlock(p->pollset_mu); - backup_poller_shutdown_unref(p); + backup_poller_shutdown_unref(exec_ctx, p); return; } - grpc_error* err = - grpc_pollset_work(p->pollset, nullptr, grpc_core::ExecCtx::Get()->Now()); + grpc_error* err = grpc_pollset_work(exec_ctx, p->pollset, nullptr, + grpc_exec_ctx_now(exec_ctx)); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); - grpc_timer_init(&p->polling_timer, - grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, + grpc_timer_init(exec_ctx, &p->polling_timer, + grpc_exec_ctx_now(exec_ctx) + g_poll_interval_ms, &p->run_poller_closure); } void grpc_client_channel_start_backup_polling( - grpc_pollset_set* interested_parties) { + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { gpr_once_init(&g_once, init_globals); if (g_poll_interval_ms == 0) { return; @@ -138,8 +139,8 @@ void grpc_client_channel_start_backup_polling( gpr_ref_init(&g_poller->shutdown_refs, 2); GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); - grpc_timer_init(&g_poller->polling_timer, - grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, + grpc_timer_init(exec_ctx, &g_poller->polling_timer, + grpc_exec_ctx_now(exec_ctx) + g_poll_interval_ms, &g_poller->run_poller_closure); } @@ -151,14 +152,14 @@ void grpc_client_channel_start_backup_polling( grpc_pollset* pollset = g_poller->pollset; gpr_mu_unlock(&g_poller_mu); - grpc_pollset_set_add_pollset(interested_parties, pollset); + grpc_pollset_set_add_pollset(exec_ctx, interested_parties, pollset); } void grpc_client_channel_stop_backup_polling( - grpc_pollset_set* interested_parties) { + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { if (g_poll_interval_ms == 0) { return; } - grpc_pollset_set_del_pollset(interested_parties, g_poller->pollset); - g_poller_unref(); + grpc_pollset_set_del_pollset(exec_ctx, interested_parties, g_poller->pollset); + g_poller_unref(exec_ctx); } diff --git a/src/core/ext/filters/client_channel/backup_poller.h b/src/core/ext/filters/client_channel/backup_poller.h index 551e0331dc..e993d50639 100644 --- a/src/core/ext/filters/client_channel/backup_poller.h +++ b/src/core/ext/filters/client_channel/backup_poller.h @@ -25,10 +25,10 @@ /* Start polling \a interested_parties periodically in the timer thread */ void grpc_client_channel_start_backup_polling( - grpc_pollset_set* interested_parties); + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); /* Stop polling \a interested_parties */ void grpc_client_channel_stop_backup_polling( - grpc_pollset_set* interested_parties); + grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_BACKUP_POLLER_H */ diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 20693ba419..7eaf5d98cd 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -33,22 +33,22 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( /* forward through to the underlying client channel */ grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_connectivity_state state; GRPC_API_TRACE( "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, (channel, try_to_connect)); if (client_channel_elem->filter == &grpc_client_channel_filter) { - state = grpc_client_channel_check_connectivity_state(client_channel_elem, - try_to_connect); - + state = grpc_client_channel_check_connectivity_state( + &exec_ctx, client_channel_elem, try_to_connect); + grpc_exec_ctx_finish(&exec_ctx); return state; } gpr_log(GPR_ERROR, "grpc_channel_check_connectivity_state called on something that is " "not a client channel, but '%s'", client_channel_elem->filter->name); - + grpc_exec_ctx_finish(&exec_ctx); return GRPC_CHANNEL_SHUTDOWN; } @@ -73,11 +73,12 @@ typedef struct { void* tag; } state_watcher; -static void delete_state_watcher(state_watcher* w) { +static void delete_state_watcher(grpc_exec_ctx* exec_ctx, state_watcher* w) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_UNREF(w->channel, "watch_channel_connectivity"); + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, + "watch_channel_connectivity"); } else { abort(); } @@ -85,7 +86,8 @@ static void delete_state_watcher(state_watcher* w) { gpr_free(w); } -static void finished_completion(void* pw, grpc_cq_completion* ignored) { +static void finished_completion(grpc_exec_ctx* exec_ctx, void* pw, + grpc_cq_completion* ignored) { bool should_delete = false; state_watcher* w = (state_watcher*)pw; gpr_mu_lock(&w->mu); @@ -100,19 +102,19 @@ static void finished_completion(void* pw, grpc_cq_completion* ignored) { gpr_mu_unlock(&w->mu); if (should_delete) { - delete_state_watcher(w); + delete_state_watcher(exec_ctx, w); } } -static void partly_done(state_watcher* w, bool due_to_completion, - grpc_error* error) { +static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, + bool due_to_completion, grpc_error* error) { if (due_to_completion) { - grpc_timer_cancel(&w->alarm); + grpc_timer_cancel(exec_ctx, &w->alarm); } else { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); grpc_client_channel_watch_connectivity_state( - client_channel_elem, + exec_ctx, client_channel_elem, grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), nullptr, &w->on_complete, nullptr); } @@ -147,7 +149,7 @@ static void partly_done(state_watcher* w, bool due_to_completion, w->error = error; } w->phase = CALLING_BACK_AND_FINISHED; - grpc_cq_end_op(w->cq, w->tag, w->error, finished_completion, w, + grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, &w->completion_storage); break; case CALLING_BACK_AND_FINISHED: @@ -159,12 +161,14 @@ static void partly_done(state_watcher* w, bool due_to_completion, GRPC_ERROR_UNREF(error); } -static void watch_complete(void* pw, grpc_error* error) { - partly_done((state_watcher*)pw, true, GRPC_ERROR_REF(error)); +static void watch_complete(grpc_exec_ctx* exec_ctx, void* pw, + grpc_error* error) { + partly_done(exec_ctx, (state_watcher*)pw, true, GRPC_ERROR_REF(error)); } -static void timeout_complete(void* pw, grpc_error* error) { - partly_done((state_watcher*)pw, false, GRPC_ERROR_REF(error)); +static void timeout_complete(grpc_exec_ctx* exec_ctx, void* pw, + grpc_error* error) { + partly_done(exec_ctx, (state_watcher*)pw, false, GRPC_ERROR_REF(error)); } int grpc_channel_num_external_connectivity_watchers(grpc_channel* channel) { @@ -179,10 +183,12 @@ typedef struct watcher_timer_init_arg { gpr_timespec deadline; } watcher_timer_init_arg; -static void watcher_timer_init(void* arg, grpc_error* error_ignored) { +static void watcher_timer_init(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { watcher_timer_init_arg* wa = (watcher_timer_init_arg*)arg; - grpc_timer_init(&wa->w->alarm, grpc_timespec_to_millis_round_up(wa->deadline), + grpc_timer_init(exec_ctx, &wa->w->alarm, + grpc_timespec_to_millis_round_up(wa->deadline), &wa->w->on_timeout); gpr_free(wa); } @@ -198,7 +204,7 @@ void grpc_channel_watch_connectivity_state( gpr_timespec deadline, grpc_completion_queue* cq, void* tag) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( @@ -235,10 +241,12 @@ void grpc_channel_watch_connectivity_state( if (client_channel_elem->filter == &grpc_client_channel_filter) { GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); grpc_client_channel_watch_connectivity_state( - client_channel_elem, + &exec_ctx, client_channel_elem, grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, &w->on_complete, &w->watcher_timer_init); } else { abort(); } + + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index ba82c88eb7..aced9adf9f 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -91,7 +91,8 @@ static void method_parameters_unref(method_parameters* method_params) { static void* method_parameters_ref_wrapper(void* value) { return method_parameters_ref((method_parameters*)value); } -static void method_parameters_unref_wrapper(void* value) { +static void method_parameters_unref_wrapper(grpc_exec_ctx* exec_ctx, + void* value) { method_parameters_unref((method_parameters*)value); } @@ -227,11 +228,12 @@ typedef struct { grpc_lb_policy* lb_policy; } lb_policy_connectivity_watcher; -static void watch_lb_policy_locked(channel_data* chand, +static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, grpc_lb_policy* lb_policy, grpc_connectivity_state current_state); -static void set_channel_connectivity_state_locked(channel_data* chand, +static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, + channel_data* chand, grpc_connectivity_state state, grpc_error* error, const char* reason) { @@ -243,12 +245,12 @@ static void set_channel_connectivity_state_locked(channel_data* chand, if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { /* cancel picks with wait_for_ready=false */ grpc_lb_policy_cancel_picks_locked( - chand->lb_policy, + exec_ctx, chand->lb_policy, /* mask= */ GRPC_INITIAL_METADATA_WAIT_FOR_READY, /* check= */ 0, GRPC_ERROR_REF(error)); } else if (state == GRPC_CHANNEL_SHUTDOWN) { /* cancel all picks */ - grpc_lb_policy_cancel_picks_locked(chand->lb_policy, + grpc_lb_policy_cancel_picks_locked(exec_ctx, chand->lb_policy, /* mask= */ 0, /* check= */ 0, GRPC_ERROR_REF(error)); } @@ -257,10 +259,12 @@ static void set_channel_connectivity_state_locked(channel_data* chand, gpr_log(GPR_DEBUG, "chand=%p: setting connectivity state to %s", chand, grpc_connectivity_state_name(state)); } - grpc_connectivity_state_set(&chand->state_tracker, state, error, reason); + grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state, error, + reason); } -static void on_lb_policy_state_changed_locked(void* arg, grpc_error* error) { +static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { lb_policy_connectivity_watcher* w = (lb_policy_connectivity_watcher*)arg; /* check if the notification is for the latest policy */ if (w->lb_policy == w->chand->lb_policy) { @@ -268,17 +272,17 @@ static void on_lb_policy_state_changed_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, w->lb_policy, grpc_connectivity_state_name(w->state)); } - set_channel_connectivity_state_locked(w->chand, w->state, + set_channel_connectivity_state_locked(exec_ctx, w->chand, w->state, GRPC_ERROR_REF(error), "lb_changed"); if (w->state != GRPC_CHANNEL_SHUTDOWN) { - watch_lb_policy_locked(w->chand, w->lb_policy, w->state); + watch_lb_policy_locked(exec_ctx, w->chand, w->lb_policy, w->state); } } - GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, "watch_lb_policy"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "watch_lb_policy"); gpr_free(w); } -static void watch_lb_policy_locked(channel_data* chand, +static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, grpc_lb_policy* lb_policy, grpc_connectivity_state current_state) { lb_policy_connectivity_watcher* w = @@ -289,18 +293,19 @@ static void watch_lb_policy_locked(channel_data* chand, grpc_combiner_scheduler(chand->combiner)); w->state = current_state; w->lb_policy = lb_policy; - grpc_lb_policy_notify_on_state_change_locked(lb_policy, &w->state, + grpc_lb_policy_notify_on_state_change_locked(exec_ctx, lb_policy, &w->state, &w->on_changed); } -static void start_resolving_locked(channel_data* chand) { +static void start_resolving_locked(grpc_exec_ctx* exec_ctx, + channel_data* chand) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand); } GPR_ASSERT(!chand->started_resolving); chand->started_resolving = true; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next_locked(chand->resolver, &chand->resolver_result, + grpc_resolver_next_locked(exec_ctx, chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } @@ -364,26 +369,29 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { } } -static void request_reresolution_locked(void* arg, grpc_error* error) { +static void request_reresolution_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { reresolution_request_args* args = (reresolution_request_args*)arg; channel_data* chand = args->chand; // If this invocation is for a stale LB policy, treat it as an LB shutdown // signal. if (args->lb_policy != chand->lb_policy || error != GRPC_ERROR_NONE || chand->resolver == nullptr) { - GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "re-resolution"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "re-resolution"); gpr_free(args); return; } if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: started name re-resolving", chand); } - grpc_resolver_channel_saw_error_locked(chand->resolver); + grpc_resolver_channel_saw_error_locked(exec_ctx, chand->resolver); // Give back the closure to the LB policy. - grpc_lb_policy_set_reresolve_closure_locked(chand->lb_policy, &args->closure); + grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, chand->lb_policy, + &args->closure); } -static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { +static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, @@ -450,10 +458,12 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { if (chand->lb_policy != nullptr && !lb_policy_name_changed) { // Continue using the same LB policy. Update with new addresses. lb_policy_updated = true; - grpc_lb_policy_update_locked(chand->lb_policy, &lb_policy_args); + grpc_lb_policy_update_locked(exec_ctx, chand->lb_policy, + &lb_policy_args); } else { // Instantiate new LB policy. - new_lb_policy = grpc_lb_policy_create(lb_policy_name, &lb_policy_args); + new_lb_policy = + grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); if (new_lb_policy == nullptr) { gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", lb_policy_name); @@ -465,7 +475,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { GRPC_CLOSURE_INIT(&args->closure, request_reresolution_locked, args, grpc_combiner_scheduler(chand->combiner)); GRPC_CHANNEL_STACK_REF(chand->owning_stack, "re-resolution"); - grpc_lb_policy_set_reresolve_closure_locked(new_lb_policy, + grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, new_lb_policy, &args->closure); } } @@ -482,7 +492,8 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { GRPC_ARG_SERVER_URI); GPR_ASSERT(channel_arg != nullptr); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); - grpc_uri* uri = grpc_uri_parse(channel_arg->value.string, true); + grpc_uri* uri = + grpc_uri_parse(exec_ctx, channel_arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); service_config_parsing_state parsing_state; memset(&parsing_state, 0, sizeof(parsing_state)); @@ -493,7 +504,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { grpc_uri_destroy(uri); retry_throttle_data = parsing_state.retry_throttle_data; method_params_table = grpc_service_config_create_method_config_table( - service_config, method_parameters_create_from_json, + exec_ctx, service_config, method_parameters_create_from_json, method_parameters_ref_wrapper, method_parameters_unref_wrapper); grpc_service_config_destroy(service_config); } @@ -503,7 +514,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { // The copy will be saved in chand->lb_policy_name below. lb_policy_name_dup = gpr_strdup(lb_policy_name); } - grpc_channel_args_destroy(chand->resolver_result); + grpc_channel_args_destroy(exec_ctx, chand->resolver_result); chand->resolver_result = nullptr; } if (grpc_client_channel_trace.enabled()) { @@ -535,7 +546,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { chand->retry_throttle_data = retry_throttle_data; // Swap out the method params table. if (chand->method_params_table != nullptr) { - grpc_slice_hash_table_unref(chand->method_params_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } chand->method_params_table = method_params_table; // If we have a new LB policy or are shutting down (in which case @@ -551,9 +562,10 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, chand->lb_policy); } - grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(exec_ctx, + chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); } chand->lb_policy = new_lb_policy; } @@ -567,20 +579,21 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); } - grpc_resolver_shutdown_locked(chand->resolver); - GRPC_RESOLVER_UNREF(chand->resolver, "channel"); + grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); + GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); chand->resolver = nullptr; } set_channel_connectivity_state_locked( - chand, GRPC_CHANNEL_SHUTDOWN, + exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Got resolver result after disconnection", &error, 1), "resolver_gone"); - GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "resolver"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "resolver"); grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Channel disconnected", &error, 1)); - GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, + &chand->waiting_for_resolver_result_closures); } else { // Not shutting down. grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_error* state_error = @@ -590,28 +603,33 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); } GRPC_ERROR_UNREF(state_error); - state = - grpc_lb_policy_check_connectivity_locked(new_lb_policy, &state_error); - grpc_pollset_set_add_pollset_set(new_lb_policy->interested_parties, + state = grpc_lb_policy_check_connectivity_locked(exec_ctx, new_lb_policy, + &state_error); + grpc_pollset_set_add_pollset_set(exec_ctx, + new_lb_policy->interested_parties, chand->interested_parties); - GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, + &chand->waiting_for_resolver_result_closures); if (chand->exit_idle_when_lb_policy_arrives) { - grpc_lb_policy_exit_idle_locked(new_lb_policy); + grpc_lb_policy_exit_idle_locked(exec_ctx, new_lb_policy); chand->exit_idle_when_lb_policy_arrives = false; } - watch_lb_policy_locked(chand, new_lb_policy, state); + watch_lb_policy_locked(exec_ctx, chand, new_lb_policy, state); } if (!lb_policy_updated) { - set_channel_connectivity_state_locked( - chand, state, GRPC_ERROR_REF(state_error), "new_lb+resolver"); + set_channel_connectivity_state_locked(exec_ctx, chand, state, + GRPC_ERROR_REF(state_error), + "new_lb+resolver"); } - grpc_resolver_next_locked(chand->resolver, &chand->resolver_result, + grpc_resolver_next_locked(exec_ctx, chand->resolver, + &chand->resolver_result, &chand->on_resolver_result_changed); GRPC_ERROR_UNREF(state_error); } } -static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { +static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { grpc_transport_op* op = (grpc_transport_op*)arg; grpc_channel_element* elem = (grpc_channel_element*)op->handler_private.extra_arg; @@ -619,7 +637,7 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( - &chand->state_tracker, op->connectivity_state, + exec_ctx, &chand->state_tracker, op->connectivity_state, op->on_connectivity_state_change); op->on_connectivity_state_change = nullptr; op->connectivity_state = nullptr; @@ -627,10 +645,11 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { if (op->send_ping != nullptr) { if (chand->lb_policy == nullptr) { - GRPC_CLOSURE_SCHED(op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Ping with no load balancing")); + GRPC_CLOSURE_SCHED( + exec_ctx, op->send_ping, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Ping with no load balancing")); } else { - grpc_lb_policy_ping_one_locked(chand->lb_policy, op->send_ping); + grpc_lb_policy_ping_one_locked(exec_ctx, chand->lb_policy, op->send_ping); op->bind_pollset = nullptr; } op->send_ping = nullptr; @@ -639,48 +658,54 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { if (chand->resolver != nullptr) { set_channel_connectivity_state_locked( - chand, GRPC_CHANNEL_SHUTDOWN, + exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); - grpc_resolver_shutdown_locked(chand->resolver); - GRPC_RESOLVER_UNREF(chand->resolver, "channel"); + grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); + GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); chand->resolver = nullptr; if (!chand->started_resolving) { grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_REF(op->disconnect_with_error)); - GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, + &chand->waiting_for_resolver_result_closures); } if (chand->lb_policy != nullptr) { - grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(exec_ctx, + chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); chand->lb_policy = nullptr; } } GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "start_transport_op"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "start_transport_op"); - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } -static void cc_start_transport_op(grpc_channel_element* elem, +static void cc_start_transport_op(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(op->set_accept_stream == false); if (op->bind_pollset != nullptr) { - grpc_pollset_set_add_pollset(chand->interested_parties, op->bind_pollset); + grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, + op->bind_pollset); } op->handler_private.extra_arg = elem; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "start_transport_op"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&op->handler_private.closure, start_transport_op_locked, op, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } -static void cc_get_channel_info(grpc_channel_element* elem, +static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* info) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_lock(&chand->info_mu); @@ -699,7 +724,8 @@ static void cc_get_channel_info(grpc_channel_element* elem, } /* Constructor for channel_data */ -static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, +static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); @@ -720,7 +746,7 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, chand->interested_parties = grpc_pollset_set_create(); grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, "client_channel"); - grpc_client_channel_start_backup_polling(chand->interested_parties); + grpc_client_channel_start_backup_polling(exec_ctx, chand->interested_parties); // Record client channel factory. const grpc_arg* arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); @@ -748,15 +774,15 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, } char* proxy_name = nullptr; grpc_channel_args* new_args = nullptr; - grpc_proxy_mappers_map_name(arg->value.string, args->channel_args, + grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, &proxy_name, &new_args); // Instantiate resolver. chand->resolver = grpc_resolver_create( - proxy_name != nullptr ? proxy_name : arg->value.string, + exec_ctx, proxy_name != nullptr ? proxy_name : arg->value.string, new_args != nullptr ? new_args : args->channel_args, chand->interested_parties, chand->combiner); if (proxy_name != nullptr) gpr_free(proxy_name); - if (new_args != nullptr) grpc_channel_args_destroy(new_args); + if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); if (chand->resolver == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed"); } @@ -765,28 +791,32 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, return GRPC_ERROR_NONE; } -static void shutdown_resolver_locked(void* arg, grpc_error* error) { +static void shutdown_resolver_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_resolver* resolver = (grpc_resolver*)arg; - grpc_resolver_shutdown_locked(resolver); - GRPC_RESOLVER_UNREF(resolver, "channel"); + grpc_resolver_shutdown_locked(exec_ctx, resolver); + GRPC_RESOLVER_UNREF(exec_ctx, resolver, "channel"); } /* Destructor for channel_data */ -static void cc_destroy_channel_elem(grpc_channel_element* elem) { +static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; if (chand->resolver != nullptr) { GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } if (chand->client_channel_factory != nullptr) { - grpc_client_channel_factory_unref(chand->client_channel_factory); + grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); } if (chand->lb_policy != nullptr) { - grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(exec_ctx, + chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); } gpr_free(chand->info_lb_policy_name); gpr_free(chand->info_service_config_json); @@ -794,12 +824,12 @@ static void cc_destroy_channel_elem(grpc_channel_element* elem) { grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } if (chand->method_params_table != nullptr) { - grpc_slice_hash_table_unref(chand->method_params_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } - grpc_client_channel_stop_backup_polling(chand->interested_parties); - grpc_connectivity_state_destroy(&chand->state_tracker); - grpc_pollset_set_destroy(chand->interested_parties); - GRPC_COMBINER_UNREF(chand->combiner, "client_channel"); + grpc_client_channel_stop_backup_polling(exec_ctx, chand->interested_parties); + grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); + grpc_pollset_set_destroy(exec_ctx, chand->interested_parties); + GRPC_COMBINER_UNREF(exec_ctx, chand->combiner, "client_channel"); gpr_mu_destroy(&chand->info_mu); gpr_mu_destroy(&chand->external_connectivity_watcher_list_mu); } @@ -886,18 +916,21 @@ static void waiting_for_pick_batches_add( } // This is called via the call combiner, so access to calld is synchronized. -static void fail_pending_batch_in_call_combiner(void* arg, grpc_error* error) { +static void fail_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_transport_stream_op_batch_finish_with_failure( + exec_ctx, calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count], GRPC_ERROR_REF(error), calld->call_combiner); } } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_fail(grpc_call_element* elem, +static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_error* error) { call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -910,34 +943,37 @@ static void waiting_for_pick_batches_fail(grpc_call_element* elem, GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], fail_pending_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START( - calld->call_combiner, &calld->handle_pending_batch_in_call_combiner[i], - GRPC_ERROR_REF(error), "waiting_for_pick_batches_fail"); + GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, + &calld->handle_pending_batch_in_call_combiner[i], + GRPC_ERROR_REF(error), + "waiting_for_pick_batches_fail"); } if (calld->initial_metadata_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - calld->initial_metadata_batch, GRPC_ERROR_REF(error), + exec_ctx, calld->initial_metadata_batch, GRPC_ERROR_REF(error), calld->call_combiner); } else { - GRPC_CALL_COMBINER_STOP(calld->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, "waiting_for_pick_batches_fail"); } GRPC_ERROR_UNREF(error); } // This is called via the call combiner, so access to calld is synchronized. -static void run_pending_batch_in_call_combiner(void* arg, grpc_error* ignored) { +static void run_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* ignored) { call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_subchannel_call_process_op( - calld->subchannel_call, + exec_ctx, calld->subchannel_call, calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count]); } } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_resume(grpc_call_element* elem) { +static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -951,18 +987,20 @@ static void waiting_for_pick_batches_resume(grpc_call_element* elem) { GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], run_pending_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START( - calld->call_combiner, &calld->handle_pending_batch_in_call_combiner[i], - GRPC_ERROR_NONE, "waiting_for_pick_batches_resume"); + GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, + &calld->handle_pending_batch_in_call_combiner[i], + GRPC_ERROR_NONE, + "waiting_for_pick_batches_resume"); } GPR_ASSERT(calld->initial_metadata_batch != nullptr); - grpc_subchannel_call_process_op(calld->subchannel_call, + grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, calld->initial_metadata_batch); } // Applies service config to the call. Must be invoked once we know // that the resolver has returned results to the channel. -static void apply_service_config_to_call_locked(grpc_call_element* elem) { +static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -975,7 +1013,7 @@ static void apply_service_config_to_call_locked(grpc_call_element* elem) { } if (chand->method_params_table != nullptr) { calld->method_params = (method_parameters*)grpc_method_config_table_get( - chand->method_params_table, calld->path); + exec_ctx, chand->method_params_table, calld->path); if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one @@ -987,14 +1025,15 @@ static void apply_service_config_to_call_locked(grpc_call_element* elem) { calld->method_params->timeout; if (per_method_deadline < calld->deadline) { calld->deadline = per_method_deadline; - grpc_deadline_state_reset(elem, calld->deadline); + grpc_deadline_state_reset(exec_ctx, elem, calld->deadline); } } } } } -static void create_subchannel_call_locked(grpc_call_element* elem, +static void create_subchannel_call_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_error* error) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1008,22 +1047,24 @@ static void create_subchannel_call_locked(grpc_call_element* elem, calld->call_combiner // call_combiner }; grpc_error* new_error = grpc_connected_subchannel_create_call( - calld->connected_subchannel, &call_args, &calld->subchannel_call); + exec_ctx, calld->connected_subchannel, &call_args, + &calld->subchannel_call); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: create subchannel_call=%p: error=%s", chand, calld, calld->subchannel_call, grpc_error_string(new_error)); } if (new_error != GRPC_ERROR_NONE) { new_error = grpc_error_add_child(new_error, error); - waiting_for_pick_batches_fail(elem, new_error); + waiting_for_pick_batches_fail(exec_ctx, elem, new_error); } else { - waiting_for_pick_batches_resume(elem); + waiting_for_pick_batches_resume(exec_ctx, elem); } GRPC_ERROR_UNREF(error); } // Invoked when a pick is completed, on both success or failure. -static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { +static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_error* error) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (calld->connected_subchannel == nullptr) { @@ -1039,10 +1080,10 @@ static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { "chand=%p calld=%p: failed to create subchannel: error=%s", chand, calld, grpc_error_string(calld->error)); } - waiting_for_pick_batches_fail(elem, GRPC_ERROR_REF(calld->error)); + waiting_for_pick_batches_fail(exec_ctx, elem, GRPC_ERROR_REF(calld->error)); } else { /* Create call on subchannel. */ - create_subchannel_call_locked(elem, GRPC_ERROR_REF(error)); + create_subchannel_call_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } @@ -1051,17 +1092,19 @@ static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { // either (a) the pick was deferred pending a resolver result or (b) the // pick was done asynchronously. Removes the call's polling entity from // chand->interested_parties before invoking pick_done_locked(). -static void async_pick_done_locked(grpc_call_element* elem, grpc_error* error) { +static void async_pick_done_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_error* error) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; - grpc_polling_entity_del_from_pollset_set(calld->pollent, + grpc_polling_entity_del_from_pollset_set(exec_ctx, calld->pollent, chand->interested_parties); - pick_done_locked(elem, error); + pick_done_locked(exec_ctx, elem, error); } // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_callback_cancel_locked(void* arg, grpc_error* error) { +static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1070,15 +1113,17 @@ static void pick_callback_cancel_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", chand, calld, calld->lb_policy); } - grpc_lb_policy_cancel_pick_locked( - calld->lb_policy, &calld->connected_subchannel, GRPC_ERROR_REF(error)); + grpc_lb_policy_cancel_pick_locked(exec_ctx, calld->lb_policy, + &calld->connected_subchannel, + GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(calld->owning_call, "pick_callback_cancel"); + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_callback_cancel"); } // Callback invoked by grpc_lb_policy_pick_locked() for async picks. // Unrefs the LB policy and invokes async_pick_done_locked(). -static void pick_callback_done_locked(void* arg, grpc_error* error) { +static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1087,22 +1132,23 @@ static void pick_callback_done_locked(void* arg, grpc_error* error) { chand, calld); } GPR_ASSERT(calld->lb_policy != nullptr); - GRPC_LB_POLICY_UNREF(calld->lb_policy, "pick_subchannel"); + GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); calld->lb_policy = nullptr; - async_pick_done_locked(elem, GRPC_ERROR_REF(error)); + async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } // Takes a ref to chand->lb_policy and calls grpc_lb_policy_pick_locked(). // If the pick was completed synchronously, unrefs the LB policy and // returns true. -static bool pick_callback_start_locked(grpc_call_element* elem) { +static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", chand, calld, chand->lb_policy); } - apply_service_config_to_call_locked(elem); + apply_service_config_to_call_locked(exec_ctx, elem); // If the application explicitly set wait_for_ready, use that. // Otherwise, if the service config specified a value for this // method, use that. @@ -1132,7 +1178,7 @@ static bool pick_callback_start_locked(grpc_call_element* elem) { GRPC_CLOSURE_INIT(&calld->lb_pick_closure, pick_callback_done_locked, elem, grpc_combiner_scheduler(chand->combiner)); const bool pick_done = grpc_lb_policy_pick_locked( - chand->lb_policy, &inputs, &calld->connected_subchannel, + exec_ctx, chand->lb_policy, &inputs, &calld->connected_subchannel, calld->subchannel_call_context, nullptr, &calld->lb_pick_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ @@ -1140,12 +1186,12 @@ static bool pick_callback_start_locked(grpc_call_element* elem) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed synchronously", chand, calld); } - GRPC_LB_POLICY_UNREF(calld->lb_policy, "pick_subchannel"); + GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); calld->lb_policy = nullptr; } else { GRPC_CALL_STACK_REF(calld->owning_call, "pick_callback_cancel"); grpc_call_combiner_set_notify_on_cancel( - calld->call_combiner, + exec_ctx, calld->call_combiner, GRPC_CLOSURE_INIT(&calld->lb_pick_cancel_closure, pick_callback_cancel_locked, elem, grpc_combiner_scheduler(chand->combiner))); @@ -1162,7 +1208,8 @@ typedef struct { // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_after_resolver_result_cancel_locked(void* arg, +static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { @@ -1190,13 +1237,16 @@ static void pick_after_resolver_result_cancel_locked(void* arg, // it's safe to call async_pick_done_locked() here -- we are // essentially calling it here instead of calling it in // pick_after_resolver_result_done_locked(). - async_pick_done_locked(elem, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Pick cancelled", &error, 1)); + async_pick_done_locked(exec_ctx, elem, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Pick cancelled", &error, 1)); } -static void pick_after_resolver_result_start_locked(grpc_call_element* elem); +static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem); -static void pick_after_resolver_result_done_locked(void* arg, +static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { @@ -1216,19 +1266,19 @@ static void pick_after_resolver_result_done_locked(void* arg, gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", chand, calld); } - async_pick_done_locked(elem, GRPC_ERROR_REF(error)); + async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } else if (chand->lb_policy != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", chand, calld); } - if (pick_callback_start_locked(elem)) { + if (pick_callback_start_locked(exec_ctx, elem)) { // Even if the LB policy returns a result synchronously, we have // already added our polling entity to chand->interested_parties // in order to wait for the resolver result, so we need to // remove it here. Therefore, we call async_pick_done_locked() // instead of pick_done_locked(). - async_pick_done_locked(elem, GRPC_ERROR_NONE); + async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); } } // TODO(roth): It should be impossible for chand->lb_policy to be NULL @@ -1246,18 +1296,19 @@ static void pick_after_resolver_result_done_locked(void* arg, "trying again", chand, calld); } - pick_after_resolver_result_start_locked(elem); + pick_after_resolver_result_start_locked(exec_ctx, elem); } else { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver disconnected", chand, calld); } async_pick_done_locked( - elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); + exec_ctx, elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); } } -static void pick_after_resolver_result_start_locked(grpc_call_element* elem) { +static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -1273,46 +1324,47 @@ static void pick_after_resolver_result_start_locked(grpc_call_element* elem) { grpc_closure_list_append(&chand->waiting_for_resolver_result_closures, &args->closure, GRPC_ERROR_NONE); grpc_call_combiner_set_notify_on_cancel( - calld->call_combiner, + exec_ctx, calld->call_combiner, GRPC_CLOSURE_INIT(&args->cancel_closure, pick_after_resolver_result_cancel_locked, args, grpc_combiner_scheduler(chand->combiner))); } -static void start_pick_locked(void* arg, grpc_error* ignored) { +static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* ignored) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(calld->connected_subchannel == nullptr); if (chand->lb_policy != nullptr) { // We already have an LB policy, so ask it for a pick. - if (pick_callback_start_locked(elem)) { + if (pick_callback_start_locked(exec_ctx, elem)) { // Pick completed synchronously. - pick_done_locked(elem, GRPC_ERROR_NONE); + pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); return; } } else { // We do not yet have an LB policy, so wait for a resolver result. if (chand->resolver == nullptr) { - pick_done_locked(elem, + pick_done_locked(exec_ctx, elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); return; } if (!chand->started_resolving) { - start_resolving_locked(chand); + start_resolving_locked(exec_ctx, chand); } - pick_after_resolver_result_start_locked(elem); + pick_after_resolver_result_start_locked(exec_ctx, elem); } // We need to wait for either a resolver result or for an async result // from the LB policy. Add the polling entity from call_data to the // channel_data's interested_parties, so that the I/O of the LB policy // and resolver can be done under it. The polling entity will be // removed in async_pick_done_locked(). - grpc_polling_entity_add_to_pollset_set(calld->pollent, + grpc_polling_entity_add_to_pollset_set(exec_ctx, calld->pollent, chand->interested_parties); } -static void on_complete(void* arg, grpc_error* error) { +static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (calld->retry_throttle_data != nullptr) { @@ -1328,15 +1380,18 @@ static void on_complete(void* arg, grpc_error* error) { calld->retry_throttle_data); } } - GRPC_CLOSURE_RUN(calld->original_on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_on_complete, + GRPC_ERROR_REF(error)); } static void cc_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { - grpc_deadline_state_client_start_transport_stream_op_batch(elem, batch); + grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, + batch); } GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0); // If we've previously been cancelled, immediately fail any new batches. @@ -1346,7 +1401,7 @@ static void cc_start_transport_stream_op_batch( chand, calld, grpc_error_string(calld->error)); } grpc_transport_stream_op_batch_finish_with_failure( - batch, GRPC_ERROR_REF(calld->error), calld->call_combiner); + exec_ctx, batch, GRPC_ERROR_REF(calld->error), calld->call_combiner); goto done; } if (batch->cancel_stream) { @@ -1364,10 +1419,11 @@ static void cc_start_transport_stream_op_batch( // If we have a subchannel call, send the cancellation batch down. // Otherwise, fail all pending batches. if (calld->subchannel_call != nullptr) { - grpc_subchannel_call_process_op(calld->subchannel_call, batch); + grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); } else { waiting_for_pick_batches_add(calld, batch); - waiting_for_pick_batches_fail(elem, GRPC_ERROR_REF(calld->error)); + waiting_for_pick_batches_fail(exec_ctx, elem, + GRPC_ERROR_REF(calld->error)); } goto done; } @@ -1390,7 +1446,7 @@ static void cc_start_transport_stream_op_batch( "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, calld, calld->subchannel_call); } - grpc_subchannel_call_process_op(calld->subchannel_call, batch); + grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); goto done; } // We do not yet have a subchannel call. @@ -1404,6 +1460,7 @@ static void cc_start_transport_stream_op_batch( chand, calld); } GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&batch->handler_private.closure, start_pick_locked, elem, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); @@ -1414,7 +1471,7 @@ static void cc_start_transport_stream_op_batch( "chand=%p calld=%p: saved batch, yeilding call combiner", chand, calld); } - GRPC_CALL_COMBINER_STOP(calld->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, "batch does not include send_initial_metadata"); } done: @@ -1422,7 +1479,8 @@ done: } /* Constructor for call_data */ -static grpc_error* cc_init_call_elem(grpc_call_element* elem, +static grpc_error* cc_init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -1434,22 +1492,23 @@ static grpc_error* cc_init_call_elem(grpc_call_element* elem, calld->owning_call = args->call_stack; calld->call_combiner = args->call_combiner; if (chand->deadline_checking_enabled) { - grpc_deadline_state_init(elem, args->call_stack, args->call_combiner, - calld->deadline); + grpc_deadline_state_init(exec_ctx, elem, args->call_stack, + args->call_combiner, calld->deadline); } return GRPC_ERROR_NONE; } /* Destructor for call_data */ -static void cc_destroy_call_elem(grpc_call_element* elem, +static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { - grpc_deadline_state_destroy(elem); + grpc_deadline_state_destroy(exec_ctx, elem); } - grpc_slice_unref_internal(calld->path); + grpc_slice_unref_internal(exec_ctx, calld->path); if (calld->method_params != nullptr) { method_parameters_unref(calld->method_params); } @@ -1458,13 +1517,14 @@ static void cc_destroy_call_elem(grpc_call_element* elem, grpc_subchannel_call_set_cleanup_closure(calld->subchannel_call, then_schedule_closure); then_schedule_closure = nullptr; - GRPC_SUBCHANNEL_CALL_UNREF(calld->subchannel_call, + GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, calld->subchannel_call, "client_channel_destroy_call"); } GPR_ASSERT(calld->lb_policy == nullptr); GPR_ASSERT(calld->waiting_for_pick_batches_count == 0); if (calld->connected_subchannel != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(calld->connected_subchannel, "picked"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, calld->connected_subchannel, + "picked"); } for (size_t i = 0; i < GRPC_CONTEXT_COUNT; ++i) { if (calld->subchannel_call_context[i].value != nullptr) { @@ -1472,10 +1532,11 @@ static void cc_destroy_call_elem(grpc_call_element* elem, calld->subchannel_call_context[i].value); } } - GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); } -static void cc_set_pollset_or_pollset_set(grpc_call_element* elem, +static void cc_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; calld->pollent = pollent; @@ -1499,27 +1560,29 @@ const grpc_channel_filter grpc_client_channel_filter = { "client-channel", }; -static void try_to_connect_locked(void* arg, grpc_error* error_ignored) { +static void try_to_connect_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { channel_data* chand = (channel_data*)arg; if (chand->lb_policy != nullptr) { - grpc_lb_policy_exit_idle_locked(chand->lb_policy); + grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); } else { chand->exit_idle_when_lb_policy_arrives = true; if (!chand->started_resolving && chand->resolver != nullptr) { - start_resolving_locked(chand); + start_resolving_locked(exec_ctx, chand); } } - GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "try_to_connect"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "try_to_connect"); } grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_channel_element* elem, int try_to_connect) { + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect) { channel_data* chand = (channel_data*)elem->channel_data; grpc_connectivity_state out = grpc_connectivity_state_check(&chand->state_tracker); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { GRPC_CHANNEL_STACK_REF(chand->owning_stack, "try_to_connect"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(try_to_connect_locked, chand, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); @@ -1600,49 +1663,50 @@ int grpc_client_channel_num_external_connectivity_watchers( return count; } -static void on_external_watch_complete_locked(void* arg, grpc_error* error) { +static void on_external_watch_complete_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; grpc_closure* follow_up = w->on_complete; - grpc_polling_entity_del_from_pollset_set(&w->pollent, + grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, w->chand->interested_parties); - GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "external_connectivity_watcher"); external_connectivity_watcher_list_remove(w->chand, w); gpr_free(w); - GRPC_CLOSURE_RUN(follow_up, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); } -static void watch_connectivity_state_locked(void* arg, +static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error_ignored) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; external_connectivity_watcher* found = nullptr; if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); - GRPC_CLOSURE_RUN(w->watcher_timer_init, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete_locked, w, grpc_combiner_scheduler(w->chand->combiner)); - grpc_connectivity_state_notify_on_state_change(&w->chand->state_tracker, - w->state, &w->my_closure); + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &w->chand->state_tracker, w->state, &w->my_closure); } else { GPR_ASSERT(w->watcher_timer_init == nullptr); found = lookup_external_connectivity_watcher(w->chand, w->on_complete); if (found) { GPR_ASSERT(found->on_complete == w->on_complete); grpc_connectivity_state_notify_on_state_change( - &found->chand->state_tracker, nullptr, &found->my_closure); + exec_ctx, &found->chand->state_tracker, nullptr, &found->my_closure); } - grpc_polling_entity_del_from_pollset_set(&w->pollent, + grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, w->chand->interested_parties); - GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "external_connectivity_watcher"); gpr_free(w); } } void grpc_client_channel_watch_connectivity_state( - grpc_channel_element* elem, grpc_polling_entity pollent, - grpc_connectivity_state* state, grpc_closure* closure, - grpc_closure* watcher_timer_init) { + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_polling_entity pollent, grpc_connectivity_state* state, + grpc_closure* closure, grpc_closure* watcher_timer_init) { channel_data* chand = (channel_data*)elem->channel_data; external_connectivity_watcher* w = (external_connectivity_watcher*)gpr_zalloc(sizeof(*w)); @@ -1651,11 +1715,12 @@ void grpc_client_channel_watch_connectivity_state( w->on_complete = closure; w->state = state; w->watcher_timer_init = watcher_timer_init; - grpc_polling_entity_add_to_pollset_set(&w->pollent, + grpc_polling_entity_add_to_pollset_set(exec_ctx, &w->pollent, chand->interested_parties); GRPC_CHANNEL_STACK_REF(w->chand->owning_stack, "external_connectivity_watcher"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&w->my_closure, watch_connectivity_state_locked, w, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 9670405cbe..48e4637a82 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -38,15 +38,15 @@ extern grpc_core::TraceFlag grpc_client_channel_trace; extern const grpc_channel_filter grpc_client_channel_filter; grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_channel_element* elem, int try_to_connect); + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect); int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem); void grpc_client_channel_watch_connectivity_state( - grpc_channel_element* elem, grpc_polling_entity pollent, - grpc_connectivity_state* state, grpc_closure* on_complete, - grpc_closure* watcher_timer_init); + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_polling_entity pollent, grpc_connectivity_state* state, + grpc_closure* on_complete, grpc_closure* watcher_timer_init); /* Debug helper: pull the subchannel call from a call stack element */ grpc_subchannel_call* grpc_client_channel_get_subchannel_call( diff --git a/src/core/ext/filters/client_channel/client_channel_factory.cc b/src/core/ext/filters/client_channel/client_channel_factory.cc index 60c95d7dc9..57eac8f875 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.cc +++ b/src/core/ext/filters/client_channel/client_channel_factory.cc @@ -23,19 +23,23 @@ void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory) { factory->vtable->ref(factory); } -void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory) { - factory->vtable->unref(factory); +void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory) { + factory->vtable->unref(exec_ctx, factory); } grpc_subchannel* grpc_client_channel_factory_create_subchannel( - grpc_client_channel_factory* factory, const grpc_subchannel_args* args) { - return factory->vtable->create_subchannel(factory, args); + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const grpc_subchannel_args* args) { + return factory->vtable->create_subchannel(exec_ctx, factory, args); } grpc_channel* grpc_client_channel_factory_create_channel( - grpc_client_channel_factory* factory, const char* target, - grpc_client_channel_type type, const grpc_channel_args* args) { - return factory->vtable->create_client_channel(factory, target, type, args); + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args) { + return factory->vtable->create_client_channel(exec_ctx, factory, target, type, + args); } static void* factory_arg_copy(void* factory) { @@ -43,8 +47,9 @@ static void* factory_arg_copy(void* factory) { return factory; } -static void factory_arg_destroy(void* factory) { - grpc_client_channel_factory_unref((grpc_client_channel_factory*)factory); +static void factory_arg_destroy(grpc_exec_ctx* exec_ctx, void* factory) { + grpc_client_channel_factory_unref(exec_ctx, + (grpc_client_channel_factory*)factory); } static int factory_arg_cmp(void* factory1, void* factory2) { diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h index 766ebb9389..db82b733ce 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.h +++ b/src/core/ext/filters/client_channel/client_channel_factory.h @@ -45,26 +45,31 @@ struct grpc_client_channel_factory { struct grpc_client_channel_factory_vtable { void (*ref)(grpc_client_channel_factory* factory); - void (*unref)(grpc_client_channel_factory* factory); - grpc_subchannel* (*create_subchannel)(grpc_client_channel_factory* factory, + void (*unref)(grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory); + grpc_subchannel* (*create_subchannel)(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, const grpc_subchannel_args* args); - grpc_channel* (*create_client_channel)(grpc_client_channel_factory* factory, + grpc_channel* (*create_client_channel)(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args); }; void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory); -void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory); +void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory); /** Create a new grpc_subchannel */ grpc_subchannel* grpc_client_channel_factory_create_subchannel( - grpc_client_channel_factory* factory, const grpc_subchannel_args* args); + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const grpc_subchannel_args* args); /** Create a new grpc_channel */ grpc_channel* grpc_client_channel_factory_create_channel( - grpc_client_channel_factory* factory, const char* target, - grpc_client_channel_type type, const grpc_channel_args* args); + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args); grpc_arg grpc_client_channel_factory_create_channel_arg( grpc_client_channel_factory* factory); diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index ea630d2917..7a5bb18157 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -34,12 +34,14 @@ #include "src/core/ext/filters/client_channel/subchannel_index.h" #include "src/core/lib/surface/channel_init.h" -static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { +static bool append_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } -static bool set_default_host_if_unset(grpc_channel_stack_builder* builder, +static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* unused) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); @@ -50,14 +52,15 @@ static bool set_default_host_if_unset(grpc_channel_stack_builder* builder, } } char* default_authority = grpc_get_default_authority( - grpc_channel_stack_builder_get_target(builder)); + exec_ctx, grpc_channel_stack_builder_get_target(builder)); if (default_authority != nullptr) { grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_DEFAULT_AUTHORITY, default_authority); grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_channel_stack_builder_set_channel_arguments(builder, new_args); + grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, + new_args); gpr_free(default_authority); - grpc_channel_args_destroy(new_args); + grpc_channel_args_destroy(exec_ctx, new_args); } return true; } diff --git a/src/core/ext/filters/client_channel/connector.cc b/src/core/ext/filters/client_channel/connector.cc index c8bf2f3e1c..c258468e58 100644 --- a/src/core/ext/filters/client_channel/connector.cc +++ b/src/core/ext/filters/client_channel/connector.cc @@ -23,17 +23,18 @@ grpc_connector* grpc_connector_ref(grpc_connector* connector) { return connector; } -void grpc_connector_unref(grpc_connector* connector) { - connector->vtable->unref(connector); +void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector) { + connector->vtable->unref(exec_ctx, connector); } -void grpc_connector_connect(grpc_connector* connector, +void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify) { - connector->vtable->connect(connector, in_args, out_args, notify); + connector->vtable->connect(exec_ctx, connector, in_args, out_args, notify); } -void grpc_connector_shutdown(grpc_connector* connector, grpc_error* why) { - connector->vtable->shutdown(connector, why); +void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + grpc_error* why) { + connector->vtable->shutdown(exec_ctx, connector, why); } diff --git a/src/core/ext/filters/client_channel/connector.h b/src/core/ext/filters/client_channel/connector.h index d657658d67..239ed8a8bd 100644 --- a/src/core/ext/filters/client_channel/connector.h +++ b/src/core/ext/filters/client_channel/connector.h @@ -49,23 +49,25 @@ typedef struct { struct grpc_connector_vtable { void (*ref)(grpc_connector* connector); - void (*unref)(grpc_connector* connector); + void (*unref)(grpc_exec_ctx* exec_ctx, grpc_connector* connector); /** Implementation of grpc_connector_shutdown */ - void (*shutdown)(grpc_connector* connector, grpc_error* why); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + grpc_error* why); /** Implementation of grpc_connector_connect */ - void (*connect)(grpc_connector* connector, + void (*connect)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify); }; grpc_connector* grpc_connector_ref(grpc_connector* connector); -void grpc_connector_unref(grpc_connector* connector); +void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector); /** Connect using the connector: max one outstanding call at a time */ -void grpc_connector_connect(grpc_connector* connector, +void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify); /** Cancel any pending connection */ -void grpc_connector_shutdown(grpc_connector* connector, grpc_error* why); +void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + grpc_error* why); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H */ diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc index 556a3bc6a1..b7cb2e3eba 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -61,38 +61,41 @@ typedef struct http_connect_handshaker { } http_connect_handshaker; // Unref and clean up handshaker. -static void http_connect_handshaker_unref(http_connect_handshaker* handshaker) { +static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx, + http_connect_handshaker* handshaker) { if (gpr_unref(&handshaker->refcount)) { gpr_mu_destroy(&handshaker->mu); if (handshaker->endpoint_to_destroy != nullptr) { - grpc_endpoint_destroy(handshaker->endpoint_to_destroy); + grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy); } if (handshaker->read_buffer_to_destroy != nullptr) { - grpc_slice_buffer_destroy_internal(handshaker->read_buffer_to_destroy); + grpc_slice_buffer_destroy_internal(exec_ctx, + handshaker->read_buffer_to_destroy); gpr_free(handshaker->read_buffer_to_destroy); } - grpc_slice_buffer_destroy_internal(&handshaker->write_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer); grpc_http_parser_destroy(&handshaker->http_parser); grpc_http_response_destroy(&handshaker->http_response); gpr_free(handshaker); } } -// Set args fields to nullptr, saving the endpoint and read buffer for +// Set args fields to NULL, saving the endpoint and read buffer for // later destruction. static void cleanup_args_for_failure_locked( - http_connect_handshaker* handshaker) { + grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) { handshaker->endpoint_to_destroy = handshaker->args->endpoint; handshaker->args->endpoint = nullptr; handshaker->read_buffer_to_destroy = handshaker->args->read_buffer; handshaker->args->read_buffer = nullptr; - grpc_channel_args_destroy(handshaker->args->args); + grpc_channel_args_destroy(exec_ctx, handshaker->args->args); handshaker->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the // callback with the error. -static void handshake_failed_locked(http_connect_handshaker* handshaker, +static void handshake_failed_locked(grpc_exec_ctx* exec_ctx, + http_connect_handshaker* handshaker, grpc_error* error) { if (error == GRPC_ERROR_NONE) { // If we were shut down after an endpoint operation succeeded but @@ -105,32 +108,34 @@ static void handshake_failed_locked(http_connect_handshaker* handshaker, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint, + GRPC_ERROR_REF(error)); // Not shutting down, so the handshake failed. Clean up before // invoking the callback. - cleanup_args_for_failure_locked(handshaker); + cleanup_args_for_failure_locked(exec_ctx, handshaker); // Set shutdown to true so that subsequent calls to // http_connect_handshaker_shutdown() do nothing. handshaker->shutdown = true; } // Invoke callback. - GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error); } // Callback invoked when finished writing HTTP CONNECT request. -static void on_write_done(void* arg, grpc_error* error) { +static void on_write_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the write failed or we're shutting down, clean up and invoke the // callback with the error. - handshake_failed_locked(handshaker, GRPC_ERROR_REF(error)); + handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error)); gpr_mu_unlock(&handshaker->mu); - http_connect_handshaker_unref(handshaker); + http_connect_handshaker_unref(exec_ctx, handshaker); } else { // Otherwise, read the response. // The read callback inherits our ref to the handshaker. - grpc_endpoint_read(handshaker->args->endpoint, + grpc_endpoint_read(exec_ctx, handshaker->args->endpoint, handshaker->args->read_buffer, &handshaker->response_read_closure); gpr_mu_unlock(&handshaker->mu); @@ -138,13 +143,14 @@ static void on_write_done(void* arg, grpc_error* error) { } // Callback invoked for reading HTTP CONNECT response. -static void on_read_done(void* arg, grpc_error* error) { +static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the read failed or we're shutting down, clean up and invoke the // callback with the error. - handshake_failed_locked(handshaker, GRPC_ERROR_REF(error)); + handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error)); goto done; } // Add buffer to parser. @@ -155,7 +161,7 @@ static void on_read_done(void* arg, grpc_error* error) { handshaker->args->read_buffer->slices[i], &body_start_offset); if (error != GRPC_ERROR_NONE) { - handshake_failed_locked(handshaker, error); + handshake_failed_locked(exec_ctx, handshaker, error); goto done; } if (handshaker->http_parser.state == GRPC_HTTP_BODY) { @@ -174,7 +180,7 @@ static void on_read_done(void* arg, grpc_error* error) { &handshaker->args->read_buffer->slices[i + 1], handshaker->args->read_buffer->count - i - 1); grpc_slice_buffer_swap(handshaker->args->read_buffer, &tmp_buffer); - grpc_slice_buffer_destroy_internal(&tmp_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &tmp_buffer); break; } } @@ -191,8 +197,9 @@ static void on_read_done(void* arg, grpc_error* error) { // complete (e.g., handling chunked transfer encoding or looking // at the Content-Length: header). if (handshaker->http_parser.state != GRPC_HTTP_BODY) { - grpc_slice_buffer_reset_and_unref_internal(handshaker->args->read_buffer); - grpc_endpoint_read(handshaker->args->endpoint, + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + handshaker->args->read_buffer); + grpc_endpoint_read(exec_ctx, handshaker->args->endpoint, handshaker->args->read_buffer, &handshaker->response_read_closure); gpr_mu_unlock(&handshaker->mu); @@ -206,44 +213,48 @@ static void on_read_done(void* arg, grpc_error* error) { handshaker->http_response.status); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - handshake_failed_locked(handshaker, error); + handshake_failed_locked(exec_ctx, handshaker, error); goto done; } // Success. Invoke handshake-done callback. - GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error); done: // Set shutdown to true so that subsequent calls to // http_connect_handshaker_shutdown() do nothing. handshaker->shutdown = true; gpr_mu_unlock(&handshaker->mu); - http_connect_handshaker_unref(handshaker); + http_connect_handshaker_unref(exec_ctx, handshaker); } // // Public handshaker methods // -static void http_connect_handshaker_destroy(grpc_handshaker* handshaker_in) { +static void http_connect_handshaker_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker_in) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; - http_connect_handshaker_unref(handshaker); + http_connect_handshaker_unref(exec_ctx, handshaker); } -static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, +static void http_connect_handshaker_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker_in, grpc_error* why) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; gpr_mu_lock(&handshaker->mu); if (!handshaker->shutdown) { handshaker->shutdown = true; - grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(why)); - cleanup_args_for_failure_locked(handshaker); + grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint, + GRPC_ERROR_REF(why)); + cleanup_args_for_failure_locked(exec_ctx, handshaker); } gpr_mu_unlock(&handshaker->mu); GRPC_ERROR_UNREF(why); } static void http_connect_handshaker_do_handshake( - grpc_handshaker* handshaker_in, grpc_tcp_server_acceptor* acceptor, - grpc_closure* on_handshake_done, grpc_handshaker_args* args) { + grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker_in, + grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, + grpc_handshaker_args* args) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; // Check for HTTP CONNECT channel arg. // If not found, invoke on_handshake_done without doing anything. @@ -255,7 +266,7 @@ static void http_connect_handshaker_do_handshake( gpr_mu_lock(&handshaker->mu); handshaker->shutdown = true; gpr_mu_unlock(&handshaker->mu); - GRPC_CLOSURE_SCHED(on_handshake_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_handshake_done, GRPC_ERROR_NONE); return; } GPR_ASSERT(arg->type == GRPC_ARG_STRING); @@ -313,7 +324,7 @@ static void http_connect_handshaker_do_handshake( gpr_free(header_strings); // Take a new ref to be held by the write callback. gpr_ref(&handshaker->refcount); - grpc_endpoint_write(args->endpoint, &handshaker->write_buffer, + grpc_endpoint_write(exec_ctx, args->endpoint, &handshaker->write_buffer, &handshaker->request_done_closure); gpr_mu_unlock(&handshaker->mu); } @@ -344,13 +355,14 @@ static grpc_handshaker* grpc_http_connect_handshaker_create() { // static void handshaker_factory_add_handshakers( - grpc_handshaker_factory* factory, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* factory, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add(handshake_mgr, grpc_http_connect_handshaker_create()); } -static void handshaker_factory_destroy(grpc_handshaker_factory* factory) {} +static void handshaker_factory_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker_factory* factory) {} static const grpc_handshaker_factory_vtable handshaker_factory_vtable = { handshaker_factory_add_handshakers, handshaker_factory_destroy}; diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 2eafeee702..405d8c0e55 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -36,18 +36,19 @@ /** * Parses the 'http_proxy' env var and returns the proxy hostname to resolve or - * nullptr on error. Also sets 'user_cred' to user credentials if present in the + * NULL on error. Also sets 'user_cred' to user credentials if present in the * 'http_proxy' env var, otherwise leaves it unchanged. It is caller's * responsibility to gpr_free user_cred. */ -static char* get_http_proxy_server(char** user_cred) { +static char* get_http_proxy_server(grpc_exec_ctx* exec_ctx, char** user_cred) { GPR_ASSERT(user_cred != nullptr); char* proxy_name = nullptr; char* uri_str = gpr_getenv("http_proxy"); char** authority_strs = nullptr; size_t authority_nstrs; if (uri_str == nullptr) return nullptr; - grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); + grpc_uri* uri = + grpc_uri_parse(exec_ctx, uri_str, false /* suppress_errors */); if (uri == nullptr || uri->authority == nullptr) { gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); goto done; @@ -81,16 +82,18 @@ done: return proxy_name; } -static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, +static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { char* user_cred = nullptr; - *name_to_resolve = get_http_proxy_server(&user_cred); + *name_to_resolve = get_http_proxy_server(exec_ctx, &user_cred); if (*name_to_resolve == nullptr) return false; char* no_proxy_str = nullptr; - grpc_uri* uri = grpc_uri_parse(server_uri, false /* suppress_errors */); + grpc_uri* uri = + grpc_uri_parse(exec_ctx, server_uri, false /* suppress_errors */); if (uri == nullptr || uri->path[0] == '\0') { gpr_log(GPR_ERROR, "'http_proxy' environment variable set, but cannot " @@ -171,7 +174,8 @@ no_use_proxy: return false; } -static bool proxy_mapper_map_address(grpc_proxy_mapper* mapper, +static bool proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index b97aa319f7..db566f1b56 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -63,13 +63,15 @@ void grpc_lb_policy_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF")); } -static void shutdown_locked(void* arg, grpc_error* error) { +static void shutdown_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_lb_policy* policy = (grpc_lb_policy*)arg; - policy->vtable->shutdown_locked(policy); - GRPC_LB_POLICY_WEAK_UNREF(policy, "strong-unref"); + policy->vtable->shutdown_locked(exec_ctx, policy); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, policy, "strong-unref"); } -void grpc_lb_policy_unref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, (gpr_atm)1 - (gpr_atm)(1 << WEAK_REF_BITS), 1 REF_MUTATE_PASS_ARGS("STRONG_UNREF")); @@ -77,11 +79,13 @@ void grpc_lb_policy_unref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm check = 1 << WEAK_REF_BITS; if ((old_val & mask) == check) { GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(shutdown_locked, policy, grpc_combiner_scheduler(policy->combiner)), GRPC_ERROR_NONE); } else { - grpc_lb_policy_weak_unref(policy REF_FUNC_PASS_ARGS("strong-unref")); + grpc_lb_policy_weak_unref(exec_ctx, + policy REF_FUNC_PASS_ARGS("strong-unref")); } } @@ -89,75 +93,88 @@ void grpc_lb_policy_weak_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1, 0 REF_MUTATE_PASS_ARGS("WEAK_REF")); } -void grpc_lb_policy_weak_unref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF")); if (old_val == 1) { - grpc_pollset_set_destroy(policy->interested_parties); + grpc_pollset_set_destroy(exec_ctx, policy->interested_parties); grpc_combiner* combiner = policy->combiner; - policy->vtable->destroy(policy); - GRPC_COMBINER_UNREF(combiner, "lb_policy"); + policy->vtable->destroy(exec_ctx, policy); + GRPC_COMBINER_UNREF(exec_ctx, combiner, "lb_policy"); } } -int grpc_lb_policy_pick_locked(grpc_lb_policy* policy, +int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { - return policy->vtable->pick_locked(policy, pick_args, target, context, - user_data, on_complete); + return policy->vtable->pick_locked(exec_ctx, policy, pick_args, target, + context, user_data, on_complete); } -void grpc_lb_policy_cancel_pick_locked(grpc_lb_policy* policy, +void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error) { - policy->vtable->cancel_pick_locked(policy, target, error); + policy->vtable->cancel_pick_locked(exec_ctx, policy, target, error); } -void grpc_lb_policy_cancel_picks_locked(grpc_lb_policy* policy, +void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { - policy->vtable->cancel_picks_locked(policy, initial_metadata_flags_mask, + policy->vtable->cancel_picks_locked(exec_ctx, policy, + initial_metadata_flags_mask, initial_metadata_flags_eq, error); } -void grpc_lb_policy_exit_idle_locked(grpc_lb_policy* policy) { - policy->vtable->exit_idle_locked(policy); +void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy) { + policy->vtable->exit_idle_locked(exec_ctx, policy); } -void grpc_lb_policy_ping_one_locked(grpc_lb_policy* policy, +void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_closure* closure) { - policy->vtable->ping_one_locked(policy, closure); + policy->vtable->ping_one_locked(exec_ctx, policy, closure); } void grpc_lb_policy_notify_on_state_change_locked( - grpc_lb_policy* policy, grpc_connectivity_state* state, - grpc_closure* closure) { - policy->vtable->notify_on_state_change_locked(policy, state, closure); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_connectivity_state* state, grpc_closure* closure) { + policy->vtable->notify_on_state_change_locked(exec_ctx, policy, state, + closure); } grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_lb_policy* policy, grpc_error** connectivity_error) { - return policy->vtable->check_connectivity_locked(policy, connectivity_error); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error) { + return policy->vtable->check_connectivity_locked(exec_ctx, policy, + connectivity_error); } -void grpc_lb_policy_update_locked(grpc_lb_policy* policy, +void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, const grpc_lb_policy_args* lb_policy_args) { - policy->vtable->update_locked(policy, lb_policy_args); + policy->vtable->update_locked(exec_ctx, policy, lb_policy_args); } void grpc_lb_policy_set_reresolve_closure_locked( - grpc_lb_policy* policy, grpc_closure* request_reresolution) { - policy->vtable->set_reresolve_closure_locked(policy, request_reresolution); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* request_reresolution) { + policy->vtable->set_reresolve_closure_locked(exec_ctx, policy, + request_reresolution); } -void grpc_lb_policy_try_reresolve(grpc_lb_policy* policy, +void grpc_lb_policy_try_reresolve(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_core::TraceFlag* grpc_lb_trace, grpc_error* error) { if (policy->request_reresolution != nullptr) { - GRPC_CLOSURE_SCHED(policy->request_reresolution, error); + GRPC_CLOSURE_SCHED(exec_ctx, policy->request_reresolution, error); policy->request_reresolution = nullptr; if (grpc_lb_trace->enabled()) { gpr_log(GPR_DEBUG, diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index fd28a2b623..d3159eebf3 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -55,49 +55,53 @@ typedef struct grpc_lb_policy_pick_args { } grpc_lb_policy_pick_args; struct grpc_lb_policy_vtable { - void (*destroy)(grpc_lb_policy* policy); - void (*shutdown_locked)(grpc_lb_policy* policy); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); + void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); /** \see grpc_lb_policy_pick */ - int (*pick_locked)(grpc_lb_policy* policy, + int (*pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete); /** \see grpc_lb_policy_cancel_pick */ - void (*cancel_pick_locked)(grpc_lb_policy* policy, + void (*cancel_pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error); /** \see grpc_lb_policy_cancel_picks */ - void (*cancel_picks_locked)(grpc_lb_policy* policy, + void (*cancel_picks_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error); /** \see grpc_lb_policy_ping_one */ - void (*ping_one_locked)(grpc_lb_policy* policy, grpc_closure* closure); + void (*ping_one_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* closure); /** Try to enter a READY connectivity state */ - void (*exit_idle_locked)(grpc_lb_policy* policy); + void (*exit_idle_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); /** check the current connectivity of the lb_policy */ grpc_connectivity_state (*check_connectivity_locked)( - grpc_lb_policy* policy, grpc_error** connectivity_error); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error); /** call notify when the connectivity state of a channel changes from *state. Updates *state with the new state of the policy. Calling with a NULL \a state cancels the subscription. */ - void (*notify_on_state_change_locked)(grpc_lb_policy* policy, + void (*notify_on_state_change_locked)(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_connectivity_state* state, grpc_closure* closure); - void (*update_locked)(grpc_lb_policy* policy, + void (*update_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_args* args); /** \see grpc_lb_policy_set_reresolve_closure */ - void (*set_reresolve_closure_locked)(grpc_lb_policy* policy, + void (*set_reresolve_closure_locked)(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_closure* request_reresolution); }; @@ -106,33 +110,33 @@ struct grpc_lb_policy_vtable { /* Strong references: the policy will shutdown when they reach zero */ #define GRPC_LB_POLICY_REF(p, r) \ grpc_lb_policy_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_UNREF(p, r) \ - grpc_lb_policy_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_UNREF(exec_ctx, p, r) \ + grpc_lb_policy_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) /* Weak references: they don't prevent the shutdown of the LB policy. When no * strong references are left but there are still weak ones, shutdown is called. * Once the weak reference also reaches zero, the LB policy is destroyed. */ #define GRPC_LB_POLICY_WEAK_REF(p, r) \ grpc_lb_policy_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_WEAK_UNREF(p, r) \ - grpc_lb_policy_weak_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, p, r) \ + grpc_lb_policy_weak_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) void grpc_lb_policy_ref(grpc_lb_policy* policy, const char* file, int line, const char* reason); -void grpc_lb_policy_unref(grpc_lb_policy* policy, const char* file, int line, - const char* reason); +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const char* file, int line, const char* reason); void grpc_lb_policy_weak_ref(grpc_lb_policy* policy, const char* file, int line, const char* reason); -void grpc_lb_policy_weak_unref(grpc_lb_policy* policy, const char* file, - int line, const char* reason); +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const char* file, int line, const char* reason); #else #define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p)) -#define GRPC_LB_POLICY_UNREF(p, r) grpc_lb_policy_unref((p)) +#define GRPC_LB_POLICY_UNREF(cl, p, r) grpc_lb_policy_unref((cl), (p)) #define GRPC_LB_POLICY_WEAK_REF(p, r) grpc_lb_policy_weak_ref((p)) -#define GRPC_LB_POLICY_WEAK_UNREF(p, r) grpc_lb_policy_weak_unref((p)) +#define GRPC_LB_POLICY_WEAK_UNREF(cl, p, r) grpc_lb_policy_weak_unref((cl), (p)) void grpc_lb_policy_ref(grpc_lb_policy* policy); -void grpc_lb_policy_unref(grpc_lb_policy* policy); +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); void grpc_lb_policy_weak_ref(grpc_lb_policy* policy); -void grpc_lb_policy_weak_unref(grpc_lb_policy* policy); +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); #endif /** called by concrete implementations to initialize the base struct */ @@ -157,7 +161,7 @@ void grpc_lb_policy_init(grpc_lb_policy* policy, Any IO should be done under the \a interested_parties \a grpc_pollset_set in the \a grpc_lb_policy struct. */ -int grpc_lb_policy_pick_locked(grpc_lb_policy* policy, +int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, @@ -165,47 +169,55 @@ int grpc_lb_policy_pick_locked(grpc_lb_policy* policy, /** Perform a connected subchannel ping (see \a grpc_connected_subchannel_ping) against one of the connected subchannels managed by \a policy. */ -void grpc_lb_policy_ping_one_locked(grpc_lb_policy* policy, +void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_closure* closure); /** Cancel picks for \a target. The \a on_complete callback of the pending picks will be invoked with \a *target set to NULL. */ -void grpc_lb_policy_cancel_pick_locked(grpc_lb_policy* policy, +void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error); /** Cancel all pending picks for which their \a initial_metadata_flags (as given in the call to \a grpc_lb_policy_pick) matches \a initial_metadata_flags_eq when AND'd with \a initial_metadata_flags_mask */ -void grpc_lb_policy_cancel_picks_locked(grpc_lb_policy* policy, +void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error); /** Try to enter a READY connectivity state */ -void grpc_lb_policy_exit_idle_locked(grpc_lb_policy* policy); +void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy); /* Call notify when the connectivity state of a channel changes from \a *state. * Updates \a *state with the new state of the policy */ void grpc_lb_policy_notify_on_state_change_locked( - grpc_lb_policy* policy, grpc_connectivity_state* state, - grpc_closure* closure); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_connectivity_state* state, grpc_closure* closure); grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_lb_policy* policy, grpc_error** connectivity_error); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error); /** Update \a policy with \a lb_policy_args. */ -void grpc_lb_policy_update_locked(grpc_lb_policy* policy, +void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, const grpc_lb_policy_args* lb_policy_args); /** Set the re-resolution closure to \a request_reresolution. */ void grpc_lb_policy_set_reresolve_closure_locked( - grpc_lb_policy* policy, grpc_closure* request_reresolution); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* request_reresolution); /** Try to request a re-resolution. It's NOT a public API; it's only for use by the LB policy implementations. */ -void grpc_lb_policy_try_reresolve(grpc_lb_policy* policy, +void grpc_lb_policy_try_reresolve(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, grpc_core::TraceFlag* grpc_lb_trace, grpc_error* error); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index 3eedb08ecc..6d9fadaf30 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -25,12 +25,14 @@ #include "src/core/lib/iomgr/error.h" #include "src/core/lib/profiling/timers.h" -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} typedef struct { // Stats object to update. @@ -45,24 +47,28 @@ typedef struct { bool recv_initial_metadata_succeeded; } call_data; -static void on_complete_for_send(void* arg, grpc_error* error) { +static void on_complete_for_send(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->send_initial_metadata_succeeded = true; } - GRPC_CLOSURE_RUN(calld->original_on_complete_for_send, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_on_complete_for_send, + GRPC_ERROR_REF(error)); } -static void recv_initial_metadata_ready(void* arg, grpc_error* error) { +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->recv_initial_metadata_succeeded = true; } - GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; // Get stats object from context and take a ref. @@ -75,7 +81,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; @@ -90,7 +96,8 @@ static void destroy_call_elem(grpc_call_element* elem, } static void start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("clr_start_transport_stream_op_batch", 0); // Intercept send_initial_metadata. @@ -111,7 +118,7 @@ static void start_transport_stream_op_batch( &calld->recv_initial_metadata_ready; } // Chain to next filter. - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); GPR_TIMER_END("clr_start_transport_stream_op_batch", 0); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index eadeea0368..db06fc20b6 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -131,12 +131,12 @@ grpc_core::TraceFlag grpc_lb_glb_trace(false, "glb"); /* add lb_token of selected subchannel (address) to the call's initial * metadata */ static grpc_error* initial_metadata_add_lb_token( - grpc_metadata_batch* initial_metadata, + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* initial_metadata, grpc_linked_mdelem* lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != nullptr); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); - return grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, - lb_token); + return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, + lb_token_mdelem_storage, lb_token); } static void destroy_client_stats(void* arg) { @@ -186,19 +186,20 @@ typedef struct wrapped_rr_closure_arg { /* The \a on_complete closure passed as part of the pick requires keeping a * reference to its associated round robin instance. We wrap this closure in * order to unref the round robin instance upon its invocation */ -static void wrapped_rr_closure(void* arg, grpc_error* error) { +static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { wrapped_rr_closure_arg* wc_arg = (wrapped_rr_closure_arg*)arg; GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); if (wc_arg->rr_policy != nullptr) { - /* if *target is nullptr, no pick has been made by the RR policy (eg, all + /* if *target is NULL, no pick has been made by the RR policy (eg, all * addresses failed to connect). There won't be any user_data/token * available */ if (*wc_arg->target != nullptr) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { - initial_metadata_add_lb_token(wc_arg->initial_metadata, + initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); } else { @@ -220,7 +221,7 @@ static void wrapped_rr_closure(void* arg, grpc_error* error) { gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p", wc_arg->glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "wrapped_rr_closure"); + GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); } GPR_ASSERT(wc_arg->free_when_done != nullptr); gpr_free(wc_arg->free_when_done); @@ -240,8 +241,8 @@ typedef struct pending_pick { /* original pick()'s arguments */ grpc_lb_policy_pick_args pick_args; - /* output argument where to store the pick()ed connected subchannel, or - * nullptr upon error. */ + /* output argument where to store the pick()ed connected subchannel, or NULL + * upon error. */ grpc_connected_subchannel** target; /* args for wrapped_on_complete */ @@ -327,8 +328,8 @@ typedef struct glb_lb_policy { /** connectivity state of the LB channel */ grpc_connectivity_state lb_channel_connectivity; - /** stores the deserialized response from the LB. May be nullptr until one - * such response has arrived. */ + /** stores the deserialized response from the LB. May be NULL until one such + * response has arrived. */ grpc_grpclb_serverlist* serverlist; /** Index into serverlist for next pick. @@ -458,9 +459,9 @@ static void* lb_token_copy(void* token) { ? nullptr : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; } -static void lb_token_destroy(void* token) { +static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) { if (token != nullptr) { - GRPC_MDELEM_UNREF(grpc_mdelem{(uintptr_t)token}); + GRPC_MDELEM_UNREF(exec_ctx, grpc_mdelem{(uintptr_t)token}); } } static int lb_token_cmp(void* token1, void* token2) { @@ -496,7 +497,7 @@ static void parse_server(const grpc_grpclb_server* server, /* Returns addresses extracted from \a serverlist. */ static grpc_lb_addresses* process_serverlist_locked( - const grpc_grpclb_serverlist* serverlist) { + grpc_exec_ctx* exec_ctx, const grpc_grpclb_serverlist* serverlist) { size_t num_valid = 0; /* first pass: count how many are valid in order to allocate the necessary * memory in a single block */ @@ -527,9 +528,9 @@ static grpc_lb_addresses* process_serverlist_locked( strnlen(server->load_balance_token, lb_token_max_length); grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( server->load_balance_token, lb_token_length); - user_data = - (void*)grpc_mdelem_from_slices(GRPC_MDSTR_LB_TOKEN, lb_token_mdstr) - .payload; + user_data = (void*)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, + lb_token_mdstr) + .payload; } else { char* uri = grpc_sockaddr_to_uri(&addr); gpr_log(GPR_INFO, @@ -551,7 +552,7 @@ static grpc_lb_addresses* process_serverlist_locked( /* Returns the backend addresses extracted from the given addresses */ static grpc_lb_addresses* extract_backend_addresses_locked( - const grpc_lb_addresses* addresses) { + grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses) { /* first pass: count the number of backend addresses */ size_t num_backends = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -576,8 +577,8 @@ static grpc_lb_addresses* extract_backend_addresses_locked( } static void update_lb_connectivity_status_locked( - glb_lb_policy* glb_policy, grpc_connectivity_state rr_state, - grpc_error* rr_state_error) { + grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, + grpc_connectivity_state rr_state, grpc_error* rr_state_error) { const grpc_connectivity_state curr_glb_state = grpc_connectivity_state_check(&glb_policy->state_tracker); @@ -629,7 +630,7 @@ static void update_lb_connectivity_status_locked( glb_policy, grpc_connectivity_state_name(rr_state), glb_policy->rr_policy); } - grpc_connectivity_state_set(&glb_policy->state_tracker, rr_state, + grpc_connectivity_state_set(exec_ctx, &glb_policy->state_tracker, rr_state, rr_state_error, "update_lb_connectivity_status_locked"); } @@ -640,9 +641,9 @@ static void update_lb_connectivity_status_locked( * If \a force_async is true, then we will manually schedule the * completion callback even if the pick is available immediately. */ static bool pick_from_internal_rr_locked( - glb_lb_policy* glb_policy, const grpc_lb_policy_pick_args* pick_args, - bool force_async, grpc_connected_subchannel** target, - wrapped_rr_closure_arg* wc_arg) { + grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, + const grpc_lb_policy_pick_args* pick_args, bool force_async, + grpc_connected_subchannel** target, wrapped_rr_closure_arg* wc_arg) { // Check for drops if we are not using fallback backend addresses. if (glb_policy->serverlist != nullptr) { // Look at the index into the serverlist to see if we should drop this call. @@ -657,7 +658,7 @@ static bool pick_from_internal_rr_locked( gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p for drop", glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "glb_pick_sync"); + GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); // Update client load reporting stats to indicate the number of // dropped calls. Note that we have to do this here instead of in // the client_load_reporting filter, because we do not create a @@ -669,7 +670,7 @@ static bool pick_from_internal_rr_locked( grpc_grpclb_client_stats_unref(wc_arg->client_stats); if (force_async) { GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; } @@ -679,7 +680,7 @@ static bool pick_from_internal_rr_locked( } // Pick via the RR policy. const bool pick_done = grpc_lb_policy_pick_locked( - wc_arg->rr_policy, pick_args, target, wc_arg->context, + exec_ctx, wc_arg->rr_policy, pick_args, target, wc_arg->context, (void**)&wc_arg->lb_token, &wc_arg->wrapper_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the RR policy. */ @@ -687,9 +688,9 @@ static bool pick_from_internal_rr_locked( gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p", glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "glb_pick_sync"); + GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); /* add the load reporting initial metadata */ - initial_metadata_add_lb_token(pick_args->initial_metadata, + initial_metadata_add_lb_token(exec_ctx, pick_args->initial_metadata, pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); // Pass on client stats via context. Passes ownership of the reference. @@ -698,7 +699,7 @@ static bool pick_from_internal_rr_locked( wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; if (force_async) { GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; } @@ -711,11 +712,12 @@ static bool pick_from_internal_rr_locked( return pick_done; } -static grpc_lb_policy_args* lb_policy_args_create(glb_lb_policy* glb_policy) { +static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { grpc_lb_addresses* addresses; if (glb_policy->serverlist != nullptr) { GPR_ASSERT(glb_policy->serverlist->num_servers > 0); - addresses = process_serverlist_locked(glb_policy->serverlist); + addresses = process_serverlist_locked(exec_ctx, glb_policy->serverlist); } else { // If rr_handover_locked() is invoked when we haven't received any // serverlist from the balancer, we use the fallback backends returned by @@ -735,21 +737,24 @@ static grpc_lb_policy_args* lb_policy_args_create(glb_lb_policy* glb_policy) { args->args = grpc_channel_args_copy_and_add_and_remove( glb_policy->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, 1); - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(exec_ctx, addresses); return args; } -static void lb_policy_args_destroy(grpc_lb_policy_args* args) { - grpc_channel_args_destroy(args->args); +static void lb_policy_args_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_args* args) { + grpc_channel_args_destroy(exec_ctx, args->args); gpr_free(args); } -static void glb_rr_connectivity_changed_locked(void* arg, grpc_error* error); -static void create_rr_locked(glb_lb_policy* glb_policy, +static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error); +static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, grpc_lb_policy_args* args) { GPR_ASSERT(glb_policy->rr_policy == nullptr); - grpc_lb_policy* new_rr_policy = grpc_lb_policy_create("round_robin", args); + grpc_lb_policy* new_rr_policy = + grpc_lb_policy_create(exec_ctx, "round_robin", args); if (new_rr_policy == nullptr) { gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy for serverlist " @@ -762,19 +767,21 @@ static void create_rr_locked(glb_lb_policy* glb_policy, return; } grpc_lb_policy_set_reresolve_closure_locked( - new_rr_policy, glb_policy->base.request_reresolution); + exec_ctx, new_rr_policy, glb_policy->base.request_reresolution); glb_policy->base.request_reresolution = nullptr; glb_policy->rr_policy = new_rr_policy; grpc_error* rr_state_error = nullptr; const grpc_connectivity_state rr_state = - grpc_lb_policy_check_connectivity_locked(glb_policy->rr_policy, + grpc_lb_policy_check_connectivity_locked(exec_ctx, glb_policy->rr_policy, &rr_state_error); /* Connectivity state is a function of the RR policy updated/created */ - update_lb_connectivity_status_locked(glb_policy, rr_state, rr_state_error); + update_lb_connectivity_status_locked(exec_ctx, glb_policy, rr_state, + rr_state_error); /* Add the gRPC LB's interested_parties pollset_set to that of the newly * created RR policy. This will make the RR policy progress upon activity on * gRPC LB, which in turn is tied to the application's call */ - grpc_pollset_set_add_pollset_set(glb_policy->rr_policy->interested_parties, + grpc_pollset_set_add_pollset_set(exec_ctx, + glb_policy->rr_policy->interested_parties, glb_policy->base.interested_parties); /* Allocate the data for the tracking of the new RR policy's connectivity. @@ -789,10 +796,10 @@ static void create_rr_locked(glb_lb_policy* glb_policy, /* Subscribe to changes to the connectivity of the new RR */ GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "glb_rr_connectivity_cb"); - grpc_lb_policy_notify_on_state_change_locked(glb_policy->rr_policy, + grpc_lb_policy_notify_on_state_change_locked(exec_ctx, glb_policy->rr_policy, &rr_connectivity->state, &rr_connectivity->on_change); - grpc_lb_policy_exit_idle_locked(glb_policy->rr_policy); + grpc_lb_policy_exit_idle_locked(exec_ctx, glb_policy->rr_policy); /* Update picks and pings in wait */ pending_pick* pp; @@ -807,7 +814,7 @@ static void create_rr_locked(glb_lb_policy* glb_policy, "[grpclb %p] Pending pick about to (async) PICK from RR %p", glb_policy, glb_policy->rr_policy); } - pick_from_internal_rr_locked(glb_policy, &pp->pick_args, + pick_from_internal_rr_locked(exec_ctx, glb_policy, &pp->pick_args, true /* force_async */, pp->target, &pp->wrapped_on_complete_arg); } @@ -821,37 +828,40 @@ static void create_rr_locked(glb_lb_policy* glb_policy, gpr_log(GPR_INFO, "[grpclb %p] Pending ping about to PING from RR %p", glb_policy, glb_policy->rr_policy); } - grpc_lb_policy_ping_one_locked(glb_policy->rr_policy, + grpc_lb_policy_ping_one_locked(exec_ctx, glb_policy->rr_policy, &pping->wrapped_notify_arg.wrapper_closure); } } -/* glb_policy->rr_policy may be nullptr (initial handover) */ -static void rr_handover_locked(glb_lb_policy* glb_policy) { +/* glb_policy->rr_policy may be NULL (initial handover) */ +static void rr_handover_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { if (glb_policy->shutting_down) return; - grpc_lb_policy_args* args = lb_policy_args_create(glb_policy); + grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); GPR_ASSERT(args != nullptr); if (glb_policy->rr_policy != nullptr) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Updating RR policy %p", glb_policy, glb_policy->rr_policy); } - grpc_lb_policy_update_locked(glb_policy->rr_policy, args); + grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args); } else { - create_rr_locked(glb_policy, args); + create_rr_locked(exec_ctx, glb_policy, args); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Created new RR policy %p", glb_policy, glb_policy->rr_policy); } } - lb_policy_args_destroy(args); + lb_policy_args_destroy(exec_ctx, args); } -static void glb_rr_connectivity_changed_locked(void* arg, grpc_error* error) { +static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { rr_connectivity_data* rr_connectivity = (rr_connectivity_data*)arg; glb_lb_policy* glb_policy = rr_connectivity->glb_policy; if (glb_policy->shutting_down) { - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "glb_rr_connectivity_cb"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); return; } @@ -859,22 +869,25 @@ static void glb_rr_connectivity_changed_locked(void* arg, grpc_error* error) { /* An RR policy that has transitioned into the SHUTDOWN connectivity state * should not be considered for picks or updates: the SHUTDOWN state is a * sink, policies can't transition back from it. .*/ - GRPC_LB_POLICY_UNREF(glb_policy->rr_policy, "rr_connectivity_shutdown"); + GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, + "rr_connectivity_shutdown"); glb_policy->rr_policy = nullptr; - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "glb_rr_connectivity_cb"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); return; } /* rr state != SHUTDOWN && !glb_policy->shutting down: biz as usual */ - update_lb_connectivity_status_locked(glb_policy, rr_connectivity->state, - GRPC_ERROR_REF(error)); + update_lb_connectivity_status_locked( + exec_ctx, glb_policy, rr_connectivity->state, GRPC_ERROR_REF(error)); /* Resubscribe. Reuse the "glb_rr_connectivity_cb" weak ref. */ - grpc_lb_policy_notify_on_state_change_locked(glb_policy->rr_policy, + grpc_lb_policy_notify_on_state_change_locked(exec_ctx, glb_policy->rr_policy, &rr_connectivity->state, &rr_connectivity->on_change); } -static void destroy_balancer_name(void* balancer_name) { +static void destroy_balancer_name(grpc_exec_ctx* exec_ctx, + void* balancer_name) { gpr_free(balancer_name); } @@ -901,7 +914,7 @@ static int balancer_name_cmp_fn(void* a, void* b) { * above the grpclb policy. * - \a args: other args inherited from the grpclb policy. */ static grpc_channel_args* build_lb_channel_args( - const grpc_lb_addresses* addresses, + grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { size_t num_grpclb_addrs = 0; @@ -944,7 +957,7 @@ static grpc_channel_args* build_lb_channel_args( gpr_free(targets_info_entries); grpc_channel_args* lb_channel_args = - grpc_lb_policy_grpclb_build_lb_channel_args(targets_info, + grpc_lb_policy_grpclb_build_lb_channel_args(exec_ctx, targets_info, response_generator, args); grpc_arg lb_channel_addresses_arg = @@ -952,34 +965,34 @@ static grpc_channel_args* build_lb_channel_args( grpc_channel_args* result = grpc_channel_args_copy_and_add( lb_channel_args, &lb_channel_addresses_arg, 1); - grpc_slice_hash_table_unref(targets_info); - grpc_channel_args_destroy(lb_channel_args); - grpc_lb_addresses_destroy(lb_addresses); + grpc_slice_hash_table_unref(exec_ctx, targets_info); + grpc_channel_args_destroy(exec_ctx, lb_channel_args); + grpc_lb_addresses_destroy(exec_ctx, lb_addresses); return result; } -static void glb_destroy(grpc_lb_policy* pol) { +static void glb_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; GPR_ASSERT(glb_policy->pending_picks == nullptr); GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); - grpc_channel_args_destroy(glb_policy->args); + grpc_channel_args_destroy(exec_ctx, glb_policy->args); if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } - grpc_connectivity_state_destroy(&glb_policy->state_tracker); + grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); if (glb_policy->serverlist != nullptr) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } if (glb_policy->fallback_backend_addresses != nullptr) { - grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); } grpc_fake_resolver_response_generator_unref(glb_policy->response_generator); grpc_subchannel_index_unref(); gpr_free(glb_policy); } -static void glb_shutdown_locked(grpc_lb_policy* pol) { +static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); glb_policy->shutting_down = true; @@ -998,11 +1011,11 @@ static void glb_shutdown_locked(grpc_lb_policy* pol) { /* lb_on_server_status_received will pick up the cancel and clean up */ } if (glb_policy->retry_timer_active) { - grpc_timer_cancel(&glb_policy->lb_call_retry_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); glb_policy->retry_timer_active = false; } if (glb_policy->fallback_timer_active) { - grpc_timer_cancel(&glb_policy->lb_fallback_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; } @@ -1011,9 +1024,10 @@ static void glb_shutdown_locked(grpc_lb_policy* pol) { pending_ping* pping = glb_policy->pending_pings; glb_policy->pending_pings = nullptr; if (glb_policy->rr_policy != nullptr) { - GRPC_LB_POLICY_UNREF(glb_policy->rr_policy, "glb_shutdown"); + GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "glb_shutdown"); } else { - grpc_lb_policy_try_reresolve(pol, &grpc_lb_glb_trace, GRPC_ERROR_CANCELLED); + grpc_lb_policy_try_reresolve(exec_ctx, pol, &grpc_lb_glb_trace, + GRPC_ERROR_CANCELLED); } // We destroy the LB channel here because // glb_lb_channel_on_connectivity_changed_cb needs a valid glb_policy @@ -1023,13 +1037,14 @@ static void glb_shutdown_locked(grpc_lb_policy* pol) { grpc_channel_destroy(glb_policy->lb_channel); glb_policy->lb_channel = nullptr; } - grpc_connectivity_state_set(&glb_policy->state_tracker, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_REF(error), "glb_shutdown"); + grpc_connectivity_state_set(exec_ctx, &glb_policy->state_tracker, + GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), + "glb_shutdown"); while (pp != nullptr) { pending_pick* next = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_REF(error)); gpr_free(pp); pp = next; @@ -1037,7 +1052,7 @@ static void glb_shutdown_locked(grpc_lb_policy* pol) { while (pping != nullptr) { pending_ping* next = pping->next; - GRPC_CLOSURE_SCHED(&pping->wrapped_notify_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(exec_ctx, &pping->wrapped_notify_arg.wrapper_closure, GRPC_ERROR_REF(error)); gpr_free(pping); pping = next; @@ -1054,8 +1069,8 @@ static void glb_shutdown_locked(grpc_lb_policy* pol) { // pick needs also be cancelled by the RR instance. // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, -// we invoke the completion closure and set *target to nullptr right here. -static void glb_cancel_pick_locked(grpc_lb_policy* pol, +// we invoke the completion closure and set *target to NULL right here. +static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; @@ -1065,7 +1080,7 @@ static void glb_cancel_pick_locked(grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); } else { @@ -1075,7 +1090,7 @@ static void glb_cancel_pick_locked(grpc_lb_policy* pol, pp = next; } if (glb_policy->rr_policy != nullptr) { - grpc_lb_policy_cancel_pick_locked(glb_policy->rr_policy, target, + grpc_lb_policy_cancel_pick_locked(exec_ctx, glb_policy->rr_policy, target, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); @@ -1090,8 +1105,9 @@ static void glb_cancel_pick_locked(grpc_lb_policy* pol, // pick needs also be cancelled by the RR instance. // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, -// we invoke the completion closure and set *target to nullptr right here. -static void glb_cancel_picks_locked(grpc_lb_policy* pol, +// we invoke the completion closure and set *target to NULL right here. +static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -1102,7 +1118,7 @@ static void glb_cancel_picks_locked(grpc_lb_policy* pol, pending_pick* next = pp->next; if ((pp->pick_args.initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); } else { @@ -1113,49 +1129,52 @@ static void glb_cancel_picks_locked(grpc_lb_policy* pol, } if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_picks_locked( - glb_policy->rr_policy, initial_metadata_flags_mask, + exec_ctx, glb_policy->rr_policy, initial_metadata_flags_mask, initial_metadata_flags_eq, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } -static void lb_on_fallback_timer_locked(void* arg, grpc_error* error); -static void query_for_backends_locked(glb_lb_policy* glb_policy); -static void start_picking_locked(glb_lb_policy* glb_policy) { +static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy); +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { /* start a timer to fall back */ if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == nullptr && !glb_policy->fallback_timer_active) { grpc_millis deadline = - grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; + grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); GRPC_CLOSURE_INIT(&glb_policy->lb_on_fallback, lb_on_fallback_timer_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); glb_policy->fallback_timer_active = true; - grpc_timer_init(&glb_policy->lb_fallback_timer, deadline, + grpc_timer_init(exec_ctx, &glb_policy->lb_fallback_timer, deadline, &glb_policy->lb_on_fallback); } glb_policy->started_picking = true; grpc_backoff_reset(&glb_policy->lb_call_backoff_state); - query_for_backends_locked(glb_policy); + query_for_backends_locked(exec_ctx, glb_policy); } -static void glb_exit_idle_locked(grpc_lb_policy* pol) { +static void glb_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (!glb_policy->started_picking) { - start_picking_locked(glb_policy); + start_picking_locked(exec_ctx, glb_policy); } } -static int glb_pick_locked(grpc_lb_policy* pol, +static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { if (pick_args->lb_token_mdelem_storage == nullptr) { *target = nullptr; - GRPC_CLOSURE_SCHED(on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, on_complete, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No mdelem storage for the LB token. Load reporting " "won't work without it. Failing")); @@ -1165,8 +1184,8 @@ static int glb_pick_locked(grpc_lb_policy* pol, bool pick_done = false; if (glb_policy->rr_policy != nullptr) { const grpc_connectivity_state rr_connectivity_state = - grpc_lb_policy_check_connectivity_locked(glb_policy->rr_policy, - nullptr); + grpc_lb_policy_check_connectivity_locked( + exec_ctx, glb_policy->rr_policy, nullptr); // The glb_policy->rr_policy may have transitioned to SHUTDOWN but the // callback registered to capture this event // (glb_rr_connectivity_changed_locked) may not have been invoked yet. We @@ -1203,8 +1222,9 @@ static int glb_pick_locked(grpc_lb_policy* pol, wc_arg->initial_metadata = pick_args->initial_metadata; wc_arg->free_when_done = wc_arg; wc_arg->glb_policy = pol; - pick_done = pick_from_internal_rr_locked( - glb_policy, pick_args, false /* force_async */, target, wc_arg); + pick_done = + pick_from_internal_rr_locked(exec_ctx, glb_policy, pick_args, + false /* force_async */, target, wc_arg); } } else { // glb_policy->rr_policy == NULL if (grpc_lb_glb_trace.enabled()) { @@ -1215,7 +1235,7 @@ static int glb_pick_locked(grpc_lb_policy* pol, add_pending_pick(&glb_policy->pending_picks, pick_args, target, context, on_complete); if (!glb_policy->started_picking) { - start_picking_locked(glb_policy); + start_picking_locked(exec_ctx, glb_policy); } pick_done = false; } @@ -1223,33 +1243,37 @@ static int glb_pick_locked(grpc_lb_policy* pol, } static grpc_connectivity_state glb_check_connectivity_locked( - grpc_lb_policy* pol, grpc_error** connectivity_error) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_error** connectivity_error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; return grpc_connectivity_state_get(&glb_policy->state_tracker, connectivity_error); } -static void glb_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { +static void glb_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (glb_policy->rr_policy) { - grpc_lb_policy_ping_one_locked(glb_policy->rr_policy, closure); + grpc_lb_policy_ping_one_locked(exec_ctx, glb_policy->rr_policy, closure); } else { add_pending_ping(&glb_policy->pending_pings, closure); if (!glb_policy->started_picking) { - start_picking_locked(glb_policy); + start_picking_locked(exec_ctx, glb_policy); } } } -static void glb_notify_on_state_change_locked(grpc_lb_policy* pol, +static void glb_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change(&glb_policy->state_tracker, - current, notify); + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &glb_policy->state_tracker, current, notify); } -static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { +static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->retry_timer_active = false; if (!glb_policy->shutting_down && glb_policy->lb_call == nullptr && @@ -1257,26 +1281,28 @@ static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", glb_policy); } - query_for_backends_locked(glb_policy); + query_for_backends_locked(exec_ctx, glb_policy); } - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "grpclb_retry_timer"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "grpclb_retry_timer"); } -static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { +static void maybe_restart_lb_call(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { if (glb_policy->started_picking && glb_policy->updating_lb_call) { if (glb_policy->retry_timer_active) { - grpc_timer_cancel(&glb_policy->lb_call_retry_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); } - if (!glb_policy->shutting_down) start_picking_locked(glb_policy); + if (!glb_policy->shutting_down) start_picking_locked(exec_ctx, glb_policy); glb_policy->updating_lb_call = false; } else if (!glb_policy->shutting_down) { /* if we aren't shutting down, restart the LB client call after some time */ - grpc_millis next_try = grpc_backoff_step(&glb_policy->lb_call_backoff_state) - .next_attempt_start_time; + grpc_millis next_try = + grpc_backoff_step(exec_ctx, &glb_policy->lb_call_backoff_state) + .next_attempt_start_time; if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); - grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); + grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); if (timeout > 0) { gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", @@ -1291,40 +1317,43 @@ static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { lb_call_on_retry_timer_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); glb_policy->retry_timer_active = true; - grpc_timer_init(&glb_policy->lb_call_retry_timer, next_try, + grpc_timer_init(exec_ctx, &glb_policy->lb_call_retry_timer, next_try, &glb_policy->lb_on_call_retry); } - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "lb_on_server_status_received_locked"); } -static void send_client_load_report_locked(void* arg, grpc_error* error); +static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); -static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { +static void schedule_next_client_load_report(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = - grpc_core::ExecCtx::Get()->Now() + - glb_policy->client_stats_report_interval; + grpc_exec_ctx_now(exec_ctx) + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, send_client_load_report_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); - grpc_timer_init(&glb_policy->client_load_report_timer, + grpc_timer_init(exec_ctx, &glb_policy->client_load_report_timer, next_client_load_report_time, &glb_policy->client_load_report_closure); } -static void client_load_report_done_locked(void* arg, grpc_error* error) { +static void client_load_report_done_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); glb_policy->client_load_report_payload = nullptr; if (error != GRPC_ERROR_NONE || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "client_load_report"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + "client_load_report"); if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(glb_policy); + maybe_restart_lb_call(exec_ctx, glb_policy); } return; } - schedule_next_client_load_report(glb_policy); + schedule_next_client_load_report(exec_ctx, glb_policy); } static bool load_report_counters_are_zero(grpc_grpclb_request* request) { @@ -1339,13 +1368,15 @@ static bool load_report_counters_are_zero(grpc_grpclb_request* request) { (drop_entries == nullptr || drop_entries->num_entries == 0); } -static void send_client_load_report_locked(void* arg, grpc_error* error) { +static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "client_load_report"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + "client_load_report"); if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(glb_policy); + maybe_restart_lb_call(exec_ctx, glb_policy); } return; } @@ -1358,7 +1389,7 @@ static void send_client_load_report_locked(void* arg, grpc_error* error) { if (load_report_counters_are_zero(request)) { if (glb_policy->last_client_load_report_counters_were_zero) { grpc_grpclb_request_destroy(request); - schedule_next_client_load_report(glb_policy); + schedule_next_client_load_report(exec_ctx, glb_policy); return; } glb_policy->last_client_load_report_counters_were_zero = true; @@ -1368,7 +1399,7 @@ static void send_client_load_report_locked(void* arg, grpc_error* error) { grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); glb_policy->client_load_report_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_slice_unref_internal(request_payload_slice); + grpc_slice_unref_internal(exec_ctx, request_payload_slice); grpc_grpclb_request_destroy(request); // Send load report message. grpc_op op; @@ -1379,16 +1410,20 @@ static void send_client_load_report_locked(void* arg, grpc_error* error) { client_load_report_done_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); grpc_call_error call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, &op, 1, &glb_policy->client_load_report_closure); + exec_ctx, glb_policy->lb_call, &op, 1, + &glb_policy->client_load_report_closure); if (call_error != GRPC_CALL_OK) { gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", glb_policy, call_error); GPR_ASSERT(GRPC_CALL_OK == call_error); } } -static void lb_on_server_status_received_locked(void* arg, grpc_error* error); -static void lb_on_response_received_locked(void* arg, grpc_error* error); -static void lb_call_init_locked(glb_lb_policy* glb_policy) { +static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error); +static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->server_name != nullptr); GPR_ASSERT(glb_policy->server_name[0] != '\0'); GPR_ASSERT(glb_policy->lb_call == nullptr); @@ -1401,13 +1436,13 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE - : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; + : grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( - glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, + exec_ctx, glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, &host, deadline, nullptr); - grpc_slice_unref_internal(host); + grpc_slice_unref_internal(exec_ctx, host); if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); @@ -1422,7 +1457,7 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); glb_policy->lb_request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_slice_unref_internal(request_payload_slice); + grpc_slice_unref_internal(exec_ctx, request_payload_slice); grpc_grpclb_request_destroy(request); GRPC_CLOSURE_INIT(&glb_policy->lb_on_server_status_received, @@ -1443,7 +1478,8 @@ static void lb_call_init_locked(glb_lb_policy* glb_policy) { glb_policy->last_client_load_report_counters_were_zero = false; } -static void lb_call_destroy_locked(glb_lb_policy* glb_policy) { +static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_unref(glb_policy->lb_call); glb_policy->lb_call = nullptr; @@ -1452,21 +1488,22 @@ static void lb_call_destroy_locked(glb_lb_policy* glb_policy) { grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); grpc_byte_buffer_destroy(glb_policy->lb_request_payload); - grpc_slice_unref_internal(glb_policy->lb_call_status_details); + grpc_slice_unref_internal(exec_ctx, glb_policy->lb_call_status_details); if (glb_policy->client_load_report_timer_pending) { - grpc_timer_cancel(&glb_policy->client_load_report_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->client_load_report_timer); } } /* * Auxiliary functions and LB client callbacks. */ -static void query_for_backends_locked(glb_lb_policy* glb_policy) { +static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_channel != nullptr); if (glb_policy->shutting_down) return; - lb_call_init_locked(glb_policy); + lb_call_init_locked(exec_ctx, glb_policy); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, @@ -1497,8 +1534,8 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { op->flags = 0; op->reserved = nullptr; op++; - call_error = grpc_call_start_batch_and_execute(glb_policy->lb_call, ops, - (size_t)(op - ops), nullptr); + call_error = grpc_call_start_batch_and_execute( + exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); op = ops; @@ -1516,7 +1553,7 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "lb_on_server_status_received_locked"); call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), + exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_server_status_received); GPR_ASSERT(GRPC_CALL_OK == call_error); @@ -1530,12 +1567,13 @@ static void query_for_backends_locked(glb_lb_policy* glb_policy) { * lb_on_response_received_locked */ GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "lb_on_response_received_locked"); call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), + exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_response_received); GPR_ASSERT(GRPC_CALL_OK == call_error); } -static void lb_on_response_received_locked(void* arg, grpc_error* error) { +static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_op ops[2]; memset(ops, 0, sizeof(ops)); @@ -1569,7 +1607,7 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { * send_client_load_report_locked() */ glb_policy->client_load_report_timer_pending = true; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "client_load_report"); - schedule_next_client_load_report(glb_policy); + schedule_next_client_load_report(exec_ctx, glb_policy); } else if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Received initial LB response message; client load " @@ -1614,10 +1652,11 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } else { /* or dispose of the fallback */ - grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(exec_ctx, + glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = nullptr; if (glb_policy->fallback_timer_active) { - grpc_timer_cancel(&glb_policy->lb_fallback_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; } } @@ -1626,7 +1665,7 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { * update or in glb_destroy() */ glb_policy->serverlist = serverlist; glb_policy->serverlist_index = 0; - rr_handover_locked(glb_policy); + rr_handover_locked(exec_ctx, glb_policy); } } else { if (grpc_lb_glb_trace.enabled()) { @@ -1636,14 +1675,14 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { } grpc_grpclb_destroy_serverlist(serverlist); } - } else { /* serverlist == nullptr */ + } else { /* serverlist == NULL */ gpr_log(GPR_ERROR, "[grpclb %p] Invalid LB response received: '%s'. Ignoring.", glb_policy, grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX)); } } - grpc_slice_unref_internal(response_slice); + grpc_slice_unref_internal(exec_ctx, response_slice); if (!glb_policy->shutting_down) { /* keep listening for serverlist updates */ op->op = GRPC_OP_RECV_MESSAGE; @@ -1654,22 +1693,23 @@ static void lb_on_response_received_locked(void* arg, grpc_error* error) { /* reuse the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() */ const grpc_call_error call_error = grpc_call_start_batch_and_execute( - glb_policy->lb_call, ops, (size_t)(op - ops), + exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_response_received); /* loop */ GPR_ASSERT(GRPC_CALL_OK == call_error); } else { - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "lb_on_response_received_locked_shutdown"); } } else { /* empty payload: call cancelled. */ /* dispose of the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() and reused in every reception loop */ - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "lb_on_response_received_locked_empty_payload"); } } -static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { +static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->fallback_timer_active = false; /* If we receive a serverlist after the timer fires but before this callback @@ -1682,13 +1722,15 @@ static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { glb_policy); } GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); - rr_handover_locked(glb_policy); + rr_handover_locked(exec_ctx, glb_policy); } } - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "grpclb_fallback_timer"); + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + "grpclb_fallback_timer"); } -static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { +static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; GPR_ASSERT(glb_policy->lb_call != nullptr); if (grpc_lb_glb_trace.enabled()) { @@ -1702,28 +1744,29 @@ static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { gpr_free(status_details); } /* We need to perform cleanups no matter what. */ - lb_call_destroy_locked(glb_policy); + lb_call_destroy_locked(exec_ctx, glb_policy); // If the load report timer is still pending, we wait for it to be // called before restarting the call. Otherwise, we restart the call // here. if (!glb_policy->client_load_report_timer_pending) { - maybe_restart_lb_call(glb_policy); + maybe_restart_lb_call(exec_ctx, glb_policy); } } -static void fallback_update_locked(glb_lb_policy* glb_policy, +static void fallback_update_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy, const grpc_lb_addresses* addresses) { GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); - grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = - extract_backend_addresses_locked(addresses); + extract_backend_addresses_locked(exec_ctx, addresses); if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->rr_policy != nullptr) { - rr_handover_locked(glb_policy); + rr_handover_locked(exec_ctx, glb_policy); } } -static void glb_update_locked(grpc_lb_policy* policy, +static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_args* args) { glb_lb_policy* glb_policy = (glb_lb_policy*)policy; const grpc_arg* arg = @@ -1733,7 +1776,7 @@ static void glb_update_locked(grpc_lb_policy* policy, // If we don't have a current channel to the LB, go into TRANSIENT // FAILURE. grpc_connectivity_state_set( - &glb_policy->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &glb_policy->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "glb_update_missing"); } else { @@ -1750,16 +1793,16 @@ static void glb_update_locked(grpc_lb_policy* policy, // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. if (glb_policy->serverlist == nullptr) { - fallback_update_locked(glb_policy, addresses); + fallback_update_locked(exec_ctx, glb_policy, addresses); } GPR_ASSERT(glb_policy->lb_channel != nullptr); // Propagate updates to the LB channel (pick_first) through the fake // resolver. grpc_channel_args* lb_channel_args = build_lb_channel_args( - addresses, glb_policy->response_generator, args->args); + exec_ctx, addresses, glb_policy->response_generator, args->args); grpc_fake_resolver_response_generator_set_response( - glb_policy->response_generator, lb_channel_args); - grpc_channel_args_destroy(lb_channel_args); + exec_ctx, glb_policy->response_generator, lb_channel_args); + grpc_channel_args_destroy(exec_ctx, lb_channel_args); // Start watching the LB channel connectivity for connection, if not // already doing so. if (!glb_policy->watching_lb_channel) { @@ -1771,7 +1814,7 @@ static void glb_update_locked(grpc_lb_policy* policy, glb_policy->watching_lb_channel = true; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "watch_lb_channel_connectivity"); grpc_client_channel_watch_connectivity_state( - client_channel_elem, + exec_ctx, client_channel_elem, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, @@ -1782,7 +1825,8 @@ static void glb_update_locked(grpc_lb_policy* policy, // Invoked as part of the update process. It continues watching the LB channel // until it shuts down or becomes READY. It's invoked even if the LB channel // stayed READY throughout the update (for example if the update is identical). -static void glb_lb_channel_on_connectivity_changed_cb(void* arg, +static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (glb_policy->shutting_down) goto done; @@ -1798,7 +1842,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(void* arg, grpc_channel_get_channel_stack(glb_policy->lb_channel)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); grpc_client_channel_watch_connectivity_state( - client_channel_elem, + exec_ctx, client_channel_elem, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, @@ -1817,28 +1861,29 @@ static void glb_lb_channel_on_connectivity_changed_cb(void* arg, // lb_call. } else if (glb_policy->started_picking) { if (glb_policy->retry_timer_active) { - grpc_timer_cancel(&glb_policy->lb_call_retry_timer); + grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); glb_policy->retry_timer_active = false; } - start_picking_locked(glb_policy); + start_picking_locked(exec_ctx, glb_policy); } /* fallthrough */ case GRPC_CHANNEL_SHUTDOWN: done: glb_policy->watching_lb_channel = false; - GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "watch_lb_channel_connectivity_cb_shutdown"); break; } } static void glb_set_reresolve_closure_locked( - grpc_lb_policy* policy, grpc_closure* request_reresolution) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* request_reresolution) { glb_lb_policy* glb_policy = (glb_lb_policy*)policy; GPR_ASSERT(!glb_policy->shutting_down); GPR_ASSERT(glb_policy->base.request_reresolution == nullptr); if (glb_policy->rr_policy != nullptr) { - grpc_lb_policy_set_reresolve_closure_locked(glb_policy->rr_policy, + grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, glb_policy->rr_policy, request_reresolution); } else { glb_policy->base.request_reresolution = request_reresolution; @@ -1859,7 +1904,8 @@ static const grpc_lb_policy_vtable glb_lb_policy_vtable = { glb_update_locked, glb_set_reresolve_closure_locked}; -static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, +static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { /* Count the number of gRPC-LB addresses. There must be at least one. */ const grpc_arg* arg = @@ -1880,7 +1926,7 @@ static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg->type == GRPC_ARG_STRING); - grpc_uri* uri = grpc_uri_parse(arg->value.string, true); + grpc_uri* uri = grpc_uri_parse(exec_ctx, arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); glb_policy->server_name = gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path); @@ -1913,26 +1959,26 @@ static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, /* Extract the backend addresses (may be empty) from the resolver for * fallback. */ glb_policy->fallback_backend_addresses = - extract_backend_addresses_locked(addresses); + extract_backend_addresses_locked(exec_ctx, addresses); /* Create a client channel over them to communicate with a LB service */ glb_policy->response_generator = grpc_fake_resolver_response_generator_create(); grpc_channel_args* lb_channel_args = build_lb_channel_args( - addresses, glb_policy->response_generator, args->args); + exec_ctx, addresses, glb_policy->response_generator, args->args); char* uri_str; gpr_asprintf(&uri_str, "fake:///%s", glb_policy->server_name); glb_policy->lb_channel = grpc_lb_policy_grpclb_create_lb_channel( - uri_str, args->client_channel_factory, lb_channel_args); + exec_ctx, uri_str, args->client_channel_factory, lb_channel_args); /* Propagate initial resolution */ grpc_fake_resolver_response_generator_set_response( - glb_policy->response_generator, lb_channel_args); - grpc_channel_args_destroy(lb_channel_args); + exec_ctx, glb_policy->response_generator, lb_channel_args); + grpc_channel_args_destroy(exec_ctx, lb_channel_args); gpr_free(uri_str); if (glb_policy->lb_channel == nullptr) { gpr_free((void*)glb_policy->server_name); - grpc_channel_args_destroy(glb_policy->args); + grpc_channel_args_destroy(exec_ctx, glb_policy->args); gpr_free(glb_policy); return nullptr; } @@ -1963,7 +2009,7 @@ grpc_lb_policy_factory* grpc_glb_lb_factory_create() { // Only add client_load_reporting filter if the grpclb LB policy is used. static bool maybe_add_client_load_reporting_filter( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* channel_arg = diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc index a8ecea4212..aacaec197d 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc @@ -26,17 +26,17 @@ #include "src/core/lib/support/string.h" grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - const char* lb_service_target_addresses, + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args) { grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( - client_channel_factory, lb_service_target_addresses, + exec_ctx, client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args); return lb_channel; } grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_slice_hash_table* targets_info, + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { const grpc_arg to_add[] = { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h index 56104b2ec0..70b1c28b0d 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h @@ -31,12 +31,12 @@ * \a client_channel_factory will be used for the creation of the LB channel, * alongside the channel args passed in \a args. */ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - const char* lb_service_target_addresses, + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args); grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_slice_hash_table* targets_info, + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 76bcddf945..8eaa90e97b 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -29,7 +29,7 @@ #include "src/core/lib/support/string.h" grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - const char* lb_service_target_addresses, + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args) { grpc_channel_args* new_args = args; @@ -50,19 +50,19 @@ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( new_args = grpc_channel_args_copy_and_add_and_remove( args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add, GPR_ARRAY_SIZE(args_to_add)); - grpc_channel_credentials_unref(creds_sans_call_creds); + grpc_channel_credentials_unref(exec_ctx, creds_sans_call_creds); } grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( - client_channel_factory, lb_service_target_addresses, + exec_ctx, client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); if (channel_credentials != nullptr) { - grpc_channel_args_destroy(new_args); + grpc_channel_args_destroy(exec_ctx, new_args); } return lb_channel; } grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_slice_hash_table* targets_info, + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { const grpc_arg to_add[] = { diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 5e75b64843..228a77d9db 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -57,12 +57,12 @@ typedef struct { grpc_connectivity_state_tracker state_tracker; } pick_first_lb_policy; -static void pf_destroy(grpc_lb_policy* pol) { +static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; GPR_ASSERT(p->subchannel_list == nullptr); GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); GPR_ASSERT(p->pending_picks == nullptr); - grpc_connectivity_state_destroy(&p->state_tracker); + grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); gpr_free(p); grpc_subchannel_index_unref(); if (grpc_lb_pick_first_trace.enabled()) { @@ -70,7 +70,7 @@ static void pf_destroy(grpc_lb_policy* pol) { } } -static void pf_shutdown_locked(grpc_lb_policy* pol) { +static void pf_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_pick_first_trace.enabled()) { @@ -81,27 +81,28 @@ static void pf_shutdown_locked(grpc_lb_policy* pol) { while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_REF(error), "shutdown"); + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), + "shutdown"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_shutdown"); p->subchannel_list = nullptr; } if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - p->latest_pending_subchannel_list, "pf_shutdown"); + exec_ctx, p->latest_pending_subchannel_list, "pf_shutdown"); p->latest_pending_subchannel_list = nullptr; } - grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, + grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_CANCELLED); GRPC_ERROR_UNREF(error); } -static void pf_cancel_pick_locked(grpc_lb_policy* pol, +static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; @@ -111,7 +112,7 @@ static void pf_cancel_pick_locked(grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(pp->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); gpr_free(pp); @@ -124,7 +125,7 @@ static void pf_cancel_pick_locked(grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void pf_cancel_picks_locked(grpc_lb_policy* pol, +static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -135,7 +136,7 @@ static void pf_cancel_picks_locked(grpc_lb_policy* pol, pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - GRPC_CLOSURE_SCHED(pp->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); gpr_free(pp); @@ -148,7 +149,8 @@ static void pf_cancel_picks_locked(grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(pick_first_lb_policy* p) { +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + pick_first_lb_policy* p) { p->started_picking = true; if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) { @@ -158,21 +160,21 @@ static void start_picking_locked(pick_first_lb_policy* p) { grpc_lb_subchannel_list_ref_for_connectivity_watch( p->subchannel_list, "connectivity_watch+start_picking"); grpc_lb_subchannel_data_start_connectivity_watch( - &p->subchannel_list->subchannels[i]); + exec_ctx, &p->subchannel_list->subchannels[i]); break; } } } } -static void pf_exit_idle_locked(grpc_lb_policy* pol) { +static void pf_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (!p->started_picking) { - start_picking_locked(p); + start_picking_locked(exec_ctx, p); } } -static int pf_pick_locked(grpc_lb_policy* pol, +static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, @@ -186,7 +188,7 @@ static int pf_pick_locked(grpc_lb_policy* pol, } // No subchannel selected yet, so handle asynchronously. if (!p->started_picking) { - start_picking_locked(p); + start_picking_locked(exec_ctx, p); } pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; @@ -197,43 +199,48 @@ static int pf_pick_locked(grpc_lb_policy* pol, return 0; } -static void destroy_unselected_subchannels_locked(pick_first_lb_policy* p) { +static void destroy_unselected_subchannels_locked(grpc_exec_ctx* exec_ctx, + pick_first_lb_policy* p) { for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { grpc_lb_subchannel_data* sd = &p->subchannel_list->subchannels[i]; if (p->selected != sd) { - grpc_lb_subchannel_data_unref_subchannel(sd, + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "selected_different_subchannel"); } } } static grpc_connectivity_state pf_check_connectivity_locked( - grpc_lb_policy* pol, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void pf_notify_on_state_change_locked(grpc_lb_policy* pol, +static void pf_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, - notify); + grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, + current, notify); } -static void pf_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { +static void pf_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (p->selected) { - grpc_connected_subchannel_ping(p->selected->connected_subchannel, closure); + grpc_connected_subchannel_ping(exec_ctx, p->selected->connected_subchannel, + closure); } else { - GRPC_CLOSURE_SCHED(closure, + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Not connected")); } } -static void pf_connectivity_changed_locked(void* arg, grpc_error* error); +static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); -static void pf_update_locked(grpc_lb_policy* policy, +static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_args* args) { pick_first_lb_policy* p = (pick_first_lb_policy*)policy; const grpc_arg* arg = @@ -242,7 +249,7 @@ static void pf_update_locked(grpc_lb_policy* policy, if (p->subchannel_list == nullptr) { // If we don't have a current subchannel list, go into TRANSIENT FAILURE. grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "pf_update_missing"); } else { @@ -261,17 +268,17 @@ static void pf_update_locked(grpc_lb_policy* policy, (void*)p, (unsigned long)addresses->num_addresses); } grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( - &p->base, &grpc_lb_pick_first_trace, addresses, args, + exec_ctx, &p->base, &grpc_lb_pick_first_trace, addresses, args, pf_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { // Empty update or no valid subchannels. Unsubscribe from all current // subchannels and put the channel in TRANSIENT_FAILURE. grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "pf_update_empty"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // Empty list. @@ -282,7 +289,7 @@ static void pf_update_locked(grpc_lb_policy* policy, // We don't yet have a selected subchannel, so replace the current // subchannel list immediately. if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_update_before_selected"); } p->subchannel_list = subchannel_list; @@ -307,19 +314,19 @@ static void pf_update_locked(grpc_lb_policy* policy, p->selected = sd; if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - p->subchannel_list, "pf_update_includes_selected"); + exec_ctx, p->subchannel_list, "pf_update_includes_selected"); } p->subchannel_list = subchannel_list; - destroy_unselected_subchannels_locked(p); + destroy_unselected_subchannels_locked(exec_ctx, p); grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+replace_selected"); - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); // If there was a previously pending update (which may or may // not have contained the currently selected subchannel), drop // it, so that it doesn't override what we've done here. if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - p->latest_pending_subchannel_list, + exec_ctx, p->latest_pending_subchannel_list, "pf_update_includes_selected+outdated"); p->latest_pending_subchannel_list = nullptr; } @@ -339,7 +346,8 @@ static void pf_update_locked(grpc_lb_policy* policy, (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( - p->latest_pending_subchannel_list, "sl_outdated_dont_smash"); + exec_ctx, p->latest_pending_subchannel_list, + "sl_outdated_dont_smash"); } p->latest_pending_subchannel_list = subchannel_list; } @@ -349,11 +357,12 @@ static void pf_update_locked(grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+update"); grpc_lb_subchannel_data_start_connectivity_watch( - &subchannel_list->subchannels[0]); + exec_ctx, &subchannel_list->subchannels[0]); } } -static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { +static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy; if (grpc_lb_pick_first_trace.enabled()) { @@ -371,18 +380,18 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { } // If the policy is shutting down, unref and return. if (p->shutdown) { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "pf_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, - "pf_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch( + exec_ctx, sd->subchannel_list, "pf_shutdown"); return; } // If the subchannel list is shutting down, stop watching. if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "pf_sl_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, - "pf_sl_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_sl_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch( + exec_ctx, sd->subchannel_list, "pf_sl_shutdown"); return; } // If we're still here, the notification must be for a subchannel in @@ -398,15 +407,15 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { if (sd->curr_connectivity_state != GRPC_CHANNEL_READY && p->latest_pending_subchannel_list != nullptr) { p->selected = nullptr; - grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); grpc_lb_subchannel_list_unref_for_connectivity_watch( - sd->subchannel_list, "selected_not_ready+switch_to_update"); + exec_ctx, sd->subchannel_list, "selected_not_ready+switch_to_update"); grpc_lb_subchannel_list_shutdown_and_unref( - p->subchannel_list, "selected_not_ready+switch_to_update"); + exec_ctx, p->subchannel_list, "selected_not_ready+switch_to_update"); p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update"); } else { // TODO(juanlishen): we re-resolve when the selected subchannel goes to @@ -417,26 +426,27 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { if (sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN || sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { // If the selected channel goes bad, request a re-resolution. - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, - GRPC_ERROR_NONE, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "selected_changed+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, - GRPC_ERROR_NONE); + grpc_lb_policy_try_reresolve( + exec_ctx, &p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_NONE); } else { - grpc_connectivity_state_set(&p->state_tracker, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, sd->curr_connectivity_state, GRPC_ERROR_REF(error), "selected_changed"); } if (sd->curr_connectivity_state != GRPC_CHANNEL_SHUTDOWN) { // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); } else { p->selected = nullptr; - grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); grpc_lb_subchannel_list_unref_for_connectivity_watch( - sd->subchannel_list, "pf_selected_shutdown"); - grpc_lb_subchannel_data_unref_subchannel(sd, "pf_selected_shutdown"); + exec_ctx, sd->subchannel_list, "pf_selected_shutdown"); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, + "pf_selected_shutdown"); } } return; @@ -456,14 +466,15 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { // p->subchannel_list. if (sd->subchannel_list == p->latest_pending_subchannel_list) { GPR_ASSERT(p->subchannel_list != nullptr); - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "finish_update"); p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; } // Cases 1 and 2. - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_READY, - GRPC_ERROR_NONE, "connecting_ready"); + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_READY, GRPC_ERROR_NONE, + "connecting_ready"); sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( grpc_subchannel_get_connected_subchannel(sd->subchannel), "connected"); @@ -473,7 +484,7 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { (void*)sd->subchannel); } // Drop all other subchannels, since we are now connected. - destroy_unselected_subchannels_locked(p); + destroy_unselected_subchannels_locked(exec_ctx, p); // Update any calls that were waiting for a pick. pending_pick* pp; while ((pp = p->pending_picks)) { @@ -485,15 +496,15 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { "Servicing pending pick with selected subchannel %p", (void*)p->selected); } - GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); break; } case GRPC_CHANNEL_TRANSIENT_FAILURE: { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); do { sd->subchannel_list->checking_subchannel = (sd->subchannel_list->checking_subchannel + 1) % @@ -506,28 +517,29 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { if (sd->subchannel_list->checking_subchannel == 0 && sd->subchannel_list == p->subchannel_list) { grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "connecting_transient_failure"); } // Reuses the connectivity refs from the previous watch. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); break; } case GRPC_CHANNEL_CONNECTING: case GRPC_CHANNEL_IDLE: { // Only update connectivity state in case 1. if (sd->subchannel_list == p->subchannel_list) { - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_CONNECTING, - GRPC_ERROR_REF(error), - "connecting_changed"); + grpc_connectivity_state_set( + exec_ctx, &p->state_tracker, GRPC_CHANNEL_CONNECTING, + GRPC_ERROR_REF(error), "connecting_changed"); } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); break; } case GRPC_CHANNEL_SHUTDOWN: { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "pf_candidate_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, + "pf_candidate_shutdown"); // Advance to next subchannel and check its state. grpc_lb_subchannel_data* original_sd = sd; do { @@ -539,30 +551,31 @@ static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { } while (sd->subchannel == nullptr && sd != original_sd); if (sd == original_sd) { grpc_lb_subchannel_list_unref_for_connectivity_watch( - sd->subchannel_list, "pf_exhausted_subchannels"); + exec_ctx, sd->subchannel_list, "pf_exhausted_subchannels"); if (sd->subchannel_list == p->subchannel_list) { - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, - GRPC_ERROR_NONE, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "exhausted_subchannels+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, - GRPC_ERROR_NONE); + grpc_lb_policy_try_reresolve( + exec_ctx, &p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_NONE); } } else { if (sd->subchannel_list == p->subchannel_list) { grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "subchannel_failed"); } // Reuses the connectivity refs from the previous watch. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); } } } } static void pf_set_reresolve_closure_locked( - grpc_lb_policy* policy, grpc_closure* request_reresolution) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* request_reresolution) { pick_first_lb_policy* p = (pick_first_lb_policy*)policy; GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); @@ -586,14 +599,15 @@ static void pick_first_factory_ref(grpc_lb_policy_factory* factory) {} static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy* create_pick_first(grpc_lb_policy_factory* factory, +static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); } - pf_update_locked(&p->base, args); + pf_update_locked(exec_ctx, &p->base, args); grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); return &p->base; diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 6958b72693..f68daba474 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -154,7 +154,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, } } -static void rr_destroy(grpc_lb_policy* pol) { +static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", @@ -162,12 +162,12 @@ static void rr_destroy(grpc_lb_policy* pol) { } GPR_ASSERT(p->subchannel_list == nullptr); GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); - grpc_connectivity_state_destroy(&p->state_tracker); + grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); grpc_subchannel_index_unref(); gpr_free(p); } -static void rr_shutdown_locked(grpc_lb_policy* pol) { +static void rr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_round_robin_trace.enabled()) { @@ -178,27 +178,29 @@ static void rr_shutdown_locked(grpc_lb_policy* pol) { while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_REF(error), "rr_shutdown"); + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), + "rr_shutdown"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_rr_shutdown"); p->subchannel_list = nullptr; } if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - p->latest_pending_subchannel_list, "sl_shutdown_pending_rr_shutdown"); + exec_ctx, p->latest_pending_subchannel_list, + "sl_shutdown_pending_rr_shutdown"); p->latest_pending_subchannel_list = nullptr; } - grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_round_robin_trace, + grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_round_robin_trace, GRPC_ERROR_CANCELLED); GRPC_ERROR_UNREF(error); } -static void rr_cancel_pick_locked(grpc_lb_policy* pol, +static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; @@ -208,7 +210,7 @@ static void rr_cancel_pick_locked(grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(pp->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); gpr_free(pp); @@ -221,7 +223,7 @@ static void rr_cancel_pick_locked(grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void rr_cancel_picks_locked(grpc_lb_policy* pol, +static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -233,7 +235,7 @@ static void rr_cancel_picks_locked(grpc_lb_policy* pol, if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { *pp->target = nullptr; - GRPC_CLOSURE_SCHED(pp->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); gpr_free(pp); @@ -246,26 +248,27 @@ static void rr_cancel_picks_locked(grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(round_robin_lb_policy* p) { +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + round_robin_lb_policy* p) { p->started_picking = true; for (size_t i = 0; i < p->subchannel_list->num_subchannels; i++) { if (p->subchannel_list->subchannels[i].subchannel != nullptr) { grpc_lb_subchannel_list_ref_for_connectivity_watch(p->subchannel_list, "connectivity_watch"); grpc_lb_subchannel_data_start_connectivity_watch( - &p->subchannel_list->subchannels[i]); + exec_ctx, &p->subchannel_list->subchannels[i]); } } } -static void rr_exit_idle_locked(grpc_lb_policy* pol) { +static void rr_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (!p->started_picking) { - start_picking_locked(p); + start_picking_locked(exec_ctx, p); } } -static int rr_pick_locked(grpc_lb_policy* pol, +static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, @@ -302,7 +305,7 @@ static int rr_pick_locked(grpc_lb_policy* pol, } /* no pick currently available. Save for later in list of pending picks */ if (!p->started_picking) { - start_picking_locked(p); + start_picking_locked(exec_ctx, p); } pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; @@ -345,7 +348,8 @@ static void update_state_counters_locked(grpc_lb_subchannel_data* sd) { * (the grpc_lb_subchannel_data associated with the updated subchannel) and the * subchannel list \a sd belongs to (sd->subchannel_list). \a error will be used * only if the policy transitions to state TRANSIENT_FAILURE. */ -static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, +static void update_lb_connectivity_status_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_data* sd, grpc_error* error) { /* In priority order. The first rule to match terminates the search (ie, if we * are on rule n, all previous rules were unfulfilled). @@ -378,36 +382,38 @@ static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, round_robin_lb_policy* p = (round_robin_lb_policy*)subchannel_list->policy; if (subchannel_list->num_ready > 0) { /* 1) READY */ - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_READY, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "rr_ready"); } else if (sd->curr_connectivity_state == GRPC_CHANNEL_CONNECTING) { /* 2) CONNECTING */ - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_CONNECTING, - GRPC_ERROR_NONE, "rr_connecting"); + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, + "rr_connecting"); } else if (subchannel_list->num_shutdown == subchannel_list->num_subchannels) { /* 3) IDLE and re-resolve */ - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "rr_exhausted_subchannels+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_round_robin_trace, + grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_round_robin_trace, GRPC_ERROR_NONE); } else if (subchannel_list->num_transient_failures == subchannel_list->num_subchannels) { /* 4) TRANSIENT_FAILURE */ - grpc_connectivity_state_set(&p->state_tracker, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "rr_transient_failure"); } else if (subchannel_list->num_idle == subchannel_list->num_subchannels) { /* 5) IDLE */ - grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, + grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "rr_idle"); } GRPC_ERROR_UNREF(error); } -static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { +static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; round_robin_lb_policy* p = (round_robin_lb_policy*)sd->subchannel_list->policy; @@ -425,18 +431,18 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { } // If the policy is shutting down, unref and return. if (p->shutdown) { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "rr_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, - "rr_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "rr_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch( + exec_ctx, sd->subchannel_list, "rr_shutdown"); return; } // If the subchannel list is shutting down, stop watching. if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "rr_sl_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, - "rr_sl_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "rr_sl_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch( + exec_ctx, sd->subchannel_list, "rr_sl_shutdown"); return; } // If we're still here, the notification must be for a subchannel in @@ -449,13 +455,14 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { sd->curr_connectivity_state = sd->pending_connectivity_state_unsafe; // Update state counters and new overall state. update_state_counters_locked(sd); - update_lb_connectivity_status_locked(sd, GRPC_ERROR_REF(error)); + update_lb_connectivity_status_locked(exec_ctx, sd, GRPC_ERROR_REF(error)); // If the sd's new state is SHUTDOWN, unref the subchannel. if (sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN) { - grpc_lb_subchannel_data_stop_connectivity_watch(sd); - grpc_lb_subchannel_data_unref_subchannel(sd, "rr_connectivity_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, + "rr_connectivity_shutdown"); grpc_lb_subchannel_list_unref_for_connectivity_watch( - sd->subchannel_list, "rr_connectivity_shutdown"); + exec_ctx, sd->subchannel_list, "rr_connectivity_shutdown"); } else { // sd not in SHUTDOWN if (sd->curr_connectivity_state == GRPC_CHANNEL_READY) { if (sd->connected_subchannel == nullptr) { @@ -483,8 +490,8 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { } if (p->subchannel_list != nullptr) { // dispose of the current subchannel_list - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, - "sl_phase_out_shutdown"); + grpc_lb_subchannel_list_shutdown_and_unref( + exec_ctx, p->subchannel_list, "sl_phase_out_shutdown"); } p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; @@ -516,30 +523,32 @@ static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { (void*)p, (void*)selected->subchannel, (void*)p->subchannel_list, (unsigned long)next_ready_index); } - GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); } } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(sd); + grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); } } static grpc_connectivity_state rr_check_connectivity_locked( - grpc_lb_policy* pol, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void rr_notify_on_state_change_locked(grpc_lb_policy* pol, +static void rr_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, - notify); + grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, + current, notify); } -static void rr_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { +static void rr_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { @@ -547,15 +556,16 @@ static void rr_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { &p->subchannel_list->subchannels[next_ready_index]; grpc_connected_subchannel* target = GRPC_CONNECTED_SUBCHANNEL_REF( selected->connected_subchannel, "rr_ping"); - grpc_connected_subchannel_ping(target, closure); - GRPC_CONNECTED_SUBCHANNEL_UNREF(target, "rr_ping"); + grpc_connected_subchannel_ping(exec_ctx, target, closure); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, target, "rr_ping"); } else { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Round Robin not connected")); + GRPC_CLOSURE_SCHED( + exec_ctx, closure, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Round Robin not connected")); } } -static void rr_update_locked(grpc_lb_policy* policy, +static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, const grpc_lb_policy_args* args) { round_robin_lb_policy* p = (round_robin_lb_policy*)policy; const grpc_arg* arg = @@ -566,7 +576,7 @@ static void rr_update_locked(grpc_lb_policy* policy, // Otherwise, keep using the current subchannel list (ignore this update). if (p->subchannel_list == nullptr) { grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "rr_update_missing"); } @@ -578,15 +588,15 @@ static void rr_update_locked(grpc_lb_policy* policy, addresses->num_addresses); } grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( - &p->base, &grpc_lb_round_robin_trace, addresses, args, + exec_ctx, &p->base, &grpc_lb_round_robin_trace, addresses, args, rr_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { grpc_connectivity_state_set( - &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "rr_update_empty"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // empty list @@ -602,7 +612,7 @@ static void rr_update_locked(grpc_lb_policy* policy, (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( - p->latest_pending_subchannel_list, "sl_outdated"); + exec_ctx, p->latest_pending_subchannel_list, "sl_outdated"); } p->latest_pending_subchannel_list = subchannel_list; for (size_t i = 0; i < subchannel_list->num_subchannels; ++i) { @@ -613,21 +623,22 @@ static void rr_update_locked(grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch(subchannel_list, "connectivity_watch"); grpc_lb_subchannel_data_start_connectivity_watch( - &subchannel_list->subchannels[i]); + exec_ctx, &subchannel_list->subchannels[i]); } } else { // The policy isn't picking yet. Save the update for later, disposing of // previous version if any. if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - p->subchannel_list, "rr_update_before_started_picking"); + exec_ctx, p->subchannel_list, "rr_update_before_started_picking"); } p->subchannel_list = subchannel_list; } } static void rr_set_reresolve_closure_locked( - grpc_lb_policy* policy, grpc_closure* request_reresolution) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* request_reresolution) { round_robin_lb_policy* p = (round_robin_lb_policy*)policy; GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); @@ -651,7 +662,8 @@ static void round_robin_factory_ref(grpc_lb_policy_factory* factory) {} static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, +static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); @@ -659,7 +671,7 @@ static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, grpc_subchannel_index_ref(); grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, "round_robin"); - rr_update_locked(&p->base, args); + rr_update_locked(exec_ctx, &p->base, args); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void*)p, (unsigned long)p->subchannel_list->num_subchannels); diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index a3b4c8e524..b6fce4d207 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -28,7 +28,8 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, +void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_data* sd, const char* reason) { if (sd->subchannel != nullptr) { if (sd->subchannel_list->tracer->enabled()) { @@ -40,22 +41,23 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); } - GRPC_SUBCHANNEL_UNREF(sd->subchannel, reason); + GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, reason); sd->subchannel = nullptr; if (sd->connected_subchannel != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(sd->connected_subchannel, reason); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, sd->connected_subchannel, + reason); sd->connected_subchannel = nullptr; } if (sd->user_data != nullptr) { GPR_ASSERT(sd->user_data_vtable != nullptr); - sd->user_data_vtable->destroy(sd->user_data); + sd->user_data_vtable->destroy(exec_ctx, sd->user_data); sd->user_data = nullptr; } } } void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_lb_subchannel_data* sd) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -67,13 +69,13 @@ void grpc_lb_subchannel_data_start_connectivity_watch( } sd->connectivity_notification_pending = true; grpc_subchannel_notify_on_state_change( - sd->subchannel, sd->subchannel_list->policy->interested_parties, + exec_ctx, sd->subchannel, sd->subchannel_list->policy->interested_parties, &sd->pending_connectivity_state_unsafe, &sd->connectivity_changed_closure); } void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_lb_subchannel_data* sd) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -88,7 +90,7 @@ void grpc_lb_subchannel_data_stop_connectivity_watch( } grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_lb_policy* p, grpc_core::TraceFlag* tracer, + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { grpc_lb_subchannel_list* subchannel_list = @@ -122,8 +124,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( gpr_free(addr_arg.value.string); sc_args.args = new_args; grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel( - args->client_channel_factory, &sc_args); - grpc_channel_args_destroy(new_args); + exec_ctx, args->client_channel_factory, &sc_args); + grpc_channel_args_destroy(exec_ctx, new_args); if (subchannel == nullptr) { // Subchannel could not be created. if (tracer->enabled()) { @@ -170,7 +172,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( return subchannel_list; } -static void subchannel_list_destroy(grpc_lb_subchannel_list* subchannel_list) { +static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list) { if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", subchannel_list->tracer->name(), subchannel_list->policy, @@ -178,7 +181,8 @@ static void subchannel_list_destroy(grpc_lb_subchannel_list* subchannel_list) { } for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; - grpc_lb_subchannel_data_unref_subchannel(sd, "subchannel_list_destroy"); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, + "subchannel_list_destroy"); } gpr_free(subchannel_list->subchannels); gpr_free(subchannel_list); @@ -196,7 +200,8 @@ void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, } } -void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, +void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list, const char* reason) { const bool done = gpr_unref(&subchannel_list->refcount); if (subchannel_list->tracer->enabled()) { @@ -207,7 +212,7 @@ void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, reason); } if (done) { - subchannel_list_destroy(subchannel_list); + subchannel_list_destroy(exec_ctx, subchannel_list); } } @@ -218,13 +223,14 @@ void grpc_lb_subchannel_list_ref_for_connectivity_watch( } void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_lb_subchannel_list* subchannel_list, const char* reason) { - GRPC_LB_POLICY_WEAK_UNREF(subchannel_list->policy, reason); - grpc_lb_subchannel_list_unref(subchannel_list, reason); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason) { + GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, subchannel_list->policy, reason); + grpc_lb_subchannel_list_unref(exec_ctx, subchannel_list, reason); } static void subchannel_data_cancel_connectivity_watch( - grpc_lb_subchannel_data* sd, const char* reason) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -234,12 +240,14 @@ static void subchannel_data_cancel_connectivity_watch( (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } - grpc_subchannel_notify_on_state_change(sd->subchannel, nullptr, nullptr, + grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, + nullptr, &sd->connectivity_changed_closure); } void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_lb_subchannel_list* subchannel_list, const char* reason) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason) { if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)", subchannel_list->tracer->name(), subchannel_list->policy, @@ -253,10 +261,10 @@ void grpc_lb_subchannel_list_shutdown_and_unref( // the callback is responsible for unreffing the subchannel. // Otherwise, unref the subchannel directly. if (sd->connectivity_notification_pending) { - subchannel_data_cancel_connectivity_watch(sd, reason); + subchannel_data_cancel_connectivity_watch(exec_ctx, sd, reason); } else if (sd->subchannel != nullptr) { - grpc_lb_subchannel_data_unref_subchannel(sd, reason); + grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, reason); } } - grpc_lb_subchannel_list_unref(subchannel_list, reason); + grpc_lb_subchannel_list_unref(exec_ctx, subchannel_list, reason); } diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index 0f8cea9347..e3e5eba56a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -65,7 +65,8 @@ typedef struct { } grpc_lb_subchannel_data; /// Unrefs the subchannel contained in sd. -void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, +void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_data* sd, const char* reason); /// Starts watching the connectivity state of the subchannel. @@ -73,11 +74,11 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, /// grpc_lb_subchannel_data_stop_connectivity_watch() or again call /// grpc_lb_subchannel_data_start_connectivity_watch(). void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_lb_subchannel_data* sd); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); /// Stops watching the connectivity state of the subchannel. void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_lb_subchannel_data* sd); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); struct grpc_lb_subchannel_list { /** backpointer to owning policy */ @@ -116,14 +117,15 @@ struct grpc_lb_subchannel_list { }; grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_lb_policy* p, grpc_core::TraceFlag* tracer, + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb); void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, const char* reason); -void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, +void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list, const char* reason); /// Takes and releases refs needed for a connectivity notification. @@ -131,11 +133,13 @@ void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, void grpc_lb_subchannel_list_ref_for_connectivity_watch( grpc_lb_subchannel_list* subchannel_list, const char* reason); void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_lb_subchannel_list* subchannel_list, const char* reason); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason); /// Mark subchannel_list as discarded. Unsubscribes all its subchannels. The /// connectivity state notification callback will ultimately unref it. void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_lb_subchannel_list* subchannel_list, const char* reason); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_SUBCHANNEL_LIST_H */ diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.cc b/src/core/ext/filters/client_channel/lb_policy_factory.cc index dbf69fdcba..d43f9fd1b9 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.cc +++ b/src/core/ext/filters/client_channel/lb_policy_factory.cc @@ -112,11 +112,13 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, return 0; } -void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { +void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_addresses* addresses) { for (size_t i = 0; i < addresses->num_addresses; ++i) { gpr_free(addresses->addresses[i].balancer_name); if (addresses->addresses[i].user_data != nullptr) { - addresses->user_data_vtable->destroy(addresses->addresses[i].user_data); + addresses->user_data_vtable->destroy(exec_ctx, + addresses->addresses[i].user_data); } } gpr_free(addresses->addresses); @@ -126,8 +128,8 @@ void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { static void* lb_addresses_copy(void* addresses) { return grpc_lb_addresses_copy((grpc_lb_addresses*)addresses); } -static void lb_addresses_destroy(void* addresses) { - grpc_lb_addresses_destroy((grpc_lb_addresses*)addresses); +static void lb_addresses_destroy(grpc_exec_ctx* exec_ctx, void* addresses) { + grpc_lb_addresses_destroy(exec_ctx, (grpc_lb_addresses*)addresses); } static int lb_addresses_cmp(void* addresses1, void* addresses2) { return grpc_lb_addresses_cmp((grpc_lb_addresses*)addresses1, @@ -160,7 +162,8 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory) { } grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( - grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args) { if (factory == nullptr) return nullptr; - return factory->vtable->create_lb_policy(factory, args); + return factory->vtable->create_lb_policy(exec_ctx, factory, args); } diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.h b/src/core/ext/filters/client_channel/lb_policy_factory.h index 9da231b657..8f6d8c1b08 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.h +++ b/src/core/ext/filters/client_channel/lb_policy_factory.h @@ -50,7 +50,7 @@ typedef struct grpc_lb_address { typedef struct grpc_lb_user_data_vtable { void* (*copy)(void*); - void (*destroy)(void*); + void (*destroy)(grpc_exec_ctx* exec_ctx, void*); int (*cmp)(void*, void*); } grpc_lb_user_data_vtable; @@ -91,7 +91,8 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, const grpc_lb_addresses* addresses2); /** Destroys \a addresses. */ -void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses); +void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_addresses* addresses); /** Returns a channel arg containing \a addresses. */ grpc_arg grpc_lb_addresses_create_channel_arg( @@ -113,7 +114,8 @@ struct grpc_lb_policy_factory_vtable { void (*unref)(grpc_lb_policy_factory* factory); /** Implementation of grpc_lb_policy_factory_create_lb_policy */ - grpc_lb_policy* (*create_lb_policy)(grpc_lb_policy_factory* factory, + grpc_lb_policy* (*create_lb_policy)(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args); /** Name for the LB policy this factory implements */ @@ -125,6 +127,7 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory); /** Create a lb_policy instance. */ grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( - grpc_lb_policy_factory* factory, grpc_lb_policy_args* args); + grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_FACTORY_H */ diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.cc b/src/core/ext/filters/client_channel/lb_policy_registry.cc index edd0330c6a..6e710e86d9 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.cc +++ b/src/core/ext/filters/client_channel/lb_policy_registry.cc @@ -61,10 +61,10 @@ static grpc_lb_policy_factory* lookup_factory(const char* name) { return nullptr; } -grpc_lb_policy* grpc_lb_policy_create(const char* name, +grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, grpc_lb_policy_args* args) { grpc_lb_policy_factory* factory = lookup_factory(name); grpc_lb_policy* lb_policy = - grpc_lb_policy_factory_create_lb_policy(factory, args); + grpc_lb_policy_factory_create_lb_policy(exec_ctx, factory, args); return lb_policy; } diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.h b/src/core/ext/filters/client_channel/lb_policy_registry.h index 5aff79376b..acddc90fdd 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.h +++ b/src/core/ext/filters/client_channel/lb_policy_registry.h @@ -34,7 +34,7 @@ void grpc_register_lb_policy(grpc_lb_policy_factory* factory); * * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init * will be returned. */ -grpc_lb_policy* grpc_lb_policy_create(const char* name, +grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, grpc_lb_policy_args* args); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_REGISTRY_H */ diff --git a/src/core/ext/filters/client_channel/proxy_mapper.cc b/src/core/ext/filters/client_channel/proxy_mapper.cc index be85cfcced..c6ea5fc680 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper.cc +++ b/src/core/ext/filters/client_channel/proxy_mapper.cc @@ -23,22 +23,24 @@ void grpc_proxy_mapper_init(const grpc_proxy_mapper_vtable* vtable, mapper->vtable = vtable; } -bool grpc_proxy_mapper_map_name(grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { - return mapper->vtable->map_name(mapper, server_uri, args, name_to_resolve, - new_args); + return mapper->vtable->map_name(exec_ctx, mapper, server_uri, args, + name_to_resolve, new_args); } -bool grpc_proxy_mapper_map_address(grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args) { - return mapper->vtable->map_address(mapper, address, args, new_address, - new_args); + return mapper->vtable->map_address(exec_ctx, mapper, address, args, + new_address, new_args); } void grpc_proxy_mapper_destroy(grpc_proxy_mapper* mapper) { diff --git a/src/core/ext/filters/client_channel/proxy_mapper.h b/src/core/ext/filters/client_channel/proxy_mapper.h index ce3e65ee46..a13861ccaf 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper.h +++ b/src/core/ext/filters/client_channel/proxy_mapper.h @@ -32,14 +32,14 @@ typedef struct { /// If no proxy is needed, returns false. /// Otherwise, sets \a name_to_resolve, optionally sets \a new_args, /// and returns true. - bool (*map_name)(grpc_proxy_mapper* mapper, const char* server_uri, - const grpc_channel_args* args, char** name_to_resolve, - grpc_channel_args** new_args); + bool (*map_name)(grpc_exec_ctx* exec_ctx, grpc_proxy_mapper* mapper, + const char* server_uri, const grpc_channel_args* args, + char** name_to_resolve, grpc_channel_args** new_args); /// Determines the proxy address to use to contact \a address. /// If no proxy is needed, returns false. /// Otherwise, sets \a new_address, optionally sets \a new_args, and /// returns true. - bool (*map_address)(grpc_proxy_mapper* mapper, + bool (*map_address)(grpc_exec_ctx* exec_ctx, grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, @@ -55,13 +55,15 @@ struct grpc_proxy_mapper { void grpc_proxy_mapper_init(const grpc_proxy_mapper_vtable* vtable, grpc_proxy_mapper* mapper); -bool grpc_proxy_mapper_map_name(grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args); -bool grpc_proxy_mapper_map_address(grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, diff --git a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc index 51778a20cc..09967eea3c 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +++ b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc @@ -46,13 +46,14 @@ static void grpc_proxy_mapper_list_register(grpc_proxy_mapper_list* list, ++list->num_mappers; } -static bool grpc_proxy_mapper_list_map_name(grpc_proxy_mapper_list* list, +static bool grpc_proxy_mapper_list_map_name(grpc_exec_ctx* exec_ctx, + grpc_proxy_mapper_list* list, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { for (size_t i = 0; i < list->num_mappers; ++i) { - if (grpc_proxy_mapper_map_name(list->list[i], server_uri, args, + if (grpc_proxy_mapper_map_name(exec_ctx, list->list[i], server_uri, args, name_to_resolve, new_args)) { return true; } @@ -61,12 +62,12 @@ static bool grpc_proxy_mapper_list_map_name(grpc_proxy_mapper_list* list, } static bool grpc_proxy_mapper_list_map_address( - grpc_proxy_mapper_list* list, const grpc_resolved_address* address, - const grpc_channel_args* args, grpc_resolved_address** new_address, - grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_proxy_mapper_list* list, + const grpc_resolved_address* address, const grpc_channel_args* args, + grpc_resolved_address** new_address, grpc_channel_args** new_args) { for (size_t i = 0; i < list->num_mappers; ++i) { - if (grpc_proxy_mapper_map_address(list->list[i], address, args, new_address, - new_args)) { + if (grpc_proxy_mapper_map_address(exec_ctx, list->list[i], address, args, + new_address, new_args)) { return true; } } @@ -104,17 +105,20 @@ void grpc_proxy_mapper_register(bool at_start, grpc_proxy_mapper* mapper) { grpc_proxy_mapper_list_register(&g_proxy_mapper_list, at_start, mapper); } -bool grpc_proxy_mappers_map_name(const char* server_uri, +bool grpc_proxy_mappers_map_name(grpc_exec_ctx* exec_ctx, + const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { - return grpc_proxy_mapper_list_map_name(&g_proxy_mapper_list, server_uri, args, - name_to_resolve, new_args); + return grpc_proxy_mapper_list_map_name(exec_ctx, &g_proxy_mapper_list, + server_uri, args, name_to_resolve, + new_args); } -bool grpc_proxy_mappers_map_address(const grpc_resolved_address* address, +bool grpc_proxy_mappers_map_address(grpc_exec_ctx* exec_ctx, + const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args) { - return grpc_proxy_mapper_list_map_address(&g_proxy_mapper_list, address, args, - new_address, new_args); + return grpc_proxy_mapper_list_map_address( + exec_ctx, &g_proxy_mapper_list, address, args, new_address, new_args); } diff --git a/src/core/ext/filters/client_channel/proxy_mapper_registry.h b/src/core/ext/filters/client_channel/proxy_mapper_registry.h index 2ad6c04e1d..99e54d1a78 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper_registry.h +++ b/src/core/ext/filters/client_channel/proxy_mapper_registry.h @@ -29,12 +29,14 @@ void grpc_proxy_mapper_registry_shutdown(); /// the list. Otherwise, it will be added to the end. void grpc_proxy_mapper_register(bool at_start, grpc_proxy_mapper* mapper); -bool grpc_proxy_mappers_map_name(const char* server_uri, +bool grpc_proxy_mappers_map_name(grpc_exec_ctx* exec_ctx, + const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args); -bool grpc_proxy_mappers_map_address(const grpc_resolved_address* address, +bool grpc_proxy_mappers_map_address(grpc_exec_ctx* exec_ctx, + const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args); diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index ff54e7179d..c16b1515c7 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -46,8 +46,8 @@ void grpc_resolver_ref(grpc_resolver* resolver) { } #ifndef NDEBUG -void grpc_resolver_unref(grpc_resolver* resolver, const char* file, int line, - const char* reason) { +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + const char* file, int line, const char* reason) { if (grpc_trace_resolver_refcount.enabled()) { gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -55,25 +55,27 @@ void grpc_resolver_unref(grpc_resolver* resolver, const char* file, int line, old_refs, old_refs - 1, reason); } #else -void grpc_resolver_unref(grpc_resolver* resolver) { +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { #endif if (gpr_unref(&resolver->refs)) { grpc_combiner* combiner = resolver->combiner; - resolver->vtable->destroy(resolver); - GRPC_COMBINER_UNREF(combiner, "resolver"); + resolver->vtable->destroy(exec_ctx, resolver); + GRPC_COMBINER_UNREF(exec_ctx, combiner, "resolver"); } } -void grpc_resolver_shutdown_locked(grpc_resolver* resolver) { - resolver->vtable->shutdown_locked(resolver); +void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + resolver->vtable->shutdown_locked(exec_ctx, resolver); } -void grpc_resolver_channel_saw_error_locked(grpc_resolver* resolver) { - resolver->vtable->channel_saw_error_locked(resolver); +void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + resolver->vtable->channel_saw_error_locked(exec_ctx, resolver); } -void grpc_resolver_next_locked(grpc_resolver* resolver, +void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { - resolver->vtable->next_locked(resolver, result, on_complete); + resolver->vtable->next_locked(exec_ctx, resolver, result, on_complete); } diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index f6a4af01d6..4e8cfbe417 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -35,40 +35,43 @@ struct grpc_resolver { }; struct grpc_resolver_vtable { - void (*destroy)(grpc_resolver* resolver); - void (*shutdown_locked)(grpc_resolver* resolver); - void (*channel_saw_error_locked)(grpc_resolver* resolver); - void (*next_locked)(grpc_resolver* resolver, grpc_channel_args** result, - grpc_closure* on_complete); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); + void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); + void (*channel_saw_error_locked)(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); + void (*next_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + grpc_channel_args** result, grpc_closure* on_complete); }; #ifndef NDEBUG #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_RESOLVER_UNREF(p, r) \ - grpc_resolver_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_RESOLVER_UNREF(e, p, r) \ + grpc_resolver_unref((e), (p), __FILE__, __LINE__, (r)) void grpc_resolver_ref(grpc_resolver* policy, const char* file, int line, const char* reason); -void grpc_resolver_unref(grpc_resolver* policy, const char* file, int line, - const char* reason); +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy, + const char* file, int line, const char* reason); #else #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) -#define GRPC_RESOLVER_UNREF(p, r) grpc_resolver_unref((p)) +#define GRPC_RESOLVER_UNREF(e, p, r) grpc_resolver_unref((e), (p)) void grpc_resolver_ref(grpc_resolver* policy); -void grpc_resolver_unref(grpc_resolver* policy); +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy); #endif void grpc_resolver_init(grpc_resolver* resolver, const grpc_resolver_vtable* vtable, grpc_combiner* combiner); -void grpc_resolver_shutdown_locked(grpc_resolver* resolver); +void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); /** Notification that the channel has seen an error on some address. Can be used as a hint that re-resolution is desirable soon. Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_channel_saw_error_locked(grpc_resolver* resolver); +void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); /** Get the next result from the resolver. Expected to set \a *result with new channel args and then schedule \a on_complete for execution. @@ -78,7 +81,7 @@ void grpc_resolver_channel_saw_error_locked(grpc_resolver* resolver); Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_next_locked(grpc_resolver* resolver, +void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 4ec4477c82..3a16b3492d 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -97,14 +97,17 @@ typedef struct { char* service_config_json; } ares_dns_resolver; -static void dns_ares_destroy(grpc_resolver* r); +static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_ares_start_resolving_locked(ares_dns_resolver* r); -static void dns_ares_maybe_finish_next_locked(ares_dns_resolver* r); +static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r); +static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r); -static void dns_ares_shutdown_locked(grpc_resolver* r); -static void dns_ares_channel_saw_error_locked(grpc_resolver* r); -static void dns_ares_next_locked(grpc_resolver* r, +static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); @@ -112,39 +115,43 @@ static const grpc_resolver_vtable dns_ares_resolver_vtable = { dns_ares_destroy, dns_ares_shutdown_locked, dns_ares_channel_saw_error_locked, dns_ares_next_locked}; -static void dns_ares_shutdown_locked(grpc_resolver* resolver) { +static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (r->have_retry_timer) { - grpc_timer_cancel(&r->retry_timer); + grpc_timer_cancel(exec_ctx, &r->retry_timer); } if (r->pending_request != nullptr) { - grpc_cancel_ares_request(r->pending_request); + grpc_cancel_ares_request(exec_ctx, r->pending_request); } if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Resolver Shutdown")); + GRPC_CLOSURE_SCHED( + exec_ctx, r->next_completion, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); r->next_completion = nullptr; } } -static void dns_ares_channel_saw_error_locked(grpc_resolver* resolver) { +static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_ares_start_resolving_locked(r); + dns_ares_start_resolving_locked(exec_ctx, r); } } -static void dns_ares_on_retry_timer_locked(void* arg, grpc_error* error) { +static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { if (!r->resolving) { - dns_ares_start_resolving_locked(r); + dns_ares_start_resolving_locked(exec_ctx, r); } } - GRPC_RESOLVER_UNREF(&r->base, "retry-timer"); + GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); } static bool value_in_json_array(grpc_json* array, const char* value) { @@ -219,7 +226,8 @@ static char* choose_service_config(char* service_config_choice_json) { return service_config; } -static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { +static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); @@ -260,13 +268,13 @@ static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { num_args_to_add); if (service_config != nullptr) grpc_service_config_destroy(service_config); gpr_free(service_config_string); - grpc_lb_addresses_destroy(r->lb_addresses); + grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); } else { const char* msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = - grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); + grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; + grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); @@ -277,19 +285,20 @@ static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { } else { gpr_log(GPR_DEBUG, "retrying immediately"); } - grpc_timer_init(&r->retry_timer, next_try, + grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->dns_ares_on_retry_timer_locked); } if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(r->resolved_result); + grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; r->resolved_version++; - dns_ares_maybe_finish_next_locked(r); - GRPC_RESOLVER_UNREF(&r->base, "dns-resolving"); + dns_ares_maybe_finish_next_locked(exec_ctx, r); + GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); } -static void dns_ares_next_locked(grpc_resolver* resolver, +static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { gpr_log(GPR_DEBUG, "dns_ares_next is called."); @@ -299,53 +308,56 @@ static void dns_ares_next_locked(grpc_resolver* resolver, r->target_result = target_result; if (r->resolved_version == 0 && !r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_ares_start_resolving_locked(r); + dns_ares_start_resolving_locked(exec_ctx, r); } else { - dns_ares_maybe_finish_next_locked(r); + dns_ares_maybe_finish_next_locked(exec_ctx, r); } } -static void dns_ares_start_resolving_locked(ares_dns_resolver* r) { +static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; r->lb_addresses = nullptr; r->service_config_json = nullptr; r->pending_request = grpc_dns_lookup_ares( - r->dns_server, r->name_to_resolve, r->default_port, r->interested_parties, - &r->dns_ares_on_resolved_locked, &r->lb_addresses, + exec_ctx, r->dns_server, r->name_to_resolve, r->default_port, + r->interested_parties, &r->dns_ares_on_resolved_locked, &r->lb_addresses, true /* check_grpclb */, r->request_service_config ? &r->service_config_json : nullptr); } -static void dns_ares_maybe_finish_next_locked(ares_dns_resolver* r) { +static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r) { if (r->next_completion != nullptr && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == nullptr ? nullptr : grpc_channel_args_copy(r->resolved_result); gpr_log(GPR_DEBUG, "dns_ares_maybe_finish_next_locked"); - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; r->published_version = r->resolved_version; } } -static void dns_ares_destroy(grpc_resolver* gr) { +static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); ares_dns_resolver* r = (ares_dns_resolver*)gr; if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(r->resolved_result); + grpc_channel_args_destroy(exec_ctx, r->resolved_result); } - grpc_pollset_set_destroy(r->interested_parties); + grpc_pollset_set_destroy(exec_ctx, r->interested_parties); gpr_free(r->dns_server); gpr_free(r->name_to_resolve); gpr_free(r->default_port); - grpc_channel_args_destroy(r->channel_args); + grpc_channel_args_destroy(exec_ctx, r->channel_args); gpr_free(r); } -static grpc_resolver* dns_ares_create(grpc_resolver_args* args, +static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, const char* default_port) { /* Get name from args. */ const char* path = args->uri->path; @@ -366,7 +378,8 @@ static grpc_resolver* dns_ares_create(grpc_resolver_args* args, arg, (grpc_integer_options){false, false, true}); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != nullptr) { - grpc_pollset_set_add_pollset_set(r->interested_parties, args->pollset_set); + grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, + args->pollset_set); } grpc_backoff_init( &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, @@ -391,8 +404,9 @@ static void dns_ares_factory_ref(grpc_resolver_factory* factory) {} static void dns_ares_factory_unref(grpc_resolver_factory* factory) {} static grpc_resolver* dns_factory_create_resolver( - grpc_resolver_factory* factory, grpc_resolver_args* args) { - return dns_ares_create(args, "https"); + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args) { + return dns_ares_create(exec_ctx, args, "https"); } static char* dns_ares_factory_get_default_host_name( diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h index ba7dad63cf..03ea36bfcc 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h @@ -28,7 +28,8 @@ typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; /* Start \a ev_driver. It will keep working until all IO on its ares_channel is done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks bound to its ares_channel when necessary. */ -void grpc_ares_ev_driver_start(grpc_ares_ev_driver* ev_driver); +void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); /* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to \a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the @@ -46,7 +47,8 @@ grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver); /* Shutdown all the grpc_fds used by \a ev_driver */ -void grpc_ares_ev_driver_shutdown(grpc_ares_ev_driver* ev_driver); +void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \ */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index 40e264504c..4cb068a41d 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -77,7 +77,8 @@ struct grpc_ares_ev_driver { bool shutting_down; }; -static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver); +static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); static grpc_ares_ev_driver* grpc_ares_ev_driver_ref( grpc_ares_ev_driver* ev_driver) { @@ -97,7 +98,7 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { } } -static void fd_node_destroy(fd_node* fdn) { +static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { gpr_log(GPR_DEBUG, "delete fd: %d", grpc_fd_wrapped_fd(fdn->fd)); GPR_ASSERT(!fdn->readable_registered); GPR_ASSERT(!fdn->writable_registered); @@ -105,20 +106,21 @@ static void fd_node_destroy(fd_node* fdn) { /* c-ares library has closed the fd inside grpc_fd. This fd may be picked up immediately by another thread, and should not be closed by the following grpc_fd_orphan. */ - grpc_fd_orphan(fdn->fd, nullptr, nullptr, true /* already_closed */, + grpc_fd_orphan(exec_ctx, fdn->fd, nullptr, nullptr, true /* already_closed */, "c-ares query finished"); gpr_free(fdn); } -static void fd_node_shutdown(fd_node* fdn) { +static void fd_node_shutdown(grpc_exec_ctx* exec_ctx, fd_node* fdn) { gpr_mu_lock(&fdn->mu); fdn->shutting_down = true; if (!fdn->readable_registered && !fdn->writable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(fdn); + fd_node_destroy(exec_ctx, fdn); } else { grpc_fd_shutdown( - fdn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("c-ares fd shutdown")); + exec_ctx, fdn->fd, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("c-ares fd shutdown")); gpr_mu_unlock(&fdn->mu); } } @@ -158,13 +160,15 @@ void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver) { grpc_ares_ev_driver_unref(ev_driver); } -void grpc_ares_ev_driver_shutdown(grpc_ares_ev_driver* ev_driver) { +void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); ev_driver->shutting_down = true; fd_node* fn = ev_driver->fds; while (fn != nullptr) { - grpc_fd_shutdown(fn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "grpc_ares_ev_driver_shutdown")); + grpc_fd_shutdown( + exec_ctx, fn->fd, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_ares_ev_driver_shutdown")); fn = fn->next; } gpr_mu_unlock(&ev_driver->mu); @@ -195,7 +199,8 @@ static bool grpc_ares_is_fd_still_readable(grpc_ares_ev_driver* ev_driver, return ioctl(fd, FIONREAD, &bytes_available) == 0 && bytes_available > 0; } -static void on_readable_cb(void* arg, grpc_error* error) { +static void on_readable_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { fd_node* fdn = (fd_node*)arg; grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); @@ -203,7 +208,7 @@ static void on_readable_cb(void* arg, grpc_error* error) { fdn->readable_registered = false; if (fdn->shutting_down && !fdn->writable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(fdn); + fd_node_destroy(exec_ctx, fdn); grpc_ares_ev_driver_unref(ev_driver); return; } @@ -224,12 +229,13 @@ static void on_readable_cb(void* arg, grpc_error* error) { ares_cancel(ev_driver->channel); } gpr_mu_lock(&ev_driver->mu); - grpc_ares_notify_on_event_locked(ev_driver); + grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); gpr_mu_unlock(&ev_driver->mu); grpc_ares_ev_driver_unref(ev_driver); } -static void on_writable_cb(void* arg, grpc_error* error) { +static void on_writable_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { fd_node* fdn = (fd_node*)arg; grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); @@ -237,7 +243,7 @@ static void on_writable_cb(void* arg, grpc_error* error) { fdn->writable_registered = false; if (fdn->shutting_down && !fdn->readable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(fdn); + fd_node_destroy(exec_ctx, fdn); grpc_ares_ev_driver_unref(ev_driver); return; } @@ -256,7 +262,7 @@ static void on_writable_cb(void* arg, grpc_error* error) { ares_cancel(ev_driver->channel); } gpr_mu_lock(&ev_driver->mu); - grpc_ares_notify_on_event_locked(ev_driver); + grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); gpr_mu_unlock(&ev_driver->mu); grpc_ares_ev_driver_unref(ev_driver); } @@ -267,7 +273,8 @@ ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver) { // Get the file descriptors used by the ev_driver's ares channel, register // driver_closure with these filedescriptors. -static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { +static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { fd_node* new_list = nullptr; if (!ev_driver->shutting_down) { ares_socket_t socks[ARES_GETSOCK_MAXNUM]; @@ -293,7 +300,7 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&fdn->write_closure, on_writable_cb, fdn, grpc_schedule_on_exec_ctx); - grpc_pollset_set_add_fd(ev_driver->pollset_set, fdn->fd); + grpc_pollset_set_add_fd(exec_ctx, ev_driver->pollset_set, fdn->fd); gpr_free(fd_name); } fdn->next = new_list; @@ -305,7 +312,7 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { !fdn->readable_registered) { grpc_ares_ev_driver_ref(ev_driver); gpr_log(GPR_DEBUG, "notify read on: %d", grpc_fd_wrapped_fd(fdn->fd)); - grpc_fd_notify_on_read(fdn->fd, &fdn->read_closure); + grpc_fd_notify_on_read(exec_ctx, fdn->fd, &fdn->read_closure); fdn->readable_registered = true; } // Register write_closure if the socket is writable and write_closure @@ -315,7 +322,7 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { gpr_log(GPR_DEBUG, "notify write on: %d", grpc_fd_wrapped_fd(fdn->fd)); grpc_ares_ev_driver_ref(ev_driver); - grpc_fd_notify_on_write(fdn->fd, &fdn->write_closure); + grpc_fd_notify_on_write(exec_ctx, fdn->fd, &fdn->write_closure); fdn->writable_registered = true; } gpr_mu_unlock(&fdn->mu); @@ -328,7 +335,7 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { while (ev_driver->fds != nullptr) { fd_node* cur = ev_driver->fds; ev_driver->fds = ev_driver->fds->next; - fd_node_shutdown(cur); + fd_node_shutdown(exec_ctx, cur); } ev_driver->fds = new_list; // If the ev driver has no working fd, all the tasks are done. @@ -338,11 +345,12 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { } } -void grpc_ares_ev_driver_start(grpc_ares_ev_driver* ev_driver) { +void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); if (!ev_driver->working) { ev_driver->working = true; - grpc_ares_notify_on_event_locked(ev_driver); + grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); } gpr_mu_unlock(&ev_driver->mu); } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 3a870b2d06..7846576c11 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -96,12 +96,24 @@ static void grpc_ares_request_ref(grpc_ares_request* r) { gpr_ref(&r->pending_queries); } -static void grpc_ares_request_unref(grpc_ares_request* r) { +static void grpc_ares_request_unref(grpc_exec_ctx* exec_ctx, + grpc_ares_request* r) { /* If there are no pending queries, invoke on_done callback and destroy the request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - GRPC_CLOSURE_SCHED(r->on_done, r->error); + if (exec_ctx == nullptr) { + /* A new exec_ctx is created here, as the c-ares interface does not + provide one in ares_host_callback. It's safe to schedule on_done with + the newly created exec_ctx, since the caller has been warned not to + acquire locks in on_done. ares_dns_resolver is using combiner to + protect resources needed by on_done. */ + grpc_exec_ctx new_exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CLOSURE_SCHED(&new_exec_ctx, r->on_done, r->error); + grpc_exec_ctx_finish(&new_exec_ctx); + } else { + GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, r->error); + } gpr_mu_destroy(&r->mu); grpc_ares_ev_driver_destroy(r->ev_driver); gpr_free(r); @@ -121,8 +133,9 @@ static grpc_ares_hostbyname_request* create_hostbyname_request( return hr; } -static void destroy_hostbyname_request(grpc_ares_hostbyname_request* hr) { - grpc_ares_request_unref(hr->parent_request); +static void destroy_hostbyname_request(grpc_exec_ctx* exec_ctx, + grpc_ares_hostbyname_request* hr) { + grpc_ares_request_unref(exec_ctx, hr->parent_request); gpr_free(hr->host); gpr_free(hr); } @@ -207,13 +220,13 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, } } gpr_mu_unlock(&r->mu); - destroy_hostbyname_request(hr); + destroy_hostbyname_request(nullptr, hr); } static void on_srv_query_done_cb(void* arg, int status, int timeouts, unsigned char* abuf, int alen) { grpc_ares_request* r = (grpc_ares_request*)arg; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { gpr_log(GPR_DEBUG, "on_query_srv_done_cb ARES_SUCCESS"); @@ -233,7 +246,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, r, srv_it->host, htons(srv_it->port), true /* is_balancer */); ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_cb, hr); - grpc_ares_ev_driver_start(r->ev_driver); + grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); } } if (reply != nullptr) { @@ -251,7 +264,8 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, r->error = grpc_error_add_child(error, r->error); } } - grpc_ares_request_unref(r); + grpc_ares_request_unref(&exec_ctx, r); + grpc_exec_ctx_finish(&exec_ctx); } static const char g_service_config_attribute_prefix[] = "grpc_config="; @@ -309,13 +323,14 @@ fail: } done: gpr_mu_unlock(&r->mu); - grpc_ares_request_unref(r); + grpc_ares_request_unref(nullptr, r); } static grpc_ares_request* grpc_dns_lookup_ares_impl( - const char* dns_server, const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) { + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) { grpc_error* error = GRPC_ERROR_NONE; grpc_ares_hostbyname_request* hr = nullptr; grpc_ares_request* r = nullptr; @@ -422,28 +437,28 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( gpr_free(config_name); } /* TODO(zyc): Handle CNAME records here. */ - grpc_ares_ev_driver_start(r->ev_driver); - grpc_ares_request_unref(r); + grpc_ares_ev_driver_start(exec_ctx, r->ev_driver); + grpc_ares_request_unref(exec_ctx, r); gpr_free(host); gpr_free(port); return r; error_cleanup: - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); gpr_free(host); gpr_free(port); return nullptr; } grpc_ares_request* (*grpc_dns_lookup_ares)( - const char* dns_server, const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addrs, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_ares_request* r) { +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) { if (grpc_dns_lookup_ares == grpc_dns_lookup_ares_impl) { - grpc_ares_ev_driver_shutdown(r->ev_driver); + grpc_ares_ev_driver_shutdown(exec_ctx, r->ev_driver); } } @@ -486,7 +501,8 @@ typedef struct grpc_resolve_address_ares_request { grpc_closure on_dns_lookup_done; } grpc_resolve_address_ares_request; -static void on_dns_lookup_done_cb(void* arg, grpc_error* error) { +static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_resolve_address_ares_request* r = (grpc_resolve_address_ares_request*)arg; grpc_resolved_addresses** resolved_addresses = r->addrs_out; @@ -504,12 +520,14 @@ static void on_dns_lookup_done_cb(void* arg, grpc_error* error) { &r->lb_addrs->addresses[i].address, sizeof(grpc_resolved_address)); } } - GRPC_CLOSURE_SCHED(r->on_resolve_address_done, GRPC_ERROR_REF(error)); - grpc_lb_addresses_destroy(r->lb_addrs); + GRPC_CLOSURE_SCHED(exec_ctx, r->on_resolve_address_done, + GRPC_ERROR_REF(error)); + grpc_lb_addresses_destroy(exec_ctx, r->lb_addrs); gpr_free(r); } -static void grpc_resolve_address_ares_impl(const char* name, +static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -521,14 +539,14 @@ static void grpc_resolve_address_ares_impl(const char* name, r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, grpc_schedule_on_exec_ctx); - grpc_dns_lookup_ares(nullptr /* dns_server */, name, default_port, + grpc_dns_lookup_ares(exec_ctx, nullptr /* dns_server */, name, default_port, interested_parties, &r->on_dns_lookup_done, &r->lb_addrs, false /* check_grpclb */, nullptr /* service_config_json */); } void (*grpc_resolve_address_ares)( - const char* name, const char* default_port, + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h index 86d870e0a6..72db622954 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h @@ -32,7 +32,8 @@ typedef struct grpc_ares_request grpc_ares_request; must be called at least once before this function. \a on_done may be called directly in this function without being scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ -extern void (*grpc_resolve_address_ares)(const char* name, +extern void (*grpc_resolve_address_ares)(grpc_exec_ctx* exec_ctx, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -46,13 +47,14 @@ extern void (*grpc_resolve_address_ares)(const char* name, scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ extern grpc_ares_request* (*grpc_dns_lookup_ares)( - const char* dns_server, const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addresses, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, char** service_config_json); /* Cancel the pending grpc_ares_request \a request */ -void grpc_cancel_ares_request(grpc_ares_request* request); +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, + grpc_ares_request* request); /* Initialize gRPC ares wrapper. Must be called at least once before grpc_resolve_address_ares(). */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc index a184cf2d57..a68a7c47fb 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc @@ -26,32 +26,34 @@ struct grpc_ares_request { }; static grpc_ares_request* grpc_dns_lookup_ares_impl( - const char* dns_server, const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) { + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) { return NULL; } grpc_ares_request* (*grpc_dns_lookup_ares)( - const char* dns_server, const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addrs, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_ares_request* r) {} +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) {} grpc_error* grpc_ares_init(void) { return GRPC_ERROR_NONE; } void grpc_ares_cleanup(void) {} -static void grpc_resolve_address_ares_impl(const char* name, +static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) {} void (*grpc_resolve_address_ares)( - const char* name, const char* default_port, + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 77698e97aa..fc40ce6966 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -76,42 +76,49 @@ typedef struct { grpc_resolved_addresses* addresses; } dns_resolver; -static void dns_destroy(grpc_resolver* r); +static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_start_resolving_locked(dns_resolver* r); -static void dns_maybe_finish_next_locked(dns_resolver* r); +static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r); +static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r); -static void dns_shutdown_locked(grpc_resolver* r); -static void dns_channel_saw_error_locked(grpc_resolver* r); -static void dns_next_locked(grpc_resolver* r, grpc_channel_args** target_result, +static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, + grpc_channel_args** target_result, grpc_closure* on_complete); static const grpc_resolver_vtable dns_resolver_vtable = { dns_destroy, dns_shutdown_locked, dns_channel_saw_error_locked, dns_next_locked}; -static void dns_shutdown_locked(grpc_resolver* resolver) { +static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { dns_resolver* r = (dns_resolver*)resolver; if (r->have_retry_timer) { - grpc_timer_cancel(&r->retry_timer); + grpc_timer_cancel(exec_ctx, &r->retry_timer); } if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Resolver Shutdown")); + GRPC_CLOSURE_SCHED( + exec_ctx, r->next_completion, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); r->next_completion = nullptr; } } -static void dns_channel_saw_error_locked(grpc_resolver* resolver) { +static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { dns_resolver* r = (dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_start_resolving_locked(r); + dns_start_resolving_locked(exec_ctx, r); } } -static void dns_next_locked(grpc_resolver* resolver, +static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { dns_resolver* r = (dns_resolver*)resolver; @@ -120,26 +127,28 @@ static void dns_next_locked(grpc_resolver* resolver, r->target_result = target_result; if (r->resolved_version == 0 && !r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_start_resolving_locked(r); + dns_start_resolving_locked(exec_ctx, r); } else { - dns_maybe_finish_next_locked(r); + dns_maybe_finish_next_locked(exec_ctx, r); } } -static void dns_on_retry_timer_locked(void* arg, grpc_error* error) { +static void dns_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { dns_resolver* r = (dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { if (!r->resolving) { - dns_start_resolving_locked(r); + dns_start_resolving_locked(exec_ctx, r); } } - GRPC_RESOLVER_UNREF(&r->base, "retry-timer"); + GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); } -static void dns_on_resolved_locked(void* arg, grpc_error* error) { +static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { dns_resolver* r = (dns_resolver*)arg; grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); @@ -159,11 +168,11 @@ static void dns_on_resolved_locked(void* arg, grpc_error* error) { grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); grpc_resolved_addresses_destroy(r->addresses); - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(exec_ctx, addresses); } else { grpc_millis next_try = - grpc_backoff_step(&r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); + grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; + grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); @@ -176,56 +185,59 @@ static void dns_on_resolved_locked(void* arg, grpc_error* error) { } GRPC_CLOSURE_INIT(&r->on_retry, dns_on_retry_timer_locked, r, grpc_combiner_scheduler(r->base.combiner)); - grpc_timer_init(&r->retry_timer, next_try, &r->on_retry); + grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->on_retry); } if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(r->resolved_result); + grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; r->resolved_version++; - dns_maybe_finish_next_locked(r); + dns_maybe_finish_next_locked(exec_ctx, r); GRPC_ERROR_UNREF(error); - GRPC_RESOLVER_UNREF(&r->base, "dns-resolving"); + GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); } -static void dns_start_resolving_locked(dns_resolver* r) { +static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; r->addresses = nullptr; grpc_resolve_address( - r->name_to_resolve, r->default_port, r->interested_parties, + exec_ctx, r->name_to_resolve, r->default_port, r->interested_parties, GRPC_CLOSURE_CREATE(dns_on_resolved_locked, r, grpc_combiner_scheduler(r->base.combiner)), &r->addresses); } -static void dns_maybe_finish_next_locked(dns_resolver* r) { +static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r) { if (r->next_completion != nullptr && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == nullptr ? nullptr : grpc_channel_args_copy(r->resolved_result); - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; r->published_version = r->resolved_version; } } -static void dns_destroy(grpc_resolver* gr) { +static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { dns_resolver* r = (dns_resolver*)gr; if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(r->resolved_result); + grpc_channel_args_destroy(exec_ctx, r->resolved_result); } - grpc_pollset_set_destroy(r->interested_parties); + grpc_pollset_set_destroy(exec_ctx, r->interested_parties); gpr_free(r->name_to_resolve); gpr_free(r->default_port); - grpc_channel_args_destroy(r->channel_args); + grpc_channel_args_destroy(exec_ctx, r->channel_args); gpr_free(r); } -static grpc_resolver* dns_create(grpc_resolver_args* args, +static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, const char* default_port) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based dns uri's not supported"); @@ -242,7 +254,8 @@ static grpc_resolver* dns_create(grpc_resolver_args* args, r->channel_args = grpc_channel_args_copy(args->args); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != nullptr) { - grpc_pollset_set_add_pollset_set(r->interested_parties, args->pollset_set); + grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, + args->pollset_set); } grpc_backoff_init( &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, @@ -261,8 +274,9 @@ static void dns_factory_ref(grpc_resolver_factory* factory) {} static void dns_factory_unref(grpc_resolver_factory* factory) {} static grpc_resolver* dns_factory_create_resolver( - grpc_resolver_factory* factory, grpc_resolver_args* args) { - return dns_create(args, "https"); + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args) { + return dns_create(exec_ctx, args, "https"); } static char* dns_factory_get_default_host_name(grpc_resolver_factory* factory, diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc index fe3ad1403c..44798ca434 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -67,52 +67,57 @@ typedef struct { grpc_channel_args** target_result; } fake_resolver; -static void fake_resolver_destroy(grpc_resolver* gr) { +static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { fake_resolver* r = (fake_resolver*)gr; - grpc_channel_args_destroy(r->next_results); - grpc_channel_args_destroy(r->results_upon_error); - grpc_channel_args_destroy(r->channel_args); + grpc_channel_args_destroy(exec_ctx, r->next_results); + grpc_channel_args_destroy(exec_ctx, r->results_upon_error); + grpc_channel_args_destroy(exec_ctx, r->channel_args); gpr_free(r); } -static void fake_resolver_shutdown_locked(grpc_resolver* resolver) { +static void fake_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Resolver Shutdown")); + GRPC_CLOSURE_SCHED( + exec_ctx, r->next_completion, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); r->next_completion = nullptr; } } -static void fake_resolver_maybe_finish_next_locked(fake_resolver* r) { +static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + fake_resolver* r) { if (r->next_completion != nullptr && r->next_results != nullptr) { *r->target_result = grpc_channel_args_union(r->next_results, r->channel_args); - grpc_channel_args_destroy(r->next_results); + grpc_channel_args_destroy(exec_ctx, r->next_results); r->next_results = nullptr; - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; } } -static void fake_resolver_channel_saw_error_locked(grpc_resolver* resolver) { +static void fake_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; if (r->next_results == nullptr && r->results_upon_error != nullptr) { // Pretend we re-resolved. r->next_results = grpc_channel_args_copy(r->results_upon_error); } - fake_resolver_maybe_finish_next_locked(r); + fake_resolver_maybe_finish_next_locked(exec_ctx, r); } -static void fake_resolver_next_locked(grpc_resolver* resolver, +static void fake_resolver_next_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { fake_resolver* r = (fake_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; - fake_resolver_maybe_finish_next_locked(r); + fake_resolver_maybe_finish_next_locked(exec_ctx, r); } static const grpc_resolver_vtable fake_resolver_vtable = { @@ -152,31 +157,33 @@ typedef struct set_response_closure_arg { grpc_channel_args* next_response; } set_response_closure_arg; -static void set_response_closure_fn(void* arg, grpc_error* error) { +static void set_response_closure_fn(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { set_response_closure_arg* closure_arg = (set_response_closure_arg*)arg; grpc_fake_resolver_response_generator* generator = closure_arg->generator; fake_resolver* r = generator->resolver; if (r->next_results != nullptr) { - grpc_channel_args_destroy(r->next_results); + grpc_channel_args_destroy(exec_ctx, r->next_results); } r->next_results = closure_arg->next_response; if (r->results_upon_error != nullptr) { - grpc_channel_args_destroy(r->results_upon_error); + grpc_channel_args_destroy(exec_ctx, r->results_upon_error); } r->results_upon_error = grpc_channel_args_copy(closure_arg->next_response); gpr_free(closure_arg); - fake_resolver_maybe_finish_next_locked(r); + fake_resolver_maybe_finish_next_locked(exec_ctx, r); } void grpc_fake_resolver_response_generator_set_response( - grpc_fake_resolver_response_generator* generator, + grpc_exec_ctx* exec_ctx, grpc_fake_resolver_response_generator* generator, grpc_channel_args* next_response) { GPR_ASSERT(generator->resolver != nullptr); set_response_closure_arg* closure_arg = (set_response_closure_arg*)gpr_zalloc(sizeof(*closure_arg)); closure_arg->generator = generator; closure_arg->next_response = grpc_channel_args_copy(next_response); - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, + GRPC_CLOSURE_SCHED(exec_ctx, + GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, set_response_closure_fn, closure_arg, grpc_combiner_scheduler( generator->resolver->base.combiner)), @@ -188,7 +195,7 @@ static void* response_generator_arg_copy(void* p) { (grpc_fake_resolver_response_generator*)p); } -static void response_generator_arg_destroy(void* p) { +static void response_generator_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { grpc_fake_resolver_response_generator_unref( (grpc_fake_resolver_response_generator*)p); } @@ -225,7 +232,8 @@ static void fake_resolver_factory_ref(grpc_resolver_factory* factory) {} static void fake_resolver_factory_unref(grpc_resolver_factory* factory) {} -static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, +static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_factory* factory, grpc_resolver_args* args) { fake_resolver* r = (fake_resolver*)gpr_zalloc(sizeof(*r)); r->channel_args = grpc_channel_args_copy(args->args); diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h index a8977e5980..7035cdda01 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h @@ -39,7 +39,7 @@ grpc_fake_resolver_response_generator_create(); // Instruct the fake resolver associated with the \a response_generator instance // to trigger a new resolution for \a uri and \a args. void grpc_fake_resolver_response_generator_set_response( - grpc_fake_resolver_response_generator* generator, + grpc_exec_ctx* exec_ctx, grpc_fake_resolver_response_generator* generator, grpc_channel_args* next_response); // Return a \a grpc_arg for a \a grpc_fake_resolver_response_generator instance. diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc index 7d1e283fa3..f0934b5943 100644 --- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc @@ -52,13 +52,15 @@ typedef struct { grpc_channel_args** target_result; } sockaddr_resolver; -static void sockaddr_destroy(grpc_resolver* r); +static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void sockaddr_maybe_finish_next_locked(sockaddr_resolver* r); +static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + sockaddr_resolver* r); -static void sockaddr_shutdown_locked(grpc_resolver* r); -static void sockaddr_channel_saw_error_locked(grpc_resolver* r); -static void sockaddr_next_locked(grpc_resolver* r, +static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); @@ -66,47 +68,52 @@ static const grpc_resolver_vtable sockaddr_resolver_vtable = { sockaddr_destroy, sockaddr_shutdown_locked, sockaddr_channel_saw_error_locked, sockaddr_next_locked}; -static void sockaddr_shutdown_locked(grpc_resolver* resolver) { +static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Resolver Shutdown")); + GRPC_CLOSURE_SCHED( + exec_ctx, r->next_completion, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); r->next_completion = nullptr; } } -static void sockaddr_channel_saw_error_locked(grpc_resolver* resolver) { +static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; r->published = false; - sockaddr_maybe_finish_next_locked(r); + sockaddr_maybe_finish_next_locked(exec_ctx, r); } -static void sockaddr_next_locked(grpc_resolver* resolver, +static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; - sockaddr_maybe_finish_next_locked(r); + sockaddr_maybe_finish_next_locked(exec_ctx, r); } -static void sockaddr_maybe_finish_next_locked(sockaddr_resolver* r) { +static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + sockaddr_resolver* r) { if (r->next_completion != nullptr && !r->published) { r->published = true; grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); *r->target_result = grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); - GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; } } -static void sockaddr_destroy(grpc_resolver* gr) { +static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { sockaddr_resolver* r = (sockaddr_resolver*)gr; - grpc_lb_addresses_destroy(r->addresses); - grpc_channel_args_destroy(r->channel_args); + grpc_lb_addresses_destroy(exec_ctx, r->addresses); + grpc_channel_args_destroy(exec_ctx, r->channel_args); gpr_free(r); } @@ -135,7 +142,8 @@ char* unix_get_default_authority(grpc_resolver_factory* factory, static void do_nothing(void* ignored) {} -static grpc_resolver* sockaddr_create(grpc_resolver_args* args, +static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) { if (0 != strcmp(args->uri->authority, "")) { @@ -162,10 +170,10 @@ static grpc_resolver* sockaddr_create(grpc_resolver_args* args, gpr_free(part_str); if (errors_found) break; } - grpc_slice_buffer_destroy_internal(&path_parts); - grpc_slice_unref_internal(path_slice); + grpc_slice_buffer_destroy_internal(exec_ctx, &path_parts); + grpc_slice_unref_internal(exec_ctx, path_slice); if (errors_found) { - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(exec_ctx, addresses); return nullptr; } /* Instantiate resolver. */ @@ -187,8 +195,9 @@ static void sockaddr_factory_unref(grpc_resolver_factory* factory) {} #define DECL_FACTORY(name) \ static grpc_resolver* name##_factory_create_resolver( \ - grpc_resolver_factory* factory, grpc_resolver_args* args) { \ - return sockaddr_create(args, grpc_parse_##name); \ + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, \ + grpc_resolver_args* args) { \ + return sockaddr_create(exec_ctx, args, grpc_parse_##name); \ } \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \ sockaddr_factory_ref, sockaddr_factory_unref, \ diff --git a/src/core/ext/filters/client_channel/resolver_factory.cc b/src/core/ext/filters/client_channel/resolver_factory.cc index 9b3ec2f1c4..1a289d9771 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.cc +++ b/src/core/ext/filters/client_channel/resolver_factory.cc @@ -28,9 +28,10 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* factory) { /** Create a resolver instance for a name */ grpc_resolver* grpc_resolver_factory_create_resolver( - grpc_resolver_factory* factory, grpc_resolver_args* args) { + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args) { if (factory == nullptr) return nullptr; - return factory->vtable->create_resolver(factory, args); + return factory->vtable->create_resolver(exec_ctx, factory, args); } char* grpc_resolver_factory_get_default_authority( diff --git a/src/core/ext/filters/client_channel/resolver_factory.h b/src/core/ext/filters/client_channel/resolver_factory.h index 170ecc0b48..fcf8ec425e 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.h +++ b/src/core/ext/filters/client_channel/resolver_factory.h @@ -43,7 +43,8 @@ struct grpc_resolver_factory_vtable { void (*unref)(grpc_resolver_factory* factory); /** Implementation of grpc_resolver_factory_create_resolver */ - grpc_resolver* (*create_resolver)(grpc_resolver_factory* factory, + grpc_resolver* (*create_resolver)(grpc_exec_ctx* exec_ctx, + grpc_resolver_factory* factory, grpc_resolver_args* args); /** Implementation of grpc_resolver_factory_get_default_authority */ @@ -58,7 +59,8 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* resolver); /** Create a resolver instance for a name */ grpc_resolver* grpc_resolver_factory_create_resolver( - grpc_resolver_factory* factory, grpc_resolver_args* args); + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args); /** Return a (freshly allocated with gpr_malloc) string representing the default authority to use for this scheme. */ diff --git a/src/core/ext/filters/client_channel/resolver_registry.cc b/src/core/ext/filters/client_channel/resolver_registry.cc index 3f8451de6b..5da6114a3d 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.cc +++ b/src/core/ext/filters/client_channel/resolver_registry.cc @@ -92,22 +92,23 @@ static grpc_resolver_factory* lookup_factory_by_uri(grpc_uri* uri) { return lookup_factory(uri->scheme); } -static grpc_resolver_factory* resolve_factory(const char* target, +static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx, + const char* target, grpc_uri** uri, char** canonical_target) { grpc_resolver_factory* factory = nullptr; GPR_ASSERT(uri != nullptr); - *uri = grpc_uri_parse(target, 1); + *uri = grpc_uri_parse(exec_ctx, target, 1); factory = lookup_factory_by_uri(*uri); if (factory == nullptr) { grpc_uri_destroy(*uri); gpr_asprintf(canonical_target, "%s%s", g_default_resolver_prefix, target); - *uri = grpc_uri_parse(*canonical_target, 1); + *uri = grpc_uri_parse(exec_ctx, *canonical_target, 1); factory = lookup_factory_by_uri(*uri); if (factory == nullptr) { - grpc_uri_destroy(grpc_uri_parse(target, 0)); - grpc_uri_destroy(grpc_uri_parse(*canonical_target, 0)); + grpc_uri_destroy(grpc_uri_parse(exec_ctx, target, 0)); + grpc_uri_destroy(grpc_uri_parse(exec_ctx, *canonical_target, 0)); gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, *canonical_target); } @@ -115,14 +116,14 @@ static grpc_resolver_factory* resolve_factory(const char* target, return factory; } -grpc_resolver* grpc_resolver_create(const char* target, +grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, const grpc_channel_args* args, grpc_pollset_set* pollset_set, grpc_combiner* combiner) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; grpc_resolver_factory* factory = - resolve_factory(target, &uri, &canonical_target); + resolve_factory(exec_ctx, target, &uri, &canonical_target); grpc_resolver* resolver; grpc_resolver_args resolver_args; memset(&resolver_args, 0, sizeof(resolver_args)); @@ -130,27 +131,29 @@ grpc_resolver* grpc_resolver_create(const char* target, resolver_args.args = args; resolver_args.pollset_set = pollset_set; resolver_args.combiner = combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &resolver_args); + resolver = + grpc_resolver_factory_create_resolver(exec_ctx, factory, &resolver_args); grpc_uri_destroy(uri); gpr_free(canonical_target); return resolver; } -char* grpc_get_default_authority(const char* target) { +char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; grpc_resolver_factory* factory = - resolve_factory(target, &uri, &canonical_target); + resolve_factory(exec_ctx, target, &uri, &canonical_target); char* authority = grpc_resolver_factory_get_default_authority(factory, uri); grpc_uri_destroy(uri); gpr_free(canonical_target); return authority; } -char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target) { +char* grpc_resolver_factory_add_default_prefix_if_needed( + grpc_exec_ctx* exec_ctx, const char* target) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; - resolve_factory(target, &uri, &canonical_target); + resolve_factory(exec_ctx, target, &uri, &canonical_target); grpc_uri_destroy(uri); return canonical_target == nullptr ? gpr_strdup(target) : canonical_target; } diff --git a/src/core/ext/filters/client_channel/resolver_registry.h b/src/core/ext/filters/client_channel/resolver_registry.h index bbd30df8da..ecc9f824e8 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.h +++ b/src/core/ext/filters/client_channel/resolver_registry.h @@ -48,7 +48,7 @@ void grpc_register_resolver_type(grpc_resolver_factory* factory); (typically the set of arguments passed in from the client API). \a pollset_set is used to drive IO in the name resolution process, it should not be NULL. */ -grpc_resolver* grpc_resolver_create(const char* target, +grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, const grpc_channel_args* args, grpc_pollset_set* pollset_set, grpc_combiner* combiner); @@ -59,10 +59,11 @@ grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name); /** Given a target, return a (freshly allocated with gpr_malloc) string representing the default authority to pass from a client. */ -char* grpc_get_default_authority(const char* target); +char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target); /** Returns a newly allocated string containing \a target, adding the default prefix if needed. */ -char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target); +char* grpc_resolver_factory_add_default_prefix_if_needed( + grpc_exec_ctx* exec_ctx, const char* target); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H */ diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 0d2be2a3f7..58e294d597 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -139,7 +139,8 @@ struct grpc_subchannel_call { #define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ (((grpc_subchannel_call*)(callstack)) - 1) -static void subchannel_connected(void* subchannel, grpc_error* error); +static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel, + grpc_error* error); #ifndef NDEBUG #define REF_REASON reason @@ -156,9 +157,10 @@ static void subchannel_connected(void* subchannel, grpc_error* error); * connection implementation */ -static void connection_destroy(void* arg, grpc_error* error) { +static void connection_destroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_connected_subchannel* c = (grpc_connected_subchannel*)arg; - grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CONNECTION(c)); + grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); gpr_free(c); } @@ -168,23 +170,26 @@ grpc_connected_subchannel* grpc_connected_subchannel_ref( return c; } -void grpc_connected_subchannel_unref( - grpc_connected_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); +void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), + REF_REASON); } /* * grpc_subchannel implementation */ -static void subchannel_destroy(void* arg, grpc_error* error) { +static void subchannel_destroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; gpr_free((void*)c->filters); - grpc_channel_args_destroy(c->args); - grpc_connectivity_state_destroy(&c->state_tracker); - grpc_connector_unref(c->connector); - grpc_pollset_set_destroy(c->pollset_set); - grpc_subchannel_key_destroy(c->key); + grpc_channel_args_destroy(exec_ctx, c->args); + grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); + grpc_connector_unref(exec_ctx, c->connector); + grpc_pollset_set_destroy(exec_ctx, c->pollset_set); + grpc_subchannel_key_destroy(exec_ctx, c->key); gpr_mu_destroy(&c->mu); gpr_free(c); } @@ -236,54 +241,59 @@ grpc_subchannel* grpc_subchannel_ref_from_weak_ref( } } -static void disconnect(grpc_subchannel* c) { +static void disconnect(grpc_exec_ctx* exec_ctx, grpc_subchannel* c) { grpc_connected_subchannel* con; - grpc_subchannel_index_unregister(c->key, c); + grpc_subchannel_index_unregister(exec_ctx, c->key, c); gpr_mu_lock(&c->mu); GPR_ASSERT(!c->disconnected); c->disconnected = true; - grpc_connector_shutdown(c->connector, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Subchannel disconnected")); + grpc_connector_shutdown( + exec_ctx, c->connector, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected")); con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); if (con != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(con, "connection"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef); } gpr_mu_unlock(&c->mu); } -void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; // add a weak ref and subtract a strong ref (atomically) old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { - disconnect(c); + disconnect(exec_ctx, c); } - GRPC_SUBCHANNEL_WEAK_UNREF(c, "strong-unref"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); } -void grpc_subchannel_weak_unref( - grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); if (old_refs == 1) { GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } } -grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, +grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, + grpc_connector* connector, const grpc_subchannel_args* args) { grpc_subchannel_key* key = grpc_subchannel_key_create(args); - grpc_subchannel* c = grpc_subchannel_index_find(key); + grpc_subchannel* c = grpc_subchannel_index_find(exec_ctx, key); if (c) { - grpc_subchannel_key_destroy(key); + grpc_subchannel_key_destroy(exec_ctx, key); return c; } - GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(); + GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx); c = (grpc_subchannel*)gpr_zalloc(sizeof(*c)); c->key = key; gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS); @@ -301,10 +311,10 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, c->pollset_set = grpc_pollset_set_create(); grpc_resolved_address* addr = (grpc_resolved_address*)gpr_malloc(sizeof(*addr)); - grpc_get_subchannel_address_arg(args->args, addr); + grpc_get_subchannel_address_arg(exec_ctx, args->args, addr); grpc_resolved_address* new_address = nullptr; grpc_channel_args* new_args = nullptr; - if (grpc_proxy_mappers_map_address(addr, args->args, &new_address, + if (grpc_proxy_mappers_map_address(exec_ctx, addr, args->args, &new_address, &new_args)) { GPR_ASSERT(new_address != nullptr); gpr_free(addr); @@ -317,7 +327,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, new_args != nullptr ? new_args : args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); gpr_free(new_arg.value.string); - if (new_args != nullptr) grpc_channel_args_destroy(new_args); + if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; GRPC_CLOSURE_INIT(&c->connected, subchannel_connected, c, @@ -363,19 +373,21 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, min_backoff_ms, max_backoff_ms); gpr_mu_init(&c->mu); - return grpc_subchannel_index_register(key, c); + return grpc_subchannel_index_register(exec_ctx, key, c); } -static void continue_connect_locked(grpc_subchannel* c) { +static void continue_connect_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { grpc_connect_in_args args; args.interested_parties = c->pollset_set; args.deadline = c->backoff_result.current_deadline; args.channel_args = c->args; - grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_CONNECTING, - GRPC_ERROR_NONE, "state_change"); - grpc_connector_connect(c->connector, &args, &c->connecting_result, + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, + GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, + "state_change"); + grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result, &c->connected); } @@ -388,23 +400,24 @@ grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c, return state; } -static void on_external_state_watcher_done(void* arg, grpc_error* error) { +static void on_external_state_watcher_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { external_state_watcher* w = (external_state_watcher*)arg; grpc_closure* follow_up = w->notify; if (w->pollset_set != nullptr) { - grpc_pollset_set_del_pollset_set(w->subchannel->pollset_set, + grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, w->pollset_set); } gpr_mu_lock(&w->subchannel->mu); w->next->prev = w->prev; w->prev->next = w->next; gpr_mu_unlock(&w->subchannel->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(w->subchannel, "external_state_watcher"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher"); gpr_free(w); - GRPC_CLOSURE_RUN(follow_up, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); } -static void on_alarm(void* arg, grpc_error* error) { +static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; gpr_mu_lock(&c->mu); c->have_alarm = false; @@ -416,17 +429,18 @@ static void on_alarm(void* arg, grpc_error* error) { } if (error == GRPC_ERROR_NONE) { gpr_log(GPR_INFO, "Failed to connect to channel, retrying"); - c->backoff_result = grpc_backoff_step(&c->backoff_state); - continue_connect_locked(c); + c->backoff_result = grpc_backoff_step(exec_ctx, &c->backoff_state); + continue_connect_locked(exec_ctx, c); gpr_mu_unlock(&c->mu); } else { gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); } GRPC_ERROR_UNREF(error); } -static void maybe_start_connecting_locked(grpc_subchannel* c) { +static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { if (c->disconnected) { /* Don't try to connect if we're already disconnected */ return; @@ -452,28 +466,28 @@ static void maybe_start_connecting_locked(grpc_subchannel* c) { if (!c->backoff_begun) { c->backoff_begun = true; - c->backoff_result = grpc_backoff_begin(&c->backoff_state); - continue_connect_locked(c); + c->backoff_result = grpc_backoff_begin(exec_ctx, &c->backoff_state); + continue_connect_locked(exec_ctx, c); } else { GPR_ASSERT(!c->have_alarm); c->have_alarm = true; const grpc_millis time_til_next = - c->backoff_result.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now(); + c->backoff_result.next_attempt_start_time - grpc_exec_ctx_now(exec_ctx); if (time_til_next <= 0) { gpr_log(GPR_INFO, "Retry immediately"); } else { gpr_log(GPR_INFO, "Retry in %" PRIdPTR " milliseconds", time_til_next); } GRPC_CLOSURE_INIT(&c->on_alarm, on_alarm, c, grpc_schedule_on_exec_ctx); - grpc_timer_init(&c->alarm, c->backoff_result.next_attempt_start_time, - &c->on_alarm); + grpc_timer_init(exec_ctx, &c->alarm, + c->backoff_result.next_attempt_start_time, &c->on_alarm); } } void grpc_subchannel_notify_on_state_change( - grpc_subchannel* c, grpc_pollset_set* interested_parties, - grpc_connectivity_state* state, grpc_closure* notify) { + grpc_exec_ctx* exec_ctx, grpc_subchannel* c, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify) { external_state_watcher* w; if (state == nullptr) { @@ -481,8 +495,8 @@ void grpc_subchannel_notify_on_state_change( for (w = c->root_external_state_watcher.next; w != &c->root_external_state_watcher; w = w->next) { if (w->notify == notify) { - grpc_connectivity_state_notify_on_state_change(&c->state_tracker, - nullptr, &w->closure); + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &c->state_tracker, nullptr, &w->closure); } } gpr_mu_unlock(&c->mu); @@ -494,28 +508,31 @@ void grpc_subchannel_notify_on_state_change( GRPC_CLOSURE_INIT(&w->closure, on_external_state_watcher_done, w, grpc_schedule_on_exec_ctx); if (interested_parties != nullptr) { - grpc_pollset_set_add_pollset_set(c->pollset_set, interested_parties); + grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, + interested_parties); } GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher"); gpr_mu_lock(&c->mu); w->next = &c->root_external_state_watcher; w->prev = w->next->prev; w->next->prev = w->prev->next = w; - grpc_connectivity_state_notify_on_state_change(&c->state_tracker, state, - &w->closure); - maybe_start_connecting_locked(c); + grpc_connectivity_state_notify_on_state_change(exec_ctx, &c->state_tracker, + state, &w->closure); + maybe_start_connecting_locked(exec_ctx, c); gpr_mu_unlock(&c->mu); } } void grpc_connected_subchannel_process_transport_op( - grpc_connected_subchannel* con, grpc_transport_op* op) { + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + grpc_transport_op* op) { grpc_channel_stack* channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); grpc_channel_element* top_elem = grpc_channel_stack_element(channel_stack, 0); - top_elem->filter->start_transport_op(top_elem, op); + top_elem->filter->start_transport_op(exec_ctx, top_elem, op); } -static void subchannel_on_child_state_changed(void* p, grpc_error* error) { +static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { state_watcher* sw = (state_watcher*)p; grpc_subchannel* c = sw->subchannel; gpr_mu* mu = &c->mu; @@ -527,22 +544,24 @@ static void subchannel_on_child_state_changed(void* p, grpc_error* error) { /* any errors on a subchannel ==> we're done, create a new one */ sw->connectivity_state = GRPC_CHANNEL_SHUTDOWN; } - grpc_connectivity_state_set(&c->state_tracker, sw->connectivity_state, - GRPC_ERROR_REF(error), "reflect_child"); + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, + sw->connectivity_state, GRPC_ERROR_REF(error), + "reflect_child"); if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_connected_subchannel_notify_on_state_change( - GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr, + exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr, &sw->connectivity_state, &sw->closure); GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); sw = nullptr; } gpr_mu_unlock(mu); - GRPC_SUBCHANNEL_WEAK_UNREF(c, "state_watcher"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher"); gpr_free(sw); } -static void connected_subchannel_state_op(grpc_connected_subchannel* con, +static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* con, grpc_pollset_set* interested_parties, grpc_connectivity_state* state, grpc_closure* closure) { @@ -552,25 +571,29 @@ static void connected_subchannel_state_op(grpc_connected_subchannel* con, op->on_connectivity_state_change = closure; op->bind_pollset_set = interested_parties; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } void grpc_connected_subchannel_notify_on_state_change( - grpc_connected_subchannel* con, grpc_pollset_set* interested_parties, - grpc_connectivity_state* state, grpc_closure* closure) { - connected_subchannel_state_op(con, interested_parties, state, closure); + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* closure) { + connected_subchannel_state_op(exec_ctx, con, interested_parties, state, + closure); } -void grpc_connected_subchannel_ping(grpc_connected_subchannel* con, +void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* con, grpc_closure* closure) { grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; op->send_ping = closure; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } -static bool publish_transport_locked(grpc_subchannel* c) { +static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { grpc_connected_subchannel* con; grpc_channel_stack* stk; state_watcher* sw_subchannel; @@ -578,18 +601,19 @@ static bool publish_transport_locked(grpc_subchannel* c) { /* construct channel stack */ grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); grpc_channel_stack_builder_set_channel_arguments( - builder, c->connecting_result.channel_args); + exec_ctx, builder, c->connecting_result.channel_args); grpc_channel_stack_builder_set_transport(builder, c->connecting_result.transport); - if (!grpc_channel_init_create_stack(builder, GRPC_CLIENT_SUBCHANNEL)) { - grpc_channel_stack_builder_destroy(builder); + if (!grpc_channel_init_create_stack(exec_ctx, builder, + GRPC_CLIENT_SUBCHANNEL)) { + grpc_channel_stack_builder_destroy(exec_ctx, builder); return false; } grpc_error* error = grpc_channel_stack_builder_finish( - builder, 0, 1, connection_destroy, nullptr, (void**)&con); + exec_ctx, builder, 0, 1, connection_destroy, nullptr, (void**)&con); if (error != GRPC_ERROR_NONE) { - grpc_transport_destroy(c->connecting_result.transport); + grpc_transport_destroy(exec_ctx, c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", grpc_error_string(error)); GRPC_ERROR_UNREF(error); @@ -607,7 +631,7 @@ static bool publish_transport_locked(grpc_subchannel* c) { if (c->disconnected) { gpr_free(sw_subchannel); - grpc_channel_stack_destroy(stk); + grpc_channel_stack_destroy(exec_ctx, stk); gpr_free(con); return false; } @@ -623,18 +647,19 @@ static bool publish_transport_locked(grpc_subchannel* c) { /* setup subchannel watching connected subchannel for changes; subchannel ref for connecting is donated to the state watcher */ GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); - GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); grpc_connected_subchannel_notify_on_state_change( - con, c->pollset_set, &sw_subchannel->connectivity_state, + exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state, &sw_subchannel->closure); /* signal completion */ - grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_READY, + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "connected"); return true; } -static void subchannel_connected(void* arg, grpc_error* error) { +static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; grpc_channel_args* delete_channel_args = c->connecting_result.channel_args; @@ -642,13 +667,13 @@ static void subchannel_connected(void* arg, grpc_error* error) { gpr_mu_lock(&c->mu); c->connecting = false; if (c->connecting_result.transport != nullptr && - publish_transport_locked(c)) { + publish_transport_locked(exec_ctx, c)) { /* do nothing, transport was published */ } else if (c->disconnected) { - GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); } else { grpc_connectivity_state_set( - &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Connect Failed", &error, 1), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE), @@ -657,26 +682,27 @@ static void subchannel_connected(void* arg, grpc_error* error) { const char* errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); - maybe_start_connecting_locked(c); - GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); + maybe_start_connecting_locked(exec_ctx, c); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); } gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(c, "connected"); - grpc_channel_args_destroy(delete_channel_args); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connected"); + grpc_channel_args_destroy(exec_ctx, delete_channel_args); } /* * grpc_subchannel_call implementation */ -static void subchannel_call_destroy(void* call, grpc_error* error) { +static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call, + grpc_error* error) { grpc_subchannel_call* c = (grpc_subchannel_call*)call; GPR_ASSERT(c->schedule_closure_after_destroy != nullptr); GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); grpc_connected_subchannel* connection = c->connection; - grpc_call_stack_destroy(SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, + grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, c->schedule_closure_after_destroy); - GRPC_CONNECTED_SUBCHANNEL_UNREF(connection, "subchannel_call"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); } @@ -692,18 +718,20 @@ void grpc_subchannel_call_ref( GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_unref( - grpc_subchannel_call* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CALL_STACK_UNREF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); +void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_process_op(grpc_subchannel_call* call, +void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* call, grpc_transport_stream_op_batch* batch) { GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0); grpc_call_stack* call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); grpc_call_element* top_elem = grpc_call_stack_element(call_stack, 0); GRPC_CALL_LOG_OP(GPR_INFO, top_elem, batch); - top_elem->filter->start_transport_stream_op_batch(top_elem, batch); + top_elem->filter->start_transport_stream_op_batch(exec_ctx, top_elem, batch); GPR_TIMER_END("grpc_subchannel_call_process_op", 0); } @@ -718,7 +746,7 @@ const grpc_subchannel_key* grpc_subchannel_get_key( } grpc_error* grpc_connected_subchannel_create_call( - grpc_connected_subchannel* con, + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, const grpc_connected_subchannel_call_args* args, grpc_subchannel_call** call) { grpc_channel_stack* chanstk = CHANNEL_STACK_FROM_CONNECTION(con); @@ -736,14 +764,14 @@ grpc_error* grpc_connected_subchannel_create_call( args->arena, /* arena */ args->call_combiner /* call_combiner */ }; - grpc_error* error = grpc_call_stack_init(chanstk, 1, subchannel_call_destroy, - *call, &call_args); + grpc_error* error = grpc_call_stack_init( + exec_ctx, chanstk, 1, subchannel_call_destroy, *call, &call_args); if (error != GRPC_ERROR_NONE) { const char* error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); return error; } - grpc_call_stack_set_pollset_or_pollset_set(callstk, args->pollent); + grpc_call_stack_set_pollset_or_pollset_set(exec_ctx, callstk, args->pollent); return GRPC_ERROR_NONE; } @@ -752,20 +780,21 @@ grpc_call_stack* grpc_subchannel_call_get_call_stack( return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); } -static void grpc_uri_to_sockaddr(const char* uri_str, +static void grpc_uri_to_sockaddr(grpc_exec_ctx* exec_ctx, const char* uri_str, grpc_resolved_address* addr) { - grpc_uri* uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */); + grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */); GPR_ASSERT(uri != nullptr); if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr)); grpc_uri_destroy(uri); } -void grpc_get_subchannel_address_arg(const grpc_channel_args* args, +void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, + const grpc_channel_args* args, grpc_resolved_address* addr) { const char* addr_uri_str = grpc_get_subchannel_address_uri_arg(args); memset(addr, 0, sizeof(*addr)); if (*addr_uri_str != '\0') { - grpc_uri_to_sockaddr(addr_uri_str, addr); + grpc_uri_to_sockaddr(exec_ctx, addr_uri_str, addr); } } diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 84d9fa27a1..1f326fc1d2 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -42,34 +42,36 @@ typedef struct grpc_subchannel_key grpc_subchannel_key; grpc_subchannel_ref((p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_UNREF(p, r) \ - grpc_subchannel_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_UNREF(cl, p, r) \ + grpc_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_WEAK_REF(p, r) \ grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) \ - grpc_subchannel_weak_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ + grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(p, r) \ - grpc_connected_subchannel_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ + grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_CALL_REF(p, r) \ grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_CALL_UNREF(p, r) \ - grpc_subchannel_call_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ + grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ , const char *file, int line, const char *reason #else #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p)) #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ grpc_subchannel_ref_from_weak_ref((p)) -#define GRPC_SUBCHANNEL_UNREF(p, r) grpc_subchannel_unref((p)) +#define GRPC_SUBCHANNEL_UNREF(cl, p, r) grpc_subchannel_unref((cl), (p)) #define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p)) -#define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) grpc_subchannel_weak_unref((p)) +#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ + grpc_subchannel_weak_unref((cl), (p)) #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(p, r) \ - grpc_connected_subchannel_unref((p)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ + grpc_connected_subchannel_unref((cl), (p)) #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) -#define GRPC_SUBCHANNEL_CALL_UNREF(p, r) grpc_subchannel_call_unref((p)) +#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ + grpc_subchannel_call_unref((cl), (p)) #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS #endif @@ -77,20 +79,24 @@ grpc_subchannel* grpc_subchannel_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_subchannel* grpc_subchannel_ref_from_weak_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_unref( - grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* channel + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_subchannel* grpc_subchannel_weak_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_weak_unref( - grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* channel + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_connected_subchannel* grpc_connected_subchannel_ref( grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_connected_subchannel_unref( - grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* channel + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); void grpc_subchannel_call_ref( grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_call_unref( - grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* call + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); /** construct a subchannel call */ typedef struct { @@ -104,13 +110,14 @@ typedef struct { } grpc_connected_subchannel_call_args; grpc_error* grpc_connected_subchannel_create_call( - grpc_connected_subchannel* connected_subchannel, + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* connected_subchannel, const grpc_connected_subchannel_call_args* args, grpc_subchannel_call** subchannel_call); /** process a transport level op */ void grpc_connected_subchannel_process_transport_op( - grpc_connected_subchannel* subchannel, grpc_transport_op* op); + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* subchannel, + grpc_transport_op* op); /** poll the current connectivity state of a channel */ grpc_connectivity_state grpc_subchannel_check_connectivity( @@ -119,12 +126,15 @@ grpc_connectivity_state grpc_subchannel_check_connectivity( /** Calls notify when the connectivity state of a channel becomes different from *state. Updates *state with the new state of the channel. */ void grpc_subchannel_notify_on_state_change( - grpc_subchannel* channel, grpc_pollset_set* interested_parties, - grpc_connectivity_state* state, grpc_closure* notify); + grpc_exec_ctx* exec_ctx, grpc_subchannel* channel, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify); void grpc_connected_subchannel_notify_on_state_change( - grpc_connected_subchannel* channel, grpc_pollset_set* interested_parties, - grpc_connectivity_state* state, grpc_closure* notify); -void grpc_connected_subchannel_ping(grpc_connected_subchannel* channel, + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* channel, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify); +void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* channel, grpc_closure* notify); /** retrieve the grpc_connected_subchannel - or NULL if called before @@ -137,7 +147,8 @@ const grpc_subchannel_key* grpc_subchannel_get_key( const grpc_subchannel* subchannel); /** continue processing a transport op */ -void grpc_subchannel_call_process_op(grpc_subchannel_call* subchannel_call, +void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* subchannel_call, grpc_transport_stream_op_batch* op); /** Must be called once per call. Sets the 'then_schedule_closure' argument for @@ -161,11 +172,13 @@ struct grpc_subchannel_args { }; /** create a subchannel given a connector */ -grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, +grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, + grpc_connector* connector, const grpc_subchannel_args* args); /// Sets \a addr from \a args. -void grpc_get_subchannel_address_arg(const grpc_channel_args* args, +void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, + const grpc_channel_args* args, grpc_resolved_address* addr); /// Returns the URI string for the address to connect to. diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 052b047f43..1624643d0b 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -81,14 +81,16 @@ int grpc_subchannel_key_compare(const grpc_subchannel_key* a, return grpc_channel_args_compare(a->args.args, b->args.args); } -void grpc_subchannel_key_destroy(grpc_subchannel_key* k) { +void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* k) { gpr_free((grpc_channel_args*)k->args.filters); - grpc_channel_args_destroy((grpc_channel_args*)k->args.args); + grpc_channel_args_destroy(exec_ctx, (grpc_channel_args*)k->args.args); gpr_free(k); } static void sck_avl_destroy(void* p, void* user_data) { - grpc_subchannel_key_destroy((grpc_subchannel_key*)p); + grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; + grpc_subchannel_key_destroy(exec_ctx, (grpc_subchannel_key*)p); } static void* sck_avl_copy(void* p, void* unused) { @@ -101,7 +103,8 @@ static long sck_avl_compare(void* a, void* b, void* unused) { } static void scv_avl_destroy(void* p, void* user_data) { - GRPC_SUBCHANNEL_WEAK_UNREF((grpc_subchannel*)p, "subchannel_index"); + grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, (grpc_subchannel*)p, "subchannel_index"); } static void* scv_avl_copy(void* p, void* unused) { @@ -132,29 +135,32 @@ void grpc_subchannel_index_shutdown(void) { void grpc_subchannel_index_unref(void) { if (gpr_unref(&g_refcount)) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index, grpc_core::ExecCtx::Get()); + gpr_avl_unref(g_subchannel_index, &exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); } } void grpc_subchannel_index_ref(void) { gpr_ref_non_zero(&g_refcount); } -grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key) { +grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); gpr_mu_unlock(&g_mu); grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()), - "index_find"); - gpr_avl_unref(index, grpc_core::ExecCtx::Get()); + (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx), "index_find"); + gpr_avl_unref(index, exec_ctx); return c; } -grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, +grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, grpc_subchannel* constructed) { grpc_subchannel* c = nullptr; bool need_to_unref_constructed = false; @@ -165,11 +171,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); + c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); if (c != nullptr) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -178,11 +184,9 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, need_to_unref_constructed = true; } else { // no -> update the avl and compare/swap - gpr_avl updated = - gpr_avl_add(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), - subchannel_key_copy(key), - GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), - grpc_core::ExecCtx::Get()); + gpr_avl updated = gpr_avl_add( + gpr_avl_ref(index, exec_ctx), subchannel_key_copy(key), + GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), exec_ctx); // it may happen (but it's expected to be unlikely) // that some other thread has changed the index: @@ -194,42 +198,41 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); + gpr_avl_unref(updated, exec_ctx); } - gpr_avl_unref(index, grpc_core::ExecCtx::Get()); + gpr_avl_unref(index, exec_ctx); } if (need_to_unref_constructed) { - GRPC_SUBCHANNEL_UNREF(constructed, "index_register"); + GRPC_SUBCHANNEL_UNREF(exec_ctx, constructed, "index_register"); } return c; } -void grpc_subchannel_index_unregister(grpc_subchannel_key* key, +void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, grpc_subchannel* constructed) { bool done = false; while (!done) { // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); + gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); gpr_mu_unlock(&g_mu); // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel* c = - (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); + grpc_subchannel* c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); if (c != constructed) { - gpr_avl_unref(index, grpc_core::ExecCtx::Get()); + gpr_avl_unref(index, exec_ctx); break; } // compare and swap the update (some other thread may have // mutated the index behind us) gpr_avl updated = - gpr_avl_remove(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), key, - grpc_core::ExecCtx::Get()); + gpr_avl_remove(gpr_avl_ref(index, exec_ctx), key, exec_ctx); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -238,8 +241,8 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); - gpr_avl_unref(index, grpc_core::ExecCtx::Get()); + gpr_avl_unref(updated, exec_ctx); + gpr_avl_unref(index, exec_ctx); } } diff --git a/src/core/ext/filters/client_channel/subchannel_index.h b/src/core/ext/filters/client_channel/subchannel_index.h index bd160a3b13..6a4d06ef8f 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.h +++ b/src/core/ext/filters/client_channel/subchannel_index.h @@ -29,22 +29,26 @@ grpc_subchannel_key* grpc_subchannel_key_create( const grpc_subchannel_args* args); /** Destroy a subchannel key */ -void grpc_subchannel_key_destroy(grpc_subchannel_key* key); +void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key); /** Given a subchannel key, find the subchannel registered for it. Returns NULL if no such channel exists. Thread-safe. */ -grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key); +grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key); /** Register a subchannel against a key. Takes ownership of \a constructed. Returns the registered subchannel. This may be different from \a constructed in the case of a registration race. */ -grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, +grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, grpc_subchannel* constructed); /** Remove \a constructed as the registered subchannel for \a key. */ -void grpc_subchannel_index_unregister(grpc_subchannel_key* key, +void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, grpc_subchannel* constructed); int grpc_subchannel_key_compare(const grpc_subchannel_key* a, diff --git a/src/core/ext/filters/client_channel/uri_parser.cc b/src/core/ext/filters/client_channel/uri_parser.cc index 3428f4b54c..b76dcbe4e3 100644 --- a/src/core/ext/filters/client_channel/uri_parser.cc +++ b/src/core/ext/filters/client_channel/uri_parser.cc @@ -56,8 +56,8 @@ static grpc_uri* bad_uri(const char* uri_text, size_t pos, const char* section, } /** Returns a copy of percent decoded \a src[begin, end) */ -static char* decode_and_copy_component(const char* src, size_t begin, - size_t end) { +static char* decode_and_copy_component(grpc_exec_ctx* exec_ctx, const char* src, + size_t begin, size_t end) { grpc_slice component = (begin == NOT_SET || end == NOT_SET) ? grpc_empty_slice() @@ -65,8 +65,8 @@ static char* decode_and_copy_component(const char* src, size_t begin, grpc_slice decoded_component = grpc_permissive_percent_decode_slice(component); char* out = grpc_dump_slice(decoded_component, GPR_DUMP_ASCII); - grpc_slice_unref_internal(component); - grpc_slice_unref_internal(decoded_component); + grpc_slice_unref_internal(exec_ctx, component); + grpc_slice_unref_internal(exec_ctx, decoded_component); return out; } @@ -184,7 +184,8 @@ static void parse_query_parts(grpc_uri* uri) { } } -grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors) { +grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, + bool suppress_errors) { grpc_uri* uri; size_t scheme_begin = 0; size_t scheme_end = NOT_SET; @@ -272,13 +273,16 @@ grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors) { } uri = (grpc_uri*)gpr_zalloc(sizeof(*uri)); - uri->scheme = decode_and_copy_component(uri_text, scheme_begin, scheme_end); - uri->authority = - decode_and_copy_component(uri_text, authority_begin, authority_end); - uri->path = decode_and_copy_component(uri_text, path_begin, path_end); - uri->query = decode_and_copy_component(uri_text, query_begin, query_end); - uri->fragment = - decode_and_copy_component(uri_text, fragment_begin, fragment_end); + uri->scheme = + decode_and_copy_component(exec_ctx, uri_text, scheme_begin, scheme_end); + uri->authority = decode_and_copy_component(exec_ctx, uri_text, + authority_begin, authority_end); + uri->path = + decode_and_copy_component(exec_ctx, uri_text, path_begin, path_end); + uri->query = + decode_and_copy_component(exec_ctx, uri_text, query_begin, query_end); + uri->fragment = decode_and_copy_component(exec_ctx, uri_text, fragment_begin, + fragment_end); parse_query_parts(uri); return uri; diff --git a/src/core/ext/filters/client_channel/uri_parser.h b/src/core/ext/filters/client_channel/uri_parser.h index 24ff06c0b5..84752905e8 100644 --- a/src/core/ext/filters/client_channel/uri_parser.h +++ b/src/core/ext/filters/client_channel/uri_parser.h @@ -37,7 +37,8 @@ typedef struct { } grpc_uri; /** parse a uri, return NULL on failure */ -grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors); +grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, + bool suppress_errors); /** return the part of a query string after the '=' in "?key=xxx&...", or NULL * if key is not present */ diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index c430f3d2d4..5db7584a59 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -36,16 +36,18 @@ // The on_complete callback used when sending a cancel_error batch down the // filter stack. Yields the call combiner when the batch returns. -static void yield_call_combiner(void* arg, grpc_error* ignored) { +static void yield_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* ignored) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; - GRPC_CALL_COMBINER_STOP(deadline_state->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, deadline_state->call_combiner, "got on_complete from cancel_stream batch"); - GRPC_CALL_STACK_UNREF(deadline_state->call_stack, "deadline_timer"); + GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); } // This is called via the call combiner, so access to deadline_state is // synchronized. -static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { +static void send_cancel_op_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; grpc_transport_stream_op_batch* batch = grpc_make_transport_stream_op( @@ -53,34 +55,37 @@ static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { deadline_state, grpc_schedule_on_exec_ctx)); batch->cancel_stream = true; batch->payload->cancel_stream.cancel_error = GRPC_ERROR_REF(error); - elem->filter->start_transport_stream_op_batch(elem, batch); + elem->filter->start_transport_stream_op_batch(exec_ctx, elem, batch); } // Timer callback. -static void timer_callback(void* arg, grpc_error* error) { +static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; if (error != GRPC_ERROR_CANCELLED) { error = grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Deadline Exceeded"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_DEADLINE_EXCEEDED); - grpc_call_combiner_cancel(deadline_state->call_combiner, + grpc_call_combiner_cancel(exec_ctx, deadline_state->call_combiner, GRPC_ERROR_REF(error)); GRPC_CLOSURE_INIT(&deadline_state->timer_callback, send_cancel_op_in_call_combiner, elem, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(deadline_state->call_combiner, + GRPC_CALL_COMBINER_START(exec_ctx, deadline_state->call_combiner, &deadline_state->timer_callback, error, "deadline exceeded -- sending cancel_stream op"); } else { - GRPC_CALL_STACK_UNREF(deadline_state->call_stack, "deadline_timer"); + GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, + "deadline_timer"); } } // Starts the deadline timer. // This is called via the call combiner, so access to deadline_state is // synchronized. -static void start_timer_if_needed(grpc_call_element* elem, +static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return; @@ -108,16 +113,17 @@ static void start_timer_if_needed(grpc_call_element* elem, } GPR_ASSERT(closure != nullptr); GRPC_CALL_STACK_REF(deadline_state->call_stack, "deadline_timer"); - grpc_timer_init(&deadline_state->timer, deadline, closure); + grpc_timer_init(exec_ctx, &deadline_state->timer, deadline, closure); } // Cancels the deadline timer. // This is called via the call combiner, so access to deadline_state is // synchronized. -static void cancel_timer_if_needed(grpc_deadline_state* deadline_state) { +static void cancel_timer_if_needed(grpc_exec_ctx* exec_ctx, + grpc_deadline_state* deadline_state) { if (deadline_state->timer_state == GRPC_DEADLINE_STATE_PENDING) { deadline_state->timer_state = GRPC_DEADLINE_STATE_FINISHED; - grpc_timer_cancel(&deadline_state->timer); + grpc_timer_cancel(exec_ctx, &deadline_state->timer); } else { // timer was either in STATE_INITAL (nothing to cancel) // OR in STATE_FINISHED (again nothing to cancel) @@ -125,11 +131,12 @@ static void cancel_timer_if_needed(grpc_deadline_state* deadline_state) { } // Callback run when the call is complete. -static void on_complete(void* arg, grpc_error* error) { +static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; - cancel_timer_if_needed(deadline_state); + cancel_timer_if_needed(exec_ctx, deadline_state); // Invoke the next callback. - GRPC_CLOSURE_RUN(deadline_state->next_on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, deadline_state->next_on_complete, + GRPC_ERROR_REF(error)); } // Inject our own on_complete callback into op. @@ -149,7 +156,8 @@ struct start_timer_after_init_state { grpc_millis deadline; grpc_closure closure; }; -static void start_timer_after_init(void* arg, grpc_error* error) { +static void start_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { struct start_timer_after_init_state* state = (struct start_timer_after_init_state*)arg; grpc_deadline_state* deadline_state = @@ -158,18 +166,18 @@ static void start_timer_after_init(void* arg, grpc_error* error) { // We are initially called without holding the call combiner, so we // need to bounce ourselves into it. state->in_call_combiner = true; - GRPC_CALL_COMBINER_START(deadline_state->call_combiner, &state->closure, - GRPC_ERROR_REF(error), + GRPC_CALL_COMBINER_START(exec_ctx, deadline_state->call_combiner, + &state->closure, GRPC_ERROR_REF(error), "scheduling deadline timer"); return; } - start_timer_if_needed(state->elem, state->deadline); + start_timer_if_needed(exec_ctx, state->elem, state->deadline); gpr_free(state); - GRPC_CALL_COMBINER_STOP(deadline_state->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, deadline_state->call_combiner, "done scheduling deadline timer"); } -void grpc_deadline_state_init(grpc_call_element* elem, +void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline) { @@ -192,27 +200,29 @@ void grpc_deadline_state_init(grpc_call_element* elem, state->deadline = deadline; GRPC_CLOSURE_INIT(&state->closure, start_timer_after_init, state, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&state->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &state->closure, GRPC_ERROR_NONE); } } -void grpc_deadline_state_destroy(grpc_call_element* elem) { +void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; - cancel_timer_if_needed(deadline_state); + cancel_timer_if_needed(exec_ctx, deadline_state); } -void grpc_deadline_state_reset(grpc_call_element* elem, +void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_millis new_deadline) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; - cancel_timer_if_needed(deadline_state); - start_timer_if_needed(elem, new_deadline); + cancel_timer_if_needed(exec_ctx, deadline_state); + start_timer_if_needed(exec_ctx, elem, new_deadline); } void grpc_deadline_state_client_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; if (op->cancel_stream) { - cancel_timer_if_needed(deadline_state); + cancel_timer_if_needed(exec_ctx, deadline_state); } else { // Make sure we know when the call is complete, so that we can cancel // the timer. @@ -227,14 +237,16 @@ void grpc_deadline_state_client_start_transport_stream_op_batch( // // Constructor for channel_data. Used for both client and server filters. -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } // Destructor for channel_data. Used for both client and server filters. -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} // Call data used for both client and server filter. typedef struct base_call_data { @@ -254,45 +266,50 @@ typedef struct server_call_data { } server_call_data; // Constructor for call_data. Used for both client and server filters. -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { - grpc_deadline_state_init(elem, args->call_stack, args->call_combiner, - args->deadline); + grpc_deadline_state_init(exec_ctx, elem, args->call_stack, + args->call_combiner, args->deadline); return GRPC_ERROR_NONE; } // Destructor for call_data. Used for both client and server filters. -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - grpc_deadline_state_destroy(elem); + grpc_deadline_state_destroy(exec_ctx, elem); } // Method for starting a call op for client filter. static void client_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { - grpc_deadline_state_client_start_transport_stream_op_batch(elem, op); + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { + grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, + op); // Chain to next filter. - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } // Callback for receiving initial metadata on the server. -static void recv_initial_metadata_ready(void* arg, grpc_error* error) { +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; server_call_data* calld = (server_call_data*)elem->call_data; // Get deadline from metadata and start the timer if needed. - start_timer_if_needed(elem, calld->recv_initial_metadata->deadline); + start_timer_if_needed(exec_ctx, elem, calld->recv_initial_metadata->deadline); // Invoke the next callback. calld->next_recv_initial_metadata_ready->cb( - calld->next_recv_initial_metadata_ready->cb_arg, error); + exec_ctx, calld->next_recv_initial_metadata_ready->cb_arg, error); } // Method for starting a call op for server filter. static void server_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { server_call_data* calld = (server_call_data*)elem->call_data; if (op->cancel_stream) { - cancel_timer_if_needed(&calld->base.deadline_state); + cancel_timer_if_needed(exec_ctx, &calld->base.deadline_state); } else { // If we're receiving initial metadata, we need to get the deadline // from the recv_initial_metadata_ready callback. So we inject our @@ -318,7 +335,7 @@ static void server_start_transport_stream_op_batch( } } // Chain to next filter. - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } const grpc_channel_filter grpc_client_deadline_filter = { @@ -355,7 +372,8 @@ bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) { !grpc_channel_args_want_minimal_stack(channel_args)); } -static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_deadline_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_deadline_checking_enabled( grpc_channel_stack_builder_get_channel_arguments(builder)) diff --git a/src/core/ext/filters/deadline/deadline_filter.h b/src/core/ext/filters/deadline/deadline_filter.h index 4de817ef54..8d835d0382 100644 --- a/src/core/ext/filters/deadline/deadline_filter.h +++ b/src/core/ext/filters/deadline/deadline_filter.h @@ -49,12 +49,13 @@ typedef struct grpc_deadline_state { // // assumes elem->call_data is zero'd -void grpc_deadline_state_init(grpc_call_element* elem, +void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline); -void grpc_deadline_state_destroy(grpc_call_element* elem); +void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem); // Cancels the existing timer and starts a new one with new_deadline. // @@ -65,7 +66,7 @@ void grpc_deadline_state_destroy(grpc_call_element* elem); // deadline may result in the timer being called twice. // // Note: Must be called while holding the call combiner. -void grpc_deadline_state_reset(grpc_call_element* elem, +void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_millis new_deadline); // To be called from the client-side filter's start_transport_stream_op_batch() @@ -77,7 +78,8 @@ void grpc_deadline_state_reset(grpc_call_element* elem, // // Note: Must be called while holding the call combiner. void grpc_deadline_state_client_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op); + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op); // Should deadline checking be performed (according to channel args) bool grpc_deadline_checking_enabled(const grpc_channel_args* args); diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index a1fb10f5b8..a625369b02 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -68,11 +68,12 @@ typedef struct channel_data { size_t max_payload_size_for_get; } channel_data; -static grpc_error* client_filter_incoming_metadata(grpc_call_element* elem, +static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_metadata_batch* b) { if (b->idx.named.status != nullptr) { if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { - grpc_metadata_batch_remove(b, b->idx.named.status); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); } else { char* val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), GPR_DUMP_ASCII); @@ -97,9 +98,10 @@ static grpc_error* client_filter_incoming_metadata(grpc_call_element* elem, GRPC_MDVALUE(b->idx.named.grpc_message->md)); if (grpc_slice_is_equivalent(pct_decoded_msg, GRPC_MDVALUE(b->idx.named.grpc_message->md))) { - grpc_slice_unref_internal(pct_decoded_msg); + grpc_slice_unref_internal(exec_ctx, pct_decoded_msg); } else { - grpc_metadata_batch_set_value(b->idx.named.grpc_message, pct_decoded_msg); + grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, + pct_decoded_msg); } } @@ -129,53 +131,60 @@ static grpc_error* client_filter_incoming_metadata(grpc_call_element* elem, gpr_free(val); } } - grpc_metadata_batch_remove(b, b->idx.named.content_type); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); } return GRPC_ERROR_NONE; } -static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - error = client_filter_incoming_metadata(elem, calld->recv_initial_metadata); + error = client_filter_incoming_metadata(exec_ctx, elem, + calld->recv_initial_metadata); } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, error); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, + error); } -static void recv_trailing_metadata_on_complete(void* user_data, +static void recv_trailing_metadata_on_complete(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - error = - client_filter_incoming_metadata(elem, calld->recv_trailing_metadata); + error = client_filter_incoming_metadata(exec_ctx, elem, + calld->recv_trailing_metadata); } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_RUN(calld->original_recv_trailing_metadata_on_complete, error); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_trailing_metadata_on_complete, + error); } -static void send_message_on_complete(void* arg, grpc_error* error) { +static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - grpc_byte_stream_cache_destroy(&calld->send_message_cache); - GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, + grpc_byte_stream_cache_destroy(exec_ctx, &calld->send_message_cache); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } // Pulls a slice from the send_message byte stream, updating // calld->send_message_bytes_read. -static grpc_error* pull_slice_from_send_message(call_data* calld) { +static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, + call_data* calld) { grpc_slice incoming_slice; grpc_error* error = grpc_byte_stream_pull( - &calld->send_message_caching_stream.base, &incoming_slice); + exec_ctx, &calld->send_message_caching_stream.base, &incoming_slice); if (error == GRPC_ERROR_NONE) { calld->send_message_bytes_read += GRPC_SLICE_LENGTH(incoming_slice); - grpc_slice_unref_internal(incoming_slice); + grpc_slice_unref_internal(exec_ctx, incoming_slice); } return error; } @@ -185,10 +194,12 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { // calld->send_message_caching_stream.base.length, then we have completed // reading from the byte stream; otherwise, an async read has been dispatched // and on_send_message_next_done() will be invoked when it is complete. -static grpc_error* read_all_available_send_message_data(call_data* calld) { - while (grpc_byte_stream_next(&calld->send_message_caching_stream.base, +static grpc_error* read_all_available_send_message_data(grpc_exec_ctx* exec_ctx, + call_data* calld) { + while (grpc_byte_stream_next(exec_ctx, + &calld->send_message_caching_stream.base, ~(size_t)0, &calld->on_send_message_next_done)) { - grpc_error* error = pull_slice_from_send_message(calld); + grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) return error; if (calld->send_message_bytes_read == calld->send_message_caching_stream.base.length) { @@ -199,18 +210,19 @@ static grpc_error* read_all_available_send_message_data(call_data* calld) { } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(void* arg, grpc_error* error) { +static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - calld->send_message_batch, error, calld->call_combiner); + exec_ctx, calld->send_message_batch, error, calld->call_combiner); return; } - error = pull_slice_from_send_message(calld); + error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - calld->send_message_batch, error, calld->call_combiner); + exec_ctx, calld->send_message_batch, error, calld->call_combiner); return; } // There may or may not be more to read, but we don't care. If we got @@ -218,7 +230,7 @@ static void on_send_message_next_done(void* arg, grpc_error* error) { // synchronously, so we were not able to do a cached call. Instead, // we just reset the byte stream and then send down the batch as-is. grpc_caching_byte_stream_reset(&calld->send_message_caching_stream); - grpc_call_next_op(elem, calld->send_message_batch); + grpc_call_next_op(exec_ctx, elem, calld->send_message_batch); } static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { @@ -236,7 +248,8 @@ static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { // Modifies the path entry in the batch's send_initial_metadata to // append the base64-encoded query for a GET request. -static grpc_error* update_path_for_get(grpc_call_element* elem, +static grpc_error* update_path_for_get(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; grpc_slice path_slice = @@ -269,22 +282,24 @@ static grpc_error* update_path_for_get(grpc_call_element* elem, grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t)); /* substitute previous path with the new path+query */ grpc_mdelem mdelem_path_and_query = - grpc_mdelem_from_slices(GRPC_MDSTR_PATH, path_with_query_slice); + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, path_with_query_slice); grpc_metadata_batch* b = batch->payload->send_initial_metadata.send_initial_metadata; - return grpc_metadata_batch_substitute(b, b->idx.named.path, + return grpc_metadata_batch_substitute(exec_ctx, b, b->idx.named.path, mdelem_path_and_query); } -static void remove_if_present(grpc_metadata_batch* batch, +static void remove_if_present(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_metadata_batch_callouts_index idx) { if (batch->idx.array[idx] != nullptr) { - grpc_metadata_batch_remove(batch, batch->idx.array[idx]); + grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); } } static void hc_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* channeld = (channel_data*)elem->channel_data; GPR_TIMER_BEGIN("hc_start_transport_stream_op_batch", 0); @@ -330,16 +345,17 @@ static void hc_start_transport_stream_op_batch( calld->original_send_message_on_complete = batch->on_complete; batch->on_complete = &calld->send_message_on_complete; calld->send_message_batch = batch; - error = read_all_available_send_message_data(calld); + error = read_all_available_send_message_data(exec_ctx, calld); if (error != GRPC_ERROR_NONE) goto done; // If all the data has been read, then we can use GET. if (calld->send_message_bytes_read == calld->send_message_caching_stream.base.length) { method = GRPC_MDELEM_METHOD_GET; - error = update_path_for_get(elem, batch); + error = update_path_for_get(exec_ctx, elem, batch); if (error != GRPC_ERROR_NONE) goto done; batch->send_message = false; - grpc_byte_stream_destroy(&calld->send_message_caching_stream.base); + grpc_byte_stream_destroy(exec_ctx, + &calld->send_message_caching_stream.base); } else { // Not all data is available. The batch will be sent down // asynchronously in on_send_message_next_done(). @@ -356,41 +372,41 @@ static void hc_start_transport_stream_op_batch( } remove_if_present( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_METHOD); remove_if_present( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_SCHEME); remove_if_present( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_TE); remove_if_present( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_CONTENT_TYPE); remove_if_present( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_USER_AGENT); /* Send : prefixed headers, which have to be before any application layer headers. */ error = grpc_metadata_batch_add_head( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, &calld->method, method); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_head( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, &calld->scheme, channeld->static_scheme); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, &calld->te_trailers, GRPC_MDELEM_TE_TRAILERS); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, &calld->user_agent, GRPC_MDELEM_REF(channeld->user_agent)); if (error != GRPC_ERROR_NONE) goto done; } @@ -398,15 +414,16 @@ static void hc_start_transport_stream_op_batch( done: if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - calld->send_message_batch, error, calld->call_combiner); + exec_ctx, calld->send_message_batch, error, calld->call_combiner); } else if (!batch_will_be_handled_asynchronously) { - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); } GPR_TIMER_END("hc_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; @@ -424,7 +441,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} @@ -516,7 +533,8 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args, } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(!args->is_last); @@ -525,16 +543,17 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, chand->max_payload_size_for_get = max_payload_size_from_args(args->channel_args); chand->user_agent = grpc_mdelem_from_slices( - GRPC_MDSTR_USER_AGENT, + exec_ctx, GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args, args->optional_transport->vtable->name)); return GRPC_ERROR_NONE; } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - GRPC_MDELEM_UNREF(chand->user_agent); + GRPC_MDELEM_UNREF(exec_ctx, chand->user_agent); } const grpc_channel_filter grpc_http_client_filter = { diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index deec77c96f..483eb021e8 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -40,7 +40,8 @@ static bool is_building_http_like_transport( return t != nullptr && strstr(t->vtable->name, "http"); } -static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { if (!is_building_http_like_transport(builder)) return true; optional_filter* filtarg = (optional_filter*)arg; @@ -54,7 +55,8 @@ static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder, : true; } -static bool maybe_add_required_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_required_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index 9ae13d2ed2..d070b56b6a 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -100,11 +100,12 @@ static bool skip_compression(grpc_call_element* elem, uint32_t flags, /** Filter initial metadata */ static grpc_error* process_send_initial_metadata( - grpc_call_element* elem, grpc_metadata_batch* initial_metadata, + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) GRPC_MUST_USE_RESULT; static grpc_error* process_send_initial_metadata( - grpc_call_element* elem, grpc_metadata_batch* initial_metadata, - bool* has_compression_algorithm) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) { call_data* calld = (call_data*)elem->call_data; channel_data* channeld = (channel_data*)elem->channel_data; *has_compression_algorithm = false; @@ -136,13 +137,13 @@ static grpc_error* process_send_initial_metadata( } *has_compression_algorithm = true; grpc_metadata_batch_remove( - initial_metadata, + exec_ctx, initial_metadata, initial_metadata->idx.named.grpc_internal_stream_encoding_request); /* Disable message-wise compression */ calld->compression_algorithm = GRPC_COMPRESS_NONE; if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { grpc_metadata_batch_remove( - initial_metadata, + exec_ctx, initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } } else if (initial_metadata->idx.named.grpc_internal_encoding_request != @@ -159,7 +160,7 @@ static grpc_error* process_send_initial_metadata( } *has_compression_algorithm = true; grpc_metadata_batch_remove( - initial_metadata, + exec_ctx, initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } else { /* If no algorithm was found in the metadata and we aren't @@ -180,11 +181,12 @@ static grpc_error* process_send_initial_metadata( /* hint compression algorithm */ if (stream_compression_algorithm != GRPC_STREAM_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->stream_compression_algorithm_storage, + exec_ctx, initial_metadata, + &calld->stream_compression_algorithm_storage, grpc_stream_compression_encoding_mdelem(stream_compression_algorithm)); } else if (calld->compression_algorithm != GRPC_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->compression_algorithm_storage, + exec_ctx, initial_metadata, &calld->compression_algorithm_storage, grpc_compression_encoding_mdelem(calld->compression_algorithm)); } @@ -192,7 +194,7 @@ static grpc_error* process_send_initial_metadata( /* convey supported compression algorithms */ error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->accept_encoding_storage, + exec_ctx, initial_metadata, &calld->accept_encoding_storage, GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( channeld->supported_compression_algorithms)); @@ -201,7 +203,7 @@ static grpc_error* process_send_initial_metadata( /* Do not overwrite accept-encoding header if it already presents. */ if (!initial_metadata->idx.named.accept_encoding) { error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->accept_stream_encoding_storage, + exec_ctx, initial_metadata, &calld->accept_stream_encoding_storage, GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS( channeld->supported_stream_compression_algorithms)); } @@ -209,15 +211,17 @@ static grpc_error* process_send_initial_metadata( return error; } -static void send_message_on_complete(void* arg, grpc_error* error) { +static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_reset_and_unref_internal(&calld->slices); - GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &calld->slices); + GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } -static void send_message_batch_continue(grpc_call_element* elem) { +static void send_message_batch_continue(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; // Note: The call to grpc_call_next_op() results in yielding the // call combiner, so we need to clear calld->send_message_batch @@ -225,18 +229,19 @@ static void send_message_batch_continue(grpc_call_element* elem) { grpc_transport_stream_op_batch* send_message_batch = calld->send_message_batch; calld->send_message_batch = nullptr; - grpc_call_next_op(elem, send_message_batch); + grpc_call_next_op(exec_ctx, elem, send_message_batch); } -static void finish_send_message(grpc_call_element* elem) { +static void finish_send_message(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; // Compress the data if appropriate. grpc_slice_buffer tmp; grpc_slice_buffer_init(&tmp); uint32_t send_flags = calld->send_message_batch->payload->send_message.send_message->flags; - bool did_compress = - grpc_msg_compress(calld->compression_algorithm, &calld->slices, &tmp); + bool did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm, + &calld->slices, &tmp); if (did_compress) { if (grpc_compression_trace.enabled()) { const char* algo_name; @@ -263,11 +268,11 @@ static void finish_send_message(grpc_call_element* elem) { algo_name, calld->slices.length); } } - grpc_slice_buffer_destroy_internal(&tmp); + grpc_slice_buffer_destroy_internal(exec_ctx, &tmp); // Swap out the original byte stream with our new one and send the // batch down. grpc_byte_stream_destroy( - calld->send_message_batch->payload->send_message.send_message); + exec_ctx, calld->send_message_batch->payload->send_message.send_message); grpc_slice_buffer_stream_init(&calld->replacement_stream, &calld->slices, send_flags); calld->send_message_batch->payload->send_message.send_message = @@ -275,24 +280,27 @@ static void finish_send_message(grpc_call_element* elem) { calld->original_send_message_on_complete = calld->send_message_batch->on_complete; calld->send_message_batch->on_complete = &calld->send_message_on_complete; - send_message_batch_continue(elem); + send_message_batch_continue(exec_ctx, elem); } -static void fail_send_message_batch_in_call_combiner(void* arg, +static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (calld->send_message_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - calld->send_message_batch, GRPC_ERROR_REF(error), calld->call_combiner); + exec_ctx, calld->send_message_batch, GRPC_ERROR_REF(error), + calld->call_combiner); calld->send_message_batch = nullptr; } } // Pulls a slice from the send_message byte stream and adds it to calld->slices. -static grpc_error* pull_slice_from_send_message(call_data* calld) { +static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, + call_data* calld) { grpc_slice incoming_slice; grpc_error* error = grpc_byte_stream_pull( - calld->send_message_batch->payload->send_message.send_message, + exec_ctx, calld->send_message_batch->payload->send_message.send_message, &incoming_slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&calld->slices, incoming_slice); @@ -304,65 +312,69 @@ static grpc_error* pull_slice_from_send_message(call_data* calld) { // If all data has been read, invokes finish_send_message(). Otherwise, // an async call to grpc_byte_stream_next() has been started, which will // eventually result in calling on_send_message_next_done(). -static void continue_reading_send_message(grpc_call_element* elem) { +static void continue_reading_send_message(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; while (grpc_byte_stream_next( - calld->send_message_batch->payload->send_message.send_message, ~(size_t)0, - &calld->on_send_message_next_done)) { - grpc_error* error = pull_slice_from_send_message(calld); + exec_ctx, calld->send_message_batch->payload->send_message.send_message, + ~(size_t)0, &calld->on_send_message_next_done)) { + grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(calld, error); + fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); GRPC_ERROR_UNREF(error); return; } if (calld->slices.length == calld->send_message_batch->payload->send_message.send_message->length) { - finish_send_message(elem); + finish_send_message(exec_ctx, elem); break; } } } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(void* arg, grpc_error* error) { +static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(calld, error); + fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); return; } - error = pull_slice_from_send_message(calld); + error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(calld, error); + fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); GRPC_ERROR_UNREF(error); return; } if (calld->slices.length == calld->send_message_batch->payload->send_message.send_message->length) { - finish_send_message(elem); + finish_send_message(exec_ctx, elem); } else { - continue_reading_send_message(elem); + continue_reading_send_message(exec_ctx, elem); } } -static void start_send_message_batch(void* arg, grpc_error* unused) { +static void start_send_message_batch(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* unused) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (skip_compression( elem, calld->send_message_batch->payload->send_message.send_message->flags, calld->send_initial_metadata_state == HAS_COMPRESSION_ALGORITHM)) { - send_message_batch_continue(elem); + send_message_batch_continue(exec_ctx, elem); } else { - continue_reading_send_message(elem); + continue_reading_send_message(exec_ctx, elem); } } static void compress_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("compress_start_transport_stream_op_batch", 0); // Handle cancel_stream. @@ -373,19 +385,21 @@ static void compress_start_transport_stream_op_batch( if (calld->send_message_batch != nullptr) { if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { GRPC_CALL_COMBINER_START( - calld->call_combiner, + exec_ctx, calld->call_combiner, GRPC_CLOSURE_CREATE(fail_send_message_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx), GRPC_ERROR_REF(calld->cancel_error), "failing send_message op"); } else { grpc_byte_stream_shutdown( + exec_ctx, calld->send_message_batch->payload->send_message.send_message, GRPC_ERROR_REF(calld->cancel_error)); } } } else if (calld->cancel_error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - batch, GRPC_ERROR_REF(calld->cancel_error), calld->call_combiner); + exec_ctx, batch, GRPC_ERROR_REF(calld->cancel_error), + calld->call_combiner); goto done; } // Handle send_initial_metadata. @@ -393,10 +407,11 @@ static void compress_start_transport_stream_op_batch( GPR_ASSERT(calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN); bool has_compression_algorithm; grpc_error* error = process_send_initial_metadata( - elem, batch->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, elem, + batch->payload->send_initial_metadata.send_initial_metadata, &has_compression_algorithm); if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_batch_finish_with_failure(batch, error, + grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, batch, error, calld->call_combiner); goto done; } @@ -410,7 +425,7 @@ static void compress_start_transport_stream_op_batch( // the call stack) will release the call combiner for each batch it sees. if (calld->send_message_batch != nullptr) { GRPC_CALL_COMBINER_START( - calld->call_combiner, + exec_ctx, calld->call_combiner, &calld->start_send_message_batch_in_call_combiner, GRPC_ERROR_NONE, "starting send_message after send_initial_metadata"); } @@ -425,21 +440,22 @@ static void compress_start_transport_stream_op_batch( // send_initial_metadata. if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { GRPC_CALL_COMBINER_STOP( - calld->call_combiner, + exec_ctx, calld->call_combiner, "send_message batch pending send_initial_metadata"); goto done; } - start_send_message_batch(elem, GRPC_ERROR_NONE); + start_send_message_batch(exec_ctx, elem, GRPC_ERROR_NONE); } else { // Pass control down the stack. - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); } done: GPR_TIMER_END("compress_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; @@ -455,16 +471,17 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_destroy_internal(&calld->slices); + grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices); GRPC_ERROR_UNREF(calld->cancel_error); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* channeld = (channel_data*)elem->channel_data; @@ -514,7 +531,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} const grpc_channel_filter grpc_message_compress_filter = { compress_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index b872dc98f5..4f3897915c 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -66,7 +66,8 @@ typedef struct channel_data { uint8_t unused; } channel_data; -static grpc_error* server_filter_outgoing_metadata(grpc_call_element* elem, +static grpc_error* server_filter_outgoing_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_metadata_batch* b) { if (b->idx.named.grpc_message != nullptr) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( @@ -74,9 +75,10 @@ static grpc_error* server_filter_outgoing_metadata(grpc_call_element* elem, grpc_compatible_percent_encoding_unreserved_bytes); if (grpc_slice_is_equivalent(pct_encoded_msg, GRPC_MDVALUE(b->idx.named.grpc_message->md))) { - grpc_slice_unref_internal(pct_encoded_msg); + grpc_slice_unref_internal(exec_ctx, pct_encoded_msg); } else { - grpc_metadata_batch_set_value(b->idx.named.grpc_message, pct_encoded_msg); + grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, + pct_encoded_msg); } } return GRPC_ERROR_NONE; @@ -91,7 +93,8 @@ static void add_error(const char* error_name, grpc_error** cumulative, *cumulative = grpc_error_add_child(*cumulative, new_err); } -static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, +static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_metadata_batch* b) { call_data* calld = (call_data*)elem->call_data; grpc_error* error = GRPC_ERROR_NONE; @@ -120,7 +123,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.method->md)); } - grpc_metadata_batch_remove(b, b->idx.named.method); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.method); } else { add_error( error_name, &error, @@ -136,7 +139,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.te->md)); } - grpc_metadata_batch_remove(b, b->idx.named.te); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.te); } else { add_error(error_name, &error, grpc_error_set_str( @@ -153,7 +156,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.scheme->md)); } - grpc_metadata_batch_remove(b, b->idx.named.scheme); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.scheme); } else { add_error( error_name, &error, @@ -188,7 +191,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, gpr_free(val); } } - grpc_metadata_batch_remove(b, b->idx.named.content_type); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); } if (b->idx.named.path == nullptr) { @@ -215,21 +218,22 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, /* substitute path metadata with just the path (not query) */ grpc_mdelem mdelem_path_without_query = grpc_mdelem_from_slices( - GRPC_MDSTR_PATH, grpc_slice_sub(path_slice, 0, offset)); + exec_ctx, GRPC_MDSTR_PATH, grpc_slice_sub(path_slice, 0, offset)); - grpc_metadata_batch_substitute(b, b->idx.named.path, + grpc_metadata_batch_substitute(exec_ctx, b, b->idx.named.path, mdelem_path_without_query); /* decode payload from query and add to the slice buffer to be returned */ const int k_url_safe = 1; - grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_base64_decode_with_len( - (const char*)GRPC_SLICE_START_PTR(query_slice), - GRPC_SLICE_LENGTH(query_slice), k_url_safe)); + grpc_slice_buffer_add( + &calld->read_slice_buffer, + grpc_base64_decode_with_len( + exec_ctx, (const char*)GRPC_SLICE_START_PTR(query_slice), + GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); calld->seen_path_with_query = true; - grpc_slice_unref_internal(query_slice); + grpc_slice_unref_internal(exec_ctx, query_slice); } else { gpr_log(GPR_ERROR, "GET request without QUERY"); } @@ -238,14 +242,14 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, if (b->idx.named.host != nullptr && b->idx.named.authority == nullptr) { grpc_linked_mdelem* el = b->idx.named.host; grpc_mdelem md = GRPC_MDELEM_REF(el->md); - grpc_metadata_batch_remove(b, el); + grpc_metadata_batch_remove(exec_ctx, b, el); add_error(error_name, &error, grpc_metadata_batch_add_head( - b, el, + exec_ctx, b, el, grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, + exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(GRPC_MDVALUE(md))))); - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } if (b->idx.named.authority == nullptr) { @@ -259,18 +263,21 @@ static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, return error; } -static void hs_on_recv(void* user_data, grpc_error* err) { +static void hs_on_recv(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (err == GRPC_ERROR_NONE) { - err = server_filter_incoming_metadata(elem, calld->recv_initial_metadata); + err = server_filter_incoming_metadata(exec_ctx, elem, + calld->recv_initial_metadata); } else { GRPC_ERROR_REF(err); } - GRPC_CLOSURE_RUN(calld->on_done_recv, err); + GRPC_CLOSURE_RUN(exec_ctx, calld->on_done_recv, err); } -static void hs_on_complete(void* user_data, grpc_error* err) { +static void hs_on_complete(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; /* Call recv_message_ready if we got the payload via the path field */ @@ -280,16 +287,17 @@ static void hs_on_complete(void* user_data, grpc_error* err) { : (grpc_byte_stream*)&calld->read_stream; // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. - GRPC_CALL_COMBINER_START(calld->call_combiner, calld->recv_message_ready, - GRPC_ERROR_REF(err), + GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, + calld->recv_message_ready, GRPC_ERROR_REF(err), "resuming recv_message_ready from on_complete"); calld->recv_message_ready = nullptr; calld->payload_bin_delivered = true; } - GRPC_CLOSURE_RUN(calld->on_complete, GRPC_ERROR_REF(err)); + GRPC_CLOSURE_RUN(exec_ctx, calld->on_complete, GRPC_ERROR_REF(err)); } -static void hs_recv_message_ready(void* user_data, grpc_error* err) { +static void hs_recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (calld->seen_path_with_query) { @@ -297,14 +305,15 @@ static void hs_recv_message_ready(void* user_data, grpc_error* err) { // returned in hs_on_complete callback. // Note that we release the call combiner here, so that other // callbacks can run. - GRPC_CALL_COMBINER_STOP(calld->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, "pausing recv_message_ready until on_complete"); } else { - GRPC_CLOSURE_RUN(calld->recv_message_ready, GRPC_ERROR_REF(err)); + GRPC_CLOSURE_RUN(exec_ctx, calld->recv_message_ready, GRPC_ERROR_REF(err)); } } -static grpc_error* hs_mutate_op(grpc_call_element* elem, +static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { /* grab pointers to our data from the call element */ call_data* calld = (call_data*)elem->call_data; @@ -312,19 +321,21 @@ static grpc_error* hs_mutate_op(grpc_call_element* elem, if (op->send_initial_metadata) { grpc_error* error = GRPC_ERROR_NONE; static const char* error_name = "Failed sending initial metadata"; - add_error(error_name, &error, - grpc_metadata_batch_add_head( - op->payload->send_initial_metadata.send_initial_metadata, - &calld->status, GRPC_MDELEM_STATUS_200)); - add_error(error_name, &error, - grpc_metadata_batch_add_tail( - op->payload->send_initial_metadata.send_initial_metadata, - &calld->content_type, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); add_error( error_name, &error, - server_filter_outgoing_metadata( - elem, op->payload->send_initial_metadata.send_initial_metadata)); + grpc_metadata_batch_add_head( + exec_ctx, op->payload->send_initial_metadata.send_initial_metadata, + &calld->status, GRPC_MDELEM_STATUS_200)); + add_error( + error_name, &error, + grpc_metadata_batch_add_tail( + exec_ctx, op->payload->send_initial_metadata.send_initial_metadata, + &calld->content_type, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); + add_error(error_name, &error, + server_filter_outgoing_metadata( + exec_ctx, elem, + op->payload->send_initial_metadata.send_initial_metadata)); if (error != GRPC_ERROR_NONE) return error; } @@ -356,7 +367,8 @@ static grpc_error* hs_mutate_op(grpc_call_element* elem, if (op->send_trailing_metadata) { grpc_error* error = server_filter_outgoing_metadata( - elem, op->payload->send_trailing_metadata.send_trailing_metadata); + exec_ctx, elem, + op->payload->send_trailing_metadata.send_trailing_metadata); if (error != GRPC_ERROR_NONE) return error; } @@ -364,21 +376,23 @@ static grpc_error* hs_mutate_op(grpc_call_element* elem, } static void hs_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("hs_start_transport_stream_op_batch", 0); - grpc_error* error = hs_mutate_op(elem, op); + grpc_error* error = hs_mutate_op(exec_ctx, elem, op); if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_batch_finish_with_failure(op, error, + grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, op, error, calld->call_combiner); } else { - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } GPR_TIMER_END("hs_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { /* grab pointers to our data from the call element */ call_data* calld = (call_data*)elem->call_data; @@ -395,22 +409,24 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_destroy_internal(&calld->read_slice_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &calld->read_slice_buffer); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} const grpc_channel_filter grpc_http_server_filter = { hs_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index f50a928fcd..762198f034 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -54,7 +54,8 @@ typedef struct channel_data { intptr_t id; /**< an id unique to the channel */ } channel_data; -static void on_initial_md_ready(void* user_data, grpc_error* err) { +static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -72,19 +73,20 @@ static void on_initial_md_ready(void* user_data, grpc_error* err) { GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); calld->have_initial_md_string = true; grpc_metadata_batch_remove( - calld->recv_initial_metadata, + exec_ctx, calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.lb_token); } } else { GRPC_ERROR_REF(err); } calld->ops_recv_initial_metadata_ready->cb( - calld->ops_recv_initial_metadata_ready->cb_arg, err); + exec_ctx, calld->ops_recv_initial_metadata_ready->cb_arg, err); GRPC_ERROR_UNREF(err); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->id = (intptr_t)args->call_stack; @@ -106,7 +108,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; @@ -123,18 +125,19 @@ static void destroy_call_elem(grpc_call_element* elem, */ if (calld->have_initial_md_string) { - grpc_slice_unref_internal(calld->initial_md_string); + grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); } if (calld->have_trailing_md_string) { - grpc_slice_unref_internal(calld->trailing_md_string); + grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); } if (calld->have_service_method) { - grpc_slice_unref_internal(calld->service_method); + grpc_slice_unref_internal(exec_ctx, calld->service_method); } } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); @@ -155,7 +158,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { /* TODO(dgq): do something with the data channel_data *chand = elem->channel_data; grpc_load_reporting_call_data lr_call_data = { @@ -169,7 +173,8 @@ static void destroy_channel_elem(grpc_channel_element* elem) { */ } -static grpc_filtered_mdelem lr_trailing_md_filter(void* user_data, +static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_mdelem md) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -181,7 +186,8 @@ static grpc_filtered_mdelem lr_trailing_md_filter(void* user_data, } static void lr_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { GPR_TIMER_BEGIN("lr_start_transport_stream_op_batch", 0); call_data* calld = (call_data*)elem->call_data; @@ -197,11 +203,12 @@ static void lr_start_transport_stream_op_batch( GRPC_LOG_IF_ERROR( "grpc_metadata_batch_filter", grpc_metadata_batch_filter( + exec_ctx, op->payload->send_trailing_metadata.send_trailing_metadata, lr_trailing_md_filter, elem, "LR trailing metadata filtering error")); } - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); GPR_TIMER_END("lr_start_transport_stream_op_batch", 0); } diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index 9d1dfcbb4c..accb7797dd 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -38,7 +38,7 @@ static bool is_load_reporting_enabled(const grpc_channel_args* a) { } static bool maybe_add_server_load_reporting_filter( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_channel_filter* filter = (const grpc_channel_filter*)arg; diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 0499c6ecfc..917fbd9198 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -88,69 +88,73 @@ typedef struct channel_data { /* Increase the nubmer of active calls. Before the increasement, if there are no calls, the max_idle_timer should be cancelled. */ -static void increase_call_count(channel_data* chand) { +static void increase_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, 1) == 0) { - grpc_timer_cancel(&chand->max_idle_timer); + grpc_timer_cancel(exec_ctx, &chand->max_idle_timer); } } /* Decrease the nubmer of active calls. After the decrement, if there are no calls, the max_idle_timer should be started. */ -static void decrease_call_count(channel_data* chand) { +static void decrease_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); - grpc_timer_init( - &chand->max_idle_timer, - grpc_core::ExecCtx::Get()->Now() + chand->max_connection_idle, - &chand->close_max_idle_channel); + grpc_timer_init(exec_ctx, &chand->max_idle_timer, + grpc_exec_ctx_now(exec_ctx) + chand->max_connection_idle, + &chand->close_max_idle_channel); } } -static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { +static void start_max_idle_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; /* Decrease call_count. If there are no active calls at this time, max_idle_timer will start here. If the number of active calls is not 0, max_idle_timer will start after all the active calls end. */ - decrease_call_count(chand); - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, + decrease_call_count(exec_ctx, chand); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, "max_age start_max_idle_timer_after_init"); } -static void start_max_age_timer_after_init(void* arg, grpc_error* error) { +static void start_max_age_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); - grpc_timer_init(&chand->max_age_timer, - grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age, + grpc_timer_init(exec_ctx, &chand->max_age_timer, + grpc_exec_ctx_now(exec_ctx) + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), op); - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, + grpc_channel_next_op(exec_ctx, + grpc_channel_stack_element(chand->channel_stack, 0), op); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, "max_age start_max_age_timer_after_init"); } -static void start_max_age_grace_timer_after_goaway_op(void* arg, +static void start_max_age_grace_timer_after_goaway_op(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); grpc_timer_init( - &chand->max_age_grace_timer, + exec_ctx, &chand->max_age_grace_timer, chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE ? GRPC_MILLIS_INF_FUTURE - : grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age_grace, + : grpc_exec_ctx_now(exec_ctx) + chand->max_connection_age_grace, &chand->force_close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, "max_age start_max_age_grace_timer_after_goaway_op"); } -static void close_max_idle_channel(void* arg, grpc_error* error) { +static void close_max_idle_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; if (error == GRPC_ERROR_NONE) { /* Prevent the max idle timer from being set again */ @@ -161,14 +165,16 @@ static void close_max_idle_channel(void* arg, grpc_error* error) { GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("close_max_idle_channel", error); } - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_idle_timer"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + "max_age max_idle_timer"); } -static void close_max_age_channel(void* arg, grpc_error* error) { +static void close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = false; @@ -183,14 +189,16 @@ static void close_max_age_channel(void* arg, grpc_error* error) { GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("close_max_age_channel", error); } - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_timer"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + "max_age max_age_timer"); } -static void force_close_max_age_channel(void* arg, grpc_error* error) { +static void force_close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = false; @@ -201,36 +209,38 @@ static void force_close_max_age_channel(void* arg, grpc_error* error) { GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel reaches max age"); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("force_close_max_age_channel", error); } - GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_grace_timer"); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + "max_age max_age_grace_timer"); } -static void channel_connectivity_changed(void* arg, grpc_error* error) { +static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { channel_data* chand = (channel_data*)arg; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), - op); + grpc_channel_next_op( + exec_ctx, grpc_channel_stack_element(chand->channel_stack, 0), op); } else { gpr_mu_lock(&chand->max_age_timer_mu); if (chand->max_age_timer_pending) { - grpc_timer_cancel(&chand->max_age_timer); + grpc_timer_cancel(exec_ctx, &chand->max_age_timer); chand->max_age_timer_pending = false; } if (chand->max_age_grace_timer_pending) { - grpc_timer_cancel(&chand->max_age_grace_timer); + grpc_timer_cancel(exec_ctx, &chand->max_age_grace_timer); chand->max_age_grace_timer_pending = false; } gpr_mu_unlock(&chand->max_age_timer_mu); /* If there are no active calls, this increasement will cancel max_idle_timer, and prevent max_idle_timer from being started in the future. */ - increase_call_count(chand); + increase_call_count(exec_ctx, chand); } } @@ -253,23 +263,25 @@ add_random_max_connection_age_jitter_and_convert_to_grpc_millis(int value) { } /* Constructor for call_data. */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; - increase_call_count(chand); + increase_call_count(exec_ctx, chand); return GRPC_ERROR_NONE; } /* Destructor for call_data. */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { channel_data* chand = (channel_data*)elem->channel_data; - decrease_call_count(chand); + decrease_call_count(exec_ctx, chand); } /* Constructor for channel_data. */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_init(&chand->max_age_timer_mu); @@ -339,7 +351,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, initialization is done. */ GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age start_max_age_timer_after_init"); - GRPC_CLOSURE_SCHED(&chand->start_max_age_timer_after_init, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &chand->start_max_age_timer_after_init, + GRPC_ERROR_NONE); } /* Initialize the number of calls as 1, so that the max_idle_timer will not @@ -348,14 +361,15 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, if (chand->max_connection_idle != GRPC_MILLIS_INF_FUTURE) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age start_max_idle_timer_after_init"); - GRPC_CLOSURE_SCHED(&chand->start_max_idle_timer_after_init, + GRPC_CLOSURE_SCHED(exec_ctx, &chand->start_max_idle_timer_after_init, GRPC_ERROR_NONE); } return GRPC_ERROR_NONE; } /* Destructor for channel_data. */ -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} const grpc_channel_filter grpc_max_age_filter = { grpc_call_next_op, @@ -370,7 +384,8 @@ const grpc_channel_filter grpc_max_age_filter = { grpc_channel_next_get_info, "max_age"}; -static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index f8487f9a9e..3d2252af2e 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -47,7 +47,8 @@ static void* refcounted_message_size_limits_ref(void* value) { return value; } -static void refcounted_message_size_limits_unref(void* value) { +static void refcounted_message_size_limits_unref(grpc_exec_ctx* exec_ctx, + void* value) { refcounted_message_size_limits* limits = (refcounted_message_size_limits*)value; if (gpr_unref(&limits->refs)) { @@ -107,7 +108,8 @@ typedef struct channel_data { // Callback invoked when we receive a message. Here we check the max // receive message size. -static void recv_message_ready(void* user_data, grpc_error* error) { +static void recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (*calld->recv_message != nullptr && calld->limits.max_recv_size >= 0 && @@ -130,12 +132,13 @@ static void recv_message_ready(void* user_data, grpc_error* error) { GRPC_ERROR_REF(error); } // Invoke the next callback. - GRPC_CLOSURE_RUN(calld->next_recv_message_ready, error); + GRPC_CLOSURE_RUN(exec_ctx, calld->next_recv_message_ready, error); } // Start transport stream op. static void start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; // Check max send message size. if (op->send_message && calld->limits.max_send_size >= 0 && @@ -146,7 +149,7 @@ static void start_transport_stream_op_batch( op->payload->send_message.send_message->length, calld->limits.max_send_size); grpc_transport_stream_op_batch_finish_with_failure( - op, + exec_ctx, op, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(message_string), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED), @@ -162,11 +165,12 @@ static void start_transport_stream_op_batch( op->payload->recv_message.recv_message_ready = &calld->recv_message_ready; } // Chain to the next filter. - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } // Constructor for call_data. -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -182,7 +186,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, if (chand->method_limit_table != nullptr) { refcounted_message_size_limits* limits = (refcounted_message_size_limits*)grpc_method_config_table_get( - chand->method_limit_table, args->path); + exec_ctx, chand->method_limit_table, args->path); if (limits != nullptr) { if (limits->limits.max_send_size >= 0 && (limits->limits.max_send_size < calld->limits.max_send_size || @@ -200,7 +204,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } // Destructor for call_data. -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} @@ -237,7 +241,8 @@ message_size_limits get_message_size_limits( } // Constructor for channel_data. -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); channel_data* chand = (channel_data*)elem->channel_data; @@ -252,7 +257,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, if (service_config != nullptr) { chand->method_limit_table = grpc_service_config_create_method_config_table( - service_config, refcounted_message_size_limits_create_from_json, + exec_ctx, service_config, + refcounted_message_size_limits_create_from_json, refcounted_message_size_limits_ref, refcounted_message_size_limits_unref); grpc_service_config_destroy(service_config); @@ -262,9 +268,10 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } // Destructor for channel_data. -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - grpc_slice_hash_table_unref(chand->method_limit_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_limit_table); } const grpc_channel_filter grpc_message_size_filter = { @@ -280,7 +287,8 @@ const grpc_channel_filter grpc_message_size_filter = { grpc_channel_next_get_info, "message_size"}; -static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_message_size_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); diff --git a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc index 555a9134a2..4ab1ee4e79 100644 --- a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +++ b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc @@ -50,7 +50,8 @@ static bool get_user_agent_mdelem(const grpc_metadata_batch* batch, } // Callback invoked when we receive an initial metadata. -static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -66,13 +67,14 @@ static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { } // Invoke the next callback. - GRPC_CLOSURE_RUN(calld->next_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(exec_ctx, calld->next_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } // Start transport stream op. static void start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; // Inject callback for receiving initial metadata @@ -94,11 +96,12 @@ static void start_transport_stream_op_batch( } // Chain to the next filter. - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } // Constructor for call_data. -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->next_recv_initial_metadata_ready = nullptr; @@ -110,18 +113,20 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } // Destructor for call_data. -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} // Constructor for channel_data. -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } // Destructor for channel_data. -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} // Parse the user agent static bool parse_user_agent(grpc_mdelem md) { @@ -176,7 +181,7 @@ const grpc_channel_filter grpc_workaround_cronet_compression_filter = { "workaround_cronet_compression"}; static bool register_workaround_cronet_compression( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* a = grpc_channel_args_find( diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index db5962e7fd..819f66aec3 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -61,34 +61,38 @@ static void chttp2_connector_ref(grpc_connector* con) { gpr_ref(&c->refs); } -static void chttp2_connector_unref(grpc_connector* con) { +static void chttp2_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_connector* con) { chttp2_connector* c = (chttp2_connector*)con; if (gpr_unref(&c->refs)) { gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. // Otherwise, the handshaker will do this for us. - if (c->endpoint != nullptr) grpc_endpoint_destroy(c->endpoint); + if (c->endpoint != nullptr) grpc_endpoint_destroy(exec_ctx, c->endpoint); gpr_free(c); } } -static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { +static void chttp2_connector_shutdown(grpc_exec_ctx* exec_ctx, + grpc_connector* con, grpc_error* why) { chttp2_connector* c = (chttp2_connector*)con; gpr_mu_lock(&c->mu); c->shutdown = true; if (c->handshake_mgr != nullptr) { - grpc_handshake_manager_shutdown(c->handshake_mgr, GRPC_ERROR_REF(why)); + grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr, + GRPC_ERROR_REF(why)); } // If handshaking is not yet in progress, shutdown the endpoint. // Otherwise, the handshaker will do this for us. if (!c->connecting && c->endpoint != nullptr) { - grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(why)); + grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(why)); } gpr_mu_unlock(&c->mu); GRPC_ERROR_UNREF(why); } -static void on_handshake_done(void* arg, grpc_error* error) { +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; chttp2_connector* c = (chttp2_connector*)args->user_data; gpr_mu_lock(&c->mu); @@ -101,20 +105,20 @@ static void on_handshake_done(void* arg, grpc_error* error) { // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(args->endpoint, GRPC_ERROR_REF(error)); - grpc_endpoint_destroy(args->endpoint); - grpc_channel_args_destroy(args->args); - grpc_slice_buffer_destroy_internal(args->read_buffer); + grpc_endpoint_shutdown(exec_ctx, args->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_destroy(exec_ctx, args->endpoint); + grpc_channel_args_destroy(exec_ctx, args->args); + grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); gpr_free(args->read_buffer); } else { error = GRPC_ERROR_REF(error); } memset(c->result, 0, sizeof(*c->result)); } else { - grpc_endpoint_delete_from_pollset_set(args->endpoint, + grpc_endpoint_delete_from_pollset_set(exec_ctx, args->endpoint, c->args.interested_parties); - c->result->transport = - grpc_create_chttp2_transport(args->args, args->endpoint, true); + c->result->transport = grpc_create_chttp2_transport(exec_ctx, args->args, + args->endpoint, true); GPR_ASSERT(c->result->transport); // TODO(roth): We ideally want to wait until we receive HTTP/2 // settings from the server before we consider the connection @@ -140,32 +144,34 @@ static void on_handshake_done(void* arg, grpc_error* error) { // so until after transparent retries is implemented. Otherwise, any // RPC that we attempt to send on the connection before the timeout // would fail instead of being retried on a subsequent attempt. - grpc_chttp2_transport_start_reading(c->result->transport, args->read_buffer, - nullptr); + grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, + args->read_buffer, nullptr); c->result->channel_args = args->args; } grpc_closure* notify = c->notify; c->notify = nullptr; - GRPC_CLOSURE_SCHED(notify, error); - grpc_handshake_manager_destroy(c->handshake_mgr); + GRPC_CLOSURE_SCHED(exec_ctx, notify, error); + grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); c->handshake_mgr = nullptr; gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)c); + chttp2_connector_unref(exec_ctx, (grpc_connector*)c); } -static void start_handshake_locked(chttp2_connector* c) { +static void start_handshake_locked(grpc_exec_ctx* exec_ctx, + chttp2_connector* c) { c->handshake_mgr = grpc_handshake_manager_create(); - grpc_handshakers_add(HANDSHAKER_CLIENT, c->args.channel_args, + grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, c->args.channel_args, c->handshake_mgr); - grpc_endpoint_add_to_pollset_set(c->endpoint, c->args.interested_parties); + grpc_endpoint_add_to_pollset_set(exec_ctx, c->endpoint, + c->args.interested_parties); grpc_handshake_manager_do_handshake( - c->handshake_mgr, c->args.interested_parties, c->endpoint, + exec_ctx, c->handshake_mgr, c->args.interested_parties, c->endpoint, c->args.channel_args, c->args.deadline, nullptr /* acceptor */, on_handshake_done, c); c->endpoint = nullptr; // Endpoint handed off to handshake manager. } -static void connected(void* arg, grpc_error* error) { +static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { chttp2_connector* c = (chttp2_connector*)arg; gpr_mu_lock(&c->mu); GPR_ASSERT(c->connecting); @@ -179,26 +185,27 @@ static void connected(void* arg, grpc_error* error) { memset(c->result, 0, sizeof(*c->result)); grpc_closure* notify = c->notify; c->notify = nullptr; - GRPC_CLOSURE_SCHED(notify, error); + GRPC_CLOSURE_SCHED(exec_ctx, notify, error); if (c->endpoint != nullptr) { - grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)arg); + chttp2_connector_unref(exec_ctx, (grpc_connector*)arg); } else { GPR_ASSERT(c->endpoint != nullptr); - start_handshake_locked(c); + start_handshake_locked(exec_ctx, c); gpr_mu_unlock(&c->mu); } } -static void chttp2_connector_connect(grpc_connector* con, +static void chttp2_connector_connect(grpc_exec_ctx* exec_ctx, + grpc_connector* con, const grpc_connect_in_args* args, grpc_connect_out_args* result, grpc_closure* notify) { chttp2_connector* c = (chttp2_connector*)con; grpc_resolved_address addr; - grpc_get_subchannel_address_arg(args->channel_args, &addr); + grpc_get_subchannel_address_arg(exec_ctx, args->channel_args, &addr); gpr_mu_lock(&c->mu); GPR_ASSERT(c->notify == nullptr); c->notify = notify; @@ -209,8 +216,9 @@ static void chttp2_connector_connect(grpc_connector* con, GRPC_CLOSURE_INIT(&c->connected, connected, c, grpc_schedule_on_exec_ctx); GPR_ASSERT(!c->connecting); c->connecting = true; - grpc_tcp_client_connect(&c->connected, &c->endpoint, args->interested_parties, - args->channel_args, &addr, args->deadline); + grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint, + args->interested_parties, args->channel_args, &addr, + args->deadline); gpr_mu_unlock(&c->mu); } diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 6a1b70964d..028b69e5ff 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -34,19 +34,21 @@ static void client_channel_factory_ref( grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_client_channel_factory* cc_factory) {} + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} static grpc_subchannel* client_channel_factory_create_subchannel( - grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const grpc_subchannel_args* args) { grpc_connector* connector = grpc_chttp2_connector_create(); - grpc_subchannel* s = grpc_subchannel_create(connector, args); - grpc_connector_unref(connector); + grpc_subchannel* s = grpc_subchannel_create(exec_ctx, connector, args); + grpc_connector_unref(exec_ctx, connector); return s; } static grpc_channel* client_channel_factory_create_channel( - grpc_client_channel_factory* cc_factory, const char* target, - grpc_client_channel_type type, const grpc_channel_args* args) { + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args) { if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return nullptr; @@ -54,14 +56,14 @@ static grpc_channel* client_channel_factory_create_channel( // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(target)); + grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); - grpc_channel* channel = - grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); - grpc_channel_args_destroy(new_args); + grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, + GRPC_CLIENT_CHANNEL, nullptr); + grpc_channel_args_destroy(exec_ctx, new_args); return channel; } @@ -80,7 +82,7 @@ static grpc_client_channel_factory client_channel_factory = { grpc_channel* grpc_insecure_channel_create(const char* target, const grpc_channel_args* args, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); @@ -91,11 +93,11 @@ grpc_channel* grpc_insecure_channel_create(const char* target, grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); // Create channel. grpc_channel* channel = client_channel_factory_create_channel( - &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, - new_args); + &exec_ctx, &client_channel_factory, target, + GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); // Clean up. - grpc_channel_args_destroy(new_args); - + grpc_channel_args_destroy(&exec_ctx, new_args); + grpc_exec_ctx_finish(&exec_ctx); return channel != nullptr ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index 0cdea5a94e..c6b149d0b1 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -37,7 +37,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, (target, fd, args)); @@ -50,17 +50,17 @@ grpc_channel* grpc_insecure_channel_create_from_fd( GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); grpc_endpoint* client = grpc_tcp_client_create_from_fd( - grpc_fd_create(fd, "client"), args, "fd-client"); + &exec_ctx, grpc_fd_create(fd, "client"), args, "fd-client"); grpc_transport* transport = - grpc_create_chttp2_transport(final_args, client, true); + grpc_create_chttp2_transport(&exec_ctx, final_args, client, true); GPR_ASSERT(transport); grpc_channel* channel = grpc_channel_create( - target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_channel_args_destroy(final_args); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + &exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_channel_args_destroy(&exec_ctx, final_args); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); return channel != nullptr ? channel : grpc_lame_client_channel_create( @@ -73,7 +73,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { GPR_ASSERT(0); - return nullptr; + return NULL; } #endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 27c5b96a4c..dd2bc427a7 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -41,10 +41,10 @@ static void client_channel_factory_ref( grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_client_channel_factory* cc_factory) {} + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} static grpc_subchannel_args* get_secure_naming_subchannel_args( - const grpc_subchannel_args* args) { + grpc_exec_ctx* exec_ctx, const grpc_subchannel_args* args) { grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args->args); if (channel_credentials == nullptr) { @@ -68,7 +68,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* server_uri_str = server_uri_arg->value.string; GPR_ASSERT(server_uri_str != nullptr); grpc_uri* server_uri = - grpc_uri_parse(server_uri_str, true /* supress errors */); + grpc_uri_parse(exec_ctx, server_uri_str, true /* supress errors */); GPR_ASSERT(server_uri != nullptr); const char* server_uri_path; server_uri_path = @@ -81,7 +81,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* target_uri_str = grpc_get_subchannel_address_uri_arg(args->args); grpc_uri* target_uri = - grpc_uri_parse(target_uri_str, false /* suppress errors */); + grpc_uri_parse(exec_ctx, target_uri_str, false /* suppress errors */); GPR_ASSERT(target_uri != nullptr); if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( @@ -89,7 +89,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* value = (const char*)grpc_slice_hash_table_get(targets_info, key); if (value != nullptr) target_name_to_check = gpr_strdup(value); - grpc_slice_unref_internal(key); + grpc_slice_unref_internal(exec_ctx, key); } if (target_name_to_check == nullptr) { // If the target name to check hasn't already been set, fall back to using @@ -107,7 +107,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args* new_args_from_connector = nullptr; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( - channel_credentials, target_name_to_check, args->args, + exec_ctx, channel_credentials, target_name_to_check, args->args, &subchannel_security_connector, &new_args_from_connector); if (security_status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, @@ -123,10 +123,10 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args* new_args = grpc_channel_args_copy_and_add( new_args_from_connector != nullptr ? new_args_from_connector : args->args, &new_security_connector_arg, 1); - GRPC_SECURITY_CONNECTOR_UNREF(&subchannel_security_connector->base, + GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &subchannel_security_connector->base, "lb_channel_create"); if (new_args_from_connector != nullptr) { - grpc_channel_args_destroy(new_args_from_connector); + grpc_channel_args_destroy(exec_ctx, new_args_from_connector); } grpc_subchannel_args* final_sc_args = (grpc_subchannel_args*)gpr_malloc(sizeof(*final_sc_args)); @@ -136,9 +136,10 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( } static grpc_subchannel* client_channel_factory_create_subchannel( - grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const grpc_subchannel_args* args) { grpc_subchannel_args* subchannel_args = - get_secure_naming_subchannel_args(args); + get_secure_naming_subchannel_args(exec_ctx, args); if (subchannel_args == nullptr) { gpr_log( GPR_ERROR, @@ -146,16 +147,19 @@ static grpc_subchannel* client_channel_factory_create_subchannel( return nullptr; } grpc_connector* connector = grpc_chttp2_connector_create(); - grpc_subchannel* s = grpc_subchannel_create(connector, subchannel_args); - grpc_connector_unref(connector); - grpc_channel_args_destroy((grpc_channel_args*)subchannel_args->args); + grpc_subchannel* s = + grpc_subchannel_create(exec_ctx, connector, subchannel_args); + grpc_connector_unref(exec_ctx, connector); + grpc_channel_args_destroy(exec_ctx, + (grpc_channel_args*)subchannel_args->args); gpr_free(subchannel_args); return s; } static grpc_channel* client_channel_factory_create_channel( - grpc_client_channel_factory* cc_factory, const char* target, - grpc_client_channel_type type, const grpc_channel_args* args) { + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args) { if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return nullptr; @@ -163,14 +167,14 @@ static grpc_channel* client_channel_factory_create_channel( // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(target)); + grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); - grpc_channel* channel = - grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); - grpc_channel_args_destroy(new_args); + grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, + GRPC_CLIENT_CHANNEL, nullptr); + grpc_channel_args_destroy(exec_ctx, new_args); return channel; } @@ -190,7 +194,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, const char* target, const grpc_channel_args* args, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", @@ -207,10 +211,11 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, args, args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Create channel. channel = client_channel_factory_create_channel( - &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, - new_args); + &exec_ctx, &client_channel_factory, target, + GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); // Clean up. - grpc_channel_args_destroy(new_args); + grpc_channel_args_destroy(&exec_ctx, new_args); + grpc_exec_ctx_finish(&exec_ctx); } return channel != nullptr ? channel : grpc_lame_client_channel_create( diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 5669fa4090..49ee677464 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -69,17 +69,17 @@ typedef struct { } server_connection_state; static void server_connection_state_unref( - server_connection_state* connection_state) { + grpc_exec_ctx* exec_ctx, server_connection_state* connection_state) { if (gpr_unref(&connection_state->refs)) { if (connection_state->transport != nullptr) { - GRPC_CHTTP2_UNREF_TRANSPORT(connection_state->transport, + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, connection_state->transport, "receive settings timeout"); } gpr_free(connection_state); } } -static void on_timeout(void* arg, grpc_error* error) { +static void on_timeout(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { server_connection_state* connection_state = (server_connection_state*)arg; // Note that we may be called with GRPC_ERROR_NONE when the timer fires // or with an error indicating that the timer system is being shut down. @@ -87,20 +87,22 @@ static void on_timeout(void* arg, grpc_error* error) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Did not receive HTTP/2 settings before handshake timeout"); - grpc_transport_perform_op(&connection_state->transport->base, op); + grpc_transport_perform_op(exec_ctx, &connection_state->transport->base, op); } - server_connection_state_unref(connection_state); + server_connection_state_unref(exec_ctx, connection_state); } -static void on_receive_settings(void* arg, grpc_error* error) { +static void on_receive_settings(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { server_connection_state* connection_state = (server_connection_state*)arg; if (error == GRPC_ERROR_NONE) { - grpc_timer_cancel(&connection_state->timer); + grpc_timer_cancel(exec_ctx, &connection_state->timer); } - server_connection_state_unref(connection_state); + server_connection_state_unref(exec_ctx, connection_state); } -static void on_handshake_done(void* arg, grpc_error* error) { +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; server_connection_state* connection_state = (server_connection_state*)args->user_data; @@ -115,10 +117,10 @@ static void on_handshake_done(void* arg, grpc_error* error) { // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(args->endpoint, GRPC_ERROR_NONE); - grpc_endpoint_destroy(args->endpoint); - grpc_channel_args_destroy(args->args); - grpc_slice_buffer_destroy_internal(args->read_buffer); + grpc_endpoint_shutdown(exec_ctx, args->endpoint, GRPC_ERROR_NONE); + grpc_endpoint_destroy(exec_ctx, args->endpoint); + grpc_channel_args_destroy(exec_ctx, args->args); + grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); gpr_free(args->read_buffer); } } else { @@ -126,10 +128,10 @@ static void on_handshake_done(void* arg, grpc_error* error) { // handshaker may have handed off the connection to some external // code, so we can just clean up here without creating a transport. if (args->endpoint != nullptr) { - grpc_transport* transport = - grpc_create_chttp2_transport(args->args, args->endpoint, false); + grpc_transport* transport = grpc_create_chttp2_transport( + exec_ctx, args->args, args->endpoint, false); grpc_server_setup_transport( - connection_state->svr_state->server, transport, + exec_ctx, connection_state->svr_state->server, transport, connection_state->accepting_pollset, args->args); // Use notify_on_receive_settings callback to enforce the // handshake deadline. @@ -139,14 +141,16 @@ static void on_handshake_done(void* arg, grpc_error* error) { on_receive_settings, connection_state, grpc_schedule_on_exec_ctx); grpc_chttp2_transport_start_reading( - transport, args->read_buffer, &connection_state->on_receive_settings); - grpc_channel_args_destroy(args->args); + exec_ctx, transport, args->read_buffer, + &connection_state->on_receive_settings); + grpc_channel_args_destroy(exec_ctx, args->args); gpr_ref(&connection_state->refs); GRPC_CHTTP2_REF_TRANSPORT((grpc_chttp2_transport*)transport, "receive settings timeout"); GRPC_CLOSURE_INIT(&connection_state->on_timeout, on_timeout, connection_state, grpc_schedule_on_exec_ctx); - grpc_timer_init(&connection_state->timer, connection_state->deadline, + grpc_timer_init(exec_ctx, &connection_state->timer, + connection_state->deadline, &connection_state->on_timeout); } } @@ -154,21 +158,21 @@ static void on_handshake_done(void* arg, grpc_error* error) { &connection_state->svr_state->pending_handshake_mgrs, connection_state->handshake_mgr); gpr_mu_unlock(&connection_state->svr_state->mu); - grpc_handshake_manager_destroy(connection_state->handshake_mgr); + grpc_handshake_manager_destroy(exec_ctx, connection_state->handshake_mgr); gpr_free(connection_state->acceptor); - grpc_tcp_server_unref(connection_state->svr_state->tcp_server); - server_connection_state_unref(connection_state); + grpc_tcp_server_unref(exec_ctx, connection_state->svr_state->tcp_server); + server_connection_state_unref(exec_ctx, connection_state); } -static void on_accept(void* arg, grpc_endpoint* tcp, +static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); if (state->shutdown) { gpr_mu_unlock(&state->mu); - grpc_endpoint_shutdown(tcp, GRPC_ERROR_NONE); - grpc_endpoint_destroy(tcp); + grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_NONE); + grpc_endpoint_destroy(exec_ctx, tcp); gpr_free(acceptor); return; } @@ -184,56 +188,59 @@ static void on_accept(void* arg, grpc_endpoint* tcp, connection_state->accepting_pollset = accepting_pollset; connection_state->acceptor = acceptor; connection_state->handshake_mgr = handshake_mgr; - grpc_handshakers_add(HANDSHAKER_SERVER, state->args, + grpc_handshakers_add(exec_ctx, HANDSHAKER_SERVER, state->args, connection_state->handshake_mgr); const grpc_arg* timeout_arg = grpc_channel_args_find(state->args, GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS); connection_state->deadline = - grpc_core::ExecCtx::Get()->Now() + + grpc_exec_ctx_now(exec_ctx) + grpc_channel_arg_get_integer(timeout_arg, {120 * GPR_MS_PER_SEC, 1, INT_MAX}); - grpc_handshake_manager_do_handshake( - connection_state->handshake_mgr, nullptr /* interested_parties */, tcp, - state->args, connection_state->deadline, acceptor, on_handshake_done, - connection_state); + grpc_handshake_manager_do_handshake(exec_ctx, connection_state->handshake_mgr, + nullptr /* interested_parties */, tcp, + state->args, connection_state->deadline, + acceptor, on_handshake_done, + connection_state); } /* Server callback: start listening on our ports */ -static void server_start_listener(grpc_server* server, void* arg, - grpc_pollset** pollsets, +static void server_start_listener(grpc_exec_ctx* exec_ctx, grpc_server* server, + void* arg, grpc_pollset** pollsets, size_t pollset_count) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); state->shutdown = false; gpr_mu_unlock(&state->mu); - grpc_tcp_server_start(state->tcp_server, pollsets, pollset_count, on_accept, - state); + grpc_tcp_server_start(exec_ctx, state->tcp_server, pollsets, pollset_count, + on_accept, state); } -static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { +static void tcp_server_shutdown_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { server_state* state = (server_state*)arg; /* ensure all threads have unlocked */ gpr_mu_lock(&state->mu); grpc_closure* destroy_done = state->server_destroy_listener_done; GPR_ASSERT(state->shutdown); grpc_handshake_manager_pending_list_shutdown_all( - state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); + exec_ctx, state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); gpr_mu_unlock(&state->mu); // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); if (destroy_done != nullptr) { - destroy_done->cb(destroy_done->cb_arg, GRPC_ERROR_REF(error)); - grpc_core::ExecCtx::Get()->Flush(); + destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error)); + grpc_exec_ctx_flush(exec_ctx); } - grpc_channel_args_destroy(state->args); + grpc_channel_args_destroy(exec_ctx, state->args); gpr_mu_destroy(&state->mu); gpr_free(state); } /* Server callback: destroy the tcp listener (so we don't generate further callbacks) */ -static void server_destroy_listener(grpc_server* server, void* arg, +static void server_destroy_listener(grpc_exec_ctx* exec_ctx, + grpc_server* server, void* arg, grpc_closure* destroy_done) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); @@ -241,11 +248,12 @@ static void server_destroy_listener(grpc_server* server, void* arg, state->server_destroy_listener_done = destroy_done; grpc_tcp_server* tcp_server = state->tcp_server; gpr_mu_unlock(&state->mu); - grpc_tcp_server_shutdown_listeners(tcp_server); - grpc_tcp_server_unref(tcp_server); + grpc_tcp_server_shutdown_listeners(exec_ctx, tcp_server); + grpc_tcp_server_unref(exec_ctx, tcp_server); } -grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, +grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, + grpc_server* server, const char* addr, grpc_channel_args* args, int* port_num) { grpc_resolved_addresses* resolved = nullptr; @@ -269,8 +277,8 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, GRPC_CLOSURE_INIT(&state->tcp_server_shutdown_complete, tcp_server_shutdown_complete, state, grpc_schedule_on_exec_ctx); - err = grpc_tcp_server_create(&state->tcp_server_shutdown_complete, args, - &tcp_server); + err = grpc_tcp_server_create(exec_ctx, &state->tcp_server_shutdown_complete, + args, &tcp_server); if (err != GRPC_ERROR_NONE) { goto error; } @@ -319,7 +327,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, grpc_resolved_addresses_destroy(resolved); /* Register with the server only upon success */ - grpc_server_add_listener(server, state, server_start_listener, + grpc_server_add_listener(exec_ctx, server, state, server_start_listener, server_destroy_listener); goto done; @@ -330,9 +338,9 @@ error: grpc_resolved_addresses_destroy(resolved); } if (tcp_server) { - grpc_tcp_server_unref(tcp_server); + grpc_tcp_server_unref(exec_ctx, tcp_server); } else { - grpc_channel_args_destroy(args); + grpc_channel_args_destroy(exec_ctx, args); gpr_free(state); } *port_num = 0; diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h index 7de859da42..68304fd4f7 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.h +++ b/src/core/ext/transport/chttp2/server/chttp2_server.h @@ -25,7 +25,8 @@ /// Adds a port to \a server. Sets \a port_num to the port number. /// Takes ownership of \a args. -grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, +grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, + grpc_server* server, const char* addr, grpc_channel_args* args, int* port_num); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_SERVER_CHTTP2_SERVER_H */ diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 52c42d056c..8984896538 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -26,12 +26,12 @@ #include "src/core/lib/surface/server.h" int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; int port_num = 0; GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2, (server, addr)); grpc_error* err = grpc_chttp2_server_add_port( - server, addr, + &exec_ctx, server, addr, grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num); if (err != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(err); @@ -39,6 +39,6 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { GRPC_ERROR_UNREF(err); } - + grpc_exec_ctx_finish(&exec_ctx); return port_num; } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index dafd4af6ce..3fe05ce4ef 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -38,29 +38,32 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, void* reserved, int fd) { GPR_ASSERT(reserved == nullptr); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; char* name; gpr_asprintf(&name, "fd:%d", fd); - grpc_endpoint* server_endpoint = grpc_tcp_create( - grpc_fd_create(fd, name), grpc_server_get_channel_args(server), name); + grpc_endpoint* server_endpoint = + grpc_tcp_create(&exec_ctx, grpc_fd_create(fd, name), + grpc_server_get_channel_args(server), name); gpr_free(name); const grpc_channel_args* server_args = grpc_server_get_channel_args(server); grpc_transport* transport = grpc_create_chttp2_transport( - server_args, server_endpoint, false /* is_client */); + &exec_ctx, server_args, server_endpoint, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server, &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(server_endpoint, pollsets[i]); + grpc_endpoint_add_to_pollset(&exec_ctx, server_endpoint, pollsets[i]); } - grpc_server_setup_transport(server, transport, nullptr, server_args); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, + server_args); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } #else // !GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index 723af97ff0..ac3ea40f47 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -36,7 +36,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_server_credentials* creds) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_error* err = GRPC_ERROR_NONE; grpc_server_security_connector* sc = nullptr; int port_num = 0; @@ -52,7 +52,8 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, "No credentials specified for secure server port (creds==NULL)"); goto done; } - status = grpc_server_credentials_create_security_connector(creds, &sc); + status = + grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); if (status != GRPC_SECURITY_OK) { char* msg; gpr_asprintf(&msg, @@ -71,12 +72,12 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_channel_args_copy_and_add(grpc_server_get_channel_args(server), args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Add server port. - err = grpc_chttp2_server_add_port(server, addr, args, &port_num); + err = grpc_chttp2_server_add_port(&exec_ctx, server, addr, args, &port_num); done: if (sc != nullptr) { - GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "server"); + GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "server"); } - + grpc_exec_ctx_finish(&exec_ctx); if (err != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 984cd4ca78..3ccae7afc3 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -130,7 +130,8 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx) { return true; } -grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { +grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, + grpc_slice input) { size_t input_length = GRPC_SLICE_LENGTH(input); size_t output_length = input_length / 4 * 3; struct grpc_base64_decode_context ctx; @@ -166,7 +167,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(exec_ctx, output); return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); @@ -174,7 +175,8 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { return output; } -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, + grpc_slice input, size_t output_length) { size_t input_length = GRPC_SLICE_LENGTH(input); grpc_slice output = GRPC_SLICE_MALLOC(output_length); @@ -187,7 +189,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, "grpc_chttp2_base64_decode_with_length has a length of %d, which " "has a tail of 1 byte.\n", (int)input_length); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(exec_ctx, output); return grpc_empty_slice(); } @@ -197,7 +199,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, "than the max possible output length %d.\n", (int)output_length, (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(exec_ctx, output); return grpc_empty_slice(); } @@ -211,7 +213,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(exec_ctx, output); return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.h b/src/core/ext/transport/chttp2/transport/bin_decoder.h index 9cb75ccd81..a78c305766 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.h @@ -40,12 +40,13 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx); /* base64 decode a slice with pad chars. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode(grpc_slice input); +grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, grpc_slice input); /* base64 decode a slice without pad chars, data length is needed. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, + grpc_slice input, size_t output_length); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */ diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.h b/src/core/ext/transport/chttp2/transport/bin_encoder.h index 93ad0dfdea..a8f36a345a 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.h @@ -32,7 +32,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input); /* equivalent to: grpc_slice x = grpc_chttp2_base64_encode(input); grpc_slice y = grpc_chttp2_huffman_compress(x); - grpc_slice_unref_internal( x); + grpc_slice_unref_internal(exec_ctx, x); return y; */ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index f537fb09c2..63ac65ac78 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -95,77 +95,105 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); /* forward declarations of various callbacks that we'll build closures around */ -static void write_action_begin_locked(void* t, grpc_error* error); -static void write_action(void* t, grpc_error* error); -static void write_action_end_locked(void* t, grpc_error* error); +static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); +static void write_action(grpc_exec_ctx* exec_ctx, void* t, grpc_error* error); +static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); -static void read_action_locked(void* t, grpc_error* error); +static void read_action_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); -static void complete_fetch_locked(void* gs, grpc_error* error); +static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, + grpc_error* error); /** Set a transport level setting, and push it to our peer */ -static void queue_setting_update(grpc_chttp2_transport* t, +static void queue_setting_update(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value); -static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_error* error); +static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error); /** Start new streams that have been created if we can */ -static void maybe_start_some_streams(grpc_chttp2_transport* t); +static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); -static void connectivity_state_set(grpc_chttp2_transport* t, +static void connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_connectivity_state state, grpc_error* error, const char* reason); -static void incoming_byte_stream_destroy_locked(void* byte_stream, +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, grpc_error* error_ignored); static void incoming_byte_stream_publish_error( - grpc_chttp2_incoming_byte_stream* bs, grpc_error* error); -static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs); - -static void benign_reclaimer_locked(void* t, grpc_error* error); -static void destructive_reclaimer_locked(void* t, grpc_error* error); - -static void post_benign_reclaimer(grpc_chttp2_transport* t); -static void post_destructive_reclaimer(grpc_chttp2_transport* t); - -static void close_transport_locked(grpc_chttp2_transport* t, grpc_error* error); -static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error); - -static void schedule_bdp_ping_locked(grpc_chttp2_transport* t); -static void start_bdp_ping_locked(void* tp, grpc_error* error); -static void finish_bdp_ping_locked(void* tp, grpc_error* error); -static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error); - -static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error); -static void send_ping_locked(grpc_chttp2_transport* t, + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error); +static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, + grpc_chttp2_incoming_byte_stream* bs); + +static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); +static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); + +static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); + +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_error* error); +static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); + +static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); +static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); +static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, + void* tp, grpc_error* error); + +static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); +static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_closure* on_initiate, grpc_closure* on_complete); -static void retry_initiate_ping_locked(void* tp, grpc_error* error); +static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); /** keepalive-relevant functions */ -static void init_keepalive_ping_locked(void* arg, grpc_error* error); -static void start_keepalive_ping_locked(void* arg, grpc_error* error); -static void finish_keepalive_ping_locked(void* arg, grpc_error* error); -static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error); - -static void reset_byte_stream(void* arg, grpc_error* error); +static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); + +static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); /******************************************************************************* * CONSTRUCTION/DESTRUCTION/REFCOUNTING */ -static void destruct_transport(grpc_chttp2_transport* t) { +static void destruct_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { size_t i; - grpc_endpoint_destroy(t->ep); + grpc_endpoint_destroy(exec_ctx, t->ep); - grpc_slice_buffer_destroy_internal(&t->qbuf); + grpc_slice_buffer_destroy_internal(exec_ctx, &t->qbuf); - grpc_slice_buffer_destroy_internal(&t->outbuf); - grpc_chttp2_hpack_compressor_destroy(&t->hpack_compressor); + grpc_slice_buffer_destroy_internal(exec_ctx, &t->outbuf); + grpc_chttp2_hpack_compressor_destroy(exec_ctx, &t->hpack_compressor); - grpc_slice_buffer_destroy_internal(&t->read_buffer); - grpc_chttp2_hpack_parser_destroy(&t->hpack_parser); + grpc_slice_buffer_destroy_internal(exec_ctx, &t->read_buffer); + grpc_chttp2_hpack_parser_destroy(exec_ctx, &t->hpack_parser); grpc_chttp2_goaway_parser_destroy(&t->goaway_parser); for (i = 0; i < STREAM_LIST_COUNT; i++) { @@ -178,11 +206,12 @@ static void destruct_transport(grpc_chttp2_transport* t) { GPR_ASSERT(grpc_chttp2_stream_map_size(&t->stream_map) == 0); grpc_chttp2_stream_map_destroy(&t->stream_map); - grpc_connectivity_state_destroy(&t->channel_callback.state_tracker); + grpc_connectivity_state_destroy(exec_ctx, &t->channel_callback.state_tracker); - GRPC_COMBINER_UNREF(t->combiner, "chttp2_transport"); + GRPC_COMBINER_UNREF(exec_ctx, t->combiner, "chttp2_transport"); - cancel_pings(t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); + cancel_pings(exec_ctx, t, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); while (t->write_cb_pool) { grpc_chttp2_write_cb* next = t->write_cb_pool->next; @@ -199,7 +228,8 @@ static void destruct_transport(grpc_chttp2_transport* t) { } #ifndef NDEBUG -void grpc_chttp2_unref_transport(grpc_chttp2_transport* t, const char* reason, +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, const char* reason, const char* file, int line) { if (grpc_trace_chttp2_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); @@ -207,7 +237,7 @@ void grpc_chttp2_unref_transport(grpc_chttp2_transport* t, const char* reason, t, val, val - 1, reason, file, line); } if (!gpr_unref(&t->refs)) return; - destruct_transport(t); + destruct_transport(exec_ctx, t); } void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, @@ -220,9 +250,10 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, gpr_ref(&t->refs); } #else -void grpc_chttp2_unref_transport(grpc_chttp2_transport* t) { +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!gpr_unref(&t->refs)) return; - destruct_transport(t); + destruct_transport(exec_ctx, t); } void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); } @@ -230,7 +261,7 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); } static const grpc_transport_vtable* get_vtable(void); -static void init_transport(grpc_chttp2_transport* t, +static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { size_t i; @@ -289,7 +320,7 @@ static void init_transport(grpc_chttp2_transport* t, t->goaway_error = GRPC_ERROR_NONE; grpc_chttp2_goaway_parser_init(&t->goaway_parser); - grpc_chttp2_hpack_parser_init(&t->hpack_parser); + grpc_chttp2_hpack_parser_init(exec_ctx, &t->hpack_parser); grpc_slice_buffer_init(&t->read_buffer); @@ -320,13 +351,14 @@ static void init_transport(grpc_chttp2_transport* t, /* configure http2 the way we like it */ if (is_client) { - queue_setting_update(t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0); - queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0); + queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0); + queue_setting_update(exec_ctx, t, + GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0); } - queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, + queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, DEFAULT_MAX_HEADER_LIST_SIZE); - queue_setting_update(t, GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, - 1); + queue_setting_update(exec_ctx, t, + GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1); t->ping_policy.max_pings_without_data = g_default_max_pings_without_data; t->ping_policy.min_sent_ping_interval_without_data = @@ -501,7 +533,7 @@ static void init_transport(grpc_chttp2_transport* t, int value = grpc_channel_arg_get_integer( &channel_args->args[i], settings_map[j].integer_options); if (value >= 0) { - queue_setting_update(t, settings_map[j].setting_id, + queue_setting_update(exec_ctx, t, settings_map[j].setting_id, (uint32_t)value); } } @@ -512,7 +544,7 @@ static void init_transport(grpc_chttp2_transport* t, } } - t->flow_control.Init(t, enable_bdp); + t->flow_control.Init(exec_ctx, t, enable_bdp); /* No pings allowed before receiving a header or data frame. */ t->ping_state.pings_before_data_required = 0; @@ -526,8 +558,8 @@ static void init_transport(grpc_chttp2_transport* t, if (t->keepalive_time != GRPC_MILLIS_INF_FUTURE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, + grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->init_keepalive_ping_locked); } else { /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no @@ -537,37 +569,42 @@ static void init_transport(grpc_chttp2_transport* t, if (enable_bdp) { GRPC_CHTTP2_REF_TRANSPORT(t, "bdp_ping"); - schedule_bdp_ping_locked(t); + schedule_bdp_ping_locked(exec_ctx, t); - grpc_chttp2_act_on_flowctl_action(t->flow_control->PeriodicUpdate(), t, - nullptr); + grpc_chttp2_act_on_flowctl_action( + exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, nullptr); } - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE); - post_benign_reclaimer(t); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE); + post_benign_reclaimer(exec_ctx, t); } -static void destroy_transport_locked(void* tp, grpc_error* error) { +static void destroy_transport_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->destroying = 1; close_transport_locked( - t, grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), - GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy"); + exec_ctx, t, + grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), + GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destroy"); } -static void destroy_transport(grpc_transport* gt) { +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(destroy_transport_locked, t, + GRPC_CLOSURE_SCHED(exec_ctx, + GRPC_CLOSURE_CREATE(destroy_transport_locked, t, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); } -static void close_transport_locked(grpc_chttp2_transport* t, +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_error* error) { - end_all_the_calls(t, GRPC_ERROR_REF(error)); - cancel_pings(t, GRPC_ERROR_REF(error)); + end_all_the_calls(exec_ctx, t, GRPC_ERROR_REF(error)); + cancel_pings(exec_ctx, t, GRPC_ERROR_REF(error)); if (t->closed_with_error == GRPC_ERROR_NONE) { if (!grpc_error_has_clear_grpc_status(error)) { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, @@ -585,21 +622,21 @@ static void close_transport_locked(grpc_chttp2_transport* t, } GPR_ASSERT(error != GRPC_ERROR_NONE); t->closed_with_error = GRPC_ERROR_REF(error); - connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), - "close_transport"); + connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_REF(error), "close_transport"); if (t->ping_state.is_delayed_ping_timer_set) { - grpc_timer_cancel(&t->ping_state.delayed_ping_timer); + grpc_timer_cancel(exec_ctx, &t->ping_state.delayed_ping_timer); } if (t->have_next_bdp_ping_timer) { - grpc_timer_cancel(&t->next_bdp_ping_timer); + grpc_timer_cancel(exec_ctx, &t->next_bdp_ping_timer); } switch (t->keepalive_state) { case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: - grpc_timer_cancel(&t->keepalive_ping_timer); + grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); break; case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING: - grpc_timer_cancel(&t->keepalive_ping_timer); - grpc_timer_cancel(&t->keepalive_watchdog_timer); + grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); + grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer); break; case GRPC_CHTTP2_KEEPALIVE_STATE_DYING: case GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED: @@ -610,13 +647,14 @@ static void close_transport_locked(grpc_chttp2_transport* t, /* flush writable stream list to avoid dangling references */ grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writable_stream(t, &s)) { - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:close"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:close"); } GPR_ASSERT(t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE); - grpc_endpoint_shutdown(t->ep, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error)); } if (t->notify_on_receive_settings != nullptr) { - GRPC_CLOSURE_SCHED(t->notify_on_receive_settings, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, t->notify_on_receive_settings, + GRPC_ERROR_CANCELLED); t->notify_on_receive_settings = nullptr; } GRPC_ERROR_UNREF(error); @@ -626,21 +664,22 @@ static void close_transport_locked(grpc_chttp2_transport* t, void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_chttp2_stream_unref(grpc_chttp2_stream* s, const char* reason) { - grpc_stream_unref(s->refcount, reason); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, + const char* reason) { + grpc_stream_unref(exec_ctx, s->refcount, reason); } #else void grpc_chttp2_stream_ref(grpc_chttp2_stream* s) { grpc_stream_ref(s->refcount); } -void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) { - grpc_stream_unref(s->refcount); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s) { + grpc_stream_unref(exec_ctx, s->refcount); } #endif -static int init_stream(grpc_transport* gt, grpc_stream* gs, - grpc_stream_refcount* refcount, const void* server_data, - gpr_arena* arena) { +static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { GPR_TIMER_BEGIN("init_stream", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; @@ -674,7 +713,7 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, s->id = (uint32_t)(uintptr_t)server_data; *t->accepting_stream = s; grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); - post_destructive_reclaimer(t); + post_destructive_reclaimer(exec_ctx, t); } s->flow_control.Init(t->flow_control.get(), s); @@ -683,7 +722,8 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, return 0; } -static void destroy_stream_locked(void* sp, grpc_error* error) { +static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, + grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; grpc_chttp2_transport* t = s->t; @@ -694,10 +734,11 @@ static void destroy_stream_locked(void* sp, grpc_error* error) { GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == nullptr); } - grpc_slice_buffer_destroy_internal(&s->unprocessed_incoming_frames_buffer); - grpc_slice_buffer_destroy_internal(&s->frame_storage); - grpc_slice_buffer_destroy_internal(&s->compressed_data_buffer); - grpc_slice_buffer_destroy_internal(&s->decompressed_data_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, + &s->unprocessed_incoming_frames_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->frame_storage); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->compressed_data_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->decompressed_data_buffer); grpc_chttp2_list_remove_stalled_by_transport(t, s); grpc_chttp2_list_remove_stalled_by_stream(t, s); @@ -716,24 +757,27 @@ static void destroy_stream_locked(void* sp, grpc_error* error) { GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); GPR_ASSERT(s->recv_message_ready == nullptr); GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); - grpc_chttp2_data_parser_destroy(&s->data_parser); - grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[0]); - grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[1]); - grpc_slice_buffer_destroy_internal(&s->flow_controlled_buffer); + grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser); + grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx, + &s->metadata_buffer[0]); + grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx, + &s->metadata_buffer[1]); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->flow_controlled_buffer); GRPC_ERROR_UNREF(s->read_closed_error); GRPC_ERROR_UNREF(s->write_closed_error); GRPC_ERROR_UNREF(s->byte_stream_error); s->flow_control.Destroy(); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "stream"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "stream"); GPR_TIMER_END("destroy_stream", 0); - GRPC_CLOSURE_SCHED(s->destroy_stream_arg, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->destroy_stream_arg, GRPC_ERROR_NONE); } -static void destroy_stream(grpc_transport* gt, grpc_stream* gs, +static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_closure* then_schedule_closure) { GPR_TIMER_BEGIN("destroy_stream", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; @@ -750,6 +794,7 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, s->destroy_stream_arg = then_schedule_closure; GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&s->destroy_stream, destroy_stream_locked, s, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -761,7 +806,8 @@ grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, return (grpc_chttp2_stream*)grpc_chttp2_stream_map_find(&t->stream_map, id); } -grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t id) { if (t->channel_callback.accept_stream == nullptr) { return nullptr; @@ -769,7 +815,8 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* accepting; GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; - t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, + t->channel_callback.accept_stream(exec_ctx, + t->channel_callback.accept_stream_user_data, &t->base, (void*)(uintptr_t)id); t->accepting_stream = nullptr; return accepting; @@ -791,7 +838,7 @@ static const char* write_state_name(grpc_chttp2_write_state st) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -static void set_write_state(grpc_chttp2_transport* t, +static void set_write_state(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_write_state st, const char* reason) { GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_DEBUG, "W:%p %s state %s -> %s [%s]", t, t->is_client ? "CLIENT" : "SERVER", @@ -799,100 +846,108 @@ static void set_write_state(grpc_chttp2_transport* t, write_state_name(st), reason)); t->write_state = st; if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { - GRPC_CLOSURE_LIST_SCHED(&t->run_after_write); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &t->run_after_write); if (t->close_transport_on_writes_finished != nullptr) { grpc_error* err = t->close_transport_on_writes_finished; t->close_transport_on_writes_finished = nullptr; - close_transport_locked(t, err); + close_transport_locked(exec_ctx, t, err); } } } static void inc_initiate_write_reason( - grpc_chttp2_initiate_write_reason reason) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_initiate_write_reason reason) { switch (reason) { case GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED( + exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(exec_ctx); break; case GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(exec_ctx); break; } } -void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, +void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason) { GPR_TIMER_BEGIN("grpc_chttp2_initiate_write", 0); switch (t->write_state) { case GRPC_CHTTP2_WRITE_STATE_IDLE: - inc_initiate_write_reason(reason); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, + inc_initiate_write_reason(exec_ctx, reason); + set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, grpc_chttp2_initiate_write_reason_string(reason)); t->is_first_write_in_batch = true; GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&t->write_action_begin_locked, write_action_begin_locked, t, grpc_combiner_finally_scheduler(t->combiner)), GRPC_ERROR_NONE); break; case GRPC_CHTTP2_WRITE_STATE_WRITING: - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE, + set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE, grpc_chttp2_initiate_write_reason_string(reason)); break; case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: @@ -901,7 +956,8 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, GPR_TIMER_END("grpc_chttp2_initiate_write", 0); } -void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (t->closed_with_error == GRPC_ERROR_NONE && grpc_chttp2_list_add_writable_stream(t, s)) { @@ -951,7 +1007,8 @@ static const char* begin_writing_desc(bool partial, bool inlined) { GPR_UNREACHABLE_CODE(return "bad state tuple"); } -static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { +static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* gt, + grpc_error* error_ignored) { GPR_TIMER_BEGIN("write_action_begin_locked", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); @@ -959,59 +1016,62 @@ static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { if (t->closed_with_error != GRPC_ERROR_NONE) { r.writing = false; } else { - r = grpc_chttp2_begin_write(t); + r = grpc_chttp2_begin_write(exec_ctx, t); } if (r.writing) { if (r.partial) { - GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(); + GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(exec_ctx); } if (!t->is_first_write_in_batch) { - GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(); + GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(exec_ctx); } grpc_closure_scheduler* scheduler = write_scheduler(t, r.early_results_scheduled, r.partial); if (scheduler != grpc_schedule_on_exec_ctx) { - GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(); + GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(exec_ctx); } set_write_state( - t, + exec_ctx, t, r.partial ? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE : GRPC_CHTTP2_WRITE_STATE_WRITING, begin_writing_desc(r.partial, scheduler == grpc_schedule_on_exec_ctx)); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&t->write_action, write_action, t, scheduler), GRPC_ERROR_NONE); } else { - GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "begin writing nothing"); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); + GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(exec_ctx); + set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE, + "begin writing nothing"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing"); } GPR_TIMER_END("write_action_begin_locked", 0); } -static void write_action(void* gt, grpc_error* error) { +static void write_action(grpc_exec_ctx* exec_ctx, void* gt, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GPR_TIMER_BEGIN("write_action", 0); grpc_endpoint_write( - t->ep, &t->outbuf, + exec_ctx, t->ep, &t->outbuf, GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, grpc_combiner_scheduler(t->combiner))); GPR_TIMER_END("write_action", 0); } -static void write_action_end_locked(void* tp, grpc_error* error) { +static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { GPR_TIMER_BEGIN("terminate_writing_with_lock", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (error != GRPC_ERROR_NONE) { - close_transport_locked(t, GRPC_ERROR_REF(error)); + close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error)); } if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT; if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { close_transport_locked( - t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); + exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); } } @@ -1020,14 +1080,17 @@ static void write_action_end_locked(void* tp, grpc_error* error) { GPR_UNREACHABLE_CODE(break); case GRPC_CHTTP2_WRITE_STATE_WRITING: GPR_TIMER_MARK("state=writing", 0); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing"); + set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE, + "finish writing"); break; case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: GPR_TIMER_MARK("state=writing_stale_no_poller", 0); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, "continue writing"); + set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, + "continue writing"); t->is_first_write_in_batch = false; GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); GRPC_CLOSURE_RUN( + exec_ctx, GRPC_CLOSURE_INIT(&t->write_action_begin_locked, write_action_begin_locked, t, grpc_combiner_finally_scheduler(t->combiner)), @@ -1035,15 +1098,16 @@ static void write_action_end_locked(void* tp, grpc_error* error) { break; } - grpc_chttp2_end_write(t, GRPC_ERROR_REF(error)); + grpc_chttp2_end_write(exec_ctx, t, GRPC_ERROR_REF(error)); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing"); GPR_TIMER_END("terminate_writing_with_lock", 0); } // Dirties an HTTP2 setting to be sent out next time a writing path occurs. // If the change needs to occur immediately, manually initiate a write. -static void queue_setting_update(grpc_chttp2_transport* t, +static void queue_setting_update(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value) { const grpc_chttp2_setting_parameters* sp = &grpc_chttp2_settings_parameters[id]; @@ -1058,7 +1122,8 @@ static void queue_setting_update(grpc_chttp2_transport* t, } } -void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, +void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text) { // GRPC_CHTTP2_IF_TRACING( @@ -1093,11 +1158,12 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, /* lie: use transient failure from the transport to indicate goaway has been * received */ - connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE, + connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(t->goaway_error), "got_goaway"); } -static void maybe_start_some_streams(grpc_chttp2_transport* t) { +static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_chttp2_stream* s; /* start streams where we have free grpc_chttp2_stream ids and free * concurrency */ @@ -1117,21 +1183,22 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) { if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) { connectivity_state_set( - t, GRPC_CHANNEL_TRANSIENT_FAILURE, + exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"), "no_more_stream_ids"); } grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); - post_destructive_reclaimer(t); - grpc_chttp2_mark_stream_writable(t, s); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM); + post_destructive_reclaimer(exec_ctx, t); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM); } /* cancel out streams that will never be started */ while (t->next_stream_id >= MAX_CLIENT_STREAM_ID && grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) { grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); @@ -1153,13 +1220,15 @@ static grpc_closure* add_closure_barrier(grpc_closure* closure) { return closure; } -static void null_then_run_closure(grpc_closure** closure, grpc_error* error) { +static void null_then_run_closure(grpc_exec_ctx* exec_ctx, + grpc_closure** closure, grpc_error* error) { grpc_closure* c = *closure; *closure = nullptr; - GRPC_CLOSURE_RUN(c, error); + GRPC_CLOSURE_RUN(exec_ctx, c, error); } -void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, +void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_closure** pclosure, grpc_error* error, const char* desc) { @@ -1199,7 +1268,7 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, } if ((t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE) || !(closure->next_data.scratch & CLOSURE_BARRIER_MAY_COVER_WRITE)) { - GRPC_CLOSURE_RUN(closure, closure->error_data.error); + GRPC_CLOSURE_RUN(exec_ctx, closure, closure->error_data.error); } else { grpc_closure_list_append(&t->run_after_write, closure, closure->error_data.error); @@ -1215,24 +1284,28 @@ static bool contains_non_ok_status(grpc_metadata_batch* batch) { return false; } -static void maybe_become_writable_due_to_send_msg(grpc_chttp2_transport* t, +static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (s->id != 0 && (!s->write_buffering || s->flow_controlled_buffer.length > t->write_buffer_size)) { - grpc_chttp2_mark_stream_writable(t, s); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); } } -static void add_fetched_slice_locked(grpc_chttp2_transport* t, +static void add_fetched_slice_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { s->fetched_send_message_length += (uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); - maybe_become_writable_due_to_send_msg(t, s); + maybe_become_writable_due_to_send_msg(exec_ctx, t, s); } -static void continue_fetching_send_locked(grpc_chttp2_transport* t, +static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { for (;;) { if (s->fetching_send_message == nullptr) { @@ -1241,11 +1314,11 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, return; /* early out */ } if (s->fetched_send_message_length == s->fetching_send_message->length) { - grpc_byte_stream_destroy(s->fetching_send_message); + grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); int64_t notify_offset = s->next_message_end_offset; if (notify_offset <= s->flow_controlled_bytes_written) { grpc_chttp2_complete_closure_step( - t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE, + exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE, "fetching_send_message_finished"); } else { grpc_chttp2_write_cb* cb = t->write_cb_pool; @@ -1266,37 +1339,39 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } s->fetching_send_message = nullptr; return; /* early out */ - } else if (grpc_byte_stream_next(s->fetching_send_message, UINT32_MAX, - &s->complete_fetch_locked)) { - grpc_error* error = - grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); + } else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message, + UINT32_MAX, &s->complete_fetch_locked)) { + grpc_error* error = grpc_byte_stream_pull( + exec_ctx, s->fetching_send_message, &s->fetching_slice); if (error != GRPC_ERROR_NONE) { - grpc_byte_stream_destroy(s->fetching_send_message); - grpc_chttp2_cancel_stream(t, s, error); + grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); + grpc_chttp2_cancel_stream(exec_ctx, t, s, error); } else { - add_fetched_slice_locked(t, s); + add_fetched_slice_locked(exec_ctx, t, s); } } } } -static void complete_fetch_locked(void* gs, grpc_error* error) { +static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, + grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; grpc_chttp2_transport* t = s->t; if (error == GRPC_ERROR_NONE) { - error = grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); + error = grpc_byte_stream_pull(exec_ctx, s->fetching_send_message, + &s->fetching_slice); if (error == GRPC_ERROR_NONE) { - add_fetched_slice_locked(t, s); - continue_fetching_send_locked(t, s); + add_fetched_slice_locked(exec_ctx, t, s); + continue_fetching_send_locked(exec_ctx, t, s); } } if (error != GRPC_ERROR_NONE) { - grpc_byte_stream_destroy(s->fetching_send_message); - grpc_chttp2_cancel_stream(t, s, error); + grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); + grpc_chttp2_cancel_stream(exec_ctx, t, s, error); } } -static void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, bool is_client, bool is_initial) { @@ -1311,7 +1386,7 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, } } -static void perform_stream_op_locked(void* stream_op, +static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, grpc_error* error_ignored) { GPR_TIMER_BEGIN("perform_stream_op_locked", 0); @@ -1321,7 +1396,7 @@ static void perform_stream_op_locked(void* stream_op, grpc_transport_stream_op_batch_payload* op_payload = op->payload; grpc_chttp2_transport* t = s->t; - GRPC_STATS_INC_HTTP2_OP_BATCHES(); + GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx); if (grpc_http_trace.enabled()) { char* str = grpc_transport_stream_op_batch_string(op); @@ -1356,12 +1431,13 @@ static void perform_stream_op_locked(void* stream_op, } if (op->cancel_stream) { - GRPC_STATS_INC_HTTP2_OP_CANCEL(); - grpc_chttp2_cancel_stream(t, s, op_payload->cancel_stream.cancel_error); + GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx); + grpc_chttp2_cancel_stream(exec_ctx, t, s, + op_payload->cancel_stream.cancel_error); } if (op->send_initial_metadata) { - GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(); + GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx); GPR_ASSERT(s->send_initial_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; @@ -1389,7 +1465,7 @@ static void perform_stream_op_locked(void* stream_op, } if (metadata_size > metadata_peer_limit) { grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int( grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -1408,10 +1484,10 @@ static void perform_stream_op_locked(void* stream_op, if (t->closed_with_error == GRPC_ERROR_NONE) { GPR_ASSERT(s->id == 0); grpc_chttp2_list_add_waiting_for_concurrency(t, s); - maybe_start_some_streams(t); + maybe_start_some_streams(exec_ctx, t); } else { grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int( GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Transport closed", &t->closed_with_error, 1), @@ -1419,18 +1495,18 @@ static void perform_stream_op_locked(void* stream_op, } } else { GPR_ASSERT(s->id != 0); - grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); if (!(op->send_message && (op->payload->send_message.send_message->flags & GRPC_WRITE_BUFFER_HINT))) { grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); + exec_ctx, t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); } } } else { s->send_initial_metadata = nullptr; grpc_chttp2_complete_closure_step( - t, s, &s->send_initial_metadata_finished, + exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Attempt to send initial metadata after stream was closed", &s->write_closed_error, 1), @@ -1444,9 +1520,9 @@ static void perform_stream_op_locked(void* stream_op, } if (op->send_message) { - GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(); + GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx); GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE( - op->payload->send_message.send_message->length); + exec_ctx, op->payload->send_message.send_message->length); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->fetching_send_message_finished = add_closure_barrier(op->on_complete); if (s->write_closed) { @@ -1456,7 +1532,7 @@ static void perform_stream_op_locked(void* stream_op, // recv_message failure, breaking out of its loop, and then // starting recv_trailing_metadata. grpc_chttp2_complete_closure_step( - t, s, &s->fetching_send_message_finished, + exec_ctx, t, s, &s->fetching_send_message_finished, t->is_client && s->received_trailing_metadata ? GRPC_ERROR_NONE : GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -1485,13 +1561,13 @@ static void perform_stream_op_locked(void* stream_op, } else { s->write_buffering = false; } - continue_fetching_send_locked(t, s); - maybe_become_writable_due_to_send_msg(t, s); + continue_fetching_send_locked(exec_ctx, t, s); + maybe_become_writable_due_to_send_msg(exec_ctx, t, s); } } if (op->send_trailing_metadata) { - GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(); + GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx); GPR_ASSERT(s->send_trailing_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); @@ -1505,7 +1581,7 @@ static void perform_stream_op_locked(void* stream_op, [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE]; if (metadata_size > metadata_peer_limit) { grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int( grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -1522,7 +1598,7 @@ static void perform_stream_op_locked(void* stream_op, if (s->write_closed) { s->send_trailing_metadata = nullptr; grpc_chttp2_complete_closure_step( - t, s, &s->send_trailing_metadata_finished, + exec_ctx, t, s, &s->send_trailing_metadata_finished, grpc_metadata_batch_is_empty( op->payload->send_trailing_metadata.send_trailing_metadata) ? GRPC_ERROR_NONE @@ -1533,15 +1609,15 @@ static void perform_stream_op_locked(void* stream_op, } else if (s->id != 0) { /* TODO(ctiller): check if there's flow control for any outstanding bytes before going writable */ - grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); + exec_ctx, t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); } } } if (op->recv_initial_metadata) { - GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(); + GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx); GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); s->recv_initial_metadata_ready = op_payload->recv_initial_metadata.recv_initial_metadata_ready; @@ -1553,11 +1629,11 @@ static void perform_stream_op_locked(void* stream_op, gpr_atm_rel_store(op_payload->recv_initial_metadata.peer_string, (gpr_atm)gpr_strdup(t->peer_string)); } - grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); } if (op->recv_message) { - GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(); + GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx); size_t already_received; GPR_ASSERT(s->recv_message_ready == nullptr); GPR_ASSERT(!s->pending_byte_stream); @@ -1568,30 +1644,32 @@ static void perform_stream_op_locked(void* stream_op, already_received = s->frame_storage.length; s->flow_control->IncomingByteStreamUpdate(GRPC_HEADER_SIZE_IN_BYTES, already_received); - grpc_chttp2_act_on_flowctl_action(s->flow_control->MakeAction(), t, s); + grpc_chttp2_act_on_flowctl_action(exec_ctx, + s->flow_control->MakeAction(), t, s); } } - grpc_chttp2_maybe_complete_recv_message(t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); } if (op->recv_trailing_metadata) { - GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(); + GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx); GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); s->recv_trailing_metadata_finished = add_closure_barrier(on_complete); s->recv_trailing_metadata = op_payload->recv_trailing_metadata.recv_trailing_metadata; s->final_metadata_requested = true; - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } - grpc_chttp2_complete_closure_step(t, s, &on_complete, GRPC_ERROR_NONE, - "op->on_complete"); + grpc_chttp2_complete_closure_step(exec_ctx, t, s, &on_complete, + GRPC_ERROR_NONE, "op->on_complete"); GPR_TIMER_END("perform_stream_op_locked", 0); - GRPC_CHTTP2_STREAM_UNREF(s, "perform_stream_op"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "perform_stream_op"); } -static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, +static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_transport_stream_op_batch* op) { GPR_TIMER_BEGIN("perform_stream_op", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; @@ -1619,29 +1697,32 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, op->handler_private.extra_arg = gs; GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_stream_op_locked, op, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); GPR_TIMER_END("perform_stream_op", 0); } -static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { +static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { /* callback remaining pings: they're not allowed to call into the transpot, and maybe they hold resources that need to be freed */ grpc_chttp2_ping_queue* pq = &t->ping_queue; GPR_ASSERT(error != GRPC_ERROR_NONE); for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) { grpc_closure_list_fail_all(&pq->lists[j], GRPC_ERROR_REF(error)); - GRPC_CLOSURE_LIST_SCHED(&pq->lists[j]); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[j]); } GRPC_ERROR_UNREF(error); } -static void send_ping_locked(grpc_chttp2_transport* t, +static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_closure* on_initiate, grpc_closure* on_ack) { if (t->closed_with_error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(on_initiate, GRPC_ERROR_REF(t->closed_with_error)); - GRPC_CLOSURE_SCHED(on_ack, GRPC_ERROR_REF(t->closed_with_error)); + GRPC_CLOSURE_SCHED(exec_ctx, on_initiate, + GRPC_ERROR_REF(t->closed_with_error)); + GRPC_CLOSURE_SCHED(exec_ctx, on_ack, GRPC_ERROR_REF(t->closed_with_error)); return; } grpc_chttp2_ping_queue* pq = &t->ping_queue; @@ -1651,15 +1732,18 @@ static void send_ping_locked(grpc_chttp2_transport* t, GRPC_ERROR_NONE); } -static void retry_initiate_ping_locked(void* tp, grpc_error* error) { +static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->ping_state.is_delayed_ping_timer_set = false; if (error == GRPC_ERROR_NONE) { - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); } } -void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { +void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + uint64_t id) { grpc_chttp2_ping_queue* pq = &t->ping_queue; if (pq->inflight_id != id) { char* from = grpc_endpoint_get_peer(t->ep); @@ -1667,48 +1751,54 @@ void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { gpr_free(from); return; } - GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS); } } -static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { +static void send_goaway(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; grpc_http2_error_code http_error; grpc_slice slice; - grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, - &http_error, nullptr); + grpc_error_get_status(exec_ctx, error, GRPC_MILLIS_INF_FUTURE, nullptr, + &slice, &http_error, nullptr); grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, grpc_slice_ref_internal(slice), &t->qbuf); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); GRPC_ERROR_UNREF(error); } -void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { +void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { t->ping_recv_state.ping_strikes++; if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes && t->ping_policy.max_ping_strikes != 0) { - send_goaway(t, + send_goaway(exec_ctx, t, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); /*The transport will be closed after the write is done */ close_transport_locked( - t, grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); + exec_ctx, t, + grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); } } -static void perform_transport_op_locked(void* stream_op, +static void perform_transport_op_locked(grpc_exec_ctx* exec_ctx, + void* stream_op, grpc_error* error_ignored) { grpc_transport_op* op = (grpc_transport_op*)stream_op; grpc_chttp2_transport* t = (grpc_chttp2_transport*)op->handler_private.extra_arg; if (op->goaway_error) { - send_goaway(t, op->goaway_error); + send_goaway(exec_ctx, t, op->goaway_error); } if (op->set_accept_stream) { @@ -1718,40 +1808,43 @@ static void perform_transport_op_locked(void* stream_op, } if (op->bind_pollset) { - grpc_endpoint_add_to_pollset(t->ep, op->bind_pollset); + grpc_endpoint_add_to_pollset(exec_ctx, t->ep, op->bind_pollset); } if (op->bind_pollset_set) { - grpc_endpoint_add_to_pollset_set(t->ep, op->bind_pollset_set); + grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, op->bind_pollset_set); } if (op->send_ping) { - send_ping_locked(t, nullptr, op->send_ping); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); + send_ping_locked(exec_ctx, t, nullptr, op->send_ping); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); } if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( - &t->channel_callback.state_tracker, op->connectivity_state, + exec_ctx, &t->channel_callback.state_tracker, op->connectivity_state, op->on_connectivity_state_change); } if (op->disconnect_with_error != GRPC_ERROR_NONE) { - close_transport_locked(t, op->disconnect_with_error); + close_transport_locked(exec_ctx, t, op->disconnect_with_error); } - GRPC_CLOSURE_RUN(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "transport_op"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "transport_op"); } -static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { +static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; char* msg = grpc_transport_op_string(op); gpr_free(msg); op->handler_private.extra_arg = gt; GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op"); - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&op->handler_private.closure, + GRPC_CLOSURE_SCHED(exec_ctx, + GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_transport_op_locked, op, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -1761,33 +1854,36 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { * INPUT PROCESSING - GENERAL */ -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (s->recv_initial_metadata_ready != nullptr && s->published_metadata[0] != GRPC_METADATA_NOT_PUBLISHED) { if (s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); } } - grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[0], - s->recv_initial_metadata); - null_then_run_closure(&s->recv_initial_metadata_ready, GRPC_ERROR_NONE); + grpc_chttp2_incoming_metadata_buffer_publish( + exec_ctx, &s->metadata_buffer[0], s->recv_initial_metadata); + null_then_run_closure(exec_ctx, &s->recv_initial_metadata_ready, + GRPC_ERROR_NONE); } } -void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { grpc_error* error = GRPC_ERROR_NONE; if (s->recv_message_ready != nullptr) { *s->recv_message = nullptr; if (s->final_metadata_requested && s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); } } if (!s->pending_byte_stream) { @@ -1814,9 +1910,10 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, &s->decompressed_data_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES - s->decompressed_header_bytes, &end_of_context)) { - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + &s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Stream decompression error."); } else { @@ -1825,8 +1922,8 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, s->decompressed_header_bytes = 0; } error = grpc_deframe_unprocessed_incoming_frames( - &s->data_parser, s, &s->decompressed_data_buffer, nullptr, - s->recv_message); + exec_ctx, &s->data_parser, s, &s->decompressed_data_buffer, + nullptr, s->recv_message); if (end_of_context) { grpc_stream_compression_context_destroy( s->stream_decompression_ctx); @@ -1835,14 +1932,15 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, } } else { error = grpc_deframe_unprocessed_incoming_frames( - &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, - nullptr, s->recv_message); + exec_ctx, &s->data_parser, s, + &s->unprocessed_incoming_frames_buffer, nullptr, s->recv_message); } if (error != GRPC_ERROR_NONE) { s->seen_error = true; - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + &s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); break; } else if (*s->recv_message != nullptr) { break; @@ -1850,25 +1948,26 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, } } if (error == GRPC_ERROR_NONE && *s->recv_message != nullptr) { - null_then_run_closure(&s->recv_message_ready, GRPC_ERROR_NONE); + null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); } else if (s->published_metadata[1] != GRPC_METADATA_NOT_PUBLISHED) { *s->recv_message = nullptr; - null_then_run_closure(&s->recv_message_ready, GRPC_ERROR_NONE); + null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); } GRPC_ERROR_UNREF(error); } } -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - grpc_chttp2_maybe_complete_recv_message(t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); if (s->recv_trailing_metadata_finished != nullptr && s->read_closed && s->write_closed) { if (s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); } } bool pending_data = s->pending_byte_stream || @@ -1886,9 +1985,9 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, s->stream_decompression_ctx, &s->frame_storage, &s->unprocessed_incoming_frames_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES, &end_of_context)) { - grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - &s->unprocessed_incoming_frames_buffer); + exec_ctx, &s->unprocessed_incoming_frames_buffer); s->seen_error = true; } else { if (s->unprocessed_incoming_frames_buffer.length > 0) { @@ -1903,23 +2002,23 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, } if (s->read_closed && s->frame_storage.length == 0 && !pending_data && s->recv_trailing_metadata_finished != nullptr) { - grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[1], - s->recv_trailing_metadata); + grpc_chttp2_incoming_metadata_buffer_publish( + exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata); grpc_chttp2_complete_closure_step( - t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, + exec_ctx, t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, "recv_trailing_metadata_finished"); } } } -static void remove_stream(grpc_chttp2_transport* t, uint32_t id, - grpc_error* error) { +static void remove_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + uint32_t id, grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)grpc_chttp2_stream_map_delete(&t->stream_map, id); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); } if (s->pending_byte_stream) { if (s->on_next != nullptr) { @@ -1927,8 +2026,8 @@ static void remove_stream(grpc_chttp2_transport* t, uint32_t id, if (error == GRPC_ERROR_NONE) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); } - incoming_byte_stream_publish_error(bs, error); - incoming_byte_stream_unref(bs); + incoming_byte_stream_publish_error(exec_ctx, bs, error); + incoming_byte_stream_unref(exec_ctx, bs); s->data_parser.parsing_frame = nullptr; } else { GRPC_ERROR_UNREF(s->byte_stream_error); @@ -1937,52 +2036,56 @@ static void remove_stream(grpc_chttp2_transport* t, uint32_t id, } if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { - post_benign_reclaimer(t); + post_benign_reclaimer(exec_ctx, t); if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SENT) { close_transport_locked( - t, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Last stream closed after sending GOAWAY", &error, 1)); + exec_ctx, t, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Last stream closed after sending GOAWAY", &error, 1)); } } if (grpc_chttp2_list_remove_writable_stream(t, s)) { - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:remove_stream"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:remove_stream"); } GRPC_ERROR_UNREF(error); - maybe_start_some_streams(t); + maybe_start_some_streams(exec_ctx, t); } -void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, +void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* due_to_error) { if (!t->is_client && !s->sent_trailing_metadata && grpc_error_has_clear_grpc_status(due_to_error)) { - close_from_api(t, s, due_to_error); + close_from_api(exec_ctx, t, s, due_to_error); return; } if (!s->read_closed || !s->write_closed) { if (s->id != 0) { grpc_http2_error_code http_error; - grpc_error_get_status(due_to_error, s->deadline, nullptr, nullptr, - &http_error, nullptr); + grpc_error_get_status(exec_ctx, due_to_error, s->deadline, nullptr, + nullptr, &http_error, nullptr); grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, &s->stats.outgoing)); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); } } if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) { s->seen_error = true; } - grpc_chttp2_mark_stream_closed(t, s, 1, 1, due_to_error); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error); } -void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_error* error) { +void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error) { grpc_status_code status; grpc_slice slice; - grpc_error_get_status(error, s->deadline, &status, &slice, nullptr, nullptr); + grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, nullptr, + nullptr); if (status != GRPC_STATUS_OK) { s->seen_error = true; } @@ -1998,20 +2101,20 @@ void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* s, gpr_ltoa(status, status_string); GRPC_LOG_IF_ERROR("add_status", grpc_chttp2_incoming_metadata_buffer_replace_or_add( - &s->metadata_buffer[1], + exec_ctx, &s->metadata_buffer[1], grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_STATUS, + exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(status_string)))); if (!GRPC_SLICE_IS_EMPTY(slice)) { GRPC_LOG_IF_ERROR( "add_status_message", grpc_chttp2_incoming_metadata_buffer_replace_or_add( - &s->metadata_buffer[1], - grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_MESSAGE, + exec_ctx, &s->metadata_buffer[1], + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal(slice)))); } s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } GRPC_ERROR_UNREF(error); @@ -2044,12 +2147,14 @@ static grpc_error* removal_error(grpc_error* extra_error, grpc_chttp2_stream* s, return error; } -static void flush_write_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_chttp2_write_cb** list, grpc_error* error) { +static void flush_write_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_write_cb** list, + grpc_error* error) { while (*list) { grpc_chttp2_write_cb* cb = *list; *list = cb->next; - grpc_chttp2_complete_closure_step(t, s, &cb->closure, GRPC_ERROR_REF(error), + grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, + GRPC_ERROR_REF(error), "on_write_finished_cb"); cb->next = t->write_cb_pool; t->write_cb_pool = cb; @@ -2057,34 +2162,37 @@ static void flush_write_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, GRPC_ERROR_UNREF(error); } -void grpc_chttp2_fail_pending_writes(grpc_chttp2_transport* t, +void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error) { error = removal_error(error, s, "Pending writes failed due to stream closure"); s->send_initial_metadata = nullptr; - grpc_chttp2_complete_closure_step(t, s, &s->send_initial_metadata_finished, - GRPC_ERROR_REF(error), - "send_initial_metadata_finished"); + grpc_chttp2_complete_closure_step( + exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_REF(error), + "send_initial_metadata_finished"); s->send_trailing_metadata = nullptr; - grpc_chttp2_complete_closure_step(t, s, &s->send_trailing_metadata_finished, - GRPC_ERROR_REF(error), - "send_trailing_metadata_finished"); + grpc_chttp2_complete_closure_step( + exec_ctx, t, s, &s->send_trailing_metadata_finished, + GRPC_ERROR_REF(error), "send_trailing_metadata_finished"); s->fetching_send_message = nullptr; - grpc_chttp2_complete_closure_step(t, s, &s->fetching_send_message_finished, - GRPC_ERROR_REF(error), - "fetching_send_message_finished"); - flush_write_list(t, s, &s->on_write_finished_cbs, GRPC_ERROR_REF(error)); - flush_write_list(t, s, &s->on_flow_controlled_cbs, error); + grpc_chttp2_complete_closure_step( + exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_REF(error), + "fetching_send_message_finished"); + flush_write_list(exec_ctx, t, s, &s->on_write_finished_cbs, + GRPC_ERROR_REF(error)); + flush_write_list(exec_ctx, t, s, &s->on_flow_controlled_cbs, error); } -void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error) { if (s->read_closed && s->write_closed) { /* already closed */ - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_ERROR_UNREF(error); return; } @@ -2098,20 +2206,20 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, if (close_writes && !s->write_closed) { s->write_closed_error = GRPC_ERROR_REF(error); s->write_closed = true; - grpc_chttp2_fail_pending_writes(t, s, GRPC_ERROR_REF(error)); + grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error)); } if (s->read_closed && s->write_closed) { became_closed = true; grpc_error* overall_error = removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { - remove_stream(t, s->id, GRPC_ERROR_REF(overall_error)); + remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error)); } else { /* Purge streams waiting on concurrency still waiting for id assignment */ grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } if (overall_error != GRPC_ERROR_NONE) { - grpc_chttp2_fake_status(t, s, overall_error); + grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); } } if (closed_read) { @@ -2120,18 +2228,18 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; } } - grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); - grpc_chttp2_maybe_complete_recv_message(t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); } if (became_closed) { - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2"); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2"); } GRPC_ERROR_UNREF(error); } -static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_error* error) { +static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error) { grpc_slice hdr; grpc_slice status_hdr; grpc_slice http_status_hdr; @@ -2141,8 +2249,8 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t len = 0; grpc_status_code grpc_status; grpc_slice slice; - grpc_error_get_status(error, s->deadline, &grpc_status, &slice, nullptr, - nullptr); + grpc_error_get_status(exec_ctx, error, s->deadline, &grpc_status, &slice, + nullptr, nullptr); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); @@ -2284,11 +2392,13 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); - grpc_chttp2_mark_stream_closed(t, s, 1, 1, error); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API); } typedef struct { + grpc_exec_ctx* exec_ctx; grpc_error* error; grpc_chttp2_transport* t; } cancel_stream_cb_args; @@ -2296,11 +2406,13 @@ typedef struct { static void cancel_stream_cb(void* user_data, uint32_t key, void* stream) { cancel_stream_cb_args* args = (cancel_stream_cb_args*)user_data; grpc_chttp2_stream* s = (grpc_chttp2_stream*)stream; - grpc_chttp2_cancel_stream(args->t, s, GRPC_ERROR_REF(args->error)); + grpc_chttp2_cancel_stream(args->exec_ctx, args->t, s, + GRPC_ERROR_REF(args->error)); } -static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error) { - cancel_stream_cb_args args = {error, t}; +static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { + cancel_stream_cb_args args = {exec_ctx, error, t}; grpc_chttp2_stream_map_for_each(&t->stream_map, cancel_stream_cb, &args); GRPC_ERROR_UNREF(error); } @@ -2310,14 +2422,14 @@ static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error) { */ template -static void WithUrgency(grpc_chttp2_transport* t, +static void WithUrgency(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_core::chttp2::FlowControlAction::Urgency urgency, grpc_chttp2_initiate_write_reason reason, F action) { switch (urgency) { case grpc_core::chttp2::FlowControlAction::Urgency::NO_ACTION_NEEDED: break; case grpc_core::chttp2::FlowControlAction::Urgency::UPDATE_IMMEDIATELY: - grpc_chttp2_initiate_write(t, reason); + grpc_chttp2_initiate_write(exec_ctx, t, reason); // fallthrough case grpc_core::chttp2::FlowControlAction::Urgency::QUEUE_UPDATE: action(); @@ -2326,27 +2438,31 @@ static void WithUrgency(grpc_chttp2_transport* t, } void grpc_chttp2_act_on_flowctl_action( - const grpc_core::chttp2::FlowControlAction& action, + grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - WithUrgency(t, action.send_stream_update(), - GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL, - [t, s]() { grpc_chttp2_mark_stream_writable(t, s); }); - WithUrgency(t, action.send_transport_update(), + WithUrgency( + exec_ctx, t, action.send_stream_update(), + GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL, + [exec_ctx, t, s]() { grpc_chttp2_mark_stream_writable(exec_ctx, t, s); }); + WithUrgency(exec_ctx, t, action.send_transport_update(), GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL, []() {}); - WithUrgency(t, action.send_initial_window_update(), - GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [t, &action]() { - queue_setting_update(t, + WithUrgency(exec_ctx, t, action.send_initial_window_update(), + GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, + [exec_ctx, t, &action]() { + queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, action.initial_window_size()); }); - WithUrgency(t, action.send_max_frame_size_update(), - GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [t, &action]() { - queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, - action.max_frame_size()); - }); + WithUrgency( + exec_ctx, t, action.send_max_frame_size_update(), + GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [exec_ctx, t, &action]() { + queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, + action.max_frame_size()); + }); } -static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { +static grpc_error* try_http_parsing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_http_parser parser; size_t i = 0; grpc_error* error = GRPC_ERROR_NONE; @@ -2375,7 +2491,8 @@ static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { return error; } -static void read_action_locked(void* tp, grpc_error* error) { +static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { GPR_TIMER_BEGIN("reading_action_locked", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; @@ -2399,10 +2516,11 @@ static void read_action_locked(void* tp, grpc_error* error) { for (; i < t->read_buffer.count && errors[1] == GRPC_ERROR_NONE; i++) { t->flow_control->bdp_estimator()->AddIncomingBytes( (int64_t)GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); - errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]); + errors[1] = + grpc_chttp2_perform_read(exec_ctx, t, t->read_buffer.slices[i]); } if (errors[1] != GRPC_ERROR_NONE) { - errors[2] = try_http_parsing(t); + errors[2] = try_http_parsing(exec_ctx, t); GRPC_ERROR_UNREF(error); error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed parsing HTTP/2", errors, GPR_ARRAY_SIZE(errors)); @@ -2417,9 +2535,10 @@ static void read_action_locked(void* tp, grpc_error* error) { if (t->initial_window_update > 0) { grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_stalled_by_stream(t, &s)) { - grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING); + exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING); } } t->initial_window_update = 0; @@ -2440,21 +2559,22 @@ static void read_action_locked(void* tp, grpc_error* error) { error = grpc_error_add_child(error, GRPC_ERROR_REF(t->goaway_error)); } - close_transport_locked(t, GRPC_ERROR_REF(error)); + close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error)); t->endpoint_reading = 0; } else if (t->closed_with_error == GRPC_ERROR_NONE) { keep_reading = true; GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading"); } - grpc_slice_buffer_reset_and_unref_internal(&t->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->read_buffer); if (keep_reading) { - grpc_endpoint_read(t->ep, &t->read_buffer, &t->read_action_locked); - grpc_chttp2_act_on_flowctl_action(t->flow_control->MakeAction(), t, - nullptr); - GRPC_CHTTP2_UNREF_TRANSPORT(t, "keep_reading"); + grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer, + &t->read_action_locked); + grpc_chttp2_act_on_flowctl_action(exec_ctx, t->flow_control->MakeAction(), + t, nullptr); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keep_reading"); } else { - GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "reading_action"); } GPR_TIMER_END("post_reading_action_locked", 0); @@ -2466,12 +2586,15 @@ static void read_action_locked(void* tp, grpc_error* error) { // t is reffed prior to calling the first time, and once the callback chain // that kicks off finishes, it's unreffed -static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) { +static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { t->flow_control->bdp_estimator()->SchedulePing(); - send_ping_locked(t, &t->start_bdp_ping_locked, &t->finish_bdp_ping_locked); + send_ping_locked(exec_ctx, t, &t->start_bdp_ping_locked, + &t->finish_bdp_ping_locked); } -static void start_bdp_ping_locked(void* tp, grpc_error* error) { +static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, @@ -2479,39 +2602,42 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) { } /* Reset the keepalive ping timer */ if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) { - grpc_timer_cancel(&t->keepalive_ping_timer); + grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); } t->flow_control->bdp_estimator()->StartPing(); } -static void finish_bdp_ping_locked(void* tp, grpc_error* error) { +static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); } if (error != GRPC_ERROR_NONE) { - GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping"); return; } - grpc_millis next_ping = t->flow_control->bdp_estimator()->CompletePing(); - grpc_chttp2_act_on_flowctl_action(t->flow_control->PeriodicUpdate(), t, - nullptr); + grpc_millis next_ping = + t->flow_control->bdp_estimator()->CompletePing(exec_ctx); + grpc_chttp2_act_on_flowctl_action( + exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, nullptr); GPR_ASSERT(!t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = true; - grpc_timer_init(&t->next_bdp_ping_timer, next_ping, + grpc_timer_init(exec_ctx, &t->next_bdp_ping_timer, next_ping, &t->next_bdp_ping_timer_expired_locked); } -static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error) { +static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, + void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { - GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping"); return; } - schedule_bdp_ping_locked(t); + schedule_bdp_ping_locked(exec_ctx, t); } void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, @@ -2572,7 +2698,8 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } } -static void init_keepalive_ping_locked(void* arg, grpc_error* error) { +static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { @@ -2582,55 +2709,59 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_stream_map_size(&t->stream_map) > 0) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end"); - send_ping_locked(t, &t->start_keepalive_ping_locked, + send_ping_locked(exec_ctx, t, &t->start_keepalive_ping_locked, &t->finish_keepalive_ping_locked); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); } else { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, + grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->init_keepalive_ping_locked); } } else if (error == GRPC_ERROR_CANCELLED) { /* The keepalive ping timer may be cancelled by bdp */ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, + grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->init_keepalive_ping_locked); } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "init keepalive ping"); } -static void start_keepalive_ping_locked(void* arg, grpc_error* error) { +static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); - grpc_timer_init(&t->keepalive_watchdog_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + grpc_timer_init(exec_ctx, &t->keepalive_watchdog_timer, + grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->keepalive_watchdog_fired_locked); } -static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { +static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; - grpc_timer_cancel(&t->keepalive_watchdog_timer); + grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer); GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, + grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->init_keepalive_ping_locked); } } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive ping end"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive ping end"); } -static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { +static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; close_transport_locked( - t, + exec_ctx, t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "keepalive watchdog timeout"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL)); @@ -2643,67 +2774,71 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); } } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive watchdog"); } /******************************************************************************* * CALLBACK LOOP */ -static void connectivity_state_set(grpc_chttp2_transport* t, +static void connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_connectivity_state state, grpc_error* error, const char* reason) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_DEBUG, "set connectivity_state=%d", state)); - grpc_connectivity_state_set(&t->channel_callback.state_tracker, state, error, - reason); + grpc_connectivity_state_set(exec_ctx, &t->channel_callback.state_tracker, + state, error, reason); } /******************************************************************************* * POLLSET STUFF */ -static void set_pollset(grpc_transport* gt, grpc_stream* gs, - grpc_pollset* pollset) { +static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_endpoint_add_to_pollset(t->ep, pollset); + grpc_endpoint_add_to_pollset(exec_ctx, t->ep, pollset); } -static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, - grpc_pollset_set* pollset_set) { +static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset_set* pollset_set) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); + grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, pollset_set); } /******************************************************************************* * BYTE STREAM */ -static void reset_byte_stream(void* arg, grpc_error* error) { +static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)arg; s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { - grpc_chttp2_maybe_complete_recv_message(s->t, s); - grpc_chttp2_maybe_complete_recv_trailing_metadata(s->t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, s->t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, s->t, s); } else { GPR_ASSERT(error != GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_NONE; - grpc_chttp2_cancel_stream(s->t, s, GRPC_ERROR_REF(error)); + grpc_chttp2_cancel_stream(exec_ctx, s->t, s, GRPC_ERROR_REF(error)); s->byte_stream_error = GRPC_ERROR_REF(error); } } -static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs) { +static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, + grpc_chttp2_incoming_byte_stream* bs) { if (gpr_unref(&bs->refs)) { gpr_free(bs); } } -static void incoming_byte_stream_next_locked(void* argp, +static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, + void* argp, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)argp; @@ -2714,29 +2849,30 @@ static void incoming_byte_stream_next_locked(void* argp, if (!s->read_closed) { s->flow_control->IncomingByteStreamUpdate(bs->next_action.max_size_hint, cur_length); - grpc_chttp2_act_on_flowctl_action(s->flow_control->MakeAction(), t, s); + grpc_chttp2_act_on_flowctl_action(exec_ctx, s->flow_control->MakeAction(), + t, s); } GPR_ASSERT(s->unprocessed_incoming_frames_buffer.length == 0); if (s->frame_storage.length > 0) { grpc_slice_buffer_swap(&s->frame_storage, &s->unprocessed_incoming_frames_buffer); s->unprocessed_incoming_frames_decompressed = false; - GRPC_CLOSURE_SCHED(bs->next_action.on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_NONE); } else if (s->byte_stream_error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(bs->next_action.on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); if (s->data_parser.parsing_frame != nullptr) { - incoming_byte_stream_unref(s->data_parser.parsing_frame); + incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); s->data_parser.parsing_frame = nullptr; } } else if (s->read_closed) { if (bs->remaining_bytes != 0) { s->byte_stream_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); - GRPC_CLOSURE_SCHED(bs->next_action.on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); if (s->data_parser.parsing_frame != nullptr) { - incoming_byte_stream_unref(s->data_parser.parsing_frame); + incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); s->data_parser.parsing_frame = nullptr; } } else { @@ -2746,10 +2882,11 @@ static void incoming_byte_stream_next_locked(void* argp, } else { s->on_next = bs->next_action.on_complete; } - incoming_byte_stream_unref(bs); + incoming_byte_stream_unref(exec_ctx, bs); } -static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, +static bool incoming_byte_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { GPR_TIMER_BEGIN("incoming_byte_stream_next", 0); @@ -2764,6 +2901,7 @@ static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, bs->next_action.max_size_hint = max_size_hint; bs->next_action.on_complete = on_complete; GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&bs->next_action.closure, incoming_byte_stream_next_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), @@ -2773,7 +2911,8 @@ static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, } } -static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, +static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_slice* slice) { GPR_TIMER_BEGIN("incoming_byte_stream_pull", 0); grpc_chttp2_incoming_byte_stream* bs = @@ -2809,28 +2948,31 @@ static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, } } error = grpc_deframe_unprocessed_incoming_frames( - &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, slice, - nullptr); + exec_ctx, &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, + slice, nullptr); if (error != GRPC_ERROR_NONE) { return error; } } else { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); - GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); return error; } GPR_TIMER_END("incoming_byte_stream_pull", 0); return GRPC_ERROR_NONE; } -static void incoming_byte_stream_destroy_locked(void* byte_stream, +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, grpc_error* error_ignored); -static void incoming_byte_stream_destroy(grpc_byte_stream* byte_stream) { +static void incoming_byte_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream) { GPR_TIMER_BEGIN("incoming_byte_stream_destroy", 0); grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&bs->destroy_action, incoming_byte_stream_destroy_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), @@ -2839,28 +2981,30 @@ static void incoming_byte_stream_destroy(grpc_byte_stream* byte_stream) { } static void incoming_byte_stream_publish_error( - grpc_chttp2_incoming_byte_stream* bs, grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error) { grpc_chttp2_stream* s = bs->stream; GPR_ASSERT(error != GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_REF(error); - grpc_chttp2_cancel_stream(bs->transport, bs->stream, GRPC_ERROR_REF(error)); + grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream, + GRPC_ERROR_REF(error)); } grpc_error* grpc_chttp2_incoming_byte_stream_push( - grpc_chttp2_incoming_byte_stream* bs, grpc_slice slice, - grpc_slice* slice_out) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_slice slice, grpc_slice* slice_out) { grpc_chttp2_stream* s = bs->stream; if (bs->remaining_bytes < GRPC_SLICE_LENGTH(slice)) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many bytes in stream"); - GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); - grpc_slice_unref_internal(slice); + GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); + grpc_slice_unref_internal(exec_ctx, slice); return error; } else { bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice); @@ -2872,8 +3016,8 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( } grpc_error* grpc_chttp2_incoming_byte_stream_finished( - grpc_chttp2_incoming_byte_stream* bs, grpc_error* error, - bool reset_on_error) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error, bool reset_on_error) { grpc_chttp2_stream* s = bs->stream; if (error == GRPC_ERROR_NONE) { @@ -2882,25 +3026,27 @@ grpc_error* grpc_chttp2_incoming_byte_stream_finished( } } if (error != GRPC_ERROR_NONE && reset_on_error) { - GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); } - incoming_byte_stream_unref(bs); + incoming_byte_stream_unref(exec_ctx, bs); return error; } -static void incoming_byte_stream_shutdown(grpc_byte_stream* byte_stream, +static void incoming_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_error* error) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - bs, error, true /* reset_on_error */)); + exec_ctx, bs, error, true /* reset_on_error */)); } static const grpc_byte_stream_vtable grpc_chttp2_incoming_byte_stream_vtable = { incoming_byte_stream_next, incoming_byte_stream_pull, incoming_byte_stream_shutdown, incoming_byte_stream_destroy}; -static void incoming_byte_stream_destroy_locked(void* byte_stream, +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; @@ -2908,15 +3054,15 @@ static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_chttp2_transport* t = s->t; GPR_ASSERT(bs->base.vtable == &grpc_chttp2_incoming_byte_stream_vtable); - incoming_byte_stream_unref(bs); + incoming_byte_stream_unref(exec_ctx, bs); s->pending_byte_stream = false; - grpc_chttp2_maybe_complete_recv_message(t, s); - grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( - grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, - uint32_t flags) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, + uint32_t frame_size, uint32_t flags) { grpc_chttp2_incoming_byte_stream* incoming_byte_stream = (grpc_chttp2_incoming_byte_stream*)gpr_malloc( sizeof(*incoming_byte_stream)); @@ -2936,25 +3082,30 @@ grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( * RESOURCE QUOTAS */ -static void post_benign_reclaimer(grpc_chttp2_transport* t) { +static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!t->benign_reclaimer_registered) { t->benign_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer"); - grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), + grpc_resource_user_post_reclaimer(exec_ctx, + grpc_endpoint_get_resource_user(t->ep), false, &t->benign_reclaimer_locked); } } -static void post_destructive_reclaimer(grpc_chttp2_transport* t) { +static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!t->destructive_reclaimer_registered) { t->destructive_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer"); - grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), + grpc_resource_user_post_reclaimer(exec_ctx, + grpc_endpoint_get_resource_user(t->ep), true, &t->destructive_reclaimer_locked); } } -static void benign_reclaimer_locked(void* arg, grpc_error* error) { +static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (error == GRPC_ERROR_NONE && grpc_chttp2_stream_map_size(&t->stream_map) == 0) { @@ -2964,7 +3115,7 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) { gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory", t->peer_string); } - send_goaway(t, + send_goaway(exec_ctx, t, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); @@ -2977,12 +3128,13 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) { t->benign_reclaimer_registered = false; if (error != GRPC_ERROR_CANCELLED) { grpc_resource_user_finish_reclamation( - grpc_endpoint_get_resource_user(t->ep)); + exec_ctx, grpc_endpoint_get_resource_user(t->ep)); } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "benign_reclaimer"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "benign_reclaimer"); } -static void destructive_reclaimer_locked(void* arg, grpc_error* error) { +static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; size_t n = grpc_chttp2_stream_map_size(&t->stream_map); t->destructive_reclaimer_registered = false; @@ -2994,7 +3146,7 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { s->id); } grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); @@ -3003,14 +3155,14 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { there are more streams left, we can immediately post a new reclaimer in case the resource quota needs to free more memory */ - post_destructive_reclaimer(t); + post_destructive_reclaimer(exec_ctx, t); } } if (error != GRPC_ERROR_CANCELLED) { grpc_resource_user_finish_reclamation( - grpc_endpoint_get_resource_user(t->ep)); + exec_ctx, grpc_endpoint_get_resource_user(t->ep)); } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer"); + GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destructive_reclaimer"); } /******************************************************************************* @@ -3064,7 +3216,8 @@ const char* grpc_chttp2_initiate_write_reason_string( GPR_UNREACHABLE_CODE(return "unknown"); } -static grpc_endpoint* chttp2_get_endpoint(grpc_transport* t) { +static grpc_endpoint* chttp2_get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* t) { return ((grpc_chttp2_transport*)t)->ep; } @@ -3082,16 +3235,17 @@ static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), static const grpc_transport_vtable* get_vtable(void) { return &vtable; } grpc_transport* grpc_create_chttp2_transport( - const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { + grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, + grpc_endpoint* ep, bool is_client) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gpr_zalloc(sizeof(grpc_chttp2_transport)); - init_transport(t, channel_args, ep, is_client); + init_transport(exec_ctx, t, channel_args, ep, is_client); return &t->base; } void grpc_chttp2_transport_start_reading( - grpc_transport* transport, grpc_slice_buffer* read_buffer, - grpc_closure* notify_on_receive_settings) { + grpc_exec_ctx* exec_ctx, grpc_transport* transport, + grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ @@ -3100,5 +3254,5 @@ void grpc_chttp2_transport_start_reading( gpr_free(read_buffer); } t->notify_on_receive_settings = notify_on_receive_settings; - GRPC_CLOSURE_SCHED(&t->read_action_locked, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &t->read_action_locked, GRPC_ERROR_NONE); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index 596ababb19..bd72e07bab 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -28,14 +28,15 @@ extern grpc_core::TraceFlag grpc_trace_http2_stream_state; extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount; grpc_transport* grpc_create_chttp2_transport( - const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client); + grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, + grpc_endpoint* ep, bool is_client); /// Takes ownership of \a read_buffer, which (if non-NULL) contains /// leftover bytes previously read from the endpoint (e.g., by handshakers). /// If non-null, \a notify_on_receive_settings will be scheduled when /// HTTP/2 settings are received from the peer. void grpc_chttp2_transport_start_reading( - grpc_transport* transport, grpc_slice_buffer* read_buffer, - grpc_closure* notify_on_receive_settings); + grpc_exec_ctx* exec_ctx, grpc_transport* transport, + grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H */ diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index ca48cc7e0a..8a057bd9ff 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -149,7 +149,8 @@ void FlowControlAction::Trace(grpc_chttp2_transport* t) const { gpr_free(mf_str); } -TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, +TransportFlowControl::TransportFlowControl(grpc_exec_ctx* exec_ctx, + const grpc_chttp2_transport* t, bool enable_bdp_probe) : t_(t), enable_bdp_probe_(enable_bdp_probe), @@ -162,7 +163,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, .set_min_control_value(-1) .set_max_control_value(25) .set_integral_range(10)), - last_pid_update_(grpc_core::ExecCtx::Get()->Now()) {} + last_pid_update_(grpc_exec_ctx_now(exec_ctx)) {} uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); @@ -307,8 +308,9 @@ double TransportFlowControl::TargetLogBdp() { 1 + log2(bdp_estimator_.EstimateBdp())); } -double TransportFlowControl::SmoothLogBdp(double value) { - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); +double TransportFlowControl::SmoothLogBdp(grpc_exec_ctx* exec_ctx, + double value) { + grpc_millis now = grpc_exec_ctx_now(exec_ctx); double bdp_error = value - pid_controller_.last_control_value(); const double dt = (double)(now - last_pid_update_) * 1e-3; last_pid_update_ = now; @@ -329,14 +331,15 @@ FlowControlAction::Urgency TransportFlowControl::DeltaUrgency( } } -FlowControlAction TransportFlowControl::PeriodicUpdate() { +FlowControlAction TransportFlowControl::PeriodicUpdate( + grpc_exec_ctx* exec_ctx) { FlowControlAction action; if (enable_bdp_probe_) { // get bdp estimate and update initial_window accordingly. // target might change based on how much memory pressure we are under // TODO(ncteisen): experiment with setting target to be huge under low // memory pressure. - const double target = pow(2, SmoothLogBdp(TargetLogBdp())); + const double target = pow(2, SmoothLogBdp(exec_ctx, TargetLogBdp())); // Though initial window 'could' drop to 0, we keep the floor at 128 target_initial_window_size_ = (int32_t)GPR_CLAMP(target, 128, INT32_MAX); diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 8306047dbc..2515c94309 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -134,7 +134,8 @@ class FlowControlTrace { class TransportFlowControl { public: - TransportFlowControl(const grpc_chttp2_transport* t, bool enable_bdp_probe); + TransportFlowControl(grpc_exec_ctx* exec_ctx, const grpc_chttp2_transport* t, + bool enable_bdp_probe); ~TransportFlowControl() {} bool bdp_probe() const { return enable_bdp_probe_; } @@ -152,7 +153,7 @@ class TransportFlowControl { // Call periodically (at a low-ish rate, 100ms - 10s makes sense) // to perform more complex flow control calculations and return an action // to let chttp2 change its parameters - FlowControlAction PeriodicUpdate(); + FlowControlAction PeriodicUpdate(grpc_exec_ctx* exec_ctx); void StreamSentData(int64_t size) { remote_window_ -= size; } @@ -211,7 +212,7 @@ class TransportFlowControl { private: friend class ::grpc::testing::TrickledCHTTP2; double TargetLogBdp(); - double SmoothLogBdp(double value); + double SmoothLogBdp(grpc_exec_ctx* exec_ctx, double value); FlowControlAction::Urgency DeltaUrgency(int32_t value, grpc_chttp2_setting_id setting_id); diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 9b3a6acc9e..f0c3b55792 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -36,10 +36,11 @@ grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser) { return GRPC_ERROR_NONE; } -void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser* parser) { +void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_data_parser* parser) { if (parser->parsing_frame != nullptr) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - parser->parsing_frame, + exec_ctx, parser->parsing_frame, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"), false)); } GRPC_ERROR_UNREF(parser->error); @@ -97,7 +98,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, } grpc_error* grpc_deframe_unprocessed_incoming_frames( - grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, grpc_slice_buffer* slices, grpc_slice* slice_out, grpc_byte_stream** stream_out) { grpc_error* error = GRPC_ERROR_NONE; @@ -117,14 +118,14 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( char* msg; if (cur == end) { - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } switch (p->state) { case GRPC_CHTTP2_DATA_ERROR: p->state = GRPC_CHTTP2_DATA_ERROR; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_REF(p->error); case GRPC_CHTTP2_DATA_FH_0: s->stats.incoming.framing_bytes++; @@ -149,12 +150,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg); p->state = GRPC_CHTTP2_DATA_ERROR; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_REF(p->error); } if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_1; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } /* fallthrough */ @@ -163,7 +164,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size = ((uint32_t)*cur) << 24; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_2; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } /* fallthrough */ @@ -172,7 +173,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size |= ((uint32_t)*cur) << 16; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_3; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } /* fallthrough */ @@ -181,7 +182,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size |= ((uint32_t)*cur) << 8; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_4; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } /* fallthrough */ @@ -197,11 +198,11 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( message_flags |= GRPC_WRITE_INTERNAL_COMPRESS; } p->parsing_frame = grpc_chttp2_incoming_byte_stream_create( - t, s, p->frame_size, message_flags); + exec_ctx, t, s, p->frame_size, message_flags); *stream_out = &p->parsing_frame->base; if (p->parsing_frame->remaining_bytes == 0) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - p->parsing_frame, GRPC_ERROR_NONE, true)); + exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true)); p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; } @@ -212,64 +213,64 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( slices, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); } - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; case GRPC_CHTTP2_DATA_FRAME: { GPR_ASSERT(p->parsing_frame != nullptr); GPR_ASSERT(slice_out != nullptr); if (cur == end) { - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); continue; } uint32_t remaining = (uint32_t)(end - cur); if (remaining == p->frame_size) { s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, + exec_ctx, p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)), slice_out))) { - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return error; } if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_finished( - p->parsing_frame, GRPC_ERROR_NONE, true))) { - grpc_slice_unref_internal(slice); + exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) { + grpc_slice_unref_internal(exec_ctx, slice); return error; } p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; } else if (remaining < p->frame_size) { s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, + exec_ctx, p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)), slice_out))) { return error; } p->frame_size -= remaining; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; } else { GPR_ASSERT(remaining > p->frame_size); s->stats.incoming.data_bytes += p->frame_size; if (GRPC_ERROR_NONE != (grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, + exec_ctx, p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(cur + p->frame_size - beg)), slice_out))) { - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return error; } if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_finished( - p->parsing_frame, GRPC_ERROR_NONE, true))) { - grpc_slice_unref_internal(slice); + exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) { + grpc_slice_unref_internal(exec_ctx, slice); return error; } p->parsing_frame = nullptr; @@ -278,7 +279,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_buffer_undo_take_first( slices, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; } } @@ -288,19 +289,19 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_data_parser_parse(void* parser, +grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { if (!s->pending_byte_stream) { grpc_slice_ref_internal(slice); grpc_slice_buffer_add(&s->frame_storage, slice); - grpc_chttp2_maybe_complete_recv_message(t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); } else if (s->on_next) { GPR_ASSERT(s->frame_storage.length == 0); grpc_slice_ref_internal(slice); grpc_slice_buffer_add(&s->unprocessed_incoming_frames_buffer, slice); - GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_NONE); s->on_next = nullptr; s->unprocessed_incoming_frames_decompressed = false; } else { @@ -309,7 +310,8 @@ grpc_error* grpc_chttp2_data_parser_parse(void* parser, } if (is_last && s->received_last_frame) { - grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, + GRPC_ERROR_NONE); } return GRPC_ERROR_NONE; diff --git a/src/core/ext/transport/chttp2/transport/frame_data.h b/src/core/ext/transport/chttp2/transport/frame_data.h index 964cc59b1b..4de553ea42 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.h +++ b/src/core/ext/transport/chttp2/transport/frame_data.h @@ -54,7 +54,8 @@ typedef struct { /* initialize per-stream state for data frame parsing */ grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser); -void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser* parser); +void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_data_parser* parser); /* start processing a new data frame */ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, @@ -64,7 +65,7 @@ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, /* handle a slice of a data frame - is_last indicates the last slice of a frame */ -grpc_error* grpc_chttp2_data_parser_parse(void* parser, +grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); @@ -75,7 +76,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, grpc_slice_buffer* outbuf); grpc_error* grpc_deframe_unprocessed_incoming_frames( - grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, grpc_slice_buffer* slices, grpc_slice* slice_out, grpc_byte_stream** stream_out); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index b60b4227fe..a2ce709a2e 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -52,7 +52,8 @@ grpc_error* grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser* p, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, +grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -134,7 +135,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { grpc_chttp2_add_incoming_goaway( - t, (uint32_t)p->error_code, + exec_ctx, t, (uint32_t)p->error_code, grpc_slice_new(p->debug_data, p->debug_length, gpr_free)); p->debug_data = nullptr; } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.h b/src/core/ext/transport/chttp2/transport/frame_goaway.h index 064d39ac59..743e763342 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.h +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.h @@ -50,7 +50,8 @@ void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser* p); void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p); grpc_error* grpc_chttp2_goaway_parser_begin_frame( grpc_chttp2_goaway_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, +grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 298a56721a..d0feb51922 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -68,7 +68,7 @@ grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_ping_parser_parse(void* parser, +grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -86,10 +86,10 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, if (p->byte == 8) { GPR_ASSERT(is_last); if (p->is_ack) { - grpc_chttp2_ack_ping(t, p->opaque_8bytes); + grpc_chttp2_ack_ping(exec_ctx, t, p->opaque_8bytes); } else { if (!t->is_client) { - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); grpc_millis next_allowed_ping = t->ping_recv_state.last_ping_recv_time + t->ping_policy.min_recv_ping_interval_without_data; @@ -104,7 +104,7 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, } if (next_allowed_ping > now) { - grpc_chttp2_add_ping_strike(t); + grpc_chttp2_add_ping_strike(exec_ctx, t); } t->ping_recv_state.last_ping_recv_time = now; @@ -116,7 +116,8 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks)); } t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes; - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); } } } diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.h b/src/core/ext/transport/chttp2/transport/frame_ping.h index 75bacfb1d4..76ca397709 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.h +++ b/src/core/ext/transport/chttp2/transport/frame_ping.h @@ -33,7 +33,7 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes); grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_ping_parser_parse(void* parser, +grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index fee576678d..05a7f056a4 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -69,7 +69,8 @@ grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, +grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -102,7 +103,7 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); gpr_free(message); } - grpc_chttp2_mark_stream_closed(t, s, true, true, error); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, error); } return GRPC_ERROR_NONE; diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h index e76a3ca841..7dfc5d4578 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h @@ -34,7 +34,8 @@ grpc_slice grpc_chttp2_rst_stream_create(uint32_t stream_id, uint32_t code, grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, +grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index c6c2a6c301..de4340fea5 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -108,7 +108,8 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame( } } -grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, void* p, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { grpc_chttp2_settings_parser* parser = (grpc_chttp2_settings_parser*)p; @@ -131,7 +132,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); grpc_slice_buffer_add(&t->qbuf, grpc_chttp2_settings_ack_create()); if (t->notify_on_receive_settings != nullptr) { - GRPC_CLOSURE_SCHED(t->notify_on_receive_settings, + GRPC_CLOSURE_SCHED(exec_ctx, t->notify_on_receive_settings, GRPC_ERROR_NONE); t->notify_on_receive_settings = nullptr; } diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.h b/src/core/ext/transport/chttp2/transport/frame_settings.h index ce65402815..36e2ca83a0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.h +++ b/src/core/ext/transport/chttp2/transport/frame_settings.h @@ -52,7 +52,8 @@ grpc_slice grpc_chttp2_settings_ack_create(void); grpc_error* grpc_chttp2_settings_parser_begin_frame( grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags, uint32_t* settings); -grpc_error* grpc_chttp2_settings_parser_parse(void* parser, +grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 418ca144ce..08407a8e67 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -64,11 +64,9 @@ grpc_error* grpc_chttp2_window_update_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, - grpc_chttp2_transport* t, - grpc_chttp2_stream* s, - grpc_slice slice, - int is_last) { +grpc_error* grpc_chttp2_window_update_parser_parse( + grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; @@ -100,9 +98,10 @@ grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, if (s != nullptr) { s->flow_control->RecvUpdate(received_update); if (grpc_chttp2_list_remove_stalled_by_stream(t, s)) { - grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_mark_stream_writable(exec_ctx, t, s); grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE); + exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE); } } } else { @@ -111,7 +110,8 @@ grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, bool is_zero = t->flow_control->remote_window() <= 0; if (was_zero && !is_zero) { grpc_chttp2_initiate_write( - t, GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED); + exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED); } } } diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.h b/src/core/ext/transport/chttp2/transport/frame_window_update.h index a32f1a9d11..e031b585fa 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.h +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.h @@ -35,10 +35,8 @@ grpc_slice grpc_chttp2_window_update_create( grpc_error* grpc_chttp2_window_update_parser_begin_frame( grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, - grpc_chttp2_transport* t, - grpc_chttp2_stream* s, - grpc_slice slice, - int is_last); +grpc_error* grpc_chttp2_window_update_parser_parse( + grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_WINDOW_UPDATE_H */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 3a5692a694..e76d92e31d 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -206,12 +206,14 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, } /* dummy function */ -static void add_nothing(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, +static void add_nothing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, size_t elem_size) {} // Add a key to the dynamic table. Both key and value will be added to table at // the decoder. -static void add_key_with_index(grpc_chttp2_hpack_compressor* c, +static void add_key_with_index(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -238,12 +240,14 @@ static void add_key_with_index(grpc_chttp2_hpack_compressor* c, c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { - grpc_slice_unref_internal(c->entries_keys[HASH_FRAGMENT_2(key_hash)]); + grpc_slice_unref_internal(exec_ctx, + c->entries_keys[HASH_FRAGMENT_2(key_hash)]); c->entries_keys[HASH_FRAGMENT_2(key_hash)] = grpc_slice_ref_internal(GRPC_MDKEY(elem)); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; } else { - grpc_slice_unref_internal(c->entries_keys[HASH_FRAGMENT_3(key_hash)]); + grpc_slice_unref_internal(exec_ctx, + c->entries_keys[HASH_FRAGMENT_3(key_hash)]); c->entries_keys[HASH_FRAGMENT_3(key_hash)] = grpc_slice_ref_internal(GRPC_MDKEY(elem)); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; @@ -251,7 +255,8 @@ static void add_key_with_index(grpc_chttp2_hpack_compressor* c, } /* add an element to the decoder table */ -static void add_elem_with_index(grpc_chttp2_hpack_compressor* c, +static void add_elem_with_index(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -281,34 +286,35 @@ static void add_elem_with_index(grpc_chttp2_hpack_compressor* c, } else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] < c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) { /* not there: replace oldest */ - GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_2(elem_hash)]); + GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_2(elem_hash)]); c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; } else { /* not there: replace oldest */ - GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_3(elem_hash)]); + GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_3(elem_hash)]); c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; } - add_key_with_index(c, elem, new_index); + add_key_with_index(exec_ctx, c, elem, new_index); } -static void add_elem(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, - size_t elem_size) { +static void add_elem(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, + grpc_mdelem elem, size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); - add_elem_with_index(c, elem, new_index); + add_elem_with_index(exec_ctx, c, elem, new_index); } -static void add_key(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, - size_t elem_size) { +static void add_key(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, + grpc_mdelem elem, size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); - add_key_with_index(c, elem, new_index); + add_key_with_index(exec_ctx, c, elem, new_index); } -static void emit_indexed(grpc_chttp2_hpack_compressor* c, uint32_t elem_index, +static void emit_indexed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t elem_index, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_INDEXED(); + GRPC_STATS_INC_HPACK_SEND_INDEXED(exec_ctx); uint32_t len = GRPC_CHTTP2_VARINT_LENGTH(elem_index, 1); GRPC_CHTTP2_WRITE_VARINT(elem_index, 1, 0x80, add_tiny_header_data(st, len), len); @@ -320,17 +326,18 @@ typedef struct { bool insert_null_before_wire_value; } wire_value; -static wire_value get_wire_value(grpc_mdelem elem, bool true_binary_enabled) { +static wire_value get_wire_value(grpc_exec_ctx* exec_ctx, grpc_mdelem elem, + bool true_binary_enabled) { wire_value wire_val; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { if (true_binary_enabled) { - GRPC_STATS_INC_HPACK_SEND_BINARY(); + GRPC_STATS_INC_HPACK_SEND_BINARY(exec_ctx); wire_val.huffman_prefix = 0x00; wire_val.insert_null_before_wire_value = true; wire_val.data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)); } else { - GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(); + GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(exec_ctx); wire_val.huffman_prefix = 0x80; wire_val.insert_null_before_wire_value = false; wire_val.data = @@ -338,7 +345,7 @@ static wire_value get_wire_value(grpc_mdelem elem, bool true_binary_enabled) { } } else { /* TODO(ctiller): opportunistically compress non-binary headers */ - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); wire_val.huffman_prefix = 0x00; wire_val.insert_null_before_wire_value = false; wire_val.data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)); @@ -355,12 +362,14 @@ static void add_wire_value(framer_state* st, wire_value v) { add_header_data(st, v.data); } -static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(); + GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(exec_ctx); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); - wire_value value = get_wire_value(elem, st->use_true_binary_metadata); + wire_value value = + get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); size_t len_val = wire_value_length(value); uint32_t len_val_len; GPR_ASSERT(len_val <= UINT32_MAX); @@ -372,12 +381,14 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor* c, add_wire_value(st, value); } -static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_noidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(); + GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(exec_ctx); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); - wire_value value = get_wire_value(elem, st->use_true_binary_metadata); + wire_value value = + get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); size_t len_val = wire_value_length(value); uint32_t len_val_len; GPR_ASSERT(len_val <= UINT32_MAX); @@ -389,14 +400,16 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor* c, add_wire_value(st, value); } -static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, framer_state* st) { GPR_ASSERT(unused_index == 0); - GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(); - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); + GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); - wire_value value = get_wire_value(elem, st->use_true_binary_metadata); + wire_value value = + get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); uint32_t len_val = (uint32_t)wire_value_length(value); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); @@ -411,14 +424,16 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, add_wire_value(st, value); } -static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_noidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, framer_state* st) { GPR_ASSERT(unused_index == 0); - GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(); - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); + GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); - wire_value value = get_wire_value(elem, st->use_true_binary_metadata); + wire_value value = + get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); uint32_t len_val = (uint32_t)wire_value_length(value); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); @@ -447,8 +462,8 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor* c, uint32_t elem_index) { } /* encode an mdelem */ -static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, - framer_state* st) { +static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, + grpc_mdelem elem, framer_state* st) { GPR_ASSERT(GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)) > 0); if (GRPC_SLICE_START_PTR(GRPC_MDKEY(elem))[0] != ':') { /* regular header */ st->seen_regular_header = 1; @@ -481,7 +496,7 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, // Key is not interned, emit literals. if (!key_interned) { - emit_lithdr_noidx_v(c, 0, elem, st); + emit_lithdr_noidx_v(exec_ctx, c, 0, elem, st); return; } @@ -500,16 +515,16 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem) && c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (first cuckoo hash) */ - emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), - st); + emit_indexed(exec_ctx, c, + dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), st); return; } if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem) && c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (second cuckoo hash) */ - emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), - st); + emit_indexed(exec_ctx, c, + dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), st); return; } } @@ -523,10 +538,10 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, decoder_space_usage < MAX_DECODER_SPACE_USAGE && c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >= c->filter_elems_sum / ONE_ON_ADD_PROBABILITY; - void (*maybe_add)(grpc_chttp2_hpack_compressor*, grpc_mdelem, size_t) = - should_add_elem ? add_elem : add_nothing; - void (*emit)(grpc_chttp2_hpack_compressor*, uint32_t, grpc_mdelem, - framer_state*) = + void (*maybe_add)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, grpc_mdelem, + size_t) = should_add_elem ? add_elem : add_nothing; + void (*emit)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, uint32_t, + grpc_mdelem, framer_state*) = should_add_elem ? emit_lithdr_incidx : emit_lithdr_noidx; /* no hits for the elem... maybe there's a key? */ @@ -535,8 +550,8 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ - emit(c, dynidx(c, indices_key), elem, st); - maybe_add(c, elem, decoder_space_usage); + emit(exec_ctx, c, dynidx(c, indices_key), elem, st); + maybe_add(exec_ctx, c, elem, decoder_space_usage); return; } @@ -545,8 +560,8 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ - emit(c, dynidx(c, indices_key), elem, st); - maybe_add(c, elem, decoder_space_usage); + emit(exec_ctx, c, dynidx(c, indices_key), elem, st); + maybe_add(exec_ctx, c, elem, decoder_space_usage); return; } @@ -557,23 +572,24 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, : emit_lithdr_noidx_v; maybe_add = should_add_elem ? add_elem : (should_add_key ? add_key : add_nothing); - emit(c, 0, elem, st); - maybe_add(c, elem, decoder_space_usage); + emit(exec_ctx, c, 0, elem, st); + maybe_add(exec_ctx, c, elem, decoder_space_usage); } #define STRLEN_LIT(x) (sizeof(x) - 1) #define TIMEOUT_KEY "grpc-timeout" -static void deadline_enc(grpc_chttp2_hpack_compressor* c, grpc_millis deadline, +static void deadline_enc(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_millis deadline, framer_state* st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem mdelem; - grpc_http2_encode_timeout(deadline - grpc_core::ExecCtx::Get()->Now(), + grpc_http2_encode_timeout(deadline - grpc_exec_ctx_now(exec_ctx), timeout_str); - mdelem = grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_TIMEOUT, + mdelem = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, grpc_slice_from_copied_string(timeout_str)); - hpack_enc(c, mdelem, st); - GRPC_MDELEM_UNREF(mdelem); + hpack_enc(exec_ctx, c, mdelem, st); + GRPC_MDELEM_UNREF(exec_ctx, mdelem); } static uint32_t elems_for_bytes(uint32_t bytes) { return (bytes + 31) / 32; } @@ -593,13 +609,14 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { } } -void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor* c) { +void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c) { int i; for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { if (c->entries_keys[i].refcount != &terminal_slice_refcount) { - grpc_slice_unref_internal(c->entries_keys[i]); + grpc_slice_unref_internal(exec_ctx, c->entries_keys[i]); } - GRPC_MDELEM_UNREF(c->entries_elems[i]); + GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); } gpr_free(c->table_elem_size); } @@ -655,7 +672,8 @@ void grpc_chttp2_hpack_compressor_set_max_table_size( } } -void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, +void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem** extra_headers, size_t extra_headers_size, grpc_metadata_batch* metadata, @@ -681,15 +699,15 @@ void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, emit_advertise_table_size_change(c, &st); } for (size_t i = 0; i < extra_headers_size; ++i) { - hpack_enc(c, *extra_headers[i], &st); + hpack_enc(exec_ctx, c, *extra_headers[i], &st); } grpc_metadata_batch_assert_ok(metadata); for (grpc_linked_mdelem* l = metadata->list.head; l; l = l->next) { - hpack_enc(c, l->md, &st); + hpack_enc(exec_ctx, c, l->md, &st); } grpc_millis deadline = metadata->deadline; if (deadline != GRPC_MILLIS_INF_FUTURE) { - deadline_enc(c, deadline, &st); + deadline_enc(exec_ctx, c, deadline, &st); } finish_frame(&st, 1, options->is_eof); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index a26514cab0..08921b19ec 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -70,7 +70,8 @@ typedef struct { } grpc_chttp2_hpack_compressor; void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c); -void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor* c); +void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c); void grpc_chttp2_hpack_compressor_set_max_table_size( grpc_chttp2_hpack_compressor* c, uint32_t max_table_size); void grpc_chttp2_hpack_compressor_set_max_usable_size( @@ -84,7 +85,8 @@ typedef struct { grpc_transport_one_way_stats* stats; } grpc_encode_header_options; -void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, +void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem** extra_headers, size_t extra_headers_size, grpc_metadata_batch* metadata, diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index a395ab234c..18cb27f199 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -61,69 +61,96 @@ typedef enum { a set of indirect jumps, and so not waste stack space. */ /* forward declarations for parsing states */ -static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, grpc_error* error); -static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p, +static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); static grpc_error* parse_value_string_with_indexed_key( - grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); static grpc_error* parse_value_string_with_literal_key( - grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); -static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); /* we translate the first byte of a hpack field into one of these decoding @@ -622,8 +649,8 @@ static const uint8_t inverse_base64[256] = { }; /* emission helpers */ -static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md, - int add_to_table) { +static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, + grpc_mdelem md, int add_to_table) { if (grpc_http_trace.enabled()) { char* k = grpc_slice_to_c_string(GRPC_MDKEY(md)); char* v = nullptr; @@ -644,25 +671,26 @@ static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md, if (add_to_table) { GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); - grpc_error* err = grpc_chttp2_hptbl_add(&p->table, md); + grpc_error* err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; } if (p->on_header == nullptr) { - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); return GRPC_ERROR_CREATE_FROM_STATIC_STRING("on_header callback not set"); } - p->on_header(p->on_header_user_data, md); + p->on_header(exec_ctx, p->on_header_user_data, md); return GRPC_ERROR_NONE; } -static grpc_slice take_string(grpc_chttp2_hpack_parser* p, +static grpc_slice take_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, grpc_chttp2_hpack_parser_string* str, bool intern) { grpc_slice s; if (!str->copied) { if (intern) { s = grpc_slice_intern(str->data.referenced); - grpc_slice_unref_internal(str->data.referenced); + grpc_slice_unref_internal(exec_ctx, str->data.referenced); } else { s = str->data.referenced; } @@ -680,77 +708,85 @@ static grpc_slice take_string(grpc_chttp2_hpack_parser* p, } /* jump to the next state */ -static grpc_error* parse_next(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_next(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { p->state = *p->next_state++; - return p->state(p, cur, end); + return p->state(exec_ctx, p, cur, end); } /* begin parsing a header: all functionality is encoded into lookup tables above */ -static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_begin; return GRPC_ERROR_NONE; } - return first_byte_action[first_byte_lut[*cur]](p, cur, end); + return first_byte_action[first_byte_lut[*cur]](exec_ctx, p, cur, end); } /* stream dependency and prioritization data: we just skip it */ -static grpc_error* parse_stream_weight(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_weight(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_weight; return GRPC_ERROR_NONE; } - return p->after_prioritization(p, cur + 1, end); + return p->after_prioritization(exec_ctx, p, cur + 1, end); } -static grpc_error* parse_stream_dep3(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep3; return GRPC_ERROR_NONE; } - return parse_stream_weight(p, cur + 1, end); + return parse_stream_weight(exec_ctx, p, cur + 1, end); } -static grpc_error* parse_stream_dep2(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep2; return GRPC_ERROR_NONE; } - return parse_stream_dep3(p, cur + 1, end); + return parse_stream_dep3(exec_ctx, p, cur + 1, end); } -static grpc_error* parse_stream_dep1(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep1; return GRPC_ERROR_NONE; } - return parse_stream_dep2(p, cur + 1, end); + return parse_stream_dep2(exec_ctx, p, cur + 1, end); } -static grpc_error* parse_stream_dep0(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep0; return GRPC_ERROR_NONE; } - return parse_stream_dep1(p, cur + 1, end); + return parse_stream_dep1(exec_ctx, p, cur + 1, end); } /* emit an indexed field; jumps to begin the next field on completion */ -static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); @@ -762,22 +798,24 @@ static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); } GRPC_MDELEM_REF(md); - GRPC_STATS_INC_HPACK_RECV_INDEXED(); - grpc_error* err = on_hdr(p, md, 0); + GRPC_STATS_INC_HPACK_RECV_INDEXED(exec_ctx); + grpc_error* err = on_hdr(exec_ctx, p, md, 0); if (err != GRPC_ERROR_NONE) return err; - return parse_begin(p, cur, end); + return parse_begin(exec_ctx, p, cur, end); } /* parse an indexed field with index < 127 */ -static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { p->dynamic_table_update_allowed = 0; p->index = (*cur) & 0x7f; - return finish_indexed_field(p, cur + 1, end); + return finish_indexed_field(exec_ctx, p, cur + 1, end); } /* parse an indexed field with index >= 127 */ -static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -786,52 +824,56 @@ static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p, p->next_state = and_then; p->index = 0x7f; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } /* finish a literal header with incremental indexing */ -static grpc_error* finish_lithdr_incidx(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, true)), - 1); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(exec_ctx, p, &p->value, true)), + 1); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* finish a literal header with incremental indexing with no index */ -static grpc_error* finish_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(take_string(p, &p->key, true), - take_string(p, &p->value, true)), - 1); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, true)), + 1); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* parse a literal header with incremental indexing; index < 63 */ -static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_incidx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0x3f; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* parse a literal header with incremental indexing; index >= 63 */ -static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -841,11 +883,12 @@ static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p, p->next_state = and_then; p->index = 0x3f; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } /* parse a literal header with incremental indexing; index = 0 */ -static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -853,52 +896,56 @@ static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, parse_value_string_with_literal_key, finish_lithdr_incidx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* finish a literal header without incremental indexing */ -static grpc_error* finish_lithdr_notidx(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(exec_ctx, p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* finish a literal header without incremental indexing with index = 0 */ -static grpc_error* finish_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(take_string(p, &p->key, true), - take_string(p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* parse a literal header without incremental indexing; index < 15 */ -static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_notidx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* parse a literal header without incremental indexing; index >= 15 */ -static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -908,11 +955,12 @@ static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p, p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } /* parse a literal header without incremental indexing; index == 0 */ -static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -920,52 +968,56 @@ static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, parse_value_string_with_literal_key, finish_lithdr_notidx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* finish a literal header that is never indexed */ -static grpc_error* finish_lithdr_nvridx(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(exec_ctx, p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* finish a literal header that is never indexed with an extra value */ -static grpc_error* finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(); - grpc_error* err = - on_hdr(p, - grpc_mdelem_from_slices(take_string(p, &p->key, true), - take_string(p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(exec_ctx); + grpc_error* err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* parse a literal header that is never indexed; index < 15 */ -static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_nvridx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* parse a literal header that is never indexed; index >= 15 */ -static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -975,11 +1027,12 @@ static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p, p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } /* parse a literal header that is never indexed; index == 0 */ -static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -987,44 +1040,47 @@ static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, parse_value_string_with_literal_key, finish_lithdr_nvridx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix(exec_ctx, p, cur + 1, end); } /* finish parsing a max table size change */ -static grpc_error* finish_max_tbl_size(grpc_chttp2_hpack_parser* p, +static grpc_error* finish_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (grpc_http_trace.enabled()) { gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); } grpc_error* err = - grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_begin(p, cur, end); + grpc_chttp2_hptbl_set_current_table_size(exec_ctx, &p->table, p->index); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_begin(exec_ctx, p, cur, end); } /* parse a max table size change, max size < 15 */ -static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (p->dynamic_table_update_allowed == 0) { return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "More than two max table size changes in a single frame")); } p->dynamic_table_update_allowed--; p->index = (*cur) & 0x1f; - return finish_max_tbl_size(p, cur + 1, end); + return finish_max_tbl_size(exec_ctx, p, cur + 1, end); } /* parse a max table size change, max size >= 15 */ -static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { finish_max_tbl_size}; if (p->dynamic_table_update_allowed == 0) { return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "More than two max table size changes in a single frame")); } @@ -1032,11 +1088,12 @@ static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p, p->next_state = and_then; p->index = 0x1f; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } /* a parse error: jam the parse state into parse_error, and return error */ -static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, grpc_error* err) { GPR_ASSERT(err != GRPC_ERROR_NONE); if (p->last_error == GRPC_ERROR_NONE) { @@ -1046,24 +1103,27 @@ static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return err; } -static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p, +static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { return GRPC_ERROR_REF(p->last_error); } -static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { GPR_ASSERT(cur != end); char* msg; gpr_asprintf(&msg, "Illegal hpack op code %d", *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(p, cur, end, err); + return parse_error(exec_ctx, p, cur, end, err); } /* parse the 1st byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value0; @@ -1073,15 +1133,16 @@ static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, *p->parsing.value += (*cur) & 0x7f; if ((*cur) & 0x80) { - return parse_value1(p, cur + 1, end); + return parse_value1(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } } /* parse the 2nd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value1; @@ -1091,15 +1152,16 @@ static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 7; if ((*cur) & 0x80) { - return parse_value2(p, cur + 1, end); + return parse_value2(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } } /* parse the 3rd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value2; @@ -1109,15 +1171,16 @@ static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 14; if ((*cur) & 0x80) { - return parse_value3(p, cur + 1, end); + return parse_value3(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } } /* parse the 4th byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value3; @@ -1127,15 +1190,16 @@ static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 21; if ((*cur) & 0x80) { - return parse_value4(p, cur + 1, end); + return parse_value4(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } } /* parse the 5th byte of a varint into p->parsing.value depending on the byte, we may overflow, and care must be taken */ -static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { uint8_t c; uint32_t cur_value; @@ -1161,9 +1225,9 @@ static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, *p->parsing.value = cur_value + add_value; if ((*cur) & 0x80) { - return parse_value5up(p, cur + 1, end); + return parse_value5up(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } error: @@ -1173,13 +1237,14 @@ error: *p->parsing.value, *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(p, cur, end, err); + return parse_error(exec_ctx, p, cur, end, err); } /* parse any trailing bytes in a varint: it's possible to append an arbitrary number of 0x80's and not affect the value - a zero will terminate - and anything else will overflow */ -static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { while (cur != end && *cur == 0x80) { ++cur; @@ -1191,7 +1256,7 @@ static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, } if (*cur == 0) { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } char* msg; @@ -1201,11 +1266,12 @@ static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, *p->parsing.value, *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(p, cur, end, err); + return parse_error(exec_ctx, p, cur, end, err); } /* parse a string prefix */ -static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_string_prefix; @@ -1216,9 +1282,9 @@ static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p, p->huff = (*cur) >> 7; if (p->strlen == 0x7f) { p->parsing.value = &p->strlen; - return parse_value0(p, cur + 1, end); + return parse_value0(exec_ctx, p, cur + 1, end); } else { - return parse_next(p, cur + 1, end); + return parse_next(exec_ctx, p, cur + 1, end); } } @@ -1237,7 +1303,8 @@ static void append_bytes(grpc_chttp2_hpack_parser_string* str, str->data.copied.length += (uint32_t)length; } -static grpc_error* append_string(grpc_chttp2_hpack_parser* p, +static grpc_error* append_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_chttp2_hpack_parser_string* str = p->parsing.str; uint32_t bits; @@ -1255,11 +1322,11 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, /* 'true-binary' case */ ++cur; p->binary = NOT_BINARY; - GRPC_STATS_INC_HPACK_RECV_BINARY(); + GRPC_STATS_INC_HPACK_RECV_BINARY(exec_ctx); append_bytes(str, cur, (size_t)(end - cur)); return GRPC_ERROR_NONE; } - GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(); + GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(exec_ctx); /* fallthrough */ b64_byte0: case B64_BYTE0: @@ -1271,7 +1338,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; if (bits == 255) return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte0; @@ -1287,7 +1354,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; if (bits == 255) return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte1; @@ -1303,7 +1370,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; if (bits == 255) return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte2; @@ -1319,7 +1386,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; if (bits == 255) return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte3; @@ -1332,11 +1399,12 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, goto b64_byte0; } GPR_UNREACHABLE_CODE(return parse_error( - p, cur, end, + exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"))); } -static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { uint8_t decoded[2]; uint32_t bits; @@ -1349,7 +1417,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, case B64_BYTE0: break; case B64_BYTE1: - return parse_error(p, cur, end, + return parse_error(exec_ctx, p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "illegal base64 encoding")); /* illegal encoding */ case B64_BYTE2: @@ -1360,7 +1428,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, bits & 0xffff); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(p, cur, end, err); + return parse_error(exec_ctx, p, cur, end, err); } decoded[0] = (uint8_t)(bits >> 16); append_bytes(str, decoded, 1); @@ -1373,7 +1441,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, bits & 0xff); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(p, cur, end, err); + return parse_error(exec_ctx, p, cur, end, err); } decoded[0] = (uint8_t)(bits >> 16); decoded[1] = (uint8_t)(bits >> 8); @@ -1384,13 +1452,14 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, } /* decode a nibble from a huffman encoded stream */ -static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) { +static grpc_error* huff_nibble(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, uint8_t nibble) { int16_t emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble]; int16_t next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble]; if (emit != -1) { if (emit >= 0 && emit < 256) { uint8_t c = (uint8_t)emit; - grpc_error* err = append_string(p, &c, (&c) + 1); + grpc_error* err = append_string(exec_ctx, p, &c, (&c) + 1); if (err != GRPC_ERROR_NONE) return err; } else { assert(emit == 256); @@ -1401,42 +1470,45 @@ static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) { } /* decode full bytes from a huffman encoded stream */ -static grpc_error* add_huff_bytes(grpc_chttp2_hpack_parser* p, +static grpc_error* add_huff_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { for (; cur != end; ++cur) { - grpc_error* err = huff_nibble(p, *cur >> 4); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - err = huff_nibble(p, *cur & 0xf); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + grpc_error* err = huff_nibble(exec_ctx, p, *cur >> 4); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + err = huff_nibble(exec_ctx, p, *cur & 0xf); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); } return GRPC_ERROR_NONE; } /* decode some string bytes based on the current decoding mode (huffman or not) */ -static grpc_error* add_str_bytes(grpc_chttp2_hpack_parser* p, +static grpc_error* add_str_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (p->huff) { - return add_huff_bytes(p, cur, end); + return add_huff_bytes(exec_ctx, p, cur, end); } else { - return append_string(p, cur, end); + return append_string(exec_ctx, p, cur, end); } } /* parse a string - tries to do large chunks at a time */ -static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { size_t remaining = p->strlen - p->strgot; size_t given = (size_t)(end - cur); if (remaining <= given) { - grpc_error* err = add_str_bytes(p, cur, cur + remaining); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - err = finish_str(p, cur + remaining, end); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_next(p, cur + remaining, end); + grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + remaining); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + err = finish_str(exec_ctx, p, cur + remaining, end); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_next(exec_ctx, p, cur + remaining, end); } else { - grpc_error* err = add_str_bytes(p, cur, cur + given); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + given); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); GPR_ASSERT(given <= UINT32_MAX - p->strgot); p->strgot += (uint32_t)given; p->state = parse_string; @@ -1445,19 +1517,20 @@ static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, } /* begin parsing a string - performs setup, calls parse_string */ -static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, +static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && p->current_slice_refcount != nullptr) { - GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); + GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; str->data.referenced.data.refcounted.bytes = (uint8_t*)cur; str->data.referenced.data.refcounted.length = p->strlen; grpc_slice_ref_internal(str->data.referenced); - return parse_next(p, cur + p->strlen, end); + return parse_next(exec_ctx, p, cur + p->strlen, end); } p->strgot = 0; str->copied = true; @@ -1468,9 +1541,9 @@ static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, switch (p->binary) { case NOT_BINARY: if (p->huff) { - GRPC_STATS_INC_HPACK_RECV_HUFFMAN(); + GRPC_STATS_INC_HPACK_RECV_HUFFMAN(exec_ctx); } else { - GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); + GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); } break; case BINARY_BEGIN: @@ -1479,13 +1552,14 @@ static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, default: abort(); } - return parse_string(p, cur, end); + return parse_string(exec_ctx, p, cur, end); } /* parse the key string */ -static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - return begin_parse_string(p, cur, end, NOT_BINARY, &p->key); + return begin_parse_string(exec_ctx, p, cur, end, NOT_BINARY, &p->key); } /* check if a key represents a binary header or not */ @@ -1512,29 +1586,33 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, } /* parse the value string */ -static grpc_error* parse_value_string(grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, bool is_binary) { - return begin_parse_string(p, cur, end, is_binary ? BINARY_BEGIN : NOT_BINARY, - &p->value); + return begin_parse_string(exec_ctx, p, cur, end, + is_binary ? BINARY_BEGIN : NOT_BINARY, &p->value); } static grpc_error* parse_value_string_with_indexed_key( - grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { bool is_binary = false; grpc_error* err = is_binary_indexed_header(p, &is_binary); - if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); - return parse_value_string(p, cur, end, is_binary); + if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + return parse_value_string(exec_ctx, p, cur, end, is_binary); } static grpc_error* parse_value_string_with_literal_key( - grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - return parse_value_string(p, cur, end, is_binary_literal_header(p)); + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { + return parse_value_string(exec_ctx, p, cur, end, is_binary_literal_header(p)); } /* PUBLIC INTERFACE */ -void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p) { +void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p) { p->on_header = nullptr; p->on_header_user_data = nullptr; p->state = parse_begin; @@ -1548,7 +1626,7 @@ void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p) { p->value.data.copied.length = 0; p->dynamic_table_update_allowed = 2; p->last_error = GRPC_ERROR_NONE; - grpc_chttp2_hptbl_init(&p->table); + grpc_chttp2_hptbl_init(exec_ctx, &p->table); } void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) { @@ -1556,16 +1634,18 @@ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) { p->state = parse_stream_dep0; } -void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser* p) { - grpc_chttp2_hptbl_destroy(&p->table); +void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p) { + grpc_chttp2_hptbl_destroy(exec_ctx, &p->table); GRPC_ERROR_UNREF(p->last_error); - grpc_slice_unref_internal(p->key.data.referenced); - grpc_slice_unref_internal(p->value.data.referenced); + grpc_slice_unref_internal(exec_ctx, p->key.data.referenced); + grpc_slice_unref_internal(exec_ctx, p->value.data.referenced); gpr_free(p->key.data.copied.str); gpr_free(p->value.data.copied.str); } -grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, grpc_slice slice) { /* max number of bytes to parse at a time... limits call stack depth on * compilers without TCO */ @@ -1576,33 +1656,37 @@ grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p, grpc_error* error = GRPC_ERROR_NONE; while (start != end && error == GRPC_ERROR_NONE) { uint8_t* target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start); - error = p->state(p, start, target); + error = p->state(exec_ctx, p, start, target); start = target; } p->current_slice_refcount = nullptr; return error; } -typedef void (*maybe_complete_func_type)(grpc_chttp2_transport* t, +typedef void (*maybe_complete_func_type)(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); static const maybe_complete_func_type maybe_complete_funcs[] = { grpc_chttp2_maybe_complete_recv_initial_metadata, grpc_chttp2_maybe_complete_recv_trailing_metadata}; -static void force_client_rst_stream(void* sp, grpc_error* error) { +static void force_client_rst_stream(grpc_exec_ctx* exec_ctx, void* sp, + grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; grpc_chttp2_transport* t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); - grpc_chttp2_mark_stream_closed(t, s, true, true, GRPC_ERROR_NONE); + grpc_chttp2_initiate_write(exec_ctx, t, + GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, GRPC_ERROR_NONE); } - GRPC_CHTTP2_STREAM_UNREF(s, "final_rst"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "final_rst"); } -static void parse_stream_compression_md(grpc_chttp2_transport* t, +static void parse_stream_compression_md(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_metadata_batch* initial_metadata) { if (initial_metadata->idx.named.content_encoding == nullptr || @@ -1614,7 +1698,8 @@ static void parse_stream_compression_md(grpc_chttp2_transport* t, } } -grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, +grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, + void* hpack_parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -1623,7 +1708,7 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error* error = grpc_chttp2_hpack_parser_parse(parser, slice); + grpc_error* error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; @@ -1646,11 +1731,12 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, /* Process stream compression md element if it exists */ if (s->header_frames_received == 0) { /* Only acts on initial metadata */ - parse_stream_compression_md(t, s, &s->metadata_buffer[0].batch); + parse_stream_compression_md(exec_ctx, t, s, + &s->metadata_buffer[0].batch); } s->published_metadata[s->header_frames_received] = GRPC_METADATA_PUBLISHED_FROM_WIRE; - maybe_complete_funcs[s->header_frames_received](t, s); + maybe_complete_funcs[s->header_frames_received](exec_ctx, t, s); s->header_frames_received++; } if (parser->is_eof) { @@ -1661,11 +1747,13 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, and can avoid the extra write */ GRPC_CHTTP2_STREAM_REF(s, "final_rst"); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(force_client_rst_stream, s, grpc_combiner_finally_scheduler(t->combiner)), GRPC_ERROR_NONE); } - grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, + GRPC_ERROR_NONE); } } parser->on_header = nullptr; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 060bc5ce9d..b4a2b14bdb 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -30,7 +30,8 @@ typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser; typedef grpc_error* (*grpc_chttp2_hpack_parser_state)( - grpc_chttp2_hpack_parser* p, const uint8_t* beg, const uint8_t* end); + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* beg, + const uint8_t* end); typedef struct { bool copied; @@ -46,7 +47,7 @@ typedef struct { struct grpc_chttp2_hpack_parser { /* user specified callback for each header output */ - void (*on_header)(void* user_data, grpc_mdelem md); + void (*on_header)(grpc_exec_ctx* exec_ctx, void* user_data, grpc_mdelem md); void* on_header_user_data; grpc_error* last_error; @@ -91,17 +92,21 @@ struct grpc_chttp2_hpack_parser { grpc_chttp2_hptbl table; }; -void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p); -void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser* p); +void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p); +void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p); void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p); -grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, grpc_slice slice); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ -grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, +grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, + void* hpack_parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index c325465daa..75b83b80b6 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -165,7 +165,7 @@ static uint32_t entries_for_bytes(uint32_t bytes) { GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; } -void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { +void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { size_t i; memset(tbl, 0, sizeof(*tbl)); @@ -177,19 +177,22 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { tbl->static_ents[i - 1] = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(static_table[i].key)), grpc_slice_intern( grpc_slice_from_static_string(static_table[i].value))); } } -void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl* tbl) { +void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl) { size_t i; for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - GRPC_MDELEM_UNREF(tbl->static_ents[i]); + GRPC_MDELEM_UNREF(exec_ctx, tbl->static_ents[i]); } for (i = 0; i < tbl->num_ents; i++) { - GRPC_MDELEM_UNREF(tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]); + GRPC_MDELEM_UNREF(exec_ctx, + tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]); } gpr_free(tbl->ents); } @@ -212,7 +215,7 @@ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, } /* Evict one element from the table */ -static void evict1(grpc_chttp2_hptbl* tbl) { +static void evict1(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { grpc_mdelem first_ent = tbl->ents[tbl->first_ent]; size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(first_ent)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + @@ -221,7 +224,7 @@ static void evict1(grpc_chttp2_hptbl* tbl) { tbl->mem_used -= (uint32_t)elem_bytes; tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries); tbl->num_ents--; - GRPC_MDELEM_UNREF(first_ent); + GRPC_MDELEM_UNREF(exec_ctx, first_ent); } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { @@ -237,7 +240,8 @@ static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { tbl->first_ent = 0; } -void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl* tbl, +void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t max_bytes) { if (tbl->max_bytes == max_bytes) { return; @@ -246,12 +250,13 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl* tbl, gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes); } while (tbl->mem_used > max_bytes) { - evict1(tbl); + evict1(exec_ctx, tbl); } tbl->max_bytes = max_bytes; } -grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t bytes) { if (tbl->current_table_bytes == bytes) { return GRPC_ERROR_NONE; @@ -269,7 +274,7 @@ grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes); } while (tbl->mem_used > bytes) { - evict1(tbl); + evict1(exec_ctx, tbl); } tbl->current_table_bytes = bytes; tbl->max_entries = entries_for_bytes(bytes); @@ -284,7 +289,8 @@ grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { +grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, grpc_mdelem md) { /* determine how many bytes of buffer this entry represents */ size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(md)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(md)) + @@ -314,14 +320,14 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { * empty table. */ while (tbl->num_ents) { - evict1(tbl); + evict1(exec_ctx, tbl); } return GRPC_ERROR_NONE; } /* evict entries to ensure no overflow */ while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) { - evict1(tbl); + evict1(exec_ctx, tbl); } /* copy the finalized entry in */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index 189ad1c697..aed7b13f0b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -69,18 +69,21 @@ typedef struct { } grpc_chttp2_hptbl; /* initialize a hpack table */ -void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl); -void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl* tbl); -void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl* tbl, +void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t max_bytes); -grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t bytes); /* lookup a table entry based on its hpack index */ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, uint32_t index); /* add a table entry to the index */ -grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, grpc_mdelem md) GRPC_MUST_USE_RESULT; /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index ef0c9ed230..4461f8c12c 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -33,31 +33,33 @@ void grpc_chttp2_incoming_metadata_buffer_init( } void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_chttp2_incoming_metadata_buffer* buffer) { - grpc_metadata_batch_destroy(&buffer->batch); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer) { + grpc_metadata_batch_destroy(exec_ctx, &buffer->batch); } grpc_error* grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_mdelem elem) { buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( - &buffer->batch, + exec_ctx, &buffer->batch, (grpc_linked_mdelem*)gpr_arena_alloc(buffer->arena, sizeof(grpc_linked_mdelem)), elem); } grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_mdelem elem) { for (grpc_linked_mdelem* l = buffer->batch.list.head; l != nullptr; l = l->next) { if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) { - GRPC_MDELEM_UNREF(l->md); + GRPC_MDELEM_UNREF(exec_ctx, l->md); l->md = elem; return GRPC_ERROR_NONE; } } - return grpc_chttp2_incoming_metadata_buffer_add(buffer, elem); + return grpc_chttp2_incoming_metadata_buffer_add(exec_ctx, buffer, elem); } void grpc_chttp2_incoming_metadata_buffer_set_deadline( @@ -66,7 +68,8 @@ void grpc_chttp2_incoming_metadata_buffer_set_deadline( } void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_metadata_batch* batch) { *batch = buffer->batch; grpc_metadata_batch_init(&buffer->batch); } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index b84cd484c4..6f2b81ef6c 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -31,15 +31,16 @@ typedef struct { void grpc_chttp2_incoming_metadata_buffer_init( grpc_chttp2_incoming_metadata_buffer* buffer, gpr_arena* arena); void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_chttp2_incoming_metadata_buffer* buffer); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer); void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_metadata_batch* batch); grpc_error* grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 932f5ba83d..f6fd6795d0 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -282,8 +282,8 @@ struct grpc_chttp2_transport { struct { /* accept stream callback */ - void (*accept_stream)(void* user_data, grpc_transport* transport, - const void* server_data); + void (*accept_stream)(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_transport* transport, const void* server_data); void* accept_stream_user_data; /** connectivity tracking */ @@ -371,8 +371,9 @@ struct grpc_chttp2_transport { /* active parser */ void* parser_data; grpc_chttp2_stream* incoming_stream; - grpc_error* (*parser)(void* parser_user_data, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_slice slice, int is_last); + grpc_error* (*parser)(grpc_exec_ctx* exec_ctx, void* parser_user_data, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_slice slice, int is_last); grpc_chttp2_write_cb* write_cb_pool; @@ -570,7 +571,8 @@ struct grpc_chttp2_stream { The actual call chain is documented in the implementation of this function. */ -void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, +void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason); typedef struct { @@ -583,12 +585,14 @@ typedef struct { } grpc_chttp2_begin_write_result; grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_chttp2_transport* t); -void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t); +void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); /** Process one slice of incoming data; return 1 if the connection is still viable after reading, or 0 if the connection should be torn down */ -grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice); bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t, @@ -636,23 +640,27 @@ bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport* t, // Takes in a flow control action and performs all the needed operations. void grpc_chttp2_act_on_flowctl_action( - const grpc_core::chttp2::FlowControlAction& action, + grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, grpc_chttp2_transport* t, grpc_chttp2_stream* s); /********* End of Flow Control ***************/ grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id); -grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t id); -void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, +void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text); -void grpc_chttp2_parsing_become_skip_parser(grpc_chttp2_transport* t); +void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); -void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, +void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_closure** pclosure, grpc_error* error, const char* desc); @@ -673,80 +681,94 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, else \ stmt -void grpc_chttp2_fake_status(grpc_chttp2_transport* t, +void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* stream, grpc_error* error); -void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error); -void grpc_chttp2_start_writing(grpc_chttp2_transport* t); +void grpc_chttp2_start_writing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); #ifndef NDEBUG #define GRPC_CHTTP2_STREAM_REF(stream, reason) \ grpc_chttp2_stream_ref(stream, reason) -#define GRPC_CHTTP2_STREAM_UNREF(stream, reason) \ - grpc_chttp2_stream_unref(stream, reason) +#define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ + grpc_chttp2_stream_unref(exec_ctx, stream, reason) void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason); -void grpc_chttp2_stream_unref(grpc_chttp2_stream* s, const char* reason); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, + const char* reason); #else #define GRPC_CHTTP2_STREAM_REF(stream, reason) grpc_chttp2_stream_ref(stream) -#define GRPC_CHTTP2_STREAM_UNREF(stream, reason) \ - grpc_chttp2_stream_unref(stream) +#define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ + grpc_chttp2_stream_unref(exec_ctx, stream) void grpc_chttp2_stream_ref(grpc_chttp2_stream* s); -void grpc_chttp2_stream_unref(grpc_chttp2_stream* s); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s); #endif #ifndef NDEBUG #define GRPC_CHTTP2_REF_TRANSPORT(t, r) \ grpc_chttp2_ref_transport(t, r, __FILE__, __LINE__) -#define GRPC_CHTTP2_UNREF_TRANSPORT(t, r) \ - grpc_chttp2_unref_transport(t, r, __FILE__, __LINE__) -void grpc_chttp2_unref_transport(grpc_chttp2_transport* t, const char* reason, +#define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) \ + grpc_chttp2_unref_transport(cl, t, r, __FILE__, __LINE__) +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, const char* reason, const char* file, int line); void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, const char* file, int line); #else #define GRPC_CHTTP2_REF_TRANSPORT(t, r) grpc_chttp2_ref_transport(t) -#define GRPC_CHTTP2_UNREF_TRANSPORT(t, r) grpc_chttp2_unref_transport(t) -void grpc_chttp2_unref_transport(grpc_chttp2_transport* t); +#define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) grpc_chttp2_unref_transport(cl, t) +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); void grpc_chttp2_ref_transport(grpc_chttp2_transport* t); #endif grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( - grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, - uint32_t flags); + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, + uint32_t frame_size, uint32_t flags); grpc_error* grpc_chttp2_incoming_byte_stream_push( - grpc_chttp2_incoming_byte_stream* bs, grpc_slice slice, - grpc_slice* slice_out); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_slice slice, grpc_slice* slice_out); grpc_error* grpc_chttp2_incoming_byte_stream_finished( - grpc_chttp2_incoming_byte_stream* bs, grpc_error* error, - bool reset_on_error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error, bool reset_on_error); void grpc_chttp2_incoming_byte_stream_notify( - grpc_chttp2_incoming_byte_stream* bs, grpc_error* error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error); -void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id); +void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + uint64_t id); /** Add a new ping strike to ping_recv_state.ping_strikes. If ping_recv_state.ping_strikes > ping_policy.max_ping_strikes, it sends GOAWAY with error code ENHANCE_YOUR_CALM and additional debug data resembling "too_many_pings" followed by immediately closing the connection. */ -void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t); +void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); /** add a ref to the stream and add it to the writable list; ref will be dropped in writing.c */ -void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, +void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* due_to_error); -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_fail_pending_writes(grpc_chttp2_transport* t, +void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error); /** Set the default keepalive configurations, must only be called at diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index a56f89cc75..46ec3fbaa6 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -31,22 +31,33 @@ #include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" -static grpc_error* init_frame_parser(grpc_chttp2_transport* t); -static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, +static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_continuation); -static grpc_error* init_data_frame_parser(grpc_chttp2_transport* t); -static grpc_error* init_rst_stream_parser(grpc_chttp2_transport* t); -static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t); -static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t); -static grpc_error* init_ping_parser(grpc_chttp2_transport* t); -static grpc_error* init_goaway_parser(grpc_chttp2_transport* t); -static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, +static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_header); -static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice, int is_last); -grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice) { uint8_t* beg = GRPC_SLICE_START_PTR(slice); uint8_t* end = GRPC_SLICE_END_PTR(slice); @@ -171,12 +182,12 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, GPR_ASSERT(cur < end); t->incoming_stream_id |= ((uint32_t)*cur); t->deframe_state = GRPC_DTS_FRAME; - err = init_frame_parser(t); + err = init_frame_parser(exec_ctx, t); if (err != GRPC_ERROR_NONE) { return err; } if (t->incoming_frame_size == 0) { - err = parse_frame_slice(t, grpc_empty_slice(), 1); + err = parse_frame_slice(exec_ctx, t, grpc_empty_slice(), 1); if (err != GRPC_ERROR_NONE) { return err; } @@ -206,7 +217,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, GPR_ASSERT(cur < end); if ((uint32_t)(end - cur) == t->incoming_frame_size) { err = - parse_frame_slice(t, + parse_frame_slice(exec_ctx, t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), (size_t)(end - beg)), 1); @@ -219,7 +230,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { size_t cur_offset = (size_t)(cur - beg); err = parse_frame_slice( - t, + exec_ctx, t, grpc_slice_sub_no_ref(slice, cur_offset, cur_offset + t->incoming_frame_size), 1); @@ -231,7 +242,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, goto dts_fh_0; /* loop */ } else { err = - parse_frame_slice(t, + parse_frame_slice(exec_ctx, t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), (size_t)(end - beg)), 0); @@ -247,7 +258,8 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, GPR_UNREACHABLE_CODE(return nullptr); } -static grpc_error* init_frame_parser(grpc_chttp2_transport* t) { +static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (t->is_first_frame && t->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) { char* msg; @@ -279,43 +291,46 @@ static grpc_error* init_frame_parser(grpc_chttp2_transport* t) { gpr_free(msg); return err; } - return init_header_frame_parser(t, 1); + return init_header_frame_parser(exec_ctx, t, 1); } switch (t->incoming_frame_type) { case GRPC_CHTTP2_FRAME_DATA: - return init_data_frame_parser(t); + return init_data_frame_parser(exec_ctx, t); case GRPC_CHTTP2_FRAME_HEADER: - return init_header_frame_parser(t, 0); + return init_header_frame_parser(exec_ctx, t, 0); case GRPC_CHTTP2_FRAME_CONTINUATION: return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Unexpected CONTINUATION frame"); case GRPC_CHTTP2_FRAME_RST_STREAM: - return init_rst_stream_parser(t); + return init_rst_stream_parser(exec_ctx, t); case GRPC_CHTTP2_FRAME_SETTINGS: - return init_settings_frame_parser(t); + return init_settings_frame_parser(exec_ctx, t); case GRPC_CHTTP2_FRAME_WINDOW_UPDATE: - return init_window_update_frame_parser(t); + return init_window_update_frame_parser(exec_ctx, t); case GRPC_CHTTP2_FRAME_PING: - return init_ping_parser(t); + return init_ping_parser(exec_ctx, t); case GRPC_CHTTP2_FRAME_GOAWAY: - return init_goaway_parser(t); + return init_goaway_parser(exec_ctx, t); default: if (grpc_http_trace.enabled()) { gpr_log(GPR_ERROR, "Unknown frame type %02x", t->incoming_frame_type); } - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } } -static grpc_error* skip_parser(void* parser, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_slice slice, - int is_last) { +static grpc_error* skip_parser(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_slice slice, int is_last) { return GRPC_ERROR_NONE; } -static void skip_header(void* tp, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } +static void skip_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_mdelem md) { + GRPC_MDELEM_UNREF(exec_ctx, md); +} -static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, +static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_header) { if (is_header) { uint8_t is_eoh = t->expect_continuation_stream_id != 0; @@ -331,11 +346,14 @@ static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, return GRPC_ERROR_NONE; } -void grpc_chttp2_parsing_become_skip_parser(grpc_chttp2_transport* t) { - init_skip_frame_parser(t, t->parser == grpc_chttp2_header_parser_parse); +void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + init_skip_frame_parser(exec_ctx, t, + t->parser == grpc_chttp2_header_parser_parse); } -static grpc_error* init_data_frame_parser(grpc_chttp2_transport* t) { +static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_chttp2_stream* s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); grpc_error* err = GRPC_ERROR_NONE; @@ -347,17 +365,17 @@ static grpc_error* init_data_frame_parser(grpc_chttp2_transport* t) { err = s->flow_control->RecvData(t->incoming_frame_size); action = s->flow_control->MakeAction(); } - grpc_chttp2_act_on_flowctl_action(action, t, s); + grpc_chttp2_act_on_flowctl_action(exec_ctx, action, t, s); if (err != GRPC_ERROR_NONE) { goto error_handler; } if (s == nullptr) { - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } s->received_bytes += t->incoming_frame_size; s->stats.incoming.framing_bytes += 9; if (err == GRPC_ERROR_NONE && s->read_closed) { - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } if (err == GRPC_ERROR_NONE) { err = grpc_chttp2_data_parser_begin_frame( @@ -376,13 +394,13 @@ error_handler: } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { /* handle stream errors by closing the stream */ if (s != nullptr) { - grpc_chttp2_mark_stream_closed(t, s, true, false, err); + grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, err); } grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, GRPC_HTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } else { return err; } @@ -390,7 +408,8 @@ error_handler: static void free_timeout(void* p) { gpr_free(p); } -static void on_initial_header(void* tp, grpc_mdelem md) { +static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, + grpc_mdelem md) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; grpc_chttp2_stream* s = t->incoming_stream; @@ -436,9 +455,9 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (timeout != GRPC_MILLIS_INF_FUTURE) { grpc_chttp2_incoming_metadata_buffer_set_deadline( - &s->metadata_buffer[0], grpc_core::ExecCtx::Get()->Now() + timeout); + &s->metadata_buffer[0], grpc_exec_ctx_now(exec_ctx) + timeout); } - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } else { const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md); const size_t metadata_size_limit = @@ -450,22 +469,22 @@ static void on_initial_header(void* tp, grpc_mdelem md) { " vs. %" PRIuPTR ")", new_size, metadata_size_limit); grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "received initial metadata size exceeds limit"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); s->seen_error = true; - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } else { - grpc_error* error = - grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[0], md); + grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( + exec_ctx, &s->metadata_buffer[0], md); if (error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(t, s, error); - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_cancel_stream(exec_ctx, t, s, error); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); s->seen_error = true; - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } } } @@ -473,7 +492,8 @@ static void on_initial_header(void* tp, grpc_mdelem md) { GPR_TIMER_END("on_initial_header", 0); } -static void on_trailing_header(void* tp, grpc_mdelem md) { +static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, + grpc_mdelem md) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; grpc_chttp2_stream* s = t->incoming_stream; @@ -507,29 +527,30 @@ static void on_trailing_header(void* tp, grpc_mdelem md) { " vs. %" PRIuPTR ")", new_size, metadata_size_limit); grpc_chttp2_cancel_stream( - t, s, + exec_ctx, t, s, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "received trailing metadata size exceeds limit"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); s->seen_error = true; - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } else { - grpc_error* error = - grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[1], md); + grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( + exec_ctx, &s->metadata_buffer[1], md); if (error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(t, s, error); - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_cancel_stream(exec_ctx, t, s, error); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); s->seen_error = true; - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } } GPR_TIMER_END("on_trailing_header", 0); } -static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, +static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_continuation) { uint8_t is_eoh = (t->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; @@ -559,7 +580,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream disbanded before CONTINUATION received")); - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } if (t->is_client) { if ((t->incoming_stream_id & 1) && @@ -569,7 +590,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "ignoring new grpc_chttp2_stream creation on client")); } - grpc_error* err = init_skip_frame_parser(t, 1); + grpc_error* err = init_skip_frame_parser(exec_ctx, t, 1); if (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY) { grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser); } @@ -581,13 +602,13 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, "last grpc_chttp2_stream " "id=%d, new grpc_chttp2_stream id=%d", t->last_new_stream_id, t->incoming_stream_id)); - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } else if ((t->incoming_stream_id & 1) == 0) { GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "ignoring grpc_chttp2_stream with non-client generated index %d", t->incoming_stream_id)); - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } else if (grpc_chttp2_stream_map_size(&t->stream_map) >= t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]) { @@ -595,11 +616,11 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, } t->last_new_stream_id = t->incoming_stream_id; s = t->incoming_stream = - grpc_chttp2_parsing_accept_stream(t, t->incoming_stream_id); + grpc_chttp2_parsing_accept_stream(exec_ctx, t, t->incoming_stream_id); if (s == nullptr) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted")); - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } } else { t->incoming_stream = s; @@ -610,7 +631,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "skipping already closed grpc_chttp2_stream header")); t->incoming_stream = nullptr; - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } t->parser = grpc_chttp2_header_parser_parse; t->parser_data = &t->hpack_parser; @@ -635,7 +656,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, break; case 2: gpr_log(GPR_ERROR, "too many header frames received"); - return init_skip_frame_parser(t, 1); + return init_skip_frame_parser(exec_ctx, t, 1); } t->hpack_parser.on_header_user_data = t; t->hpack_parser.is_boundary = is_eoh; @@ -647,7 +668,8 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, return GRPC_ERROR_NONE; } -static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t) { +static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_window_update_parser_begin_frame( &t->simple.window_update, t->incoming_frame_size, t->incoming_frame_flags); @@ -656,7 +678,7 @@ static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t) { grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (s == nullptr) { - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } s->stats.incoming.framing_bytes += 9; } @@ -665,7 +687,8 @@ static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t) { return GRPC_ERROR_NONE; } -static grpc_error* init_ping_parser(grpc_chttp2_transport* t) { +static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_ping_parser_begin_frame( &t->simple.ping, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; @@ -674,14 +697,15 @@ static grpc_error* init_ping_parser(grpc_chttp2_transport* t) { return GRPC_ERROR_NONE; } -static grpc_error* init_rst_stream_parser(grpc_chttp2_transport* t) { +static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_rst_stream_parser_begin_frame( &t->simple.rst_stream, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (!t->incoming_stream) { - return init_skip_frame_parser(t, 0); + return init_skip_frame_parser(exec_ctx, t, 0); } s->stats.incoming.framing_bytes += 9; t->parser = grpc_chttp2_rst_stream_parser_parse; @@ -689,7 +713,8 @@ static grpc_error* init_rst_stream_parser(grpc_chttp2_transport* t) { return GRPC_ERROR_NONE; } -static grpc_error* init_goaway_parser(grpc_chttp2_transport* t) { +static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_goaway_parser_begin_frame( &t->goaway_parser, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; @@ -698,7 +723,8 @@ static grpc_error* init_goaway_parser(grpc_chttp2_transport* t) { return GRPC_ERROR_NONE; } -static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t) { +static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (t->incoming_stream_id != 0) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Settings frame received for grpc_chttp2_stream"); @@ -714,7 +740,7 @@ static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t) { memcpy(t->settings[GRPC_ACKED_SETTINGS], t->settings[GRPC_SENT_SETTINGS], GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); grpc_chttp2_hptbl_set_max_bytes( - &t->hpack_parser.table, + exec_ctx, &t->hpack_parser.table, t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]); t->sent_local_settings = 0; @@ -724,10 +750,11 @@ static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t) { return GRPC_ERROR_NONE; } -static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice, int is_last) { grpc_chttp2_stream* s = t->incoming_stream; - grpc_error* err = t->parser(t->parser_data, t, s, slice, is_last); + grpc_error* err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); if (err == GRPC_ERROR_NONE) { return err; } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { @@ -735,7 +762,7 @@ static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice, const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); } - grpc_chttp2_parsing_become_skip_parser(t); + grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); if (s) { s->forced_close_error = err; grpc_slice_buffer_add( diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 3310f35f5f..204b5a7708 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -33,15 +33,17 @@ static void add_to_write_list(grpc_chttp2_write_cb** list, *list = cb; } -static void finish_write_cb(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_chttp2_write_cb* cb, grpc_error* error) { - grpc_chttp2_complete_closure_step(t, s, &cb->closure, error, +static void finish_write_cb(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_write_cb* cb, + grpc_error* error) { + grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, error, "finish_write_cb"); cb->next = t->write_cb_pool; t->write_cb_pool = cb; } -static void maybe_initiate_ping(grpc_chttp2_transport* t) { +static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_chttp2_ping_queue* pq = &t->ping_queue; if (grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { /* no ping needed: wait */ @@ -66,7 +68,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { } return; } - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); grpc_millis next_allowed_ping = t->ping_state.last_ping_sent_time + t->ping_policy.min_sent_ping_interval_without_data; @@ -87,20 +89,20 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { } if (!t->ping_state.is_delayed_ping_timer_set) { t->ping_state.is_delayed_ping_timer_set = true; - grpc_timer_init(&t->ping_state.delayed_ping_timer, next_allowed_ping, - &t->retry_initiate_ping_locked); + grpc_timer_init(exec_ctx, &t->ping_state.delayed_ping_timer, + next_allowed_ping, &t->retry_initiate_ping_locked); } return; } pq->inflight_id = t->ping_ctr; t->ping_ctr++; - GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INITIATE]); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INITIATE]); grpc_closure_list_move(&pq->lists[GRPC_CHTTP2_PCL_NEXT], &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); grpc_slice_buffer_add(&t->outbuf, grpc_chttp2_ping_create(false, pq->inflight_id)); - GRPC_STATS_INC_HTTP2_PINGS_SENT(); + GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx); t->ping_state.last_ping_sent_time = now; if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping sent [%p]: %d/%d", @@ -112,9 +114,10 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { (t->ping_state.pings_before_data_required != 0); } -static bool update_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, - int64_t send_bytes, grpc_chttp2_write_cb** list, - int64_t* ctr, grpc_error* error) { +static bool update_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, int64_t send_bytes, + grpc_chttp2_write_cb** list, int64_t* ctr, + grpc_error* error) { bool sched_any = false; grpc_chttp2_write_cb* cb = *list; *list = nullptr; @@ -123,7 +126,7 @@ static bool update_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_chttp2_write_cb* next = cb->next; if (cb->call_at_byte <= *ctr) { sched_any = true; - finish_write_cb(t, s, cb, GRPC_ERROR_REF(error)); + finish_write_cb(exec_ctx, t, s, cb, GRPC_ERROR_REF(error)); } else { add_to_write_list(list, cb); } @@ -176,22 +179,22 @@ class StreamWriteContext; class WriteContext { public: - WriteContext(grpc_chttp2_transport* t) : t_(t) { - GRPC_STATS_INC_HTTP2_WRITES_BEGUN(); + WriteContext(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) : t_(t) { + GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx); GPR_TIMER_BEGIN("grpc_chttp2_begin_write", 0); } // TODO(ctiller): make this the destructor - void FlushStats() { + void FlushStats(grpc_exec_ctx* exec_ctx) { GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE( - initial_metadata_writes_); - GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(message_writes_); + exec_ctx, initial_metadata_writes_); + GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(exec_ctx, message_writes_); GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE( - trailing_metadata_writes_); - GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(flow_control_writes_); + exec_ctx, trailing_metadata_writes_); + GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(exec_ctx, flow_control_writes_); } - void FlushSettings() { + void FlushSettings(grpc_exec_ctx* exec_ctx) { if (t_->dirtied_local_settings && !t_->sent_local_settings) { grpc_slice_buffer_add( &t_->outbuf, grpc_chttp2_settings_create( @@ -201,17 +204,17 @@ class WriteContext { t_->force_send_settings = false; t_->dirtied_local_settings = false; t_->sent_local_settings = true; - GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(); + GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(exec_ctx); } } - void FlushQueuedBuffers() { + void FlushQueuedBuffers(grpc_exec_ctx* exec_ctx) { /* simple writes are queued to qbuf, and flushed here */ grpc_slice_buffer_move_into(&t_->qbuf, &t_->outbuf); GPR_ASSERT(t_->qbuf.count == 0); } - void FlushWindowUpdates() { + void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { uint32_t transport_announce = t_->flow_control->MaybeSendUpdate(t_->outbuf.count > 0); if (transport_announce) { @@ -231,7 +234,7 @@ class WriteContext { t_->ping_ack_count = 0; } - void EnactHpackSettings() { + void EnactHpackSettings(grpc_exec_ctx* exec_ctx) { grpc_chttp2_hpack_compressor_set_max_table_size( &t_->hpack_compressor, t_->settings[GRPC_PEER_SETTINGS] @@ -371,8 +374,8 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } - void CallCallbacks() { - if (update_list(t_, s_, + void CallCallbacks(grpc_exec_ctx* exec_ctx) { + if (update_list(exec_ctx, t_, s_, (int64_t)(s_->sending_bytes - sending_bytes_before_), &s_->on_flow_controlled_cbs, &s_->flow_controlled_bytes_flowed, GRPC_ERROR_NONE)) { @@ -400,7 +403,7 @@ class StreamWriteContext { s->flow_control->announced_window_delta()))); } - void FlushInitialMetadata() { + void FlushInitialMetadata(grpc_exec_ctx* exec_ctx) { /* send initial metadata if it's available */ if (s_->sent_initial_metadata) return; if (s_->send_initial_metadata == nullptr) return; @@ -427,7 +430,7 @@ class StreamWriteContext { [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], // max_frame_size &s_->stats.outgoing // stats }; - grpc_chttp2_encode_header(&t_->hpack_compressor, nullptr, 0, + grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, nullptr, 0, s_->send_initial_metadata, &hopt, &t_->outbuf); write_context_->ResetPingRecvClock(); write_context_->IncInitialMetadataWrites(); @@ -437,11 +440,11 @@ class StreamWriteContext { s_->sent_initial_metadata = true; write_context_->NoteScheduledResults(); grpc_chttp2_complete_closure_step( - t_, s_, &s_->send_initial_metadata_finished, GRPC_ERROR_NONE, + exec_ctx, t_, s_, &s_->send_initial_metadata_finished, GRPC_ERROR_NONE, "send_initial_metadata_finished"); } - void FlushWindowUpdates() { + void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { /* send any window updates */ const uint32_t stream_announce = s_->flow_control->MaybeSendUpdate(); if (stream_announce == 0) return; @@ -453,7 +456,7 @@ class StreamWriteContext { write_context_->IncWindowUpdateWrites(); } - void FlushData() { + void FlushData(grpc_exec_ctx* exec_ctx) { if (!s_->sent_initial_metadata) return; if (s_->flow_controlled_buffer.length == 0 && @@ -485,9 +488,9 @@ class StreamWriteContext { } write_context_->ResetPingRecvClock(); if (data_send_context.is_last_frame()) { - SentLastFrame(); + SentLastFrame(exec_ctx); } - data_send_context.CallCallbacks(); + data_send_context.CallCallbacks(exec_ctx); stream_became_writable_ = true; if (s_->flow_controlled_buffer.length > 0 || s_->compressed_data_buffer.length > 0) { @@ -497,7 +500,7 @@ class StreamWriteContext { write_context_->IncMessageWrites(); } - void FlushTrailingMetadata() { + void FlushTrailingMetadata(grpc_exec_ctx* exec_ctx) { if (!s_->sent_initial_metadata) return; if (s_->send_trailing_metadata == nullptr) return; @@ -518,18 +521,18 @@ class StreamWriteContext { t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], &s_->stats.outgoing}; - grpc_chttp2_encode_header(&t_->hpack_compressor, + grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, extra_headers_for_trailing_metadata_, num_extra_headers_for_trailing_metadata_, s_->send_trailing_metadata, &hopt, &t_->outbuf); } write_context_->IncTrailingMetadataWrites(); write_context_->ResetPingRecvClock(); - SentLastFrame(); + SentLastFrame(exec_ctx); write_context_->NoteScheduledResults(); grpc_chttp2_complete_closure_step( - t_, s_, &s_->send_trailing_metadata_finished, GRPC_ERROR_NONE, + exec_ctx, t_, s_, &s_->send_trailing_metadata_finished, GRPC_ERROR_NONE, "send_trailing_metadata_finished"); } @@ -553,7 +556,7 @@ class StreamWriteContext { } } - void SentLastFrame() { + void SentLastFrame(grpc_exec_ctx* exec_ctx) { s_->send_trailing_metadata = nullptr; s_->sent_trailing_metadata = true; @@ -562,7 +565,7 @@ class StreamWriteContext { &t_->outbuf, grpc_chttp2_rst_stream_create( s_->id, GRPC_HTTP2_NO_ERROR, &s_->stats.outgoing)); } - grpc_chttp2_mark_stream_closed(t_, s_, !t_->is_client, true, + grpc_chttp2_mark_stream_closed(exec_ctx, t_, s_, !t_->is_client, true, GRPC_ERROR_NONE); } @@ -576,12 +579,12 @@ class StreamWriteContext { } // namespace grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_chttp2_transport* t) { - WriteContext ctx(t); - ctx.FlushSettings(); + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) { + WriteContext ctx(exec_ctx, t); + ctx.FlushSettings(exec_ctx); ctx.FlushPingAcks(); - ctx.FlushQueuedBuffers(); - ctx.EnactHpackSettings(); + ctx.FlushQueuedBuffers(exec_ctx); + ctx.EnactHpackSettings(exec_ctx); if (t->flow_control->remote_window() > 0) { ctx.UpdateStreamsNoLongerStalled(); @@ -591,45 +594,47 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( (according to available window sizes) and add to the output buffer */ while (grpc_chttp2_stream* s = ctx.NextStream()) { StreamWriteContext stream_ctx(&ctx, s); - stream_ctx.FlushInitialMetadata(); - stream_ctx.FlushWindowUpdates(); - stream_ctx.FlushData(); - stream_ctx.FlushTrailingMetadata(); + stream_ctx.FlushInitialMetadata(exec_ctx); + stream_ctx.FlushWindowUpdates(exec_ctx); + stream_ctx.FlushData(exec_ctx); + stream_ctx.FlushTrailingMetadata(exec_ctx); if (stream_ctx.stream_became_writable()) { if (!grpc_chttp2_list_add_writing_stream(t, s)) { /* already in writing list: drop ref */ - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:already_writing"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:already_writing"); } else { /* ref will be dropped at end of write */ } } else { - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:no_write"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:no_write"); } } - ctx.FlushWindowUpdates(); + ctx.FlushWindowUpdates(exec_ctx); - maybe_initiate_ping(t); + maybe_initiate_ping(exec_ctx, t); GPR_TIMER_END("grpc_chttp2_begin_write", 0); return ctx.Result(); } -void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { +void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { GPR_TIMER_BEGIN("grpc_chttp2_end_write", 0); grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - update_list(t, s, (int64_t)s->sending_bytes, &s->on_write_finished_cbs, - &s->flow_controlled_bytes_written, GRPC_ERROR_REF(error)); + update_list(exec_ctx, t, s, (int64_t)s->sending_bytes, + &s->on_write_finished_cbs, &s->flow_controlled_bytes_written, + GRPC_ERROR_REF(error)); s->sending_bytes = 0; } - GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:end"); + GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:end"); } - grpc_slice_buffer_reset_and_unref_internal(&t->outbuf); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->outbuf); GRPC_ERROR_UNREF(error); GPR_TIMER_END("grpc_chttp2_end_write", 0); } diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc index 40a30e4a31..d590ba0371 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc @@ -49,6 +49,7 @@ GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( grpc_transport* ct = grpc_create_cronet_transport(engine, target, args, reserved); - grpc_core::ExecCtx exec_ctx; - return grpc_channel_create(target, args, GRPC_CLIENT_DIRECT_CHANNEL, ct); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + return grpc_channel_create(&exec_ctx, target, args, + GRPC_CLIENT_DIRECT_CHANNEL, ct); } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index c9fd94176b..4d24efe47b 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -197,23 +197,27 @@ typedef struct stream_obj stream_obj; #ifndef NDEBUG #define GRPC_CRONET_STREAM_REF(stream, reason) \ grpc_cronet_stream_ref((stream), (reason)) -#define GRPC_CRONET_STREAM_UNREF(stream, reason) \ - grpc_cronet_stream_unref((stream), (reason)) +#define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ + grpc_cronet_stream_unref((exec_ctx), (stream), (reason)) void grpc_cronet_stream_ref(stream_obj* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_cronet_stream_unref(stream_obj* s, const char* reason) { - grpc_stream_unref(s->refcount, reason); +void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s, + const char* reason) { + grpc_stream_unref(exec_ctx, s->refcount, reason); } #else #define GRPC_CRONET_STREAM_REF(stream, reason) grpc_cronet_stream_ref((stream)) -#define GRPC_CRONET_STREAM_UNREF(stream, reason) \ - grpc_cronet_stream_unref((stream)) +#define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ + grpc_cronet_stream_unref((exec_ctx), (stream)) void grpc_cronet_stream_ref(stream_obj* s) { grpc_stream_ref(s->refcount); } -void grpc_cronet_stream_unref(stream_obj* s) { grpc_stream_unref(s->refcount); } +void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s) { + grpc_stream_unref(exec_ctx, s->refcount); +} #endif -static enum e_op_result execute_stream_op(struct op_and_state* oas); +static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, + struct op_and_state* oas); /* Utility function to translate enum into string for printing @@ -369,12 +373,12 @@ static void remove_from_storage(struct stream_obj* s, This can get executed from the Cronet network thread via cronet callback or on the application supplied thread via the perform_stream_op function. */ -static void execute_from_storage(stream_obj* s) { +static void execute_from_storage(grpc_exec_ctx* exec_ctx, stream_obj* s) { gpr_mu_lock(&s->mu); for (struct op_and_state* curr = s->storage.head; curr != nullptr;) { CRONET_LOG(GPR_DEBUG, "calling op at %p. done = %d", curr, curr->done); GPR_ASSERT(curr->done == 0); - enum e_op_result result = execute_stream_op(curr); + enum e_op_result result = execute_stream_op(exec_ctx, curr); CRONET_LOG(GPR_DEBUG, "execute_stream_op[%p] returns %s", curr, op_result_string(result)); /* if this op is done, then remove it and free memory */ @@ -398,7 +402,7 @@ static void execute_from_storage(stream_obj* s) { */ static void on_failed(bidirectional_stream* stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -415,8 +419,9 @@ static void on_failed(bidirectional_stream* stream, int net_error) { } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(s); - GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); + execute_from_storage(&exec_ctx, s); + GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -424,7 +429,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) { */ static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -441,8 +446,9 @@ static void on_canceled(bidirectional_stream* stream) { } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(s); - GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); + execute_from_storage(&exec_ctx, s); + GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -450,7 +456,7 @@ static void on_canceled(bidirectional_stream* stream) { */ static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -459,8 +465,9 @@ static void on_succeeded(bidirectional_stream* stream) { s->cbs = nullptr; null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(s); - GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); + execute_from_storage(&exec_ctx, s); + GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -468,7 +475,7 @@ static void on_succeeded(bidirectional_stream* stream) { */ static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); @@ -488,7 +495,8 @@ static void on_stream_ready(bidirectional_stream* stream) { } } gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -498,7 +506,7 @@ static void on_response_headers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* headers, const char* negotiated_protocol) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); stream_obj* s = (stream_obj*)stream->annotation; @@ -520,8 +528,9 @@ static void on_response_headers_received( for (size_t i = 0; i < headers->count; i++) { GRPC_LOG_IF_ERROR("on_response_headers_received", grpc_chttp2_incoming_metadata_buffer_add( - &s->state.rs.initial_metadata, + &exec_ctx, &s->state.rs.initial_metadata, grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( headers->headers[i].key)), grpc_slice_intern(grpc_slice_from_static_string( @@ -543,14 +552,15 @@ static void on_response_headers_received( s->state.pending_read_from_cronet = true; } gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } /* Cronet callback */ static void on_write_completed(bidirectional_stream* stream, const char* data) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); @@ -560,7 +570,8 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { } s->state.state_callback_received[OP_SEND_MESSAGE] = true; gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -568,7 +579,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { */ static void on_read_completed(bidirectional_stream* stream, char* data, int count) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); @@ -594,14 +605,15 @@ static void on_read_completed(bidirectional_stream* stream, char* data, gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); } } else { null_and_maybe_free_read_buffer(s); s->state.rs.read_stream_closed = true; gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); } + grpc_exec_ctx_finish(&exec_ctx); } /* @@ -610,7 +622,7 @@ static void on_read_completed(bidirectional_stream* stream, char* data, static void on_response_trailers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* trailers) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); stream_obj* s = (stream_obj*)stream->annotation; @@ -626,8 +638,9 @@ static void on_response_trailers_received( trailers->headers[i].value); GRPC_LOG_IF_ERROR("on_response_trailers_received", grpc_chttp2_incoming_metadata_buffer_add( - &s->state.rs.trailing_metadata, + &exec_ctx, &s->state.rs.trailing_metadata, grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( trailers->headers[i].key)), grpc_slice_intern(grpc_slice_from_static_string( @@ -657,15 +670,17 @@ static void on_response_trailers_received( gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - execute_from_storage(s); + execute_from_storage(&exec_ctx, s); } + grpc_exec_ctx_finish(&exec_ctx); } /* Utility function that takes the data from s->write_slice_buffer and assembles into a contiguous byte stream with 5 byte gRPC header prepended. */ -static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, +static void create_grpc_frame(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* write_slice_buffer, char** pp_write_buffer, size_t* p_write_buffer_size, uint32_t flags) { grpc_slice slice = grpc_slice_buffer_take_first(write_slice_buffer); @@ -685,7 +700,7 @@ static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, *p++ = (uint8_t)(length); /* append actual data */ memcpy(p, GRPC_SLICE_START_PTR(slice), length); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); } /* @@ -966,7 +981,8 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op, /* TODO (makdharma): Break down this function in smaller chunks for readability. */ -static enum e_op_result execute_stream_op(struct op_and_state* oas) { +static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, + struct op_and_state* oas) { grpc_transport_stream_op_batch* stream_op = &oas->op; struct stream_obj* s = oas->s; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; @@ -1024,14 +1040,15 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { grpc_slice slice; grpc_slice_buffer_init(&write_slice_buffer); if (1 != grpc_byte_stream_next( - stream_op->payload->send_message.send_message, + exec_ctx, stream_op->payload->send_message.send_message, stream_op->payload->send_message.send_message->length, nullptr)) { /* Should never reach here */ GPR_ASSERT(false); } if (GRPC_ERROR_NONE != - grpc_byte_stream_pull(stream_op->payload->send_message.send_message, + grpc_byte_stream_pull(exec_ctx, + stream_op->payload->send_message.send_message, &slice)) { /* Should never reach here */ GPR_ASSERT(false); @@ -1044,15 +1061,15 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { } if (write_slice_buffer.count > 0) { size_t write_buffer_size; - create_grpc_frame(&write_slice_buffer, &stream_state->ws.write_buffer, - &write_buffer_size, + create_grpc_frame(exec_ctx, &write_slice_buffer, + &stream_state->ws.write_buffer, &write_buffer_size, stream_op->payload->send_message.send_message->flags); CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", s->cbs, stream_state->ws.write_buffer); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, (int)write_buffer_size, false); - grpc_slice_buffer_destroy_internal(&write_slice_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &write_slice_buffer); if (t->use_packet_coalescing) { if (!stream_op->send_trailing_metadata) { CRONET_LOG(GPR_DEBUG, "bidirectional_stream_flush (%p)", s->cbs); @@ -1095,21 +1112,25 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_INITIAL_METADATA", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { GRPC_CLOSURE_SCHED( + exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else if (stream_state->state_callback_received[OP_FAILED]) { GRPC_CLOSURE_SCHED( + exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else if (stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) { GRPC_CLOSURE_SCHED( + exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else { grpc_chttp2_incoming_metadata_buffer_publish( - &oas->s->state.rs.initial_metadata, + exec_ctx, &oas->s->state.rs.initial_metadata, stream_op->payload->recv_initial_metadata.recv_initial_metadata); GRPC_CLOSURE_SCHED( + exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } @@ -1120,14 +1141,16 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_MESSAGE", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { CRONET_LOG(GPR_DEBUG, "Stream is cancelled."); - GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->state_callback_received[OP_FAILED]) { CRONET_LOG(GPR_DEBUG, "Stream failed."); - GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1135,14 +1158,16 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { } else if (stream_state->rs.read_stream_closed == true) { /* No more data will be received */ CRONET_LOG(GPR_DEBUG, "read stream closed"); - GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->flush_read) { CRONET_LOG(GPR_DEBUG, "flush read"); - GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1175,7 +1200,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { CRONET_LOG(GPR_DEBUG, "read operation complete. Empty response."); /* Clean up read_slice_buffer in case there is unread data. */ grpc_slice_buffer_destroy_internal( - &stream_state->rs.read_slice_buffer); + exec_ctx, &stream_state->rs.read_slice_buffer); grpc_slice_buffer_init(&stream_state->rs.read_slice_buffer); grpc_slice_buffer_stream_init(&stream_state->rs.sbs, &stream_state->rs.read_slice_buffer, 0); @@ -1185,7 +1210,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = (grpc_byte_buffer*)&stream_state->rs.sbs; GRPC_CLOSURE_SCHED( - stream_op->payload->recv_message.recv_message_ready, + exec_ctx, stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1229,7 +1254,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { (size_t)stream_state->rs.length_field); null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ - grpc_slice_buffer_destroy_internal(&stream_state->rs.read_slice_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, + &stream_state->rs.read_slice_buffer); grpc_slice_buffer_init(&stream_state->rs.read_slice_buffer); grpc_slice_buffer_add(&stream_state->rs.read_slice_buffer, read_data_slice); @@ -1240,7 +1266,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { } *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = (grpc_byte_buffer*)&stream_state->rs.sbs; - GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1263,7 +1290,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", oas); if (oas->s->state.rs.trailing_metadata_valid) { grpc_chttp2_incoming_metadata_buffer_publish( - &oas->s->state.rs.trailing_metadata, + exec_ctx, &oas->s->state.rs.trailing_metadata, stream_op->payload->recv_trailing_metadata.recv_trailing_metadata); stream_state->rs.trailing_metadata_valid = false; } @@ -1288,17 +1315,17 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { op_can_be_run(stream_op, s, &oas->state, OP_ON_COMPLETE)) { CRONET_LOG(GPR_DEBUG, "running: %p OP_ON_COMPLETE", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { - GRPC_CLOSURE_SCHED(stream_op->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, stream_op->on_complete, GRPC_ERROR_REF(stream_state->cancel_error)); } else if (stream_state->state_callback_received[OP_FAILED]) { GRPC_CLOSURE_SCHED( - stream_op->on_complete, + exec_ctx, stream_op->on_complete, make_error_with_desc(GRPC_STATUS_UNAVAILABLE, "Unavailable.")); } else { /* All actions in this stream_op are complete. Call the on_complete * callback */ - GRPC_CLOSURE_SCHED(stream_op->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, stream_op->on_complete, GRPC_ERROR_NONE); } oas->state.state_op_done[OP_ON_COMPLETE] = true; oas->done = true; @@ -1323,9 +1350,9 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { Functions used by upper layers to access transport functionality. */ -static int init_stream(grpc_transport* gt, grpc_stream* gs, - grpc_stream_refcount* refcount, const void* server_data, - gpr_arena* arena) { +static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { stream_obj* s = (stream_obj*)gs; s->refcount = refcount; @@ -1356,13 +1383,15 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, return 0; } -static void set_pollset_do_nothing(grpc_transport* gt, grpc_stream* gs, - grpc_pollset* pollset) {} +static void set_pollset_do_nothing(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) {} -static void set_pollset_set_do_nothing(grpc_transport* gt, grpc_stream* gs, +static void set_pollset_set_do_nothing(grpc_exec_ctx* exec_ctx, + grpc_transport* gt, grpc_stream* gs, grpc_pollset_set* pollset_set) {} -static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, +static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_transport_stream_op_batch* op) { CRONET_LOG(GPR_DEBUG, "perform_stream_op"); if (op->send_initial_metadata && @@ -1372,36 +1401,42 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, this field is present in metadata */ if (op->recv_initial_metadata) { GRPC_CLOSURE_SCHED( + exec_ctx, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_CANCELLED); } if (op->recv_message) { - GRPC_CLOSURE_SCHED(op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, op->payload->recv_message.recv_message_ready, GRPC_ERROR_CANCELLED); } - GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_CANCELLED); return; } stream_obj* s = (stream_obj*)gs; add_to_storage(s, op); - execute_from_storage(s); + execute_from_storage(exec_ctx, s); } -static void destroy_stream(grpc_transport* gt, grpc_stream* gs, +static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_closure* then_schedule_closure) { stream_obj* s = (stream_obj*)gs; null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ - grpc_slice_buffer_destroy_internal(&s->state.rs.read_slice_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->state.rs.read_slice_buffer); GRPC_ERROR_UNREF(s->state.cancel_error); - GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); } -static void destroy_transport(grpc_transport* gt) {} +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) {} -static grpc_endpoint* get_endpoint(grpc_transport* gt) { return nullptr; } +static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* gt) { + return nullptr; +} -static void perform_op(grpc_transport* gt, grpc_transport_op* op) {} +static void perform_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) {} static const grpc_transport_vtable grpc_cronet_vtable = { sizeof(stream_obj), diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 8dd0b7dce2..d8d753e459 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -54,8 +54,8 @@ typedef struct inproc_transport { gpr_refcount refs; bool is_client; grpc_connectivity_state_tracker connectivity; - void (*accept_stream_cb)(void* user_data, grpc_transport* transport, - const void* server_data); + void (*accept_stream_cb)(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_transport* transport, const void* server_data); void* accept_stream_data; bool is_closed; struct inproc_transport* other_side; @@ -118,36 +118,39 @@ typedef struct inproc_stream { } inproc_stream; static grpc_closure do_nothing_closure; -static bool cancel_stream_locked(inproc_stream* s, grpc_error* error); -static void op_state_machine(void* arg, grpc_error* error); +static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error); +static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); static void ref_transport(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "ref_transport %p", t); gpr_ref(&t->refs); } -static void really_destroy_transport(inproc_transport* t) { +static void really_destroy_transport(grpc_exec_ctx* exec_ctx, + inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "really_destroy_transport %p", t); - grpc_connectivity_state_destroy(&t->connectivity); + grpc_connectivity_state_destroy(exec_ctx, &t->connectivity); if (gpr_unref(&t->mu->refs)) { gpr_free(t->mu); } gpr_free(t); } -static void unref_transport(inproc_transport* t) { +static void unref_transport(grpc_exec_ctx* exec_ctx, inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "unref_transport %p", t); if (gpr_unref(&t->refs)) { - really_destroy_transport(t); + really_destroy_transport(exec_ctx, t); } } #ifndef NDEBUG #define STREAM_REF(refs, reason) grpc_stream_ref(refs, reason) -#define STREAM_UNREF(refs, reason) grpc_stream_unref(refs, reason) +#define STREAM_UNREF(e, refs, reason) grpc_stream_unref(e, refs, reason) #else #define STREAM_REF(refs, reason) grpc_stream_ref(refs) -#define STREAM_UNREF(refs, reason) grpc_stream_unref(refs) +#define STREAM_UNREF(e, refs, reason) grpc_stream_unref(e, refs) #endif static void ref_stream(inproc_stream* s, const char* reason) { @@ -155,12 +158,13 @@ static void ref_stream(inproc_stream* s, const char* reason) { STREAM_REF(s->refs, reason); } -static void unref_stream(inproc_stream* s, const char* reason) { +static void unref_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s, + const char* reason) { INPROC_LOG(GPR_DEBUG, "unref_stream %p %s", s, reason); - STREAM_UNREF(s->refs, reason); + STREAM_UNREF(exec_ctx, s->refs, reason); } -static void really_destroy_stream(inproc_stream* s) { +static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { INPROC_LOG(GPR_DEBUG, "really_destroy_stream %p", s); GRPC_ERROR_UNREF(s->write_buffer_cancel_error); @@ -168,13 +172,13 @@ static void really_destroy_stream(inproc_stream* s) { GRPC_ERROR_UNREF(s->cancel_other_error); if (s->recv_inited) { - grpc_slice_buffer_destroy_internal(&s->recv_message); + grpc_slice_buffer_destroy_internal(exec_ctx, &s->recv_message); } - unref_transport(s->t); + unref_transport(exec_ctx, s->t); if (s->closure_at_destroy) { - GRPC_CLOSURE_SCHED(s->closure_at_destroy, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->closure_at_destroy, GRPC_ERROR_NONE); } } @@ -191,7 +195,7 @@ static void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, } } -static grpc_error* fill_in_metadata(inproc_stream* s, +static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, const grpc_metadata_batch* metadata, uint32_t flags, grpc_metadata_batch* out_md, uint32_t* outflags, bool* markfilled) { @@ -210,18 +214,18 @@ static grpc_error* fill_in_metadata(inproc_stream* s, (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { grpc_linked_mdelem* nelem = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); - nelem->md = - grpc_mdelem_from_slices(grpc_slice_intern(GRPC_MDKEY(elem->md)), - grpc_slice_intern(GRPC_MDVALUE(elem->md))); + nelem->md = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(GRPC_MDKEY(elem->md)), + grpc_slice_intern(GRPC_MDVALUE(elem->md))); - error = grpc_metadata_batch_link_tail(out_md, nelem); + error = grpc_metadata_batch_link_tail(exec_ctx, out_md, nelem); } return error; } -static int init_stream(grpc_transport* gt, grpc_stream* gs, - grpc_stream_refcount* refcount, const void* server_data, - gpr_arena* arena) { +static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { INPROC_LOG(GPR_DEBUG, "init_stream %p %p %p", gt, gs, server_data); inproc_transport* t = (inproc_transport*)gt; inproc_stream* s = (inproc_stream*)gs; @@ -281,7 +285,8 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, // side to avoid destruction INPROC_LOG(GPR_DEBUG, "calling accept stream cb %p %p", st->accept_stream_cb, st->accept_stream_data); - (*st->accept_stream_cb)(st->accept_stream_data, &st->base, (void*)s); + (*st->accept_stream_cb)(exec_ctx, st->accept_stream_data, &st->base, + (void*)s); } else { // This is the server-side and is being called through accept_stream_cb inproc_stream* cs = (inproc_stream*)server_data; @@ -296,19 +301,19 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, // Now transfer from the other side's write_buffer if any to the to_read // buffer if (cs->write_buffer_initial_md_filled) { - fill_in_metadata(s, &cs->write_buffer_initial_md, + fill_in_metadata(exec_ctx, s, &cs->write_buffer_initial_md, cs->write_buffer_initial_md_flags, &s->to_read_initial_md, &s->to_read_initial_md_flags, &s->to_read_initial_md_filled); s->deadline = GPR_MIN(s->deadline, cs->write_buffer_deadline); - grpc_metadata_batch_clear(&cs->write_buffer_initial_md); + grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_initial_md); cs->write_buffer_initial_md_filled = false; } if (cs->write_buffer_trailing_md_filled) { - fill_in_metadata(s, &cs->write_buffer_trailing_md, 0, + fill_in_metadata(exec_ctx, s, &cs->write_buffer_trailing_md, 0, &s->to_read_trailing_md, nullptr, &s->to_read_trailing_md_filled); - grpc_metadata_batch_clear(&cs->write_buffer_trailing_md); + grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_trailing_md); cs->write_buffer_trailing_md_filled = false; } if (cs->write_buffer_cancel_error != GRPC_ERROR_NONE) { @@ -321,11 +326,11 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, return 0; // return value is not important } -static void close_stream_locked(inproc_stream* s) { +static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { if (!s->closed) { // Release the metadata that we would have written out - grpc_metadata_batch_destroy(&s->write_buffer_initial_md); - grpc_metadata_batch_destroy(&s->write_buffer_trailing_md); + grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_initial_md); + grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_trailing_md); if (s->listed) { inproc_stream* p = s->stream_list_prev; @@ -339,21 +344,22 @@ static void close_stream_locked(inproc_stream* s) { n->stream_list_prev = p; } s->listed = false; - unref_stream(s, "close_stream:list"); + unref_stream(exec_ctx, s, "close_stream:list"); } s->closed = true; - unref_stream(s, "close_stream:closing"); + unref_stream(exec_ctx, s, "close_stream:closing"); } } // This function means that we are done talking/listening to the other side -static void close_other_side_locked(inproc_stream* s, const char* reason) { +static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + const char* reason) { if (s->other_side != nullptr) { // First release the metadata that came from the other side's arena - grpc_metadata_batch_destroy(&s->to_read_initial_md); - grpc_metadata_batch_destroy(&s->to_read_trailing_md); + grpc_metadata_batch_destroy(exec_ctx, &s->to_read_initial_md); + grpc_metadata_batch_destroy(exec_ctx, &s->to_read_trailing_md); - unref_stream(s->other_side, reason); + unref_stream(exec_ctx, s->other_side, reason); s->other_side_closed = true; s->other_side = nullptr; } else if (!s->other_side_closed) { @@ -365,7 +371,8 @@ static void close_other_side_locked(inproc_stream* s, const char* reason) { // this stream_op_batch is only one of the pending operations for this // stream. This is called when one of the pending operations for the stream // is done and about to be NULLed out -static void complete_if_batch_end_locked(inproc_stream* s, grpc_error* error, +static void complete_if_batch_end_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* s, grpc_error* error, grpc_transport_stream_op_batch* op, const char* msg) { int is_sm = (int)(op == s->send_message_op); @@ -376,20 +383,22 @@ static void complete_if_batch_end_locked(inproc_stream* s, grpc_error* error, if ((is_sm + is_stm + is_rim + is_rm + is_rtm) == 1) { INPROC_LOG(GPR_DEBUG, "%s %p %p %p", msg, s, op, error); - GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_REF(error)); } } -static void maybe_schedule_op_closure_locked(inproc_stream* s, +static void maybe_schedule_op_closure_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* s, grpc_error* error) { if (s && s->ops_needed && !s->op_closure_scheduled) { - GRPC_CLOSURE_SCHED(&s->op_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_REF(error)); s->op_closure_scheduled = true; s->ops_needed = false; } } -static void fail_helper_locked(inproc_stream* s, grpc_error* error) { +static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p fail_helper", s); // If we're failing this side, we need to make sure that // we also send or have already sent trailing metadata @@ -406,14 +415,14 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(s, &fake_md, 0, dest, nullptr, destfilled); - grpc_metadata_batch_destroy(&fake_md); + fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, nullptr, destfilled); + grpc_metadata_batch_destroy(exec_ctx, &fake_md); if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(error); } - maybe_schedule_op_closure_locked(other, error); + maybe_schedule_op_closure_locked(exec_ctx, other, error); } else if (s->write_buffer_cancel_error == GRPC_ERROR_NONE) { s->write_buffer_cancel_error = GRPC_ERROR_REF(error); } @@ -427,22 +436,24 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { grpc_metadata_batch_init(&fake_md); grpc_linked_mdelem* path_md = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*path_md)); - path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value); - GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, path_md) == + path_md->md = + grpc_mdelem_from_slices(exec_ctx, g_fake_path_key, g_fake_path_value); + GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, path_md) == GRPC_ERROR_NONE); grpc_linked_mdelem* auth_md = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*auth_md)); - auth_md->md = grpc_mdelem_from_slices(g_fake_auth_key, g_fake_auth_value); - GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, auth_md) == + auth_md->md = + grpc_mdelem_from_slices(exec_ctx, g_fake_auth_key, g_fake_auth_value); + GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, auth_md) == GRPC_ERROR_NONE); fill_in_metadata( - s, &fake_md, 0, + exec_ctx, s, &fake_md, 0, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, nullptr); - grpc_metadata_batch_destroy(&fake_md); + grpc_metadata_batch_destroy(exec_ctx, &fake_md); err = GRPC_ERROR_NONE; } else { err = GRPC_ERROR_REF(error); @@ -458,13 +469,14 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling initial-metadata-ready %p %p", s, error, err); - GRPC_CLOSURE_SCHED(s->recv_initial_md_op->payload->recv_initial_metadata + GRPC_CLOSURE_SCHED(exec_ctx, + s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata_ready, err); // Last use of err so no need to REF and then UNREF it complete_if_batch_end_locked( - s, error, s->recv_initial_md_op, + exec_ctx, s, error, s->recv_initial_md_op, "fail_helper scheduling recv-initial-metadata-on-complete"); s->recv_initial_md_op = nullptr; } @@ -472,22 +484,22 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling message-ready %p", s, error); GRPC_CLOSURE_SCHED( - s->recv_message_op->payload->recv_message.recv_message_ready, + exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_REF(error)); complete_if_batch_end_locked( - s, error, s->recv_message_op, + exec_ctx, s, error, s->recv_message_op, "fail_helper scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } if (s->send_message_op) { complete_if_batch_end_locked( - s, error, s->send_message_op, + exec_ctx, s, error, s->send_message_op, "fail_helper scheduling send-message-on-complete"); s->send_message_op = nullptr; } if (s->send_trailing_md_op) { complete_if_batch_end_locked( - s, error, s->send_trailing_md_op, + exec_ctx, s, error, s->send_trailing_md_op, "fail_helper scheduling send-trailng-md-on-complete"); s->send_trailing_md_op = nullptr; } @@ -496,22 +508,23 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { "fail_helper %p scheduling trailing-md-on-complete %p", s, error); complete_if_batch_end_locked( - s, error, s->recv_trailing_md_op, + exec_ctx, s, error, s->recv_trailing_md_op, "fail_helper scheduling recv-trailing-metadata-on-complete"); s->recv_trailing_md_op = nullptr; } - close_other_side_locked(s, "fail_helper:other_side"); - close_stream_locked(s); + close_other_side_locked(exec_ctx, s, "fail_helper:other_side"); + close_stream_locked(exec_ctx, s); GRPC_ERROR_UNREF(error); } -static void message_transfer_locked(inproc_stream* sender, +static void message_transfer_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* sender, inproc_stream* receiver) { size_t remaining = sender->send_message_op->payload->send_message.send_message->length; if (receiver->recv_inited) { - grpc_slice_buffer_destroy_internal(&receiver->recv_message); + grpc_slice_buffer_destroy_internal(exec_ctx, &receiver->recv_message); } grpc_slice_buffer_init(&receiver->recv_message); receiver->recv_inited = true; @@ -519,13 +532,13 @@ static void message_transfer_locked(inproc_stream* sender, grpc_slice message_slice; grpc_closure unused; GPR_ASSERT(grpc_byte_stream_next( - sender->send_message_op->payload->send_message.send_message, SIZE_MAX, - &unused)); + exec_ctx, sender->send_message_op->payload->send_message.send_message, + SIZE_MAX, &unused)); grpc_error* error = grpc_byte_stream_pull( - sender->send_message_op->payload->send_message.send_message, + exec_ctx, sender->send_message_op->payload->send_message.send_message, &message_slice); if (error != GRPC_ERROR_NONE) { - cancel_stream_locked(sender, GRPC_ERROR_REF(error)); + cancel_stream_locked(exec_ctx, sender, GRPC_ERROR_REF(error)); break; } GPR_ASSERT(error == GRPC_ERROR_NONE); @@ -540,20 +553,22 @@ static void message_transfer_locked(inproc_stream* sender, INPROC_LOG(GPR_DEBUG, "message_transfer_locked %p scheduling message-ready", receiver); GRPC_CLOSURE_SCHED( + exec_ctx, receiver->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - sender, GRPC_ERROR_NONE, sender->send_message_op, + exec_ctx, sender, GRPC_ERROR_NONE, sender->send_message_op, "message_transfer scheduling sender on_complete"); complete_if_batch_end_locked( - receiver, GRPC_ERROR_NONE, receiver->recv_message_op, + exec_ctx, receiver, GRPC_ERROR_NONE, receiver->recv_message_op, "message_transfer scheduling receiver on_complete"); receiver->recv_message_op = nullptr; sender->send_message_op = nullptr; } -static void op_state_machine(void* arg, grpc_error* error) { +static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { // This function gets called when we have contents in the unprocessed reads // Get what we want based on our ops wanted // Schedule our appropriate closures @@ -574,26 +589,26 @@ static void op_state_machine(void* arg, grpc_error* error) { inproc_stream* other = s->other_side; if (s->cancel_self_error != GRPC_ERROR_NONE) { - fail_helper_locked(s, GRPC_ERROR_REF(s->cancel_self_error)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(s->cancel_self_error)); goto done; } else if (s->cancel_other_error != GRPC_ERROR_NONE) { - fail_helper_locked(s, GRPC_ERROR_REF(s->cancel_other_error)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(s->cancel_other_error)); goto done; } else if (error != GRPC_ERROR_NONE) { - fail_helper_locked(s, GRPC_ERROR_REF(error)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(error)); goto done; } if (s->send_message_op && other) { if (other->recv_message_op) { - message_transfer_locked(s, other); - maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); + message_transfer_locked(exec_ctx, s, other); + maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); } else if (!s->t->is_client && (s->trailing_md_sent || other->recv_trailing_md_op)) { // A server send will never be matched if the client is waiting // for trailing metadata already complete_if_batch_end_locked( - s, GRPC_ERROR_NONE, s->send_message_op, + exec_ctx, s, GRPC_ERROR_NONE, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -615,11 +630,11 @@ static void op_state_machine(void* arg, grpc_error* error) { // The buffer is already in use; that's an error! INPROC_LOG(GPR_DEBUG, "Extra trailing metadata %p", s); new_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Extra trailing metadata"); - fail_helper_locked(s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } else { if (!other || !other->closed) { - fill_in_metadata(s, + fill_in_metadata(exec_ctx, s, s->send_trailing_md_op->payload->send_trailing_metadata .send_trailing_metadata, 0, dest, nullptr, destfilled); @@ -628,15 +643,15 @@ static void op_state_machine(void* arg, grpc_error* error) { if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling trailing-md-on-complete", s); - GRPC_CLOSURE_SCHED(s->recv_trailing_md_op->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_NONE); s->recv_trailing_md_op = nullptr; needs_close = true; } } - maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); + maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); complete_if_batch_end_locked( - s, GRPC_ERROR_NONE, s->send_trailing_md_op, + exec_ctx, s, GRPC_ERROR_NONE, s->send_trailing_md_op, "op_state_machine scheduling send-trailing-metadata-on-complete"); s->send_trailing_md_op = nullptr; } @@ -649,14 +664,14 @@ static void op_state_machine(void* arg, grpc_error* error) { "op_state_machine %p scheduling on_complete errors for already " "recvd initial md %p", s, new_err); - fail_helper_locked(s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } if (s->to_read_initial_md_filled) { s->initial_md_recvd = true; new_err = fill_in_metadata( - s, &s->to_read_initial_md, s->to_read_initial_md_flags, + exec_ctx, s, &s->to_read_initial_md, s->to_read_initial_md_flags, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, @@ -669,16 +684,17 @@ static void op_state_machine(void* arg, grpc_error* error) { .trailing_metadata_available = (other != nullptr && other->send_trailing_md_op != nullptr); } - grpc_metadata_batch_clear(&s->to_read_initial_md); + grpc_metadata_batch_clear(exec_ctx, &s->to_read_initial_md); s->to_read_initial_md_filled = false; INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling initial-metadata-ready %p", s, new_err); - GRPC_CLOSURE_SCHED(s->recv_initial_md_op->payload->recv_initial_metadata + GRPC_CLOSURE_SCHED(exec_ctx, + s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata_ready, GRPC_ERROR_REF(new_err)); complete_if_batch_end_locked( - s, new_err, s->recv_initial_md_op, + exec_ctx, s, new_err, s->recv_initial_md_op, "op_state_machine scheduling recv-initial-metadata-on-complete"); s->recv_initial_md_op = nullptr; @@ -686,20 +702,20 @@ static void op_state_machine(void* arg, grpc_error* error) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling on_complete errors2 %p", s, new_err); - fail_helper_locked(s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } } } if (s->recv_message_op) { if (other && other->send_message_op) { - message_transfer_locked(other, s); - maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); + message_transfer_locked(exec_ctx, other, s); + maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); } } if (s->recv_trailing_md_op && s->t->is_client && other && other->send_message_op) { - maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); + maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); } if (s->to_read_trailing_md_filled) { if (s->trailing_md_recvd) { @@ -710,7 +726,7 @@ static void op_state_machine(void* arg, grpc_error* error) { "op_state_machine %p scheduling on_complete errors for already " "recvd trailing md %p", s, new_err); - fail_helper_locked(s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } if (s->recv_message_op != nullptr) { @@ -718,10 +734,11 @@ static void op_state_machine(void* arg, grpc_error* error) { // satisfied INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); GRPC_CLOSURE_SCHED( + exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - s, new_err, s->recv_message_op, + exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } @@ -729,7 +746,7 @@ static void op_state_machine(void* arg, grpc_error* error) { // Nothing further will try to receive from this stream, so finish off // any outstanding send_message op complete_if_batch_end_locked( - s, new_err, s->send_message_op, + exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -737,11 +754,11 @@ static void op_state_machine(void* arg, grpc_error* error) { // We wanted trailing metadata and we got it s->trailing_md_recvd = true; new_err = - fill_in_metadata(s, &s->to_read_trailing_md, 0, + fill_in_metadata(exec_ctx, s, &s->to_read_trailing_md, 0, s->recv_trailing_md_op->payload ->recv_trailing_metadata.recv_trailing_metadata, nullptr, nullptr); - grpc_metadata_batch_clear(&s->to_read_trailing_md); + grpc_metadata_batch_clear(exec_ctx, &s->to_read_trailing_md); s->to_read_trailing_md_filled = false; // We should schedule the recv_trailing_md_op completion if @@ -753,7 +770,7 @@ static void op_state_machine(void* arg, grpc_error* error) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling trailing-md-on-complete %p", s, new_err); - GRPC_CLOSURE_SCHED(s->recv_trailing_md_op->on_complete, + GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_REF(new_err)); s->recv_trailing_md_op = nullptr; needs_close = true; @@ -774,10 +791,10 @@ static void op_state_machine(void* arg, grpc_error* error) { // recv_message_op INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); GRPC_CLOSURE_SCHED( - s->recv_message_op->payload->recv_message.recv_message_ready, + exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - s, new_err, s->recv_message_op, + exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } @@ -786,7 +803,7 @@ static void op_state_machine(void* arg, grpc_error* error) { // Nothing further will try to receive from this stream, so finish off // any outstanding send_message op complete_if_batch_end_locked( - s, new_err, s->send_message_op, + exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -802,21 +819,22 @@ static void op_state_machine(void* arg, grpc_error* error) { } done: if (needs_close) { - close_other_side_locked(s, "op_state_machine"); - close_stream_locked(s); + close_other_side_locked(exec_ctx, s, "op_state_machine"); + close_stream_locked(exec_ctx, s); } gpr_mu_unlock(mu); GRPC_ERROR_UNREF(new_err); } -static bool cancel_stream_locked(inproc_stream* s, grpc_error* error) { +static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error) { bool ret = false; // was the cancel accepted INPROC_LOG(GPR_DEBUG, "cancel_stream %p with %s", s, grpc_error_string(error)); if (s->cancel_self_error == GRPC_ERROR_NONE) { ret = true; s->cancel_self_error = GRPC_ERROR_REF(error); - maybe_schedule_op_closure_locked(s, s->cancel_self_error); + maybe_schedule_op_closure_locked(exec_ctx, s, s->cancel_self_error); // Send trailing md to the other side indicating cancellation, even if we // already have s->trailing_md_sent = true; @@ -830,14 +848,15 @@ static bool cancel_stream_locked(inproc_stream* s, grpc_error* error) { : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(s, &cancel_md, 0, dest, nullptr, destfilled); - grpc_metadata_batch_destroy(&cancel_md); + fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, nullptr, destfilled); + grpc_metadata_batch_destroy(exec_ctx, &cancel_md); if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(s->cancel_self_error); } - maybe_schedule_op_closure_locked(other, other->cancel_other_error); + maybe_schedule_op_closure_locked(exec_ctx, other, + other->cancel_other_error); } else if (s->write_buffer_cancel_error == GRPC_ERROR_NONE) { s->write_buffer_cancel_error = GRPC_ERROR_REF(s->cancel_self_error); } @@ -847,20 +866,21 @@ static bool cancel_stream_locked(inproc_stream* s, grpc_error* error) { // md, now's the chance if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { complete_if_batch_end_locked( - s, s->cancel_self_error, s->recv_trailing_md_op, + exec_ctx, s, s->cancel_self_error, s->recv_trailing_md_op, "cancel_stream scheduling trailing-md-on-complete"); s->recv_trailing_md_op = nullptr; } } - close_other_side_locked(s, "cancel_stream:other_side"); - close_stream_locked(s); + close_other_side_locked(exec_ctx, s, "cancel_stream:other_side"); + close_stream_locked(exec_ctx, s); GRPC_ERROR_UNREF(error); return ret; } -static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, +static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_transport_stream_op_batch* op) { INPROC_LOG(GPR_DEBUG, "perform_stream_op %p %p %p", gt, gs, op); inproc_stream* s = (inproc_stream*)gs; @@ -886,7 +906,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, if (op->cancel_stream) { // Call cancel_stream_locked without ref'ing the cancel_error because // this function is responsible to make sure that that field gets unref'ed - cancel_stream_locked(s, op->payload->cancel_stream.cancel_error); + cancel_stream_locked(exec_ctx, s, op->payload->cancel_stream.cancel_error); // this op can complete without an error } else if (s->cancel_self_error != GRPC_ERROR_NONE) { // already self-canceled so still give it an error @@ -926,7 +946,8 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, } else { if (!other || !other->closed) { fill_in_metadata( - s, op->payload->send_initial_metadata.send_initial_metadata, + exec_ctx, s, + op->payload->send_initial_metadata.send_initial_metadata, op->payload->send_initial_metadata.send_initial_metadata_flags, dest, destflags, destfilled); } @@ -938,7 +959,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, s->initial_md_sent = true; } } - maybe_schedule_op_closure_locked(other, error); + maybe_schedule_op_closure_locked(exec_ctx, other, error); } } @@ -978,7 +999,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, (op->recv_message && other && (other->send_message_op != nullptr)) || (s->to_read_trailing_md_filled || s->trailing_md_recvd)) { if (!s->op_closure_scheduled) { - GRPC_CLOSURE_SCHED(&s->op_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_NONE); s->op_closure_scheduled = true; } } else { @@ -1002,6 +1023,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, "perform_stream_op error %p scheduling initial-metadata-ready %p", s, error); GRPC_CLOSURE_SCHED( + exec_ctx, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } @@ -1010,26 +1032,28 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, GPR_DEBUG, "perform_stream_op error %p scheduling recv message-ready %p", s, error); - GRPC_CLOSURE_SCHED(op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(exec_ctx, + op->payload->recv_message.recv_message_ready, GRPC_ERROR_REF(error)); } } INPROC_LOG(GPR_DEBUG, "perform_stream_op %p scheduling on_complete %p", s, error); - GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, on_complete, GRPC_ERROR_REF(error)); } if (needs_close) { - close_other_side_locked(s, "perform_stream_op:other_side"); - close_stream_locked(s); + close_other_side_locked(exec_ctx, s, "perform_stream_op:other_side"); + close_stream_locked(exec_ctx, s); } gpr_mu_unlock(mu); GRPC_ERROR_UNREF(error); } -static void close_transport_locked(inproc_transport* t) { +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "close_transport %p %d", t, t->is_closed); grpc_connectivity_state_set( - &t->connectivity, GRPC_CHANNEL_SHUTDOWN, + exec_ctx, &t->connectivity, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Closing transport."), "close transport"); if (!t->is_closed) { @@ -1038,7 +1062,7 @@ static void close_transport_locked(inproc_transport* t) { while (t->stream_list != nullptr) { // cancel_stream_locked also adjusts stream list cancel_stream_locked( - t->stream_list, + exec_ctx, t->stream_list, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); @@ -1046,13 +1070,14 @@ static void close_transport_locked(inproc_transport* t) { } } -static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { +static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) { inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); if (op->on_connectivity_state_change) { grpc_connectivity_state_notify_on_state_change( - &t->connectivity, op->connectivity_state, + exec_ctx, &t->connectivity, op->connectivity_state, op->on_connectivity_state_change); } if (op->set_accept_stream) { @@ -1060,7 +1085,7 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { t->accept_stream_data = op->set_accept_stream_user_data; } if (op->on_consumed) { - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } bool do_close = false; @@ -1074,67 +1099,71 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { } if (do_close) { - close_transport_locked(t); + close_transport_locked(exec_ctx, t); } gpr_mu_unlock(&t->mu->mu); } -static void destroy_stream(grpc_transport* gt, grpc_stream* gs, +static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_closure* then_schedule_closure) { INPROC_LOG(GPR_DEBUG, "destroy_stream %p %p", gs, then_schedule_closure); inproc_stream* s = (inproc_stream*)gs; s->closure_at_destroy = then_schedule_closure; - really_destroy_stream(s); + really_destroy_stream(exec_ctx, s); } -static void destroy_transport(grpc_transport* gt) { +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "destroy_transport %p", t); gpr_mu_lock(&t->mu->mu); - close_transport_locked(t); + close_transport_locked(exec_ctx, t); gpr_mu_unlock(&t->mu->mu); - unref_transport(t->other_side); - unref_transport(t); + unref_transport(exec_ctx, t->other_side); + unref_transport(exec_ctx, t); } /******************************************************************************* * INTEGRATION GLUE */ -static void set_pollset(grpc_transport* gt, grpc_stream* gs, - grpc_pollset* pollset) { +static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) { // Nothing to do here } -static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, - grpc_pollset_set* pollset_set) { +static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset_set* pollset_set) { // Nothing to do here } -static grpc_endpoint* get_endpoint(grpc_transport* t) { return nullptr; } +static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* t) { + return nullptr; +} /******************************************************************************* * GLOBAL INIT AND DESTROY */ -static void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, nullptr, grpc_schedule_on_exec_ctx); g_empty_slice = grpc_slice_from_static_buffer(nullptr, 0); grpc_slice key_tmp = grpc_slice_from_static_string(":path"); g_fake_path_key = grpc_slice_intern(key_tmp); - grpc_slice_unref_internal(key_tmp); + grpc_slice_unref_internal(&exec_ctx, key_tmp); g_fake_path_value = grpc_slice_from_static_string("/"); grpc_slice auth_tmp = grpc_slice_from_static_string(":authority"); g_fake_auth_key = grpc_slice_intern(auth_tmp); - grpc_slice_unref_internal(auth_tmp); + grpc_slice_unref_internal(&exec_ctx, auth_tmp); g_fake_auth_value = grpc_slice_from_static_string("inproc-fail"); + grpc_exec_ctx_finish(&exec_ctx); } static const grpc_transport_vtable inproc_vtable = { @@ -1146,7 +1175,8 @@ static const grpc_transport_vtable inproc_vtable = { /******************************************************************************* * Main inproc transport functions */ -static void inproc_transports_create(grpc_transport** server_transport, +static void inproc_transports_create(grpc_exec_ctx* exec_ctx, + grpc_transport** server_transport, const grpc_channel_args* server_args, grpc_transport** client_transport, const grpc_channel_args* client_args) { @@ -1183,7 +1213,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, GRPC_API_TRACE("grpc_inproc_channel_create(server=%p, args=%p)", 2, (server, args)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const grpc_channel_args* server_args = grpc_server_get_channel_args(server); @@ -1198,26 +1228,30 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, grpc_transport* server_transport; grpc_transport* client_transport; - inproc_transports_create(&server_transport, server_args, &client_transport, - client_args); + inproc_transports_create(&exec_ctx, &server_transport, server_args, + &client_transport, client_args); - grpc_server_setup_transport(server, server_transport, nullptr, server_args); - grpc_channel* channel = grpc_channel_create( - "inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport); + grpc_server_setup_transport(&exec_ctx, server, server_transport, nullptr, + server_args); + grpc_channel* channel = + grpc_channel_create(&exec_ctx, "inproc", client_args, + GRPC_CLIENT_DIRECT_CHANNEL, client_transport); // Free up created channel args - grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(&exec_ctx, client_args); // Now finish scheduled operations + grpc_exec_ctx_finish(&exec_ctx); return channel; } void grpc_inproc_transport_shutdown(void) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_unref_internal(g_empty_slice); - grpc_slice_unref_internal(g_fake_path_key); - grpc_slice_unref_internal(g_fake_path_value); - grpc_slice_unref_internal(g_fake_auth_key); - grpc_slice_unref_internal(g_fake_auth_value); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, g_empty_slice); + grpc_slice_unref_internal(&exec_ctx, g_fake_path_key); + grpc_slice_unref_internal(&exec_ctx, g_fake_path_value); + grpc_slice_unref_internal(&exec_ctx, g_fake_auth_key); + grpc_slice_unref_internal(&exec_ctx, g_fake_auth_value); + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index da3b9b1b2d..dc754ddd82 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -32,11 +32,12 @@ void grpc_backoff_init(grpc_backoff* backoff, grpc_millis initial_backoff, backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; } -grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff) { +grpc_backoff_result grpc_backoff_begin(grpc_exec_ctx* exec_ctx, + grpc_backoff* backoff) { backoff->current_backoff = backoff->initial_backoff; const grpc_millis initial_timeout = GPR_MAX(backoff->initial_backoff, backoff->min_connect_timeout); - const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + const grpc_millis now = grpc_exec_ctx_now(exec_ctx); const grpc_backoff_result result = {now + initial_timeout, now + backoff->current_backoff}; return result; @@ -56,7 +57,8 @@ static double generate_uniform_random_number_between(uint32_t* rng_state, return a + generate_uniform_random_number(rng_state) * range; } -grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff) { +grpc_backoff_result grpc_backoff_step(grpc_exec_ctx* exec_ctx, + grpc_backoff* backoff) { backoff->current_backoff = (grpc_millis)(GPR_MIN( backoff->current_backoff * backoff->multiplier, backoff->max_backoff)); const double jitter = generate_uniform_random_number_between( @@ -67,7 +69,7 @@ grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff) { backoff->min_connect_timeout); const grpc_millis next_timeout = GPR_MIN( (grpc_millis)(backoff->current_backoff + jitter), backoff->max_backoff); - const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + const grpc_millis now = grpc_exec_ctx_now(exec_ctx); const grpc_backoff_result result = {now + current_timeout, now + next_timeout}; return result; diff --git a/src/core/lib/backoff/backoff.h b/src/core/lib/backoff/backoff.h index f61d14ec95..0da9082e70 100644 --- a/src/core/lib/backoff/backoff.h +++ b/src/core/lib/backoff/backoff.h @@ -60,11 +60,13 @@ void grpc_backoff_init(grpc_backoff* backoff, grpc_millis initial_backoff, /// Begin retry loop: returns the deadlines to be used for the current attempt /// and the subsequent retry, if any. -grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff); +grpc_backoff_result grpc_backoff_begin(grpc_exec_ctx* exec_ctx, + grpc_backoff* backoff); /// Step a retry loop: returns the deadlines to be used for the current attempt /// and the subsequent retry, if any. -grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff); +grpc_backoff_result grpc_backoff_step(grpc_exec_ctx* exec_ctx, + grpc_backoff* backoff); /// Reset the backoff, so the next grpc_backoff_step will be a /// grpc_backoff_begin. diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 578475b248..735fcbe405 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -188,7 +188,7 @@ grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { return b; } -void grpc_channel_args_destroy(grpc_channel_args* a) { +void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a) { size_t i; if (!a) return; for (i = 0; i < a->num_args; i++) { @@ -199,7 +199,8 @@ void grpc_channel_args_destroy(grpc_channel_args* a) { case GRPC_ARG_INTEGER: break; case GRPC_ARG_POINTER: - a->args[i].value.pointer.vtable->destroy(a->args[i].value.pointer.p); + a->args[i].value.pointer.vtable->destroy(exec_ctx, + a->args[i].value.pointer.p); break; } gpr_free(a->args[i].key); @@ -298,7 +299,8 @@ static int find_stream_compression_algorithm_states_bitset( } grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( - grpc_channel_args** a, grpc_compression_algorithm algorithm, int state) { + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, + grpc_compression_algorithm algorithm, int state) { int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = @@ -331,15 +333,15 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); - grpc_channel_args_destroy(*a); + grpc_channel_args_destroy(exec_ctx, *a); *a = result; } return result; } grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, - int state) { + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, + grpc_stream_compression_algorithm algorithm, int state) { int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = @@ -373,7 +375,7 @@ grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); - grpc_channel_args_destroy(*a); + grpc_channel_args_destroy(exec_ctx, *a); *a = result; } return result; diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index 9c7d06f34e..f6cb7fa73d 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -53,7 +53,7 @@ grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, const grpc_channel_args* b); /** Destroy arguments created by \a grpc_channel_args_copy */ -void grpc_channel_args_destroy(grpc_channel_args* a); +void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a); /** Returns the compression algorithm set in \a a. */ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( @@ -85,7 +85,8 @@ grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( * modified to point to the returned instance (which may be different from the * input value of \a a). */ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( - grpc_channel_args** a, grpc_compression_algorithm algorithm, int enabled); + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, + grpc_compression_algorithm algorithm, int enabled); /** Sets the support for the given stream compression algorithm. By default, all * stream compression algorithms are enabled. It's an error to disable an @@ -95,8 +96,8 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( * modified to point to the returned instance (which may be different from the * input value of \a a). */ grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, - int enabled); + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, + grpc_stream_compression_algorithm algorithm, int enabled); /** Returns the bitset representing the support state (true for enabled, false * for disabled) for compression algorithms. diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 195fe0b195..7629d18789 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -88,8 +88,8 @@ grpc_call_element* grpc_call_stack_element(grpc_call_stack* call_stack, } grpc_error* grpc_channel_stack_init( - int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, - const grpc_channel_filter** filters, size_t filter_count, + grpc_exec_ctx* exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, + void* destroy_arg, const grpc_channel_filter** filters, size_t filter_count, const grpc_channel_args* channel_args, grpc_transport* optional_transport, const char* name, grpc_channel_stack* stack) { size_t call_size = @@ -117,7 +117,8 @@ grpc_error* grpc_channel_stack_init( args.is_last = i == (filter_count - 1); elems[i].filter = filters[i]; elems[i].channel_data = user_data; - grpc_error* error = elems[i].filter->init_channel_elem(&elems[i], &args); + grpc_error* error = + elems[i].filter->init_channel_elem(exec_ctx, &elems[i], &args); if (error != GRPC_ERROR_NONE) { if (first_error == GRPC_ERROR_NONE) { first_error = error; @@ -137,18 +138,20 @@ grpc_error* grpc_channel_stack_init( return first_error; } -void grpc_channel_stack_destroy(grpc_channel_stack* stack) { +void grpc_channel_stack_destroy(grpc_exec_ctx* exec_ctx, + grpc_channel_stack* stack) { grpc_channel_element* channel_elems = CHANNEL_ELEMS_FROM_STACK(stack); size_t count = stack->count; size_t i; /* destroy per-filter data */ for (i = 0; i < count; i++) { - channel_elems[i].filter->destroy_channel_elem(&channel_elems[i]); + channel_elems[i].filter->destroy_channel_elem(exec_ctx, &channel_elems[i]); } } -grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, +grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, + grpc_channel_stack* channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, const grpc_call_element_args* elem_args) { @@ -171,8 +174,8 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, call_elems[i].filter = channel_elems[i].filter; call_elems[i].channel_data = channel_elems[i].channel_data; call_elems[i].call_data = user_data; - grpc_error* error = - call_elems[i].filter->init_call_elem(&call_elems[i], elem_args); + grpc_error* error = call_elems[i].filter->init_call_elem( + exec_ctx, &call_elems[i], elem_args); if (error != GRPC_ERROR_NONE) { if (first_error == GRPC_ERROR_NONE) { first_error = error; @@ -186,7 +189,8 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, return first_error; } -void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, +void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_stack* call_stack, grpc_polling_entity* pollent) { size_t count = call_stack->count; grpc_call_element* call_elems; @@ -199,16 +203,18 @@ void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, /* init per-filter data */ for (i = 0; i < count; i++) { - call_elems[i].filter->set_pollset_or_pollset_set(&call_elems[i], pollent); + call_elems[i].filter->set_pollset_or_pollset_set(exec_ctx, &call_elems[i], + pollent); user_data += ROUND_UP_TO_ALIGNMENT_SIZE(call_elems[i].filter->sizeof_call_data); } } void grpc_call_stack_ignore_set_pollset_or_pollset_set( - grpc_call_element* elem, grpc_polling_entity* pollent) {} + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_polling_entity* pollent) {} -void grpc_call_stack_destroy(grpc_call_stack* stack, +void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { grpc_call_element* elems = CALL_ELEMS_FROM_STACK(stack); @@ -218,27 +224,29 @@ void grpc_call_stack_destroy(grpc_call_stack* stack, /* destroy per-filter data */ for (i = 0; i < count; i++) { elems[i].filter->destroy_call_elem( - &elems[i], final_info, + exec_ctx, &elems[i], final_info, i == count - 1 ? then_schedule_closure : nullptr); } } -void grpc_call_next_op(grpc_call_element* elem, +void grpc_call_next_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op_batch* op) { grpc_call_element* next_elem = elem + 1; GRPC_CALL_LOG_OP(GPR_INFO, next_elem, op); - next_elem->filter->start_transport_stream_op_batch(next_elem, op); + next_elem->filter->start_transport_stream_op_batch(exec_ctx, next_elem, op); } -void grpc_channel_next_get_info(grpc_channel_element* elem, +void grpc_channel_next_get_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* channel_info) { grpc_channel_element* next_elem = elem + 1; - next_elem->filter->get_channel_info(next_elem, channel_info); + next_elem->filter->get_channel_info(exec_ctx, next_elem, channel_info); } -void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op) { +void grpc_channel_next_op(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op) { grpc_channel_element* next_elem = elem + 1; - next_elem->filter->start_transport_op(next_elem, op); + next_elem->filter->start_transport_op(exec_ctx, next_elem, op); } grpc_channel_stack* grpc_channel_stack_from_top_element( diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 716866be26..1b6e5396a5 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -96,12 +96,14 @@ typedef struct { typedef struct { /* Called to eg. send/receive data on a call. See grpc_call_next_op on how to call the next element in the stack */ - void (*start_transport_stream_op_batch)(grpc_call_element* elem, + void (*start_transport_stream_op_batch)(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* op); /* Called to handle channel level operations - e.g. new calls, or transport closure. See grpc_channel_next_op on how to call the next element in the stack */ - void (*start_transport_op)(grpc_channel_element* elem, grpc_transport_op* op); + void (*start_transport_op)(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op); /* sizeof(per call data) */ size_t sizeof_call_data; @@ -114,9 +116,11 @@ typedef struct { transport and is on the server. Most filters want to ignore this argument. Implementations may assume that elem->call_data is all zeros. */ - grpc_error* (*init_call_elem)(grpc_call_element* elem, + grpc_error* (*init_call_elem)(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args); - void (*set_pollset_or_pollset_set)(grpc_call_element* elem, + void (*set_pollset_or_pollset_set)(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent); /* Destroy per call data. The filter does not need to do any chaining. @@ -124,7 +128,7 @@ typedef struct { \a then_schedule_closure that should be passed to GRPC_CLOSURE_SCHED when destruction is complete. \a final_info contains data about the completed call, mainly for reporting purposes. */ - void (*destroy_call_elem)(grpc_call_element* elem, + void (*destroy_call_elem)(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure); @@ -137,14 +141,16 @@ typedef struct { useful for asserting correct configuration by upper layer code. The filter does not need to do any chaining. Implementations may assume that elem->call_data is all zeros. */ - grpc_error* (*init_channel_elem)(grpc_channel_element* elem, + grpc_error* (*init_channel_elem)(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args); /* Destroy per channel data. The filter does not need to do any chaining */ - void (*destroy_channel_elem)(grpc_channel_element* elem); + void (*destroy_channel_elem)(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem); /* Implement grpc_channel_get_info() */ - void (*get_channel_info)(grpc_channel_element* elem, + void (*get_channel_info)(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, const grpc_channel_info* channel_info); /* The name of this filter */ @@ -202,62 +208,68 @@ size_t grpc_channel_stack_size(const grpc_channel_filter** filters, size_t filter_count); /* Initialize a channel stack given some filters */ grpc_error* grpc_channel_stack_init( - int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, - const grpc_channel_filter** filters, size_t filter_count, + grpc_exec_ctx* exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, + void* destroy_arg, const grpc_channel_filter** filters, size_t filter_count, const grpc_channel_args* args, grpc_transport* optional_transport, const char* name, grpc_channel_stack* stack); /* Destroy a channel stack */ -void grpc_channel_stack_destroy(grpc_channel_stack* stack); +void grpc_channel_stack_destroy(grpc_exec_ctx* exec_ctx, + grpc_channel_stack* stack); /* Initialize a call stack given a channel stack. transport_server_data is expected to be NULL on a client, or an opaque transport owned pointer on the server. */ -grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, +grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, + grpc_channel_stack* channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, const grpc_call_element_args* elem_args); /* Set a pollset or a pollset_set for a call stack: must occur before the first * op is started */ -void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, +void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_stack* call_stack, grpc_polling_entity* pollent); #ifndef NDEBUG #define GRPC_CALL_STACK_REF(call_stack, reason) \ grpc_stream_ref(&(call_stack)->refcount, reason) -#define GRPC_CALL_STACK_UNREF(call_stack, reason) \ - grpc_stream_unref(&(call_stack)->refcount, reason) +#define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ + grpc_stream_unref(exec_ctx, &(call_stack)->refcount, reason) #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ grpc_stream_ref(&(channel_stack)->refcount, reason) -#define GRPC_CHANNEL_STACK_UNREF(channel_stack, reason) \ - grpc_stream_unref(&(channel_stack)->refcount, reason) +#define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ + grpc_stream_unref(exec_ctx, &(channel_stack)->refcount, reason) #else #define GRPC_CALL_STACK_REF(call_stack, reason) \ grpc_stream_ref(&(call_stack)->refcount) -#define GRPC_CALL_STACK_UNREF(call_stack, reason) \ - grpc_stream_unref(&(call_stack)->refcount) +#define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ + grpc_stream_unref(exec_ctx, &(call_stack)->refcount) #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ grpc_stream_ref(&(channel_stack)->refcount) -#define GRPC_CHANNEL_STACK_UNREF(channel_stack, reason) \ - grpc_stream_unref(&(channel_stack)->refcount) +#define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ + grpc_stream_unref(exec_ctx, &(channel_stack)->refcount) #endif /* Destroy a call stack */ -void grpc_call_stack_destroy(grpc_call_stack* stack, +void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure); /* Ignore set pollset{_set} - used by filters if they don't care about pollsets * at all. Does nothing. */ void grpc_call_stack_ignore_set_pollset_or_pollset_set( - grpc_call_element* elem, grpc_polling_entity* pollent); + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_polling_entity* pollent); /* Call the next operation in a call stack */ -void grpc_call_next_op(grpc_call_element* elem, +void grpc_call_next_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op_batch* op); /* Call the next operation (depending on call directionality) in a channel stack */ -void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op); +void grpc_channel_next_op(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op); /* Pass through a request to get_channel_info() to the next child element */ -void grpc_channel_next_get_info(grpc_channel_element* elem, +void grpc_channel_next_get_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* channel_info); /* Given the top element of a channel stack, get the channel stack itself */ diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index fcba826644..77b7854f94 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -150,9 +150,10 @@ void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder* builder, } void grpc_channel_stack_builder_set_channel_arguments( - grpc_channel_stack_builder* builder, const grpc_channel_args* args) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + const grpc_channel_args* args) { if (builder->args != nullptr) { - grpc_channel_args_destroy(builder->args); + grpc_channel_args_destroy(exec_ctx, builder->args); } builder->args = grpc_channel_args_copy(args); } @@ -240,7 +241,8 @@ bool grpc_channel_stack_builder_add_filter_after( return true; } -void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder* builder) { +void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder) { filter_node* p = builder->begin.next; while (p != &builder->end) { filter_node* next = p->next; @@ -248,15 +250,16 @@ void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder* builder) { p = next; } if (builder->args != nullptr) { - grpc_channel_args_destroy(builder->args); + grpc_channel_args_destroy(exec_ctx, builder->args); } gpr_free(builder->target); gpr_free(builder); } grpc_error* grpc_channel_stack_builder_finish( - grpc_channel_stack_builder* builder, size_t prefix_bytes, int initial_refs, - grpc_iomgr_cb_func destroy, void* destroy_arg, void** result) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + size_t prefix_bytes, int initial_refs, grpc_iomgr_cb_func destroy, + void* destroy_arg, void** result) { // count the number of filters size_t num_filters = 0; for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) { @@ -281,12 +284,12 @@ grpc_error* grpc_channel_stack_builder_finish( (grpc_channel_stack*)((char*)(*result) + prefix_bytes); // and initialize it grpc_error* error = grpc_channel_stack_init( - initial_refs, destroy, destroy_arg == nullptr ? *result : destroy_arg, - filters, num_filters, builder->args, builder->transport, builder->name, - channel_stack); + exec_ctx, initial_refs, destroy, + destroy_arg == nullptr ? *result : destroy_arg, filters, num_filters, + builder->args, builder->transport, builder->name, channel_stack); if (error != GRPC_ERROR_NONE) { - grpc_channel_stack_destroy(channel_stack); + grpc_channel_stack_destroy(exec_ctx, channel_stack); gpr_free(*result); *result = nullptr; } else { @@ -302,7 +305,7 @@ grpc_error* grpc_channel_stack_builder_finish( } } - grpc_channel_stack_builder_destroy(builder); + grpc_channel_stack_builder_destroy(exec_ctx, builder); gpr_free((grpc_channel_filter**)filters); return error; diff --git a/src/core/lib/channel/channel_stack_builder.h b/src/core/lib/channel/channel_stack_builder.h index d00ddc698c..10019542b1 100644 --- a/src/core/lib/channel/channel_stack_builder.h +++ b/src/core/lib/channel/channel_stack_builder.h @@ -54,7 +54,8 @@ grpc_transport* grpc_channel_stack_builder_get_transport( /// Set channel arguments: copies args void grpc_channel_stack_builder_set_channel_arguments( - grpc_channel_stack_builder* builder, const grpc_channel_args* args); + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + const grpc_channel_args* args); /// Return a borrowed pointer to the channel arguments const grpc_channel_args* grpc_channel_stack_builder_get_channel_arguments( @@ -147,11 +148,13 @@ void grpc_channel_stack_builder_iterator_destroy( /// \a initial_refs, \a destroy, \a destroy_arg are as per /// grpc_channel_stack_init grpc_error* grpc_channel_stack_builder_finish( - grpc_channel_stack_builder* builder, size_t prefix_bytes, int initial_refs, - grpc_iomgr_cb_func destroy, void* destroy_arg, void** result); + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + size_t prefix_bytes, int initial_refs, grpc_iomgr_cb_func destroy, + void* destroy_arg, void** result); /// Destroy the builder without creating a channel stack -void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder* builder); +void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder); extern grpc_core::TraceFlag grpc_trace_channel_stack_builder; diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index 9d07cfff4e..af2f88ab2e 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -51,14 +51,17 @@ typedef struct connected_channel_call_data { callback_state recv_message_ready; } call_data; -static void run_in_call_combiner(void* arg, grpc_error* error) { +static void run_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { callback_state* state = (callback_state*)arg; - GRPC_CALL_COMBINER_START(state->call_combiner, state->original_closure, - GRPC_ERROR_REF(error), state->reason); + GRPC_CALL_COMBINER_START(exec_ctx, state->call_combiner, + state->original_closure, GRPC_ERROR_REF(error), + state->reason); } -static void run_cancel_in_call_combiner(void* arg, grpc_error* error) { - run_in_call_combiner(arg, error); +static void run_cancel_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + run_in_call_combiner(exec_ctx, arg, error); gpr_free(arg); } @@ -95,7 +98,8 @@ static callback_state* get_state_for_batch( /* Intercept a call operation and either push it directly up or translate it into transport stream operations */ static void con_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (batch->recv_initial_metadata) { @@ -122,52 +126,58 @@ static void con_start_transport_stream_op_batch( callback_state* state = get_state_for_batch(calld, batch); intercept_callback(calld, state, false, "on_complete", &batch->on_complete); } - grpc_transport_perform_stream_op( - chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), batch); - GRPC_CALL_COMBINER_STOP(calld->call_combiner, "passed batch to transport"); + grpc_transport_perform_stream_op(exec_ctx, chand->transport, + TRANSPORT_STREAM_FROM_CALL_DATA(calld), + batch); + GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, + "passed batch to transport"); } -static void con_start_transport_op(grpc_channel_element* elem, +static void con_start_transport_op(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) { channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_perform_op(chand->transport, op); + grpc_transport_perform_op(exec_ctx, chand->transport, op); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; calld->call_combiner = args->call_combiner; int r = grpc_transport_init_stream( - chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), + exec_ctx, chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), &args->call_stack->refcount, args->server_transport_data, args->arena); return r == 0 ? GRPC_ERROR_NONE : GRPC_ERROR_CREATE_FROM_STATIC_STRING( "transport stream initialization failed"); } -static void set_pollset_or_pollset_set(grpc_call_element* elem, +static void set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_set_pops(chand->transport, + grpc_transport_set_pops(exec_ctx, chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), pollent); } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_destroy_stream(chand->transport, + grpc_transport_destroy_stream(exec_ctx, chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), then_schedule_closure); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* cd = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); @@ -176,15 +186,17 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel_data */ -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { channel_data* cd = (channel_data*)elem->channel_data; if (cd->transport) { - grpc_transport_destroy(cd->transport); + grpc_transport_destroy(exec_ctx, cd->transport); } } /* No-op. */ -static void con_get_channel_info(grpc_channel_element* elem, +static void con_get_channel_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* channel_info) {} const grpc_channel_filter grpc_connected_filter = { @@ -218,7 +230,8 @@ static void bind_transport(grpc_channel_stack* channel_stack, grpc_transport_stream_size((grpc_transport*)t); } -bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, +bool grpc_add_connected_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg_must_be_null) { GPR_ASSERT(arg_must_be_null == nullptr); grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); diff --git a/src/core/lib/channel/connected_channel.h b/src/core/lib/channel/connected_channel.h index 91de8022db..cab8aad154 100644 --- a/src/core/lib/channel/connected_channel.h +++ b/src/core/lib/channel/connected_channel.h @@ -23,7 +23,8 @@ extern const grpc_channel_filter grpc_connected_filter; -bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, +bool grpc_add_connected_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg_must_be_null); /* Debug helper to dig the transport stream out of a call element */ diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc index dcb149c03e..58c30b165b 100644 --- a/src/core/lib/channel/handshaker.cc +++ b/src/core/lib/channel/handshaker.cc @@ -34,20 +34,23 @@ void grpc_handshaker_init(const grpc_handshaker_vtable* vtable, handshaker->vtable = vtable; } -void grpc_handshaker_destroy(grpc_handshaker* handshaker) { - handshaker->vtable->destroy(handshaker); +void grpc_handshaker_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker) { + handshaker->vtable->destroy(exec_ctx, handshaker); } -void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) { - handshaker->vtable->shutdown(handshaker, why); +void grpc_handshaker_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_error* why) { + handshaker->vtable->shutdown(exec_ctx, handshaker, why); } -void grpc_handshaker_do_handshake(grpc_handshaker* handshaker, +void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - handshaker->vtable->do_handshake(handshaker, acceptor, on_handshake_done, - args); + handshaker->vtable->do_handshake(exec_ctx, handshaker, acceptor, + on_handshake_done, args); } // @@ -113,9 +116,9 @@ void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, } void grpc_handshake_manager_pending_list_shutdown_all( - grpc_handshake_manager* head, grpc_error* why) { + grpc_exec_ctx* exec_ctx, grpc_handshake_manager* head, grpc_error* why) { while (head != nullptr) { - grpc_handshake_manager_shutdown(head, GRPC_ERROR_REF(why)); + grpc_handshake_manager_shutdown(exec_ctx, head, GRPC_ERROR_REF(why)); head = head->next; } GRPC_ERROR_UNREF(why); @@ -142,10 +145,11 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr, gpr_mu_unlock(&mgr->mu); } -static void grpc_handshake_manager_unref(grpc_handshake_manager* mgr) { +static void grpc_handshake_manager_unref(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr) { if (gpr_unref(&mgr->refs)) { for (size_t i = 0; i < mgr->count; ++i) { - grpc_handshaker_destroy(mgr->handshakers[i]); + grpc_handshaker_destroy(exec_ctx, mgr->handshakers[i]); } gpr_free(mgr->handshakers); gpr_mu_destroy(&mgr->mu); @@ -153,17 +157,19 @@ static void grpc_handshake_manager_unref(grpc_handshake_manager* mgr) { } } -void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr) { - grpc_handshake_manager_unref(mgr); +void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr) { + grpc_handshake_manager_unref(exec_ctx, mgr); } -void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, +void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr, grpc_error* why) { gpr_mu_lock(&mgr->mu); // Shutdown the handshaker that's currently in progress, if any. if (!mgr->shutdown && mgr->index > 0) { mgr->shutdown = true; - grpc_handshaker_shutdown(mgr->handshakers[mgr->index - 1], + grpc_handshaker_shutdown(exec_ctx, mgr->handshakers[mgr->index - 1], GRPC_ERROR_REF(why)); } gpr_mu_unlock(&mgr->mu); @@ -173,7 +179,8 @@ void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, // Helper function to call either the next handshaker or the // on_handshake_done callback. // Returns true if we've scheduled the on_handshake_done callback. -static bool call_next_handshaker_locked(grpc_handshake_manager* mgr, +static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr, grpc_error* error) { GPR_ASSERT(mgr->index <= mgr->count); // If we got an error or we've been shut down or we're exiting early or @@ -183,12 +190,13 @@ static bool call_next_handshaker_locked(grpc_handshake_manager* mgr, mgr->index == mgr->count) { // Cancel deadline timer, since we're invoking the on_handshake_done // callback now. - grpc_timer_cancel(&mgr->deadline_timer); - GRPC_CLOSURE_SCHED(&mgr->on_handshake_done, error); + grpc_timer_cancel(exec_ctx, &mgr->deadline_timer); + GRPC_CLOSURE_SCHED(exec_ctx, &mgr->on_handshake_done, error); mgr->shutdown = true; } else { - grpc_handshaker_do_handshake(mgr->handshakers[mgr->index], mgr->acceptor, - &mgr->call_next_handshaker, &mgr->args); + grpc_handshaker_do_handshake(exec_ctx, mgr->handshakers[mgr->index], + mgr->acceptor, &mgr->call_next_handshaker, + &mgr->args); } ++mgr->index; return mgr->shutdown; @@ -196,34 +204,37 @@ static bool call_next_handshaker_locked(grpc_handshake_manager* mgr, // A function used as the handshaker-done callback when chaining // handshakers together. -static void call_next_handshaker(void* arg, grpc_error* error) { +static void call_next_handshaker(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; gpr_mu_lock(&mgr->mu); - bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_REF(error)); + bool done = call_next_handshaker_locked(exec_ctx, mgr, GRPC_ERROR_REF(error)); gpr_mu_unlock(&mgr->mu); // If we're invoked the final callback, we won't be coming back // to this function, so we can release our reference to the // handshake manager. if (done) { - grpc_handshake_manager_unref(mgr); + grpc_handshake_manager_unref(exec_ctx, mgr); } } // Callback invoked when deadline is exceeded. -static void on_timeout(void* arg, grpc_error* error) { +static void on_timeout(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; if (error == GRPC_ERROR_NONE) { // Timer fired, rather than being cancelled. grpc_handshake_manager_shutdown( - mgr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); + exec_ctx, mgr, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); } - grpc_handshake_manager_unref(mgr); + grpc_handshake_manager_unref(exec_ctx, mgr); } void grpc_handshake_manager_do_handshake( - grpc_handshake_manager* mgr, grpc_pollset_set* interested_parties, - grpc_endpoint* endpoint, const grpc_channel_args* channel_args, - grpc_millis deadline, grpc_tcp_server_acceptor* acceptor, - grpc_iomgr_cb_func on_handshake_done, void* user_data) { + grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, + grpc_pollset_set* interested_parties, grpc_endpoint* endpoint, + const grpc_channel_args* channel_args, grpc_millis deadline, + grpc_tcp_server_acceptor* acceptor, grpc_iomgr_cb_func on_handshake_done, + void* user_data) { gpr_mu_lock(&mgr->mu); GPR_ASSERT(mgr->index == 0); GPR_ASSERT(!mgr->shutdown); @@ -246,12 +257,12 @@ void grpc_handshake_manager_do_handshake( gpr_ref(&mgr->refs); GRPC_CLOSURE_INIT(&mgr->on_timeout, on_timeout, mgr, grpc_schedule_on_exec_ctx); - grpc_timer_init(&mgr->deadline_timer, deadline, &mgr->on_timeout); + grpc_timer_init(exec_ctx, &mgr->deadline_timer, deadline, &mgr->on_timeout); // Start first handshaker, which also owns a ref. gpr_ref(&mgr->refs); - bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_NONE); + bool done = call_next_handshaker_locked(exec_ctx, mgr, GRPC_ERROR_NONE); gpr_mu_unlock(&mgr->mu); if (done) { - grpc_handshake_manager_unref(mgr); + grpc_handshake_manager_unref(exec_ctx, mgr); } } diff --git a/src/core/lib/channel/handshaker.h b/src/core/lib/channel/handshaker.h index 68e5463123..8e4114dc64 100644 --- a/src/core/lib/channel/handshaker.h +++ b/src/core/lib/channel/handshaker.h @@ -68,17 +68,18 @@ typedef struct { typedef struct { /// Destroys the handshaker. - void (*destroy)(grpc_handshaker* handshaker); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker); /// Shuts down the handshaker (e.g., to clean up when the operation is /// aborted in the middle). - void (*shutdown)(grpc_handshaker* handshaker, grpc_error* why); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker, + grpc_error* why); /// Performs handshaking, modifying \a args as needed (e.g., to /// replace \a endpoint with a wrapped endpoint). /// When finished, invokes \a on_handshake_done. /// \a acceptor will be NULL for client-side handshakers. - void (*do_handshake)(grpc_handshaker* handshaker, + void (*do_handshake)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args); @@ -94,9 +95,12 @@ struct grpc_handshaker { void grpc_handshaker_init(const grpc_handshaker_vtable* vtable, grpc_handshaker* handshaker); -void grpc_handshaker_destroy(grpc_handshaker* handshaker); -void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why); -void grpc_handshaker_do_handshake(grpc_handshaker* handshaker, +void grpc_handshaker_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker); +void grpc_handshaker_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_error* why); +void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args); @@ -116,13 +120,15 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr, grpc_handshaker* handshaker); /// Destroys the handshake manager. -void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr); +void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr); /// Shuts down the handshake manager (e.g., to clean up when the operation is /// aborted in the middle). /// The caller must still call grpc_handshake_manager_destroy() after /// calling this function. -void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, +void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshake_manager* mgr, grpc_error* why); /// Invokes handshakers in the order they were added. @@ -140,10 +146,11 @@ void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, /// the necessary clean-up. Otherwise, the callback takes ownership of /// the arguments. void grpc_handshake_manager_do_handshake( - grpc_handshake_manager* mgr, grpc_pollset_set* interested_parties, - grpc_endpoint* endpoint, const grpc_channel_args* channel_args, - grpc_millis deadline, grpc_tcp_server_acceptor* acceptor, - grpc_iomgr_cb_func on_handshake_done, void* user_data); + grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, + grpc_pollset_set* interested_parties, grpc_endpoint* endpoint, + const grpc_channel_args* channel_args, grpc_millis deadline, + grpc_tcp_server_acceptor* acceptor, grpc_iomgr_cb_func on_handshake_done, + void* user_data); /// Add \a mgr to the server side list of all pending handshake managers, the /// list starts with \a *head. @@ -159,6 +166,6 @@ void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, /// Shutdown all pending handshake managers on the server side. // Not thread-safe. Caller needs to synchronize. void grpc_handshake_manager_pending_list_shutdown_all( - grpc_handshake_manager* head, grpc_error* why); + grpc_exec_ctx* exec_ctx, grpc_handshake_manager* head, grpc_error* why); #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_H */ diff --git a/src/core/lib/channel/handshaker_factory.cc b/src/core/lib/channel/handshaker_factory.cc index 2380d98300..015006ade0 100644 --- a/src/core/lib/channel/handshaker_factory.cc +++ b/src/core/lib/channel/handshaker_factory.cc @@ -21,19 +21,19 @@ #include void grpc_handshaker_factory_add_handshakers( - grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { if (handshaker_factory != nullptr) { GPR_ASSERT(handshaker_factory->vtable != nullptr); - handshaker_factory->vtable->add_handshakers(handshaker_factory, args, - handshake_mgr); + handshaker_factory->vtable->add_handshakers(exec_ctx, handshaker_factory, + args, handshake_mgr); } } void grpc_handshaker_factory_destroy( - grpc_handshaker_factory* handshaker_factory) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) { if (handshaker_factory != nullptr) { GPR_ASSERT(handshaker_factory->vtable != nullptr); - handshaker_factory->vtable->destroy(handshaker_factory); + handshaker_factory->vtable->destroy(exec_ctx, handshaker_factory); } } diff --git a/src/core/lib/channel/handshaker_factory.h b/src/core/lib/channel/handshaker_factory.h index 8a7c0157e8..ca7c26b50a 100644 --- a/src/core/lib/channel/handshaker_factory.h +++ b/src/core/lib/channel/handshaker_factory.h @@ -29,10 +29,12 @@ typedef struct grpc_handshaker_factory grpc_handshaker_factory; typedef struct { - void (*add_handshakers)(grpc_handshaker_factory* handshaker_factory, + void (*add_handshakers)(grpc_exec_ctx* exec_ctx, + grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); - void (*destroy)(grpc_handshaker_factory* handshaker_factory); + void (*destroy)(grpc_exec_ctx* exec_ctx, + grpc_handshaker_factory* handshaker_factory); } grpc_handshaker_factory_vtable; struct grpc_handshaker_factory { @@ -40,10 +42,10 @@ struct grpc_handshaker_factory { }; void grpc_handshaker_factory_add_handshakers( - grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr); + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); void grpc_handshaker_factory_destroy( - grpc_handshaker_factory* handshaker_factory); + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory); #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H */ diff --git a/src/core/lib/channel/handshaker_registry.cc b/src/core/lib/channel/handshaker_registry.cc index 098eabf084..c6bc87d704 100644 --- a/src/core/lib/channel/handshaker_registry.cc +++ b/src/core/lib/channel/handshaker_registry.cc @@ -47,17 +47,18 @@ static void grpc_handshaker_factory_list_register( } static void grpc_handshaker_factory_list_add_handshakers( - grpc_handshaker_factory_list* list, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { for (size_t i = 0; i < list->num_factories; ++i) { - grpc_handshaker_factory_add_handshakers(list->list[i], args, handshake_mgr); + grpc_handshaker_factory_add_handshakers(exec_ctx, list->list[i], args, + handshake_mgr); } } static void grpc_handshaker_factory_list_destroy( - grpc_handshaker_factory_list* list) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list) { for (size_t i = 0; i < list->num_factories; ++i) { - grpc_handshaker_factory_destroy(list->list[i]); + grpc_handshaker_factory_destroy(exec_ctx, list->list[i]); } gpr_free(list->list); } @@ -73,9 +74,10 @@ void grpc_handshaker_factory_registry_init() { memset(g_handshaker_factory_lists, 0, sizeof(g_handshaker_factory_lists)); } -void grpc_handshaker_factory_registry_shutdown() { +void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx) { for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; ++i) { - grpc_handshaker_factory_list_destroy(&g_handshaker_factory_lists[i]); + grpc_handshaker_factory_list_destroy(exec_ctx, + &g_handshaker_factory_lists[i]); } } @@ -86,9 +88,11 @@ void grpc_handshaker_factory_register(bool at_start, &g_handshaker_factory_lists[handshaker_type], at_start, factory); } -void grpc_handshakers_add(grpc_handshaker_type handshaker_type, +void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, + grpc_handshaker_type handshaker_type, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_handshaker_factory_list_add_handshakers( - &g_handshaker_factory_lists[handshaker_type], args, handshake_mgr); + exec_ctx, &g_handshaker_factory_lists[handshaker_type], args, + handshake_mgr); } diff --git a/src/core/lib/channel/handshaker_registry.h b/src/core/lib/channel/handshaker_registry.h index 0b05531b7e..a3b2ac1dc7 100644 --- a/src/core/lib/channel/handshaker_registry.h +++ b/src/core/lib/channel/handshaker_registry.h @@ -31,7 +31,7 @@ typedef enum { } grpc_handshaker_type; void grpc_handshaker_factory_registry_init(); -void grpc_handshaker_factory_registry_shutdown(); +void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx); /// Registers a new handshaker factory. Takes ownership. /// If \a at_start is true, the new handshaker will be at the beginning of @@ -40,7 +40,8 @@ void grpc_handshaker_factory_register(bool at_start, grpc_handshaker_type handshaker_type, grpc_handshaker_factory* factory); -void grpc_handshakers_add(grpc_handshaker_type handshaker_type, +void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, + grpc_handshaker_type handshaker_type, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index aa43a53f2b..c051e28864 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -29,8 +29,8 @@ #define OUTPUT_BLOCK_SIZE 1024 -static int zlib_body(z_stream* zs, grpc_slice_buffer* input, - grpc_slice_buffer* output, +static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs, + grpc_slice_buffer* input, grpc_slice_buffer* output, int (*flate)(z_stream* zs, int flush)) { int r; int flush; @@ -74,7 +74,7 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input, return 1; error: - grpc_slice_unref_internal(outbuf); + grpc_slice_unref_internal(exec_ctx, outbuf); return 0; } @@ -84,8 +84,8 @@ static void* zalloc_gpr(void* opaque, unsigned int items, unsigned int size) { static void zfree_gpr(void* opaque, void* address) { gpr_free(address); } -static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output, - int gzip) { +static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, + grpc_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; @@ -97,10 +97,11 @@ static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output, r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0), 8, Z_DEFAULT_STRATEGY); GPR_ASSERT(r == Z_OK); - r = zlib_body(&zs, input, output, deflate) && output->length < input->length; + r = zlib_body(exec_ctx, &zs, input, output, deflate) && + output->length < input->length; if (!r) { for (i = count_before; i < output->count; i++) { - grpc_slice_unref_internal(output->slices[i]); + grpc_slice_unref_internal(exec_ctx, output->slices[i]); } output->count = count_before; output->length = length_before; @@ -109,8 +110,8 @@ static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output, return r; } -static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output, - int gzip) { +static int zlib_decompress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, + grpc_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; @@ -121,10 +122,10 @@ static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output, zs.zfree = zfree_gpr; r = inflateInit2(&zs, 15 | (gzip ? 16 : 0)); GPR_ASSERT(r == Z_OK); - r = zlib_body(&zs, input, output, inflate); + r = zlib_body(exec_ctx, &zs, input, output, inflate); if (!r) { for (i = count_before; i < output->count; i++) { - grpc_slice_unref_internal(output->slices[i]); + grpc_slice_unref_internal(exec_ctx, output->slices[i]); } output->count = count_before; output->length = length_before; @@ -141,7 +142,8 @@ static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) { return 1; } -static int compress_inner(grpc_compression_algorithm algorithm, +static int compress_inner(grpc_exec_ctx* exec_ctx, + grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -149,9 +151,9 @@ static int compress_inner(grpc_compression_algorithm algorithm, rely on that here */ return 0; case GRPC_COMPRESS_DEFLATE: - return zlib_compress(input, output, 0); + return zlib_compress(exec_ctx, input, output, 0); case GRPC_COMPRESS_GZIP: - return zlib_compress(input, output, 1); + return zlib_compress(exec_ctx, input, output, 1); case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } @@ -159,24 +161,26 @@ static int compress_inner(grpc_compression_algorithm algorithm, return 0; } -int grpc_msg_compress(grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_exec_ctx* exec_ctx, + grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { - if (!compress_inner(algorithm, input, output)) { + if (!compress_inner(exec_ctx, algorithm, input, output)) { copy(input, output); return 0; } return 1; } -int grpc_msg_decompress(grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_exec_ctx* exec_ctx, + grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { case GRPC_COMPRESS_NONE: return copy(input, output); case GRPC_COMPRESS_DEFLATE: - return zlib_decompress(input, output, 0); + return zlib_decompress(exec_ctx, input, output, 0); case GRPC_COMPRESS_GZIP: - return zlib_decompress(input, output, 1); + return zlib_decompress(exec_ctx, input, output, 1); case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } diff --git a/src/core/lib/compression/message_compress.h b/src/core/lib/compression/message_compress.h index c963fccc73..ca8ca37f8e 100644 --- a/src/core/lib/compression/message_compress.h +++ b/src/core/lib/compression/message_compress.h @@ -25,13 +25,15 @@ /* compress 'input' to 'output' using 'algorithm'. On success, appends compressed slices to output and returns 1. On failure, appends uncompressed slices to output and returns 0. */ -int grpc_msg_compress(grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_exec_ctx* exec_ctx, + grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); /* decompress 'input' to 'output' using 'algorithm'. On success, appends slices to output and returns 1. On failure, output is unchanged, and returns 0. */ -int grpc_msg_decompress(grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_exec_ctx* exec_ctx, + grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); #endif /* GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H */ diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 9d829b31db..0c3fdd1269 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -40,7 +40,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, /* Full flush is not allowed when inflating. */ GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; int r; bool eoc = false; size_t original_max_output_size = max_output_size; @@ -57,8 +57,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, r = ctx->flate(&ctx->zs, Z_NO_FLUSH); if (r < 0 && r != Z_BUF_ERROR) { gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(slice_out); - + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); return false; } else if (r == Z_STREAM_END && ctx->flate == inflate) { eoc = true; @@ -69,7 +69,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in, GRPC_SLICE_LENGTH(slice))); } - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(&exec_ctx, slice); } if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) { GPR_ASSERT(in->length == 0); @@ -88,8 +88,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, break; default: gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(slice_out); - + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); return false; } } else if (flush == Z_FINISH) { @@ -104,8 +104,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, break; default: gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(slice_out); - + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); return false; } } @@ -117,11 +117,11 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, slice_out.data.refcounted.length -= ctx->zs.avail_out; grpc_slice_buffer_add(out, slice_out); } else { - grpc_slice_unref_internal(slice_out); + grpc_slice_unref_internal(&exec_ctx, slice_out); } max_output_size -= (slice_size - ctx->zs.avail_out); } - + grpc_exec_ctx_finish(&exec_ctx); if (end_of_context) { *end_of_context = eoc; } diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc index 0b39b2b1e7..7d2af71c47 100644 --- a/src/core/lib/debug/stats.cc +++ b/src/core/lib/debug/stats.cc @@ -62,9 +62,9 @@ void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a, } } -int grpc_stats_histo_find_bucket_slow(int value, const int* table, - int table_size) { - GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(); +int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx* exec_ctx, int value, + const int* table, int table_size) { + GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx); const int* const start = table; while (table_size > 0) { int step = table_size / 2; diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index 02eed5e844..55db44e0c2 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -30,15 +30,17 @@ typedef struct grpc_stats_data { extern grpc_stats_data* grpc_stats_per_cpu_storage; -#define GRPC_THREAD_STATS_DATA() \ - (&grpc_stats_per_cpu_storage[grpc_core::ExecCtx::Get()->starting_cpu()]) +#define GRPC_THREAD_STATS_DATA(exec_ctx) \ + (&grpc_stats_per_cpu_storage[(exec_ctx)->starting_cpu]) -#define GRPC_STATS_INC_COUNTER(ctr) \ - (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1)) +#define GRPC_STATS_INC_COUNTER(exec_ctx, ctr) \ + (gpr_atm_no_barrier_fetch_add( \ + &GRPC_THREAD_STATS_DATA((exec_ctx))->counters[(ctr)], 1)) -#define GRPC_STATS_INC_HISTOGRAM(histogram, index) \ - (gpr_atm_no_barrier_fetch_add( \ - &GRPC_THREAD_STATS_DATA()->histograms[histogram##_FIRST_SLOT + (index)], \ +#define GRPC_STATS_INC_HISTOGRAM(exec_ctx, histogram, index) \ + (gpr_atm_no_barrier_fetch_add( \ + &GRPC_THREAD_STATS_DATA((exec_ctx)) \ + ->histograms[histogram##_FIRST_SLOT + (index)], \ 1)) void grpc_stats_init(void); @@ -48,8 +50,8 @@ void grpc_stats_collect(grpc_stats_data* output); void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a, grpc_stats_data* c); char* grpc_stats_data_as_json(const grpc_stats_data* data); -int grpc_stats_histo_find_bucket_slow(int value, const int* table, - int table_size); +int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx* exec_ctx, int value, + const int* table, int table_size); double grpc_stats_histo_percentile(const grpc_stats_data* data, grpc_stats_histograms histogram, double percentile); diff --git a/src/core/lib/debug/stats_data.cc b/src/core/lib/debug/stats_data.cc index 996ed3de9a..17e15f4cfb 100644 --- a/src/core/lib/debug/stats_data.cc +++ b/src/core/lib/debug/stats_data.cc @@ -342,10 +342,11 @@ const uint8_t grpc_stats_table_7[102] = { 42, 42, 43, 44, 44, 45, 46, 46, 47, 48, 48, 49, 49, 50, 50, 51, 51}; const int grpc_stats_table_8[9] = {0, 1, 2, 4, 7, 13, 23, 39, 64}; const uint8_t grpc_stats_table_9[9] = {0, 0, 1, 2, 2, 3, 4, 4, 5}; -void grpc_stats_inc_call_initial_size(int value) { +void grpc_stats_inc_call_initial_size(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 262144); if (value < 6) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, + value); return; } union { @@ -358,17 +359,19 @@ void grpc_stats_inc_call_initial_size(int value) { grpc_stats_table_1[((_val.uint - 4618441417868443648ull) >> 49)] + 6; _bkt.dbl = grpc_stats_table_0[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_0, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_0, 64)); } -void grpc_stats_inc_poll_events_returned(int value) { +void grpc_stats_inc_poll_events_returned(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 29) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value); return; } union { @@ -381,17 +384,20 @@ void grpc_stats_inc_poll_events_returned(int value) { grpc_stats_table_3[((_val.uint - 4628855992006737920ull) >> 47)] + 29; _bkt.dbl = grpc_stats_table_2[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_2, 128)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_2, 128)); } -void grpc_stats_inc_tcp_write_size(int value) { +void grpc_stats_inc_tcp_write_size(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + value); return; } union { @@ -404,17 +410,19 @@ void grpc_stats_inc_tcp_write_size(int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_write_iov_size(int value) { +void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); return; } union { @@ -427,17 +435,19 @@ void grpc_stats_inc_tcp_write_iov_size(int value) { grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_tcp_read_size(int value) { +void grpc_stats_inc_tcp_read_size(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + value); return; } union { @@ -450,17 +460,19 @@ void grpc_stats_inc_tcp_read_size(int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_read_offer(int value) { +void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, + value); return; } union { @@ -473,18 +485,20 @@ void grpc_stats_inc_tcp_read_offer(int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_read_offer_iov_size(int value) { +void grpc_stats_inc_tcp_read_offer_iov_size(grpc_exec_ctx* exec_ctx, + int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, - value); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, value); return; } union { @@ -497,19 +511,21 @@ void grpc_stats_inc_tcp_read_offer_iov_size(int value) { grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, - bucket); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_message_size(int value) { +void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx* exec_ctx, + int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - value); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, value); return; } union { @@ -522,19 +538,22 @@ void grpc_stats_inc_http2_send_message_size(int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - bucket); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_http2_send_initial_metadata_per_write(int value) { +void grpc_stats_inc_http2_send_initial_metadata_per_write( + grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, value); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, + value); return; } union { @@ -548,18 +567,21 @@ void grpc_stats_inc_http2_send_initial_metadata_per_write(int value) { _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, bucket); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, + bucket); return; } GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, + grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_6, + 64)); } -void grpc_stats_inc_http2_send_message_per_write(int value) { +void grpc_stats_inc_http2_send_message_per_write(grpc_exec_ctx* exec_ctx, + int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, - value); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, value); return; } union { @@ -572,19 +594,22 @@ void grpc_stats_inc_http2_send_message_per_write(int value) { grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, - bucket); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_trailing_metadata_per_write(int value) { +void grpc_stats_inc_http2_send_trailing_metadata_per_write( + grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, value); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, + value); return; } union { @@ -598,18 +623,21 @@ void grpc_stats_inc_http2_send_trailing_metadata_per_write(int value) { _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, bucket); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, + bucket); return; } GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, + grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_6, + 64)); } -void grpc_stats_inc_http2_send_flowctl_per_write(int value) { +void grpc_stats_inc_http2_send_flowctl_per_write(grpc_exec_ctx* exec_ctx, + int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, - value); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, value); return; } union { @@ -622,18 +650,20 @@ void grpc_stats_inc_http2_send_flowctl_per_write(int value) { grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, - bucket); + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_server_cqs_checked(int value) { +void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx* exec_ctx, int value) { value = GPR_CLAMP(value, 0, 64); if (value < 3) { - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value); return; } union { @@ -646,12 +676,13 @@ void grpc_stats_inc_server_cqs_checked(int value) { grpc_stats_table_9[((_val.uint - 4613937818241073152ull) >> 51)] + 3; _bkt.dbl = grpc_stats_table_8[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, bucket); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, bucket); return; } - GRPC_STATS_INC_HISTOGRAM( - GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, - grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_8, 8)); + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, + grpc_stats_histo_find_bucket_slow( + (exec_ctx), value, grpc_stats_table_8, 8)); } const int grpc_stats_histo_buckets[13] = {64, 128, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 8}; @@ -663,7 +694,7 @@ const int* const grpc_stats_histo_bucket_boundaries[13] = { grpc_stats_table_6, grpc_stats_table_4, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_8}; -void (*const grpc_stats_inc_histogram[13])(int x) = { +void (*const grpc_stats_inc_histogram[13])(grpc_exec_ctx* exec_ctx, int x) = { grpc_stats_inc_call_initial_size, grpc_stats_inc_poll_events_returned, grpc_stats_inc_tcp_write_size, diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 4504be33e7..8a5bc97389 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -172,262 +172,330 @@ typedef enum { GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED_BUCKETS = 8, GRPC_STATS_HISTOGRAM_BUCKETS = 840 } grpc_stats_histogram_constants; -#define GRPC_STATS_INC_CLIENT_CALLS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) -#define GRPC_STATS_INC_SERVER_CALLS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) -#define GRPC_STATS_INC_CQS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQS_CREATED) -#define GRPC_STATS_INC_CLIENT_CHANNELS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_CHANNELS_CREATED) -#define GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_SUBCHANNELS_CREATED) -#define GRPC_STATS_INC_SERVER_CHANNELS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_CHANNELS_CREATED) -#define GRPC_STATS_INC_SYSCALL_POLL() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_POLL) -#define GRPC_STATS_INC_SYSCALL_WAIT() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_WAIT) -#define GRPC_STATS_INC_POLLSET_KICK() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK) -#define GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICKED_WITHOUT_POLLER) -#define GRPC_STATS_INC_POLLSET_KICKED_AGAIN() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICKED_AGAIN) -#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_FD) -#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_CV) -#define GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_OWN_THREAD) -#define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) -#define GRPC_STATS_INC_SYSCALL_WRITE() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_WRITE) -#define GRPC_STATS_INC_SYSCALL_READ() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_READ) -#define GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_TCP_BACKUP_POLLERS_CREATED) -#define GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_TCP_BACKUP_POLLER_POLLS) -#define GRPC_STATS_INC_HTTP2_OP_BATCHES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_BATCHES) -#define GRPC_STATS_INC_HTTP2_OP_CANCEL() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_CANCEL) -#define GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE) -#define GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE) -#define GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_SETTINGS_WRITES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_SETTINGS_WRITES) -#define GRPC_STATS_INC_HTTP2_PINGS_SENT() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_PINGS_SENT) -#define GRPC_STATS_INC_HTTP2_WRITES_BEGUN() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN) -#define GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_OFFLOADED) -#define GRPC_STATS_INC_HTTP2_WRITES_CONTINUED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_CONTINUED) -#define GRPC_STATS_INC_HTTP2_PARTIAL_WRITES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_PARTIAL_WRITES) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) +#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) +#define GRPC_STATS_INC_CQS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CQS_CREATED) +#define GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CHANNELS_CREATED) +#define GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_CLIENT_SUBCHANNELS_CREATED) +#define GRPC_STATS_INC_SERVER_CHANNELS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CHANNELS_CREATED) +#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) +#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) +#define GRPC_STATS_INC_POLLSET_KICK(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK) +#define GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_POLLSET_KICKED_WITHOUT_POLLER) +#define GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICKED_AGAIN) +#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_FD) +#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_CV) +#define GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_OWN_THREAD) +#define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) +#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_TCP_BACKUP_POLLERS_CREATED) +#define GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_TCP_BACKUP_POLLER_POLLS) +#define GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_BATCHES) +#define GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_CANCEL) +#define GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_SETTINGS_WRITES) +#define GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_PINGS_SENT) +#define GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN) +#define GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_OFFLOADED) +#define GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_CONTINUED) +#define GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_PARTIAL_WRITES) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL() \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(exec_ctx) \ GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL() \ + (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(exec_ctx) \ GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE() \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING( \ + exec_ctx) \ GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED( \ + exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM() \ - GRPC_STATS_INC_COUNTER( \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM) -#define GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_SPURIOUS_WRITES_BEGUN) -#define GRPC_STATS_INC_HPACK_RECV_INDEXED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_INDEXED) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_UNCOMPRESSED) -#define GRPC_STATS_INC_HPACK_RECV_HUFFMAN() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_HUFFMAN) -#define GRPC_STATS_INC_HPACK_RECV_BINARY() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_BINARY) -#define GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_BINARY_BASE64) -#define GRPC_STATS_INC_HPACK_SEND_INDEXED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_INDEXED) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX_V() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_UNCOMPRESSED) -#define GRPC_STATS_INC_HPACK_SEND_HUFFMAN() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_HUFFMAN) -#define GRPC_STATS_INC_HPACK_SEND_BINARY() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_BINARY) -#define GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_BINARY_BASE64) -#define GRPC_STATS_INC_COMBINER_LOCKS_INITIATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED) -#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS) -#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS() \ - GRPC_STATS_INC_COUNTER( \ - GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS) -#define GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED) -#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_INITIATED) -#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS) -#define GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_SET_NOTIFY_ON_CANCEL) -#define GRPC_STATS_INC_CALL_COMBINER_CANCELLED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_CANCELLED) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_SHORT_ITEMS) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_LONG_ITEMS) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF) -#define GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) -#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) -#define GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_PUSH_RETRIES) -#define GRPC_STATS_INC_SERVER_REQUESTED_CALLS() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS) -#define GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_FAILURES) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_SUCCESSES) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES() \ - GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES) -#define GRPC_STATS_INC_CALL_INITIAL_SIZE(value) \ - grpc_stats_inc_call_initial_size((int)(value)) -void grpc_stats_inc_call_initial_size(int x); -#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(value) \ - grpc_stats_inc_poll_events_returned((int)(value)) -void grpc_stats_inc_poll_events_returned(int x); -#define GRPC_STATS_INC_TCP_WRITE_SIZE(value) \ - grpc_stats_inc_tcp_write_size((int)(value)) -void grpc_stats_inc_tcp_write_size(int x); -#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(value) \ - grpc_stats_inc_tcp_write_iov_size((int)(value)) -void grpc_stats_inc_tcp_write_iov_size(int x); -#define GRPC_STATS_INC_TCP_READ_SIZE(value) \ - grpc_stats_inc_tcp_read_size((int)(value)) -void grpc_stats_inc_tcp_read_size(int x); -#define GRPC_STATS_INC_TCP_READ_OFFER(value) \ - grpc_stats_inc_tcp_read_offer((int)(value)) -void grpc_stats_inc_tcp_read_offer(int x); -#define GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(value) \ - grpc_stats_inc_tcp_read_offer_iov_size((int)(value)) -void grpc_stats_inc_tcp_read_offer_iov_size(int x); -#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(value) \ - grpc_stats_inc_http2_send_message_size((int)(value)) -void grpc_stats_inc_http2_send_message_size(int x); -#define GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE(value) \ - grpc_stats_inc_http2_send_initial_metadata_per_write((int)(value)) -void grpc_stats_inc_http2_send_initial_metadata_per_write(int x); -#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(value) \ - grpc_stats_inc_http2_send_message_per_write((int)(value)) -void grpc_stats_inc_http2_send_message_per_write(int x); -#define GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE(value) \ - grpc_stats_inc_http2_send_trailing_metadata_per_write((int)(value)) -void grpc_stats_inc_http2_send_trailing_metadata_per_write(int x); -#define GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(value) \ - grpc_stats_inc_http2_send_flowctl_per_write((int)(value)) -void grpc_stats_inc_http2_send_flowctl_per_write(int x); -#define GRPC_STATS_INC_SERVER_CQS_CHECKED(value) \ - grpc_stats_inc_server_cqs_checked((int)(value)) -void grpc_stats_inc_server_cqs_checked(int x); +#define GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_SPURIOUS_WRITES_BEGUN) +#define GRPC_STATS_INC_HPACK_RECV_INDEXED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_INDEXED) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_UNCOMPRESSED) +#define GRPC_STATS_INC_HPACK_RECV_HUFFMAN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_HUFFMAN) +#define GRPC_STATS_INC_HPACK_RECV_BINARY(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_BINARY) +#define GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_RECV_BINARY_BASE64) +#define GRPC_STATS_INC_HPACK_SEND_INDEXED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_INDEXED) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX_V(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_UNCOMPRESSED) +#define GRPC_STATS_INC_HPACK_SEND_HUFFMAN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_HUFFMAN) +#define GRPC_STATS_INC_HPACK_SEND_BINARY(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_BINARY) +#define GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HPACK_SEND_BINARY_BASE64) +#define GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED) +#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_INITIATED) +#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_SET_NOTIFY_ON_CANCEL) +#define GRPC_STATS_INC_CALL_COMBINER_CANCELLED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_CANCELLED) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_SHORT_ITEMS) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_LONG_ITEMS) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF) +#define GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) +#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) +#define GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_PUSH_RETRIES) +#define GRPC_STATS_INC_SERVER_REQUESTED_CALLS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS) +#define GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_FAILURES) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_SUCCESSES) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES) +#define GRPC_STATS_INC_CALL_INITIAL_SIZE(exec_ctx, value) \ + grpc_stats_inc_call_initial_size((exec_ctx), (int)(value)) +void grpc_stats_inc_call_initial_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, value) \ + grpc_stats_inc_poll_events_returned((exec_ctx), (int)(value)) +void grpc_stats_inc_poll_events_returned(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_write_size((exec_ctx), (int)(value)) +void grpc_stats_inc_tcp_write_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_write_iov_size((exec_ctx), (int)(value)) +void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_read_size((exec_ctx), (int)(value)) +void grpc_stats_inc_tcp_read_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, value) \ + grpc_stats_inc_tcp_read_offer((exec_ctx), (int)(value)) +void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_read_offer_iov_size((exec_ctx), (int)(value)) +void grpc_stats_inc_tcp_read_offer_iov_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \ + grpc_stats_inc_http2_send_message_size((exec_ctx), (int)(value)) +void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE(exec_ctx, value) \ + grpc_stats_inc_http2_send_initial_metadata_per_write((exec_ctx), (int)(value)) +void grpc_stats_inc_http2_send_initial_metadata_per_write( + grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(exec_ctx, value) \ + grpc_stats_inc_http2_send_message_per_write((exec_ctx), (int)(value)) +void grpc_stats_inc_http2_send_message_per_write(grpc_exec_ctx* exec_ctx, + int x); +#define GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE(exec_ctx, value) \ + grpc_stats_inc_http2_send_trailing_metadata_per_write((exec_ctx), \ + (int)(value)) +void grpc_stats_inc_http2_send_trailing_metadata_per_write( + grpc_exec_ctx* exec_ctx, int x); +#define GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(exec_ctx, value) \ + grpc_stats_inc_http2_send_flowctl_per_write((exec_ctx), (int)(value)) +void grpc_stats_inc_http2_send_flowctl_per_write(grpc_exec_ctx* exec_ctx, + int x); +#define GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, value) \ + grpc_stats_inc_server_cqs_checked((exec_ctx), (int)(value)) +void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx* exec_ctx, int x); extern const int grpc_stats_histo_buckets[13]; extern const int grpc_stats_histo_start[13]; extern const int* const grpc_stats_histo_bucket_boundaries[13]; -extern void (*const grpc_stats_inc_histogram[13])(int x); +extern void (*const grpc_stats_inc_histogram[13])(grpc_exec_ctx* exec_ctx, + int x); #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc index ed874c4265..73b484b06d 100644 --- a/src/core/lib/http/httpcli.cc +++ b/src/core/lib/http/httpcli.cc @@ -63,11 +63,13 @@ typedef struct { static grpc_httpcli_get_override g_get_override = nullptr; static grpc_httpcli_post_override g_post_override = nullptr; -static void plaintext_handshake(void* arg, grpc_endpoint* endpoint, - const char* host, grpc_millis deadline, - void (*on_done)(void* arg, +static void plaintext_handshake(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* endpoint, const char* host, + grpc_millis deadline, + void (*on_done)(grpc_exec_ctx* exec_ctx, + void* arg, grpc_endpoint* endpoint)) { - on_done(arg, endpoint); + on_done(exec_ctx, arg, endpoint); } const grpc_httpcli_handshaker grpc_httpcli_plaintext = {"http", @@ -77,31 +79,34 @@ void grpc_httpcli_context_init(grpc_httpcli_context* context) { context->pollset_set = grpc_pollset_set_create(); } -void grpc_httpcli_context_destroy(grpc_httpcli_context* context) { - grpc_pollset_set_destroy(context->pollset_set); +void grpc_httpcli_context_destroy(grpc_exec_ctx* exec_ctx, + grpc_httpcli_context* context) { + grpc_pollset_set_destroy(exec_ctx, context->pollset_set); } -static void next_address(internal_request* req, grpc_error* due_to_error); +static void next_address(grpc_exec_ctx* exec_ctx, internal_request* req, + grpc_error* due_to_error); -static void finish(internal_request* req, grpc_error* error) { - grpc_polling_entity_del_from_pollset_set(req->pollent, +static void finish(grpc_exec_ctx* exec_ctx, internal_request* req, + grpc_error* error) { + grpc_polling_entity_del_from_pollset_set(exec_ctx, req->pollent, req->context->pollset_set); - GRPC_CLOSURE_SCHED(req->on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, req->on_done, error); grpc_http_parser_destroy(&req->parser); if (req->addresses != nullptr) { grpc_resolved_addresses_destroy(req->addresses); } if (req->ep != nullptr) { - grpc_endpoint_destroy(req->ep); + grpc_endpoint_destroy(exec_ctx, req->ep); } - grpc_slice_unref_internal(req->request_text); + grpc_slice_unref_internal(exec_ctx, req->request_text); gpr_free(req->host); gpr_free(req->ssl_host_override); grpc_iomgr_unregister_object(&req->iomgr_obj); - grpc_slice_buffer_destroy_internal(&req->incoming); - grpc_slice_buffer_destroy_internal(&req->outgoing); + grpc_slice_buffer_destroy_internal(exec_ctx, &req->incoming); + grpc_slice_buffer_destroy_internal(exec_ctx, &req->outgoing); GRPC_ERROR_UNREF(req->overall_error); - grpc_resource_quota_unref_internal(req->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, req->resource_quota); gpr_free(req); } @@ -119,11 +124,12 @@ static void append_error(internal_request* req, grpc_error* error) { gpr_free(addr_text); } -static void do_read(internal_request* req) { - grpc_endpoint_read(req->ep, &req->incoming, &req->on_read); +static void do_read(grpc_exec_ctx* exec_ctx, internal_request* req) { + grpc_endpoint_read(exec_ctx, req->ep, &req->incoming, &req->on_read); } -static void on_read(void* user_data, grpc_error* error) { +static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { internal_request* req = (internal_request*)user_data; size_t i; @@ -133,70 +139,77 @@ static void on_read(void* user_data, grpc_error* error) { grpc_error* err = grpc_http_parser_parse( &req->parser, req->incoming.slices[i], nullptr); if (err != GRPC_ERROR_NONE) { - finish(req, err); + finish(exec_ctx, req, err); return; } } } if (error == GRPC_ERROR_NONE) { - do_read(req); + do_read(exec_ctx, req); } else if (!req->have_read_byte) { - next_address(req, GRPC_ERROR_REF(error)); + next_address(exec_ctx, req, GRPC_ERROR_REF(error)); } else { - finish(req, grpc_http_parser_eof(&req->parser)); + finish(exec_ctx, req, grpc_http_parser_eof(&req->parser)); } } -static void on_written(internal_request* req) { do_read(req); } +static void on_written(grpc_exec_ctx* exec_ctx, internal_request* req) { + do_read(exec_ctx, req); +} -static void done_write(void* arg, grpc_error* error) { +static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { internal_request* req = (internal_request*)arg; if (error == GRPC_ERROR_NONE) { - on_written(req); + on_written(exec_ctx, req); } else { - next_address(req, GRPC_ERROR_REF(error)); + next_address(exec_ctx, req, GRPC_ERROR_REF(error)); } } -static void start_write(internal_request* req) { +static void start_write(grpc_exec_ctx* exec_ctx, internal_request* req) { grpc_slice_ref_internal(req->request_text); grpc_slice_buffer_add(&req->outgoing, req->request_text); - grpc_endpoint_write(req->ep, &req->outgoing, &req->done_write); + grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write); } -static void on_handshake_done(void* arg, grpc_endpoint* ep) { +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* ep) { internal_request* req = (internal_request*)arg; if (!ep) { - next_address(req, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Unexplained handshake failure")); + next_address( + exec_ctx, req, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unexplained handshake failure")); return; } req->ep = ep; - start_write(req); + start_write(exec_ctx, req); } -static void on_connected(void* arg, grpc_error* error) { +static void on_connected(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { internal_request* req = (internal_request*)arg; if (!req->ep) { - next_address(req, GRPC_ERROR_REF(error)); + next_address(exec_ctx, req, GRPC_ERROR_REF(error)); return; } req->handshaker->handshake( - req, req->ep, req->ssl_host_override ? req->ssl_host_override : req->host, + exec_ctx, req, req->ep, + req->ssl_host_override ? req->ssl_host_override : req->host, req->deadline, on_handshake_done); } -static void next_address(internal_request* req, grpc_error* error) { +static void next_address(grpc_exec_ctx* exec_ctx, internal_request* req, + grpc_error* error) { grpc_resolved_address* addr; if (error != GRPC_ERROR_NONE) { append_error(req, error); } if (req->next_address == req->addresses->naddrs) { - finish(req, + finish(exec_ctx, req, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed HTTP requests to all targets", &req->overall_error, 1)); return; @@ -208,21 +221,23 @@ static void next_address(internal_request* req, grpc_error* error) { (char*)GRPC_ARG_RESOURCE_QUOTA, req->resource_quota, grpc_resource_quota_arg_vtable()); grpc_channel_args args = {1, &arg}; - grpc_tcp_client_connect(&req->connected, &req->ep, req->context->pollset_set, - &args, addr, req->deadline); + grpc_tcp_client_connect(exec_ctx, &req->connected, &req->ep, + req->context->pollset_set, &args, addr, + req->deadline); } -static void on_resolved(void* arg, grpc_error* error) { +static void on_resolved(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { internal_request* req = (internal_request*)arg; if (error != GRPC_ERROR_NONE) { - finish(req, GRPC_ERROR_REF(error)); + finish(exec_ctx, req, GRPC_ERROR_REF(error)); return; } req->next_address = 0; - next_address(req, GRPC_ERROR_NONE); + next_address(exec_ctx, req, GRPC_ERROR_NONE); } -static void internal_request_begin(grpc_httpcli_context* context, +static void internal_request_begin(grpc_exec_ctx* exec_ctx, + grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -252,31 +267,33 @@ static void internal_request_begin(grpc_httpcli_context* context, req->ssl_host_override = gpr_strdup(request->ssl_host_override); GPR_ASSERT(pollent); - grpc_polling_entity_add_to_pollset_set(req->pollent, + grpc_polling_entity_add_to_pollset_set(exec_ctx, req->pollent, req->context->pollset_set); grpc_resolve_address( - request->host, req->handshaker->default_port, req->context->pollset_set, + exec_ctx, request->host, req->handshaker->default_port, + req->context->pollset_set, GRPC_CLOSURE_CREATE(on_resolved, req, grpc_schedule_on_exec_ctx), &req->addresses); } -void grpc_httpcli_get(grpc_httpcli_context* context, +void grpc_httpcli_get(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { char* name; - if (g_get_override && g_get_override(request, deadline, on_done, response)) { + if (g_get_override && + g_get_override(exec_ctx, request, deadline, on_done, response)) { return; } gpr_asprintf(&name, "HTTP:GET:%s:%s", request->host, request->http.path); - internal_request_begin(context, pollent, resource_quota, request, deadline, - on_done, response, name, + internal_request_begin(exec_ctx, context, pollent, resource_quota, request, + deadline, on_done, response, name, grpc_httpcli_format_get_request(request)); gpr_free(name); } -void grpc_httpcli_post(grpc_httpcli_context* context, +void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -284,14 +301,16 @@ void grpc_httpcli_post(grpc_httpcli_context* context, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { char* name; - if (g_post_override && g_post_override(request, body_bytes, body_size, - deadline, on_done, response)) { + if (g_post_override && + g_post_override(exec_ctx, request, body_bytes, body_size, deadline, + on_done, response)) { return; } gpr_asprintf(&name, "HTTP:POST:%s:%s", request->host, request->http.path); internal_request_begin( - context, pollent, resource_quota, request, deadline, on_done, response, - name, grpc_httpcli_format_post_request(request, body_bytes, body_size)); + exec_ctx, context, pollent, resource_quota, request, deadline, on_done, + response, name, + grpc_httpcli_format_post_request(request, body_bytes, body_size)); gpr_free(name); } diff --git a/src/core/lib/http/httpcli.h b/src/core/lib/http/httpcli.h index 72d20cc7a3..6f675568bd 100644 --- a/src/core/lib/http/httpcli.h +++ b/src/core/lib/http/httpcli.h @@ -41,9 +41,10 @@ typedef struct grpc_httpcli_context { typedef struct { const char* default_port; - void (*handshake)(void* arg, grpc_endpoint* endpoint, const char* host, - grpc_millis deadline, - void (*on_done)(void* arg, grpc_endpoint* endpoint)); + void (*handshake)(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint, + const char* host, grpc_millis deadline, + void (*on_done)(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* endpoint)); } grpc_httpcli_handshaker; extern const grpc_httpcli_handshaker grpc_httpcli_plaintext; @@ -67,7 +68,8 @@ typedef struct grpc_httpcli_request { typedef struct grpc_http_response grpc_httpcli_response; void grpc_httpcli_context_init(grpc_httpcli_context* context); -void grpc_httpcli_context_destroy(grpc_httpcli_context* context); +void grpc_httpcli_context_destroy(grpc_exec_ctx* exec_ctx, + grpc_httpcli_context* context); /* Asynchronously perform a HTTP GET. 'context' specifies the http context under which to do the get @@ -78,7 +80,7 @@ void grpc_httpcli_context_destroy(grpc_httpcli_context* context); destroyed once the call returns 'deadline' contains a deadline for the request (or gpr_inf_future) 'on_response' is a callback to report results to */ -void grpc_httpcli_get(grpc_httpcli_context* context, +void grpc_httpcli_get(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, grpc_millis deadline, @@ -99,7 +101,7 @@ void grpc_httpcli_get(grpc_httpcli_context* context, lifetime of the request 'on_response' is a callback to report results to Does not support ?var1=val1&var2=val2 in the path. */ -void grpc_httpcli_post(grpc_httpcli_context* context, +void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -108,16 +110,15 @@ void grpc_httpcli_post(grpc_httpcli_context* context, grpc_httpcli_response* response); /* override functions return 1 if they handled the request, 0 otherwise */ -typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request* request, +typedef int (*grpc_httpcli_get_override)(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_complete, grpc_httpcli_response* response); -typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request* request, - const char* body_bytes, - size_t body_size, - grpc_millis deadline, - grpc_closure* on_complete, - grpc_httpcli_response* response); +typedef int (*grpc_httpcli_post_override)( + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + const char* body_bytes, size_t body_size, grpc_millis deadline, + grpc_closure* on_complete, grpc_httpcli_response* response); void grpc_httpcli_set_override(grpc_httpcli_get_override get, grpc_httpcli_post_override post); diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index bfb536a921..dfcaee702b 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -38,7 +38,8 @@ typedef struct { char* secure_peer_name; } grpc_httpcli_ssl_channel_security_connector; -static void httpcli_ssl_destroy(grpc_security_connector* sc) { +static void httpcli_ssl_destroy(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; if (c->handshaker_factory != nullptr) { @@ -49,7 +50,8 @@ static void httpcli_ssl_destroy(grpc_security_connector* sc) { gpr_free(sc); } -static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc, +static void httpcli_ssl_add_handshakers(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; @@ -63,11 +65,13 @@ static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc, } } grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(handshaker), &sc->base)); + handshake_mgr, + grpc_security_handshaker_create( + exec_ctx, tsi_create_adapter_handshaker(handshaker), &sc->base)); } -static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void httpcli_ssl_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_httpcli_ssl_channel_security_connector* c = @@ -83,7 +87,7 @@ static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); } - GRPC_CLOSURE_SCHED(on_peer_checked, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); tsi_peer_destruct(&peer); } @@ -100,8 +104,8 @@ static grpc_security_connector_vtable httpcli_ssl_vtable = { httpcli_ssl_destroy, httpcli_ssl_check_peer, httpcli_ssl_cmp}; static grpc_security_status httpcli_ssl_channel_security_connector_create( - const char* pem_root_certs, const char* secure_peer_name, - grpc_channel_security_connector** sc) { + grpc_exec_ctx* exec_ctx, const char* pem_root_certs, + const char* secure_peer_name, grpc_channel_security_connector** sc) { tsi_result result = TSI_OK; grpc_httpcli_ssl_channel_security_connector* c; @@ -124,12 +128,12 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); - httpcli_ssl_destroy(&c->base.base); + httpcli_ssl_destroy(exec_ctx, &c->base.base); *sc = nullptr; return GRPC_SECURITY_ERROR; } // We don't actually need a channel credentials object in this case, - // but we set it to a non-nullptr address so that we don't trigger + // but we set it to a non-NULL address so that we don't trigger // assertions in grpc_channel_security_connector_cmp(). c->base.channel_creds = (grpc_channel_credentials*)1; c->base.add_handshakers = httpcli_ssl_add_handshakers; @@ -140,37 +144,40 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( /* handshaker */ typedef struct { - void (*func)(void* arg, grpc_endpoint* endpoint); + void (*func)(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint); void* arg; grpc_handshake_manager* handshake_mgr; } on_done_closure; -static void on_handshake_done(void* arg, grpc_error* error) { +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; on_done_closure* c = (on_done_closure*)args->user_data; if (error != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - c->func(c->arg, nullptr); + c->func(exec_ctx, c->arg, nullptr); } else { - grpc_channel_args_destroy(args->args); - grpc_slice_buffer_destroy_internal(args->read_buffer); + grpc_channel_args_destroy(exec_ctx, args->args); + grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); gpr_free(args->read_buffer); - c->func(c->arg, args->endpoint); + c->func(exec_ctx, c->arg, args->endpoint); } - grpc_handshake_manager_destroy(c->handshake_mgr); + grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); gpr_free(c); } -static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host, +static void ssl_handshake(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* tcp, const char* host, grpc_millis deadline, - void (*on_done)(void* arg, grpc_endpoint* endpoint)) { + void (*on_done)(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* endpoint)) { on_done_closure* c = (on_done_closure*)gpr_malloc(sizeof(*c)); const char* pem_root_certs = grpc_get_default_ssl_roots(); if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); - on_done(arg, nullptr); + on_done(exec_ctx, arg, nullptr); gpr_free(c); return; } @@ -178,16 +185,16 @@ static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host, c->arg = arg; grpc_channel_security_connector* sc = nullptr; GPR_ASSERT(httpcli_ssl_channel_security_connector_create( - pem_root_certs, host, &sc) == GRPC_SECURITY_OK); + exec_ctx, pem_root_certs, host, &sc) == GRPC_SECURITY_OK); grpc_arg channel_arg = grpc_security_connector_to_arg(&sc->base); grpc_channel_args args = {1, &channel_arg}; c->handshake_mgr = grpc_handshake_manager_create(); - grpc_handshakers_add(HANDSHAKER_CLIENT, &args, c->handshake_mgr); + grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, &args, c->handshake_mgr); grpc_handshake_manager_do_handshake( - c->handshake_mgr, nullptr /* interested_parties */, tcp, + exec_ctx, c->handshake_mgr, nullptr /* interested_parties */, tcp, nullptr /* channel_args */, deadline, nullptr /* acceptor */, on_handshake_done, c /* user_data */); - GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli"); + GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "httpcli"); } const grpc_httpcli_handshaker grpc_httpcli_ssl = {"https", ssl_handshake}; diff --git a/src/core/lib/iomgr/block_annotate.h b/src/core/lib/iomgr/block_annotate.h index a57873aabb..340ebcb1af 100644 --- a/src/core/lib/iomgr/block_annotate.h +++ b/src/core/lib/iomgr/block_annotate.h @@ -31,27 +31,26 @@ void gpr_thd_end_blocking_region(); do { \ gpr_thd_start_blocking_region(); \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION \ - do { \ - gpr_thd_end_blocking_region(); \ - grpc_core::ExecCtx::Get()->InvalidateNow(); \ - } while (0) #define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ do { \ gpr_thd_end_blocking_region(); \ } while (0) - +#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(ec) \ + do { \ + gpr_thd_end_blocking_region(); \ + grpc_exec_ctx_invalidate_now((ec)); \ + } while (0) #else #define GRPC_SCHEDULING_START_BLOCKING_REGION \ do { \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION \ - do { \ - grpc_core::ExecCtx::Get()->InvalidateNow(); \ - } while (0) #define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ do { \ } while (0) +#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(ec) \ + do { \ + grpc_exec_ctx_invalidate_now((ec)); \ + } while (0) #endif #endif /* GRPC_CORE_LIB_IOMGR_BLOCK_ANNOTATE_H */ diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index a9f48fb3c2..b5910b42e4 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -56,7 +56,8 @@ void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner) { #define DEBUG_FMT_ARGS #endif -void grpc_call_combiner_start(grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error DEBUG_ARGS, const char* reason) { @@ -74,16 +75,15 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size + 1); } - GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(); + GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx); if (prev_size == 0) { - GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(); - + GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx); GPR_TIMER_MARK("call_combiner_initiate", 0); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " EXECUTING IMMEDIATELY"); } // Queue was empty, so execute this closure immediately. - GRPC_CLOSURE_SCHED(closure, error); + GRPC_CLOSURE_SCHED(exec_ctx, closure, error); } else { if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_INFO, " QUEUING"); @@ -95,7 +95,8 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner, GPR_TIMER_END("call_combiner_start", 0); } -void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, +void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner DEBUG_ARGS, const char* reason) { GPR_TIMER_BEGIN("call_combiner_stop", 0); if (grpc_call_combiner_trace.enabled()) { @@ -130,7 +131,7 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, gpr_log(GPR_DEBUG, " EXECUTING FROM QUEUE: closure=%p error=%s", closure, grpc_error_string(closure->error_data.error)); } - GRPC_CLOSURE_SCHED(closure, closure->error_data.error); + GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error); break; } } else if (grpc_call_combiner_trace.enabled()) { @@ -139,9 +140,10 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, GPR_TIMER_END("call_combiner_stop", 0); } -void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, +void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_closure* closure) { - GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(); + GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(exec_ctx); while (true) { // Decode original state. gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state); @@ -155,7 +157,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, "for pre-existing cancellation", call_combiner, closure); } - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_REF(original_error)); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_REF(original_error)); break; } else { if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state, @@ -174,7 +176,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, "call_combiner=%p: scheduling old cancel callback=%p", call_combiner, closure); } - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } break; } @@ -183,9 +185,10 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, } } -void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner, +void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_error* error) { - GRPC_STATS_INC_CALL_COMBINER_CANCELLED(); + GRPC_STATS_INC_CALL_COMBINER_CANCELLED(exec_ctx); while (true) { gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state); grpc_error* original_error = decode_cancel_state_error(original_state); @@ -202,7 +205,7 @@ void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner, "call_combiner=%p: scheduling notify_on_cancel callback=%p", call_combiner, notify_on_cancel); } - GRPC_CLOSURE_SCHED(notify_on_cancel, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, notify_on_cancel, GRPC_ERROR_REF(error)); } break; } diff --git a/src/core/lib/iomgr/call_combiner.h b/src/core/lib/iomgr/call_combiner.h index 9f7e6ce1c9..c07af51c91 100644 --- a/src/core/lib/iomgr/call_combiner.h +++ b/src/core/lib/iomgr/call_combiner.h @@ -53,29 +53,37 @@ void grpc_call_combiner_init(grpc_call_combiner* call_combiner); void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner); #ifndef NDEBUG -#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \ - grpc_call_combiner_start((call_combiner), (closure), (error), __FILE__, \ - __LINE__, (reason)) -#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \ - grpc_call_combiner_stop((call_combiner), __FILE__, __LINE__, (reason)) +#define GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, closure, error, \ + reason) \ + grpc_call_combiner_start((exec_ctx), (call_combiner), (closure), (error), \ + __FILE__, __LINE__, (reason)) +#define GRPC_CALL_COMBINER_STOP(exec_ctx, call_combiner, reason) \ + grpc_call_combiner_stop((exec_ctx), (call_combiner), __FILE__, __LINE__, \ + (reason)) /// Starts processing \a closure on \a call_combiner. -void grpc_call_combiner_start(grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error, const char* file, int line, const char* reason); /// Yields the call combiner to the next closure in the queue, if any. -void grpc_call_combiner_stop(grpc_call_combiner* call_combiner, +void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, const char* file, int line, const char* reason); #else -#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \ - grpc_call_combiner_start((call_combiner), (closure), (error), (reason)) -#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \ - grpc_call_combiner_stop((call_combiner), (reason)) +#define GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, closure, error, \ + reason) \ + grpc_call_combiner_start((exec_ctx), (call_combiner), (closure), (error), \ + (reason)) +#define GRPC_CALL_COMBINER_STOP(exec_ctx, call_combiner, reason) \ + grpc_call_combiner_stop((exec_ctx), (call_combiner), (reason)) /// Starts processing \a closure on \a call_combiner. -void grpc_call_combiner_start(grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error, const char* reason); /// Yields the call combiner to the next closure in the queue, if any. -void grpc_call_combiner_stop(grpc_call_combiner* call_combiner, +void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, const char* reason); #endif @@ -101,11 +109,13 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner, /// cancellation; this effectively unregisters the previously set closure. /// However, most filters will not need to explicitly unregister their /// callbacks, as this is done automatically when the call is destroyed. -void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, +void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_closure* closure); /// Indicates that the call has been cancelled. -void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner, +void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, + grpc_call_combiner* call_combiner, grpc_error* error); #endif /* GRPC_CORE_LIB_IOMGR_CALL_COMBINER_H */ diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 88af76006a..46793dd2c5 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -47,15 +47,18 @@ typedef struct grpc_closure_list { * describing what went wrong. * Error contract: it is not the cb's job to unref this error; * the closure scheduler will do that after the cb returns */ -typedef void (*grpc_iomgr_cb_func)(void* arg, grpc_error* error); +typedef void (*grpc_iomgr_cb_func)(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); typedef struct grpc_closure_scheduler grpc_closure_scheduler; typedef struct grpc_closure_scheduler_vtable { /* NOTE: for all these functions, closure->scheduler == the scheduler that was used to find this vtable */ - void (*run)(grpc_closure* closure, grpc_error* error); - void (*sched)(grpc_closure* closure, grpc_error* error); + void (*run)(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error); + void (*sched)(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error); const char* name; } grpc_closure_scheduler_vtable; @@ -143,12 +146,13 @@ typedef struct { grpc_closure wrapper; } wrapped_closure; -inline void closure_wrapper(void* arg, grpc_error* error) { +inline void closure_wrapper(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { wrapped_closure* wc = (wrapped_closure*)arg; grpc_iomgr_cb_func cb = wc->cb; void* cb_arg = wc->cb_arg; gpr_free(wc); - cb(cb_arg, error); + cb(exec_ctx, cb_arg, error); } } // namespace closure_impl @@ -243,10 +247,12 @@ inline bool grpc_closure_list_empty(grpc_closure_list closure_list) { } #ifndef NDEBUG -inline void grpc_closure_run(const char* file, int line, grpc_closure* c, +inline void grpc_closure_run(const char* file, int line, + grpc_exec_ctx* exec_ctx, grpc_closure* c, grpc_error* error) { #else -inline void grpc_closure_run(grpc_closure* c, grpc_error* error) { +inline void grpc_closure_run(grpc_exec_ctx* exec_ctx, grpc_closure* c, + grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_run", 0); if (c != nullptr) { @@ -256,7 +262,7 @@ inline void grpc_closure_run(grpc_closure* c, grpc_error* error) { c->run = true; #endif assert(c->cb); - c->scheduler->vtable->run(c, error); + c->scheduler->vtable->run(exec_ctx, c, error); } else { GRPC_ERROR_UNREF(error); } @@ -267,17 +273,20 @@ inline void grpc_closure_run(grpc_closure* c, grpc_error* error) { * Note that calling this at the end of a closure callback function itself is * by definition safe. */ #ifndef NDEBUG -#define GRPC_CLOSURE_RUN(closure, error) \ - grpc_closure_run(__FILE__, __LINE__, closure, error) +#define GRPC_CLOSURE_RUN(exec_ctx, closure, error) \ + grpc_closure_run(__FILE__, __LINE__, exec_ctx, closure, error) #else -#define GRPC_CLOSURE_RUN(closure, error) grpc_closure_run(closure, error) +#define GRPC_CLOSURE_RUN(exec_ctx, closure, error) \ + grpc_closure_run(exec_ctx, closure, error) #endif #ifndef NDEBUG -inline void grpc_closure_sched(const char* file, int line, grpc_closure* c, +inline void grpc_closure_sched(const char* file, int line, + grpc_exec_ctx* exec_ctx, grpc_closure* c, grpc_error* error) { #else -inline void grpc_closure_sched(grpc_closure* c, grpc_error* error) { +inline void grpc_closure_sched(grpc_exec_ctx* exec_ctx, grpc_closure* c, + grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_sched", 0); if (c != nullptr) { @@ -296,7 +305,7 @@ inline void grpc_closure_sched(grpc_closure* c, grpc_error* error) { c->run = false; #endif assert(c->cb); - c->scheduler->vtable->sched(c, error); + c->scheduler->vtable->sched(exec_ctx, c, error); } else { GRPC_ERROR_UNREF(error); } @@ -305,17 +314,20 @@ inline void grpc_closure_sched(grpc_closure* c, grpc_error* error) { /** Schedule a closure to be run. Does not need to be run from a safe point. */ #ifndef NDEBUG -#define GRPC_CLOSURE_SCHED(closure, error) \ - grpc_closure_sched(__FILE__, __LINE__, closure, error) +#define GRPC_CLOSURE_SCHED(exec_ctx, closure, error) \ + grpc_closure_sched(__FILE__, __LINE__, exec_ctx, closure, error) #else -#define GRPC_CLOSURE_SCHED(closure, error) grpc_closure_sched(closure, error) +#define GRPC_CLOSURE_SCHED(exec_ctx, closure, error) \ + grpc_closure_sched(exec_ctx, closure, error) #endif #ifndef NDEBUG inline void grpc_closure_list_sched(const char* file, int line, + grpc_exec_ctx* exec_ctx, grpc_closure_list* list) { #else -inline void grpc_closure_list_sched(grpc_closure_list* list) { +inline void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, + grpc_closure_list* list) { #endif grpc_closure* c = list->head; while (c != nullptr) { @@ -335,7 +347,7 @@ inline void grpc_closure_list_sched(grpc_closure_list* list) { c->run = false; #endif assert(c->cb); - c->scheduler->vtable->sched(c, c->error_data.error); + c->scheduler->vtable->sched(exec_ctx, c, c->error_data.error); c = next; } list->head = list->tail = nullptr; @@ -344,11 +356,11 @@ inline void grpc_closure_list_sched(grpc_closure_list* list) { /** Schedule all closures in a list to be run. Does not need to be run from a * safe point. */ #ifndef NDEBUG -#define GRPC_CLOSURE_LIST_SCHED(closure_list) \ - grpc_closure_list_sched(__FILE__, __LINE__, closure_list) +#define GRPC_CLOSURE_LIST_SCHED(exec_ctx, closure_list) \ + grpc_closure_list_sched(__FILE__, __LINE__, exec_ctx, closure_list) #else -#define GRPC_CLOSURE_LIST_SCHED(closure_list) \ - grpc_closure_list_sched(closure_list) +#define GRPC_CLOSURE_LIST_SCHED(exec_ctx, closure_list) \ + grpc_closure_list_sched(exec_ctx, closure_list) #endif #endif /* GRPC_CORE_LIB_IOMGR_CLOSURE_H */ diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index e4d7a6abd8..15c009dd77 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -61,15 +61,17 @@ struct grpc_combiner { gpr_refcount refs; }; -static void combiner_exec(grpc_closure* closure, grpc_error* error); -static void combiner_finally_exec(grpc_closure* closure, grpc_error* error); +static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error); +static void combiner_finally_exec(grpc_exec_ctx* exec_ctx, + grpc_closure* closure, grpc_error* error); static const grpc_closure_scheduler_vtable scheduler = { combiner_exec, combiner_exec, "combiner:immediately"}; static const grpc_closure_scheduler_vtable finally_scheduler = { combiner_finally_exec, combiner_finally_exec, "combiner:finally"}; -static void offload(void* arg, grpc_error* error); +static void offload(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); grpc_combiner* grpc_combiner_create(void) { grpc_combiner* lock = (grpc_combiner*)gpr_zalloc(sizeof(*lock)); @@ -85,19 +87,19 @@ grpc_combiner* grpc_combiner_create(void) { return lock; } -static void really_destroy(grpc_combiner* lock) { +static void really_destroy(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p really_destroy", lock)); GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0); gpr_mpscq_destroy(&lock->queue); gpr_free(lock); } -static void start_destroy(grpc_combiner* lock) { +static void start_destroy(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_UNORPHANED); GRPC_COMBINER_TRACE(gpr_log( GPR_DEBUG, "C:%p really_destroy old_state=%" PRIdPTR, lock, old_state)); if (old_state == 1) { - really_destroy(lock); + really_destroy(exec_ctx, lock); } } @@ -113,10 +115,11 @@ static void start_destroy(grpc_combiner* lock) { #define GRPC_COMBINER_DEBUG_SPAM(op, delta) #endif -void grpc_combiner_unref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { +void grpc_combiner_unref(grpc_exec_ctx* exec_ctx, + grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { GRPC_COMBINER_DEBUG_SPAM("UNREF", -1); if (gpr_unref(&lock->refs)) { - start_destroy(lock); + start_destroy(exec_ctx, lock); } } @@ -126,25 +129,23 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { return lock; } -static void push_last_on_exec_ctx(grpc_combiner* lock) { +static void push_last_on_exec_ctx(grpc_exec_ctx* exec_ctx, + grpc_combiner* lock) { lock->next_combiner_on_this_exec_ctx = nullptr; - if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { - grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = - grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; + if (exec_ctx->active_combiner == nullptr) { + exec_ctx->active_combiner = exec_ctx->last_combiner = lock; } else { - grpc_core::ExecCtx::Get() - ->combiner_data() - ->last_combiner->next_combiner_on_this_exec_ctx = lock; - grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; + exec_ctx->last_combiner->next_combiner_on_this_exec_ctx = lock; + exec_ctx->last_combiner = lock; } } -static void push_first_on_exec_ctx(grpc_combiner* lock) { - lock->next_combiner_on_this_exec_ctx = - grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; - grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = lock; +static void push_first_on_exec_ctx(grpc_exec_ctx* exec_ctx, + grpc_combiner* lock) { + lock->next_combiner_on_this_exec_ctx = exec_ctx->active_combiner; + exec_ctx->active_combiner = lock; if (lock->next_combiner_on_this_exec_ctx == nullptr) { - grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; + exec_ctx->last_combiner = lock; } } @@ -152,8 +153,9 @@ static void push_first_on_exec_ctx(grpc_combiner* lock) { ((grpc_combiner*)(((char*)((closure)->scheduler)) - \ offsetof(grpc_combiner, scheduler_name))) -static void combiner_exec(grpc_closure* cl, grpc_error* error) { - GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(); +static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl, + grpc_error* error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx); GPR_TIMER_BEGIN("combiner.execute", 0); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(cl, scheduler); gpr_atm last = gpr_atm_full_fetch_add(&lock->state, STATE_ELEM_COUNT_LOW_BIT); @@ -161,19 +163,19 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { "C:%p grpc_combiner_execute c=%p last=%" PRIdPTR, lock, cl, last)); if (last == 1) { - GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(); + GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx); GPR_TIMER_MARK("combiner.initiated", 0); gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, - (gpr_atm)grpc_core::ExecCtx::Get()); + (gpr_atm)exec_ctx); // first element on this list: add it to the list of combiner locks // executing within this exec_ctx - push_last_on_exec_ctx(lock); + push_last_on_exec_ctx(exec_ctx, lock); } else { // there may be a race with setting here: if that happens, we may delay // offload for one or two actions, and that's fine gpr_atm initiator = gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null); - if (initiator != 0 && initiator != (gpr_atm)grpc_core::ExecCtx::Get()) { + if (initiator != 0 && initiator != (gpr_atm)exec_ctx) { gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } @@ -184,32 +186,29 @@ static void combiner_exec(grpc_closure* cl, grpc_error* error) { GPR_TIMER_END("combiner.execute", 0); } -static void move_next() { - grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = - grpc_core::ExecCtx::Get() - ->combiner_data() - ->active_combiner->next_combiner_on_this_exec_ctx; - if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { - grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = nullptr; +static void move_next(grpc_exec_ctx* exec_ctx) { + exec_ctx->active_combiner = + exec_ctx->active_combiner->next_combiner_on_this_exec_ctx; + if (exec_ctx->active_combiner == nullptr) { + exec_ctx->last_combiner = nullptr; } } -static void offload(void* arg, grpc_error* error) { +static void offload(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_combiner* lock = (grpc_combiner*)arg; - push_last_on_exec_ctx(lock); + push_last_on_exec_ctx(exec_ctx, lock); } -static void queue_offload(grpc_combiner* lock) { - GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(); - move_next(); +static void queue_offload(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { + GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx); + move_next(exec_ctx); GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p queue_offload", lock)); - GRPC_CLOSURE_SCHED(&lock->offload, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &lock->offload, GRPC_ERROR_NONE); } -bool grpc_combiner_continue_exec_ctx() { +bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0); - grpc_combiner* lock = - grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; + grpc_combiner* lock = exec_ctx->active_combiner; if (lock == nullptr) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); return false; @@ -224,15 +223,15 @@ bool grpc_combiner_continue_exec_ctx() { "exec_ctx_ready_to_finish=%d " "time_to_execute_final_list=%d", lock, contended, - grpc_core::ExecCtx::Get()->IsReadyToFinish(), + grpc_exec_ctx_ready_to_finish(exec_ctx), lock->time_to_execute_final_list)); - if (contended && grpc_core::ExecCtx::Get()->IsReadyToFinish() && + if (contended && grpc_exec_ctx_ready_to_finish(exec_ctx) && grpc_executor_is_threaded()) { GPR_TIMER_MARK("offload_from_finished_exec_ctx", 0); // this execution context wants to move on: schedule remaining work to be // picked up on the executor - queue_offload(lock); + queue_offload(exec_ctx, lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } @@ -248,7 +247,7 @@ bool grpc_combiner_continue_exec_ctx() { // queue is in an inconsistent state: use this as a cue that we should // go off and do something else for a while (and come back later) GPR_TIMER_MARK("delay_busy", 0); - queue_offload(lock); + queue_offload(exec_ctx, lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } @@ -258,7 +257,7 @@ bool grpc_combiner_continue_exec_ctx() { #ifndef NDEBUG cl->scheduled = false; #endif - cl->cb(cl->cb_arg, cl_err); + cl->cb(exec_ctx, cl->cb_arg, cl_err); GRPC_ERROR_UNREF(cl_err); GPR_TIMER_END("combiner.exec1", 0); } else { @@ -275,7 +274,7 @@ bool grpc_combiner_continue_exec_ctx() { #ifndef NDEBUG c->scheduled = false; #endif - c->cb(c->cb_arg, error); + c->cb(exec_ctx, c->cb_arg, error); GRPC_ERROR_UNREF(error); c = next; GPR_TIMER_END("combiner.exec_1final", 0); @@ -283,7 +282,7 @@ bool grpc_combiner_continue_exec_ctx() { } GPR_TIMER_MARK("unref", 0); - move_next(); + move_next(exec_ctx); lock->time_to_execute_final_list = false; gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_ELEM_COUNT_LOW_BIT); @@ -312,7 +311,7 @@ bool grpc_combiner_continue_exec_ctx() { return true; case OLD_STATE_WAS(true, 1): // and one count, one orphaned --> unlocked and orphaned - really_destroy(lock); + really_destroy(exec_ctx, lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; case OLD_STATE_WAS(false, 0): @@ -322,24 +321,27 @@ bool grpc_combiner_continue_exec_ctx() { GPR_TIMER_END("combiner.continue_exec_ctx", 0); GPR_UNREACHABLE_CODE(return true); } - push_first_on_exec_ctx(lock); + push_first_on_exec_ctx(exec_ctx, lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } -static void enqueue_finally(void* closure, grpc_error* error); +static void enqueue_finally(grpc_exec_ctx* exec_ctx, void* closure, + grpc_error* error); -static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { - GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(); +static void combiner_finally_exec(grpc_exec_ctx* exec_ctx, + grpc_closure* closure, grpc_error* error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(closure, finally_scheduler); - GRPC_COMBINER_TRACE(gpr_log( - GPR_DEBUG, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, - closure, grpc_core::ExecCtx::Get()->combiner_data()->active_combiner)); + GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, + "C:%p grpc_combiner_execute_finally c=%p; ac=%p", + lock, closure, exec_ctx->active_combiner)); GPR_TIMER_BEGIN("combiner.execute_finally", 0); - if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner != lock) { + if (exec_ctx->active_combiner != lock) { GPR_TIMER_MARK("slowpath", 0); - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(enqueue_finally, closure, + GRPC_CLOSURE_SCHED(exec_ctx, + GRPC_CLOSURE_CREATE(enqueue_finally, closure, grpc_combiner_scheduler(lock)), error); GPR_TIMER_END("combiner.execute_finally", 0); @@ -353,8 +355,10 @@ static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { GPR_TIMER_END("combiner.execute_finally", 0); } -static void enqueue_finally(void* closure, grpc_error* error) { - combiner_finally_exec((grpc_closure*)closure, GRPC_ERROR_REF(error)); +static void enqueue_finally(grpc_exec_ctx* exec_ctx, void* closure, + grpc_error* error) { + combiner_finally_exec(exec_ctx, (grpc_closure*)closure, + GRPC_ERROR_REF(error)); } grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* combiner) { diff --git a/src/core/lib/iomgr/combiner.h b/src/core/lib/iomgr/combiner.h index 46b9ac58be..0c05511331 100644 --- a/src/core/lib/iomgr/combiner.h +++ b/src/core/lib/iomgr/combiner.h @@ -40,24 +40,26 @@ grpc_combiner* grpc_combiner_create(void); , const char *file, int line, const char *reason #define GRPC_COMBINER_REF(combiner, reason) \ grpc_combiner_ref((combiner), __FILE__, __LINE__, (reason)) -#define GRPC_COMBINER_UNREF(combiner, reason) \ - grpc_combiner_unref((combiner), __FILE__, __LINE__, (reason)) +#define GRPC_COMBINER_UNREF(exec_ctx, combiner, reason) \ + grpc_combiner_unref((exec_ctx), (combiner), __FILE__, __LINE__, (reason)) #else #define GRPC_COMBINER_DEBUG_ARGS #define GRPC_COMBINER_REF(combiner, reason) grpc_combiner_ref((combiner)) -#define GRPC_COMBINER_UNREF(combiner, reason) grpc_combiner_unref((combiner)) +#define GRPC_COMBINER_UNREF(exec_ctx, combiner, reason) \ + grpc_combiner_unref((exec_ctx), (combiner)) #endif // Ref/unref the lock, for when we're sharing the lock ownership // Prefer to use the macros above grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); -void grpc_combiner_unref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); +void grpc_combiner_unref(grpc_exec_ctx* exec_ctx, + grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); // Fetch a scheduler to schedule closures against grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* lock); // Scheduler to execute \a action within the lock just prior to unlocking. grpc_closure_scheduler* grpc_combiner_finally_scheduler(grpc_combiner* lock); -bool grpc_combiner_continue_exec_ctx(); +bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx); extern grpc_core::TraceFlag grpc_combiner_trace; diff --git a/src/core/lib/iomgr/endpoint.cc b/src/core/lib/iomgr/endpoint.cc index 9d4b102822..5eab1d3158 100644 --- a/src/core/lib/iomgr/endpoint.cc +++ b/src/core/lib/iomgr/endpoint.cc @@ -18,35 +18,41 @@ #include "src/core/lib/iomgr/endpoint.h" -void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { - ep->vtable->read(ep, slices, cb); +void grpc_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { + ep->vtable->read(exec_ctx, ep, slices, cb); } -void grpc_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { - ep->vtable->write(ep, slices, cb); +void grpc_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { + ep->vtable->write(exec_ctx, ep, slices, cb); } -void grpc_endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - ep->vtable->add_to_pollset(ep, pollset); +void grpc_endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) { + ep->vtable->add_to_pollset(exec_ctx, ep, pollset); } -void grpc_endpoint_add_to_pollset_set(grpc_endpoint* ep, +void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - ep->vtable->add_to_pollset_set(ep, pollset_set); + ep->vtable->add_to_pollset_set(exec_ctx, ep, pollset_set); } -void grpc_endpoint_delete_from_pollset_set(grpc_endpoint* ep, +void grpc_endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - ep->vtable->delete_from_pollset_set(ep, pollset_set); + ep->vtable->delete_from_pollset_set(exec_ctx, ep, pollset_set); } -void grpc_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { - ep->vtable->shutdown(ep, why); +void grpc_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { + ep->vtable->shutdown(exec_ctx, ep, why); } -void grpc_endpoint_destroy(grpc_endpoint* ep) { ep->vtable->destroy(ep); } +void grpc_endpoint_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { + ep->vtable->destroy(exec_ctx, ep); +} char* grpc_endpoint_get_peer(grpc_endpoint* ep) { return ep->vtable->get_peer(ep); diff --git a/src/core/lib/iomgr/endpoint.h b/src/core/lib/iomgr/endpoint.h index cd53099334..6ab0a6591c 100644 --- a/src/core/lib/iomgr/endpoint.h +++ b/src/core/lib/iomgr/endpoint.h @@ -33,13 +33,18 @@ typedef struct grpc_endpoint grpc_endpoint; typedef struct grpc_endpoint_vtable grpc_endpoint_vtable; struct grpc_endpoint_vtable { - void (*read)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb); - void (*write)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb); - void (*add_to_pollset)(grpc_endpoint* ep, grpc_pollset* pollset); - void (*add_to_pollset_set)(grpc_endpoint* ep, grpc_pollset_set* pollset); - void (*delete_from_pollset_set)(grpc_endpoint* ep, grpc_pollset_set* pollset); - void (*shutdown)(grpc_endpoint* ep, grpc_error* why); - void (*destroy)(grpc_endpoint* ep); + void (*read)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb); + void (*write)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb); + void (*add_to_pollset)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset); + void (*add_to_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset_set* pollset); + void (*delete_from_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset_set* pollset); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_error* why); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep); grpc_resource_user* (*get_resource_user)(grpc_endpoint* ep); char* (*get_peer)(grpc_endpoint* ep); int (*get_fd)(grpc_endpoint* ep); @@ -50,8 +55,8 @@ struct grpc_endpoint_vtable { indicates the endpoint is closed. Valid slices may be placed into \a slices even when the callback is invoked with error != GRPC_ERROR_NONE. */ -void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb); +void grpc_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb); char* grpc_endpoint_get_peer(grpc_endpoint* ep); @@ -69,22 +74,26 @@ int grpc_endpoint_get_fd(grpc_endpoint* ep); No guarantee is made to the content of slices after a write EXCEPT that it is a valid slice buffer. */ -void grpc_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb); +void grpc_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb); /* Causes any pending and future read/write callbacks to run immediately with success==0 */ -void grpc_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why); -void grpc_endpoint_destroy(grpc_endpoint* ep); +void grpc_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why); +void grpc_endpoint_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep); /* Add an endpoint to a pollset or pollset_set, so that when the pollset is polled, events from this endpoint are considered */ -void grpc_endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset); -void grpc_endpoint_add_to_pollset_set(grpc_endpoint* ep, +void grpc_endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset); +void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set); /* Delete an endpoint from a pollset_set */ -void grpc_endpoint_delete_from_pollset_set(grpc_endpoint* ep, +void grpc_endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set); grpc_resource_user* grpc_endpoint_get_resource_user(grpc_endpoint* endpoint); diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index 0b4aefd1b7..f5f59f9917 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -54,17 +54,18 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name, char* final_name; create_sockets(sv); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_asprintf(&final_name, "%s:client", name); - p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name), args, + p.client = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], final_name), args, "socketpair-server"); gpr_free(final_name); gpr_asprintf(&final_name, "%s:server", name); - p.server = grpc_tcp_create(grpc_fd_create(sv[0], final_name), args, + p.server = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[0], final_name), args, "socketpair-client"); gpr_free(final_name); + grpc_exec_ctx_finish(&exec_ctx); return p; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index cc07ac0708..afa995a1c7 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -72,12 +72,14 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( SOCKET sv[2]; grpc_endpoint_pair p; create_sockets(sv); - grpc_core::ExecCtx exec_ctx; - p.client = grpc_tcp_create(grpc_winsocket_create(sv[1], "endpoint:client"), + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + p.client = grpc_tcp_create(&exec_ctx, + grpc_winsocket_create(sv[1], "endpoint:client"), channel_args, "endpoint:server"); - p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server"), + p.server = grpc_tcp_create(&exec_ctx, + grpc_winsocket_create(sv[0], "endpoint:server"), channel_args, "endpoint:client"); - + grpc_exec_ctx_finish(&exec_ctx); return p; } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 42cd7c455d..e6d640c106 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -156,7 +156,11 @@ static void unref_errs(grpc_error* err) { } } -static void unref_slice(grpc_slice slice) { grpc_slice_unref_internal(slice); } +static void unref_slice(grpc_slice slice) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, slice); + grpc_exec_ctx_finish(&exec_ctx); +} static void unref_strs(grpc_error* err) { for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) { diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index d9e8a30f5e..0dda1d924c 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -299,29 +299,31 @@ static int fd_wrapped_fd(grpc_fd* fd) { return fd->fd; } /* if 'releasing_fd' is true, it means that we are going to detach the internal * fd from grpc_fd structure (i.e which means we should not be calling * shutdown() syscall on that fd) */ -static void fd_shutdown_internal(grpc_fd* fd, grpc_error* why, - bool releasing_fd) { - if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { +static void fd_shutdown_internal(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_error* why, bool releasing_fd) { + if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { if (!releasing_fd) { shutdown(fd->fd, SHUT_RDWR); } - fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } /* Might be called multiple times */ -static void fd_shutdown(grpc_fd* fd, grpc_error* why) { - fd_shutdown_internal(fd, why, false); +static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { + fd_shutdown_internal(exec_ctx, fd, why, false); } -static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; bool is_release_fd = (release_fd != nullptr); if (!fd->read_closure->IsShutdown()) { - fd_shutdown_internal(fd, GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason), + fd_shutdown_internal(exec_ctx, fd, + GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason), is_release_fd); } @@ -333,7 +335,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, close(fd->fd); } - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_REF(error)); grpc_iomgr_unregister_object(&fd->iomgr_object); fd->read_closure->DestroyEvent(); @@ -345,7 +347,8 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, gpr_mu_unlock(&fd_freelist_mu); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, + grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -354,21 +357,26 @@ static bool fd_is_shutdown(grpc_fd* fd) { return fd->read_closure->IsShutdown(); } -static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { - fd->read_closure->NotifyOn(closure); +static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->read_closure->NotifyOn(exec_ctx, closure); } -static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { - fd->write_closure->NotifyOn(closure); +static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->write_closure->NotifyOn(exec_ctx, closure); } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); +static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_pollset* notifier) { + fd->read_closure->SetReady(exec_ctx); /* Use release store to match with acquire load in fd_get_read_notifier */ gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } +static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { + fd->write_closure->SetReady(exec_ctx); +} /******************************************************************************* * Pollset Definitions @@ -471,7 +479,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->next = pollset->prev = nullptr; } -static void pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { gpr_mu_lock(&pollset->mu); if (!pollset->seen_inactive) { pollset_neighborhood* neighborhood = pollset->neighborhood; @@ -499,26 +507,27 @@ static void pollset_destroy(grpc_pollset* pollset) { gpr_mu_destroy(&pollset->mu); } -static grpc_error* pollset_kick_all(grpc_pollset* pollset) { +static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { GPR_TIMER_BEGIN("pollset_kick_all", 0); grpc_error* error = GRPC_ERROR_NONE; if (pollset->root_worker != nullptr) { grpc_pollset_worker* worker = pollset->root_worker; do { - GRPC_STATS_INC_POLLSET_KICK(); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); switch (worker->state) { case KICKED: - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); break; case UNKICKED: SET_KICK_STATE(worker, KICKED); if (worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); gpr_cv_signal(&worker->cv); } break; case DESIGNATED_POLLER: - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); SET_KICK_STATE(worker, KICKED); append_error(&error, grpc_wakeup_fd_wakeup(&global_wakeup_fd), "pollset_kick_all"); @@ -534,29 +543,32 @@ static grpc_error* pollset_kick_all(grpc_pollset* pollset) { return error; } -static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { +static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->begin_refs == 0) { GPR_TIMER_MARK("pollset_finish_shutdown", 0); - GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); pollset->shutdown_closure = nullptr; } } -static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { GPR_TIMER_BEGIN("pollset_shutdown", 0); GPR_ASSERT(pollset->shutdown_closure == nullptr); GPR_ASSERT(!pollset->shutting_down); pollset->shutdown_closure = closure; pollset->shutting_down = true; - GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset)); - pollset_maybe_finish_shutdown(pollset); + GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); + pollset_maybe_finish_shutdown(exec_ctx, pollset); GPR_TIMER_END("pollset_shutdown", 0); } -static int poll_deadline_to_millis_timeout(grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); if (delta > INT_MAX) { return INT_MAX; } else if (delta < 0) { @@ -574,7 +586,8 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { NOTE ON SYNCRHONIZATION: Similar to do_epoll_wait(), this function is only called by g_active_poller thread. So there is no need for synchronization when accessing fields in g_epoll_set */ -static grpc_error* process_epoll_events(grpc_pollset* pollset) { +static grpc_error* process_epoll_events(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { static const char* err_desc = "process_events"; grpc_error* error = GRPC_ERROR_NONE; @@ -598,11 +611,11 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) { bool write_ev = (ev->events & EPOLLOUT) != 0; if (read_ev || cancel) { - fd_become_readable(fd, pollset); + fd_become_readable(exec_ctx, fd, pollset); } if (write_ev || cancel) { - fd_become_writable(fd); + fd_become_writable(exec_ctx, fd); } } } @@ -618,26 +631,27 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) { NOTE ON SYNCHRONIZATION: At any point of time, only the g_active_poller (i.e the designated poller thread) will be calling this function. So there is no need for any synchronization when accesing fields in g_epoll_set */ -static grpc_error* do_epoll_wait(grpc_pollset* ps, grpc_millis deadline) { +static grpc_error* do_epoll_wait(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, + grpc_millis deadline) { GPR_TIMER_BEGIN("do_epoll_wait", 0); int r; - int timeout = poll_deadline_to_millis_timeout(deadline); + int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); if (timeout != 0) { GRPC_SCHEDULING_START_BLOCKING_REGION; } do { - GRPC_STATS_INC_SYSCALL_POLL(); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = epoll_wait(g_epoll_set.epfd, g_epoll_set.events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); - GRPC_STATS_INC_POLL_EVENTS_RETURNED(r); + GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, r); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "ps: %p poll got %d events", ps, r); @@ -650,7 +664,8 @@ static grpc_error* do_epoll_wait(grpc_pollset* ps, grpc_millis deadline) { return GRPC_ERROR_NONE; } -static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, +static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { GPR_TIMER_BEGIN("begin_worker", 0); @@ -745,7 +760,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, SET_KICK_STATE(worker, KICKED); } } - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); } if (grpc_polling_trace.enabled()) { @@ -776,7 +791,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, } static bool check_neighborhood_for_available_poller( - pollset_neighborhood* neighborhood) { + grpc_exec_ctx* exec_ctx, pollset_neighborhood* neighborhood) { GPR_TIMER_BEGIN("check_neighborhood_for_available_poller", 0); bool found_worker = false; do { @@ -800,7 +815,7 @@ static bool check_neighborhood_for_available_poller( SET_KICK_STATE(inspect_worker, DESIGNATED_POLLER); if (inspect_worker->initialized_cv) { GPR_TIMER_MARK("signal worker", 0); - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); gpr_cv_signal(&inspect_worker->cv); } } else { @@ -840,7 +855,8 @@ static bool check_neighborhood_for_available_poller( return found_worker; } -static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, +static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { GPR_TIMER_BEGIN("end_worker", 0); if (grpc_polling_trace.enabled()) { @@ -850,7 +866,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, /* Make sure we appear kicked */ SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, - grpc_core::ExecCtx::Get()->closure_list()); + &exec_ctx->closure_list); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { if (worker->next != worker && worker->next->state == UNKICKED) { if (grpc_polling_trace.enabled()) { @@ -859,11 +875,11 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, GPR_ASSERT(worker->next->initialized_cv); gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next); SET_KICK_STATE(worker->next, DESIGNATED_POLLER); - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); gpr_cv_signal(&worker->next->cv); - if (grpc_core::ExecCtx::Get()->HasWork()) { + if (grpc_exec_ctx_has_work(exec_ctx)) { gpr_mu_unlock(&pollset->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); } } else { @@ -878,7 +894,8 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, &g_neighborhoods[(poller_neighborhood_idx + i) % g_num_neighborhoods]; if (gpr_mu_trylock(&neighborhood->mu)) { - found_worker = check_neighborhood_for_available_poller(neighborhood); + found_worker = + check_neighborhood_for_available_poller(exec_ctx, neighborhood); gpr_mu_unlock(&neighborhood->mu); scan_state[i] = true; } else { @@ -891,15 +908,16 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, &g_neighborhoods[(poller_neighborhood_idx + i) % g_num_neighborhoods]; gpr_mu_lock(&neighborhood->mu); - found_worker = check_neighborhood_for_available_poller(neighborhood); + found_worker = + check_neighborhood_for_available_poller(exec_ctx, neighborhood); gpr_mu_unlock(&neighborhood->mu); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); } - } else if (grpc_core::ExecCtx::Get()->HasWork()) { + } else if (grpc_exec_ctx_has_work(exec_ctx)) { gpr_mu_unlock(&pollset->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); } if (worker->initialized_cv) { @@ -909,7 +927,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, gpr_log(GPR_DEBUG, " .. remove worker"); } if (EMPTIED == worker_remove(pollset, worker)) { - pollset_maybe_finish_shutdown(pollset); + pollset_maybe_finish_shutdown(exec_ctx, pollset); } GPR_ASSERT(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); GPR_TIMER_END("end_worker", 0); @@ -919,7 +937,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_pollset* ps, +static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -932,7 +950,7 @@ static grpc_error* pollset_work(grpc_pollset* ps, return GRPC_ERROR_NONE; } - if (begin_worker(ps, &worker, worker_hdl, deadline)) { + if (begin_worker(exec_ctx, ps, &worker, worker_hdl, deadline)) { gpr_tls_set(&g_current_thread_pollset, (intptr_t)ps); gpr_tls_set(&g_current_thread_worker, (intptr_t)&worker); GPR_ASSERT(!ps->shutting_down); @@ -950,14 +968,14 @@ static grpc_error* pollset_work(grpc_pollset* ps, process_epoll_events() returns very quickly: It just queues the work on exec_ctx but does not execute it (the actual exectution or more - accurately grpc_core::ExecCtx::Get()->Flush() happens in end_worker() - AFTER selecting a designated poller). So we are not waiting long periods - without a designated poller */ + accurately grpc_exec_ctx_flush() happens in end_worker() AFTER selecting + a designated poller). So we are not waiting long periods without a + designated poller */ if (gpr_atm_acq_load(&g_epoll_set.cursor) == gpr_atm_acq_load(&g_epoll_set.num_events)) { - append_error(&error, do_epoll_wait(ps, deadline), err_desc); + append_error(&error, do_epoll_wait(exec_ctx, ps, deadline), err_desc); } - append_error(&error, process_epoll_events(ps), err_desc); + append_error(&error, process_epoll_events(exec_ctx, ps), err_desc); gpr_mu_lock(&ps->mu); /* lock */ @@ -965,17 +983,17 @@ static grpc_error* pollset_work(grpc_pollset* ps, } else { gpr_tls_set(&g_current_thread_pollset, (intptr_t)ps); } - end_worker(ps, &worker, worker_hdl); + end_worker(exec_ctx, ps, &worker, worker_hdl); gpr_tls_set(&g_current_thread_pollset, 0); GPR_TIMER_END("pollset_work", 0); return error; } -static grpc_error* pollset_kick(grpc_pollset* pollset, +static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { GPR_TIMER_BEGIN("pollset_kick", 0); - GRPC_STATS_INC_POLLSET_KICK(); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); grpc_error* ret_err = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { gpr_strvec log; @@ -1008,7 +1026,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { grpc_pollset_worker* root_worker = pollset->root_worker; if (root_worker == nullptr) { - GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); + GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); pollset->kicked_without_poller = true; if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked_without_poller"); @@ -1017,14 +1035,14 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } grpc_pollset_worker* next_worker = root_worker->next; if (root_worker->state == KICKED) { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. already kicked %p", root_worker); } SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. already kicked %p", next_worker); } @@ -1035,7 +1053,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, // there is no next worker root_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load( &g_active_poller)) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked %p", root_worker); } @@ -1043,7 +1061,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (next_worker->state == UNKICKED) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked %p", next_worker); } @@ -1061,12 +1079,12 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, } SET_KICK_STATE(root_worker, KICKED); if (root_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); gpr_cv_signal(&root_worker->cv); } goto done; } else { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker, root_worker); @@ -1076,13 +1094,13 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, goto done; } } else { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); GPR_ASSERT(next_worker->state == KICKED); SET_KICK_STATE(next_worker, KICKED); goto done; } } else { - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked while waking up"); } @@ -1099,7 +1117,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, goto done; } else if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker); } @@ -1107,7 +1125,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, goto done; } else if (specific_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick active poller"); } @@ -1115,7 +1133,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (specific_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick waiting worker"); } @@ -1123,7 +1141,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, gpr_cv_signal(&specific_worker->cv); goto done; } else { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick non-waiting worker"); } @@ -1135,7 +1153,8 @@ done: return ret_err; } -static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {} +static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_fd* fd) {} /******************************************************************************* * Pollset-set Definitions @@ -1145,20 +1164,27 @@ static grpc_pollset_set* pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -static void pollset_set_destroy(grpc_pollset_set* pss) {} +static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss) {} -static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {} +static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) {} -static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {} +static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) {} -static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {} +static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) {} -static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {} +static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) {} -static void pollset_set_add_pollset_set(grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} -static void pollset_set_del_pollset_set(grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} /******************************************************************************* @@ -1234,7 +1260,7 @@ const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { gpr_log(GPR_ERROR, "Skipping epoll1 becuase GRPC_LINUX_EPOLL is not defined."); - return nullptr; + return NULL; } #endif /* defined(GRPC_POSIX_SOCKET) */ #endif /* !defined(GRPC_LINUX_EPOLL) */ diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index b2817156a8..62643df697 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -257,7 +257,8 @@ static gpr_mu fd_freelist_mu; #ifndef NDEBUG #define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__) -#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) +#define UNREF_BY(ec, fd, n, reason) \ + unref_by(ec, fd, n, reason, __FILE__, __LINE__) static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, int line) { if (grpc_trace_fd_refcount.enabled()) { @@ -268,13 +269,13 @@ static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, } #else #define REF_BY(fd, n, reason) ref_by(fd, n) -#define UNREF_BY(fd, n, reason) unref_by(fd, n) +#define UNREF_BY(ec, fd, n, reason) unref_by(ec, fd, n) static void ref_by(grpc_fd* fd, int n) { #endif GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0); } -static void fd_destroy(void* arg, grpc_error* error) { +static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_fd* fd = (grpc_fd*)arg; /* Add the fd to the freelist */ grpc_iomgr_unregister_object(&fd->iomgr_object); @@ -292,8 +293,8 @@ static void fd_destroy(void* arg, grpc_error* error) { } #ifndef NDEBUG -static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, - int line) { +static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n, + const char* reason, const char* file, int line) { if (grpc_trace_fd_refcount.enabled()) { gpr_log(GPR_DEBUG, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", @@ -301,11 +302,12 @@ static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); } #else -static void unref_by(grpc_fd* fd, int n) { +static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n) { #endif gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n); if (old == n) { GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(fd_destroy, fd, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } else { @@ -371,7 +373,8 @@ static int fd_wrapped_fd(grpc_fd* fd) { return (gpr_atm_acq_load(&fd->refst) & 1) ? ret_fd : -1; } -static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { bool is_fd_closed = already_closed; @@ -396,14 +399,15 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, to be alive (and not added to freelist) until the end of this function */ REF_BY(fd, 1, reason); - GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_NONE); gpr_mu_unlock(&fd->orphan_mu); - UNREF_BY(fd, 2, reason); /* Drop the reference */ + UNREF_BY(exec_ctx, fd, 2, reason); /* Drop the reference */ } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, + grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -413,20 +417,22 @@ static bool fd_is_shutdown(grpc_fd* fd) { } /* Might be called multiple times */ -static void fd_shutdown(grpc_fd* fd, grpc_error* why) { - if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { +static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { + if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { shutdown(fd->fd, SHUT_RDWR); - fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } -static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { - fd->read_closure->NotifyOn(closure); +static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->read_closure->NotifyOn(exec_ctx, closure); } -static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { - fd->write_closure->NotifyOn(closure); +static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->write_closure->NotifyOn(exec_ctx, closure); } /******************************************************************************* @@ -550,7 +556,8 @@ static void pollset_global_shutdown(void) { } /* pollset->mu must be held while calling this function */ -static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { +static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) " @@ -560,7 +567,7 @@ static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { } if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->containing_pollset_set_count == 0) { - GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); pollset->shutdown_closure = nullptr; } } @@ -568,7 +575,8 @@ static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { /* pollset->mu must be held before calling this function, * pollset->active_pollable->mu & specific_worker->pollable_obj->mu must not be * held */ -static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { +static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, + grpc_pollset_worker* specific_worker) { pollable* p = specific_worker->pollable_obj; grpc_core::mu_guard lock(&p->mu); GPR_ASSERT(specific_worker != nullptr); @@ -576,19 +584,19 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p); } - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); return GRPC_ERROR_NONE; } if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p); } - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); specific_worker->kicked = true; return GRPC_ERROR_NONE; } if (specific_worker == p->root_worker) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p); } @@ -597,7 +605,7 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { return error; } if (specific_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p); } @@ -610,9 +618,9 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { return GRPC_ERROR_NONE; } -static grpc_error* pollset_kick(grpc_pollset* pollset, +static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - GRPC_STATS_INC_POLLSET_KICK(); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", @@ -626,7 +634,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset); } - GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); + GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); pollset->kicked_without_poller = true; return GRPC_ERROR_NONE; } else { @@ -646,28 +654,29 @@ static grpc_error* pollset_kick(grpc_pollset* pollset, // so we take our chances and choose the SECOND worker enqueued against // the pollset as a worker that's likely to be in cv_wait return kick_one_worker( - pollset->root_worker->links[PWLINK_POLLSET].next); + exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next); } } else { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset); } - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); return GRPC_ERROR_NONE; } } else { - return kick_one_worker(specific_worker); + return kick_one_worker(exec_ctx, specific_worker); } } -static grpc_error* pollset_kick_all(grpc_pollset* pollset) { +static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { grpc_error* error = GRPC_ERROR_NONE; const char* err_desc = "pollset_kick_all"; grpc_pollset_worker* w = pollset->root_worker; if (w != nullptr) { do { - GRPC_STATS_INC_POLLSET_KICK(); - append_error(&error, kick_one_worker(w), err_desc); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + append_error(&error, kick_one_worker(exec_ctx, w), err_desc); w = w->links[PWLINK_POLLSET].next; } while (w != pollset->root_worker); } @@ -680,9 +689,10 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &pollset->mu; } -static int poll_deadline_to_millis_timeout(grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -691,8 +701,9 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { return (int)delta; } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); +static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_pollset* notifier) { + fd->read_closure->SetReady(exec_ctx); /* Note, it is possible that fd_become_readable might be called twice with different 'notifier's when an fd becomes readable and it is in two epoll @@ -703,7 +714,9 @@ static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } +static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { + fd->write_closure->SetReady(exec_ctx); +} static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { gpr_mu_lock(&fd->pollable_mu); @@ -732,14 +745,16 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { } /* pollset->po.mu lock must be held by the caller before calling this */ -static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { GPR_ASSERT(pollset->shutdown_closure == nullptr); pollset->shutdown_closure = closure; - GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset)); - pollset_maybe_finish_shutdown(pollset); + GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); + pollset_maybe_finish_shutdown(exec_ctx, pollset); } -static grpc_error* pollable_process_events(grpc_pollset* pollset, +static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, pollable* pollable_obj, bool drain) { static const char* err_desc = "pollset_process_events"; grpc_error* error = GRPC_ERROR_NONE; @@ -769,10 +784,10 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, pollset, fd, cancel, read_ev, write_ev); } if (read_ev || cancel) { - fd_become_readable(fd, pollset); + fd_become_readable(exec_ctx, fd, pollset); } if (write_ev || cancel) { - fd_become_writable(fd); + fd_become_writable(exec_ctx, fd); } } } @@ -781,13 +796,14 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, } /* pollset_shutdown is guaranteed to be called before pollset_destroy. */ -static void pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = nullptr; } -static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) { - int timeout = poll_deadline_to_millis_timeout(deadline); +static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, + grpc_millis deadline) { + int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); if (grpc_polling_trace.enabled()) { char* desc = pollable_desc(p); @@ -800,11 +816,11 @@ static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) { } int r; do { - GRPC_STATS_INC_SYSCALL_POLL(); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = epoll_wait(p->epfd, p->events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); @@ -859,7 +875,8 @@ static worker_remove_result worker_remove(grpc_pollset_worker** root_worker, } /* Return true if this thread should poll */ -static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, +static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { bool do_poll = (pollset->shutdown_closure == nullptr); @@ -880,7 +897,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset, worker->pollable_obj, worker, - poll_deadline_to_millis_timeout(deadline)); + poll_deadline_to_millis_timeout(exec_ctx, deadline)); } while (do_poll && worker->pollable_obj->root_worker != worker) { if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu, @@ -902,7 +919,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, worker->pollable_obj, worker); } } - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); } else { gpr_mu_unlock(&pollset->mu); } @@ -911,7 +928,8 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, return do_poll; } -static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, +static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { gpr_mu_lock(&pollset->mu); gpr_mu_lock(&worker->pollable_obj->mu); @@ -927,7 +945,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, case WRR_EMPTIED: if (pollset->active_pollable != worker->pollable_obj) { // pollable no longer being polled: flush events - pollable_process_events(pollset, worker->pollable_obj, true); + pollable_process_events(exec_ctx, pollset, worker->pollable_obj, true); } break; case WRR_REMOVED: @@ -937,7 +955,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, POLLABLE_UNREF(worker->pollable_obj, "pollset_worker"); if (worker_remove(&pollset->root_worker, worker, PWLINK_POLLSET) == WRR_EMPTIED) { - pollset_maybe_finish_shutdown(pollset); + pollset_maybe_finish_shutdown(exec_ctx, pollset); } if (worker->initialized_cv) { gpr_cv_destroy(&worker->cv); @@ -952,7 +970,7 @@ static long gettid(void) { return syscall(__NR_gettid); } The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { #ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP @@ -970,7 +988,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR " kwp=%d pollable=%p", - pollset, worker_hdl, WORKER_PTR, grpc_core::ExecCtx::Get()->Now(), + pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(exec_ctx), deadline, pollset->kicked_without_poller, pollset->active_pollable); } static const char* err_desc = "pollset_work"; @@ -978,23 +996,25 @@ static grpc_error* pollset_work(grpc_pollset* pollset, if (pollset->kicked_without_poller) { pollset->kicked_without_poller = false; } else { - if (begin_worker(pollset, WORKER_PTR, worker_hdl, deadline)) { + if (begin_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl, deadline)) { gpr_tls_set(&g_current_thread_pollset, (intptr_t)pollset); gpr_tls_set(&g_current_thread_worker, (intptr_t)WORKER_PTR); if (WORKER_PTR->pollable_obj->event_cursor == WORKER_PTR->pollable_obj->event_count) { - append_error(&error, pollable_epoll(WORKER_PTR->pollable_obj, deadline), - err_desc); + append_error( + &error, + pollable_epoll(exec_ctx, WORKER_PTR->pollable_obj, deadline), + err_desc); } - append_error( - &error, - pollable_process_events(pollset, WORKER_PTR->pollable_obj, false), - err_desc); - grpc_core::ExecCtx::Get()->Flush(); + append_error(&error, + pollable_process_events(exec_ctx, pollset, + WORKER_PTR->pollable_obj, false), + err_desc); + grpc_exec_ctx_flush(exec_ctx); gpr_tls_set(&g_current_thread_pollset, 0); gpr_tls_set(&g_current_thread_worker, 0); } - end_worker(pollset, WORKER_PTR, worker_hdl); + end_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl); } #ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP gpr_free(worker); @@ -1004,7 +1024,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, } static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( - grpc_pollset* pollset, grpc_fd* fd) { + grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* fd) { static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd"; grpc_error* error = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { @@ -1012,7 +1032,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( "PS:%p add fd %p (%d); transition pollable from empty to fd", pollset, fd, fd->fd); } - append_error(&error, pollset_kick_all(pollset), err_desc); + append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); POLLABLE_UNREF(pollset->active_pollable, "pollset"); append_error(&error, fd_get_or_become_pollable(fd, &pollset->active_pollable), err_desc); @@ -1020,7 +1040,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( } static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( - grpc_pollset* pollset, grpc_fd* and_add_fd) { + grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* and_add_fd) { static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi"; grpc_error* error = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { @@ -1030,7 +1050,7 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( pollset, and_add_fd, and_add_fd ? and_add_fd->fd : -1, pollset->active_pollable->owner_fd); } - append_error(&error, pollset_kick_all(pollset), err_desc); + append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); grpc_fd* initial_fd = pollset->active_pollable->owner_fd; POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = nullptr; @@ -1048,25 +1068,27 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( } /* expects pollsets locked, flag whether fd is locked or not */ -static grpc_error* pollset_add_fd_locked(grpc_pollset* pollset, grpc_fd* fd) { +static grpc_error* pollset_add_fd_locked(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, grpc_fd* fd) { grpc_error* error = GRPC_ERROR_NONE; pollable* po_at_start = POLLABLE_REF(pollset->active_pollable, "pollset_add_fd"); switch (pollset->active_pollable->type) { case PO_EMPTY: /* empty pollable --> single fd pollable */ - error = pollset_transition_pollable_from_empty_to_fd_locked(pollset, fd); + error = pollset_transition_pollable_from_empty_to_fd_locked(exec_ctx, + pollset, fd); break; case PO_FD: gpr_mu_lock(&po_at_start->owner_fd->orphan_mu); if ((gpr_atm_no_barrier_load(&pollset->active_pollable->owner_fd->refst) & 1) == 0) { - error = - pollset_transition_pollable_from_empty_to_fd_locked(pollset, fd); + error = pollset_transition_pollable_from_empty_to_fd_locked( + exec_ctx, pollset, fd); } else { /* fd --> multipoller */ - error = - pollset_transition_pollable_from_fd_to_multi_locked(pollset, fd); + error = pollset_transition_pollable_from_fd_to_multi_locked( + exec_ctx, pollset, fd); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1083,7 +1105,8 @@ static grpc_error* pollset_add_fd_locked(grpc_pollset* pollset, grpc_fd* fd) { return error; } -static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset, +static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, pollable** pollable_obj) { grpc_error* error = GRPC_ERROR_NONE; pollable* po_at_start = @@ -1100,8 +1123,8 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset, POLLABLE_UNREF(pollset->active_pollable, "pollset"); error = pollable_create(PO_MULTI, &pollset->active_pollable); } else { - error = pollset_transition_pollable_from_fd_to_multi_locked(pollset, - nullptr); + error = pollset_transition_pollable_from_fd_to_multi_locked( + exec_ctx, pollset, nullptr); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1119,9 +1142,10 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset, return error; } -static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { +static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_fd* fd) { gpr_mu_lock(&pollset->mu); - grpc_error* error = pollset_add_fd_locked(pollset, fd); + grpc_error* error = pollset_add_fd_locked(exec_ctx, pollset, fd); gpr_mu_unlock(&pollset->mu); GRPC_LOG_IF_ERROR("pollset_add_fd", error); } @@ -1147,27 +1171,28 @@ static grpc_pollset_set* pollset_set_create(void) { return pss; } -static void pollset_set_unref(grpc_pollset_set* pss) { +static void pollset_set_unref(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) { if (pss == nullptr) return; if (!gpr_unref(&pss->refs)) return; - pollset_set_unref(pss->parent); + pollset_set_unref(exec_ctx, pss->parent); gpr_mu_destroy(&pss->mu); for (size_t i = 0; i < pss->pollset_count; i++) { gpr_mu_lock(&pss->pollsets[i]->mu); if (0 == --pss->pollsets[i]->containing_pollset_set_count) { - pollset_maybe_finish_shutdown(pss->pollsets[i]); + pollset_maybe_finish_shutdown(exec_ctx, pss->pollsets[i]); } gpr_mu_unlock(&pss->pollsets[i]->mu); } for (size_t i = 0; i < pss->fd_count; i++) { - UNREF_BY(pss->fds[i], 2, "pollset_set"); + UNREF_BY(exec_ctx, pss->fds[i], 2, "pollset_set"); } gpr_free(pss->pollsets); gpr_free(pss->fds); gpr_free(pss); } -static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { +static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd); } @@ -1190,7 +1215,8 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { GRPC_LOG_IF_ERROR(err_desc, error); } -static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { +static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: del fd %p", pss, fd); } @@ -1198,7 +1224,7 @@ static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { size_t i; for (i = 0; i < pss->fd_count; i++) { if (pss->fds[i] == fd) { - UNREF_BY(fd, 2, "pollset_set"); + UNREF_BY(exec_ctx, fd, 2, "pollset_set"); break; } } @@ -1210,7 +1236,8 @@ static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { gpr_mu_unlock(&pss->mu); } -static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: del pollset %p", pss, ps); } @@ -1229,15 +1256,15 @@ static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { gpr_mu_unlock(&pss->mu); gpr_mu_lock(&ps->mu); if (0 == --ps->containing_pollset_set_count) { - pollset_maybe_finish_shutdown(ps); + pollset_maybe_finish_shutdown(exec_ctx, ps); } gpr_mu_unlock(&ps->mu); } // add all fds to pollables, and output a new array of unorphaned out_fds // assumes pollsets are multipollable -static grpc_error* add_fds_to_pollsets(grpc_fd** fds, size_t fd_count, - grpc_pollset** pollsets, +static grpc_error* add_fds_to_pollsets(grpc_exec_ctx* exec_ctx, grpc_fd** fds, + size_t fd_count, grpc_pollset** pollsets, size_t pollset_count, const char* err_desc, grpc_fd** out_fds, size_t* out_fd_count) { @@ -1246,7 +1273,7 @@ static grpc_error* add_fds_to_pollsets(grpc_fd** fds, size_t fd_count, gpr_mu_lock(&fds[i]->orphan_mu); if ((gpr_atm_no_barrier_load(&fds[i]->refst) & 1) == 0) { gpr_mu_unlock(&fds[i]->orphan_mu); - UNREF_BY(fds[i], 2, "pollset_set"); + UNREF_BY(exec_ctx, fds[i], 2, "pollset_set"); } else { for (size_t j = 0; j < pollset_count; j++) { append_error(&error, @@ -1260,7 +1287,8 @@ static grpc_error* add_fds_to_pollsets(grpc_fd** fds, size_t fd_count, return error; } -static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: add pollset %p", pss, ps); } @@ -1268,8 +1296,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { static const char* err_desc = "pollset_set_add_pollset"; pollable* pollable_obj = nullptr; gpr_mu_lock(&ps->mu); - if (!GRPC_LOG_IF_ERROR(err_desc, - pollset_as_multipollable_locked(ps, &pollable_obj))) { + if (!GRPC_LOG_IF_ERROR(err_desc, pollset_as_multipollable_locked( + exec_ctx, ps, &pollable_obj))) { GPR_ASSERT(pollable_obj == nullptr); gpr_mu_unlock(&ps->mu); return; @@ -1280,8 +1308,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { size_t initial_fd_count = pss->fd_count; pss->fd_count = 0; append_error(&error, - add_fds_to_pollsets(pss->fds, initial_fd_count, &ps, 1, err_desc, - pss->fds, &pss->fd_count), + add_fds_to_pollsets(exec_ctx, pss->fds, initial_fd_count, &ps, 1, + err_desc, pss->fds, &pss->fd_count), err_desc); if (pss->pollset_count == pss->pollset_capacity) { pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8); @@ -1295,7 +1323,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { GRPC_LOG_IF_ERROR(err_desc, error); } -static void pollset_set_add_pollset_set(grpc_pollset_set* a, +static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* a, grpc_pollset_set* b) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS: merge (%p, %p)", a, b); @@ -1344,13 +1373,13 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, a->fd_count = 0; append_error( &error, - add_fds_to_pollsets(a->fds, initial_a_fd_count, b->pollsets, + add_fds_to_pollsets(exec_ctx, a->fds, initial_a_fd_count, b->pollsets, b->pollset_count, "merge_a2b", a->fds, &a->fd_count), err_desc); append_error( &error, - add_fds_to_pollsets(b->fds, b->fd_count, a->pollsets, a->pollset_count, - "merge_b2a", a->fds, &a->fd_count), + add_fds_to_pollsets(exec_ctx, b->fds, b->fd_count, a->pollsets, + a->pollset_count, "merge_b2a", a->fds, &a->fd_count), err_desc); if (a->pollset_capacity < a->pollset_count + b->pollset_count) { a->pollset_capacity = @@ -1372,7 +1401,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a, gpr_mu_unlock(&b->mu); } -static void pollset_set_del_pollset_set(grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} /******************************************************************************* @@ -1451,7 +1481,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux( bool explicitly_requested) { gpr_log(GPR_ERROR, "Skipping epollex becuase GRPC_LINUX_EPOLL is not defined."); - return nullptr; + return NULL; } #endif /* defined(GRPC_POSIX_SOCKET) */ diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 7a8962f4a8..12c8483b8e 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -165,12 +165,13 @@ static void fd_global_shutdown(void); #ifndef NDEBUG #define PI_ADD_REF(p, r) pi_add_ref_dbg((p), (r), __FILE__, __LINE__) -#define PI_UNREF(p, r) pi_unref_dbg((p), (r), __FILE__, __LINE__) +#define PI_UNREF(exec_ctx, p, r) \ + pi_unref_dbg((exec_ctx), (p), (r), __FILE__, __LINE__) #else #define PI_ADD_REF(p, r) pi_add_ref((p)) -#define PI_UNREF(p, r) pi_unref((p)) +#define PI_UNREF(exec_ctx, p, r) pi_unref((exec_ctx), (p)) #endif @@ -269,7 +270,7 @@ static grpc_wakeup_fd polling_island_wakeup_fd; static __thread polling_island* g_current_thread_polling_island; /* Forward declaration */ -static void polling_island_delete(polling_island* pi); +static void polling_island_delete(grpc_exec_ctx* exec_ctx, polling_island* pi); #ifdef GRPC_TSAN /* Currently TSAN may incorrectly flag data races between epoll_ctl and @@ -283,7 +284,7 @@ gpr_atm g_epoll_sync; #endif /* defined(GRPC_TSAN) */ static void pi_add_ref(polling_island* pi); -static void pi_unref(polling_island* pi); +static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi); #ifndef NDEBUG static void pi_add_ref_dbg(polling_island* pi, const char* reason, @@ -298,8 +299,8 @@ static void pi_add_ref_dbg(polling_island* pi, const char* reason, pi_add_ref(pi); } -static void pi_unref_dbg(polling_island* pi, const char* reason, - const char* file, int line) { +static void pi_unref_dbg(grpc_exec_ctx* exec_ctx, polling_island* pi, + const char* reason, const char* file, int line) { if (grpc_polling_trace.enabled()) { gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count); gpr_log(GPR_DEBUG, @@ -307,7 +308,7 @@ static void pi_unref_dbg(polling_island* pi, const char* reason, " (%s) - (%s, %d)", pi, old_cnt, (old_cnt - 1), reason, file, line); } - pi_unref(pi); + pi_unref(exec_ctx, pi); } #endif @@ -315,7 +316,7 @@ static void pi_add_ref(polling_island* pi) { gpr_atm_no_barrier_fetch_add(&pi->ref_count, 1); } -static void pi_unref(polling_island* pi) { +static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi) { /* If ref count went to zero, delete the polling island. Note that this deletion not be done under a lock. Once the ref count goes to zero, we are guaranteed that no one else holds a reference to the @@ -326,9 +327,9 @@ static void pi_unref(polling_island* pi) { */ if (1 == gpr_atm_full_fetch_add(&pi->ref_count, -1)) { polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); - polling_island_delete(pi); + polling_island_delete(exec_ctx, pi); if (next != nullptr) { - PI_UNREF(next, "pi_delete"); /* Recursive call */ + PI_UNREF(exec_ctx, next, "pi_delete"); /* Recursive call */ } } } @@ -464,7 +465,8 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd, } /* Might return NULL in case of an error */ -static polling_island* polling_island_create(grpc_fd* initial_fd, +static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, + grpc_fd* initial_fd, grpc_error** error) { polling_island* pi = nullptr; const char* err_desc = "polling_island_create"; @@ -480,7 +482,7 @@ static polling_island* polling_island_create(grpc_fd* initial_fd, gpr_atm_rel_store(&pi->ref_count, 0); gpr_atm_rel_store(&pi->poller_count, 0); - gpr_atm_rel_store(&pi->merged_to, (gpr_atm) nullptr); + gpr_atm_rel_store(&pi->merged_to, (gpr_atm)NULL); pi->epoll_fd = epoll_create1(EPOLL_CLOEXEC); @@ -495,13 +497,13 @@ static polling_island* polling_island_create(grpc_fd* initial_fd, done: if (*error != GRPC_ERROR_NONE) { - polling_island_delete(pi); + polling_island_delete(exec_ctx, pi); pi = nullptr; } return pi; } -static void polling_island_delete(polling_island* pi) { +static void polling_island_delete(grpc_exec_ctx* exec_ctx, polling_island* pi) { GPR_ASSERT(pi->fd_cnt == 0); if (pi->epoll_fd >= 0) { @@ -860,7 +862,8 @@ static int fd_wrapped_fd(grpc_fd* fd) { return ret_fd; } -static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; polling_island* unref_pi = nullptr; @@ -899,7 +902,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, fd->orphaned = true; - GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_REF(error)); gpr_mu_unlock(&fd->po.mu); UNREF_BY(fd, 2, reason); /* Drop the reference */ @@ -908,7 +911,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, The polling island owns a workqueue which owns an fd, and unreffing inside the lock can cause an eventual lock loop that makes TSAN very unhappy. */ - PI_UNREF(unref_pi, "fd_orphan"); + PI_UNREF(exec_ctx, unref_pi, "fd_orphan"); } if (error != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(error); @@ -917,7 +920,8 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, GRPC_ERROR_UNREF(error); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, + grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -927,20 +931,22 @@ static bool fd_is_shutdown(grpc_fd* fd) { } /* Might be called multiple times */ -static void fd_shutdown(grpc_fd* fd, grpc_error* why) { - if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { +static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { + if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { shutdown(fd->fd, SHUT_RDWR); - fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } -static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { - fd->read_closure->NotifyOn(closure); +static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->read_closure->NotifyOn(exec_ctx, closure); } -static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { - fd->write_closure->NotifyOn(closure); +static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + fd->write_closure->NotifyOn(exec_ctx, closure); } /******************************************************************************* @@ -1022,11 +1028,11 @@ static void push_front_worker(grpc_pollset* p, grpc_pollset_worker* worker) { } /* p->mu must be held before calling this function */ -static grpc_error* pollset_kick(grpc_pollset* p, +static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, grpc_pollset_worker* specific_worker) { GPR_TIMER_BEGIN("pollset_kick", 0); grpc_error* error = GRPC_ERROR_NONE; - GRPC_STATS_INC_POLLSET_KICK(); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); const char* err_desc = "Kick Failure"; grpc_pollset_worker* worker = specific_worker; if (worker != nullptr) { @@ -1090,9 +1096,10 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutdown_done = nullptr; } -static int poll_deadline_to_millis_timeout(grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); + grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -1101,8 +1108,9 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { return (int)delta; } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); +static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_pollset* notifier) { + fd->read_closure->SetReady(exec_ctx); /* Note, it is possible that fd_become_readable might be called twice with different 'notifier's when an fd becomes readable and it is in two epoll @@ -1113,34 +1121,39 @@ static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } +static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { + fd->write_closure->SetReady(exec_ctx); +} -static void pollset_release_polling_island(grpc_pollset* ps, +static void pollset_release_polling_island(grpc_exec_ctx* exec_ctx, + grpc_pollset* ps, const char* reason) { if (ps->po.pi != nullptr) { - PI_UNREF(ps->po.pi, reason); + PI_UNREF(exec_ctx, ps->po.pi, reason); } ps->po.pi = nullptr; } -static void finish_shutdown_locked(grpc_pollset* pollset) { +static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { /* The pollset cannot have any workers if we are at this stage */ GPR_ASSERT(!pollset_has_workers(pollset)); pollset->finish_shutdown_called = true; /* Release the ref and set pollset->po.pi to NULL */ - pollset_release_polling_island(pollset, "ps_shutdown"); - GRPC_CLOSURE_SCHED(pollset->shutdown_done, GRPC_ERROR_NONE); + pollset_release_polling_island(exec_ctx, pollset, "ps_shutdown"); + GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_done, GRPC_ERROR_NONE); } /* pollset->po.mu lock must be held by the caller before calling this */ -static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { GPR_TIMER_BEGIN("pollset_shutdown", 0); GPR_ASSERT(!pollset->shutting_down); pollset->shutting_down = true; pollset->shutdown_done = closure; - pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); + pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); /* If the pollset has any workers, we cannot call finish_shutdown_locked() because it would release the underlying polling island. In such a case, we @@ -1148,7 +1161,7 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { if (!pollset_has_workers(pollset)) { GPR_ASSERT(!pollset->finish_shutdown_called); GPR_TIMER_MARK("pollset_shutdown.finish_shutdown_locked", 0); - finish_shutdown_locked(pollset); + finish_shutdown_locked(exec_ctx, pollset); } GPR_TIMER_END("pollset_shutdown", 0); } @@ -1156,14 +1169,15 @@ static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { /* pollset_shutdown is guaranteed to be called before pollset_destroy. So other * than destroying the mutexes, there is nothing special that needs to be done * here */ -static void pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { GPR_ASSERT(!pollset_has_workers(pollset)); gpr_mu_destroy(&pollset->po.mu); } #define GRPC_EPOLL_MAX_EVENTS 100 /* Note: sig_mask contains the signal mask to use *during* epoll_wait() */ -static void pollset_work_and_unlock(grpc_pollset* pollset, +static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, grpc_pollset_worker* worker, int timeout_ms, sigset_t* sig_mask, grpc_error** error) { struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS]; @@ -1185,7 +1199,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, this function (i.e pollset_work_and_unlock()) is called */ if (pollset->po.pi == nullptr) { - pollset->po.pi = polling_island_create(nullptr, error); + pollset->po.pi = polling_island_create(exec_ctx, nullptr, error); if (pollset->po.pi == nullptr) { GPR_TIMER_END("pollset_work_and_unlock", 0); return; /* Fatal error. We cannot continue */ @@ -1205,7 +1219,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, /* Always do PI_ADD_REF before PI_UNREF because PI_UNREF may cause the polling island to be deleted */ PI_ADD_REF(pi, "ps"); - PI_UNREF(pollset->po.pi, "ps"); + PI_UNREF(exec_ctx, pollset->po.pi, "ps"); pollset->po.pi = pi; } @@ -1219,10 +1233,10 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, g_current_thread_polling_island = pi; GRPC_SCHEDULING_START_BLOCKING_REGION; - GRPC_STATS_INC_SYSCALL_POLL(); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms, sig_mask); - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); if (ep_rv < 0) { if (errno != EINTR) { gpr_asprintf(&err_msg, @@ -1260,10 +1274,10 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, int read_ev = ep_ev[i].events & (EPOLLIN | EPOLLPRI); int write_ev = ep_ev[i].events & EPOLLOUT; if (read_ev || cancel) { - fd_become_readable(fd, pollset); + fd_become_readable(exec_ctx, fd, pollset); } if (write_ev || cancel) { - fd_become_writable(fd); + fd_become_writable(exec_ctx, fd); } } } @@ -1278,7 +1292,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, that we got before releasing the polling island lock). This is because pollset->po.pi pointer might get udpated in other parts of the code when there is an island merge while we are doing epoll_wait() above */ - PI_UNREF(pi, "ps_work"); + PI_UNREF(exec_ctx, pi, "ps_work"); GPR_TIMER_END("pollset_work_and_unlock", 0); } @@ -1287,12 +1301,12 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { GPR_TIMER_BEGIN("pollset_work", 0); grpc_error* error = GRPC_ERROR_NONE; - int timeout_ms = poll_deadline_to_millis_timeout(deadline); + int timeout_ms = poll_deadline_to_millis_timeout(exec_ctx, deadline); sigset_t new_mask; @@ -1350,9 +1364,9 @@ static grpc_error* pollset_work(grpc_pollset* pollset, push_front_worker(pollset, &worker); /* Add worker to pollset */ - pollset_work_and_unlock(pollset, &worker, timeout_ms, &g_orig_sigmask, - &error); - grpc_core::ExecCtx::Get()->Flush(); + pollset_work_and_unlock(exec_ctx, pollset, &worker, timeout_ms, + &g_orig_sigmask, &error); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->po.mu); @@ -1372,10 +1386,10 @@ static grpc_error* pollset_work(grpc_pollset* pollset, if (pollset->shutting_down && !pollset_has_workers(pollset) && !pollset->finish_shutdown_called) { GPR_TIMER_MARK("pollset_work.finish_shutdown_locked", 0); - finish_shutdown_locked(pollset); + finish_shutdown_locked(exec_ctx, pollset); gpr_mu_unlock(&pollset->po.mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->po.mu); } @@ -1390,8 +1404,9 @@ static grpc_error* pollset_work(grpc_pollset* pollset, return error; } -static void add_poll_object(poll_obj* bag, poll_obj_type bag_type, - poll_obj* item, poll_obj_type item_type) { +static void add_poll_object(grpc_exec_ctx* exec_ctx, poll_obj* bag, + poll_obj_type bag_type, poll_obj* item, + poll_obj_type item_type) { GPR_TIMER_BEGIN("add_poll_object", 0); #ifndef NDEBUG @@ -1441,7 +1456,7 @@ retry: keeping TSAN happy outweigh any performance advantage we might have by keeping the lock held. */ gpr_mu_unlock(&item->mu); - pi_new = polling_island_create(FD_FROM_PO(item), &error); + pi_new = polling_island_create(exec_ctx, FD_FROM_PO(item), &error); gpr_mu_lock(&item->mu); /* Need to reverify any assumptions made between the initial lock and @@ -1460,11 +1475,11 @@ retry: /* Ref and unref so that the polling island gets deleted during unref */ PI_ADD_REF(pi_new, "dance_of_destruction"); - PI_UNREF(pi_new, "dance_of_destruction"); + PI_UNREF(exec_ctx, pi_new, "dance_of_destruction"); goto retry; } } else { - pi_new = polling_island_create(nullptr, &error); + pi_new = polling_island_create(exec_ctx, nullptr, &error); } GRPC_POLLING_TRACE( @@ -1518,7 +1533,7 @@ retry: if (item->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(item_type)); if (item->pi != nullptr) { - PI_UNREF(item->pi, poll_obj_string(item_type)); + PI_UNREF(exec_ctx, item->pi, poll_obj_string(item_type)); } item->pi = pi_new; } @@ -1526,7 +1541,7 @@ retry: if (bag->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(bag_type)); if (bag->pi != nullptr) { - PI_UNREF(bag->pi, poll_obj_string(bag_type)); + PI_UNREF(exec_ctx, bag->pi, poll_obj_string(bag_type)); } bag->pi = pi_new; } @@ -1538,8 +1553,10 @@ retry: GPR_TIMER_END("add_poll_object", 0); } -static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { - add_poll_object(&pollset->po, POLL_OBJ_POLLSET, &fd->po, POLL_OBJ_FD); +static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_fd* fd) { + add_poll_object(exec_ctx, &pollset->po, POLL_OBJ_POLLSET, &fd->po, + POLL_OBJ_FD); } /******************************************************************************* @@ -1556,39 +1573,48 @@ static grpc_pollset_set* pollset_set_create(void) { return pss; } -static void pollset_set_destroy(grpc_pollset_set* pss) { +static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss) { gpr_mu_destroy(&pss->po.mu); if (pss->po.pi != nullptr) { - PI_UNREF(pss->po.pi, "pss_destroy"); + PI_UNREF(exec_ctx, pss->po.pi, "pss_destroy"); } gpr_free(pss); } -static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { - add_poll_object(&pss->po, POLL_OBJ_POLLSET_SET, &fd->po, POLL_OBJ_FD); +static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) { + add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &fd->po, + POLL_OBJ_FD); } -static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { +static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, + grpc_fd* fd) { /* Nothing to do */ } -static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { - add_poll_object(&pss->po, POLL_OBJ_POLLSET_SET, &ps->po, POLL_OBJ_POLLSET); +static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) { + add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &ps->po, + POLL_OBJ_POLLSET); } -static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pss, grpc_pollset* ps) { /* Nothing to do */ } -static void pollset_set_add_pollset_set(grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { - add_poll_object(&bag->po, POLL_OBJ_POLLSET_SET, &item->po, + add_poll_object(exec_ctx, &bag->po, POLL_OBJ_POLLSET_SET, &item->po, POLL_OBJ_POLLSET_SET); } -static void pollset_set_del_pollset_set(grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { /* Nothing to do */ } @@ -1734,7 +1760,7 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux( bool explicit_request) { gpr_log(GPR_ERROR, "Skipping epollsig becuase GRPC_LINUX_EPOLL is not defined."); - return nullptr; + return NULL; } #endif /* defined(GRPC_POSIX_SOCKET) */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 006e3ddd2f..e32e1ba42a 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -128,7 +128,8 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, MUST NOT be called with a pollset lock taken if got_read or got_write are 1, also does the become_{readable,writable} as appropriate. */ -static void fd_end_poll(grpc_fd_watcher* rec, int got_read, int got_write, +static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* rec, + int got_read, int got_write, grpc_pollset* read_notifier_pollset); /* Return 1 if this fd is orphaned, 0 otherwise */ @@ -185,9 +186,11 @@ struct grpc_pollset { }; /* Add an fd to a pollset */ -static void pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd); +static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + struct grpc_fd* fd); -static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); +static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd); /* Convert a timespec to milliseconds: - very small or negative poll times are clamped to zero to do a @@ -196,7 +199,8 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); - longer than a millisecond polls are rounded up to the next nearest millisecond to avoid spinning - infinite timeouts are converted to -1 */ -static int poll_deadline_to_millis_timeout(grpc_millis deadline); +static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis deadline); /* Allow kick to wakeup the currently polling worker */ #define GRPC_POLLSET_CAN_KICK_SELF 1 @@ -204,7 +208,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis deadline); #define GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP 2 /* As per pollset_kick, with an extended set of flags (defined above) -- mostly for fd_posix's use. */ -static grpc_error* pollset_kick_ext(grpc_pollset* p, +static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, grpc_pollset_worker* specific_worker, uint32_t flags) GRPC_MUST_USE_RESULT; @@ -349,7 +353,8 @@ static bool fd_is_orphaned(grpc_fd* fd) { } /* Return the read-notifier pollset */ -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, + grpc_fd* fd) { grpc_pollset* notifier = nullptr; gpr_mu_lock(&fd->mu); @@ -359,36 +364,39 @@ static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { return notifier; } -static grpc_error* pollset_kick_locked(grpc_fd_watcher* watcher) { +static grpc_error* pollset_kick_locked(grpc_exec_ctx* exec_ctx, + grpc_fd_watcher* watcher) { gpr_mu_lock(&watcher->pollset->mu); GPR_ASSERT(watcher->worker); - grpc_error* err = pollset_kick_ext(watcher->pollset, watcher->worker, - GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); + grpc_error* err = + pollset_kick_ext(exec_ctx, watcher->pollset, watcher->worker, + GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); gpr_mu_unlock(&watcher->pollset->mu); return err; } -static void maybe_wake_one_watcher_locked(grpc_fd* fd) { +static void maybe_wake_one_watcher_locked(grpc_exec_ctx* exec_ctx, + grpc_fd* fd) { if (fd->inactive_watcher_root.next != &fd->inactive_watcher_root) { - pollset_kick_locked(fd->inactive_watcher_root.next); + pollset_kick_locked(exec_ctx, fd->inactive_watcher_root.next); } else if (fd->read_watcher) { - pollset_kick_locked(fd->read_watcher); + pollset_kick_locked(exec_ctx, fd->read_watcher); } else if (fd->write_watcher) { - pollset_kick_locked(fd->write_watcher); + pollset_kick_locked(exec_ctx, fd->write_watcher); } } -static void wake_all_watchers_locked(grpc_fd* fd) { +static void wake_all_watchers_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { grpc_fd_watcher* watcher; for (watcher = fd->inactive_watcher_root.next; watcher != &fd->inactive_watcher_root; watcher = watcher->next) { - pollset_kick_locked(watcher); + pollset_kick_locked(exec_ctx, watcher); } if (fd->read_watcher) { - pollset_kick_locked(fd->read_watcher); + pollset_kick_locked(exec_ctx, fd->read_watcher); } if (fd->write_watcher && fd->write_watcher != fd->read_watcher) { - pollset_kick_locked(fd->write_watcher); + pollset_kick_locked(exec_ctx, fd->write_watcher); } } @@ -397,12 +405,12 @@ static int has_watchers(grpc_fd* fd) { fd->inactive_watcher_root.next != &fd->inactive_watcher_root; } -static void close_fd_locked(grpc_fd* fd) { +static void close_fd_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { fd->closed = 1; if (!fd->released) { close(fd->fd); } - GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_NONE); } static int fd_wrapped_fd(grpc_fd* fd) { @@ -413,7 +421,8 @@ static int fd_wrapped_fd(grpc_fd* fd) { } } -static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { fd->on_done_closure = on_done; fd->released = release_fd != nullptr; @@ -426,9 +435,9 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, gpr_mu_lock(&fd->mu); REF_BY(fd, 1, reason); /* remove active status, but keep referenced */ if (!has_watchers(fd)) { - close_fd_locked(fd); + close_fd_locked(exec_ctx, fd); } else { - wake_all_watchers_locked(fd); + wake_all_watchers_locked(exec_ctx, fd); } gpr_mu_unlock(&fd->mu); UNREF_BY(fd, 2, reason); /* drop the reference */ @@ -460,10 +469,10 @@ static grpc_error* fd_shutdown_error(grpc_fd* fd) { } } -static void notify_on_locked(grpc_fd* fd, grpc_closure** st, - grpc_closure* closure) { +static void notify_on_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure** st, grpc_closure* closure) { if (fd->shutdown) { - GRPC_CLOSURE_SCHED(closure, + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("FD shutdown")); } else if (*st == CLOSURE_NOT_READY) { /* not ready ==> switch to a waiting state by setting the closure */ @@ -471,8 +480,8 @@ static void notify_on_locked(grpc_fd* fd, grpc_closure** st, } else if (*st == CLOSURE_READY) { /* already ready ==> queue the closure to run immediately */ *st = CLOSURE_NOT_READY; - GRPC_CLOSURE_SCHED(closure, fd_shutdown_error(fd)); - maybe_wake_one_watcher_locked(fd); + GRPC_CLOSURE_SCHED(exec_ctx, closure, fd_shutdown_error(fd)); + maybe_wake_one_watcher_locked(exec_ctx, fd); } else { /* upcallptr was set to a different closure. This is an error! */ gpr_log(GPR_ERROR, @@ -483,7 +492,8 @@ static void notify_on_locked(grpc_fd* fd, grpc_closure** st, } /* returns 1 if state becomes not ready */ -static int set_ready_locked(grpc_fd* fd, grpc_closure** st) { +static int set_ready_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure** st) { if (*st == CLOSURE_READY) { /* duplicate ready ==> ignore */ return 0; @@ -493,18 +503,18 @@ static int set_ready_locked(grpc_fd* fd, grpc_closure** st) { return 0; } else { /* waiting ==> queue closure */ - GRPC_CLOSURE_SCHED(*st, fd_shutdown_error(fd)); + GRPC_CLOSURE_SCHED(exec_ctx, *st, fd_shutdown_error(fd)); *st = CLOSURE_NOT_READY; return 1; } } static void set_read_notifier_pollset_locked( - grpc_fd* fd, grpc_pollset* read_notifier_pollset) { + grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_pollset* read_notifier_pollset) { fd->read_notifier_pollset = read_notifier_pollset; } -static void fd_shutdown(grpc_fd* fd, grpc_error* why) { +static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { gpr_mu_lock(&fd->mu); /* only shutdown once */ if (!fd->shutdown) { @@ -512,8 +522,8 @@ static void fd_shutdown(grpc_fd* fd, grpc_error* why) { fd->shutdown_error = why; /* signal read/write closed to OS so that future operations fail */ shutdown(fd->fd, SHUT_RDWR); - set_ready_locked(fd, &fd->read_closure); - set_ready_locked(fd, &fd->write_closure); + set_ready_locked(exec_ctx, fd, &fd->read_closure); + set_ready_locked(exec_ctx, fd, &fd->write_closure); } else { GRPC_ERROR_UNREF(why); } @@ -527,15 +537,17 @@ static bool fd_is_shutdown(grpc_fd* fd) { return r; } -static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { +static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { gpr_mu_lock(&fd->mu); - notify_on_locked(fd, &fd->read_closure, closure); + notify_on_locked(exec_ctx, fd, &fd->read_closure, closure); gpr_mu_unlock(&fd->mu); } -static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { +static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { gpr_mu_lock(&fd->mu); - notify_on_locked(fd, &fd->write_closure, closure); + notify_on_locked(exec_ctx, fd, &fd->write_closure, closure); gpr_mu_unlock(&fd->mu); } @@ -590,7 +602,8 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, return mask; } -static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write, +static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, + int got_read, int got_write, grpc_pollset* read_notifier_pollset) { int was_polling = 0; int kick = 0; @@ -624,23 +637,23 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write, watcher->prev->next = watcher->next; } if (got_read) { - if (set_ready_locked(fd, &fd->read_closure)) { + if (set_ready_locked(exec_ctx, fd, &fd->read_closure)) { kick = 1; } if (read_notifier_pollset != nullptr) { - set_read_notifier_pollset_locked(fd, read_notifier_pollset); + set_read_notifier_pollset_locked(exec_ctx, fd, read_notifier_pollset); } } if (got_write) { - if (set_ready_locked(fd, &fd->write_closure)) { + if (set_ready_locked(exec_ctx, fd, &fd->write_closure)) { kick = 1; } } if (kick) { - maybe_wake_one_watcher_locked(fd); + maybe_wake_one_watcher_locked(exec_ctx, fd); } if (fd_is_orphaned(fd) && !has_watchers(fd) && !fd->closed) { - close_fd_locked(fd); + close_fd_locked(exec_ctx, fd); } gpr_mu_unlock(&fd->mu); @@ -701,12 +714,12 @@ static void kick_append_error(grpc_error** composite, grpc_error* error) { *composite = grpc_error_add_child(*composite, error); } -static grpc_error* pollset_kick_ext(grpc_pollset* p, +static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, grpc_pollset_worker* specific_worker, uint32_t flags) { GPR_TIMER_BEGIN("pollset_kick_ext", 0); grpc_error* error = GRPC_ERROR_NONE; - GRPC_STATS_INC_POLLSET_KICK(); + GRPC_STATS_INC_POLLSET_KICK(exec_ctx); /* pollset->mu already held */ if (specific_worker != nullptr) { @@ -772,9 +785,9 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p, return error; } -static grpc_error* pollset_kick(grpc_pollset* p, +static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, grpc_pollset_worker* specific_worker) { - return pollset_kick_ext(p, specific_worker, 0); + return pollset_kick_ext(exec_ctx, p, specific_worker, 0); } /* global state management */ @@ -808,7 +821,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->pollset_set_count = 0; } -static void pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { GPR_ASSERT(!pollset_has_workers(pollset)); GPR_ASSERT(pollset->idle_jobs.head == pollset->idle_jobs.tail); while (pollset->local_wakeup_cache) { @@ -821,7 +834,8 @@ static void pollset_destroy(grpc_pollset* pollset) { gpr_mu_destroy(&pollset->mu); } -static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { +static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_fd* fd) { gpr_mu_lock(&pollset->mu); size_t i; /* TODO(ctiller): this is O(num_fds^2); maybe switch to a hash set here */ @@ -836,19 +850,19 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { } pollset->fds[pollset->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); - pollset_kick(pollset, nullptr); + pollset_kick(exec_ctx, pollset, nullptr); exit: gpr_mu_unlock(&pollset->mu); } -static void finish_shutdown(grpc_pollset* pollset) { +static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { GPR_ASSERT(grpc_closure_list_empty(pollset->idle_jobs)); size_t i; for (i = 0; i < pollset->fd_count; i++) { GRPC_FD_UNREF(pollset->fds[i], "multipoller"); } pollset->fd_count = 0; - GRPC_CLOSURE_SCHED(pollset->shutdown_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_done, GRPC_ERROR_NONE); } static void work_combine_error(grpc_error** composite, grpc_error* error) { @@ -859,7 +873,7 @@ static void work_combine_error(grpc_error** composite, grpc_error* error) { *composite = grpc_error_add_child(*composite, error); } -static grpc_error* pollset_work(grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -898,7 +912,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, if (!pollset_has_workers(pollset) && !grpc_closure_list_empty(pollset->idle_jobs)) { GPR_TIMER_MARK("pollset_work.idle_jobs", 0); - GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); goto done; } /* If we're shutting down then we don't execute any extended work */ @@ -930,7 +944,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, grpc_fd_watcher* watchers; struct pollfd* pfds; - timeout = poll_deadline_to_millis_timeout(deadline); + timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); if (pollset->fd_count + 2 <= inline_elements) { pfds = pollfd_space; @@ -974,9 +988,9 @@ static grpc_error* pollset_work(grpc_pollset* pollset, /* TODO(vpai): Consider first doing a 0 timeout poll here to avoid even going into the blocking annotation if possible */ GRPC_SCHEDULING_START_BLOCKING_REGION; - GRPC_STATS_INC_SYSCALL_POLL(); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = grpc_poll_function(pfds, pfd_count, timeout); - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); @@ -989,16 +1003,16 @@ static grpc_error* pollset_work(grpc_pollset* pollset, for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } else { // Wake up all the file descriptors, if we have an invalid one // we can identify it on the next pollset_work() - fd_end_poll(&watchers[i], 1, 1, pollset); + fd_end_poll(exec_ctx, &watchers[i], 1, 1, pollset); } } } else if (r == 0) { for (i = 1; i < pfd_count; i++) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } } else { if (pfds[0].revents & POLLIN_CHECK) { @@ -1010,14 +1024,14 @@ static grpc_error* pollset_work(grpc_pollset* pollset, } for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } else { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); } - fd_end_poll(&watchers[i], pfds[i].revents & POLLIN_CHECK, + fd_end_poll(exec_ctx, &watchers[i], pfds[i].revents & POLLIN_CHECK, pfds[i].revents & POLLOUT_CHECK, pollset); } } @@ -1040,7 +1054,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, worker list, which means nobody could ask us to re-evaluate polling). */ done: if (!locked) { - queued_work |= grpc_core::ExecCtx::Get()->Flush(); + queued_work |= grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); locked = 1; } @@ -1069,21 +1083,21 @@ static grpc_error* pollset_work(grpc_pollset* pollset, /* check shutdown conditions */ if (pollset->shutting_down) { if (pollset_has_workers(pollset)) { - pollset_kick(pollset, nullptr); + pollset_kick(exec_ctx, pollset, nullptr); } else if (!pollset->called_shutdown && !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(pollset); - grpc_core::ExecCtx::Get()->Flush(); + finish_shutdown(exec_ctx, pollset); + grpc_exec_ctx_flush(exec_ctx); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * pollset_work. * TODO(dklempner): Can we refactor the shutdown logic to avoid this? */ gpr_mu_lock(&pollset->mu); } else if (!grpc_closure_list_empty(pollset->idle_jobs)) { - GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); gpr_mu_unlock(&pollset->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); } } @@ -1093,24 +1107,26 @@ static grpc_error* pollset_work(grpc_pollset* pollset, return error; } -static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { GPR_ASSERT(!pollset->shutting_down); pollset->shutting_down = 1; pollset->shutdown_done = closure; - pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); + pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset_has_workers(pollset)) { - GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); } if (!pollset->called_shutdown && !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; - finish_shutdown(pollset); + finish_shutdown(exec_ctx, pollset); } } -static int poll_deadline_to_millis_timeout(grpc_millis deadline) { +static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) return -1; if (deadline == 0) return 0; - grpc_millis n = deadline - grpc_core::ExecCtx::Get()->Now(); + grpc_millis n = deadline - grpc_exec_ctx_now(exec_ctx); if (n < 0) return 0; if (n > INT_MAX) return -1; return (int)n; @@ -1127,7 +1143,8 @@ static grpc_pollset_set* pollset_set_create(void) { return pollset_set; } -static void pollset_set_destroy(grpc_pollset_set* pollset_set) { +static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set) { size_t i; gpr_mu_destroy(&pollset_set->mu); for (i = 0; i < pollset_set->fd_count; i++) { @@ -1142,7 +1159,7 @@ static void pollset_set_destroy(grpc_pollset_set* pollset_set) { !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(pollset); + finish_shutdown(exec_ctx, pollset); } else { gpr_mu_unlock(&pollset->mu); } @@ -1153,7 +1170,8 @@ static void pollset_set_destroy(grpc_pollset_set* pollset_set) { gpr_free(pollset_set); } -static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, +static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) { size_t i, j; gpr_mu_lock(&pollset->mu); @@ -1172,7 +1190,7 @@ static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, if (fd_is_orphaned(pollset_set->fds[i])) { GRPC_FD_UNREF(pollset_set->fds[i], "pollset_set"); } else { - pollset_add_fd(pollset, pollset_set->fds[i]); + pollset_add_fd(exec_ctx, pollset, pollset_set->fds[i]); pollset_set->fds[j++] = pollset_set->fds[i]; } } @@ -1180,7 +1198,8 @@ static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, gpr_mu_unlock(&pollset_set->mu); } -static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, +static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) { size_t i; gpr_mu_lock(&pollset_set->mu); @@ -1200,13 +1219,14 @@ static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(pollset); + finish_shutdown(exec_ctx, pollset); } else { gpr_mu_unlock(&pollset->mu); } } -static void pollset_set_add_pollset_set(grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { size_t i, j; gpr_mu_lock(&bag->mu); @@ -1221,7 +1241,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag, if (fd_is_orphaned(bag->fds[i])) { GRPC_FD_UNREF(bag->fds[i], "pollset_set"); } else { - pollset_set_add_fd(item, bag->fds[i]); + pollset_set_add_fd(exec_ctx, item, bag->fds[i]); bag->fds[j++] = bag->fds[i]; } } @@ -1229,7 +1249,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag, gpr_mu_unlock(&bag->mu); } -static void pollset_set_del_pollset_set(grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { size_t i; gpr_mu_lock(&bag->mu); @@ -1244,7 +1265,8 @@ static void pollset_set_del_pollset_set(grpc_pollset_set* bag, gpr_mu_unlock(&bag->mu); } -static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { +static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd) { size_t i; gpr_mu_lock(&pollset_set->mu); if (pollset_set->fd_count == pollset_set->fd_capacity) { @@ -1255,15 +1277,16 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { GRPC_FD_REF(fd, "pollset_set"); pollset_set->fds[pollset_set->fd_count++] = fd; for (i = 0; i < pollset_set->pollset_count; i++) { - pollset_add_fd(pollset_set->pollsets[i], fd); + pollset_add_fd(exec_ctx, pollset_set->pollsets[i], fd); } for (i = 0; i < pollset_set->pollset_set_count; i++) { - pollset_set_add_fd(pollset_set->pollset_sets[i], fd); + pollset_set_add_fd(exec_ctx, pollset_set->pollset_sets[i], fd); } gpr_mu_unlock(&pollset_set->mu); } -static void pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { +static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd) { size_t i; gpr_mu_lock(&pollset_set->mu); for (i = 0; i < pollset_set->fd_count; i++) { @@ -1276,7 +1299,7 @@ static void pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { } } for (i = 0; i < pollset_set->pollset_set_count; i++) { - pollset_set_del_fd(pollset_set->pollset_sets[i], fd); + pollset_set_del_fd(exec_ctx, pollset_set->pollset_sets[i], fd); } gpr_mu_unlock(&pollset_set->mu); } diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index b516f93058..031c97564a 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -46,7 +46,7 @@ grpc_poll_function_type grpc_poll_function = poll; grpc_wakeup_fd grpc_global_wakeup_fd; -static const grpc_event_engine_vtable* g_event_engine = nullptr; +static const grpc_event_engine_vtable* g_event_engine; static const char* g_poll_strategy_name = nullptr; typedef const grpc_event_engine_vtable* (*event_engine_factory_fn)( @@ -184,25 +184,28 @@ int grpc_fd_wrapped_fd(grpc_fd* fd) { return g_event_engine->fd_wrapped_fd(fd); } -void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, - bool already_closed, const char* reason) { - g_event_engine->fd_orphan(fd, on_done, release_fd, already_closed, reason); +void grpc_fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, + int* release_fd, bool already_closed, const char* reason) { + g_event_engine->fd_orphan(exec_ctx, fd, on_done, release_fd, already_closed, + reason); } -void grpc_fd_shutdown(grpc_fd* fd, grpc_error* why) { - g_event_engine->fd_shutdown(fd, why); +void grpc_fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { + g_event_engine->fd_shutdown(exec_ctx, fd, why); } bool grpc_fd_is_shutdown(grpc_fd* fd) { return g_event_engine->fd_is_shutdown(fd); } -void grpc_fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { - g_event_engine->fd_notify_on_read(fd, closure); +void grpc_fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + g_event_engine->fd_notify_on_read(exec_ctx, fd, closure); } -void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { - g_event_engine->fd_notify_on_write(fd, closure); +void grpc_fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure) { + g_event_engine->fd_notify_on_write(exec_ctx, fd, closure); } size_t grpc_pollset_size(void) { return g_event_engine->pollset_size; } @@ -211,63 +214,72 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { g_event_engine->pollset_init(pollset, mu); } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - g_event_engine->pollset_shutdown(pollset, closure); +void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { + g_event_engine->pollset_shutdown(exec_ctx, pollset, closure); } -void grpc_pollset_destroy(grpc_pollset* pollset) { - g_event_engine->pollset_destroy(pollset); +void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { + g_event_engine->pollset_destroy(exec_ctx, pollset); } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) { - return g_event_engine->pollset_work(pollset, worker, deadline); + return g_event_engine->pollset_work(exec_ctx, pollset, worker, deadline); } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - return g_event_engine->pollset_kick(pollset, specific_worker); + return g_event_engine->pollset_kick(exec_ctx, pollset, specific_worker); } -void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { - g_event_engine->pollset_add_fd(pollset, fd); +void grpc_pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + struct grpc_fd* fd) { + g_event_engine->pollset_add_fd(exec_ctx, pollset, fd); } grpc_pollset_set* grpc_pollset_set_create(void) { return g_event_engine->pollset_set_create(); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { - g_event_engine->pollset_set_destroy(pollset_set); +void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set) { + g_event_engine->pollset_set_destroy(exec_ctx, pollset_set); } -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - g_event_engine->pollset_set_add_pollset(pollset_set, pollset); + g_event_engine->pollset_set_add_pollset(exec_ctx, pollset_set, pollset); } -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - g_event_engine->pollset_set_del_pollset(pollset_set, pollset); + g_event_engine->pollset_set_del_pollset(exec_ctx, pollset_set, pollset); } -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { - g_event_engine->pollset_set_add_pollset_set(bag, item); + g_event_engine->pollset_set_add_pollset_set(exec_ctx, bag, item); } -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) { - g_event_engine->pollset_set_del_pollset_set(bag, item); + g_event_engine->pollset_set_del_pollset_set(exec_ctx, bag, item); } -void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - g_event_engine->pollset_set_add_fd(pollset_set, fd); +void grpc_pollset_set_add_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd) { + g_event_engine->pollset_set_add_fd(exec_ctx, pollset_set, fd); } -void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - g_event_engine->pollset_set_del_fd(pollset_set, fd); +void grpc_pollset_set_del_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd) { + g_event_engine->pollset_set_del_fd(exec_ctx, pollset_set, fd); } #endif // GRPC_POSIX_SOCKET diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index 62f1162a23..16fa10ca56 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -36,36 +36,48 @@ typedef struct grpc_event_engine_vtable { grpc_fd* (*fd_create)(int fd, const char* name); int (*fd_wrapped_fd)(grpc_fd* fd); - void (*fd_orphan)(grpc_fd* fd, grpc_closure* on_done, int* release_fd, - bool already_closed, const char* reason); - void (*fd_shutdown)(grpc_fd* fd, grpc_error* why); - void (*fd_notify_on_read)(grpc_fd* fd, grpc_closure* closure); - void (*fd_notify_on_write)(grpc_fd* fd, grpc_closure* closure); + void (*fd_orphan)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, + int* release_fd, bool already_closed, const char* reason); + void (*fd_shutdown)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why); + void (*fd_notify_on_read)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure); + void (*fd_notify_on_write)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure); bool (*fd_is_shutdown)(grpc_fd* fd); - grpc_pollset* (*fd_get_read_notifier_pollset)(grpc_fd* fd); + grpc_pollset* (*fd_get_read_notifier_pollset)(grpc_exec_ctx* exec_ctx, + grpc_fd* fd); void (*pollset_init)(grpc_pollset* pollset, gpr_mu** mu); - void (*pollset_shutdown)(grpc_pollset* pollset, grpc_closure* closure); - void (*pollset_destroy)(grpc_pollset* pollset); - grpc_error* (*pollset_work)(grpc_pollset* pollset, + void (*pollset_shutdown)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure); + void (*pollset_destroy)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); + grpc_error* (*pollset_work)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline); - grpc_error* (*pollset_kick)(grpc_pollset* pollset, + grpc_error* (*pollset_kick)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker); - void (*pollset_add_fd)(grpc_pollset* pollset, struct grpc_fd* fd); + void (*pollset_add_fd)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + struct grpc_fd* fd); grpc_pollset_set* (*pollset_set_create)(void); - void (*pollset_set_destroy)(grpc_pollset_set* pollset_set); - void (*pollset_set_add_pollset)(grpc_pollset_set* pollset_set, + void (*pollset_set_destroy)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set); + void (*pollset_set_add_pollset)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset); - void (*pollset_set_del_pollset)(grpc_pollset_set* pollset_set, + void (*pollset_set_del_pollset)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset); - void (*pollset_set_add_pollset_set)(grpc_pollset_set* bag, + void (*pollset_set_add_pollset_set)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item); - void (*pollset_set_del_pollset_set)(grpc_pollset_set* bag, + void (*pollset_set_del_pollset_set)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item); - void (*pollset_set_add_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd); - void (*pollset_set_del_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd); + void (*pollset_set_add_fd)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd); + void (*pollset_set_del_fd)(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd); void (*shutdown_engine)(void); } grpc_event_engine_vtable; @@ -91,14 +103,14 @@ int grpc_fd_wrapped_fd(grpc_fd* fd); Requires: *fd initialized; no outstanding notify_on_read or notify_on_write. MUST NOT be called with a pollset lock taken */ -void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, - bool already_closed, const char* reason); +void grpc_fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, + int* release_fd, bool already_closed, const char* reason); /* Has grpc_fd_shutdown been called on an fd? */ bool grpc_fd_is_shutdown(grpc_fd* fd); /* Cause any current and future callbacks to fail. */ -void grpc_fd_shutdown(grpc_fd* fd, grpc_error* why); +void grpc_fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why); /* Register read interest, causing read_cb to be called once when fd becomes readable, on deadline specified by deadline, or on shutdown triggered by @@ -113,23 +125,29 @@ void grpc_fd_shutdown(grpc_fd* fd, grpc_error* why); underlying platform. This means that users must drain fd in read_cb before calling notify_on_read again. Users are also expected to handle spurious events, i.e read_cb is called while nothing can be readable from fd */ -void grpc_fd_notify_on_read(grpc_fd* fd, grpc_closure* closure); +void grpc_fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure); /* Exactly the same semantics as above, except based on writable events. */ -void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure); +void grpc_fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + grpc_closure* closure); /* Return the read notifier pollset from the fd */ -grpc_pollset* grpc_fd_get_read_notifier_pollset(grpc_fd* fd); +grpc_pollset* grpc_fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, + grpc_fd* fd); /* pollset_posix functions */ /* Add an fd to a pollset */ -void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd); +void grpc_pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + struct grpc_fd* fd); /* pollset_set_posix functions */ -void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); -void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); +void grpc_pollset_set_add_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd); +void grpc_pollset_set_del_fd(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_fd* fd); /* override to allow tests to hook poll() usage */ typedef int (*grpc_poll_function_type)(struct pollfd*, nfds_t, int); diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index e005437e0a..1777456342 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -25,7 +25,39 @@ #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/profiling/timers.h" -static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { +bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx* exec_ctx) { + if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { + if (exec_ctx->check_ready_to_finish(exec_ctx, + exec_ctx->check_ready_to_finish_arg)) { + exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + return true; + } + return false; + } else { + return true; + } +} + +bool grpc_never_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) { + return false; +} + +bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) { + return true; +} + +bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx) { + return exec_ctx->active_combiner != nullptr || + !grpc_closure_list_empty(exec_ctx->closure_list); +} + +void grpc_exec_ctx_finish(grpc_exec_ctx* exec_ctx) { + exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + grpc_exec_ctx_flush(exec_ctx); +} + +static void exec_ctx_run(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error) { #ifndef NDEBUG closure->scheduled = false; if (grpc_trace_closure.enabled()) { @@ -35,7 +67,7 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { closure->line_initiated); } #endif - closure->cb(closure->cb_arg, error); + closure->cb(exec_ctx, closure->cb_arg, error); #ifndef NDEBUG if (grpc_trace_closure.enabled()) { gpr_log(GPR_DEBUG, "closure %p finished", closure); @@ -44,13 +76,42 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { GRPC_ERROR_UNREF(error); } -static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { - grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure, - error); +bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) { + bool did_something = 0; + GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); + for (;;) { + if (!grpc_closure_list_empty(exec_ctx->closure_list)) { + grpc_closure* c = exec_ctx->closure_list.head; + exec_ctx->closure_list.head = exec_ctx->closure_list.tail = nullptr; + while (c != nullptr) { + grpc_closure* next = c->next_data.next; + grpc_error* error = c->error_data.error; + did_something = true; + exec_ctx_run(exec_ctx, c, error); + c = next; + } + } else if (!grpc_combiner_continue_exec_ctx(exec_ctx)) { + break; + } + } + GPR_ASSERT(exec_ctx->active_combiner == nullptr); + GPR_TIMER_END("grpc_exec_ctx_flush", 0); + return did_something; +} + +static void exec_ctx_sched(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error) { + grpc_closure_list_append(&exec_ctx->closure_list, closure, error); } static gpr_timespec g_start_time; +void grpc_exec_ctx_global_init(void) { + g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); +} + +void grpc_exec_ctx_global_shutdown(void) {} + static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); double x = @@ -70,6 +131,18 @@ static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { return (gpr_atm)x; } +grpc_millis grpc_exec_ctx_now(grpc_exec_ctx* exec_ctx) { + if (!exec_ctx->now_is_valid) { + exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); + exec_ctx->now_is_valid = true; + } + return exec_ctx->now; +} + +void grpc_exec_ctx_invalidate_now(grpc_exec_ctx* exec_ctx) { + exec_ctx->now_is_valid = false; +} + gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock_type) { // special-case infinities as grpc_millis can be 32bit on some platforms @@ -102,44 +175,3 @@ static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; - -namespace grpc_core { -GPR_TLS_CLASS_DEF(ExecCtx::exec_ctx_); - -void ExecCtx::GlobalInit(void) { - g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); - gpr_tls_init(&exec_ctx_); -} - -bool ExecCtx::Flush() { - bool did_something = 0; - GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); - for (;;) { - if (!grpc_closure_list_empty(closure_list_)) { - grpc_closure* c = closure_list_.head; - closure_list_.head = closure_list_.tail = nullptr; - while (c != nullptr) { - grpc_closure* next = c->next_data.next; - grpc_error* error = c->error_data.error; - did_something = true; - exec_ctx_run(c, error); - c = next; - } - } else if (!grpc_combiner_continue_exec_ctx()) { - break; - } - } - GPR_ASSERT(combiner_data_.active_combiner == nullptr); - GPR_TIMER_END("grpc_exec_ctx_flush", 0); - return did_something; -} - -grpc_millis ExecCtx::Now() { - if (!now_is_valid_) { - now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); - now_is_valid_ = true; - } - return now_; -} - -} // namespace grpc_core diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index b0c1740155..b415d2c255 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -21,8 +21,6 @@ #include #include -#include -#include #include "src/core/lib/iomgr/closure.h" @@ -43,13 +41,6 @@ typedef struct grpc_combiner grpc_combiner; should be given to not delete said call/channel from this exec_ctx */ #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 -extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; - -gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); -grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); -grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); - -namespace grpc_core { /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -70,130 +61,63 @@ namespace grpc_core { * - Instances are always passed as the first argument to a function that * takes it, and always as a pointer (grpc_exec_ctx is never copied). */ -class ExecCtx { - public: - /** Default Constructor */ - - ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { Set(this); } - - /** Parameterised Constructor */ - ExecCtx(uintptr_t fl) : flags_(fl) { Set(this); } - - /** Destructor */ - ~ExecCtx() { - flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - Flush(); - Set(last_exec_ctx_); - } - - /** Disallow copy and assignment operators */ - ExecCtx(const ExecCtx&) = delete; - ExecCtx& operator=(const ExecCtx&) = delete; - - /** Return starting_cpu */ - unsigned starting_cpu() const { return starting_cpu_; } - - struct CombinerData { - /* currently active combiner: updated only via combiner.c */ - grpc_combiner* active_combiner; - /* last active combiner in the active combiner list */ - grpc_combiner* last_combiner; - }; - - /** Only to be used by grpc-combiner code */ - CombinerData* combiner_data() { return &combiner_data_; } - - /** Return pointer to grpc_closure_list */ - grpc_closure_list* closure_list() { return &closure_list_; } - - /** Return flags */ - uintptr_t flags() { return flags_; } - - /** Checks if there is work to be done */ - bool HasWork() { - return combiner_data_.active_combiner != NULL || - !grpc_closure_list_empty(closure_list_); - } - - /** Flush any work that has been enqueued onto this grpc_exec_ctx. - * Caller must guarantee that no interfering locks are held. - * Returns true if work was performed, false otherwise. */ - bool Flush(); - - /** Returns true if we'd like to leave this execution context as soon as -possible: useful for deciding whether to do something more or not depending -on outside context */ - bool IsReadyToFinish() { - if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { - if (CheckReadyToFinish()) { - flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - return true; - } - return false; - } else { - return true; - } - } - - /** Returns the stored current time relative to start if valid, - * otherwise refreshes the stored time, sets it valid and returns the new - * value */ - grpc_millis Now(); - - /** Invalidates the stored time value. A new time value will be set on calling - * Now() */ - void InvalidateNow() { now_is_valid_ = false; } - - /** To be used only by shutdown code in iomgr */ - void SetNowIomgrShutdown() { - now_ = GRPC_MILLIS_INF_FUTURE; - now_is_valid_ = true; - } - - /** To be used only for testing. - * Sets the now value - */ - void TestOnlySetNow(grpc_millis new_val) { - now_ = new_val; - now_is_valid_ = true; - } - - /** Finish any pending work for a grpc_exec_ctx. Must be called before - * the instance is destroyed, or work may be lost. */ - void Finish(); - - /** Global initialization for ExecCtx. Called by iomgr */ - static void GlobalInit(void); - - /** Global shutdown for ExecCtx. Called by iomgr */ - static void GlobalShutdown(void) { gpr_tls_destroy(&exec_ctx_); } - - /** Gets pointer to current exec_ctx */ - static ExecCtx* Get() { - return reinterpret_cast(gpr_tls_get(&exec_ctx_)); - } - - protected: - /** Check if ready to finish */ - virtual bool CheckReadyToFinish() { return false; } +struct grpc_exec_ctx { + grpc_closure_list closure_list; + /** currently active combiner: updated only via combiner.c */ + grpc_combiner* active_combiner; + /** last active combiner in the active combiner list */ + grpc_combiner* last_combiner; + uintptr_t flags; + unsigned starting_cpu; + void* check_ready_to_finish_arg; + bool (*check_ready_to_finish)(grpc_exec_ctx* exec_ctx, void* arg); + + bool now_is_valid; + grpc_millis now; +}; - private: - /** Set exec_ctx_ to exec_ctx */ - void Set(ExecCtx* exec_ctx) { - gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); +/* initializer for grpc_exec_ctx: + prefer to use GRPC_EXEC_CTX_INIT whenever possible */ +#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \ + { \ + GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, gpr_cpu_current_cpu(), \ + finish_check_arg, finish_check, false, 0 \ } - grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; - CombinerData combiner_data_ = {nullptr, nullptr}; - uintptr_t flags_; - unsigned starting_cpu_ = gpr_cpu_current_cpu(); +/* initialize an execution context at the top level of an API call into grpc + (this is safe to use elsewhere, though possibly not as efficient) */ +#define GRPC_EXEC_CTX_INIT \ + GRPC_EXEC_CTX_INITIALIZER(GRPC_EXEC_CTX_FLAG_IS_FINISHED, NULL, NULL) - bool now_is_valid_ = false; - grpc_millis now_ = 0; +extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; - GPR_TLS_CLASS_DECL(exec_ctx_); - ExecCtx* last_exec_ctx_ = Get(); -}; -} // namespace grpc_core +bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx); + +/** Flush any work that has been enqueued onto this grpc_exec_ctx. + * Caller must guarantee that no interfering locks are held. + * Returns true if work was performed, false otherwise. */ +bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx); +/** Finish any pending work for a grpc_exec_ctx. Must be called before + * the instance is destroyed, or work may be lost. */ +void grpc_exec_ctx_finish(grpc_exec_ctx* exec_ctx); +/** Returns true if we'd like to leave this execution context as soon as + possible: useful for deciding whether to do something more or not depending + on outside context */ +bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx* exec_ctx); +/** A finish check that is never ready to finish */ +bool grpc_never_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored); +/** A finish check that is always ready to finish */ +bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored); + +void grpc_exec_ctx_global_init(void); + +void grpc_exec_ctx_global_init(void); +void grpc_exec_ctx_global_shutdown(void); + +grpc_millis grpc_exec_ctx_now(grpc_exec_ctx* exec_ctx); +void grpc_exec_ctx_invalidate_now(grpc_exec_ctx* exec_ctx); +gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); #endif /* GRPC_CORE_LIB_IOMGR_EXEC_CTX_H */ diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index b45223ce16..fabdbdf934 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -55,7 +55,7 @@ grpc_core::TraceFlag executor_trace(false, "executor"); static void executor_thread(void* arg); -static size_t run_closures(grpc_closure_list list) { +static size_t run_closures(grpc_exec_ctx* exec_ctx, grpc_closure_list list) { size_t n = 0; grpc_closure* c = list.head; @@ -73,11 +73,11 @@ static size_t run_closures(grpc_closure_list list) { #ifndef NDEBUG c->scheduled = false; #endif - c->cb(c->cb_arg, error); + c->cb(exec_ctx, c->cb_arg, error); GRPC_ERROR_UNREF(error); c = next; n++; - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); } return n; @@ -87,7 +87,7 @@ bool grpc_executor_is_threaded() { return gpr_atm_no_barrier_load(&g_cur_threads) > 0; } -void grpc_executor_set_threading(bool threading) { +void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool threading) { gpr_atm cur_threads = gpr_atm_no_barrier_load(&g_cur_threads); if (threading) { if (cur_threads > 0) return; @@ -125,25 +125,28 @@ void grpc_executor_set_threading(bool threading) { for (size_t i = 0; i < g_max_threads; i++) { gpr_mu_destroy(&g_thread_state[i].mu); gpr_cv_destroy(&g_thread_state[i].cv); - run_closures(g_thread_state[i].elems); + run_closures(exec_ctx, g_thread_state[i].elems); } gpr_free(g_thread_state); gpr_tls_destroy(&g_this_thread_state); } } -void grpc_executor_init() { +void grpc_executor_init(grpc_exec_ctx* exec_ctx) { gpr_atm_no_barrier_store(&g_cur_threads, 0); - grpc_executor_set_threading(true); + grpc_executor_set_threading(exec_ctx, true); } -void grpc_executor_shutdown() { grpc_executor_set_threading(false); } +void grpc_executor_shutdown(grpc_exec_ctx* exec_ctx) { + grpc_executor_set_threading(exec_ctx, false); +} static void executor_thread(void* arg) { thread_state* ts = (thread_state*)arg; gpr_tls_set(&g_this_thread_state, (intptr_t)ts); - grpc_core::ExecCtx exec_ctx(0); + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); size_t subtract_depth = 0; for (;;) { @@ -165,7 +168,7 @@ static void executor_thread(void* arg) { gpr_mu_unlock(&ts->mu); break; } - GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(); + GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(&exec_ctx); grpc_closure_list exec = ts->elems; ts->elems = GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); @@ -173,18 +176,19 @@ static void executor_thread(void* arg) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); } - grpc_core::ExecCtx::Get()->InvalidateNow(); - subtract_depth = run_closures(exec); + grpc_exec_ctx_invalidate_now(&exec_ctx); + subtract_depth = run_closures(&exec_ctx, exec); } + grpc_exec_ctx_finish(&exec_ctx); } -static void executor_push(grpc_closure* closure, grpc_error* error, - bool is_short) { +static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error, bool is_short) { bool retry_push; if (is_short) { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(exec_ctx); } else { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(exec_ctx); } do { retry_push = false; @@ -198,16 +202,14 @@ static void executor_push(grpc_closure* closure, grpc_error* error, gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p inline", closure); #endif } - grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), - closure, error); + grpc_closure_list_append(&exec_ctx->closure_list, closure, error); return; } thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state); if (ts == nullptr) { - ts = &g_thread_state[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(), - cur_thread_count)]; + ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)]; } else { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx); } thread_state* orig_ts = ts; @@ -243,7 +245,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error, continue; } if (grpc_closure_list_empty(ts->elems)) { - GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(); + GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx); gpr_cv_signal(&ts->cv); } grpc_closure_list_append(&ts->elems, closure, error); @@ -267,17 +269,19 @@ static void executor_push(grpc_closure* closure, grpc_error* error, gpr_spinlock_unlock(&g_adding_thread_lock); } if (retry_push) { - GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(); + GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(exec_ctx); } } while (retry_push); } -static void executor_push_short(grpc_closure* closure, grpc_error* error) { - executor_push(closure, error, true); +static void executor_push_short(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error) { + executor_push(exec_ctx, closure, error, true); } -static void executor_push_long(grpc_closure* closure, grpc_error* error) { - executor_push(closure, error, false); +static void executor_push_long(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_error* error) { + executor_push(exec_ctx, closure, error, false); } static const grpc_closure_scheduler_vtable executor_vtable_short = { diff --git a/src/core/lib/iomgr/executor.h b/src/core/lib/iomgr/executor.h index e16f11aa21..d349083eeb 100644 --- a/src/core/lib/iomgr/executor.h +++ b/src/core/lib/iomgr/executor.h @@ -31,18 +31,18 @@ typedef enum { * This mechanism is meant to outsource work (grpc_closure instances) to a * thread, for those cases where blocking isn't an option but there isn't a * non-blocking solution available. */ -void grpc_executor_init(); +void grpc_executor_init(grpc_exec_ctx* exec_ctx); grpc_closure_scheduler* grpc_executor_scheduler(grpc_executor_job_length); /** Shutdown the executor, running all pending work as part of the call */ -void grpc_executor_shutdown(); +void grpc_executor_shutdown(grpc_exec_ctx* exec_ctx); /** Is the executor multi-threaded? */ bool grpc_executor_is_threaded(); /* enable/disable threading - must be called after grpc_executor_init and before grpc_executor_shutdown */ -void grpc_executor_set_threading(bool enable); +void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool enable); #endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */ diff --git a/src/core/lib/iomgr/fork_posix.cc b/src/core/lib/iomgr/fork_posix.cc index cc131408af..f3cfd141b6 100644 --- a/src/core/lib/iomgr/fork_posix.cc +++ b/src/core/lib/iomgr/fork_posix.cc @@ -49,10 +49,10 @@ void grpc_prefork() { return; } if (grpc_is_initialized()) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_timer_manager_set_threading(false); - grpc_executor_set_threading(false); - grpc_core::ExecCtx::Get()->Flush(); + grpc_executor_set_threading(&exec_ctx, false); + grpc_exec_ctx_finish(&exec_ctx); if (!gpr_await_threads( gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(3, GPR_TIMESPAN)))) { @@ -64,17 +64,18 @@ void grpc_prefork() { void grpc_postfork_parent() { if (grpc_is_initialized()) { grpc_timer_manager_set_threading(true); - grpc_core::ExecCtx exec_ctx; - grpc_executor_set_threading(true); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_executor_set_threading(&exec_ctx, true); + grpc_exec_ctx_finish(&exec_ctx); } } void grpc_postfork_child() { if (grpc_is_initialized()) { grpc_timer_manager_set_threading(true); - grpc_core::ExecCtx exec_ctx; - grpc_executor_set_threading(true); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_executor_set_threading(&exec_ctx, true); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 0b6e6823b3..6bbe5669c7 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -42,18 +42,20 @@ static gpr_atm g_custom_events = 0; static HANDLE g_iocp; -static DWORD deadline_to_millis_timeout(grpc_millis deadline) { +static DWORD deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, + grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return INFINITE; } - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); if (deadline < now) return 0; grpc_millis timeout = deadline - now; if (timeout > std::numeric_limits::max()) return INFINITE; return static_cast(deadline - now); } -grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { +grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, + grpc_millis deadline) { BOOL success; DWORD bytes = 0; DWORD flags = 0; @@ -61,11 +63,11 @@ grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { LPOVERLAPPED overlapped; grpc_winsocket* socket; grpc_winsocket_callback_info* info; - GRPC_STATS_INC_SYSCALL_POLL(); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key, &overlapped, - deadline_to_millis_timeout(deadline)); - grpc_core::ExecCtx::Get()->InvalidateNow(); + deadline_to_millis_timeout(exec_ctx, deadline)); + grpc_exec_ctx_invalidate_now(exec_ctx); if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } @@ -93,7 +95,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { info->bytes_transfered = bytes; info->wsa_error = success ? 0 : WSAGetLastError(); GPR_ASSERT(overlapped == &info->overlapped); - grpc_socket_become_ready(socket, info); + grpc_socket_become_ready(exec_ctx, socket, info); return GRPC_IOCP_WORK_WORK; } @@ -113,22 +115,22 @@ void grpc_iocp_kick(void) { } void grpc_iocp_flush(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_iocp_work_status work_status; do { - work_status = grpc_iocp_work(GRPC_MILLIS_INF_PAST); + work_status = grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_PAST); } while (work_status == GRPC_IOCP_WORK_KICK || - grpc_core::ExecCtx::Get()->Flush()); + grpc_exec_ctx_flush(&exec_ctx)); } void grpc_iocp_shutdown(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (gpr_atm_acq_load(&g_custom_events)) { - grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); - grpc_core::ExecCtx::Get()->Flush(); + grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_FUTURE); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(CloseHandle(g_iocp)); } diff --git a/src/core/lib/iomgr/iocp_windows.h b/src/core/lib/iomgr/iocp_windows.h index 75b0ff4a92..0e9c3481f7 100644 --- a/src/core/lib/iomgr/iocp_windows.h +++ b/src/core/lib/iomgr/iocp_windows.h @@ -33,7 +33,8 @@ typedef enum { GRPC_IOCP_WORK_KICK } grpc_iocp_work_status; -grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline); +grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, + grpc_millis deadline); void grpc_iocp_init(void); void grpc_iocp_kick(void); void grpc_iocp_flush(void); diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index dacf08ea9e..e077b35014 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -45,20 +45,20 @@ static gpr_cv g_rcv; static int g_shutdown; static grpc_iomgr_object g_root_object; -void grpc_iomgr_init() { - grpc_core::ExecCtx exec_ctx; +void grpc_iomgr_init(grpc_exec_ctx* exec_ctx) { g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); - grpc_executor_init(); - grpc_timer_list_init(); + grpc_exec_ctx_global_init(); + grpc_executor_init(exec_ctx); + grpc_timer_list_init(exec_ctx); g_root_object.next = g_root_object.prev = &g_root_object; g_root_object.name = (char*)"root"; grpc_network_status_init(); grpc_iomgr_platform_init(); } -void grpc_iomgr_start() { grpc_timer_manager_init(); } +void grpc_iomgr_start(grpc_exec_ctx* exec_ctx) { grpc_timer_manager_init(); } static size_t count_objects(void) { grpc_iomgr_object* obj; @@ -76,76 +76,75 @@ static void dump_objects(const char* kind) { } } -void grpc_iomgr_shutdown() { +void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) { gpr_timespec shutdown_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)); gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME); - { - grpc_timer_manager_shutdown(); - grpc_iomgr_platform_flush(); - grpc_executor_shutdown(); - - gpr_mu_lock(&g_mu); - g_shutdown = 1; - while (g_root_object.next != &g_root_object) { - if (gpr_time_cmp( - gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), - gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Waiting for %" PRIuPTR " iomgr objects to be destroyed", - count_objects()); - } - last_warning_time = gpr_now(GPR_CLOCK_REALTIME); + grpc_timer_manager_shutdown(); + grpc_iomgr_platform_flush(); + grpc_executor_shutdown(exec_ctx); + + gpr_mu_lock(&g_mu); + g_shutdown = 1; + while (g_root_object.next != &g_root_object) { + if (gpr_time_cmp( + gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), + gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Waiting for %" PRIuPTR " iomgr objects to be destroyed", + count_objects()); } - grpc_core::ExecCtx::Get()->SetNowIomgrShutdown(); - if (grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED) { - gpr_mu_unlock(&g_mu); - grpc_core::ExecCtx::Get()->Flush(); - grpc_iomgr_platform_flush(); - gpr_mu_lock(&g_mu); - continue; + last_warning_time = gpr_now(GPR_CLOCK_REALTIME); + } + exec_ctx->now_is_valid = true; + exec_ctx->now = GRPC_MILLIS_INF_FUTURE; + if (grpc_timer_check(exec_ctx, nullptr) == GRPC_TIMERS_FIRED) { + gpr_mu_unlock(&g_mu); + grpc_exec_ctx_flush(exec_ctx); + grpc_iomgr_platform_flush(); + gpr_mu_lock(&g_mu); + continue; + } + if (g_root_object.next != &g_root_object) { + if (grpc_iomgr_abort_on_leaks()) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); + abort(); } - if (g_root_object.next != &g_root_object) { - if (grpc_iomgr_abort_on_leaks()) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); - abort(); - } - gpr_timespec short_deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(100, GPR_TIMESPAN)); - if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { - if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > - 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); - } - break; + gpr_timespec short_deadline = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); + if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { + if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); } + break; } } } - gpr_mu_unlock(&g_mu); - grpc_timer_list_shutdown(); - grpc_core::ExecCtx::Get()->Flush(); } + gpr_mu_unlock(&g_mu); + + grpc_timer_list_shutdown(exec_ctx); + grpc_exec_ctx_flush(exec_ctx); /* ensure all threads have left g_mu */ gpr_mu_lock(&g_mu); gpr_mu_unlock(&g_mu); grpc_iomgr_platform_shutdown(); + grpc_exec_ctx_global_shutdown(); grpc_network_status_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr.h b/src/core/lib/iomgr/iomgr.h index 3f238c660a..2f00c0343d 100644 --- a/src/core/lib/iomgr/iomgr.h +++ b/src/core/lib/iomgr/iomgr.h @@ -23,13 +23,13 @@ #include "src/core/lib/iomgr/port.h" /** Initializes the iomgr. */ -void grpc_iomgr_init(); +void grpc_iomgr_init(grpc_exec_ctx* exec_ctx); /** Starts any background threads for iomgr. */ -void grpc_iomgr_start(); +void grpc_iomgr_start(grpc_exec_ctx* exec_ctx); /** Signals the intention to shutdown the iomgr. Expects to be able to flush * exec_ctx. */ -void grpc_iomgr_shutdown(); +void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx); #endif /* GRPC_CORE_LIB_IOMGR_IOMGR_H */ diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index 9614c2e664..b8a10f2ae8 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -29,11 +29,12 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_global_init(); - grpc_executor_set_threading(false); + grpc_executor_set_threading(&exec_ctx, false); g_init_thread = gpr_thd_currentid(); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_iomgr_platform_flush(void) {} void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index 7b194e3db5..f0e798e8d8 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -85,7 +85,7 @@ void LockfreeEvent::DestroyEvent() { kShutdownBit /* shutdown, no error */)); } -void LockfreeEvent::NotifyOn(grpc_closure* closure) { +void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); if (grpc_polling_trace.enabled()) { @@ -118,7 +118,7 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { closure when transitioning out of CLOSURE_NO_READY state (i.e there is no other code that needs to 'happen-after' this) */ if (gpr_atm_no_barrier_cas(&state_, kClosureReady, kClosureNotReady)) { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); return; /* Successful. Return */ } @@ -131,7 +131,7 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { schedule the closure with the shutdown error */ if ((curr & kShutdownBit) > 0) { grpc_error* shutdown_err = (grpc_error*)(curr & ~kShutdownBit); - GRPC_CLOSURE_SCHED(closure, + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_err, 1)); return; @@ -149,7 +149,8 @@ void LockfreeEvent::NotifyOn(grpc_closure* closure) { GPR_UNREACHABLE_CODE(return ); } -bool LockfreeEvent::SetShutdown(grpc_error* shutdown_err) { +bool LockfreeEvent::SetShutdown(grpc_exec_ctx* exec_ctx, + grpc_error* shutdown_err) { gpr_atm new_state = (gpr_atm)shutdown_err | kShutdownBit; while (true) { @@ -183,7 +184,7 @@ bool LockfreeEvent::SetShutdown(grpc_error* shutdown_err) { happens-after on that edge), and a release to pair with anything loading the shutdown state. */ if (gpr_atm_full_cas(&state_, curr, new_state)) { - GRPC_CLOSURE_SCHED((grpc_closure*)curr, + GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_err, 1)); return true; @@ -199,7 +200,7 @@ bool LockfreeEvent::SetShutdown(grpc_error* shutdown_err) { GPR_UNREACHABLE_CODE(return false); } -void LockfreeEvent::SetReady() { +void LockfreeEvent::SetReady(grpc_exec_ctx* exec_ctx) { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); @@ -233,7 +234,7 @@ void LockfreeEvent::SetReady() { spurious set_ready; release pairs with this or the acquire in notify_on (or set_shutdown) */ else if (gpr_atm_full_cas(&state_, curr, kClosureNotReady)) { - GRPC_CLOSURE_SCHED((grpc_closure*)curr, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr, GRPC_ERROR_NONE); return; } /* else the state changed again (only possible by either a racing diff --git a/src/core/lib/iomgr/lockfree_event.h b/src/core/lib/iomgr/lockfree_event.h index 3bd3fd72f1..aec67a3399 100644 --- a/src/core/lib/iomgr/lockfree_event.h +++ b/src/core/lib/iomgr/lockfree_event.h @@ -44,9 +44,9 @@ class LockfreeEvent { return (gpr_atm_no_barrier_load(&state_) & kShutdownBit) != 0; } - void NotifyOn(grpc_closure* closure); - bool SetShutdown(grpc_error* error); - void SetReady(); + void NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure); + bool SetShutdown(grpc_exec_ctx* exec_ctx, grpc_error* error); + void SetReady(grpc_exec_ctx* exec_ctx); private: enum State { kClosureNotReady = 0, kClosureReady = 2, kShutdownBit = 1 }; diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc index 126f6f45d6..0ee4ea1255 100644 --- a/src/core/lib/iomgr/polling_entity.cc +++ b/src/core/lib/iomgr/polling_entity.cc @@ -56,28 +56,32 @@ bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) { return pollent->tag == GRPC_POLLS_NONE; } -void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, +void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { GPR_ASSERT(pollent->pollent.pollset != nullptr); - grpc_pollset_set_add_pollset(pss_dst, pollent->pollent.pollset); + grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { GPR_ASSERT(pollent->pollent.pollset_set != nullptr); - grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set); + grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst, + pollent->pollent.pollset_set); } else { gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); abort(); } } -void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, +void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { GPR_ASSERT(pollent->pollent.pollset != nullptr); - grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset); + grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { GPR_ASSERT(pollent->pollent.pollset_set != nullptr); - grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set); + grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst, + pollent->pollent.pollset_set); } else { gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); abort(); diff --git a/src/core/lib/iomgr/polling_entity.h b/src/core/lib/iomgr/polling_entity.h index 0102d32c11..dbe579e60d 100644 --- a/src/core/lib/iomgr/polling_entity.h +++ b/src/core/lib/iomgr/polling_entity.h @@ -55,12 +55,14 @@ bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent); /** Add the pollset or pollset_set in \a pollent to the destination pollset_set * \a * pss_dst */ -void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, +void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_polling_entity* pollent, grpc_pollset_set* pss_dst); /** Delete the pollset or pollset_set in \a pollent from the destination * pollset_set \a * pss_dst */ -void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, +void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_polling_entity* pollent, grpc_pollset_set* pss_dst); #endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */ diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index 6bb3cd3e0c..d5d78f3101 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -42,8 +42,9 @@ size_t grpc_pollset_size(void); void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu); /* Begin shutting down the pollset, and call closure when done. * pollset's mutex must be held */ -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure); -void grpc_pollset_destroy(grpc_pollset* pollset); +void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure); +void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); /* Do some work on a pollset. May involve invoking asynchronous callbacks, or actually polling file @@ -67,13 +68,13 @@ void grpc_pollset_destroy(grpc_pollset* pollset); May call grpc_closure_list_run on grpc_closure_list, without holding the pollset lock */ -grpc_error* grpc_pollset_work(grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) GRPC_MUST_USE_RESULT; /* Break one polling thread out of polling work for this pollset. If specific_worker is non-NULL, then kick that worker. */ -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) GRPC_MUST_USE_RESULT; diff --git a/src/core/lib/iomgr/pollset_set.h b/src/core/lib/iomgr/pollset_set.h index a94d0afe75..089c15cc94 100644 --- a/src/core/lib/iomgr/pollset_set.h +++ b/src/core/lib/iomgr/pollset_set.h @@ -29,14 +29,19 @@ typedef struct grpc_pollset_set grpc_pollset_set; grpc_pollset_set* grpc_pollset_set_create(void); -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set); -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set); +void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset); -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset); -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item); -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item); #endif /* GRPC_CORE_LIB_IOMGR_POLLSET_SET_H */ diff --git a/src/core/lib/iomgr/pollset_set_uv.cc b/src/core/lib/iomgr/pollset_set_uv.cc index ac5dade8a5..90186edbb7 100644 --- a/src/core/lib/iomgr/pollset_set_uv.cc +++ b/src/core/lib/iomgr/pollset_set_uv.cc @@ -26,18 +26,23 @@ grpc_pollset_set* grpc_pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} +void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/pollset_set_windows.cc b/src/core/lib/iomgr/pollset_set_windows.cc index 85edc9dee1..2105a47ad4 100644 --- a/src/core/lib/iomgr/pollset_set_windows.cc +++ b/src/core/lib/iomgr/pollset_set_windows.cc @@ -27,18 +27,23 @@ grpc_pollset_set* grpc_pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} +void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_pollset_set* bag, grpc_pollset_set* item) {} #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index d9e5ad81be..16132f3a80 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -88,7 +88,8 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutting_down = 0; } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { GPR_ASSERT(!pollset->shutting_down); GRPC_UV_ASSERT_SAME_THREAD(); pollset->shutting_down = 1; @@ -99,10 +100,10 @@ void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { // kick the loop once uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); } - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } -void grpc_pollset_destroy(grpc_pollset* pollset) { +void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { GRPC_UV_ASSERT_SAME_THREAD(); uv_close((uv_handle_t*)pollset->timer, timer_close_cb); // timer.data is a boolean indicating that the timer has finished closing @@ -114,14 +115,14 @@ void grpc_pollset_destroy(grpc_pollset* pollset) { } } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { uint64_t timeout; GRPC_UV_ASSERT_SAME_THREAD(); gpr_mu_unlock(&grpc_polling_mu); if (grpc_pollset_work_run_loop) { - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); if (deadline >= now) { timeout = deadline - now; } else { @@ -139,14 +140,14 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, uv_run(uv_default_loop(), UV_RUN_NOWAIT); } } - if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { - grpc_core::ExecCtx::Get()->Flush(); + if (!grpc_closure_list_empty(exec_ctx->closure_list)) { + grpc_exec_ctx_flush(exec_ctx); } gpr_mu_lock(&grpc_polling_mu); return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { GRPC_UV_ASSERT_SAME_THREAD(); uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 6ef949aad7..95dd7d7ddd 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -92,19 +92,20 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { &pollset->root_worker; } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure) { pollset->shutting_down = 1; - grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); + grpc_pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset->is_iocp_worker) { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } else { pollset->on_shutdown = closure; } } -void grpc_pollset_destroy(grpc_pollset* pollset) {} +void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) {} -grpc_error* grpc_pollset_work(grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -125,8 +126,8 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, pollset->is_iocp_worker = 1; g_active_poller = &worker; gpr_mu_unlock(&grpc_polling_mu); - grpc_iocp_work(deadline); - grpc_core::ExecCtx::Get()->Flush(); + grpc_iocp_work(exec_ctx, deadline); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&grpc_polling_mu); pollset->is_iocp_worker = 0; g_active_poller = NULL; @@ -144,7 +145,7 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, } if (pollset->shutting_down && pollset->on_shutdown != NULL) { - GRPC_CLOSURE_SCHED(pollset->on_shutdown, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, pollset->on_shutdown, GRPC_ERROR_NONE); pollset->on_shutdown = NULL; } goto done; @@ -157,18 +158,18 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, while (!worker.kicked) { if (gpr_cv_wait(&worker.cv, &grpc_polling_mu, grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); break; } - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); } } else { pollset->kicked_without_pollers = 0; } done: - if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { + if (!grpc_closure_list_empty(exec_ctx->closure_list)) { gpr_mu_unlock(&grpc_polling_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&grpc_polling_mu); } if (added_worker) { @@ -180,7 +181,7 @@ done: return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* p, +grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, grpc_pollset_worker* specific_worker) { if (specific_worker != NULL) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { @@ -208,7 +209,7 @@ grpc_error* grpc_pollset_kick(grpc_pollset* p, specific_worker = pop_front_worker(&p->root_worker, GRPC_POLLSET_WORKER_LINK_POLLSET); if (specific_worker != NULL) { - grpc_pollset_kick(p, specific_worker); + grpc_pollset_kick(exec_ctx, p, specific_worker); } else if (p->is_iocp_worker) { grpc_iocp_kick(); } else { diff --git a/src/core/lib/iomgr/resolve_address.h b/src/core/lib/iomgr/resolve_address.h index 12fc2ed088..5105020404 100644 --- a/src/core/lib/iomgr/resolve_address.h +++ b/src/core/lib/iomgr/resolve_address.h @@ -38,7 +38,8 @@ typedef struct { /* Asynchronously resolve addr. Use default_port if a port isn't designated in addr, otherwise use the port in addr. */ /* TODO(ctiller): add a timeout here */ -extern void (*grpc_resolve_address)(const char* addr, const char* default_port, +extern void (*grpc_resolve_address)(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses); diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index cc3d4fd7cf..fb5fa9d422 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -42,7 +42,6 @@ static grpc_error* blocking_resolve_address_impl( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { - grpc_core::ExecCtx exec_ctx; struct addrinfo hints; struct addrinfo *result = nullptr, *resp; char* host; @@ -82,7 +81,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; if (s != 0) { /* Retry if well-known service name is recognized */ @@ -91,7 +90,7 @@ static grpc_error* blocking_resolve_address_impl( if (strcmp(port, svc[i][0]) == 0) { GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, svc[i][1], &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; break; } } @@ -153,10 +152,12 @@ typedef struct { /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ -static void do_request_thread(void* rp, grpc_error* error) { +static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, + grpc_error* error) { request* r = (request*)rp; - GRPC_CLOSURE_SCHED(r->on_done, grpc_blocking_resolve_address( - r->name, r->default_port, r->addrs_out)); + GRPC_CLOSURE_SCHED( + exec_ctx, r->on_done, + grpc_blocking_resolve_address(r->name, r->default_port, r->addrs_out)); gpr_free(r->name); gpr_free(r->default_port); gpr_free(r); @@ -169,7 +170,8 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(const char* name, const char* default_port, +static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -180,11 +182,11 @@ static void resolve_address_impl(const char* name, const char* default_port, r->default_port = gpr_strdup(default_port); r->on_done = on_done; r->addrs_out = addrs; - GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &r->request_closure, GRPC_ERROR_NONE); } void (*grpc_resolve_address)( - const char* name, const char* default_port, + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc index 3eab04f3de..6d09fd1d02 100644 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ b/src/core/lib/iomgr/resolve_address_uv.cc @@ -114,7 +114,7 @@ static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { request* r = (request*)req->data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_error* error; int retry_status; char* port = r->port; @@ -130,8 +130,8 @@ static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, /* Either no retry was attempted, or the retry failed. Either way, the original error probably has more interesting information */ error = handle_addrinfo_result(status, res, r->addresses); - GRPC_CLOSURE_SCHED(r->on_done, error); - + GRPC_CLOSURE_SCHED(&exec_ctx, r->on_done, error); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(r->hints); gpr_free(r->host); gpr_free(r->port); @@ -224,7 +224,8 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(const char* name, const char* default_port, +static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -238,7 +239,7 @@ static void resolve_address_impl(const char* name, const char* default_port, GRPC_UV_ASSERT_SAME_THREAD(); err = try_split_host_port(name, default_port, &host, &port); if (err != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(on_done, err); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, err); gpr_free(host); gpr_free(port); return; @@ -267,7 +268,7 @@ static void resolve_address_impl(const char* name, const char* default_port, err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); err = grpc_error_set_str(err, GRPC_ERROR_STR_OS_ERROR, grpc_slice_from_static_string(uv_strerror(s))); - GRPC_CLOSURE_SCHED(on_done, err); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, err); gpr_free(r); gpr_free(req); gpr_free(hints); @@ -277,7 +278,7 @@ static void resolve_address_impl(const char* name, const char* default_port, } void (*grpc_resolve_address)( - const char* name, const char* default_port, + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index ccb1dae689..d9fc17a9f4 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -51,7 +51,6 @@ typedef struct { static grpc_error* blocking_resolve_address_impl( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { - grpc_core::ExecCtx exec_ctx; struct addrinfo hints; struct addrinfo *result = NULL, *resp; char* host; @@ -88,7 +87,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION; + GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; if (s != 0) { error = GRPC_WSA_ERROR(WSAGetLastError(), "getaddrinfo"); goto done; @@ -133,7 +132,8 @@ grpc_error* (*grpc_blocking_resolve_address)( /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ -static void do_request_thread(void* rp, grpc_error* error) { +static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, + grpc_error* error) { request* r = (request*)rp; if (error == GRPC_ERROR_NONE) { error = @@ -141,7 +141,7 @@ static void do_request_thread(void* rp, grpc_error* error) { } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_SCHED(r->on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, error); gpr_free(r->name); gpr_free(r->default_port); gpr_free(r); @@ -154,7 +154,8 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(const char* name, const char* default_port, +static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) { @@ -165,11 +166,11 @@ static void resolve_address_impl(const char* name, const char* default_port, r->default_port = gpr_strdup(default_port); r->on_done = on_done; r->addresses = addresses; - GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &r->request_closure, GRPC_ERROR_NONE); } void (*grpc_resolve_address)( - const char* name, const char* default_port, + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index cabe28e4e6..ccd8d9f379 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -154,7 +154,8 @@ struct grpc_resource_quota { char* name; }; -static void ru_unref_by(grpc_resource_user* resource_user, gpr_atm amount); +static void ru_unref_by(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, gpr_atm amount); /******************************************************************************* * list management @@ -238,31 +239,35 @@ static void rulist_remove(grpc_resource_user* resource_user, grpc_rulist list) { * resource quota state machine */ -static bool rq_alloc(grpc_resource_quota* resource_quota); +static bool rq_alloc(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota); static bool rq_reclaim_from_per_user_free_pool( - grpc_resource_quota* resource_quota); -static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive); + grpc_exec_ctx* exec_ctx, grpc_resource_quota* resource_quota); +static bool rq_reclaim(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota, bool destructive); -static void rq_step(void* rq, grpc_error* error) { +static void rq_step(grpc_exec_ctx* exec_ctx, void* rq, grpc_error* error) { grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; resource_quota->step_scheduled = false; do { - if (rq_alloc(resource_quota)) goto done; - } while (rq_reclaim_from_per_user_free_pool(resource_quota)); + if (rq_alloc(exec_ctx, resource_quota)) goto done; + } while (rq_reclaim_from_per_user_free_pool(exec_ctx, resource_quota)); - if (!rq_reclaim(resource_quota, false)) { - rq_reclaim(resource_quota, true); + if (!rq_reclaim(exec_ctx, resource_quota, false)) { + rq_reclaim(exec_ctx, resource_quota, true); } done: - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); } -static void rq_step_sched(grpc_resource_quota* resource_quota) { +static void rq_step_sched(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota) { if (resource_quota->step_scheduled) return; resource_quota->step_scheduled = true; grpc_resource_quota_ref_internal(resource_quota); - GRPC_CLOSURE_SCHED(&resource_quota->rq_step_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &resource_quota->rq_step_closure, + GRPC_ERROR_NONE); } /* update the atomically available resource estimate - use no barriers since @@ -281,7 +286,8 @@ static void rq_update_estimate(grpc_resource_quota* resource_quota) { } /* returns true if all allocations are completed */ -static bool rq_alloc(grpc_resource_quota* resource_quota) { +static bool rq_alloc(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota) { grpc_resource_user* resource_user; while ((resource_user = rulist_pop_head(resource_quota, GRPC_RULIST_AWAITING_ALLOCATION))) { @@ -301,9 +307,9 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) { int64_t aborted_allocations = resource_user->outstanding_allocations; resource_user->outstanding_allocations = 0; resource_user->free_pool += aborted_allocations; - GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &resource_user->on_allocated); gpr_mu_unlock(&resource_user->mu); - ru_unref_by(resource_user, (gpr_atm)aborted_allocations); + ru_unref_by(exec_ctx, resource_user, (gpr_atm)aborted_allocations); continue; } if (resource_user->free_pool < 0 && @@ -327,7 +333,7 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) { if (resource_user->free_pool >= 0) { resource_user->allocating = false; resource_user->outstanding_allocations = 0; - GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &resource_user->on_allocated); gpr_mu_unlock(&resource_user->mu); } else { rulist_add_head(resource_user, GRPC_RULIST_AWAITING_ALLOCATION); @@ -340,7 +346,7 @@ static bool rq_alloc(grpc_resource_quota* resource_quota) { /* returns true if any memory could be reclaimed from buffers */ static bool rq_reclaim_from_per_user_free_pool( - grpc_resource_quota* resource_quota) { + grpc_exec_ctx* exec_ctx, grpc_resource_quota* resource_quota) { grpc_resource_user* resource_user; while ((resource_user = rulist_pop_head(resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL))) { @@ -367,7 +373,8 @@ static bool rq_reclaim_from_per_user_free_pool( } /* returns true if reclamation is proceeding */ -static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) { +static bool rq_reclaim(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota, bool destructive) { if (resource_quota->reclaiming) return true; grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE : GRPC_RULIST_RECLAIMER_BENIGN; @@ -385,7 +392,7 @@ static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) { resource_quota->debug_only_last_reclaimer_resource_user = resource_user; resource_quota->debug_only_last_initiated_reclaimer = c; resource_user->reclaimers[destructive] = nullptr; - GRPC_CLOSURE_RUN(c, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_NONE); return true; } @@ -405,10 +412,10 @@ static void ru_slice_ref(void* p) { gpr_ref(&rc->refs); } -static void ru_slice_unref(void* p) { +static void ru_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { ru_slice_refcount* rc = (ru_slice_refcount*)p; if (gpr_unref(&rc->refs)) { - grpc_resource_user_free(rc->resource_user, rc->size); + grpc_resource_user_free(exec_ctx, rc->resource_user, rc->size); gpr_free(rc); } } @@ -438,57 +445,61 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user, * the combiner */ -static void ru_allocate(void* ru, grpc_error* error) { +static void ru_allocate(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; if (rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION)) { - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_AWAITING_ALLOCATION); } -static void ru_add_to_free_pool(void* ru, grpc_error* error) { +static void ru_add_to_free_pool(grpc_exec_ctx* exec_ctx, void* ru, + grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL)) { - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_NON_EMPTY_FREE_POOL); } -static bool ru_post_reclaimer(grpc_resource_user* resource_user, +static bool ru_post_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, bool destructive) { grpc_closure* closure = resource_user->new_reclaimers[destructive]; GPR_ASSERT(closure != nullptr); resource_user->new_reclaimers[destructive] = nullptr; GPR_ASSERT(resource_user->reclaimers[destructive] == nullptr); if (gpr_atm_acq_load(&resource_user->shutdown) > 0) { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CANCELLED); return false; } resource_user->reclaimers[destructive] = closure; return true; } -static void ru_post_benign_reclaimer(void* ru, grpc_error* error) { +static void ru_post_benign_reclaimer(grpc_exec_ctx* exec_ctx, void* ru, + grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; - if (!ru_post_reclaimer(resource_user, false)) return; + if (!ru_post_reclaimer(exec_ctx, resource_user, false)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_RECLAIMER_BENIGN)) { - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); } -static void ru_post_destructive_reclaimer(void* ru, grpc_error* error) { +static void ru_post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, void* ru, + grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; - if (!ru_post_reclaimer(resource_user, true)) return; + if (!ru_post_reclaimer(exec_ctx, resource_user, true)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, @@ -497,46 +508,51 @@ static void ru_post_destructive_reclaimer(void* ru, grpc_error* error) { GRPC_RULIST_RECLAIMER_BENIGN) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_RECLAIMER_DESTRUCTIVE)) { - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); } -static void ru_shutdown(void* ru, grpc_error* error) { +static void ru_shutdown(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RU shutdown %p", ru); } grpc_resource_user* resource_user = (grpc_resource_user*)ru; - GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[0], + GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], + GRPC_ERROR_CANCELLED); resource_user->reclaimers[0] = nullptr; resource_user->reclaimers[1] = nullptr; rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); if (resource_user->allocating) { - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } } -static void ru_destroy(void* ru, grpc_error* error) { +static void ru_destroy(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; GPR_ASSERT(gpr_atm_no_barrier_load(&resource_user->refs) == 0); for (int i = 0; i < GRPC_RULIST_COUNT; i++) { rulist_remove(resource_user, (grpc_rulist)i); } - GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[0], + GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], + GRPC_ERROR_CANCELLED); if (resource_user->free_pool != 0) { resource_user->resource_quota->free_pool += resource_user->free_pool; - rq_step_sched(resource_user->resource_quota); + rq_step_sched(exec_ctx, resource_user->resource_quota); } - grpc_resource_quota_unref_internal(resource_user->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_user->resource_quota); gpr_mu_destroy(&resource_user->mu); gpr_free(resource_user->name); gpr_free(resource_user); } -static void ru_allocated_slices(void* arg, grpc_error* error) { +static void ru_allocated_slices(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_resource_user_slice_allocator* slice_allocator = (grpc_resource_user_slice_allocator*)arg; if (error == GRPC_ERROR_NONE) { @@ -546,7 +562,7 @@ static void ru_allocated_slices(void* arg, grpc_error* error) { slice_allocator->length)); } } - GRPC_CLOSURE_RUN(&slice_allocator->on_done, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, &slice_allocator->on_done, GRPC_ERROR_REF(error)); } /******************************************************************************* @@ -560,22 +576,23 @@ typedef struct { grpc_closure closure; } rq_resize_args; -static void rq_resize(void* args, grpc_error* error) { +static void rq_resize(grpc_exec_ctx* exec_ctx, void* args, grpc_error* error) { rq_resize_args* a = (rq_resize_args*)args; int64_t delta = a->size - a->resource_quota->size; a->resource_quota->size += delta; a->resource_quota->free_pool += delta; rq_update_estimate(a->resource_quota); - rq_step_sched(a->resource_quota); - grpc_resource_quota_unref_internal(a->resource_quota); + rq_step_sched(exec_ctx, a->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, a->resource_quota); gpr_free(a); } -static void rq_reclamation_done(void* rq, grpc_error* error) { +static void rq_reclamation_done(grpc_exec_ctx* exec_ctx, void* rq, + grpc_error* error) { grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; resource_quota->reclaiming = false; - rq_step_sched(resource_quota); - grpc_resource_quota_unref_internal(resource_quota); + rq_step_sched(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); } /******************************************************************************* @@ -611,9 +628,10 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { return resource_quota; } -void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { +void grpc_resource_quota_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota) { if (gpr_unref(&resource_quota->refs)) { - GRPC_COMBINER_UNREF(resource_quota->combiner, "resource_quota"); + GRPC_COMBINER_UNREF(exec_ctx, resource_quota->combiner, "resource_quota"); gpr_free(resource_quota->name); gpr_free(resource_quota); } @@ -621,8 +639,9 @@ void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { /* Public API */ void grpc_resource_quota_unref(grpc_resource_quota* resource_quota) { - grpc_core::ExecCtx exec_ctx; - grpc_resource_quota_unref_internal(resource_quota); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota* grpc_resource_quota_ref_internal( @@ -646,14 +665,15 @@ double grpc_resource_quota_get_memory_pressure( /* Public API */ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t size) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a)); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota); a->size = (int64_t)size; gpr_atm_no_barrier_store(&resource_quota->last_size, (gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size)); GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&a->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &a->closure, GRPC_ERROR_NONE); + grpc_exec_ctx_finish(&exec_ctx); } size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) { @@ -684,8 +704,8 @@ static void* rq_copy(void* rq) { return rq; } -static void rq_destroy(void* rq) { - grpc_resource_quota_unref_internal((grpc_resource_quota*)rq); +static void rq_destroy(grpc_exec_ctx* exec_ctx, void* rq) { + grpc_resource_quota_unref_internal(exec_ctx, (grpc_resource_quota*)rq); } static int rq_cmp(void* a, void* b) { return GPR_ICMP(a, b); } @@ -753,12 +773,14 @@ static void ru_ref_by(grpc_resource_user* resource_user, gpr_atm amount) { GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&resource_user->refs, amount) != 0); } -static void ru_unref_by(grpc_resource_user* resource_user, gpr_atm amount) { +static void ru_unref_by(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, gpr_atm amount) { GPR_ASSERT(amount > 0); gpr_atm old = gpr_atm_full_fetch_add(&resource_user->refs, -amount); GPR_ASSERT(old >= amount); if (old == amount) { - GRPC_CLOSURE_SCHED(&resource_user->destroy_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->destroy_closure, + GRPC_ERROR_NONE); } } @@ -766,13 +788,16 @@ void grpc_resource_user_ref(grpc_resource_user* resource_user) { ru_ref_by(resource_user, 1); } -void grpc_resource_user_unref(grpc_resource_user* resource_user) { - ru_unref_by(resource_user, 1); +void grpc_resource_user_unref(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user) { + ru_unref_by(exec_ctx, resource_user, 1); } -void grpc_resource_user_shutdown(grpc_resource_user* resource_user) { +void grpc_resource_user_shutdown(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user) { if (gpr_atm_full_fetch_add(&resource_user->shutdown, 1) == 0) { GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE( ru_shutdown, resource_user, grpc_combiner_scheduler(resource_user->resource_quota->combiner)), @@ -780,7 +805,8 @@ void grpc_resource_user_shutdown(grpc_resource_user* resource_user) { } } -void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, +void grpc_resource_user_alloc(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, size_t size, grpc_closure* optional_on_done) { gpr_mu_lock(&resource_user->mu); ru_ref_by(resource_user, (gpr_atm)size); @@ -796,16 +822,18 @@ void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, GRPC_ERROR_NONE); if (!resource_user->allocating) { resource_user->allocating = true; - GRPC_CLOSURE_SCHED(&resource_user->allocate_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->allocate_closure, + GRPC_ERROR_NONE); } } else { resource_user->outstanding_allocations -= (int64_t)size; - GRPC_CLOSURE_SCHED(optional_on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, optional_on_done, GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); } -void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) { +void grpc_resource_user_free(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, size_t size) { gpr_mu_lock(&resource_user->mu); bool was_zero_or_negative = resource_user->free_pool <= 0; resource_user->free_pool += (int64_t)size; @@ -818,29 +846,32 @@ void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) { if (is_bigger_than_zero && was_zero_or_negative && !resource_user->added_to_free_pool) { resource_user->added_to_free_pool = true; - GRPC_CLOSURE_SCHED(&resource_user->add_to_free_pool_closure, + GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->add_to_free_pool_closure, GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); - ru_unref_by(resource_user, (gpr_atm)size); + ru_unref_by(exec_ctx, resource_user, (gpr_atm)size); } -void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user, +void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, bool destructive, grpc_closure* closure) { GPR_ASSERT(resource_user->new_reclaimers[destructive] == nullptr); resource_user->new_reclaimers[destructive] = closure; - GRPC_CLOSURE_SCHED(&resource_user->post_reclaimer_closure[destructive], + GRPC_CLOSURE_SCHED(exec_ctx, + &resource_user->post_reclaimer_closure[destructive], GRPC_ERROR_NONE); } -void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user) { +void grpc_resource_user_finish_reclamation(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user) { if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RQ %s %s: reclamation complete", resource_user->resource_quota->name, resource_user->name); } GRPC_CLOSURE_SCHED( - &resource_user->resource_quota->rq_reclamation_done_closure, + exec_ctx, &resource_user->resource_quota->rq_reclamation_done_closure, GRPC_ERROR_NONE); } @@ -855,11 +886,12 @@ void grpc_resource_user_slice_allocator_init( } void grpc_resource_user_alloc_slices( + grpc_exec_ctx* exec_ctx, grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest) { slice_allocator->length = length; slice_allocator->count = count; slice_allocator->dest = dest; - grpc_resource_user_alloc(slice_allocator->resource_user, count * length, - &slice_allocator->on_allocated); + grpc_resource_user_alloc(exec_ctx, slice_allocator->resource_user, + count * length, &slice_allocator->on_allocated); } diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 39e3aabf18..787370307a 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -65,7 +65,8 @@ extern grpc_core::TraceFlag grpc_resource_quota_trace; grpc_resource_quota* grpc_resource_quota_ref_internal( grpc_resource_quota* resource_quota); -void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota); +void grpc_resource_quota_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_resource_quota* resource_quota); grpc_resource_quota* grpc_resource_quota_from_channel_args( const grpc_channel_args* channel_args); @@ -88,26 +89,32 @@ grpc_resource_quota* grpc_resource_user_quota( grpc_resource_user* resource_user); void grpc_resource_user_ref(grpc_resource_user* resource_user); -void grpc_resource_user_unref(grpc_resource_user* resource_user); -void grpc_resource_user_shutdown(grpc_resource_user* resource_user); +void grpc_resource_user_unref(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user); +void grpc_resource_user_shutdown(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user); /* Allocate from the resource user (and its quota). If optional_on_done is NULL, then allocate immediately. This may push the quota over-limit, at which point reclamation will kick in. If optional_on_done is non-NULL, it will be scheduled when the allocation has been granted by the quota. */ -void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, +void grpc_resource_user_alloc(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, size_t size, grpc_closure* optional_on_done); /* Release memory back to the quota */ -void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size); +void grpc_resource_user_free(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, size_t size); /* Post a memory reclaimer to the resource user. Only one benign and one destructive reclaimer can be posted at once. When executed, the reclaimer MUST call grpc_resource_user_finish_reclamation before it completes, to return control to the resource quota. */ -void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user, +void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, bool destructive, grpc_closure* closure); /* Finish a reclamation step */ -void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user); +void grpc_resource_user_finish_reclamation(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user); /* Helper to allocate slices from a resource user */ typedef struct grpc_resource_user_slice_allocator { @@ -134,11 +141,13 @@ void grpc_resource_user_slice_allocator_init( /* Allocate \a count slices of length \a length into \a dest. Only one request can be outstanding at a time. */ void grpc_resource_user_alloc_slices( + grpc_exec_ctx* exec_ctx, grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest); /* Allocate one slice of length \a size synchronously. */ -grpc_slice grpc_resource_user_slice_malloc(grpc_resource_user* resource_user, +grpc_slice grpc_resource_user_slice_malloc(grpc_exec_ctx* exec_ctx, + grpc_resource_user* resource_user, size_t size); #endif /* GRPC_CORE_LIB_IOMGR_RESOURCE_QUOTA_H */ diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc index bc7d0b12f3..40bfecd4c2 100644 --- a/src/core/lib/iomgr/socket_factory_posix.cc +++ b/src/core/lib/iomgr/socket_factory_posix.cc @@ -72,7 +72,7 @@ static void* socket_factory_arg_copy(void* p) { return grpc_socket_factory_ref((grpc_socket_factory*)p); } -static void socket_factory_arg_destroy(void* p) { +static void socket_factory_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { grpc_socket_factory_unref((grpc_socket_factory*)p); } diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index 9d30e46b6b..ff6c0c70d8 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -63,7 +63,7 @@ static void* socket_mutator_arg_copy(void* p) { return grpc_socket_mutator_ref((grpc_socket_mutator*)p); } -static void socket_mutator_arg_destroy(void* p) { +static void socket_mutator_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { grpc_socket_mutator_unref((grpc_socket_mutator*)p); } diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 9bb6a75dd8..aee80f4b4c 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -109,34 +109,37 @@ void grpc_winsocket_destroy(grpc_winsocket* winsocket) { -) The IOCP already completed in the background, and we need to call the callback now. -) The IOCP hasn't completed yet, and we're queuing it for later. */ -static void socket_notify_on_iocp(grpc_winsocket* socket, grpc_closure* closure, +static void socket_notify_on_iocp(grpc_exec_ctx* exec_ctx, + grpc_winsocket* socket, grpc_closure* closure, grpc_winsocket_callback_info* info) { GPR_ASSERT(info->closure == NULL); gpr_mu_lock(&socket->state_mu); if (info->has_pending_iocp) { info->has_pending_iocp = 0; - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } else { info->closure = closure; } gpr_mu_unlock(&socket->state_mu); } -void grpc_socket_notify_on_write(grpc_winsocket* socket, +void grpc_socket_notify_on_write(grpc_exec_ctx* exec_ctx, + grpc_winsocket* socket, grpc_closure* closure) { - socket_notify_on_iocp(socket, closure, &socket->write_info); + socket_notify_on_iocp(exec_ctx, socket, closure, &socket->write_info); } -void grpc_socket_notify_on_read(grpc_winsocket* socket, grpc_closure* closure) { - socket_notify_on_iocp(socket, closure, &socket->read_info); +void grpc_socket_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, + grpc_closure* closure) { + socket_notify_on_iocp(exec_ctx, socket, closure, &socket->read_info); } -void grpc_socket_become_ready(grpc_winsocket* socket, +void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, grpc_winsocket_callback_info* info) { GPR_ASSERT(!info->has_pending_iocp); gpr_mu_lock(&socket->state_mu); if (info->closure) { - GRPC_CLOSURE_SCHED(info->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, info->closure, GRPC_ERROR_NONE); info->closure = NULL; } else { info->has_pending_iocp = 1; diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index cb28f2b8df..04e0a89d70 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -98,13 +98,16 @@ void grpc_winsocket_shutdown(grpc_winsocket* socket); /* Destroy a socket. Should only be called if there's no pending operation. */ void grpc_winsocket_destroy(grpc_winsocket* socket); -void grpc_socket_notify_on_write(grpc_winsocket* winsocket, +void grpc_socket_notify_on_write(grpc_exec_ctx* exec_ctx, + grpc_winsocket* winsocket, grpc_closure* closure); -void grpc_socket_notify_on_read(grpc_winsocket* winsocket, +void grpc_socket_notify_on_read(grpc_exec_ctx* exec_ctx, + grpc_winsocket* winsocket, grpc_closure* closure); -void grpc_socket_become_ready(grpc_winsocket* winsocket, +void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx, + grpc_winsocket* winsocket, grpc_winsocket_callback_info* ci); #endif diff --git a/src/core/lib/iomgr/tcp_client.h b/src/core/lib/iomgr/tcp_client.h index 5f55d30955..75e2fe0f36 100644 --- a/src/core/lib/iomgr/tcp_client.h +++ b/src/core/lib/iomgr/tcp_client.h @@ -30,7 +30,8 @@ NULL on failure). interested_parties points to a set of pollsets that would be interested in this connection being established (in order to continue their work) */ -void grpc_tcp_client_connect(grpc_closure* on_connect, grpc_endpoint** endpoint, +void grpc_tcp_client_connect(grpc_exec_ctx* exec_ctx, grpc_closure* on_connect, + grpc_endpoint** endpoint, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* addr, diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 15062a52cd..4cb2ac49d5 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(void* acp, grpc_error* error) { +static void tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { int done; async_connect* ac = (async_connect*)acp; if (grpc_tcp_trace.enabled()) { @@ -107,24 +107,26 @@ static void tc_on_alarm(void* acp, grpc_error* error) { gpr_mu_lock(&ac->mu); if (ac->fd != nullptr) { grpc_fd_shutdown( - ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out")); + exec_ctx, 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(ac->channel_args); + grpc_channel_args_destroy(exec_ctx, ac->channel_args); gpr_free(ac); } } grpc_endpoint* grpc_tcp_client_create_from_fd( - grpc_fd* fd, const grpc_channel_args* channel_args, const char* addr_str) { - return grpc_tcp_create(fd, channel_args, addr_str); + 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); } -static void on_writable(void* acp, grpc_error* error) { +static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { async_connect* ac = (async_connect*)acp; int so_error = 0; socklen_t so_error_size; @@ -148,7 +150,7 @@ static void on_writable(void* acp, grpc_error* error) { ac->fd = nullptr; gpr_mu_unlock(&ac->mu); - grpc_timer_cancel(&ac->alarm); + grpc_timer_cancel(exec_ctx, &ac->alarm); gpr_mu_lock(&ac->mu); if (error != GRPC_ERROR_NONE) { @@ -170,8 +172,9 @@ static void on_writable(void* acp, grpc_error* error) { switch (so_error) { case 0: - grpc_pollset_set_del_fd(ac->interested_parties, fd); - *ep = grpc_tcp_client_create_from_fd(fd, ac->channel_args, ac->addr_str); + 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); fd = nullptr; break; case ENOBUFS: @@ -191,7 +194,7 @@ static void on_writable(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(fd, &ac->write_closure); + grpc_fd_notify_on_write(exec_ctx, fd, &ac->write_closure); return; case ECONNREFUSED: /* This error shouldn't happen for anything other than connect(). */ @@ -206,8 +209,8 @@ static void on_writable(void* acp, grpc_error* error) { finish: if (fd != nullptr) { - grpc_pollset_set_del_fd(ac->interested_parties, fd); - grpc_fd_orphan(fd, nullptr, nullptr, false /* already_closed */, + grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); + grpc_fd_orphan(exec_ctx, fd, nullptr, nullptr, false /* already_closed */, "tcp_client_orphan"); fd = nullptr; } @@ -230,13 +233,14 @@ finish: if (done) { gpr_mu_destroy(&ac->mu); gpr_free(ac->addr_str); - grpc_channel_args_destroy(ac->channel_args); + grpc_channel_args_destroy(exec_ctx, ac->channel_args); gpr_free(ac); } - GRPC_CLOSURE_SCHED(closure, error); + GRPC_CLOSURE_SCHED(exec_ctx, closure, error); } -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, +static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, + grpc_closure* closure, grpc_endpoint** ep, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* addr, @@ -261,7 +265,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, error = grpc_create_dualstack_socket(addr, SOCK_STREAM, 0, &dsmode, &fd); if (error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(closure, error); + GRPC_CLOSURE_SCHED(exec_ctx, closure, error); return; } if (dsmode == GRPC_DSMODE_IPV4) { @@ -270,7 +274,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, addr = &addr4_copy; } if ((error = prepare_socket(addr, fd, channel_args)) != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(closure, error); + GRPC_CLOSURE_SCHED(exec_ctx, closure, error); return; } @@ -285,19 +289,20 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, fdobj = grpc_fd_create(fd, name); if (err >= 0) { - *ep = grpc_tcp_client_create_from_fd(fdobj, channel_args, addr_str); - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + *ep = + grpc_tcp_client_create_from_fd(exec_ctx, fdobj, channel_args, addr_str); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); goto done; } if (errno != EWOULDBLOCK && errno != EINPROGRESS) { - grpc_fd_orphan(fdobj, nullptr, nullptr, false /* already_closed */, - "tcp_client_connect_error"); - GRPC_CLOSURE_SCHED(closure, GRPC_OS_ERROR(errno, "connect")); + grpc_fd_orphan(exec_ctx, fdobj, nullptr, nullptr, + false /* already_closed */, "tcp_client_connect_error"); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_OS_ERROR(errno, "connect")); goto done; } - grpc_pollset_set_add_fd(interested_parties, fdobj); + grpc_pollset_set_add_fd(exec_ctx, interested_parties, fdobj); ac = (async_connect*)gpr_malloc(sizeof(async_connect)); ac->closure = closure; @@ -319,8 +324,8 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, gpr_mu_lock(&ac->mu); GRPC_CLOSURE_INIT(&ac->on_alarm, tc_on_alarm, ac, grpc_schedule_on_exec_ctx); - grpc_timer_init(&ac->alarm, deadline, &ac->on_alarm); - grpc_fd_notify_on_write(ac->fd, &ac->write_closure); + grpc_timer_init(exec_ctx, &ac->alarm, deadline, &ac->on_alarm); + grpc_fd_notify_on_write(exec_ctx, ac->fd, &ac->write_closure); gpr_mu_unlock(&ac->mu); done: @@ -330,18 +335,19 @@ done: // overridden by api_fuzzer.c void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, + grpc_exec_ctx* exec_ctx, 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_closure* closure, grpc_endpoint** ep, +void grpc_tcp_client_connect(grpc_exec_ctx* exec_ctx, 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(closure, ep, interested_parties, channel_args, - addr, deadline); + grpc_tcp_client_connect_impl(exec_ctx, closure, ep, interested_parties, + channel_args, addr, deadline); } #endif diff --git a/src/core/lib/iomgr/tcp_client_posix.h b/src/core/lib/iomgr/tcp_client_posix.h index 7d0f133a6b..2b1fe79e90 100644 --- a/src/core/lib/iomgr/tcp_client_posix.h +++ b/src/core/lib/iomgr/tcp_client_posix.h @@ -24,6 +24,7 @@ #include "src/core/lib/iomgr/tcp_client.h" grpc_endpoint* grpc_tcp_client_create_from_fd( - grpc_fd* fd, const grpc_channel_args* channel_args, const char* addr_str); + grpc_exec_ctx* exec_ctx, grpc_fd* fd, const grpc_channel_args* channel_args, + const char* addr_str); #endif /* GRPC_CORE_LIB_IOMGR_TCP_CLIENT_POSIX_H */ diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 4e9c7cc11d..5cca0c9936 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -46,15 +46,17 @@ typedef struct grpc_uv_tcp_connect { grpc_resource_quota* resource_quota; } grpc_uv_tcp_connect; -static void uv_tcp_connect_cleanup(grpc_uv_tcp_connect* connect) { - grpc_resource_quota_unref_internal(connect->resource_quota); +static void uv_tcp_connect_cleanup(grpc_exec_ctx* exec_ctx, + grpc_uv_tcp_connect* connect) { + grpc_resource_quota_unref_internal(exec_ctx, connect->resource_quota); gpr_free(connect->addr_name); gpr_free(connect); } static void tcp_close_callback(uv_handle_t* handle) { gpr_free(handle); } -static void uv_tc_on_alarm(void* acp, grpc_error* error) { +static void uv_tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, + grpc_error* error) { int done; grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)acp; if (grpc_tcp_trace.enabled()) { @@ -70,17 +72,17 @@ static void uv_tc_on_alarm(void* acp, grpc_error* error) { } done = (--connect->refs == 0); if (done) { - uv_tcp_connect_cleanup(connect); + uv_tcp_connect_cleanup(exec_ctx, connect); } } static void uv_tc_on_connect(uv_connect_t* req, int status) { grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_error* error = GRPC_ERROR_NONE; int done; grpc_closure* closure = connect->closure; - grpc_timer_cancel(&connect->alarm); + grpc_timer_cancel(&exec_ctx, &connect->alarm); if (status == 0) { *connect->endpoint = grpc_tcp_create( connect->tcp_handle, connect->resource_quota, connect->addr_name); @@ -105,13 +107,15 @@ static void uv_tc_on_connect(uv_connect_t* req, int status) { } done = (--connect->refs == 0); if (done) { - grpc_core::ExecCtx::Get()->Flush(); - uv_tcp_connect_cleanup(connect); + grpc_exec_ctx_flush(&exec_ctx); + uv_tcp_connect_cleanup(&exec_ctx, connect); } - GRPC_CLOSURE_SCHED(closure, error); + GRPC_CLOSURE_SCHED(&exec_ctx, closure, error); + grpc_exec_ctx_finish(&exec_ctx); } -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, +static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, + grpc_closure* closure, grpc_endpoint** ep, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* resolved_addr, @@ -126,7 +130,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, if (channel_args != NULL) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -153,23 +157,24 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, (const struct sockaddr*)resolved_addr->addr, uv_tc_on_connect); GRPC_CLOSURE_INIT(&connect->on_alarm, uv_tc_on_alarm, connect, grpc_schedule_on_exec_ctx); - grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); + grpc_timer_init(exec_ctx, &connect->alarm, deadline, &connect->on_alarm); } // overridden by api_fuzzer.c void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, + grpc_exec_ctx* exec_ctx, 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_closure* closure, grpc_endpoint** ep, +void grpc_tcp_client_connect(grpc_exec_ctx* exec_ctx, 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(closure, ep, interested_parties, channel_args, - addr, deadline); + grpc_tcp_client_connect_impl(exec_ctx, closure, ep, interested_parties, + channel_args, addr, deadline); } #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 5521a0a9ae..5e30725e90 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -52,12 +52,13 @@ typedef struct { grpc_channel_args* channel_args; } async_connect; -static void async_connect_unlock_and_cleanup(async_connect* ac, +static void async_connect_unlock_and_cleanup(grpc_exec_ctx* exec_ctx, + async_connect* ac, grpc_winsocket* socket) { int done = (--ac->refs == 0); gpr_mu_unlock(&ac->mu); if (done) { - grpc_channel_args_destroy(ac->channel_args); + grpc_channel_args_destroy(exec_ctx, ac->channel_args); gpr_mu_destroy(&ac->mu); gpr_free(ac->addr_name); gpr_free(ac); @@ -65,7 +66,7 @@ static void async_connect_unlock_and_cleanup(async_connect* ac, if (socket != NULL) grpc_winsocket_destroy(socket); } -static void on_alarm(void* acp, grpc_error* error) { +static void on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { async_connect* ac = (async_connect*)acp; gpr_mu_lock(&ac->mu); grpc_winsocket* socket = ac->socket; @@ -73,10 +74,10 @@ static void on_alarm(void* acp, grpc_error* error) { if (socket != NULL) { grpc_winsocket_shutdown(socket); } - async_connect_unlock_and_cleanup(ac, socket); + async_connect_unlock_and_cleanup(exec_ctx, ac, socket); } -static void on_connect(void* acp, grpc_error* error) { +static void on_connect(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { async_connect* ac = (async_connect*)acp; grpc_endpoint** ep = ac->endpoint; GPR_ASSERT(*ep == NULL); @@ -89,7 +90,7 @@ static void on_connect(void* acp, grpc_error* error) { ac->socket = NULL; gpr_mu_unlock(&ac->mu); - grpc_timer_cancel(&ac->alarm); + grpc_timer_cancel(exec_ctx, &ac->alarm); gpr_mu_lock(&ac->mu); @@ -104,7 +105,8 @@ static void on_connect(void* acp, grpc_error* error) { if (!wsa_success) { error = GRPC_WSA_ERROR(WSAGetLastError(), "ConnectEx"); } else { - *ep = grpc_tcp_create(socket, ac->channel_args, ac->addr_name); + *ep = + grpc_tcp_create(exec_ctx, socket, ac->channel_args, ac->addr_name); socket = NULL; } } else { @@ -112,20 +114,18 @@ static void on_connect(void* acp, grpc_error* error) { } } - async_connect_unlock_and_cleanup(ac, socket); + async_connect_unlock_and_cleanup(exec_ctx, ac, socket); /* If the connection was aborted, the callback was already called when the deadline was met. */ - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); } /* Tries to issue one async connection, then schedules both an IOCP notification request for the connection, and one timeout alert. */ -static void tcp_client_connect_impl(grpc_closure* on_done, - grpc_endpoint** endpoint, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { +static void tcp_client_connect_impl( + grpc_exec_ctx* exec_ctx, grpc_closure* on_done, grpc_endpoint** endpoint, + grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, grpc_millis deadline) { SOCKET sock = INVALID_SOCKET; BOOL success; int status; @@ -205,8 +205,8 @@ static void tcp_client_connect_impl(grpc_closure* on_done, GRPC_CLOSURE_INIT(&ac->on_connect, on_connect, ac, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&ac->on_alarm, on_alarm, ac, grpc_schedule_on_exec_ctx); - grpc_timer_init(&ac->alarm, deadline, &ac->on_alarm); - grpc_socket_notify_on_write(socket, &ac->on_connect); + grpc_timer_init(exec_ctx, &ac->alarm, deadline, &ac->on_alarm); + grpc_socket_notify_on_write(exec_ctx, socket, &ac->on_connect); return; failure: @@ -222,23 +222,24 @@ failure: } else if (sock != INVALID_SOCKET) { closesocket(sock); } - GRPC_CLOSURE_SCHED(on_done, final_error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, final_error); } // overridden by api_fuzzer.c void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, + grpc_exec_ctx* exec_ctx, 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_closure* closure, grpc_endpoint** ep, +void grpc_tcp_client_connect(grpc_exec_ctx* exec_ctx, 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(closure, ep, interested_parties, channel_args, - addr, deadline); + grpc_tcp_client_connect_impl(exec_ctx, closure, ep, interested_parties, + channel_args, addr, deadline); } #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 155329d2e8..d09cfca9af 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -108,31 +108,36 @@ typedef struct backup_poller { static gpr_atm g_uncovered_notifications_pending; static gpr_atm g_backup_poller; /* backup_poller* */ -static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error); -static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error); -static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */, +static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error); +static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error); +static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx* exec_ctx, + void* arg /* grpc_tcp */, grpc_error* error); -static void done_poller(void* bp, grpc_error* error_ignored) { +static void done_poller(grpc_exec_ctx* exec_ctx, void* bp, + grpc_error* error_ignored) { backup_poller* p = (backup_poller*)bp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); } - grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p)); + grpc_pollset_destroy(exec_ctx, BACKUP_POLLER_POLLSET(p)); gpr_free(p); } -static void run_poller(void* bp, grpc_error* error_ignored) { +static void run_poller(grpc_exec_ctx* exec_ctx, void* bp, + grpc_error* error_ignored) { backup_poller* p = (backup_poller*)bp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); } gpr_mu_lock(p->pollset_mu); - grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 13 * GPR_MS_PER_SEC; - GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(); + grpc_millis deadline = grpc_exec_ctx_now(exec_ctx) + 13 * GPR_MS_PER_SEC; + GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", - grpc_pollset_work(BACKUP_POLLER_POLLSET(p), nullptr, deadline)); + grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), nullptr, deadline)); gpr_mu_unlock(p->pollset_mu); /* last "uncovered" notification is the ref that keeps us polling, if we get * there try a cas to release it */ @@ -147,18 +152,18 @@ static void run_poller(void* bp, grpc_error* error_ignored) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p); } - grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p), + grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p), GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, grpc_schedule_on_exec_ctx)); } else { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); } - GRPC_CLOSURE_SCHED(&p->run_poller, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &p->run_poller, GRPC_ERROR_NONE); } } -static void drop_uncovered(grpc_tcp* tcp) { +static void drop_uncovered(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { backup_poller* p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller); gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); @@ -169,7 +174,7 @@ static void drop_uncovered(grpc_tcp* tcp) { GPR_ASSERT(old_count != 1); } -static void cover_self(grpc_tcp* tcp) { +static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { backup_poller* p; gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); @@ -178,7 +183,7 @@ static void cover_self(grpc_tcp* tcp) { 2 + (int)old_count); } if (old_count == 0) { - GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(); + GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx); p = (backup_poller*)gpr_zalloc(sizeof(*p) + grpc_pollset_size()); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); @@ -186,6 +191,7 @@ static void cover_self(grpc_tcp* tcp) { grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); gpr_atm_rel_store(&g_backup_poller, (gpr_atm)p); GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)), GRPC_ERROR_NONE); @@ -198,38 +204,39 @@ static void cover_self(grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); } - grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd); + grpc_pollset_add_fd(exec_ctx, BACKUP_POLLER_POLLSET(p), tcp->em_fd); if (old_count != 0) { - drop_uncovered(tcp); + drop_uncovered(exec_ctx, tcp); } } -static void notify_on_read(grpc_tcp* tcp) { +static void notify_on_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp); } GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure); + grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_done_closure); } -static void notify_on_write(grpc_tcp* tcp) { +static void notify_on_write(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp); } - cover_self(tcp); + cover_self(exec_ctx, tcp); GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_drop_uncovered_then_handle_write, tcp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_write(tcp->em_fd, &tcp->write_done_closure); + grpc_fd_notify_on_write(exec_ctx, tcp->em_fd, &tcp->write_done_closure); } -static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error* error) { +static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); } - drop_uncovered((grpc_tcp*)arg); - tcp_handle_write(arg, error); + drop_uncovered(exec_ctx, (grpc_tcp*)arg); + tcp_handle_write(exec_ctx, arg, error); } static void add_to_estimate(grpc_tcp* tcp, size_t bytes) { @@ -275,29 +282,33 @@ static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) { grpc_slice_from_copied_string(tcp->peer_string)); } -static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error); -static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error); +static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error); +static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error); -static void tcp_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void tcp_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_fd_shutdown(tcp->em_fd, why); - grpc_resource_user_shutdown(tcp->resource_user); + grpc_fd_shutdown(exec_ctx, tcp->em_fd, why); + grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); } -static void tcp_free(grpc_tcp* tcp) { - grpc_fd_orphan(tcp->em_fd, tcp->release_fd_cb, tcp->release_fd, +static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { + grpc_fd_orphan(exec_ctx, tcp->em_fd, tcp->release_fd_cb, tcp->release_fd, false /* already_closed */, "tcp_unref_orphan"); - grpc_slice_buffer_destroy_internal(&tcp->last_read_buffer); - grpc_resource_user_unref(tcp->resource_user); + grpc_slice_buffer_destroy_internal(exec_ctx, &tcp->last_read_buffer); + grpc_resource_user_unref(exec_ctx, tcp->resource_user); gpr_free(tcp->peer_string); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(cl, tcp, reason) \ + tcp_unref((cl), (tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + const char* reason, const char* file, int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -305,7 +316,7 @@ static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } @@ -320,25 +331,26 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) +#define TCP_UNREF(cl, tcp, reason) tcp_unref((cl), (tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_tcp* tcp) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif -static void tcp_destroy(grpc_endpoint* ep) { +static void tcp_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); - TCP_UNREF(tcp, "destroy"); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer); + TCP_UNREF(exec_ctx, tcp, "destroy"); } -static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { +static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + grpc_error* error) { grpc_closure* cb = tcp->read_cb; if (grpc_tcp_trace.enabled()) { @@ -357,11 +369,11 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { tcp->read_cb = nullptr; tcp->incoming_buffer = nullptr; - GRPC_CLOSURE_RUN(cb, error); + GRPC_CLOSURE_RUN(exec_ctx, cb, error); } #define MAX_READ_IOVEC 4 -static void tcp_do_read(grpc_tcp* tcp) { +static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { struct msghdr msg; struct iovec iov[MAX_READ_IOVEC]; ssize_t read_bytes; @@ -384,12 +396,12 @@ static void tcp_do_read(grpc_tcp* tcp) { msg.msg_controllen = 0; msg.msg_flags = 0; - GRPC_STATS_INC_TCP_READ_OFFER(tcp->incoming_buffer->length); - GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(tcp->incoming_buffer->count); + GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, tcp->incoming_buffer->length); + GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(exec_ctx, tcp->incoming_buffer->count); GPR_TIMER_BEGIN("recvmsg", 0); do { - GRPC_STATS_INC_SYSCALL_READ(); + GRPC_STATS_INC_SYSCALL_READ(exec_ctx); read_bytes = recvmsg(tcp->fd, &msg, 0); } while (read_bytes < 0 && errno == EINTR); GPR_TIMER_END("recvmsg", read_bytes >= 0); @@ -400,22 +412,24 @@ static void tcp_do_read(grpc_tcp* tcp) { if (errno == EAGAIN) { finish_estimate(tcp); /* We've consumed the edge, request a new one */ - notify_on_read(tcp); + notify_on_read(exec_ctx, tcp); } else { - grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); - call_read_cb(tcp, + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + tcp->incoming_buffer); + call_read_cb(exec_ctx, tcp, tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp)); - TCP_UNREF(tcp, "read"); + TCP_UNREF(exec_ctx, tcp, "read"); } } else if (read_bytes == 0) { /* 0 read size ==> end of stream */ - grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); call_read_cb( - tcp, tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp)); - TCP_UNREF(tcp, "read"); + exec_ctx, tcp, + tcp_annotate_error( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp)); + TCP_UNREF(exec_ctx, tcp, "read"); } else { - GRPC_STATS_INC_TCP_READ_SIZE(read_bytes); + GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, read_bytes); add_to_estimate(tcp, (size_t)read_bytes); GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length); if ((size_t)read_bytes < tcp->incoming_buffer->length) { @@ -425,47 +439,50 @@ static void tcp_do_read(grpc_tcp* tcp) { &tcp->last_read_buffer); } GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length); - call_read_cb(tcp, GRPC_ERROR_NONE); - TCP_UNREF(tcp, "read"); + call_read_cb(exec_ctx, tcp, GRPC_ERROR_NONE); + TCP_UNREF(exec_ctx, tcp, "read"); } GPR_TIMER_END("tcp_continue_read", 0); } -static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { +static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, + grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, grpc_error_string(error)); } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); - grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); - call_read_cb(tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + &tcp->last_read_buffer); + call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(exec_ctx, tcp, "read"); } else { - tcp_do_read(tcp); + tcp_do_read(exec_ctx, tcp); } } -static void tcp_continue_read(grpc_tcp* tcp) { +static void tcp_continue_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { size_t target_read_size = get_target_read_size(tcp); if (tcp->incoming_buffer->length < target_read_size && tcp->incoming_buffer->count < MAX_READ_IOVEC) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp); } - grpc_resource_user_alloc_slices(&tcp->slice_allocator, target_read_size, 1, - tcp->incoming_buffer); + grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, + target_read_size, 1, tcp->incoming_buffer); } else { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp); } - tcp_do_read(tcp); + tcp_do_read(exec_ctx, tcp); } } -static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) { +static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)arg; GPR_ASSERT(!tcp->finished_edge); if (grpc_tcp_trace.enabled()) { @@ -473,35 +490,37 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) { } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); - grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); - call_read_cb(tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + &tcp->last_read_buffer); + call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(exec_ctx, tcp, "read"); } else { - tcp_continue_read(tcp); + tcp_continue_read(exec_ctx, tcp); } } -static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, - grpc_closure* cb) { +static void tcp_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* incoming_buffer, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; tcp->incoming_buffer = incoming_buffer; - grpc_slice_buffer_reset_and_unref_internal(incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, incoming_buffer); grpc_slice_buffer_swap(incoming_buffer, &tcp->last_read_buffer); TCP_REF(tcp, "read"); if (tcp->finished_edge) { tcp->finished_edge = false; - notify_on_read(tcp); + notify_on_read(exec_ctx, tcp); } else { - GRPC_CLOSURE_SCHED(&tcp->read_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &tcp->read_done_closure, GRPC_ERROR_NONE); } } /* returns true if done, false if pending; if returning true, *error is set */ #define MAX_WRITE_IOVEC 1000 -static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { +static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + grpc_error** error) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; msg_iovlen_type iov_size; @@ -543,13 +562,13 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { msg.msg_controllen = 0; msg.msg_flags = 0; - GRPC_STATS_INC_TCP_WRITE_SIZE(sending_length); - GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(iov_size); + GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, sending_length); + GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, iov_size); GPR_TIMER_BEGIN("sendmsg", 1); do { /* TODO(klempner): Cork if this is a partial write */ - GRPC_STATS_INC_SYSCALL_WRITE(); + GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx); sent_length = sendmsg(tcp->fd, &msg, SENDMSG_FLAGS); } while (sent_length < 0 && errno == EINTR); GPR_TIMER_END("sendmsg", 0); @@ -561,18 +580,20 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { // point for (size_t idx = 0; idx < unwind_slice_idx; ++idx) { grpc_slice_unref_internal( - grpc_slice_buffer_take_first(tcp->outgoing_buffer)); + exec_ctx, grpc_slice_buffer_take_first(tcp->outgoing_buffer)); } return false; } else if (errno == EPIPE) { *error = grpc_error_set_int(GRPC_OS_ERROR(errno, "sendmsg"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); - grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + tcp->outgoing_buffer); return true; } else { *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "sendmsg"), tcp); - grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + tcp->outgoing_buffer); return true; } } @@ -595,29 +616,31 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { if (outgoing_slice_idx == tcp->outgoing_buffer->count) { *error = GRPC_ERROR_NONE; - grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + tcp->outgoing_buffer); return true; } } } -static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) { +static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, + grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)arg; grpc_closure* cb; if (error != GRPC_ERROR_NONE) { cb = tcp->write_cb; tcp->write_cb = nullptr; - cb->cb(cb->cb_arg, error); - TCP_UNREF(tcp, "write"); + cb->cb(exec_ctx, cb->cb_arg, error); + TCP_UNREF(exec_ctx, tcp, "write"); return; } - if (!tcp_flush(tcp, &error)) { + if (!tcp_flush(exec_ctx, tcp, &error)) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } - notify_on_write(tcp); + notify_on_write(exec_ctx, tcp); } else { cb = tcp->write_cb; tcp->write_cb = nullptr; @@ -626,13 +649,13 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) { gpr_log(GPR_DEBUG, "write: %s", str); } - GRPC_CLOSURE_RUN(cb, error); - TCP_UNREF(tcp, "write"); + GRPC_CLOSURE_RUN(exec_ctx, cb, error); + TCP_UNREF(exec_ctx, tcp, "write"); } } -static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, - grpc_closure* cb) { +static void tcp_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* buf, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_error* error = GRPC_ERROR_NONE; @@ -653,48 +676,51 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, if (buf->length == 0) { GPR_TIMER_END("tcp_write", 0); GRPC_CLOSURE_SCHED( - cb, grpc_fd_is_shutdown(tcp->em_fd) - ? tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp) - : GRPC_ERROR_NONE); + exec_ctx, cb, + grpc_fd_is_shutdown(tcp->em_fd) + ? tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), + tcp) + : GRPC_ERROR_NONE); return; } tcp->outgoing_buffer = buf; tcp->outgoing_byte_idx = 0; - if (!tcp_flush(tcp, &error)) { + if (!tcp_flush(exec_ctx, tcp, &error)) { TCP_REF(tcp, "write"); tcp->write_cb = cb; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } - notify_on_write(tcp); + notify_on_write(exec_ctx, tcp); } else { if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); } - GRPC_CLOSURE_SCHED(cb, error); + GRPC_CLOSURE_SCHED(exec_ctx, cb, error); } GPR_TIMER_END("tcp_write", 0); } -static void tcp_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { +static void tcp_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_add_fd(pollset, tcp->em_fd); + grpc_pollset_add_fd(exec_ctx, pollset, tcp->em_fd); } -static void tcp_add_to_pollset_set(grpc_endpoint* ep, +static void tcp_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_pollset_set* pollset_set) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_set_add_fd(pollset_set, tcp->em_fd); + grpc_pollset_set_add_fd(exec_ctx, pollset_set, tcp->em_fd); } -static void tcp_delete_from_pollset_set(grpc_endpoint* ep, +static void tcp_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_set_del_fd(pollset_set, tcp->em_fd); + grpc_pollset_set_del_fd(exec_ctx, pollset_set, tcp->em_fd); } static char* tcp_get_peer(grpc_endpoint* ep) { @@ -725,7 +751,7 @@ static const grpc_endpoint_vtable vtable = {tcp_read, #define MAX_CHUNK_SIZE 32 * 1024 * 1024 -grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, +grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, const grpc_channel_args* channel_args, const char* peer_string) { int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE; @@ -754,7 +780,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -791,7 +817,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); /* Tell network status tracker about new endpoint */ grpc_network_status_register_endpoint(&tcp->base); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); return &tcp->base; } @@ -802,15 +828,15 @@ int grpc_tcp_fd(grpc_endpoint* ep) { return grpc_fd_wrapped_fd(tcp->em_fd); } -void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, - grpc_closure* done) { +void grpc_tcp_destroy_and_release_fd(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + int* fd, grpc_closure* done) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; GPR_ASSERT(ep->vtable == &vtable); tcp->release_fd = fd; tcp->release_fd_cb = done; - grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); - TCP_UNREF(tcp, "destroy"); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer); + TCP_UNREF(exec_ctx, tcp, "destroy"); } #endif diff --git a/src/core/lib/iomgr/tcp_posix.h b/src/core/lib/iomgr/tcp_posix.h index 4529c02beb..09051b7ed6 100644 --- a/src/core/lib/iomgr/tcp_posix.h +++ b/src/core/lib/iomgr/tcp_posix.h @@ -37,7 +37,8 @@ extern grpc_core::TraceFlag grpc_tcp_trace; /* Create a tcp endpoint given a file desciptor and a read slice size. Takes ownership of fd. */ -grpc_endpoint* grpc_tcp_create(grpc_fd* fd, const grpc_channel_args* args, +grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* fd, + const grpc_channel_args* args, const char* peer_string); /* Return the tcp endpoint's fd, or -1 if this is not available. Does not @@ -49,7 +50,7 @@ int grpc_tcp_fd(grpc_endpoint* ep); /* Destroy the tcp endpoint without closing its fd. *fd will be set and done * will be called when the endpoint is destroyed. * Requires: ep must be a tcp endpoint and fd must not be NULL. */ -void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, - grpc_closure* done); +void grpc_tcp_destroy_and_release_fd(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + int* fd, grpc_closure* done); #endif /* GRPC_CORE_LIB_IOMGR_TCP_POSIX_H */ diff --git a/src/core/lib/iomgr/tcp_server.h b/src/core/lib/iomgr/tcp_server.h index 038c765c6c..a1757a2b3e 100644 --- a/src/core/lib/iomgr/tcp_server.h +++ b/src/core/lib/iomgr/tcp_server.h @@ -39,20 +39,22 @@ typedef struct grpc_tcp_server_acceptor { /* Called for newly connected TCP connections. Takes ownership of acceptor. */ -typedef void (*grpc_tcp_server_cb)(void* arg, grpc_endpoint* ep, +typedef void (*grpc_tcp_server_cb)(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* ep, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor); /* Create a server, initially not bound to any ports. The caller owns one ref. If shutdown_complete is not NULL, it will be used by grpc_tcp_server_unref() when the ref count reaches zero. */ -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, + grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server); /* Start listening to bound ports */ -void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, - size_t pollset_count, +void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* server, + grpc_pollset** pollsets, size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* cb_arg); /* Add a port to the server, returning the newly allocated port on success, or @@ -90,9 +92,10 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, /* If the refcount drops to zero, enqueue calls on exec_ctx to shutdown_listeners and delete s. */ -void grpc_tcp_server_unref(grpc_tcp_server* s); +void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s); /* Shutdown the fds of listeners. */ -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s); +void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, + grpc_tcp_server* s); #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_H */ diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 99e1c6cd06..6fed13c6c7 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -68,7 +68,8 @@ static void init(void) { #endif } -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, + grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { gpr_once_init(&check_init, init); @@ -115,12 +116,12 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, return GRPC_ERROR_NONE; } -static void finish_shutdown(grpc_tcp_server* s) { +static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { gpr_mu_lock(&s->mu); GPR_ASSERT(s->shutdown); gpr_mu_unlock(&s->mu); if (s->shutdown_complete != nullptr) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } gpr_mu_destroy(&s->mu); @@ -130,18 +131,19 @@ static void finish_shutdown(grpc_tcp_server* s) { s->head = sp->next; gpr_free(sp); } - grpc_channel_args_destroy(s->channel_args); + grpc_channel_args_destroy(exec_ctx, s->channel_args); gpr_free(s); } -static void destroyed_port(void* server, grpc_error* error) { +static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, + grpc_error* error) { grpc_tcp_server* s = (grpc_tcp_server*)server; gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { gpr_mu_unlock(&s->mu); - finish_shutdown(s); + finish_shutdown(exec_ctx, s); } else { GPR_ASSERT(s->destroyed_ports < s->nports); gpr_mu_unlock(&s->mu); @@ -151,7 +153,7 @@ static void destroyed_port(void* server, grpc_error* error) { /* called when all listening endpoints have been shutdown, so no further events will be received on them - at this point it's safe to destroy things */ -static void deactivated_all_ports(grpc_tcp_server* s) { +static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { /* delete ALL the things */ gpr_mu_lock(&s->mu); @@ -163,17 +165,17 @@ static void deactivated_all_ports(grpc_tcp_server* s) { grpc_unlink_if_unix_domain_socket(&sp->addr); GRPC_CLOSURE_INIT(&sp->destroyed_closure, destroyed_port, s, grpc_schedule_on_exec_ctx); - grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr, + grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "tcp_listener_shutdown"); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - finish_shutdown(s); + finish_shutdown(exec_ctx, s); } } -static void tcp_server_destroy(grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { gpr_mu_lock(&s->mu); GPR_ASSERT(!s->shutdown); @@ -184,17 +186,18 @@ static void tcp_server_destroy(grpc_tcp_server* s) { grpc_tcp_listener* sp; for (sp = s->head; sp; sp = sp->next) { grpc_fd_shutdown( - sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server destroyed")); + exec_ctx, sp->emfd, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server destroyed")); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - deactivated_all_ports(s); + deactivated_all_ports(exec_ctx, s); } } /* event manager callback when reads are ready */ -static void on_read(void* arg, grpc_error* err) { +static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* err) { grpc_tcp_listener* sp = (grpc_tcp_listener*)arg; grpc_pollset* read_notifier_pollset; if (err != GRPC_ERROR_NONE) { @@ -220,7 +223,7 @@ static void on_read(void* arg, grpc_error* err) { case EINTR: continue; case EAGAIN: - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); return; default: gpr_mu_lock(&sp->server->mu); @@ -246,7 +249,7 @@ static void on_read(void* arg, grpc_error* err) { grpc_fd* fdobj = grpc_fd_create(fd, name); - grpc_pollset_add_fd(read_notifier_pollset, fdobj); + grpc_pollset_add_fd(exec_ctx, read_notifier_pollset, fdobj); // Create acceptor. grpc_tcp_server_acceptor* acceptor = @@ -256,8 +259,8 @@ static void on_read(void* arg, grpc_error* err) { acceptor->fd_index = sp->fd_index; sp->server->on_accept_cb( - sp->server->on_accept_cb_arg, - grpc_tcp_create(fdobj, sp->server->channel_args, addr_str), + exec_ctx, sp->server->on_accept_cb_arg, + grpc_tcp_create(exec_ctx, fdobj, sp->server->channel_args, addr_str), read_notifier_pollset, acceptor); gpr_free(name); @@ -270,7 +273,7 @@ error: gpr_mu_lock(&sp->server->mu); if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(sp->server); + deactivated_all_ports(exec_ctx, sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -480,8 +483,8 @@ int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, return -1; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, - size_t pollset_count, +void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, + grpc_pollset** pollsets, size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* on_accept_cb_arg) { size_t i; @@ -501,20 +504,20 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, GPR_ASSERT(GRPC_LOG_IF_ERROR( "clone_port", clone_port(sp, (unsigned)(pollset_count - 1)))); for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(pollsets[i], sp->emfd); + grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); s->active_ports++; sp = sp->next; } } else { for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(pollsets[i], sp->emfd); + grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); } GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); s->active_ports++; sp = sp->next; } @@ -535,24 +538,25 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { - grpc_tcp_server_shutdown_listeners(s); + grpc_tcp_server_shutdown_listeners(exec_ctx, s); gpr_mu_lock(&s->mu); - GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &s->shutdown_starting); gpr_mu_unlock(&s->mu); - tcp_server_destroy(s); + tcp_server_destroy(exec_ctx, s); } } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { +void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, + grpc_tcp_server* s) { gpr_mu_lock(&s->mu); s->shutdown_listeners = true; /* shutdown all fd's */ if (s->active_ports) { grpc_tcp_listener* sp; for (sp = s->head; sp; sp = sp->next) { - grpc_fd_shutdown(sp->emfd, + grpc_fd_shutdown(exec_ctx, sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown")); } } diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 1ac49190fb..ffadf0b1ab 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -73,7 +73,8 @@ struct grpc_tcp_server { grpc_resource_quota* resource_quota; }; -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, + grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); @@ -81,11 +82,11 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { if (args->args[i].type == GRPC_ARG_POINTER) { - grpc_resource_quota_unref_internal(s->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); s->resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)args->args[i].value.pointer.p); } else { - grpc_resource_quota_unref_internal(s->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); gpr_free(s); return GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); @@ -118,10 +119,10 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, GRPC_ERROR_NONE); } -static void finish_shutdown(grpc_tcp_server* s) { +static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { GPR_ASSERT(s->shutdown); if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } while (s->head) { @@ -131,17 +132,18 @@ static void finish_shutdown(grpc_tcp_server* s) { gpr_free(sp->handle); gpr_free(sp); } - grpc_resource_quota_unref_internal(s->resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); gpr_free(s); } static void handle_close_callback(uv_handle_t* handle) { grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; sp->server->open_ports--; if (sp->server->open_ports == 0 && sp->server->shutdown) { - finish_shutdown(sp->server); + finish_shutdown(&exec_ctx, sp->server); } + grpc_exec_ctx_finish(&exec_ctx); } static void close_listener(grpc_tcp_listener* sp) { @@ -151,7 +153,7 @@ static void close_listener(grpc_tcp_listener* sp) { } } -static void tcp_server_destroy(grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { int immediately_done = 0; grpc_tcp_listener* sp; @@ -166,22 +168,28 @@ static void tcp_server_destroy(grpc_tcp_server* s) { } if (immediately_done) { - finish_shutdown(s); + finish_shutdown(exec_ctx, s); } } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); if (gpr_unref(&s->refs)) { /* Complete shutdown_starting work before destroying. */ - grpc_core::ExecCtx exec_ctx; - GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); - grpc_core::ExecCtx::Get()->Flush(); - tcp_server_destroy(s); + grpc_exec_ctx local_exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CLOSURE_LIST_SCHED(&local_exec_ctx, &s->shutdown_starting); + if (exec_ctx == NULL) { + grpc_exec_ctx_flush(&local_exec_ctx); + tcp_server_destroy(&local_exec_ctx, s); + grpc_exec_ctx_finish(&local_exec_ctx); + } else { + grpc_exec_ctx_finish(&local_exec_ctx); + tcp_server_destroy(exec_ctx, s); + } } } -static void finish_accept(grpc_tcp_listener* sp) { +static void finish_accept(grpc_exec_ctx* exec_ctx, grpc_tcp_listener* sp) { grpc_tcp_server_acceptor* acceptor = (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); uv_tcp_t* client = NULL; @@ -217,13 +225,14 @@ static void finish_accept(grpc_tcp_listener* sp) { acceptor->from_server = sp->server; acceptor->port_index = sp->port_index; acceptor->fd_index = 0; - sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); + sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep, NULL, + acceptor); gpr_free(peer_name_string); } static void on_connect(uv_stream_t* server, int status) { grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; if (status < 0) { switch (status) { @@ -244,10 +253,11 @@ static void on_connect(uv_stream_t* server, int status) { // Create acceptor. if (sp->server->on_accept_cb) { - finish_accept(sp); + finish_accept(&exec_ctx, sp); } else { sp->has_pending_connection = true; } + grpc_exec_ctx_finish(&exec_ctx); } static grpc_error* add_addr_to_server(grpc_tcp_server* s, @@ -444,8 +454,8 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, return error; } -void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, - size_t pollset_count, +void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* server, + grpc_pollset** pollsets, size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* cb_arg) { grpc_tcp_listener* sp; (void)pollsets; @@ -460,12 +470,13 @@ void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, server->on_accept_cb_arg = cb_arg; for (sp = server->head; sp; sp = sp->next) { if (sp->has_pending_connection) { - finish_accept(sp); + finish_accept(exec_ctx, sp); sp->has_pending_connection = false; } } } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} +void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, + grpc_tcp_server* s) {} #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 8a30dfde43..f538194895 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -94,7 +94,8 @@ struct grpc_tcp_server { /* Public function. Allocates the proper data structures to hold a grpc_tcp_server. */ -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, + grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); @@ -113,7 +114,8 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, return GRPC_ERROR_NONE; } -static void destroy_server(void* arg, grpc_error* error) { +static void destroy_server(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_tcp_server* s = (grpc_tcp_server*)arg; /* Now that the accepts have been aborted, we can destroy the sockets. @@ -126,16 +128,18 @@ static void destroy_server(void* arg, grpc_error* error) { grpc_winsocket_destroy(sp->socket); gpr_free(sp); } - grpc_channel_args_destroy(s->channel_args); + grpc_channel_args_destroy(exec_ctx, s->channel_args); gpr_free(s); } -static void finish_shutdown_locked(grpc_tcp_server* s) { +static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_tcp_server* s) { if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(destroy_server, s, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } @@ -153,14 +157,14 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, gpr_mu_unlock(&s->mu); } -static void tcp_server_destroy(grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { grpc_tcp_listener* sp; gpr_mu_lock(&s->mu); /* First, shutdown all fd's. This will queue abortion calls for all of the pending accepts due to the normal operation mechanism. */ if (s->active_ports == 0) { - finish_shutdown_locked(s); + finish_shutdown_locked(exec_ctx, s); } else { for (sp = s->head; sp; sp = sp->next) { sp->shutting_down = 1; @@ -170,13 +174,13 @@ static void tcp_server_destroy(grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { - grpc_tcp_server_shutdown_listeners(s); + grpc_tcp_server_shutdown_listeners(exec_ctx, s); gpr_mu_lock(&s->mu); - GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); + GRPC_CLOSURE_LIST_SCHED(exec_ctx, &s->shutdown_starting); gpr_mu_unlock(&s->mu); - tcp_server_destroy(s); + tcp_server_destroy(exec_ctx, s); } } @@ -230,17 +234,19 @@ failure: return error; } -static void decrement_active_ports_and_notify_locked(grpc_tcp_listener* sp) { +static void decrement_active_ports_and_notify_locked(grpc_exec_ctx* exec_ctx, + grpc_tcp_listener* sp) { sp->shutting_down = 0; GPR_ASSERT(sp->server->active_ports > 0); if (0 == --sp->server->active_ports) { - finish_shutdown_locked(sp->server); + finish_shutdown_locked(exec_ctx, sp->server); } } /* In order to do an async accept, we need to create a socket first which will be the one assigned to the new incoming connection. */ -static grpc_error* start_accept_locked(grpc_tcp_listener* port) { +static grpc_error* start_accept_locked(grpc_exec_ctx* exec_ctx, + grpc_tcp_listener* port) { SOCKET sock = INVALID_SOCKET; BOOL success; DWORD addrlen = sizeof(struct sockaddr_in6) + 16; @@ -279,7 +285,7 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { /* We're ready to do the accept. Calling grpc_socket_notify_on_read may immediately process an accept that happened in the meantime. */ port->new_socket = sock; - grpc_socket_notify_on_read(port->socket, &port->on_accept); + grpc_socket_notify_on_read(exec_ctx, port->socket, &port->on_accept); port->outstanding_calls++; return error; @@ -290,7 +296,7 @@ failure: } /* Event manager callback when reads are ready. */ -static void on_accept(void* arg, grpc_error* error) { +static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_tcp_listener* sp = (grpc_tcp_listener*)arg; SOCKET sock = sp->new_socket; grpc_winsocket_callback_info* info = &sp->socket->read_info; @@ -351,7 +357,7 @@ static void on_accept(void* arg, grpc_error* error) { gpr_free(utf8_message); } gpr_asprintf(&fd_name, "tcp_server:%s", peer_name_string); - ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name), + ep = grpc_tcp_create(exec_ctx, grpc_winsocket_create(sock, fd_name), sp->server->channel_args, peer_name_string); gpr_free(fd_name); gpr_free(peer_name_string); @@ -369,15 +375,17 @@ static void on_accept(void* arg, grpc_error* error) { acceptor->from_server = sp->server; acceptor->port_index = sp->port_index; acceptor->fd_index = 0; - sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); + sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep, NULL, + acceptor); } /* As we were notified from the IOCP of one and exactly one accept, the former socked we created has now either been destroy or assigned to the new connection. We need to create a new one for the next connection. */ - GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(exec_ctx, sp))); if (0 == --sp->outstanding_calls) { - decrement_active_ports_and_notify_locked(sp); + decrement_active_ports_and_notify_locked(exec_ctx, sp); } gpr_mu_unlock(&sp->server->mu); } @@ -514,8 +522,8 @@ done: return error; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, - size_t pollset_count, +void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, + grpc_pollset** pollset, size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* on_accept_cb_arg) { grpc_tcp_listener* sp; @@ -526,12 +534,14 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, s->on_accept_cb = on_accept_cb; s->on_accept_cb_arg = on_accept_cb_arg; for (sp = s->head; sp; sp = sp->next) { - GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(exec_ctx, sp))); s->active_ports++; } gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} +void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, + grpc_tcp_server* s) {} #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 2c26b60511..40f4006203 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -65,18 +65,19 @@ typedef struct { grpc_pollset* pollset; } grpc_tcp; -static void tcp_free(grpc_tcp* tcp) { - grpc_resource_user_unref(tcp->resource_user); +static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { + grpc_resource_user_unref(exec_ctx, tcp->resource_user); gpr_free(tcp->handle); gpr_free(tcp->peer_string); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(exec_ctx, tcp, reason) \ + tcp_unref((exec_ctx), (tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + const char* reason, const char* file, int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -84,7 +85,7 @@ static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } @@ -99,11 +100,11 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) +#define TCP_UNREF(exec_ctx, tcp, reason) tcp_unref((exec_ctx), (tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_tcp* tcp) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } @@ -111,14 +112,15 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif static void uv_close_callback(uv_handle_t* handle) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp* tcp = (grpc_tcp*)handle->data; - TCP_UNREF(tcp, "destroy"); + TCP_UNREF(&exec_ctx, tcp, "destroy"); + grpc_exec_ctx_finish(&exec_ctx); } static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp* tcp = (grpc_tcp*)handle->data; (void)suggested_size; /* Before calling uv_read_start, we allocate a buffer with exactly one slice @@ -126,9 +128,11 @@ static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, * allocation was successful. So slices[0] should always exist here */ buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); buf->len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); + grpc_exec_ctx_finish(&exec_ctx); } -static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { +static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + grpc_error* error) { grpc_closure* cb = tcp->read_cb; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); @@ -145,25 +149,25 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { } tcp->read_slices = NULL; tcp->read_cb = NULL; - GRPC_CLOSURE_RUN(cb, error); + GRPC_CLOSURE_RUN(exec_ctx, cb, error); } static void read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { grpc_error* error; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp* tcp = (grpc_tcp*)stream->data; grpc_slice_buffer garbage; if (nread == 0) { // Nothing happened. Wait for the next callback return; } - TCP_UNREF(tcp, "read"); + TCP_UNREF(&exec_ctx, tcp, "read"); // TODO(murgatroid99): figure out what the return value here means uv_read_stop(stream); if (nread == UV_EOF) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); } else if (nread > 0) { // Successful read error = GRPC_ERROR_NONE; @@ -173,17 +177,19 @@ static void read_callback(uv_stream_t* stream, ssize_t nread, grpc_slice_buffer_init(&garbage); grpc_slice_buffer_trim_end( tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); - grpc_slice_buffer_reset_and_unref_internal(&garbage); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &garbage); } } else { // nread < 0: Error error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); } - call_read_cb(tcp, error); + call_read_cb(&exec_ctx, tcp, error); + grpc_exec_ctx_finish(&exec_ctx); } -static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { +static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, + grpc_error* error) { int status; grpc_tcp* tcp = (grpc_tcp*)tcpp; if (grpc_tcp_trace.enabled()) { @@ -201,9 +207,9 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { } } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); - call_read_cb(tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->read_slices); + call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(exec_ctx, tcp, "read"); } if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); @@ -211,16 +217,16 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { } } -static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, - grpc_closure* cb) { +static void uv_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* read_slices, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(tcp->read_cb == NULL); tcp->read_cb = cb; tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(read_slices); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices); TCP_REF(tcp, "read"); - grpc_resource_user_alloc_slices(&tcp->slice_allocator, + grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, tcp->read_slices); } @@ -228,10 +234,10 @@ static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, static void write_callback(uv_write_t* req, int status) { grpc_tcp* tcp = (grpc_tcp*)req->data; grpc_error* error; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure* cb = tcp->write_cb; tcp->write_cb = NULL; - TCP_UNREF(tcp, "write"); + TCP_UNREF(&exec_ctx, tcp, "write"); if (status == 0) { error = GRPC_ERROR_NONE; } else { @@ -242,10 +248,11 @@ static void write_callback(uv_write_t* req, int status) { gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str); } gpr_free(tcp->write_buffers); - GRPC_CLOSURE_SCHED(cb, error); + GRPC_CLOSURE_SCHED(&exec_ctx, cb, error); + grpc_exec_ctx_finish(&exec_ctx); } -static void uv_endpoint_write(grpc_endpoint* ep, +static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_slice_buffer* write_slices, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; @@ -268,8 +275,9 @@ static void uv_endpoint_write(grpc_endpoint* ep, } if (tcp->shutting_down) { - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "TCP socket is shutting down")); + GRPC_CLOSURE_SCHED( + exec_ctx, cb, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP socket is shutting down")); return; } @@ -279,7 +287,7 @@ static void uv_endpoint_write(grpc_endpoint* ep, if (tcp->write_slices->count == 0) { // No slices means we don't have to do anything, // and libuv doesn't like empty writes - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); return; } @@ -300,31 +308,37 @@ static void uv_endpoint_write(grpc_endpoint* ep, write_callback); } -static void uv_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { +static void uv_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) { // No-op. We're ignoring pollsets currently + (void)exec_ctx; (void)ep; (void)pollset; grpc_tcp* tcp = (grpc_tcp*)ep; tcp->pollset = pollset; } -static void uv_add_to_pollset_set(grpc_endpoint* ep, +static void uv_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_pollset_set* pollset) { // No-op. We're ignoring pollsets currently + (void)exec_ctx; (void)ep; (void)pollset; } -static void uv_delete_from_pollset_set(grpc_endpoint* ep, +static void uv_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset) { // No-op. We're ignoring pollsets currently + (void)exec_ctx; (void)ep; (void)pollset; } static void shutdown_callback(uv_shutdown_t* req, int status) {} -static void uv_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void uv_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; if (!tcp->shutting_down) { if (grpc_tcp_trace.enabled()) { @@ -334,12 +348,12 @@ static void uv_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { tcp->shutting_down = true; uv_shutdown_t* req = &tcp->shutdown_req; uv_shutdown(req, (uv_stream_t*)tcp->handle, shutdown_callback); - grpc_resource_user_shutdown(tcp->resource_user); + grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); } GRPC_ERROR_UNREF(why); } -static void uv_destroy(grpc_endpoint* ep) { +static void uv_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; uv_close((uv_handle_t*)tcp->handle, uv_close_callback); @@ -372,7 +386,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, grpc_resource_quota* resource_quota, char* peer_string) { grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); @@ -399,6 +413,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, uv_unref((uv_handle_t*)handle); #endif + grpc_exec_ctx_finish(&exec_ctx); return &tcp->base; } diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 6d091b77bb..33868cdc7a 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -109,20 +109,21 @@ typedef struct grpc_tcp { char* peer_string; } grpc_tcp; -static void tcp_free(grpc_tcp* tcp) { +static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { grpc_winsocket_destroy(tcp->socket); gpr_mu_destroy(&tcp->mu); gpr_free(tcp->peer_string); - grpc_resource_user_unref(tcp->resource_user); + grpc_resource_user_unref(exec_ctx, tcp->resource_user); if (tcp->shutting_down) GRPC_ERROR_UNREF(tcp->shutdown_error); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(exec_ctx, tcp, reason) \ + tcp_unref((exec_ctx), (tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, + const char* reason, const char* file, int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -130,7 +131,7 @@ static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } @@ -145,11 +146,11 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) +#define TCP_UNREF(exec_ctx, tcp, reason) tcp_unref((exec_ctx), (tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_tcp* tcp) { +static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); + tcp_free(exec_ctx, tcp); } } @@ -157,7 +158,7 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif /* Asynchronous callback from the IOCP, or the background thread. */ -static void on_read(void* tcpp, grpc_error* error) { +static void on_read(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; grpc_closure* cb = tcp->read_cb; grpc_winsocket* socket = tcp->socket; @@ -171,13 +172,13 @@ static void on_read(void* tcpp, grpc_error* error) { char* utf8_message = gpr_format_message(info->wsa_error); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(utf8_message); gpr_free(utf8_message); - grpc_slice_unref_internal(tcp->read_slice); + grpc_slice_unref_internal(exec_ctx, tcp->read_slice); } else { if (info->bytes_transfered != 0 && !tcp->shutting_down) { sub = grpc_slice_sub_no_ref(tcp->read_slice, 0, info->bytes_transfered); grpc_slice_buffer_add(tcp->read_slices, sub); } else { - grpc_slice_unref_internal(tcp->read_slice); + grpc_slice_unref_internal(exec_ctx, tcp->read_slice); error = tcp->shutting_down ? GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "TCP stream shutting down", &tcp->shutdown_error, 1) @@ -187,12 +188,12 @@ static void on_read(void* tcpp, grpc_error* error) { } tcp->read_cb = NULL; - TCP_UNREF(tcp, "read"); - GRPC_CLOSURE_SCHED(cb, error); + TCP_UNREF(exec_ctx, tcp, "read"); + GRPC_CLOSURE_SCHED(exec_ctx, cb, error); } -static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, - grpc_closure* cb) { +static void win_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* read_slices, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_winsocket* handle = tcp->socket; grpc_winsocket_callback_info* info = &handle->read_info; @@ -203,14 +204,15 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, if (tcp->shutting_down) { GRPC_CLOSURE_SCHED( - cb, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "TCP socket is shutting down", &tcp->shutdown_error, 1)); + exec_ctx, cb, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "TCP socket is shutting down", &tcp->shutdown_error, 1)); return; } tcp->read_cb = cb; tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(read_slices); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices); tcp->read_slice = GRPC_SLICE_MALLOC(8192); @@ -228,7 +230,7 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, /* Did we get data immediately ? Yay. */ if (info->wsa_error != WSAEWOULDBLOCK) { info->bytes_transfered = bytes_read; - GRPC_CLOSURE_SCHED(&tcp->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &tcp->on_read, GRPC_ERROR_NONE); return; } @@ -241,17 +243,17 @@ static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, int wsa_error = WSAGetLastError(); if (wsa_error != WSA_IO_PENDING) { info->wsa_error = wsa_error; - GRPC_CLOSURE_SCHED(&tcp->on_read, + GRPC_CLOSURE_SCHED(exec_ctx, &tcp->on_read, GRPC_WSA_ERROR(info->wsa_error, "WSARecv")); return; } } - grpc_socket_notify_on_read(tcp->socket, &tcp->on_read); + grpc_socket_notify_on_read(exec_ctx, tcp->socket, &tcp->on_read); } /* Asynchronous callback from the IOCP, or the background thread. */ -static void on_write(void* tcpp, grpc_error* error) { +static void on_write(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; grpc_winsocket* handle = tcp->socket; grpc_winsocket_callback_info* info = &handle->write_info; @@ -272,13 +274,13 @@ static void on_write(void* tcpp, grpc_error* error) { } } - TCP_UNREF(tcp, "write"); - GRPC_CLOSURE_SCHED(cb, error); + TCP_UNREF(exec_ctx, tcp, "write"); + GRPC_CLOSURE_SCHED(exec_ctx, cb, error); } /* Initiates a write. */ -static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void win_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_winsocket* socket = tcp->socket; grpc_winsocket_callback_info* info = &socket->write_info; @@ -292,8 +294,9 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, if (tcp->shutting_down) { GRPC_CLOSURE_SCHED( - cb, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "TCP socket is shutting down", &tcp->shutdown_error, 1)); + exec_ctx, cb, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "TCP socket is shutting down", &tcp->shutdown_error, 1)); return; } @@ -324,7 +327,7 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_error* error = status == 0 ? GRPC_ERROR_NONE : GRPC_WSA_ERROR(info->wsa_error, "WSASend"); - GRPC_CLOSURE_SCHED(cb, error); + GRPC_CLOSURE_SCHED(exec_ctx, cb, error); if (allocated) gpr_free(allocated); return; } @@ -341,32 +344,35 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, if (status != 0) { int wsa_error = WSAGetLastError(); if (wsa_error != WSA_IO_PENDING) { - TCP_UNREF(tcp, "write"); - GRPC_CLOSURE_SCHED(cb, GRPC_WSA_ERROR(wsa_error, "WSASend")); + TCP_UNREF(exec_ctx, tcp, "write"); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_WSA_ERROR(wsa_error, "WSASend")); return; } } /* As all is now setup, we can now ask for the IOCP notification. It may trigger the callback immediately however, but no matter. */ - grpc_socket_notify_on_write(socket, &tcp->on_write); + grpc_socket_notify_on_write(exec_ctx, socket, &tcp->on_write); } -static void win_add_to_pollset(grpc_endpoint* ep, grpc_pollset* ps) { +static void win_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* ps) { grpc_tcp* tcp; (void)ps; tcp = (grpc_tcp*)ep; grpc_iocp_add_socket(tcp->socket); } -static void win_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pss) { +static void win_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset_set* pss) { grpc_tcp* tcp; (void)pss; tcp = (grpc_tcp*)ep; grpc_iocp_add_socket(tcp->socket); } -static void win_delete_from_pollset_set(grpc_endpoint* ep, +static void win_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pss) {} /* Initiates a shutdown of the TCP endpoint. This will queue abort callbacks @@ -375,7 +381,8 @@ static void win_delete_from_pollset_set(grpc_endpoint* ep, we're not going to protect against these. However the IO Completion Port callback will happen from another thread, so we need to protect against concurrent access of the data structure in that regard. */ -static void win_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void win_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; gpr_mu_lock(&tcp->mu); /* At that point, what may happen is that we're already inside the IOCP @@ -388,13 +395,13 @@ static void win_shutdown(grpc_endpoint* ep, grpc_error* why) { } grpc_winsocket_shutdown(tcp->socket); gpr_mu_unlock(&tcp->mu); - grpc_resource_user_shutdown(tcp->resource_user); + grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); } -static void win_destroy(grpc_endpoint* ep) { +static void win_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; - TCP_UNREF(tcp, "destroy"); + TCP_UNREF(exec_ctx, tcp, "destroy"); } static char* win_get_peer(grpc_endpoint* ep) { @@ -420,14 +427,14 @@ static grpc_endpoint_vtable vtable = {win_read, win_get_peer, win_get_fd}; -grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket, +grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, grpc_channel_args* channel_args, const char* peer_string) { grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); if (channel_args != NULL) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -445,7 +452,7 @@ grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket, tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); /* Tell network status tracking code about the new endpoint */ grpc_network_status_register_endpoint(&tcp->base); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); return &tcp->base; } diff --git a/src/core/lib/iomgr/tcp_windows.h b/src/core/lib/iomgr/tcp_windows.h index 8578a358ea..28287e2795 100644 --- a/src/core/lib/iomgr/tcp_windows.h +++ b/src/core/lib/iomgr/tcp_windows.h @@ -38,7 +38,7 @@ /* Create a tcp endpoint given a winsock handle. * Takes ownership of the handle. */ -grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket, +grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, grpc_channel_args* channel_args, const char* peer_string); diff --git a/src/core/lib/iomgr/timer.h b/src/core/lib/iomgr/timer.h index 82049859c5..b9acce229e 100644 --- a/src/core/lib/iomgr/timer.h +++ b/src/core/lib/iomgr/timer.h @@ -40,8 +40,8 @@ typedef struct grpc_timer grpc_timer; application code should check the error to determine how it was invoked. The application callback is also responsible for maintaining information about when to free up any user-level state. */ -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure); +void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, + grpc_millis deadline, grpc_closure* closure); /* Initialize *timer without setting it. This can later be passed through the regular init or cancel */ @@ -73,7 +73,7 @@ void grpc_timer_init_unset(grpc_timer* timer); matches this aim. Requires: cancel() must happen after init() on a given timer */ -void grpc_timer_cancel(grpc_timer* timer); +void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer); /* iomgr internal api for dealing with timers */ @@ -90,9 +90,10 @@ typedef enum { *next is never guaranteed to be updated on any given execution; however, with high probability at least one thread in the system will see an update at any time slice. */ -grpc_timer_check_result grpc_timer_check(grpc_millis* next); -void grpc_timer_list_init(); -void grpc_timer_list_shutdown(); +grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, + grpc_millis* next); +void grpc_timer_list_init(grpc_exec_ctx* exec_ctx); +void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx); /* Consume a kick issued by grpc_kick_poller */ void grpc_timer_consume_kick(void); diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 103144eb3b..fa95c43dbe 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -225,7 +225,8 @@ static gpr_atm saturating_add(gpr_atm a, gpr_atm b) { return a + b; } -static grpc_timer_check_result run_some_expired_timers(gpr_atm now, +static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, + gpr_atm now, gpr_atm* next, grpc_error* error); @@ -235,7 +236,7 @@ static gpr_atm compute_min_deadline(timer_shard* shard) { : grpc_timer_heap_top(&shard->heap)->deadline; } -void grpc_timer_list_init() { +void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); @@ -246,7 +247,7 @@ void grpc_timer_list_init() { g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; gpr_mu_init(&g_shared_mutables.mu); - g_shared_mutables.min_timer = grpc_core::ExecCtx::Get()->Now(); + g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); gpr_tls_init(&g_last_seen_min_timer); gpr_tls_set(&g_last_seen_min_timer, 0); @@ -266,10 +267,10 @@ void grpc_timer_list_init() { INIT_TIMER_HASH_TABLE(); } -void grpc_timer_list_shutdown() { +void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) { size_t i; run_some_expired_timers( - GPR_ATM_MAX, nullptr, + exec_ctx, GPR_ATM_MAX, nullptr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown")); for (i = 0; i < g_num_shards; i++) { timer_shard* shard = &g_shards[i]; @@ -322,8 +323,8 @@ static void note_deadline_change(timer_shard* shard) { void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { +void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, + grpc_millis deadline, grpc_closure* closure) { int is_first_timer = 0; timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer->closure = closure; @@ -336,12 +337,12 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, if (grpc_timer_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, - deadline, grpc_core::ExecCtx::Get()->Now(), closure, closure->cb); + deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); } if (!g_shared_mutables.initialized) { timer->pending = false; - GRPC_CLOSURE_SCHED(timer->closure, + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Attempt to create timer before initialization")); return; @@ -349,10 +350,10 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, gpr_mu_lock(&shard->mu); timer->pending = true; - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); if (deadline <= now) { timer->pending = false; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_NONE); gpr_mu_unlock(&shard->mu); /* early out */ return; @@ -413,7 +414,7 @@ void grpc_timer_consume_kick(void) { gpr_tls_set(&g_last_seen_min_timer, 0); } -void grpc_timer_cancel(grpc_timer* timer) { +void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { if (!g_shared_mutables.initialized) { /* must have already been cancelled, also the shard mutex is invalid */ return; @@ -429,7 +430,7 @@ void grpc_timer_cancel(grpc_timer* timer) { if (timer->pending) { REMOVE_FROM_HASH_TABLE(timer); - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CANCELLED); timer->pending = false; if (timer->heap_index == INVALID_HEAP_INDEX) { list_remove(timer); @@ -515,14 +516,15 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { } /* REQUIRES: shard->mu unlocked */ -static size_t pop_timers(timer_shard* shard, gpr_atm now, - gpr_atm* new_min_deadline, grpc_error* error) { +static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard, + gpr_atm now, gpr_atm* new_min_deadline, + grpc_error* error) { size_t n = 0; grpc_timer* timer; gpr_mu_lock(&shard->mu); while ((timer = pop_one(shard, now))) { REMOVE_FROM_HASH_TABLE(timer); - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_REF(error)); n++; } *new_min_deadline = compute_min_deadline(shard); @@ -534,7 +536,8 @@ static size_t pop_timers(timer_shard* shard, gpr_atm now, return n; } -static grpc_timer_check_result run_some_expired_timers(gpr_atm now, +static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, + gpr_atm now, gpr_atm* next, grpc_error* error) { grpc_timer_check_result result = GRPC_TIMERS_NOT_CHECKED; @@ -563,7 +566,8 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, /* For efficiency, we pop as many available timers as we can from the shard. This may violate perfect timer deadline ordering, but that shouldn't be a big deal because we don't make ordering guarantees. */ - if (pop_timers(g_shard_queue[0], now, &new_min_deadline, error) > 0) { + if (pop_timers(exec_ctx, g_shard_queue[0], now, &new_min_deadline, + error) > 0) { result = GRPC_TIMERS_FIRED; } @@ -600,9 +604,10 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, return result; } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { +grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, + grpc_millis* next) { // prelude - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + grpc_millis now = grpc_exec_ctx_now(exec_ctx); /* fetch from a thread-local first: this avoids contention on a globally mutable cacheline in the common case */ @@ -641,7 +646,7 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) { } // actual code grpc_timer_check_result r = - run_some_expired_timers(now, next, shutdown_error); + run_some_expired_timers(exec_ctx, now, next, shutdown_error); // tracing if (grpc_timer_check_trace.enabled()) { char* next_str; diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 8ca6a3c23e..87ed0e05dc 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -98,12 +98,13 @@ static void start_timer_thread_and_unlock(void) { } void grpc_timer_manager_tick() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_timer_check(&next); + grpc_timer_check(&exec_ctx, &next); + grpc_exec_ctx_finish(&exec_ctx); } -static void run_some_timers() { +static void run_some_timers(grpc_exec_ctx* exec_ctx) { // if there's something to execute... gpr_mu_lock(&g_mu); // remove a waiter from the pool, and start another thread if necessary @@ -125,7 +126,7 @@ static void run_some_timers() { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -137,7 +138,7 @@ static void run_some_timers() { // wait until 'next' (or forever if there is already a timed waiter in the pool) // returns true if the thread should continue executing (false if it should // shutdown) -static bool wait_until(grpc_millis next) { +static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { gpr_mu_lock(&g_mu); // if we're not threaded anymore, leave if (!g_threaded) { @@ -178,7 +179,7 @@ static bool wait_until(grpc_millis next) { g_timed_waiter_deadline = next; if (grpc_timer_check_trace.enabled()) { - grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now(); + grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -219,15 +220,15 @@ static bool wait_until(grpc_millis next) { return true; } -static void timer_main_loop() { +static void timer_main_loop(grpc_exec_ctx* exec_ctx) { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); // check timer state, updates next to the next time to run a check - switch (grpc_timer_check(&next)) { + switch (grpc_timer_check(exec_ctx, &next)) { case GRPC_TIMERS_FIRED: - run_some_timers(); + run_some_timers(exec_ctx); break; case GRPC_TIMERS_NOT_CHECKED: /* This case only happens under contention, meaning more than one timer @@ -245,7 +246,7 @@ static void timer_main_loop() { next = GRPC_MILLIS_INF_FUTURE; /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: - if (!wait_until(next)) { + if (!wait_until(exec_ctx, next)) { return; } break; @@ -273,9 +274,10 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - grpc_core::ExecCtx exec_ctx(0); - timer_main_loop(); - + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); + timer_main_loop(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); timer_thread_cleanup((completed_thread*)completed_thread_ptr); } diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 5d238da089..fac2026fa9 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -42,27 +42,28 @@ static void stop_uv_timer(uv_timer_t* handle) { void run_expired_timer(uv_timer_t* handle) { grpc_timer* timer = (grpc_timer*)handle->data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(timer->pending); timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, timer->closure, GRPC_ERROR_NONE); stop_uv_timer(handle); + grpc_exec_ctx_finish(&exec_ctx); } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { +void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, + grpc_millis deadline, grpc_closure* closure) { uint64_t timeout; uv_timer_t* uv_timer; GRPC_UV_ASSERT_SAME_THREAD(); timer->closure = closure; - if (deadline <= grpc_core::ExecCtx::Get()->Now()) { + if (deadline <= grpc_exec_ctx_now(exec_ctx)) { timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_NONE); return; } timer->pending = 1; - timeout = (uint64_t)(deadline - grpc_core::ExecCtx::Get()->Now()); + timeout = (uint64_t)(deadline - grpc_exec_ctx_now(exec_ctx)); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); uv_timer->data = timer; @@ -76,21 +77,22 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = 0; } -void grpc_timer_cancel(grpc_timer* timer) { +void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { GRPC_UV_ASSERT_SAME_THREAD(); if (timer->pending) { timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CANCELLED); stop_uv_timer((uv_timer_t*)timer->uv_timer); } } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { +grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, + grpc_millis* next) { return GRPC_TIMERS_NOT_CHECKED; } -void grpc_timer_list_init() {} -void grpc_timer_list_shutdown() {} +void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) {} +void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) {} void grpc_timer_consume_kick(void) {} diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 55e0b165ec..7b7d6946b1 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -150,30 +150,31 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { return s; } -static void shutdown_fd(void* args, grpc_error* error) { +static void shutdown_fd(grpc_exec_ctx* exec_ctx, void* args, + grpc_error* error) { struct shutdown_fd_args* shutdown_args = (struct shutdown_fd_args*)args; grpc_udp_listener* sp = shutdown_args->sp; gpr_log(GPR_DEBUG, "shutdown fd %d", sp->fd); gpr_mu_lock(shutdown_args->server_mu); - grpc_fd_shutdown(sp->emfd, GRPC_ERROR_REF(error)); + grpc_fd_shutdown(exec_ctx, sp->emfd, GRPC_ERROR_REF(error)); sp->already_shutdown = true; if (!sp->notify_on_write_armed) { // Re-arm write notification to notify listener with error. This is // necessary to decrement active_ports. sp->notify_on_write_armed = true; - grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); } gpr_mu_unlock(shutdown_args->server_mu); gpr_free(shutdown_args); } -static void dummy_cb(void* arg, grpc_error* error) { +static void dummy_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { // No-op. } -static void finish_shutdown(grpc_udp_server* s) { +static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { if (s->shutdown_complete != nullptr) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } gpr_mu_destroy(&s->mu); @@ -192,13 +193,14 @@ static void finish_shutdown(grpc_udp_server* s) { gpr_free(s); } -static void destroyed_port(void* server, grpc_error* error) { +static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, + grpc_error* error) { grpc_udp_server* s = (grpc_udp_server*)server; gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { gpr_mu_unlock(&s->mu); - finish_shutdown(s); + finish_shutdown(exec_ctx, s); } else { gpr_mu_unlock(&s->mu); } @@ -207,7 +209,7 @@ static void destroyed_port(void* server, grpc_error* error) { /* called when all listening endpoints have been shutdown, so no further events will be received on them - at this point it's safe to destroy things */ -static void deactivated_all_ports(grpc_udp_server* s) { +static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { /* delete ALL the things */ gpr_mu_lock(&s->mu); @@ -228,19 +230,21 @@ static void deactivated_all_ports(grpc_udp_server* s) { grpc_schedule_on_exec_ctx); GPR_ASSERT(sp->orphan_cb); gpr_log(GPR_DEBUG, "Orphan fd %d", sp->fd); - sp->orphan_cb(sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); + sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, + sp->server->user_data); } - grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr, + grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "udp_listener_shutdown"); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - finish_shutdown(s); + finish_shutdown(exec_ctx, s); } } -void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) { +void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, + grpc_closure* on_done) { grpc_udp_listener* sp; gpr_mu_lock(&s->mu); @@ -260,13 +264,14 @@ void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) { args->server_mu = &s->mu; GRPC_CLOSURE_INIT(&sp->orphan_fd_closure, shutdown_fd, args, grpc_schedule_on_exec_ctx); - sp->orphan_cb(sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); + sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, + sp->server->user_data); sp->orphan_notified = true; } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - deactivated_all_ports(s); + deactivated_all_ports(exec_ctx, s); } } @@ -345,7 +350,7 @@ error: return -1; } -static void do_read(void* arg, grpc_error* error) { +static void do_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); GPR_ASSERT(sp->read_cb && error == GRPC_ERROR_NONE); /* TODO: the reason we hold server->mu here is merely to prevent fd @@ -353,28 +358,29 @@ static void do_read(void* arg, grpc_error* error) { * read lock if available. */ gpr_mu_lock(&sp->server->mu); /* Tell the registered callback that data is available to read. */ - if (!sp->already_shutdown && sp->read_cb(sp->emfd, sp->server->user_data)) { + if (!sp->already_shutdown && + sp->read_cb(exec_ctx, sp->emfd, sp->server->user_data)) { /* There maybe more packets to read. Schedule read_more_cb_ closure to run * after finishing this event loop. */ - GRPC_CLOSURE_SCHED(&sp->do_read_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_read_closure, GRPC_ERROR_NONE); } else { /* Finish reading all the packets, re-arm the notification event so we can * get another chance to read. Or fd already shutdown, re-arm to get a * notification with shutdown error. */ - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); } gpr_mu_unlock(&sp->server->mu); } /* event manager callback when reads are ready */ -static void on_read(void* arg, grpc_error* error) { +static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_udp_listener* sp = (grpc_udp_listener*)arg; gpr_mu_lock(&sp->server->mu); if (error != GRPC_ERROR_NONE) { if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(sp->server); + deactivated_all_ports(exec_ctx, sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -383,57 +389,59 @@ static void on_read(void* arg, grpc_error* error) { /* Read once. If there is more data to read, off load the work to another * thread to finish. */ GPR_ASSERT(sp->read_cb); - if (sp->read_cb(sp->emfd, sp->server->user_data)) { + if (sp->read_cb(exec_ctx, sp->emfd, sp->server->user_data)) { /* There maybe more packets to read. Schedule read_more_cb_ closure to run * after finishing this event loop. */ GRPC_CLOSURE_INIT(&sp->do_read_closure, do_read, arg, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)); - GRPC_CLOSURE_SCHED(&sp->do_read_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_read_closure, GRPC_ERROR_NONE); } else { /* Finish reading all the packets, re-arm the notification event so we can * get another chance to read. Or fd already shutdown, re-arm to get a * notification with shutdown error. */ - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); } gpr_mu_unlock(&sp->server->mu); } // Wrapper of grpc_fd_notify_on_write() with a grpc_closure callback interface. -void fd_notify_on_write_wrapper(void* arg, grpc_error* error) { +void fd_notify_on_write_wrapper(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); gpr_mu_lock(&sp->server->mu); if (!sp->notify_on_write_armed) { - grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); sp->notify_on_write_armed = true; } gpr_mu_unlock(&sp->server->mu); } -static void do_write(void* arg, grpc_error* error) { +static void do_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); gpr_mu_lock(&(sp->server->mu)); if (sp->already_shutdown) { // If fd has been shutdown, don't write any more and re-arm notification. - grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); } else { sp->notify_on_write_armed = false; /* Tell the registered callback that the socket is writeable. */ GPR_ASSERT(sp->write_cb && error == GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&sp->notify_on_write_closure, fd_notify_on_write_wrapper, arg, grpc_schedule_on_exec_ctx); - sp->write_cb(sp->emfd, sp->server->user_data, &sp->notify_on_write_closure); + sp->write_cb(exec_ctx, sp->emfd, sp->server->user_data, + &sp->notify_on_write_closure); } gpr_mu_unlock(&sp->server->mu); } -static void on_write(void* arg, grpc_error* error) { +static void on_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_udp_listener* sp = (grpc_udp_listener*)arg; gpr_mu_lock(&(sp->server->mu)); if (error != GRPC_ERROR_NONE) { if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(sp->server); + deactivated_all_ports(exec_ctx, sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -444,7 +452,7 @@ static void on_write(void* arg, grpc_error* error) { GRPC_CLOSURE_INIT(&sp->do_write_closure, do_write, arg, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)); - GRPC_CLOSURE_SCHED(&sp->do_write_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_write_closure, GRPC_ERROR_NONE); gpr_mu_unlock(&sp->server->mu); } @@ -585,8 +593,9 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index) { return sp->fd; } -void grpc_udp_server_start(grpc_udp_server* s, grpc_pollset** pollsets, - size_t pollset_count, void* user_data) { +void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, + grpc_pollset** pollsets, size_t pollset_count, + void* user_data) { size_t i; gpr_mu_lock(&s->mu); grpc_udp_listener* sp; @@ -597,16 +606,16 @@ void grpc_udp_server_start(grpc_udp_server* s, grpc_pollset** pollsets, sp = s->head; while (sp != nullptr) { for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(pollsets[i], sp->emfd); + grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); } GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); GRPC_CLOSURE_INIT(&sp->write_closure, on_write, sp, grpc_schedule_on_exec_ctx); sp->notify_on_write_armed = true; - grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); /* Registered for both read and write callbacks: increment active_ports * twice to account for this, and delay free-ing of memory until both diff --git a/src/core/lib/iomgr/udp_server.h b/src/core/lib/iomgr/udp_server.h index 02e3acb7f5..1bd6922de6 100644 --- a/src/core/lib/iomgr/udp_server.h +++ b/src/core/lib/iomgr/udp_server.h @@ -32,15 +32,18 @@ typedef struct grpc_udp_server grpc_udp_server; /* Called when data is available to read from the socket. * Return true if there is more data to read from fd. */ -typedef bool (*grpc_udp_server_read_cb)(grpc_fd* emfd, void* user_data); +typedef bool (*grpc_udp_server_read_cb)(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, + void* user_data); /* Called when the socket is writeable. The given closure should be scheduled * when the socket becomes blocked next time. */ -typedef void (*grpc_udp_server_write_cb)(grpc_fd* emfd, void* user_data, +typedef void (*grpc_udp_server_write_cb)(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, + void* user_data, grpc_closure* notify_on_write_closure); /* Called when the grpc_fd is about to be orphaned (and the FD closed). */ -typedef void (*grpc_udp_server_orphan_cb)(grpc_fd* emfd, +typedef void (*grpc_udp_server_orphan_cb)(grpc_exec_ctx* exec_ctx, + grpc_fd* emfd, grpc_closure* shutdown_fd_callback, void* user_data); @@ -48,8 +51,9 @@ typedef void (*grpc_udp_server_orphan_cb)(grpc_fd* emfd, grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args); /* Start listening to bound ports. user_data is passed to callbacks. */ -void grpc_udp_server_start(grpc_udp_server* udp_server, grpc_pollset** pollsets, - size_t pollset_count, void* user_data); +void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* udp_server, + grpc_pollset** pollsets, size_t pollset_count, + void* user_data); int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index); @@ -69,6 +73,7 @@ int grpc_udp_server_add_port(grpc_udp_server* s, grpc_udp_server_write_cb write_cb, grpc_udp_server_orphan_cb orphan_cb); -void grpc_udp_server_destroy(grpc_udp_server* server, grpc_closure* on_done); +void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* server, + grpc_closure* on_done); #endif /* GRPC_CORE_LIB_IOMGR_UDP_SERVER_H */ diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 0371027994..19c6148e43 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -36,7 +36,7 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount( grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_client_security_context* ctx = nullptr; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); @@ -52,10 +52,10 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx, grpc_client_security_context_destroy); } else { - grpc_call_credentials_unref(ctx->creds); + grpc_call_credentials_unref(&exec_ctx, ctx->creds); ctx->creds = grpc_call_credentials_ref(creds); } - + grpc_exec_ctx_finish(&exec_ctx); return GRPC_CALL_OK; } @@ -85,14 +85,15 @@ grpc_client_security_context* grpc_client_security_context_create(void) { } void grpc_client_security_context_destroy(void* ctx) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_client_security_context* c = (grpc_client_security_context*)ctx; - grpc_call_credentials_unref(c->creds); + grpc_call_credentials_unref(&exec_ctx, c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); + grpc_exec_ctx_finish(&exec_ctx); } /* --- grpc_server_security_context --- */ @@ -140,7 +141,7 @@ grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx, } #else grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) { - if (ctx == nullptr) return nullptr; + if (ctx == NULL) return NULL; #endif gpr_ref(&ctx->refcount); return ctx; @@ -158,7 +159,7 @@ void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line, } #else void grpc_auth_context_unref(grpc_auth_context* ctx) { - if (ctx == nullptr) return; + if (ctx == NULL) return; #endif if (gpr_unref(&ctx->refcount)) { size_t i; @@ -302,7 +303,7 @@ void grpc_auth_property_reset(grpc_auth_property* property) { memset(property, 0, sizeof(grpc_auth_property)); } -static void auth_context_pointer_arg_destroy(void* p) { +static void auth_context_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { GRPC_AUTH_CONTEXT_UNREF((grpc_auth_context*)p, "auth_context_pointer_arg"); } diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index e4c1604795..93dd721240 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -39,15 +39,17 @@ typedef struct { grpc_closure internal_on_request_metadata; } grpc_composite_call_credentials_metadata_context; -static void composite_call_destruct(grpc_call_credentials* creds) { +static void composite_call_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; for (size_t i = 0; i < c->inner.num_creds; i++) { - grpc_call_credentials_unref(c->inner.creds_array[i]); + grpc_call_credentials_unref(exec_ctx, c->inner.creds_array[i]); } gpr_free(c->inner.creds_array); } -static void composite_call_metadata_cb(void* arg, grpc_error* error) { +static void composite_call_metadata_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_composite_call_credentials_metadata_context* ctx = (grpc_composite_call_credentials_metadata_context*)arg; if (error == GRPC_ERROR_NONE) { @@ -56,23 +58,23 @@ static void composite_call_metadata_cb(void* arg, grpc_error* error) { grpc_call_credentials* inner_creds = ctx->composite_creds->inner.creds_array[ctx->creds_index++]; if (grpc_call_credentials_get_request_metadata( - inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array, - &ctx->internal_on_request_metadata, &error)) { + exec_ctx, inner_creds, ctx->pollent, ctx->auth_md_context, + ctx->md_array, &ctx->internal_on_request_metadata, &error)) { // Synchronous response, so call ourselves recursively. - composite_call_metadata_cb(arg, error); + composite_call_metadata_cb(exec_ctx, arg, error); GRPC_ERROR_UNREF(error); } return; } // We're done! } - GRPC_CLOSURE_SCHED(ctx->on_request_metadata, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, ctx->on_request_metadata, GRPC_ERROR_REF(error)); gpr_free(ctx); } static bool composite_call_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context auth_md_context, + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context auth_md_context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; @@ -91,8 +93,8 @@ static bool composite_call_get_request_metadata( grpc_call_credentials* inner_creds = ctx->composite_creds->inner.creds_array[ctx->creds_index++]; if (grpc_call_credentials_get_request_metadata( - inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array, - &ctx->internal_on_request_metadata, error)) { + exec_ctx, inner_creds, ctx->pollent, ctx->auth_md_context, + ctx->md_array, &ctx->internal_on_request_metadata, error)) { if (*error != GRPC_ERROR_NONE) break; } else { synchronous = false; // Async return. @@ -104,12 +106,12 @@ static bool composite_call_get_request_metadata( } static void composite_call_cancel_get_request_metadata( - grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; for (size_t i = 0; i < c->inner.num_creds; ++i) { grpc_call_credentials_cancel_get_request_metadata( - c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); + exec_ctx, c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } @@ -198,17 +200,19 @@ grpc_call_credentials* grpc_credentials_contains_type( /* -- Composite channel credentials. -- */ -static void composite_channel_destruct(grpc_channel_credentials* creds) { +static void composite_channel_destruct(grpc_exec_ctx* exec_ctx, + grpc_channel_credentials* creds) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)creds; - grpc_channel_credentials_unref(c->inner_creds); - grpc_call_credentials_unref(c->call_creds); + grpc_channel_credentials_unref(exec_ctx, c->inner_creds); + grpc_call_credentials_unref(exec_ctx, c->call_creds); } static grpc_security_status composite_channel_create_security_connector( - grpc_channel_credentials* creds, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)creds; grpc_security_status status = GRPC_SECURITY_ERROR; @@ -223,11 +227,12 @@ static grpc_security_status composite_channel_create_security_connector( grpc_composite_call_credentials_create(c->call_creds, call_creds, nullptr); status = c->inner_creds->vtable->create_security_connector( - c->inner_creds, composite_call_creds, target, args, sc, new_args); - grpc_call_credentials_unref(composite_call_creds); + exec_ctx, c->inner_creds, composite_call_creds, target, args, sc, + new_args); + grpc_call_credentials_unref(exec_ctx, composite_call_creds); } else { status = c->inner_creds->vtable->create_security_connector( - c->inner_creds, c->call_creds, target, args, sc, new_args); + exec_ctx, c->inner_creds, c->call_creds, target, args, sc, new_args); } return status; } diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 48b459e1be..90576e69b9 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -47,8 +47,8 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( } void grpc_credentials_metadata_request_destroy( - grpc_credentials_metadata_request* r) { - grpc_call_credentials_unref(r->creds); + grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* r) { + grpc_call_credentials_unref(exec_ctx, r->creds); grpc_http_response_destroy(&r->response); gpr_free(r); } @@ -60,11 +60,12 @@ grpc_channel_credentials* grpc_channel_credentials_ref( return creds; } -void grpc_channel_credentials_unref(grpc_channel_credentials* creds) { +void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_channel_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(creds); + creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); } @@ -72,8 +73,9 @@ void grpc_channel_credentials_unref(grpc_channel_credentials* creds) { void grpc_channel_credentials_release(grpc_channel_credentials* creds) { GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx exec_ctx; - grpc_channel_credentials_unref(creds); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { @@ -82,11 +84,12 @@ grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { return creds; } -void grpc_call_credentials_unref(grpc_call_credentials* creds) { +void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(creds); + creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); } @@ -94,42 +97,44 @@ void grpc_call_credentials_unref(grpc_call_credentials* creds) { void grpc_call_credentials_release(grpc_call_credentials* creds) { GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx exec_ctx; - grpc_call_credentials_unref(creds); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_call_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } bool grpc_call_credentials_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, - grpc_closure* on_request_metadata, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context context, + grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, + grpc_error** error) { if (creds == nullptr || creds->vtable->get_request_metadata == nullptr) { return true; } - return creds->vtable->get_request_metadata(creds, pollent, context, md_array, - on_request_metadata, error); + return creds->vtable->get_request_metadata( + exec_ctx, creds, pollent, context, md_array, on_request_metadata, error); } void grpc_call_credentials_cancel_get_request_metadata( - grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { if (creds == nullptr || creds->vtable->cancel_get_request_metadata == nullptr) { return; } - creds->vtable->cancel_get_request_metadata(creds, md_array, error); + creds->vtable->cancel_get_request_metadata(exec_ctx, creds, md_array, error); } grpc_security_status grpc_channel_credentials_create_security_connector( - grpc_channel_credentials* channel_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { *new_args = nullptr; if (channel_creds == nullptr) { return GRPC_SECURITY_ERROR; } GPR_ASSERT(channel_creds->vtable->create_security_connector != nullptr); return channel_creds->vtable->create_security_connector( - channel_creds, nullptr, target, args, sc, new_args); + exec_ctx, channel_creds, nullptr, target, args, sc, new_args); } grpc_channel_credentials* @@ -144,8 +149,8 @@ grpc_channel_credentials_duplicate_without_call_credentials( } } -static void credentials_pointer_arg_destroy(void* p) { - grpc_channel_credentials_unref((grpc_channel_credentials*)p); +static void credentials_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { + grpc_channel_credentials_unref(exec_ctx, (grpc_channel_credentials*)p); } static void* credentials_pointer_arg_copy(void* p) { @@ -195,11 +200,12 @@ grpc_server_credentials* grpc_server_credentials_ref( return creds; } -void grpc_server_credentials_unref(grpc_server_credentials* creds) { +void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_server_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(creds); + creds->vtable->destruct(exec_ctx, creds); } if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { @@ -211,17 +217,19 @@ void grpc_server_credentials_unref(grpc_server_credentials* creds) { void grpc_server_credentials_release(grpc_server_credentials* creds) { GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); - grpc_core::ExecCtx exec_ctx; - grpc_server_credentials_unref(creds); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } grpc_security_status grpc_server_credentials_create_security_connector( - grpc_server_credentials* creds, grpc_server_security_connector** sc) { + grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, + grpc_server_security_connector** sc) { if (creds == nullptr || creds->vtable->create_security_connector == nullptr) { gpr_log(GPR_ERROR, "Server credentials cannot create security context."); return GRPC_SECURITY_ERROR; } - return creds->vtable->create_security_connector(creds, sc); + return creds->vtable->create_security_connector(exec_ctx, creds, sc); } void grpc_server_credentials_set_auth_metadata_processor( @@ -239,8 +247,9 @@ void grpc_server_credentials_set_auth_metadata_processor( creds->processor = processor; } -static void server_credentials_pointer_arg_destroy(void* p) { - grpc_server_credentials_unref((grpc_server_credentials*)p); +static void server_credentials_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, + void* p) { + grpc_server_credentials_unref(exec_ctx, (grpc_server_credentials*)p); } static void* server_credentials_pointer_arg_copy(void* p) { diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index 4825b65720..bc1bd11c77 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -88,12 +88,13 @@ void grpc_override_well_known_credentials_path_getter( #define GRPC_ARG_CHANNEL_CREDENTIALS "grpc.channel_credentials" typedef struct { - void (*destruct)(grpc_channel_credentials* c); + void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c); grpc_security_status (*create_security_connector)( - grpc_channel_credentials* c, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args); + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args); grpc_channel_credentials* (*duplicate_without_call_credentials)( grpc_channel_credentials* c); @@ -107,16 +108,17 @@ struct grpc_channel_credentials { grpc_channel_credentials* grpc_channel_credentials_ref( grpc_channel_credentials* creds); -void grpc_channel_credentials_unref(grpc_channel_credentials* creds); +void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_channel_credentials* creds); /* Creates a security connector for the channel. May also create new channel args for the channel to be used in place of the passed in const args if returned non NULL. In that case the caller is responsible for destroying new_args after channel creation. */ grpc_security_status grpc_channel_credentials_create_security_connector( - grpc_channel_credentials* creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args); + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args); /* Creates a version of the channel credentials without any attached call credentials. This can be used in order to open a channel to a non-trusted @@ -151,19 +153,22 @@ void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list, void grpc_credentials_mdelem_array_append(grpc_credentials_mdelem_array* dst, grpc_credentials_mdelem_array* src); -void grpc_credentials_mdelem_array_destroy(grpc_credentials_mdelem_array* list); +void grpc_credentials_mdelem_array_destroy(grpc_exec_ctx* exec_ctx, + grpc_credentials_mdelem_array* list); /* --- grpc_call_credentials. --- */ typedef struct { - void (*destruct)(grpc_call_credentials* c); - bool (*get_request_metadata)(grpc_call_credentials* c, + void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_call_credentials* c); + bool (*get_request_metadata)(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* c, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error); - void (*cancel_get_request_metadata)(grpc_call_credentials* c, + void (*cancel_get_request_metadata)(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, grpc_error* error); } grpc_call_credentials_vtable; @@ -175,35 +180,39 @@ struct grpc_call_credentials { }; grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds); -void grpc_call_credentials_unref(grpc_call_credentials* creds); +void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds); /// Returns true if completed synchronously, in which case \a error will /// be set to indicate the result. Otherwise, \a on_request_metadata will /// be invoked asynchronously when complete. \a md_array will be populated /// with the resulting metadata once complete. bool grpc_call_credentials_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, - grpc_closure* on_request_metadata, grpc_error** error); + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context context, + grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, + grpc_error** error); /// Cancels a pending asynchronous operation started by /// grpc_call_credentials_get_request_metadata() with the corresponding /// value of \a md_array. void grpc_call_credentials_cancel_get_request_metadata( - grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, - grpc_error* error); + grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, + grpc_credentials_mdelem_array* md_array, grpc_error* error); /* Metadata-only credentials with the specified key and value where asynchronicity can be simulated for testing. */ grpc_call_credentials* grpc_md_only_test_credentials_create( - const char* md_key, const char* md_value, bool is_async); + grpc_exec_ctx* exec_ctx, const char* md_key, const char* md_value, + bool is_async); /* --- grpc_server_credentials. --- */ typedef struct { - void (*destruct)(grpc_server_credentials* c); + void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_server_credentials* c); grpc_security_status (*create_security_connector)( - grpc_server_credentials* c, grpc_server_security_connector** sc); + grpc_exec_ctx* exec_ctx, grpc_server_credentials* c, + grpc_server_security_connector** sc); } grpc_server_credentials_vtable; struct grpc_server_credentials { @@ -214,12 +223,14 @@ struct grpc_server_credentials { }; grpc_security_status grpc_server_credentials_create_security_connector( - grpc_server_credentials* creds, grpc_server_security_connector** sc); + grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, + grpc_server_security_connector** sc); grpc_server_credentials* grpc_server_credentials_ref( grpc_server_credentials* creds); -void grpc_server_credentials_unref(grpc_server_credentials* creds); +void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, + grpc_server_credentials* creds); #define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials" @@ -239,6 +250,6 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( grpc_call_credentials* creds); void grpc_credentials_metadata_request_destroy( - grpc_credentials_metadata_request* r); + grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* r); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc index 9ceaf21139..a3623fa1d6 100644 --- a/src/core/lib/security/credentials/credentials_metadata.cc +++ b/src/core/lib/security/credentials/credentials_metadata.cc @@ -52,9 +52,9 @@ void grpc_credentials_mdelem_array_append(grpc_credentials_mdelem_array* dst, } void grpc_credentials_mdelem_array_destroy( - grpc_credentials_mdelem_array* list) { + grpc_exec_ctx* exec_ctx, grpc_credentials_mdelem_array* list) { for (size_t i = 0; i < list->size; ++i) { - GRPC_MDELEM_UNREF(list->md[i]); + GRPC_MDELEM_UNREF(exec_ctx, list->md[i]); } gpr_free(list->md); } diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index 99b1214951..a535a317ee 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -34,9 +34,10 @@ "grpc.fake_security.expected_targets" static grpc_security_status fake_transport_security_create_security_connector( - grpc_channel_credentials* c, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { *sc = grpc_fake_channel_security_connector_create(c, call_creds, target, args); return GRPC_SECURITY_OK; @@ -44,7 +45,8 @@ static grpc_security_status fake_transport_security_create_security_connector( static grpc_security_status fake_transport_security_server_create_security_connector( - grpc_server_credentials* c, grpc_server_security_connector** sc) { + grpc_exec_ctx* exec_ctx, grpc_server_credentials* c, + grpc_server_security_connector** sc) { *sc = grpc_fake_server_security_connector_create(c); return GRPC_SECURITY_OK; } @@ -96,27 +98,29 @@ const char* grpc_fake_transport_get_expected_targets( /* -- Metadata-only test credentials. -- */ -static void md_only_test_destruct(grpc_call_credentials* creds) { +static void md_only_test_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; - GRPC_MDELEM_UNREF(c->md); + GRPC_MDELEM_UNREF(exec_ctx, c->md); } static bool md_only_test_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, - grpc_closure* on_request_metadata, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context context, + grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, + grpc_error** error) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; grpc_credentials_mdelem_array_add(md_array, c->md); if (c->is_async) { - GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_request_metadata, GRPC_ERROR_NONE); return false; } return true; } static void md_only_test_cancel_get_request_metadata( - grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -125,14 +129,16 @@ static grpc_call_credentials_vtable md_only_test_vtable = { md_only_test_cancel_get_request_metadata}; grpc_call_credentials* grpc_md_only_test_credentials_create( - const char* md_key, const char* md_value, bool is_async) { + grpc_exec_ctx* exec_ctx, const char* md_key, const char* md_value, + bool is_async) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)gpr_zalloc( sizeof(grpc_md_only_test_credentials)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &md_only_test_vtable; gpr_ref_init(&c->base.refcount, 1); - c->md = grpc_mdelem_from_slices(grpc_slice_from_copied_string(md_key), - grpc_slice_from_copied_string(md_value)); + c->md = + grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(md_key), + grpc_slice_from_copied_string(md_value)); c->is_async = is_async; return &c->base; } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 03d52850d9..f586c7b604 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -58,7 +58,8 @@ typedef struct { grpc_http_response response; } compute_engine_detector; -static void on_compute_engine_detection_http_response(void* user_data, +static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { compute_engine_detector* detector = (compute_engine_detector*)user_data; if (error == GRPC_ERROR_NONE && detector->response.status == 200 && @@ -79,16 +80,16 @@ static void on_compute_engine_detection_http_response(void* user_data, detector->is_done = 1; GRPC_LOG_IF_ERROR( "Pollset kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&detector->pollent), - nullptr)); + grpc_pollset_kick( + exec_ctx, grpc_polling_entity_pollset(&detector->pollent), nullptr)); gpr_mu_unlock(g_polling_mu); } -static void destroy_pollset(void* p, grpc_error* e) { - grpc_pollset_destroy((grpc_pollset*)p); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, grpc_error* e) { + grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); } -static int is_stack_running_on_compute_engine() { +static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { compute_engine_detector detector; grpc_httpcli_request request; grpc_httpcli_context context; @@ -114,14 +115,14 @@ static int is_stack_running_on_compute_engine() { grpc_resource_quota* resource_quota = grpc_resource_quota_create("google_default_credentials"); grpc_httpcli_get( - &context, &detector.pollent, resource_quota, &request, - grpc_core::ExecCtx::Get()->Now() + max_detection_delay, + exec_ctx, &context, &detector.pollent, resource_quota, &request, + grpc_exec_ctx_now(exec_ctx) + max_detection_delay, GRPC_CLOSURE_CREATE(on_compute_engine_detection_http_response, &detector, grpc_schedule_on_exec_ctx), &detector.response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ @@ -130,7 +131,8 @@ static int is_stack_running_on_compute_engine() { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(grpc_polling_entity_pollset(&detector.pollent), + grpc_pollset_work(exec_ctx, + grpc_polling_entity_pollset(&detector.pollent), &worker, GRPC_MILLIS_INF_FUTURE))) { detector.is_done = 1; detector.success = 0; @@ -138,14 +140,15 @@ static int is_stack_running_on_compute_engine() { } gpr_mu_unlock(g_polling_mu); - grpc_httpcli_context_destroy(&context); + grpc_httpcli_context_destroy(exec_ctx, &context); GRPC_CLOSURE_INIT(&destroy_closure, destroy_pollset, grpc_polling_entity_pollset(&detector.pollent), grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&detector.pollent), + grpc_pollset_shutdown(exec_ctx, + grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); g_polling_mu = nullptr; - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); grpc_http_response_destroy(&detector.response); @@ -155,7 +158,7 @@ static int is_stack_running_on_compute_engine() { /* Takes ownership of creds_path if not NULL. */ static grpc_error* create_default_creds_from_path( - char* creds_path, grpc_call_credentials** creds) { + grpc_exec_ctx* exec_ctx, char* creds_path, grpc_call_credentials** creds) { grpc_json* json = nullptr; grpc_auth_json_key key; grpc_auth_refresh_token token; @@ -184,7 +187,7 @@ static grpc_error* create_default_creds_from_path( if (grpc_auth_json_key_is_valid(&key)) { result = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - key, grpc_max_auth_token_lifetime()); + exec_ctx, key, grpc_max_auth_token_lifetime()); if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_service_account_jwt_access_credentials_create_from_auth_json_" @@ -209,7 +212,7 @@ static grpc_error* create_default_creds_from_path( end: GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1); if (creds_path != nullptr) gpr_free(creds_path); - grpc_slice_unref_internal(creds_data); + grpc_slice_unref_internal(exec_ctx, creds_data); if (json != nullptr) grpc_json_destroy(json); *creds = result; return error; @@ -221,7 +224,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ()); @@ -236,20 +239,22 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { /* First, try the environment variable. */ err = create_default_creds_from_path( - gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds); + &exec_ctx, gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds); if (err == GRPC_ERROR_NONE) goto end; error = grpc_error_add_child(error, err); /* Then the well-known file. */ err = create_default_creds_from_path( - grpc_get_well_known_google_credentials_file_path(), &call_creds); + &exec_ctx, grpc_get_well_known_google_credentials_file_path(), + &call_creds); if (err == GRPC_ERROR_NONE) goto end; error = grpc_error_add_child(error, err); /* At last try to see if we're on compute engine (do the detection only once since it requires a network test). */ if (!compute_engine_detection_done) { - int need_compute_engine_creds = is_stack_running_on_compute_engine(); + int need_compute_engine_creds = + is_stack_running_on_compute_engine(&exec_ctx); compute_engine_detection_done = 1; if (need_compute_engine_creds) { call_creds = grpc_google_compute_engine_credentials_create(nullptr); @@ -273,8 +278,8 @@ end: grpc_composite_channel_credentials_create(ssl_creds, call_creds, nullptr)); GPR_ASSERT(default_credentials != nullptr); - grpc_channel_credentials_unref(ssl_creds); - grpc_call_credentials_unref(call_creds); + grpc_channel_credentials_unref(&exec_ctx, ssl_creds); + grpc_call_credentials_unref(&exec_ctx, call_creds); result = default_credentials; } else { gpr_log(GPR_ERROR, "Could not create google default credentials."); @@ -286,20 +291,21 @@ end: } else { GRPC_ERROR_UNREF(error); } - + grpc_exec_ctx_finish(&exec_ctx); return result; } void grpc_flush_cached_google_default_credentials(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); if (default_credentials != nullptr) { - grpc_channel_credentials_unref(default_credentials); + grpc_channel_credentials_unref(&exec_ctx, default_credentials); default_credentials = nullptr; } compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); + grpc_exec_ctx_finish(&exec_ctx); } /* -- Well known credentials path. -- */ diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 75acb2a58e..1741bf3068 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -27,12 +27,14 @@ #include #include -static void iam_destruct(grpc_call_credentials* creds) { +static void iam_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds; - grpc_credentials_mdelem_array_destroy(&c->md_array); + grpc_credentials_mdelem_array_destroy(exec_ctx, &c->md_array); } -static bool iam_get_request_metadata(grpc_call_credentials* creds, +static bool iam_get_request_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -44,8 +46,8 @@ static bool iam_get_request_metadata(grpc_call_credentials* creds, } static void iam_cancel_get_request_metadata( - grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -54,7 +56,7 @@ static grpc_call_credentials_vtable iam_vtable = { grpc_call_credentials* grpc_google_iam_credentials_create( const char* token, const char* authority_selector, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", @@ -68,15 +70,17 @@ grpc_call_credentials* grpc_google_iam_credentials_create( c->base.vtable = &iam_vtable; gpr_ref_init(&c->base.refcount, 1); grpc_mdelem md = grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY), grpc_slice_from_copied_string(token)); grpc_credentials_mdelem_array_add(&c->md_array, md); - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(&exec_ctx, md); md = grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY), grpc_slice_from_copied_string(authority_selector)); grpc_credentials_mdelem_array_add(&c->md_array, md); - GRPC_MDELEM_UNREF(md); - + GRPC_MDELEM_UNREF(&exec_ctx, md); + grpc_exec_ctx_finish(&exec_ctx); return &c->base; } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 2404e860e4..77163c0cc1 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -30,8 +30,9 @@ #include #include -static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) { - GRPC_MDELEM_UNREF(c->cached.jwt_md); +static void jwt_reset_cache(grpc_exec_ctx* exec_ctx, + grpc_service_account_jwt_access_credentials* c) { + GRPC_MDELEM_UNREF(exec_ctx, c->cached.jwt_md); c->cached.jwt_md = GRPC_MDNULL; if (c->cached.service_url != nullptr) { gpr_free(c->cached.service_url); @@ -40,15 +41,17 @@ static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) { c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); } -static void jwt_destruct(grpc_call_credentials* creds) { +static void jwt_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_service_account_jwt_access_credentials* c = (grpc_service_account_jwt_access_credentials*)creds; grpc_auth_json_key_destruct(&c->key); - jwt_reset_cache(c); + jwt_reset_cache(exec_ctx, c); gpr_mu_destroy(&c->cache_mu); } -static bool jwt_get_request_metadata(grpc_call_credentials* creds, +static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -78,7 +81,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds, char* jwt = nullptr; /* Generate a new jwt. */ gpr_mu_lock(&c->cache_mu); - jwt_reset_cache(c); + jwt_reset_cache(exec_ctx, c); jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url, c->jwt_lifetime, nullptr); if (jwt != nullptr) { @@ -89,6 +92,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c->jwt_lifetime); c->cached.service_url = gpr_strdup(context.service_url); c->cached.jwt_md = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(md_value)); gpr_free(md_value); @@ -99,7 +103,7 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds, if (!GRPC_MDISNULL(jwt_md)) { grpc_credentials_mdelem_array_add(md_array, jwt_md); - GRPC_MDELEM_UNREF(jwt_md); + GRPC_MDELEM_UNREF(exec_ctx, jwt_md); } else { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Could not generate JWT."); } @@ -107,8 +111,8 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds, } static void jwt_cancel_get_request_metadata( - grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -117,7 +121,8 @@ static grpc_call_credentials_vtable jwt_vtable = { grpc_call_credentials* grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - grpc_auth_json_key key, gpr_timespec token_lifetime) { + grpc_exec_ctx* exec_ctx, grpc_auth_json_key key, + gpr_timespec token_lifetime) { grpc_service_account_jwt_access_credentials* c; if (!grpc_auth_json_key_is_valid(&key)) { gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); @@ -138,7 +143,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( } c->jwt_lifetime = token_lifetime; gpr_mu_init(&c->cache_mu); - jwt_reset_cache(c); + jwt_reset_cache(exec_ctx, c); return &c->base; } @@ -181,10 +186,11 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( gpr_free(clean_json); } GPR_ASSERT(reserved == nullptr); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - grpc_auth_json_key_create_from_string(json_key), token_lifetime); - + &exec_ctx, grpc_auth_json_key_create_from_string(json_key), + token_lifetime); + grpc_exec_ctx_finish(&exec_ctx); return creds; } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.h b/src/core/lib/security/credentials/jwt/jwt_credentials.h index f58a8b67ba..85f068aac8 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.h +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.h @@ -42,6 +42,7 @@ typedef struct { // Takes ownership of the key. grpc_call_credentials* grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - grpc_auth_json_key key, gpr_timespec token_lifetime); + grpc_exec_ctx* exec_ctx, grpc_auth_json_key key, + gpr_timespec token_lifetime); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 39339f07d7..3709b83c4e 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -74,11 +74,12 @@ static const EVP_MD* evp_md_from_alg(const char* alg) { } } -static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, +static grpc_json* parse_json_part_from_jwt(grpc_exec_ctx* exec_ctx, + const char* str, size_t len, grpc_slice* buffer) { grpc_json* json; - *buffer = grpc_base64_decode_with_len(str, len, 1); + *buffer = grpc_base64_decode_with_len(exec_ctx, str, len, 1); if (GRPC_SLICE_IS_EMPTY(*buffer)) { gpr_log(GPR_ERROR, "Invalid base64."); return nullptr; @@ -86,7 +87,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer), GRPC_SLICE_LENGTH(*buffer)); if (json == nullptr) { - grpc_slice_unref_internal(*buffer); + grpc_slice_unref_internal(exec_ctx, *buffer); gpr_log(GPR_ERROR, "JSON parsing error."); } return json; @@ -122,13 +123,14 @@ typedef struct { grpc_slice buffer; } jose_header; -static void jose_header_destroy(jose_header* h) { - grpc_slice_unref_internal(h->buffer); +static void jose_header_destroy(grpc_exec_ctx* exec_ctx, jose_header* h) { + grpc_slice_unref_internal(exec_ctx, h->buffer); gpr_free(h); } /* Takes ownership of json and buffer. */ -static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) { +static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, + grpc_json* json, grpc_slice buffer) { grpc_json* cur; jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header)); h->buffer = buffer; @@ -162,7 +164,7 @@ static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) { error: grpc_json_destroy(json); - jose_header_destroy(h); + jose_header_destroy(exec_ctx, h); return nullptr; } @@ -182,9 +184,9 @@ struct grpc_jwt_claims { grpc_slice buffer; }; -void grpc_jwt_claims_destroy(grpc_jwt_claims* claims) { +void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims) { grpc_json_destroy(claims->json); - grpc_slice_unref_internal(claims->buffer); + grpc_slice_unref_internal(exec_ctx, claims->buffer); gpr_free(claims); } @@ -229,7 +231,8 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) { } /* Takes ownership of json and buffer even in case of failure. */ -grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) { +grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, + grpc_json* json, grpc_slice buffer) { grpc_json* cur; grpc_jwt_claims* claims = (grpc_jwt_claims*)gpr_malloc(sizeof(grpc_jwt_claims)); @@ -271,7 +274,7 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) { return claims; error: - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(exec_ctx, claims); return nullptr; } @@ -347,7 +350,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( grpc_jwt_claims* claims, const char* audience, grpc_slice signature, const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx)); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); @@ -358,16 +361,16 @@ static verifier_cb_ctx* verifier_cb_ctx_create( ctx->signed_data = grpc_slice_from_copied_buffer(signed_jwt, signed_jwt_len); ctx->user_data = user_data; ctx->user_cb = cb; - + grpc_exec_ctx_finish(&exec_ctx); return ctx; } -void verifier_cb_ctx_destroy(verifier_cb_ctx* ctx) { +void verifier_cb_ctx_destroy(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { if (ctx->audience != nullptr) gpr_free(ctx->audience); - if (ctx->claims != nullptr) grpc_jwt_claims_destroy(ctx->claims); - grpc_slice_unref_internal(ctx->signature); - grpc_slice_unref_internal(ctx->signed_data); - jose_header_destroy(ctx->header); + if (ctx->claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); + grpc_slice_unref_internal(exec_ctx, ctx->signature); + grpc_slice_unref_internal(exec_ctx, ctx->signed_data); + jose_header_destroy(exec_ctx, ctx->header); for (size_t i = 0; i < HTTP_RESPONSE_COUNT; i++) { grpc_http_response_destroy(&ctx->responses[i]); } @@ -447,19 +450,19 @@ end: return result; } -static BIGNUM* bignum_from_base64(const char* b64) { +static BIGNUM* bignum_from_base64(grpc_exec_ctx* exec_ctx, const char* b64) { BIGNUM* result = nullptr; grpc_slice bin; if (b64 == nullptr) return nullptr; - bin = grpc_base64_decode(b64, 1); + bin = grpc_base64_decode(exec_ctx, b64, 1); if (GRPC_SLICE_IS_EMPTY(bin)) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); return nullptr; } result = BN_bin2bn(GRPC_SLICE_START_PTR(bin), TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), nullptr); - grpc_slice_unref_internal(bin); + grpc_slice_unref_internal(exec_ctx, bin); return result; } @@ -492,7 +495,8 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { } #endif // OPENSSL_VERSION_NUMBER < 0x10100000L -static EVP_PKEY* pkey_from_jwk(const grpc_json* json, const char* kty) { +static EVP_PKEY* pkey_from_jwk(grpc_exec_ctx* exec_ctx, const grpc_json* json, + const char* kty) { const grpc_json* key_prop; RSA* rsa = nullptr; EVP_PKEY* result = nullptr; @@ -511,10 +515,12 @@ static EVP_PKEY* pkey_from_jwk(const grpc_json* json, const char* kty) { } for (key_prop = json->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "n") == 0) { - tmp_n = bignum_from_base64(validate_string_field(key_prop, "n")); + tmp_n = + bignum_from_base64(exec_ctx, validate_string_field(key_prop, "n")); if (tmp_n == nullptr) goto end; } else if (strcmp(key_prop->key, "e") == 0) { - tmp_e = bignum_from_base64(validate_string_field(key_prop, "e")); + tmp_e = + bignum_from_base64(exec_ctx, validate_string_field(key_prop, "e")); if (tmp_e == nullptr) goto end; } } @@ -539,7 +545,8 @@ end: return result; } -static EVP_PKEY* find_verification_key(const grpc_json* json, +static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, + const grpc_json* json, const char* header_alg, const char* header_kid) { const grpc_json* jkey; @@ -584,7 +591,7 @@ static EVP_PKEY* find_verification_key(const grpc_json* json, } if (alg != nullptr && kid != nullptr && kty != nullptr && strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) { - return pkey_from_jwk(jkey, kty); + return pkey_from_jwk(exec_ctx, jkey, kty); } } gpr_log(GPR_ERROR, @@ -625,7 +632,8 @@ end: return result; } -static void on_keys_retrieved(void* user_data, grpc_error* error) { +static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]); EVP_PKEY* verification_key = nullptr; @@ -637,7 +645,7 @@ static void on_keys_retrieved(void* user_data, grpc_error* error) { goto end; } verification_key = - find_verification_key(json, ctx->header->alg, ctx->header->kid); + find_verification_key(exec_ctx, json, ctx->header->alg, ctx->header->kid); if (verification_key == nullptr) { gpr_log(GPR_ERROR, "Could not find verification key with kid %s.", ctx->header->kid); @@ -661,11 +669,12 @@ static void on_keys_retrieved(void* user_data, grpc_error* error) { end: if (json != nullptr) grpc_json_destroy(json); EVP_PKEY_free(verification_key); - ctx->user_cb(ctx->user_data, status, claims); - verifier_cb_ctx_destroy(ctx); + ctx->user_cb(exec_ctx, ctx->user_data, status, claims); + verifier_cb_ctx_destroy(exec_ctx, ctx); } -static void on_openid_config_retrieved(void* user_data, grpc_error* error) { +static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { const grpc_json* cur; verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; const grpc_http_response* response = &ctx->responses[HTTP_RESPONSE_OPENID]; @@ -702,19 +711,20 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) { extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); grpc_httpcli_get( - &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, + exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, + grpc_exec_ctx_now(exec_ctx) + grpc_jwt_verifier_max_delay, GRPC_CLOSURE_CREATE(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx), &ctx->responses[HTTP_RESPONSE_KEYS]); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); grpc_json_destroy(json); gpr_free(req.host); return; error: if (json != nullptr) grpc_json_destroy(json); - ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr); - verifier_cb_ctx_destroy(ctx); + ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, + nullptr); + verifier_cb_ctx_destroy(exec_ctx, ctx); } static email_key_mapping* verifier_get_mapping(grpc_jwt_verifier* v, @@ -762,7 +772,8 @@ const char* grpc_jwt_issuer_email_domain(const char* issuer) { } /* Takes ownership of ctx. */ -static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { +static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, + verifier_cb_ctx* ctx) { const char* email_domain; grpc_closure* http_cb; char* path_prefix = nullptr; @@ -829,21 +840,23 @@ static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { channel. This would allow us to cancel an authentication query when under extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); - grpc_httpcli_get( - &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, http_cb, - &ctx->responses[rsp_idx]); - grpc_resource_quota_unref_internal(resource_quota); + grpc_httpcli_get(exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, + resource_quota, &req, + grpc_exec_ctx_now(exec_ctx) + grpc_jwt_verifier_max_delay, + http_cb, &ctx->responses[rsp_idx]); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); gpr_free(req.host); gpr_free(req.http.path); return; error: - ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr); - verifier_cb_ctx_destroy(ctx); + ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, + nullptr); + verifier_cb_ctx_destroy(exec_ctx, ctx); } -void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, +void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, + grpc_jwt_verifier* verifier, grpc_pollset* pollset, const char* jwt, const char* audience, grpc_jwt_verification_done_cb cb, @@ -862,32 +875,35 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, cb != nullptr); dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer); + json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), + &header_buffer); if (json == nullptr) goto error; - header = jose_header_from_json(json, header_buffer); + header = jose_header_from_json(exec_ctx, json, header_buffer); if (header == nullptr) goto error; cur = dot + 1; dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer); + json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), + &claims_buffer); if (json == nullptr) goto error; - claims = grpc_jwt_claims_from_json(json, claims_buffer); + claims = grpc_jwt_claims_from_json(exec_ctx, json, claims_buffer); if (claims == nullptr) goto error; signed_jwt_len = (size_t)(dot - jwt); cur = dot + 1; - signature = grpc_base64_decode(cur, 1); + signature = grpc_base64_decode(exec_ctx, cur, 1); if (GRPC_SLICE_IS_EMPTY(signature)) goto error; retrieve_key_and_verify( + exec_ctx, verifier_cb_ctx_create(verifier, pollset, header, claims, audience, signature, jwt, signed_jwt_len, user_data, cb)); return; error: - if (header != nullptr) jose_header_destroy(header); - if (claims != nullptr) grpc_jwt_claims_destroy(claims); - cb(user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); + if (header != nullptr) jose_header_destroy(exec_ctx, header); + if (claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, claims); + cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); } grpc_jwt_verifier* grpc_jwt_verifier_create( @@ -914,10 +930,10 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( return v; } -void grpc_jwt_verifier_destroy(grpc_jwt_verifier* v) { +void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_verifier* v) { size_t i; if (v == nullptr) return; - grpc_httpcli_context_destroy(&v->http_ctx); + grpc_httpcli_context_destroy(exec_ctx, &v->http_ctx); if (v->mappings != nullptr) { for (i = 0; i < v->num_mappings; i++) { gpr_free(v->mappings[i].email_domain); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.h b/src/core/lib/security/credentials/jwt/jwt_verifier.h index b3805e75cd..2aacd497c7 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.h +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.h @@ -51,7 +51,7 @@ const char* grpc_jwt_verifier_status_to_string(grpc_jwt_verifier_status status); typedef struct grpc_jwt_claims grpc_jwt_claims; -void grpc_jwt_claims_destroy(grpc_jwt_claims* claims); +void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims); /* Returns the whole JSON tree of the claims. */ const grpc_json* grpc_jwt_claims_json(const grpc_jwt_claims* claims); @@ -94,18 +94,21 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( size_t num_mappings); /*The verifier must not be destroyed if there are still outstanding callbacks.*/ -void grpc_jwt_verifier_destroy(grpc_jwt_verifier* verifier); +void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, + grpc_jwt_verifier* verifier); /* User provided callback that will be called when the verification of the JWT is done (maybe in another thread). It is the responsibility of the callee to call grpc_jwt_claims_destroy on the claims. */ -typedef void (*grpc_jwt_verification_done_cb)(void* user_data, +typedef void (*grpc_jwt_verification_done_cb)(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims); /* Verifies for the JWT for the given expected audience. */ -void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, +void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, + grpc_jwt_verifier* verifier, grpc_pollset* pollset, const char* jwt, const char* audience, grpc_jwt_verification_done_cb cb, @@ -113,7 +116,8 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, /* --- TESTING ONLY exposed functions. --- */ -grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer); +grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, + grpc_json* json, grpc_slice buffer); grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, const char* audience); const char* grpc_jwt_issuer_email_domain(const char* issuer); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index e243ea52c6..ccefb4db9c 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -103,19 +103,21 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { // Oauth2 Token Fetcher credentials. // -static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) { +static void oauth2_token_fetcher_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; - GRPC_MDELEM_UNREF(c->access_token_md); + GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md); gpr_mu_destroy(&c->mu); - grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent)); - grpc_httpcli_context_destroy(&c->httpcli_context); + grpc_pollset_set_destroy(exec_ctx, + grpc_polling_entity_pollset_set(&c->pollent)); + grpc_httpcli_context_destroy(exec_ctx, &c->httpcli_context); } grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - const grpc_http_response* response, grpc_mdelem* token_md, - grpc_millis* token_lifetime) { + grpc_exec_ctx* exec_ctx, const grpc_http_response* response, + grpc_mdelem* token_md, grpc_millis* token_lifetime) { char* null_terminated_body = nullptr; char* new_access_token = nullptr; grpc_credentials_status status = GRPC_CREDENTIALS_OK; @@ -182,8 +184,9 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( gpr_asprintf(&new_access_token, "%s %s", token_type->value, access_token->value); *token_lifetime = strtol(expires_in->value, nullptr, 10) * GPR_MS_PER_SEC; - if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(*token_md); + if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(new_access_token)); status = GRPC_CREDENTIALS_OK; @@ -191,7 +194,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( end: if (status != GRPC_CREDENTIALS_OK && !GRPC_MDISNULL(*token_md)) { - GRPC_MDELEM_UNREF(*token_md); + GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = GRPC_MDNULL; } if (null_terminated_body != nullptr) gpr_free(null_terminated_body); @@ -200,7 +203,8 @@ end: return status; } -static void on_oauth2_token_fetcher_http_response(void* user_data, +static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error)); grpc_credentials_metadata_request* r = @@ -211,13 +215,13 @@ static void on_oauth2_token_fetcher_http_response(void* user_data, grpc_millis token_lifetime; grpc_credentials_status status = grpc_oauth2_token_fetcher_credentials_parse_server_response( - &r->response, &access_token_md, &token_lifetime); + exec_ctx, &r->response, &access_token_md, &token_lifetime); // Update cache and grab list of pending requests. gpr_mu_lock(&c->mu); c->token_fetch_pending = false; c->access_token_md = GRPC_MDELEM_REF(access_token_md); c->token_expiration = status == GRPC_CREDENTIALS_OK - ? grpc_core::ExecCtx::Get()->Now() + token_lifetime + ? grpc_exec_ctx_now(exec_ctx) + token_lifetime : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; @@ -232,22 +236,24 @@ static void on_oauth2_token_fetcher_http_response(void* user_data, error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Error occured when fetching oauth2 token.", &error, 1); } - GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, error); + GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, error); grpc_polling_entity_del_from_pollset_set( - pending_request->pollent, grpc_polling_entity_pollset_set(&c->pollent)); + exec_ctx, pending_request->pollent, + grpc_polling_entity_pollset_set(&c->pollent)); grpc_oauth2_pending_get_request_metadata* prev = pending_request; pending_request = pending_request->next; gpr_free(prev); } - GRPC_MDELEM_UNREF(access_token_md); - grpc_call_credentials_unref(r->creds); - grpc_credentials_metadata_request_destroy(r); + GRPC_MDELEM_UNREF(exec_ctx, access_token_md); + grpc_call_credentials_unref(exec_ctx, r->creds); + grpc_credentials_metadata_request_destroy(exec_ctx, r); } static bool oauth2_token_fetcher_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, - grpc_closure* on_request_metadata, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context context, + grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, + grpc_error** error) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; // Check if we can use the cached token. @@ -256,14 +262,13 @@ static bool oauth2_token_fetcher_get_request_metadata( grpc_mdelem cached_access_token_md = GRPC_MDNULL; gpr_mu_lock(&c->mu); if (!GRPC_MDISNULL(c->access_token_md) && - (c->token_expiration - grpc_core::ExecCtx::Get()->Now() > - refresh_threshold)) { + (c->token_expiration - grpc_exec_ctx_now(exec_ctx) > refresh_threshold)) { cached_access_token_md = GRPC_MDELEM_REF(c->access_token_md); } if (!GRPC_MDISNULL(cached_access_token_md)) { gpr_mu_unlock(&c->mu); grpc_credentials_mdelem_array_add(md_array, cached_access_token_md); - GRPC_MDELEM_UNREF(cached_access_token_md); + GRPC_MDELEM_UNREF(exec_ctx, cached_access_token_md); return true; } // Couldn't get the token from the cache. @@ -275,7 +280,7 @@ static bool oauth2_token_fetcher_get_request_metadata( pending_request->on_request_metadata = on_request_metadata; pending_request->pollent = pollent; grpc_polling_entity_add_to_pollset_set( - pollent, grpc_polling_entity_pollset_set(&c->pollent)); + exec_ctx, pollent, grpc_polling_entity_pollset_set(&c->pollent)); pending_request->next = c->pending_requests; c->pending_requests = pending_request; bool start_fetch = false; @@ -286,17 +291,17 @@ static bool oauth2_token_fetcher_get_request_metadata( gpr_mu_unlock(&c->mu); if (start_fetch) { grpc_call_credentials_ref(creds); - c->fetch_func(grpc_credentials_metadata_request_create(creds), + c->fetch_func(exec_ctx, grpc_credentials_metadata_request_create(creds), &c->httpcli_context, &c->pollent, on_oauth2_token_fetcher_http_response, - grpc_core::ExecCtx::Get()->Now() + refresh_threshold); + grpc_exec_ctx_now(exec_ctx) + refresh_threshold); } return false; } static void oauth2_token_fetcher_cancel_get_request_metadata( - grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; gpr_mu_lock(&c->mu); @@ -312,7 +317,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata( c->pending_requests = pending_request->next; } // Invoke the callback immediately with an error. - GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, + GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, GRPC_ERROR_REF(error)); gpr_free(pending_request); break; @@ -346,7 +351,7 @@ static grpc_call_credentials_vtable compute_engine_vtable = { oauth2_token_fetcher_cancel_get_request_metadata}; static void compute_engine_fetch_oauth2( - grpc_credentials_metadata_request* metadata_req, + grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req, grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_http_header header = {(char*)"Metadata-Flavor", (char*)"Google"}; @@ -362,10 +367,10 @@ static void compute_engine_fetch_oauth2( grpc_resource_quota* resource_quota = grpc_resource_quota_create("oauth2_credentials"); grpc_httpcli_get( - httpcli_context, pollent, resource_quota, &request, deadline, + exec_ctx, httpcli_context, pollent, resource_quota, &request, deadline, GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx), &metadata_req->response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); } grpc_call_credentials* grpc_google_compute_engine_credentials_create( @@ -385,11 +390,12 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( // Google Refresh Token credentials. // -static void refresh_token_destruct(grpc_call_credentials* creds) { +static void refresh_token_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_google_refresh_token_credentials* c = (grpc_google_refresh_token_credentials*)creds; grpc_auth_refresh_token_destruct(&c->refresh_token); - oauth2_token_fetcher_destruct(&c->base.base); + oauth2_token_fetcher_destruct(exec_ctx, &c->base.base); } static grpc_call_credentials_vtable refresh_token_vtable = { @@ -397,7 +403,7 @@ static grpc_call_credentials_vtable refresh_token_vtable = { oauth2_token_fetcher_cancel_get_request_metadata}; static void refresh_token_fetch_oauth2( - grpc_credentials_metadata_request* metadata_req, + grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req, grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_google_refresh_token_credentials* c = @@ -421,11 +427,11 @@ static void refresh_token_fetch_oauth2( grpc_resource_quota* resource_quota = grpc_resource_quota_create("oauth2_credentials_refresh"); grpc_httpcli_post( - httpcli_context, pollent, resource_quota, &request, body, strlen(body), - deadline, + exec_ctx, httpcli_context, pollent, resource_quota, &request, body, + strlen(body), deadline, GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx), &metadata_req->response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); gpr_free(body); } @@ -477,23 +483,25 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( // Oauth2 Access Token credentials. // -static void access_token_destruct(grpc_call_credentials* creds) { +static void access_token_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; - GRPC_MDELEM_UNREF(c->access_token_md); + GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md); } static bool access_token_get_request_metadata( - grpc_call_credentials* creds, grpc_polling_entity* pollent, - grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, - grpc_closure* on_request_metadata, grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_polling_entity* pollent, grpc_auth_metadata_context context, + grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, + grpc_error** error) { grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; grpc_credentials_mdelem_array_add(md_array, c->access_token_md); return true; } static void access_token_cancel_get_request_metadata( - grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -515,11 +523,11 @@ grpc_call_credentials* grpc_access_token_credentials_create( gpr_ref_init(&c->base.refcount, 1); char* token_md_value; gpr_asprintf(&token_md_value, "Bearer %s", access_token); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; c->access_token_md = grpc_mdelem_from_slices( - grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), + &exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(token_md_value)); - + grpc_exec_ctx_finish(&exec_ctx); gpr_free(token_md_value); return &c->base; } diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index e5b8df8eb9..627783d648 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -52,7 +52,8 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token); // This object is a base for credentials that need to acquire an oauth2 token // from an http service. -typedef void (*grpc_fetch_oauth2_func)(grpc_credentials_metadata_request* req, +typedef void (*grpc_fetch_oauth2_func)(grpc_exec_ctx* exec_ctx, + grpc_credentials_metadata_request* req, grpc_httpcli_context* http_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, @@ -98,7 +99,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( // Exposed for testing only. grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - const struct grpc_http_response* response, grpc_mdelem* token_md, - grpc_millis* token_lifetime); + grpc_exec_ctx* exec_ctx, const struct grpc_http_response* response, + grpc_mdelem* token_md, grpc_millis* token_lifetime); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_OAUTH2_OAUTH2_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 203ba58c67..1f1efd078d 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -33,7 +33,8 @@ grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials"); -static void plugin_destruct(grpc_call_credentials* creds) { +static void plugin_destruct(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_destroy(&c->mu); if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { @@ -60,17 +61,18 @@ static void pending_request_remove_locked( // When this returns, r->cancelled indicates whether the request was // cancelled before completion. static void pending_request_complete( - grpc_plugin_credentials_pending_request* r) { + grpc_exec_ctx* exec_ctx, grpc_plugin_credentials_pending_request* r) { gpr_mu_lock(&r->creds->mu); if (!r->cancelled) pending_request_remove_locked(r->creds, r); gpr_mu_unlock(&r->creds->mu); // Ref to credentials not needed anymore. - grpc_call_credentials_unref(&r->creds->base); + grpc_call_credentials_unref(exec_ctx, &r->creds->base); } static grpc_error* process_plugin_result( - grpc_plugin_credentials_pending_request* r, const grpc_metadata* md, - size_t num_md, grpc_status_code status, const char* error_details) { + grpc_exec_ctx* exec_ctx, grpc_plugin_credentials_pending_request* r, + const grpc_metadata* md, size_t num_md, grpc_status_code status, + const char* error_details) { grpc_error* error = GRPC_ERROR_NONE; if (status != GRPC_STATUS_OK) { char* msg; @@ -98,11 +100,11 @@ static grpc_error* process_plugin_result( error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal metadata"); } else { for (size_t i = 0; i < num_md; ++i) { - grpc_mdelem mdelem = - grpc_mdelem_from_slices(grpc_slice_ref_internal(md[i].key), - grpc_slice_ref_internal(md[i].value)); + grpc_mdelem mdelem = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md[i].key), + grpc_slice_ref_internal(md[i].value)); grpc_credentials_mdelem_array_add(r->md_array, mdelem); - GRPC_MDELEM_UNREF(mdelem); + GRPC_MDELEM_UNREF(exec_ctx, mdelem); } } } @@ -115,8 +117,9 @@ static void plugin_md_request_metadata_ready(void* request, grpc_status_code status, const char* error_details) { /* called from application code */ - grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | - GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( + GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, + nullptr, nullptr); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (grpc_plugin_credentials_trace.enabled()) { @@ -126,12 +129,12 @@ static void plugin_md_request_metadata_ready(void* request, r->creds, r); } // Remove request from pending list if not previously cancelled. - pending_request_complete(r); + pending_request_complete(&exec_ctx, r); // If it has not been cancelled, process it. if (!r->cancelled) { grpc_error* error = - process_plugin_result(r, md, num_md, status, error_details); - GRPC_CLOSURE_SCHED(r->on_request_metadata, error); + process_plugin_result(&exec_ctx, r, md, num_md, status, error_details); + GRPC_CLOSURE_SCHED(&exec_ctx, r->on_request_metadata, error); } else if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin was previously " @@ -139,9 +142,11 @@ static void plugin_md_request_metadata_ready(void* request, r->creds, r); } gpr_free(r); + grpc_exec_ctx_finish(&exec_ctx); } -static bool plugin_get_request_metadata(grpc_call_credentials* creds, +static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -189,7 +194,7 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, } // Returned synchronously. // Remove request from pending list if not previously cancelled. - pending_request_complete(pending_request); + pending_request_complete(exec_ctx, pending_request); // If the request was cancelled, the error will have been returned // asynchronously by plugin_cancel_get_request_metadata(), so return // false. Otherwise, process the result. @@ -208,13 +213,13 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, "synchronously", c, pending_request); } - *error = process_plugin_result(pending_request, creds_md, num_creds_md, - status, error_details); + *error = process_plugin_result(exec_ctx, pending_request, creds_md, + num_creds_md, status, error_details); } // Clean up. for (size_t i = 0; i < num_creds_md; ++i) { - grpc_slice_unref_internal(creds_md[i].key); - grpc_slice_unref_internal(creds_md[i].value); + grpc_slice_unref_internal(exec_ctx, creds_md[i].key); + grpc_slice_unref_internal(exec_ctx, creds_md[i].value); } gpr_free((void*)error_details); gpr_free(pending_request); @@ -223,8 +228,8 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds, } static void plugin_cancel_get_request_metadata( - grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, + grpc_credentials_mdelem_array* md_array, grpc_error* error) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = @@ -236,7 +241,7 @@ static void plugin_cancel_get_request_metadata( pending_request); } pending_request->cancelled = true; - GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, + GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, GRPC_ERROR_REF(error)); pending_request_remove_locked(c, pending_request); break; diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index d8546441c9..39dd38cf88 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -41,16 +41,18 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, gpr_free(kp); } -static void ssl_destruct(grpc_channel_credentials* creds) { +static void ssl_destruct(grpc_exec_ctx* exec_ctx, + grpc_channel_credentials* creds) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; gpr_free(c->config.pem_root_certs); grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1); } static grpc_security_status ssl_create_security_connector( - grpc_channel_credentials* creds, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; grpc_security_status status = GRPC_SECURITY_OK; const char* overridden_target_name = nullptr; @@ -63,7 +65,8 @@ static grpc_security_status ssl_create_security_connector( } } status = grpc_ssl_channel_security_connector_create( - creds, call_creds, &c->config, target, overridden_target_name, sc); + exec_ctx, creds, call_creds, &c->config, target, overridden_target_name, + sc); if (status != GRPC_SECURITY_OK) { return status; } @@ -122,7 +125,8 @@ struct grpc_ssl_server_credentials_options { grpc_ssl_server_certificate_config_fetcher* certificate_config_fetcher; }; -static void ssl_server_destruct(grpc_server_credentials* creds) { +static void ssl_server_destruct(grpc_exec_ctx* exec_ctx, + grpc_server_credentials* creds) { grpc_ssl_server_credentials* c = (grpc_ssl_server_credentials*)creds; grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs, c->config.num_key_cert_pairs); @@ -130,8 +134,9 @@ static void ssl_server_destruct(grpc_server_credentials* creds) { } static grpc_security_status ssl_server_create_security_connector( - grpc_server_credentials* creds, grpc_server_security_connector** sc) { - return grpc_ssl_server_security_connector_create(creds, sc); + grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, + grpc_server_security_connector** sc) { + return grpc_ssl_server_security_connector_create(exec_ctx, creds, sc); } static grpc_server_credentials_vtable ssl_server_vtable = { diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc index cd3c2e3f19..326f4d7773 100644 --- a/src/core/lib/security/transport/client_auth_filter.cc +++ b/src/core/lib/security/transport/client_auth_filter.cc @@ -90,7 +90,8 @@ static void add_error(grpc_error** combined, grpc_error* error) { *combined = grpc_error_add_child(*combined, error); } -static void on_credentials_metadata(void* arg, grpc_error* input_error) { +static void on_credentials_metadata(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* input_error) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call_element* elem = (grpc_call_element*)batch->handler_private.extra_arg; @@ -104,16 +105,16 @@ static void on_credentials_metadata(void* arg, grpc_error* input_error) { batch->payload->send_initial_metadata.send_initial_metadata; for (size_t i = 0; i < calld->md_array.size; ++i) { add_error(&error, grpc_metadata_batch_add_tail( - mdb, &calld->md_links[i], + exec_ctx, mdb, &calld->md_links[i], GRPC_MDELEM_REF(calld->md_array.md[i]))); } } if (error == GRPC_ERROR_NONE) { - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); } else { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED); - grpc_transport_stream_op_batch_finish_with_failure(batch, error, + grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, batch, error, calld->call_combiner); } } @@ -155,17 +156,20 @@ void grpc_auth_metadata_context_build( gpr_free(host_and_port); } -static void cancel_get_request_metadata(void* arg, grpc_error* error) { +static void cancel_get_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { grpc_call_credentials_cancel_get_request_metadata( - calld->creds, &calld->md_array, GRPC_ERROR_REF(error)); + exec_ctx, calld->creds, &calld->md_array, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_get_request_metadata"); + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, + "cancel_get_request_metadata"); } -static void send_security_metadata(grpc_call_element* elem, +static void send_security_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -179,7 +183,7 @@ static void send_security_metadata(grpc_call_element* elem, if (channel_call_creds == nullptr && !call_creds_has_md) { /* Skip sending metadata altogether. */ - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); return; } @@ -188,7 +192,7 @@ static void send_security_metadata(grpc_call_element* elem, ctx->creds, nullptr); if (calld->creds == nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - batch, + exec_ctx, batch, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Incompatible credentials set on channel and call."), @@ -211,29 +215,30 @@ static void send_security_metadata(grpc_call_element* elem, batch, grpc_schedule_on_exec_ctx); grpc_error* error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - calld->creds, calld->pollent, calld->auth_md_context, + exec_ctx, calld->creds, calld->pollent, calld->auth_md_context, &calld->md_array, &calld->async_result_closure, &error)) { // Synchronous return; invoke on_credentials_metadata() directly. - on_credentials_metadata(batch, error); + on_credentials_metadata(exec_ctx, batch, error); GRPC_ERROR_UNREF(error); } else { // Async return; register cancellation closure with call combiner. GRPC_CALL_STACK_REF(calld->owning_call, "cancel_get_request_metadata"); grpc_call_combiner_set_notify_on_cancel( - calld->call_combiner, + exec_ctx, calld->call_combiner, GRPC_CLOSURE_INIT(&calld->get_request_metadata_cancel_closure, cancel_get_request_metadata, elem, grpc_schedule_on_exec_ctx)); } } -static void on_host_checked(void* arg, grpc_error* error) { +static void on_host_checked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call_element* elem = (grpc_call_element*)batch->handler_private.extra_arg; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - send_security_metadata(elem, batch); + send_security_metadata(exec_ctx, elem, batch); } else { char* error_msg; char* host = grpc_slice_to_c_string(calld->host); @@ -241,7 +246,7 @@ static void on_host_checked(void* arg, grpc_error* error) { host); gpr_free(host); grpc_transport_stream_op_batch_finish_with_failure( - batch, + exec_ctx, batch, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED), @@ -250,20 +255,22 @@ static void on_host_checked(void* arg, grpc_error* error) { } } -static void cancel_check_call_host(void* arg, grpc_error* error) { +static void cancel_check_call_host(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (error != GRPC_ERROR_NONE) { grpc_channel_security_connector_cancel_check_call_host( - chand->security_connector, &calld->async_result_closure, + exec_ctx, chand->security_connector, &calld->async_result_closure, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_check_call_host"); + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_check_call_host"); } static void auth_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { GPR_TIMER_BEGIN("auth_start_transport_stream_op_batch", 0); /* grab pointers to our data from the call element */ @@ -296,13 +303,13 @@ static void auth_start_transport_stream_op_batch( */ if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { if (calld->have_host) { - grpc_slice_unref_internal(calld->host); + grpc_slice_unref_internal(exec_ctx, calld->host); } calld->host = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_host = true; } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { if (calld->have_method) { - grpc_slice_unref_internal(calld->method); + grpc_slice_unref_internal(exec_ctx, calld->method); } calld->method = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_method = true; @@ -315,16 +322,16 @@ static void auth_start_transport_stream_op_batch( char* call_host = grpc_slice_to_c_string(calld->host); grpc_error* error = GRPC_ERROR_NONE; if (grpc_channel_security_connector_check_call_host( - chand->security_connector, call_host, chand->auth_context, - &calld->async_result_closure, &error)) { + exec_ctx, chand->security_connector, call_host, + chand->auth_context, &calld->async_result_closure, &error)) { // Synchronous return; invoke on_host_checked() directly. - on_host_checked(batch, error); + on_host_checked(exec_ctx, batch, error); GRPC_ERROR_UNREF(error); } else { // Async return; register cancellation closure with call combiner. GRPC_CALL_STACK_REF(calld->owning_call, "cancel_check_call_host"); grpc_call_combiner_set_notify_on_cancel( - calld->call_combiner, + exec_ctx, calld->call_combiner, GRPC_CLOSURE_INIT(&calld->check_call_host_cancel_closure, cancel_check_call_host, elem, grpc_schedule_on_exec_ctx)); @@ -336,12 +343,13 @@ static void auth_start_transport_stream_op_batch( } /* pass control down the stack */ - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); GPR_TIMER_END("auth_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->owning_call = args->call_stack; @@ -349,30 +357,32 @@ static grpc_error* init_call_elem(grpc_call_element* elem, return GRPC_ERROR_NONE; } -static void set_pollset_or_pollset_set(grpc_call_element* elem, +static void set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; calld->pollent = pollent; } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_credentials_mdelem_array_destroy(&calld->md_array); - grpc_call_credentials_unref(calld->creds); + grpc_credentials_mdelem_array_destroy(exec_ctx, &calld->md_array); + grpc_call_credentials_unref(exec_ctx, calld->creds); if (calld->have_host) { - grpc_slice_unref_internal(calld->host); + grpc_slice_unref_internal(exec_ctx, calld->host); } if (calld->have_method) { - grpc_slice_unref_internal(calld->method); + grpc_slice_unref_internal(exec_ctx, calld->method); } grpc_auth_metadata_context_reset(&calld->auth_md_context); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { grpc_security_connector* sc = grpc_security_connector_find_in_args(args->channel_args); @@ -405,12 +415,13 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { /* grab pointers to our data from the channel element */ channel_data* chand = (channel_data*)elem->channel_data; grpc_channel_security_connector* sc = chand->security_connector; if (sc != nullptr) { - GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter"); + GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "client_auth_filter"); } GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter"); } diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc index 183b1ebf35..c07be35840 100644 --- a/src/core/lib/security/transport/lb_targets_info.cc +++ b/src/core/lib/security/transport/lb_targets_info.cc @@ -28,8 +28,8 @@ static void* targets_info_copy(void* p) { return grpc_slice_hash_table_ref((grpc_slice_hash_table*)p); } -static void targets_info_destroy(void* p) { - grpc_slice_hash_table_unref((grpc_slice_hash_table*)p); +static void targets_info_destroy(grpc_exec_ctx* exec_ctx, void* p) { + grpc_slice_hash_table_unref(exec_ctx, (grpc_slice_hash_table*)p); } static int targets_info_cmp(void* a, void* b) { return grpc_slice_hash_table_cmp((const grpc_slice_hash_table*)a, diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index e5c089de9c..4cd317a06d 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -63,27 +63,28 @@ typedef struct { grpc_core::TraceFlag grpc_trace_secure_endpoint(false, "secure_endpoint"); -static void destroy(secure_endpoint* secure_ep) { +static void destroy(grpc_exec_ctx* exec_ctx, secure_endpoint* secure_ep) { secure_endpoint* ep = secure_ep; - grpc_endpoint_destroy(ep->wrapped_ep); + grpc_endpoint_destroy(exec_ctx, ep->wrapped_ep); tsi_frame_protector_destroy(ep->protector); - tsi_zero_copy_grpc_protector_destroy(ep->zero_copy_protector); - grpc_slice_buffer_destroy_internal(&ep->leftover_bytes); - grpc_slice_unref_internal(ep->read_staging_buffer); - grpc_slice_unref_internal(ep->write_staging_buffer); - grpc_slice_buffer_destroy_internal(&ep->output_buffer); - grpc_slice_buffer_destroy_internal(&ep->source_buffer); + tsi_zero_copy_grpc_protector_destroy(exec_ctx, ep->zero_copy_protector); + grpc_slice_buffer_destroy_internal(exec_ctx, &ep->leftover_bytes); + grpc_slice_unref_internal(exec_ctx, ep->read_staging_buffer); + grpc_slice_unref_internal(exec_ctx, ep->write_staging_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &ep->output_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &ep->source_buffer); gpr_mu_destroy(&ep->protector_mu); gpr_free(ep); } #ifndef NDEBUG -#define SECURE_ENDPOINT_UNREF(ep, reason) \ - secure_endpoint_unref((ep), (reason), __FILE__, __LINE__) +#define SECURE_ENDPOINT_UNREF(exec_ctx, ep, reason) \ + secure_endpoint_unref((exec_ctx), (ep), (reason), __FILE__, __LINE__) #define SECURE_ENDPOINT_REF(ep, reason) \ secure_endpoint_ref((ep), (reason), __FILE__, __LINE__) -static void secure_endpoint_unref(secure_endpoint* ep, const char* reason, - const char* file, int line) { +static void secure_endpoint_unref(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, + const char* reason, const char* file, + int line) { if (grpc_trace_secure_endpoint.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -91,7 +92,7 @@ static void secure_endpoint_unref(secure_endpoint* ep, const char* reason, val - 1); } if (gpr_unref(&ep->ref)) { - destroy(ep); + destroy(exec_ctx, ep); } } @@ -106,11 +107,13 @@ static void secure_endpoint_ref(secure_endpoint* ep, const char* reason, gpr_ref(&ep->ref); } #else -#define SECURE_ENDPOINT_UNREF(ep, reason) secure_endpoint_unref((ep)) +#define SECURE_ENDPOINT_UNREF(exec_ctx, ep, reason) \ + secure_endpoint_unref((exec_ctx), (ep)) #define SECURE_ENDPOINT_REF(ep, reason) secure_endpoint_ref((ep)) -static void secure_endpoint_unref(secure_endpoint* ep) { +static void secure_endpoint_unref(grpc_exec_ctx* exec_ctx, + secure_endpoint* ep) { if (gpr_unref(&ep->ref)) { - destroy(ep); + destroy(exec_ctx, ep); } } @@ -125,7 +128,8 @@ static void flush_read_staging_buffer(secure_endpoint* ep, uint8_t** cur, *end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); } -static void call_read_cb(secure_endpoint* ep, grpc_error* error) { +static void call_read_cb(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, + grpc_error* error) { if (grpc_trace_secure_endpoint.enabled()) { size_t i; for (i = 0; i < ep->read_buffer->count; i++) { @@ -136,11 +140,12 @@ static void call_read_cb(secure_endpoint* ep, grpc_error* error) { } } ep->read_buffer = nullptr; - GRPC_CLOSURE_SCHED(ep->read_cb, error); - SECURE_ENDPOINT_UNREF(ep, "read"); + GRPC_CLOSURE_SCHED(exec_ctx, ep->read_cb, error); + SECURE_ENDPOINT_UNREF(exec_ctx, ep, "read"); } -static void on_read(void* user_data, grpc_error* error) { +static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { unsigned i; uint8_t keep_looping = 0; tsi_result result = TSI_OK; @@ -149,16 +154,17 @@ static void on_read(void* user_data, grpc_error* error) { uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); - call_read_cb(ep, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Secure read failed", &error, 1)); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); + call_read_cb(exec_ctx, ep, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Secure read failed", &error, 1)); return; } if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to unprotect. result = tsi_zero_copy_grpc_protector_unprotect( - ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer); + exec_ctx, ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer); } else { // Use frame protector to unprotect. /* TODO(yangg) check error, maybe bail out early */ @@ -211,35 +217,37 @@ static void on_read(void* user_data, grpc_error* error) { /* TODO(yangg) experiment with moving this block after read_cb to see if it helps latency */ - grpc_slice_buffer_reset_and_unref_internal(&ep->source_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->source_buffer); if (result != TSI_OK) { - grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); call_read_cb( - ep, grpc_set_tsi_error_result( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unwrap failed"), result)); + exec_ctx, ep, + grpc_set_tsi_error_result( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unwrap failed"), result)); return; } - call_read_cb(ep, GRPC_ERROR_NONE); + call_read_cb(exec_ctx, ep, GRPC_ERROR_NONE); } -static void endpoint_read(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, + grpc_slice_buffer* slices, grpc_closure* cb) { secure_endpoint* ep = (secure_endpoint*)secure_ep; ep->read_cb = cb; ep->read_buffer = slices; - grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); SECURE_ENDPOINT_REF(ep, "read"); if (ep->leftover_bytes.count) { grpc_slice_buffer_swap(&ep->leftover_bytes, &ep->source_buffer); GPR_ASSERT(ep->leftover_bytes.count == 0); - on_read(ep, GRPC_ERROR_NONE); + on_read(exec_ctx, ep, GRPC_ERROR_NONE); return; } - grpc_endpoint_read(ep->wrapped_ep, &ep->source_buffer, &ep->on_read); + grpc_endpoint_read(exec_ctx, ep->wrapped_ep, &ep->source_buffer, + &ep->on_read); } static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur, @@ -250,8 +258,8 @@ static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur, *end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); } -static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, + grpc_slice_buffer* slices, grpc_closure* cb) { GPR_TIMER_BEGIN("secure_endpoint.endpoint_write", 0); unsigned i; @@ -260,7 +268,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, uint8_t* cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer); uint8_t* end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); - grpc_slice_buffer_reset_and_unref_internal(&ep->output_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer); if (grpc_trace_secure_endpoint.enabled()) { for (i = 0; i < slices->count; i++) { @@ -273,8 +281,8 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to protect. - result = tsi_zero_copy_grpc_protector_protect(ep->zero_copy_protector, - slices, &ep->output_buffer); + result = tsi_zero_copy_grpc_protector_protect( + exec_ctx, ep->zero_copy_protector, slices, &ep->output_buffer); } else { // Use frame protector to protect. for (i = 0; i < slices->count; i++) { @@ -332,44 +340,50 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, if (result != TSI_OK) { /* TODO(yangg) do different things according to the error type? */ - grpc_slice_buffer_reset_and_unref_internal(&ep->output_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer); GRPC_CLOSURE_SCHED( - cb, grpc_set_tsi_error_result( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result)); + exec_ctx, cb, + grpc_set_tsi_error_result( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result)); GPR_TIMER_END("secure_endpoint.endpoint_write", 0); return; } - grpc_endpoint_write(ep->wrapped_ep, &ep->output_buffer, cb); + grpc_endpoint_write(exec_ctx, ep->wrapped_ep, &ep->output_buffer, cb); GPR_TIMER_END("secure_endpoint.endpoint_write", 0); } -static void endpoint_shutdown(grpc_endpoint* secure_ep, grpc_error* why) { +static void endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, + grpc_error* why) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_shutdown(ep->wrapped_ep, why); + grpc_endpoint_shutdown(exec_ctx, ep->wrapped_ep, why); } -static void endpoint_destroy(grpc_endpoint* secure_ep) { +static void endpoint_destroy(grpc_exec_ctx* exec_ctx, + grpc_endpoint* secure_ep) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - SECURE_ENDPOINT_UNREF(ep, "destroy"); + SECURE_ENDPOINT_UNREF(exec_ctx, ep, "destroy"); } -static void endpoint_add_to_pollset(grpc_endpoint* secure_ep, +static void endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, + grpc_endpoint* secure_ep, grpc_pollset* pollset) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_add_to_pollset(ep->wrapped_ep, pollset); + grpc_endpoint_add_to_pollset(exec_ctx, ep->wrapped_ep, pollset); } -static void endpoint_add_to_pollset_set(grpc_endpoint* secure_ep, +static void endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_add_to_pollset_set(ep->wrapped_ep, pollset_set); + grpc_endpoint_add_to_pollset_set(exec_ctx, ep->wrapped_ep, pollset_set); } -static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep, +static void endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set); + grpc_endpoint_delete_from_pollset_set(exec_ctx, ep->wrapped_ep, pollset_set); } static char* endpoint_get_peer(grpc_endpoint* secure_ep) { diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index fd139714da..c56e459aeb 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -105,32 +105,33 @@ const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, } void grpc_channel_security_connector_add_handshakers( - grpc_channel_security_connector* connector, + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr) { if (connector != nullptr) { - connector->add_handshakers(connector, handshake_mgr); + connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } void grpc_server_security_connector_add_handshakers( - grpc_server_security_connector* connector, + grpc_exec_ctx* exec_ctx, grpc_server_security_connector* connector, grpc_handshake_manager* handshake_mgr) { if (connector != nullptr) { - connector->add_handshakers(connector, handshake_mgr); + connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } -void grpc_security_connector_check_peer(grpc_security_connector* sc, +void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { if (sc == nullptr) { - GRPC_CLOSURE_SCHED(on_peer_checked, + GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check peer -- no security connector")); tsi_peer_destruct(&peer); } else { - sc->vtable->check_peer(sc, peer, auth_context, on_peer_checked); + sc->vtable->check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); } } @@ -168,26 +169,26 @@ int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, } bool grpc_channel_security_connector_check_call_host( - grpc_channel_security_connector* sc, const char* host, - grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, - grpc_error** error) { + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + const char* host, grpc_auth_context* auth_context, + grpc_closure* on_call_host_checked, grpc_error** error) { if (sc == nullptr || sc->check_call_host == nullptr) { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check call host -- no security connector"); return true; } - return sc->check_call_host(sc, host, auth_context, on_call_host_checked, - error); + return sc->check_call_host(exec_ctx, sc, host, auth_context, + on_call_host_checked, error); } void grpc_channel_security_connector_cancel_check_call_host( - grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + grpc_closure* on_call_host_checked, grpc_error* error) { if (sc == nullptr || sc->cancel_check_call_host == nullptr) { GRPC_ERROR_UNREF(error); return; } - sc->cancel_check_call_host(sc, on_call_host_checked, error); + sc->cancel_check_call_host(exec_ctx, sc, on_call_host_checked, error); } #ifndef NDEBUG @@ -204,14 +205,15 @@ grpc_security_connector* grpc_security_connector_ref( #else grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* sc) { - if (sc == nullptr) return nullptr; + if (sc == NULL) return NULL; #endif gpr_ref(&sc->refcount); return sc; } #ifndef NDEBUG -void grpc_security_connector_unref(grpc_security_connector* sc, +void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, const char* file, int line, const char* reason) { if (sc == nullptr) return; @@ -222,14 +224,15 @@ void grpc_security_connector_unref(grpc_security_connector* sc, val, val - 1, reason); } #else -void grpc_security_connector_unref(grpc_security_connector* sc) { - if (sc == nullptr) return; +void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { + if (sc == NULL) return; #endif - if (gpr_unref(&sc->refcount)) sc->vtable->destroy(sc); + if (gpr_unref(&sc->refcount)) sc->vtable->destroy(exec_ctx, sc); } -static void connector_arg_destroy(void* p) { - GRPC_SECURITY_CONNECTOR_UNREF((grpc_security_connector*)p, +static void connector_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { + GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, (grpc_security_connector*)p, "connector_arg_destroy"); } @@ -306,16 +309,20 @@ typedef struct { bool is_lb_channel; } grpc_fake_channel_security_connector; -static void fake_channel_destroy(grpc_security_connector* sc) { +static void fake_channel_destroy(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { grpc_fake_channel_security_connector* c = (grpc_fake_channel_security_connector*)sc; - grpc_call_credentials_unref(c->base.request_metadata_creds); + grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); gpr_free(c->target); gpr_free(c->expected_targets); gpr_free(c); } -static void fake_server_destroy(grpc_security_connector* sc) { gpr_free(sc); } +static void fake_server_destroy(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { + gpr_free(sc); +} static bool fake_check_target(const char* target_type, const char* target, const char* set_str) { @@ -379,7 +386,8 @@ done: if (!success) abort(); } -static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void fake_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { const char* prop_name; @@ -411,23 +419,25 @@ static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer, *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_FAKE_TRANSPORT_SECURITY_TYPE); end: - GRPC_CLOSURE_SCHED(on_peer_checked, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); tsi_peer_destruct(&peer); } -static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void fake_channel_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - fake_check_peer(sc, peer, auth_context, on_peer_checked); + fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); grpc_fake_channel_security_connector* c = (grpc_fake_channel_security_connector*)sc; fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel); } -static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void fake_server_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - fake_check_peer(sc, peer, auth_context, on_peer_checked); + fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); } static int fake_channel_cmp(grpc_security_connector* sc1, @@ -456,7 +466,8 @@ static int fake_server_cmp(grpc_security_connector* sc1, (grpc_server_security_connector*)sc2); } -static bool fake_channel_check_call_host(grpc_channel_security_connector* sc, +static bool fake_channel_check_call_host(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, @@ -465,26 +476,29 @@ static bool fake_channel_check_call_host(grpc_channel_security_connector* sc, } static void fake_channel_cancel_check_call_host( - grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + grpc_closure* on_call_host_checked, grpc_error* error) { GRPC_ERROR_UNREF(error); } static void fake_channel_add_handshakers( - grpc_channel_security_connector* sc, + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add( handshake_mgr, grpc_security_handshaker_create( - tsi_create_fake_handshaker(true /* is_client */), &sc->base)); + exec_ctx, tsi_create_fake_handshaker(true /* is_client */), + &sc->base)); } -static void fake_server_add_handshakers(grpc_server_security_connector* sc, +static void fake_server_add_handshakers(grpc_exec_ctx* exec_ctx, + grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add( handshake_mgr, grpc_security_handshaker_create( - tsi_create_fake_handshaker(false /* is_client */), &sc->base)); + exec_ctx, tsi_create_fake_handshaker(false /* is_client */), + &sc->base)); } static grpc_security_connector_vtable fake_channel_vtable = { @@ -551,11 +565,12 @@ static bool server_connector_has_cert_config_fetcher( return server_creds->certificate_config_fetcher.cb != nullptr; } -static void ssl_channel_destroy(grpc_security_connector* sc) { +static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; - grpc_channel_credentials_unref(c->base.channel_creds); - grpc_call_credentials_unref(c->base.request_metadata_creds); + grpc_channel_credentials_unref(exec_ctx, c->base.channel_creds); + grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory); c->client_handshaker_factory = nullptr; if (c->target_name != nullptr) gpr_free(c->target_name); @@ -563,16 +578,18 @@ static void ssl_channel_destroy(grpc_security_connector* sc) { gpr_free(sc); } -static void ssl_server_destroy(grpc_security_connector* sc) { +static void ssl_server_destroy(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc) { grpc_ssl_server_security_connector* c = (grpc_ssl_server_security_connector*)sc; - grpc_server_credentials_unref(c->base.server_creds); + grpc_server_credentials_unref(exec_ctx, c->base.server_creds); tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory); c->server_handshaker_factory = nullptr; gpr_free(sc); } -static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, +static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; @@ -590,8 +607,9 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, + grpc_security_handshaker_create( + exec_ctx, tsi_create_adapter_handshaker(tsi_hs), &sc->base)); } static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { @@ -683,7 +701,8 @@ static bool try_fetch_ssl_server_credentials( return status; } -static void ssl_server_add_handshakers(grpc_server_security_connector* sc, +static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, + grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_server_security_connector* c = (grpc_ssl_server_security_connector*)sc; @@ -699,8 +718,9 @@ static void ssl_server_add_handshakers(grpc_server_security_connector* sc, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, + grpc_security_handshaker_create( + exec_ctx, tsi_create_adapter_handshaker(tsi_hs), &sc->base)); } static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { @@ -784,7 +804,8 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, return GRPC_ERROR_NONE; } -static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void ssl_channel_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_ssl_channel_security_connector* c = @@ -794,16 +815,17 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, ? c->overridden_target_name : c->target_name, &peer, auth_context); - GRPC_CLOSURE_SCHED(on_peer_checked, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); tsi_peer_destruct(&peer); } -static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer, +static void ssl_server_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_error* error = ssl_check_peer(sc, nullptr, &peer, auth_context); tsi_peer_destruct(&peer); - GRPC_CLOSURE_SCHED(on_peer_checked, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); } static int ssl_channel_cmp(grpc_security_connector* sc1, @@ -873,7 +895,8 @@ void tsi_shallow_peer_destruct(tsi_peer* peer) { if (peer->properties != nullptr) gpr_free(peer->properties); } -static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc, +static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, @@ -899,8 +922,8 @@ static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc, } static void ssl_channel_cancel_check_call_host( - grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, - grpc_error* error) { + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + grpc_closure* on_call_host_checked, grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -967,7 +990,7 @@ const char* grpc_get_default_ssl_roots(void) { } grpc_security_status grpc_ssl_channel_security_connector_create( - grpc_channel_credentials* channel_creds, + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, grpc_call_credentials* request_metadata_creds, const grpc_ssl_config* config, const char* target_name, const char* overridden_target_name, grpc_channel_security_connector** sc) { @@ -1022,7 +1045,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); - ssl_channel_destroy(&c->base.base); + ssl_channel_destroy(exec_ctx, &c->base.base); *sc = nullptr; goto error; } @@ -1050,7 +1073,8 @@ grpc_ssl_server_security_connector_initialize( } grpc_security_status grpc_ssl_server_security_connector_create( - grpc_server_credentials* gsc, grpc_server_security_connector** sc) { + grpc_exec_ctx* exec_ctx, grpc_server_credentials* gsc, + grpc_server_security_connector** sc) { tsi_result result = TSI_OK; grpc_ssl_server_credentials* server_credentials = (grpc_ssl_server_credentials*)gsc; @@ -1090,7 +1114,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( if (retval == GRPC_SECURITY_OK) { *sc = &c->base; } else { - if (c != nullptr) ssl_server_destroy(&c->base.base); + if (c != nullptr) ssl_server_destroy(exec_ctx, &c->base.base); if (sc != nullptr) *sc = nullptr; } return retval; diff --git a/src/core/lib/security/transport/security_connector.h b/src/core/lib/security/transport/security_connector.h index 495821d247..03daba3a18 100644 --- a/src/core/lib/security/transport/security_connector.h +++ b/src/core/lib/security/transport/security_connector.h @@ -50,9 +50,9 @@ typedef struct grpc_security_connector grpc_security_connector; #define GRPC_ARG_SECURITY_CONNECTOR "grpc.security_connector" typedef struct { - void (*destroy)(grpc_security_connector* sc); - void (*check_peer)(grpc_security_connector* sc, tsi_peer peer, - grpc_auth_context** auth_context, + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc); + void (*check_peer)(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, + tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked); int (*cmp)(grpc_security_connector* sc, grpc_security_connector* other); } grpc_security_connector_vtable; @@ -67,25 +67,29 @@ struct grpc_security_connector { #ifndef NDEBUG #define GRPC_SECURITY_CONNECTOR_REF(p, r) \ grpc_security_connector_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SECURITY_CONNECTOR_UNREF(p, r) \ - grpc_security_connector_unref((p), __FILE__, __LINE__, (r)) +#define GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, p, r) \ + grpc_security_connector_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* policy, const char* file, int line, const char* reason); -void grpc_security_connector_unref(grpc_security_connector* policy, +void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_security_connector* policy, const char* file, int line, const char* reason); #else #define GRPC_SECURITY_CONNECTOR_REF(p, r) grpc_security_connector_ref((p)) -#define GRPC_SECURITY_CONNECTOR_UNREF(p, r) grpc_security_connector_unref((p)) +#define GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, p, r) \ + grpc_security_connector_unref((exec_ctx), (p)) grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* policy); -void grpc_security_connector_unref(grpc_security_connector* policy); +void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_security_connector* policy); #endif /* Check the peer. Callee takes ownership of the peer object. When done, sets *auth_context and invokes on_peer_checked. */ -void grpc_security_connector_check_peer(grpc_security_connector* sc, +void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, + grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked); @@ -115,14 +119,17 @@ struct grpc_channel_security_connector { grpc_security_connector base; grpc_channel_credentials* channel_creds; grpc_call_credentials* request_metadata_creds; - bool (*check_call_host)(grpc_channel_security_connector* sc, const char* host, + bool (*check_call_host)(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, grpc_error** error); - void (*cancel_check_call_host)(grpc_channel_security_connector* sc, + void (*cancel_check_call_host)(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, grpc_error* error); - void (*add_handshakers)(grpc_channel_security_connector* sc, + void (*add_handshakers)(grpc_exec_ctx* exec_ctx, + grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr); }; @@ -135,20 +142,20 @@ int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, /// be set to indicate the result. Otherwise, \a on_call_host_checked /// will be invoked when complete. bool grpc_channel_security_connector_check_call_host( - grpc_channel_security_connector* sc, const char* host, - grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, - grpc_error** error); + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + const char* host, grpc_auth_context* auth_context, + grpc_closure* on_call_host_checked, grpc_error** error); /// Cancels a pending asychronous call to /// grpc_channel_security_connector_check_call_host() with /// \a on_call_host_checked as its callback. void grpc_channel_security_connector_cancel_check_call_host( - grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, - grpc_error* error); + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + grpc_closure* on_call_host_checked, grpc_error* error); /* Registers handshakers with \a handshake_mgr. */ void grpc_channel_security_connector_add_handshakers( - grpc_channel_security_connector* connector, + grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr); /* --- server_security_connector object. --- @@ -161,7 +168,8 @@ typedef struct grpc_server_security_connector grpc_server_security_connector; struct grpc_server_security_connector { grpc_security_connector base; grpc_server_credentials* server_creds; - void (*add_handshakers)(grpc_server_security_connector* sc, + void (*add_handshakers)(grpc_exec_ctx* exec_ctx, + grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr); }; @@ -170,7 +178,8 @@ int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, grpc_server_security_connector* sc2); void grpc_server_security_connector_add_handshakers( - grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr); + grpc_exec_ctx* exec_ctx, grpc_server_security_connector* sc, + grpc_handshake_manager* handshake_mgr); /* --- Creation security connectors. --- */ @@ -207,7 +216,7 @@ typedef struct { specific error code otherwise. */ grpc_security_status grpc_ssl_channel_security_connector_create( - grpc_channel_credentials* channel_creds, + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, grpc_call_credentials* request_metadata_creds, const grpc_ssl_config* config, const char* target_name, const char* overridden_target_name, grpc_channel_security_connector** sc); @@ -233,7 +242,7 @@ typedef struct { specific error code otherwise. */ grpc_security_status grpc_ssl_server_security_connector_create( - grpc_server_credentials* server_credentials, + grpc_exec_ctx* exec_ctx, grpc_server_credentials* server_credentials, grpc_server_security_connector** sc); /* Util. */ diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 7623fbfd5b..7067b70cb6 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -65,7 +65,8 @@ typedef struct { tsi_handshaker_result* handshaker_result; } security_handshaker; -static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) { +static size_t move_read_buffer_into_handshake_buffer(grpc_exec_ctx* exec_ctx, + security_handshaker* h) { size_t bytes_in_read_buffer = h->args->read_buffer->length; if (h->handshake_buffer_size < bytes_in_read_buffer) { h->handshake_buffer = @@ -78,45 +79,48 @@ static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) { memcpy(h->handshake_buffer + offset, GRPC_SLICE_START_PTR(next_slice), GRPC_SLICE_LENGTH(next_slice)); offset += GRPC_SLICE_LENGTH(next_slice); - grpc_slice_unref_internal(next_slice); + grpc_slice_unref_internal(exec_ctx, next_slice); } return bytes_in_read_buffer; } -static void security_handshaker_unref(security_handshaker* h) { +static void security_handshaker_unref(grpc_exec_ctx* exec_ctx, + security_handshaker* h) { if (gpr_unref(&h->refs)) { gpr_mu_destroy(&h->mu); tsi_handshaker_destroy(h->handshaker); tsi_handshaker_result_destroy(h->handshaker_result); if (h->endpoint_to_destroy != nullptr) { - grpc_endpoint_destroy(h->endpoint_to_destroy); + grpc_endpoint_destroy(exec_ctx, h->endpoint_to_destroy); } if (h->read_buffer_to_destroy != nullptr) { - grpc_slice_buffer_destroy_internal(h->read_buffer_to_destroy); + grpc_slice_buffer_destroy_internal(exec_ctx, h->read_buffer_to_destroy); gpr_free(h->read_buffer_to_destroy); } gpr_free(h->handshake_buffer); - grpc_slice_buffer_destroy_internal(&h->outgoing); + grpc_slice_buffer_destroy_internal(exec_ctx, &h->outgoing); GRPC_AUTH_CONTEXT_UNREF(h->auth_context, "handshake"); - GRPC_SECURITY_CONNECTOR_UNREF(h->connector, "handshake"); + GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, h->connector, "handshake"); gpr_free(h); } } // Set args fields to NULL, saving the endpoint and read buffer for // later destruction. -static void cleanup_args_for_failure_locked(security_handshaker* h) { +static void cleanup_args_for_failure_locked(grpc_exec_ctx* exec_ctx, + security_handshaker* h) { h->endpoint_to_destroy = h->args->endpoint; h->args->endpoint = nullptr; h->read_buffer_to_destroy = h->args->read_buffer; h->args->read_buffer = nullptr; - grpc_channel_args_destroy(h->args->args); + grpc_channel_args_destroy(exec_ctx, h->args->args); h->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the // callback with the error. -static void security_handshake_failed_locked(security_handshaker* h, +static void security_handshake_failed_locked(grpc_exec_ctx* exec_ctx, + security_handshaker* h, grpc_error* error) { if (error == GRPC_ERROR_NONE) { // If we were shut down after the handshake succeeded but before an @@ -131,33 +135,34 @@ static void security_handshake_failed_locked(security_handshaker* h, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(h->args->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(error)); // Not shutting down, so the write failed. Clean up before // invoking the callback. - cleanup_args_for_failure_locked(h); + cleanup_args_for_failure_locked(exec_ctx, h); // Set shutdown to true so that subsequent calls to // security_handshaker_shutdown() do nothing. h->shutdown = true; } // Invoke callback. - GRPC_CLOSURE_SCHED(h->on_handshake_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, h->on_handshake_done, error); } -static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { +static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, + security_handshaker* h, grpc_error* error) { if (error != GRPC_ERROR_NONE || h->shutdown) { - security_handshake_failed_locked(h, GRPC_ERROR_REF(error)); + security_handshake_failed_locked(exec_ctx, h, GRPC_ERROR_REF(error)); return; } // Create zero-copy frame protector, if implemented. tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr; tsi_result result = tsi_handshaker_result_create_zero_copy_grpc_protector( - h->handshaker_result, nullptr, &zero_copy_protector); + exec_ctx, h->handshaker_result, nullptr, &zero_copy_protector); if (result != TSI_OK && result != TSI_UNIMPLEMENTED) { error = grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Zero-copy frame protector creation failed"), result); - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(exec_ctx, h, error); return; } // Create frame protector if zero-copy frame protector is NULL. @@ -169,7 +174,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { error = grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Frame protector creation failed"), result); - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(exec_ctx, h, error); return; } } @@ -184,7 +189,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { grpc_slice_from_copied_buffer((char*)unused_bytes, unused_bytes_size); h->args->endpoint = grpc_secure_endpoint_create( protector, zero_copy_protector, h->args->endpoint, &slice, 1); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); } else { h->args->endpoint = grpc_secure_endpoint_create( protector, zero_copy_protector, h->args->endpoint, nullptr, 0); @@ -196,23 +201,25 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { grpc_channel_args* tmp_args = h->args->args; h->args->args = grpc_channel_args_copy_and_add(tmp_args, &auth_context_arg, 1); - grpc_channel_args_destroy(tmp_args); + grpc_channel_args_destroy(exec_ctx, tmp_args); // Invoke callback. - GRPC_CLOSURE_SCHED(h->on_handshake_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, h->on_handshake_done, GRPC_ERROR_NONE); // Set shutdown to true so that subsequent calls to // security_handshaker_shutdown() do nothing. h->shutdown = true; } -static void on_peer_checked(void* arg, grpc_error* error) { +static void on_peer_checked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); - on_peer_checked_inner(h, error); + on_peer_checked_inner(exec_ctx, h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); } -static grpc_error* check_peer_locked(security_handshaker* h) { +static grpc_error* check_peer_locked(grpc_exec_ctx* exec_ctx, + security_handshaker* h) { tsi_peer peer; tsi_result result = tsi_handshaker_result_extract_peer(h->handshaker_result, &peer); @@ -220,20 +227,20 @@ static grpc_error* check_peer_locked(security_handshaker* h) { return grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Peer extraction failed"), result); } - grpc_security_connector_check_peer(h->connector, peer, &h->auth_context, - &h->on_peer_checked); + grpc_security_connector_check_peer(exec_ctx, h->connector, peer, + &h->auth_context, &h->on_peer_checked); return GRPC_ERROR_NONE; } static grpc_error* on_handshake_next_done_locked( - security_handshaker* h, tsi_result result, + grpc_exec_ctx* exec_ctx, security_handshaker* h, tsi_result result, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { grpc_error* error = GRPC_ERROR_NONE; // Read more if we need to. if (result == TSI_INCOMPLETE_DATA) { GPR_ASSERT(bytes_to_send_size == 0); - grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); return error; } @@ -250,17 +257,17 @@ static grpc_error* on_handshake_next_done_locked( // Send data to peer, if needed. grpc_slice to_send = grpc_slice_from_copied_buffer( (const char*)bytes_to_send, bytes_to_send_size); - grpc_slice_buffer_reset_and_unref_internal(&h->outgoing); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &h->outgoing); grpc_slice_buffer_add(&h->outgoing, to_send); - grpc_endpoint_write(h->args->endpoint, &h->outgoing, + grpc_endpoint_write(exec_ctx, h->args->endpoint, &h->outgoing, &h->on_handshake_data_sent_to_peer); } else if (handshaker_result == nullptr) { // There is nothing to send, but need to read from peer. - grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); } else { // Handshake has finished, check peer and so on. - error = check_peer_locked(h); + error = check_peer_locked(exec_ctx, h); } return error; } @@ -271,22 +278,24 @@ static void on_handshake_next_done_grpc_wrapper( security_handshaker* h = (security_handshaker*)user_data; // This callback will be invoked by TSI in a non-grpc thread, so it's // safe to create our own exec_ctx here. - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(&h->mu); - grpc_error* error = on_handshake_next_done_locked( - h, result, bytes_to_send, bytes_to_send_size, handshaker_result); + grpc_error* error = + on_handshake_next_done_locked(&exec_ctx, h, result, bytes_to_send, + bytes_to_send_size, handshaker_result); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(&exec_ctx, h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(&exec_ctx, h); } else { gpr_mu_unlock(&h->mu); } + grpc_exec_ctx_finish(&exec_ctx); } static grpc_error* do_handshaker_next_locked( - security_handshaker* h, const unsigned char* bytes_received, - size_t bytes_received_size) { + grpc_exec_ctx* exec_ctx, security_handshaker* h, + const unsigned char* bytes_received, size_t bytes_received_size) { // Invoke TSI handshaker. const unsigned char* bytes_to_send = nullptr; size_t bytes_to_send_size = 0; @@ -302,57 +311,62 @@ static grpc_error* do_handshaker_next_locked( } // Handshaker returned synchronously. Invoke callback directly in // this thread with our existing exec_ctx. - return on_handshake_next_done_locked(h, result, bytes_to_send, + return on_handshake_next_done_locked(exec_ctx, h, result, bytes_to_send, bytes_to_send_size, handshaker_result); } -static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) { +static void on_handshake_data_received_from_peer(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( - h, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Handshake read failed", &error, 1)); + exec_ctx, h, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Handshake read failed", &error, 1)); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); return; } // Copy all slices received. - size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h); + size_t bytes_received_size = + move_read_buffer_into_handshake_buffer(exec_ctx, h); // Call TSI handshaker. - error = - do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size); + error = do_handshaker_next_locked(exec_ctx, h, h->handshake_buffer, + bytes_received_size); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(exec_ctx, h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); } else { gpr_mu_unlock(&h->mu); } } -static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) { +static void on_handshake_data_sent_to_peer(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( - h, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Handshake write failed", &error, 1)); + exec_ctx, h, + GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Handshake write failed", &error, 1)); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); return; } // We may be done. if (h->handshaker_result == nullptr) { - grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); } else { - error = check_peer_locked(h); + error = check_peer_locked(exec_ctx, h); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(exec_ctx, h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); return; } } @@ -363,25 +377,28 @@ static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) { // public handshaker API // -static void security_handshaker_destroy(grpc_handshaker* handshaker) { +static void security_handshaker_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker) { security_handshaker* h = (security_handshaker*)handshaker; - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); } -static void security_handshaker_shutdown(grpc_handshaker* handshaker, +static void security_handshaker_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_error* why) { security_handshaker* h = (security_handshaker*)handshaker; gpr_mu_lock(&h->mu); if (!h->shutdown) { h->shutdown = true; - grpc_endpoint_shutdown(h->args->endpoint, GRPC_ERROR_REF(why)); - cleanup_args_for_failure_locked(h); + grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(why)); + cleanup_args_for_failure_locked(exec_ctx, h); } gpr_mu_unlock(&h->mu); GRPC_ERROR_UNREF(why); } -static void security_handshaker_do_handshake(grpc_handshaker* handshaker, +static void security_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { @@ -390,13 +407,14 @@ static void security_handshaker_do_handshake(grpc_handshaker* handshaker, h->args = args; h->on_handshake_done = on_handshake_done; gpr_ref(&h->refs); - size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h); - grpc_error* error = - do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size); + size_t bytes_received_size = + move_read_buffer_into_handshake_buffer(exec_ctx, h); + grpc_error* error = do_handshaker_next_locked( + exec_ctx, h, h->handshake_buffer, bytes_received_size); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(h, error); + security_handshake_failed_locked(exec_ctx, h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(h); + security_handshaker_unref(exec_ctx, h); return; } gpr_mu_unlock(&h->mu); @@ -407,7 +425,8 @@ static const grpc_handshaker_vtable security_handshaker_vtable = { security_handshaker_do_handshake}; static grpc_handshaker* security_handshaker_create( - tsi_handshaker* handshaker, grpc_security_connector* connector) { + grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, + grpc_security_connector* connector) { security_handshaker* h = (security_handshaker*)gpr_zalloc(sizeof(security_handshaker)); grpc_handshaker_init(&security_handshaker_vtable, &h->base); @@ -433,20 +452,23 @@ static grpc_handshaker* security_handshaker_create( // fail_handshaker // -static void fail_handshaker_destroy(grpc_handshaker* handshaker) { +static void fail_handshaker_destroy(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker) { gpr_free(handshaker); } -static void fail_handshaker_shutdown(grpc_handshaker* handshaker, +static void fail_handshaker_shutdown(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_error* why) { GRPC_ERROR_UNREF(why); } -static void fail_handshaker_do_handshake(grpc_handshaker* handshaker, +static void fail_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - GRPC_CLOSURE_SCHED(on_handshake_done, + GRPC_CLOSURE_SCHED(exec_ctx, on_handshake_done, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create security handshaker")); } @@ -466,27 +488,27 @@ static grpc_handshaker* fail_handshaker_create() { // static void client_handshaker_factory_add_handshakers( - grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_channel_security_connector* security_connector = (grpc_channel_security_connector*)grpc_security_connector_find_in_args( args); - grpc_channel_security_connector_add_handshakers(security_connector, + grpc_channel_security_connector_add_handshakers(exec_ctx, security_connector, handshake_mgr); } static void server_handshaker_factory_add_handshakers( - grpc_handshaker_factory* hf, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* hf, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_server_security_connector* security_connector = (grpc_server_security_connector*)grpc_security_connector_find_in_args( args); - grpc_server_security_connector_add_handshakers(security_connector, + grpc_server_security_connector_add_handshakers(exec_ctx, security_connector, handshake_mgr); } static void handshaker_factory_destroy( - grpc_handshaker_factory* handshaker_factory) {} + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) {} static const grpc_handshaker_factory_vtable client_handshaker_factory_vtable = { client_handshaker_factory_add_handshakers, handshaker_factory_destroy}; @@ -505,13 +527,14 @@ static grpc_handshaker_factory server_handshaker_factory = { // grpc_handshaker* grpc_security_handshaker_create( - tsi_handshaker* handshaker, grpc_security_connector* connector) { + grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, + grpc_security_connector* connector) { // If no TSI handshaker was created, return a handshaker that always fails. // Otherwise, return a real security handshaker. if (handshaker == nullptr) { return fail_handshaker_create(); } else { - return security_handshaker_create(handshaker, connector); + return security_handshaker_create(exec_ctx, handshaker, connector); } } diff --git a/src/core/lib/security/transport/security_handshaker.h b/src/core/lib/security/transport/security_handshaker.h index 6cd6446b5a..6c3a0510ce 100644 --- a/src/core/lib/security/transport/security_handshaker.h +++ b/src/core/lib/security/transport/security_handshaker.h @@ -25,7 +25,8 @@ /// Creates a security handshaker using \a handshaker. grpc_handshaker* grpc_security_handshaker_create( - tsi_handshaker* handshaker, grpc_security_connector* connector); + grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, + grpc_security_connector* connector); /// Registers security handshaker factories. void grpc_security_register_handshaker_factories(); diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 73653f2a66..9cf368acd0 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -73,7 +73,8 @@ static grpc_metadata_array metadata_batch_to_md_array( return result; } -static grpc_filtered_mdelem remove_consumed_md(void* user_data, +static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_mdelem md) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -87,7 +88,8 @@ static grpc_filtered_mdelem remove_consumed_md(void* user_data, return GRPC_FILTERED_MDELEM(md); } -static void on_md_processing_done_inner(grpc_call_element* elem, +static void on_md_processing_done_inner(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_metadata* consumed_md, size_t num_consumed_md, const grpc_metadata* response_md, @@ -105,10 +107,11 @@ static void on_md_processing_done_inner(grpc_call_element* elem, calld->consumed_md = consumed_md; calld->num_consumed_md = num_consumed_md; error = grpc_metadata_batch_filter( - batch->payload->recv_initial_metadata.recv_initial_metadata, + exec_ctx, batch->payload->recv_initial_metadata.recv_initial_metadata, remove_consumed_md, elem, "Response metadata filtering error"); } - GRPC_CLOSURE_SCHED(calld->original_recv_initial_metadata_ready, error); + GRPC_CLOSURE_SCHED(exec_ctx, calld->original_recv_initial_metadata_ready, + error); } // Called from application code. @@ -118,7 +121,7 @@ static void on_md_processing_done( grpc_status_code status, const char* error_details) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // If the call was not cancelled while we were in flight, process the result. if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_DONE)) { @@ -131,32 +134,34 @@ static void on_md_processing_done( GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_details), GRPC_ERROR_INT_GRPC_STATUS, status); } - on_md_processing_done_inner(elem, consumed_md, num_consumed_md, response_md, - num_response_md, error); + on_md_processing_done_inner(&exec_ctx, elem, consumed_md, num_consumed_md, + response_md, num_response_md, error); } // Clean up. for (size_t i = 0; i < calld->md.count; i++) { - grpc_slice_unref_internal(calld->md.metadata[i].key); - grpc_slice_unref_internal(calld->md.metadata[i].value); + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); } grpc_metadata_array_destroy(&calld->md); - GRPC_CALL_STACK_UNREF(calld->owning_call, "server_auth_metadata"); + GRPC_CALL_STACK_UNREF(&exec_ctx, calld->owning_call, "server_auth_metadata"); + grpc_exec_ctx_finish(&exec_ctx); } -static void cancel_call(void* arg, grpc_error* error) { +static void cancel_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; // If the result was not already processed, invoke the callback now. if (error != GRPC_ERROR_NONE && gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_CANCELLED)) { - on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0, + on_md_processing_done_inner(exec_ctx, elem, nullptr, 0, nullptr, 0, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_call"); + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_call"); } -static void recv_initial_metadata_ready(void* arg, grpc_error* error) { +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -168,7 +173,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) { GRPC_CALL_STACK_REF(calld->owning_call, "cancel_call"); GRPC_CLOSURE_INIT(&calld->cancel_closure, cancel_call, elem, grpc_schedule_on_exec_ctx); - grpc_call_combiner_set_notify_on_cancel(calld->call_combiner, + grpc_call_combiner_set_notify_on_cancel(exec_ctx, calld->call_combiner, &calld->cancel_closure); GRPC_CALL_STACK_REF(calld->owning_call, "server_auth_metadata"); calld->md = metadata_batch_to_md_array( @@ -179,12 +184,13 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) { return; } } - GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } static void auth_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; if (batch->recv_initial_metadata) { // Inject our callback. @@ -194,11 +200,12 @@ static void auth_start_transport_stream_op_batch( batch->payload->recv_initial_metadata.recv_initial_metadata_ready = &calld->recv_initial_metadata_ready; } - grpc_call_next_op(elem, batch); + grpc_call_next_op(exec_ctx, elem, batch); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -224,12 +231,13 @@ static grpc_error* init_call_elem(grpc_call_element* elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); channel_data* chand = (channel_data*)elem->channel_data; @@ -245,10 +253,11 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "server_auth_filter"); - grpc_server_credentials_unref(chand->creds); + grpc_server_credentials_unref(exec_ctx, chand->creds); } const grpc_channel_filter grpc_server_auth_filter = { diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index f36b13ef1b..fe7a86ef84 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -122,8 +122,9 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, result[current - result] = '\0'; } -grpc_slice grpc_base64_decode(const char* b64, int url_safe) { - return grpc_base64_decode_with_len(b64, strlen(b64), url_safe); +grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, + int url_safe) { + return grpc_base64_decode_with_len(exec_ctx, b64, strlen(b64), url_safe); } static void decode_one_char(const unsigned char* codes, unsigned char* result, @@ -184,8 +185,8 @@ static int decode_group(const unsigned char* codes, size_t num_codes, return 1; } -grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, - int url_safe) { +grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, + size_t b64_len, int url_safe) { grpc_slice result = GRPC_SLICE_MALLOC(b64_len); unsigned char* current = GRPC_SLICE_START_PTR(result); size_t result_size = 0; @@ -230,6 +231,6 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, return result; fail: - grpc_slice_unref_internal(result); + grpc_slice_unref_internal(exec_ctx, result); return grpc_empty_slice(); } diff --git a/src/core/lib/slice/b64.h b/src/core/lib/slice/b64.h index 17e7306303..f86c1d9901 100644 --- a/src/core/lib/slice/b64.h +++ b/src/core/lib/slice/b64.h @@ -40,10 +40,11 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, /* Decodes data according to the base64 specification. Returns an empty slice in case of failure. */ -grpc_slice grpc_base64_decode(const char* b64, int url_safe); +grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, + int url_safe); /* Same as above except that the length is provided by the caller. */ -grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, - int url_safe); +grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, + size_t b64_len, int url_safe); #endif /* GRPC_CORE_LIB_SLICE_B64_H */ diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 1eb15290eb..bbaf87ba23 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -54,9 +54,9 @@ grpc_slice grpc_slice_ref_internal(grpc_slice slice) { return slice; } -void grpc_slice_unref_internal(grpc_slice slice) { +void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice) { if (slice.refcount) { - slice.refcount->vtable->unref(slice.refcount); + slice.refcount->vtable->unref(exec_ctx, slice.refcount); } } @@ -67,14 +67,15 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { /* Public API */ void grpc_slice_unref(grpc_slice slice) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_unref_internal(slice); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, slice); + grpc_exec_ctx_finish(&exec_ctx); } /* grpc_slice_from_static_string support structure - a refcount that does nothing */ static void noop_ref(void* unused) {} -static void noop_unref(void* unused) {} +static void noop_unref(grpc_exec_ctx* exec_ctx, void* unused) {} static const grpc_slice_refcount_vtable noop_refcount_vtable = { noop_ref, noop_unref, grpc_slice_default_eq_impl, @@ -108,7 +109,7 @@ static void new_slice_ref(void* p) { gpr_ref(&r->refs); } -static void new_slice_unref(void* p) { +static void new_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { new_slice_refcount* r = (new_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data); @@ -158,7 +159,7 @@ static void new_with_len_ref(void* p) { gpr_ref(&r->refs); } -static void new_with_len_unref(void* p) { +static void new_with_len_unref(grpc_exec_ctx* exec_ctx, void* p) { new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data, r->user_length); @@ -209,7 +210,7 @@ static void malloc_ref(void* p) { gpr_ref(&r->refs); } -static void malloc_unref(void* p) { +static void malloc_unref(grpc_exec_ctx* exec_ctx, void* p) { malloc_refcount* r = (malloc_refcount*)p; if (gpr_unref(&r->refs)) { gpr_free(r); diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 33ec2af683..5db54dad91 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -65,16 +65,18 @@ void grpc_slice_buffer_init(grpc_slice_buffer* sb) { sb->base_slices = sb->slices = sb->inlined; } -void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { - grpc_slice_buffer_reset_and_unref_internal(sb); +void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb) { + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, sb); if (sb->base_slices != sb->inlined) { gpr_free(sb->base_slices); } } void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_destroy_internal(sb); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_destroy_internal(&exec_ctx, sb); + grpc_exec_ctx_finish(&exec_ctx); } uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { @@ -161,10 +163,11 @@ void grpc_slice_buffer_pop(grpc_slice_buffer* sb) { } } -void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { +void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb) { size_t i; for (i = 0; i < sb->count; i++) { - grpc_slice_unref_internal(sb->slices[i]); + grpc_slice_unref_internal(exec_ctx, sb->slices[i]); } sb->count = 0; @@ -172,8 +175,9 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_reset_and_unref_internal(sb); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, sb); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { @@ -285,7 +289,8 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, slice_buffer_move_first_maybe_ref(src, n, dst, false); } -void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, +void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* src, size_t n, void* dst) { char* dstp = (char*)dst; GPR_ASSERT(src->length >= n); @@ -300,13 +305,13 @@ void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, n = 0; } else if (slice_len == n) { memcpy(dstp, GRPC_SLICE_START_PTR(slice), n); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); n = 0; } else { memcpy(dstp, GRPC_SLICE_START_PTR(slice), slice_len); dstp += slice_len; n -= slice_len; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); } } } diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 89340eff84..8f8e5a6b34 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -27,7 +27,7 @@ struct grpc_slice_hash_table { gpr_refcount refs; - void (*destroy_value)(void* value); + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); int (*value_cmp)(void* a, void* b); size_t size; size_t max_num_probes; @@ -58,7 +58,8 @@ static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) { + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), + int (*value_cmp)(void* a, void* b)) { grpc_slice_hash_table* table = (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table)); gpr_ref_init(&table->refs, 1); @@ -80,13 +81,14 @@ grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { return table; } -void grpc_slice_hash_table_unref(grpc_slice_hash_table* table) { +void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table) { if (table != nullptr && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; if (!is_empty(entry)) { - grpc_slice_unref_internal(entry->key); - table->destroy_value(entry->value); + grpc_slice_unref_internal(exec_ctx, entry->key); + table->destroy_value(exec_ctx, entry->value); } } gpr_free(table->entries); diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index db69da662a..85102bd67d 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -46,10 +46,12 @@ typedef struct grpc_slice_hash_table_entry { will be used. */ grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)); + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), + int (*value_cmp)(void* a, void* b)); grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table); -void grpc_slice_hash_table_unref(grpc_slice_hash_table* table); +void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index c578c6d9de..e8949135c0 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -90,7 +90,7 @@ static void interned_slice_destroy(interned_slice_refcount* s) { gpr_mu_unlock(&shard->mu); } -static void interned_slice_unref(void* p) { +static void interned_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { interned_slice_refcount* s = (interned_slice_refcount*)p; if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { interned_slice_destroy(s); @@ -101,8 +101,9 @@ static void interned_slice_sub_ref(void* p) { interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub)); } -static void interned_slice_sub_unref(void* p) { - interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub)); +static void interned_slice_sub_unref(grpc_exec_ctx* exec_ctx, void* p) { + interned_slice_unref(exec_ctx, + ((char*)p) - offsetof(interned_slice_refcount, sub)); } static uint32_t interned_slice_hash(grpc_slice slice) { diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 4e9ab80261..ed0070d375 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -25,11 +25,14 @@ #include "src/core/lib/iomgr/exec_ctx.h" grpc_slice grpc_slice_ref_internal(grpc_slice slice); -void grpc_slice_unref_internal(grpc_slice slice); -void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb); -void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb, +void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice); +void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb); +void grpc_slice_buffer_partial_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb, size_t idx); -void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb); +void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb); /* Check if a slice is interned */ bool grpc_slice_is_interned(grpc_slice slice); diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index f6ea016c33..b1c9f7b164 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -45,11 +45,11 @@ static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } static void alarm_unref(grpc_alarm* alarm) { if (gpr_unref(&alarm->refs)) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; if (alarm->cq != nullptr) { - GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); + GRPC_CQ_INTERNAL_UNREF(&exec_ctx, alarm->cq, "alarm"); } - + grpc_exec_ctx_finish(&exec_ctx); gpr_free(alarm); } } @@ -80,19 +80,20 @@ static void alarm_unref_dbg(grpc_alarm* alarm, const char* reason, } #endif -static void alarm_end_completion(void* arg, grpc_cq_completion* c) { +static void alarm_end_completion(grpc_exec_ctx* exec_ctx, void* arg, + grpc_cq_completion* c) { grpc_alarm* alarm = (grpc_alarm*)arg; GRPC_ALARM_UNREF(alarm, "dequeue-end-op"); } -static void alarm_cb(void* arg, grpc_error* error) { +static void alarm_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_alarm* alarm = (grpc_alarm*)arg; /* We are queuing an op on completion queue. This means, the alarm's structure cannot be destroyed until the op is dequeued. Adding an extra ref here and unref'ing when the op is dequeued will achieve this */ GRPC_ALARM_REF(alarm, "queue-end-op"); - grpc_cq_end_op(alarm->cq, alarm->tag, error, alarm_end_completion, + grpc_cq_end_op(exec_ctx, alarm->cq, alarm->tag, error, alarm_end_completion, (void*)alarm, &alarm->completion); } @@ -115,20 +116,22 @@ grpc_alarm* grpc_alarm_create(void* reserved) { void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, gpr_timespec deadline, void* tag, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_CQ_INTERNAL_REF(cq, "alarm"); alarm->cq = cq; alarm->tag = tag; GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - grpc_timer_init(&alarm->alarm, grpc_timespec_to_millis_round_up(deadline), - &alarm->on_alarm); + grpc_timer_init(&exec_ctx, &alarm->alarm, + grpc_timespec_to_millis_round_up(deadline), &alarm->on_alarm); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { - grpc_core::ExecCtx exec_ctx; - grpc_timer_cancel(&alarm->alarm); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_cancel(&exec_ctx, &alarm->alarm); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved) { diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index e4c2a4a4c2..9e0636b4ce 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -71,13 +71,14 @@ grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { if (!bb) return; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; switch (bb->type) { case GRPC_BB_RAW: - grpc_slice_buffer_destroy_internal(&bb->data.raw.slice_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, &bb->data.raw.slice_buffer); break; } gpr_free(bb); + grpc_exec_ctx_finish(&exec_ctx); } size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) { diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index 81a48e95fc..001227a2aa 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -42,14 +42,15 @@ static int is_compressed(grpc_byte_buffer* buffer) { int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice_buffer decompressed_slices_buffer; reader->buffer_in = buffer; switch (reader->buffer_in->type) { case GRPC_BB_RAW: grpc_slice_buffer_init(&decompressed_slices_buffer); if (is_compressed(reader->buffer_in)) { - if (grpc_msg_decompress(reader->buffer_in->data.raw.compression, + if (grpc_msg_decompress(&exec_ctx, + reader->buffer_in->data.raw.compression, &reader->buffer_in->data.raw.slice_buffer, &decompressed_slices_buffer) == 0) { gpr_log(GPR_ERROR, @@ -63,14 +64,15 @@ int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_raw_byte_buffer_create(decompressed_slices_buffer.slices, decompressed_slices_buffer.count); } - grpc_slice_buffer_destroy_internal(&decompressed_slices_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, + &decompressed_slices_buffer); } else { /* not compressed, use the input buffer as output */ reader->buffer_out = reader->buffer_in; } reader->current.index = 0; break; } - + grpc_exec_ctx_finish(&exec_ctx); return 1; } @@ -110,14 +112,14 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) { grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size); uint8_t* const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { const size_t slice_length = GRPC_SLICE_LENGTH(in_slice); memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length); bytes_read += slice_length; - grpc_slice_unref_internal(in_slice); + grpc_slice_unref_internal(&exec_ctx, in_slice); GPR_ASSERT(bytes_read <= input_size); } - + grpc_exec_ctx_finish(&exec_ctx); return out_slice; } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index a457aaa7a2..a2eb02bd85 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -270,25 +270,30 @@ grpc_core::TraceFlag grpc_compression_trace(false, "compression"); #define CALL_FROM_TOP_ELEM(top_elem) \ CALL_FROM_CALL_STACK(grpc_call_stack_from_top_element(top_elem)) -static void execute_batch(grpc_call* call, grpc_transport_stream_op_batch* op, +static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, + grpc_transport_stream_op_batch* op, grpc_closure* start_batch_closure); -static void cancel_with_status(grpc_call* c, status_source source, - grpc_status_code status, +static void cancel_with_status(grpc_exec_ctx* exec_ctx, grpc_call* c, + status_source source, grpc_status_code status, const char* description); -static void cancel_with_error(grpc_call* c, status_source source, - grpc_error* error); -static void destroy_call(void* call_stack, grpc_error* error); -static void receiving_slice_ready(void* bctlp, grpc_error* error); -static void get_final_status( - grpc_call* call, void (*set_value)(grpc_status_code code, void* user_data), - void* set_value_user_data, grpc_slice* details, const char** error_string); -static void set_status_value_directly(grpc_status_code status, void* dest); -static void set_status_from_error(grpc_call* call, status_source source, +static void cancel_with_error(grpc_exec_ctx* exec_ctx, grpc_call* c, + status_source source, grpc_error* error); +static void destroy_call(grpc_exec_ctx* exec_ctx, void* call_stack, + grpc_error* error); +static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, grpc_error* error); -static void process_data_after_md(batch_control* bctl); -static void post_batch_completion(batch_control* bctl); -static void add_batch_error(batch_control* bctl, grpc_error* error, - bool has_cancelled); +static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, + void (*set_value)(grpc_status_code code, + void* user_data), + void* set_value_user_data, grpc_slice* details, + const char** error_string); +static void set_status_value_directly(grpc_status_code status, void* dest); +static void set_status_from_error(grpc_exec_ctx* exec_ctx, grpc_call* call, + status_source source, grpc_error* error); +static void process_data_after_md(grpc_exec_ctx* exec_ctx, batch_control* bctl); +static void post_batch_completion(grpc_exec_ctx* exec_ctx, batch_control* bctl); +static void add_batch_error(grpc_exec_ctx* exec_ctx, batch_control* bctl, + grpc_error* error, bool has_cancelled); static void add_init_error(grpc_error** composite, grpc_error* new_err) { if (new_err == GRPC_ERROR_NONE) return; @@ -306,8 +311,7 @@ static parent_call* get_or_create_parent_call(grpc_call* call) { if (p == nullptr) { p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p)); gpr_mu_init(&p->child_list_mu); - if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm) nullptr, - (gpr_atm)p)) { + if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm)NULL, (gpr_atm)p)) { gpr_mu_destroy(&p->child_list_mu); p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); } @@ -319,7 +323,8 @@ static parent_call* get_parent_call(grpc_call* call) { return (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); } -grpc_error* grpc_call_create(const grpc_call_create_args* args, +grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, + const grpc_call_create_args* args, grpc_call** out_call) { size_t i, j; grpc_error* error = GRPC_ERROR_NONE; @@ -328,7 +333,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, grpc_call* call; GPR_TIMER_BEGIN("grpc_call_create", 0); size_t initial_size = grpc_channel_get_call_size_estimate(args->channel); - GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size); + GRPC_STATS_INC_CALL_INITIAL_SIZE(exec_ctx, initial_size); gpr_arena* arena = gpr_arena_create(initial_size); call = (grpc_call*)gpr_arena_alloc( arena, sizeof(grpc_call) + channel_stack->call_stack_size); @@ -343,9 +348,9 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); call->is_client = args->server_transport_data == nullptr; if (call->is_client) { - GRPC_STATS_INC_CLIENT_CALLS_CREATED(); + GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx); } else { - GRPC_STATS_INC_SERVER_CALLS_CREATED(); + GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx); } call->stream_op_payload.context = call->context; grpc_slice path = grpc_empty_slice(); @@ -440,13 +445,15 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, send_deadline, call->arena, &call->call_combiner}; - add_init_error(&error, grpc_call_stack_init(channel_stack, 1, destroy_call, - call, &call_args)); + add_init_error(&error, grpc_call_stack_init(exec_ctx, channel_stack, 1, + destroy_call, call, &call_args)); if (error != GRPC_ERROR_NONE) { - cancel_with_error(call, STATUS_FROM_SURFACE, GRPC_ERROR_REF(error)); + cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_ERROR_REF(error)); } if (immediately_cancel) { - cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); + cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, + GRPC_ERROR_CANCELLED); } if (args->cq != nullptr) { GPR_ASSERT( @@ -461,17 +468,17 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, args->pollset_set_alternative); } if (!grpc_polling_entity_is_empty(&call->pollent)) { - grpc_call_stack_set_pollset_or_pollset_set(CALL_STACK_FROM_CALL(call), - &call->pollent); + grpc_call_stack_set_pollset_or_pollset_set( + exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); } - grpc_slice_unref_internal(path); + grpc_slice_unref_internal(exec_ctx, path); GPR_TIMER_END("grpc_call_create", 0); return error; } -void grpc_call_set_completion_queue(grpc_call* call, +void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_completion_queue* cq) { GPR_ASSERT(cq); @@ -482,8 +489,8 @@ void grpc_call_set_completion_queue(grpc_call* call, call->cq = cq; GRPC_CQ_INTERNAL_REF(cq, "bind"); call->pollent = grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)); - grpc_call_stack_set_pollset_or_pollset_set(CALL_STACK_FROM_CALL(call), - &call->pollent); + grpc_call_stack_set_pollset_or_pollset_set( + exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); } #ifndef NDEBUG @@ -496,38 +503,40 @@ void grpc_call_set_completion_queue(grpc_call* call, void grpc_call_internal_ref(grpc_call* c REF_ARG) { GRPC_CALL_STACK_REF(CALL_STACK_FROM_CALL(c), REF_REASON); } -void grpc_call_internal_unref(grpc_call* c REF_ARG) { - GRPC_CALL_STACK_UNREF(CALL_STACK_FROM_CALL(c), REF_REASON); +void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* c REF_ARG) { + GRPC_CALL_STACK_UNREF(exec_ctx, CALL_STACK_FROM_CALL(c), REF_REASON); } -static void release_call(void* call, grpc_error* error) { +static void release_call(grpc_exec_ctx* exec_ctx, void* call, + grpc_error* error) { grpc_call* c = (grpc_call*)call; grpc_channel* channel = c->channel; grpc_call_combiner_destroy(&c->call_combiner); gpr_free((char*)c->peer_string); grpc_channel_update_call_size_estimate(channel, gpr_arena_destroy(c->arena)); - GRPC_CHANNEL_INTERNAL_UNREF(channel, "call"); + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "call"); } static void set_status_value_directly(grpc_status_code status, void* dest); -static void destroy_call(void* call, grpc_error* error) { +static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, + grpc_error* error) { size_t i; int ii; grpc_call* c = (grpc_call*)call; GPR_TIMER_BEGIN("destroy_call", 0); for (i = 0; i < 2; i++) { grpc_metadata_batch_destroy( - &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); + exec_ctx, &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); } if (c->receiving_stream != nullptr) { - grpc_byte_stream_destroy(c->receiving_stream); + grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } parent_call* pc = get_parent_call(c); if (pc != nullptr) { gpr_mu_destroy(&pc->child_list_mu); } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { - GRPC_MDELEM_UNREF(c->send_extra_metadata[ii].md); + GRPC_MDELEM_UNREF(exec_ctx, c->send_extra_metadata[ii].md); } for (i = 0; i < GRPC_CONTEXT_COUNT; i++) { if (c->context[i].destroy) { @@ -535,11 +544,12 @@ static void destroy_call(void* call, grpc_error* error) { } } if (c->cq) { - GRPC_CQ_INTERNAL_UNREF(c->cq, "bind"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, c->cq, "bind"); } - get_final_status(c, set_status_value_directly, &c->final_info.final_status, - nullptr, c->final_info.error_string); + get_final_status(exec_ctx, c, set_status_value_directly, + &c->final_info.final_status, nullptr, + c->final_info.error_string); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); @@ -548,7 +558,7 @@ static void destroy_call(void* call, grpc_error* error) { unpack_received_status(gpr_atm_acq_load(&c->status[i])).error); } - grpc_call_stack_destroy(CALL_STACK_FROM_CALL(c), &c->final_info, + grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), &c->final_info, GRPC_CLOSURE_INIT(&c->release_call, release_call, c, grpc_schedule_on_exec_ctx)); GPR_TIMER_END("destroy_call", 0); @@ -560,7 +570,7 @@ void grpc_call_unref(grpc_call* c) { if (!gpr_unref(&c->ext_ref)) return; child_call* cc = c->child; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_TIMER_BEGIN("grpc_call_unref", 0); GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c)); @@ -577,7 +587,7 @@ void grpc_call_unref(grpc_call* c) { cc->sibling_prev->child->sibling_next = cc->sibling_next; cc->sibling_next->child->sibling_prev = cc->sibling_prev; gpr_mu_unlock(&pc->child_list_mu); - GRPC_CALL_INTERNAL_UNREF(cc->parent, "child"); + GRPC_CALL_INTERNAL_UNREF(&exec_ctx, cc->parent, "child"); } GPR_ASSERT(!c->destroy_called); @@ -585,49 +595,53 @@ void grpc_call_unref(grpc_call* c) { bool cancel = gpr_atm_acq_load(&c->any_ops_sent_atm) != 0 && gpr_atm_acq_load(&c->received_final_op_atm) == 0; if (cancel) { - cancel_with_error(c, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); + cancel_with_error(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, + GRPC_ERROR_CANCELLED); } else { // Unset the call combiner cancellation closure. This has the // effect of scheduling the previously set cancellation closure, if // any, so that it can release any internal references it may be // holding to the call stack. - grpc_call_combiner_set_notify_on_cancel(&c->call_combiner, nullptr); + grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, + nullptr); } - GRPC_CALL_INTERNAL_UNREF(c, "destroy"); - + GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); + grpc_exec_ctx_finish(&exec_ctx); GPR_TIMER_END("grpc_call_unref", 0); } grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx exec_ctx; - cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + cancel_with_error(&exec_ctx, call, STATUS_FROM_API_OVERRIDE, + GRPC_ERROR_CANCELLED); + grpc_exec_ctx_finish(&exec_ctx); return GRPC_CALL_OK; } // This is called via the call combiner to start sending a batch down // the filter stack. -static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) { +static void execute_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* ignored) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call* call = (grpc_call*)batch->handler_private.extra_arg; GPR_TIMER_BEGIN("execute_batch", 0); grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, batch); - elem->filter->start_transport_stream_op_batch(elem, batch); + elem->filter->start_transport_stream_op_batch(exec_ctx, elem, batch); GPR_TIMER_END("execute_batch", 0); } // start_batch_closure points to a caller-allocated closure to be used // for entering the call combiner. -static void execute_batch(grpc_call* call, +static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_transport_stream_op_batch* batch, grpc_closure* start_batch_closure) { batch->handler_private.extra_arg = call; GRPC_CLOSURE_INIT(start_batch_closure, execute_batch_in_call_combiner, batch, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(&call->call_combiner, start_batch_closure, + GRPC_CALL_COMBINER_START(exec_ctx, &call->call_combiner, start_batch_closure, GRPC_ERROR_NONE, "executing batch"); } @@ -651,14 +665,15 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, grpc_status_code status, const char* description, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", 4, (c, (int)status, description, reserved)); GPR_ASSERT(reserved == nullptr); - cancel_with_status(c, STATUS_FROM_API_OVERRIDE, status, description); - + cancel_with_status(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, status, + description); + grpc_exec_ctx_finish(&exec_ctx); return GRPC_CALL_OK; } @@ -670,23 +685,24 @@ typedef struct { // The on_complete callback used when sending a cancel_stream batch down // the filter stack. Yields the call combiner when the batch is done. -static void done_termination(void* arg, grpc_error* error) { +static void done_termination(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { cancel_state* state = (cancel_state*)arg; - GRPC_CALL_COMBINER_STOP(&state->call->call_combiner, + GRPC_CALL_COMBINER_STOP(exec_ctx, &state->call->call_combiner, "on_complete for cancel_stream op"); - GRPC_CALL_INTERNAL_UNREF(state->call, "termination"); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, state->call, "termination"); gpr_free(state); } -static void cancel_with_error(grpc_call* c, status_source source, - grpc_error* error) { +static void cancel_with_error(grpc_exec_ctx* exec_ctx, grpc_call* c, + status_source source, grpc_error* error) { GRPC_CALL_INTERNAL_REF(c, "termination"); // Inform the call combiner of the cancellation, so that it can cancel // any in-flight asynchronous actions that may be holding the call // combiner. This ensures that the cancel_stream batch can be sent // down the filter stack in a timely manner. - grpc_call_combiner_cancel(&c->call_combiner, GRPC_ERROR_REF(error)); - set_status_from_error(c, source, GRPC_ERROR_REF(error)); + grpc_call_combiner_cancel(exec_ctx, &c->call_combiner, GRPC_ERROR_REF(error)); + set_status_from_error(exec_ctx, c, source, GRPC_ERROR_REF(error)); cancel_state* state = (cancel_state*)gpr_malloc(sizeof(*state)); state->call = c; GRPC_CLOSURE_INIT(&state->finish_batch, done_termination, state, @@ -695,7 +711,7 @@ static void cancel_with_error(grpc_call* c, status_source source, grpc_make_transport_stream_op(&state->finish_batch); op->cancel_stream = true; op->payload->cancel_stream.cancel_error = error; - execute_batch(c, op, &state->start_batch); + execute_batch(exec_ctx, c, op, &state->start_batch); } static grpc_error* error_from_status(grpc_status_code status, @@ -709,10 +725,11 @@ static grpc_error* error_from_status(grpc_status_code status, GRPC_ERROR_INT_GRPC_STATUS, status); } -static void cancel_with_status(grpc_call* c, status_source source, - grpc_status_code status, +static void cancel_with_status(grpc_exec_ctx* exec_ctx, grpc_call* c, + status_source source, grpc_status_code status, const char* description) { - cancel_with_error(c, source, error_from_status(status, description)); + cancel_with_error(exec_ctx, c, source, + error_from_status(status, description)); } /******************************************************************************* @@ -720,13 +737,14 @@ static void cancel_with_status(grpc_call* c, status_source source, */ static bool get_final_status_from( - grpc_call* call, grpc_error* error, bool allow_ok_status, + grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_error* error, + bool allow_ok_status, void (*set_value)(grpc_status_code code, void* user_data), void* set_value_user_data, grpc_slice* details, const char** error_string) { grpc_status_code code; grpc_slice slice = grpc_empty_slice(); - grpc_error_get_status(error, call->send_deadline, &code, &slice, nullptr, - error_string); + grpc_error_get_status(exec_ctx, error, call->send_deadline, &code, &slice, + nullptr, error_string); if (code == GRPC_STATUS_OK && !allow_ok_status) { return false; } @@ -738,9 +756,11 @@ static bool get_final_status_from( return true; } -static void get_final_status( - grpc_call* call, void (*set_value)(grpc_status_code code, void* user_data), - void* set_value_user_data, grpc_slice* details, const char** error_string) { +static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, + void (*set_value)(grpc_status_code code, + void* user_data), + void* set_value_user_data, grpc_slice* details, + const char** error_string) { int i; received_status status[STATUS_SOURCE_COUNT]; for (i = 0; i < STATUS_SOURCE_COUNT; i++) { @@ -762,9 +782,9 @@ static void get_final_status( for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (status[i].is_set && grpc_error_has_clear_grpc_status(status[i].error)) { - if (get_final_status_from(call, status[i].error, allow_ok_status != 0, - set_value, set_value_user_data, details, - error_string)) { + if (get_final_status_from(exec_ctx, call, status[i].error, + allow_ok_status != 0, set_value, + set_value_user_data, details, error_string)) { return; } } @@ -772,9 +792,9 @@ static void get_final_status( /* If no clearly defined status exists, search for 'anything' */ for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (status[i].is_set) { - if (get_final_status_from(call, status[i].error, allow_ok_status != 0, - set_value, set_value_user_data, details, - error_string)) { + if (get_final_status_from(exec_ctx, call, status[i].error, + allow_ok_status != 0, set_value, + set_value_user_data, details, error_string)) { return; } } @@ -788,8 +808,8 @@ static void get_final_status( } } -static void set_status_from_error(grpc_call* call, status_source source, - grpc_error* error) { +static void set_status_from_error(grpc_exec_ctx* exec_ctx, grpc_call* call, + status_source source, grpc_error* error) { if (!gpr_atm_rel_cas(&call->status[source], pack_received_status({false, GRPC_ERROR_NONE}), pack_received_status({true, error}))) { @@ -841,7 +861,8 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call* call) { static void destroy_encodings_accepted_by_peer(void* p) { return; } -static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { +static void set_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, + grpc_call* call, grpc_mdelem mdel) { size_t i; grpc_compression_algorithm algorithm; grpc_slice_buffer accept_encoding_parts; @@ -879,14 +900,15 @@ static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { } } - grpc_slice_buffer_destroy_internal(&accept_encoding_parts); + grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, (void*)(((uintptr_t)call->encodings_accepted_by_peer) + 1)); } -static void set_stream_encodings_accepted_by_peer(grpc_call* call, +static void set_stream_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, + grpc_call* call, grpc_mdelem mdel) { size_t i; grpc_stream_compression_algorithm algorithm; @@ -924,7 +946,7 @@ static void set_stream_encodings_accepted_by_peer(grpc_call* call, } } - grpc_slice_buffer_destroy_internal(&accept_encoding_parts); + grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, @@ -962,12 +984,10 @@ static grpc_metadata* get_md_elem(grpc_metadata* metadata, return res; } -static int prepare_application_metadata(grpc_call* call, int count, - grpc_metadata* metadata, - int is_trailing, - int prepend_extra_metadata, - grpc_metadata* additional_metadata, - int additional_metadata_count) { +static int prepare_application_metadata( + grpc_exec_ctx* exec_ctx, grpc_call* call, int count, + grpc_metadata* metadata, int is_trailing, int prepend_extra_metadata, + grpc_metadata* additional_metadata, int additional_metadata_count) { int total_count = count + additional_metadata_count; int i; grpc_metadata_batch* batch = @@ -986,14 +1006,14 @@ static int prepare_application_metadata(grpc_call* call, int count, grpc_validate_header_nonbin_value_is_legal(md->value))) { break; } - l->md = grpc_mdelem_from_grpc_metadata((grpc_metadata*)md); + l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata*)md); } if (i != total_count) { for (int j = 0; j < i; j++) { const grpc_metadata* md = get_md_elem(metadata, additional_metadata, j, count); grpc_linked_mdelem* l = linked_from_md(md); - GRPC_MDELEM_UNREF(l->md); + GRPC_MDELEM_UNREF(exec_ctx, l->md); } return 0; } @@ -1004,16 +1024,16 @@ static int prepare_application_metadata(grpc_call* call, int count, for (i = 0; i < call->send_extra_metadata_count; i++) { GRPC_LOG_IF_ERROR("prepare_application_metadata", grpc_metadata_batch_link_tail( - batch, &call->send_extra_metadata[i])); + exec_ctx, batch, &call->send_extra_metadata[i])); } } } for (i = 0; i < total_count; i++) { grpc_metadata* md = get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem* l = linked_from_md(md); - grpc_error* error = grpc_metadata_batch_link_tail(batch, l); + grpc_error* error = grpc_metadata_batch_link_tail(exec_ctx, batch, l); if (error != GRPC_ERROR_NONE) { - GRPC_MDELEM_UNREF(l->md); + GRPC_MDELEM_UNREF(exec_ctx, l->md); } GRPC_LOG_IF_ERROR("prepare_application_metadata", error); } @@ -1100,43 +1120,46 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, GPR_TIMER_END("publish_app_metadata", 0); } -static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) { +static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, + grpc_metadata_batch* b) { if (b->idx.named.content_encoding != nullptr) { if (b->idx.named.grpc_encoding != nullptr) { gpr_log(GPR_ERROR, "Received both content-encoding and grpc-encoding header. " "Ignoring grpc-encoding."); - grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); } GPR_TIMER_BEGIN("incoming_stream_compression_algorithm", 0); set_incoming_stream_compression_algorithm( call, decode_stream_compression(b->idx.named.content_encoding->md)); GPR_TIMER_END("incoming_stream_compression_algorithm", 0); - grpc_metadata_batch_remove(b, b->idx.named.content_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_encoding); } else if (b->idx.named.grpc_encoding != nullptr) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm( call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); - grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); } if (b->idx.named.grpc_accept_encoding != nullptr) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(call, b->idx.named.grpc_accept_encoding->md); - grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); + set_encodings_accepted_by_peer(exec_ctx, call, + b->idx.named.grpc_accept_encoding->md); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } if (b->idx.named.accept_encoding != nullptr) { GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); - set_stream_encodings_accepted_by_peer(call, + set_stream_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.accept_encoding->md); - grpc_metadata_batch_remove(b, b->idx.named.accept_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.accept_encoding); GPR_TIMER_END("stream_encodings_accepted_by_peer", 0); } publish_app_metadata(call, b, false); } -static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { +static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, + grpc_metadata_batch* b) { grpc_call* call = (grpc_call*)args; if (b->idx.named.grpc_status != nullptr) { uint32_t status_code = decode_status(b->idx.named.grpc_status->md); @@ -1151,13 +1174,13 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { error = grpc_error_set_str( error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); - grpc_metadata_batch_remove(b, b->idx.named.grpc_message); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); } else if (error != GRPC_ERROR_NONE) { error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_empty_slice()); } - set_status_from_error(call, STATUS_FROM_WIRE, error); - grpc_metadata_batch_remove(b, b->idx.named.grpc_status); + set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); } publish_app_metadata(call, b, true); } @@ -1234,12 +1257,12 @@ static batch_control* allocate_batch_control(grpc_call* call, return bctl; } -static void finish_batch_completion(void* user_data, +static void finish_batch_completion(grpc_exec_ctx* exec_ctx, void* user_data, grpc_cq_completion* storage) { batch_control* bctl = (batch_control*)user_data; grpc_call* call = bctl->call; bctl->call = nullptr; - GRPC_CALL_INTERNAL_UNREF(call, "completion"); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } static grpc_error* consolidate_batch_errors(batch_control* bctl) { @@ -1263,13 +1286,15 @@ static grpc_error* consolidate_batch_errors(batch_control* bctl) { } } -static void post_batch_completion(batch_control* bctl) { +static void post_batch_completion(grpc_exec_ctx* exec_ctx, + batch_control* bctl) { grpc_call* next_child_call; grpc_call* call = bctl->call; grpc_error* error = consolidate_batch_errors(bctl); if (bctl->op.send_initial_metadata) { grpc_metadata_batch_destroy( + exec_ctx, &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); } if (bctl->op.send_message) { @@ -1277,12 +1302,13 @@ static void post_batch_completion(batch_control* bctl) { } if (bctl->op.send_trailing_metadata) { grpc_metadata_batch_destroy( + exec_ctx, &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); } if (bctl->op.recv_trailing_metadata) { grpc_metadata_batch* md = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - recv_trailing_filter(call, md); + recv_trailing_filter(exec_ctx, call, md); /* propagate cancellation to any interested children */ gpr_atm_rel_store(&call->received_final_op_atm, 1); @@ -1296,9 +1322,9 @@ static void post_batch_completion(batch_control* bctl) { next_child_call = child->child->sibling_next; if (child->cancellation_is_inherited) { GRPC_CALL_INTERNAL_REF(child, "propagate_cancel"); - cancel_with_error(child, STATUS_FROM_API_OVERRIDE, + cancel_with_error(exec_ctx, child, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); - GRPC_CALL_INTERNAL_UNREF(child, "propagate_cancel"); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, child, "propagate_cancel"); } child = next_child_call; } while (child != pc->first_child); @@ -1307,12 +1333,12 @@ static void post_batch_completion(batch_control* bctl) { } if (call->is_client) { - get_final_status(call, set_status_value_directly, + get_final_status(exec_ctx, call, set_status_value_directly, call->final_op.client.status, call->final_op.client.status_details, call->final_op.client.error_string); } else { - get_final_status(call, set_cancelled_value, + get_final_status(exec_ctx, call, set_cancelled_value, call->final_op.server.cancelled, nullptr, nullptr); } @@ -1328,24 +1354,25 @@ static void post_batch_completion(batch_control* bctl) { if (bctl->completion_data.notify_tag.is_closure) { /* unrefs bctl->error */ bctl->call = nullptr; - GRPC_CLOSURE_RUN((grpc_closure*)bctl->completion_data.notify_tag.tag, - error); - GRPC_CALL_INTERNAL_UNREF(call, "completion"); + GRPC_CLOSURE_RUN( + exec_ctx, (grpc_closure*)bctl->completion_data.notify_tag.tag, error); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } else { /* unrefs bctl->error */ - grpc_cq_end_op(bctl->call->cq, bctl->completion_data.notify_tag.tag, error, - finish_batch_completion, bctl, - &bctl->completion_data.cq_completion); + grpc_cq_end_op( + exec_ctx, bctl->call->cq, bctl->completion_data.notify_tag.tag, error, + finish_batch_completion, bctl, &bctl->completion_data.cq_completion); } } -static void finish_batch_step(batch_control* bctl) { +static void finish_batch_step(grpc_exec_ctx* exec_ctx, batch_control* bctl) { if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(bctl); + post_batch_completion(exec_ctx, bctl); } } -static void continue_receiving_slices(batch_control* bctl) { +static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, + batch_control* bctl) { grpc_error* error; grpc_call* call = bctl->call; for (;;) { @@ -1353,25 +1380,25 @@ static void continue_receiving_slices(batch_control* bctl) { (*call->receiving_buffer)->data.raw.slice_buffer.length; if (remaining == 0) { call->receiving_message = 0; - grpc_byte_stream_destroy(call->receiving_stream); + grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = nullptr; - finish_batch_step(bctl); + finish_batch_step(exec_ctx, bctl); return; } - if (grpc_byte_stream_next(call->receiving_stream, remaining, + if (grpc_byte_stream_next(exec_ctx, call->receiving_stream, remaining, &call->receiving_slice_ready)) { - error = - grpc_byte_stream_pull(call->receiving_stream, &call->receiving_slice); + error = grpc_byte_stream_pull(exec_ctx, call->receiving_stream, + &call->receiving_slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer, call->receiving_slice); } else { - grpc_byte_stream_destroy(call->receiving_stream); + grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(bctl); + finish_batch_step(exec_ctx, bctl); return; } } else { @@ -1380,7 +1407,8 @@ static void continue_receiving_slices(batch_control* bctl) { } } -static void receiving_slice_ready(void* bctlp, grpc_error* error) { +static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, + grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; grpc_byte_stream* bs = call->receiving_stream; @@ -1388,11 +1416,11 @@ static void receiving_slice_ready(void* bctlp, grpc_error* error) { if (error == GRPC_ERROR_NONE) { grpc_slice slice; - error = grpc_byte_stream_pull(bs, &slice); + error = grpc_byte_stream_pull(exec_ctx, bs, &slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer, slice); - continue_receiving_slices(bctl); + continue_receiving_slices(exec_ctx, bctl); } else { /* Error returned by grpc_byte_stream_pull needs to be released manually */ @@ -1404,24 +1432,25 @@ static void receiving_slice_ready(void* bctlp, grpc_error* error) { if (grpc_trace_operation_failures.enabled()) { GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error)); } - grpc_byte_stream_destroy(call->receiving_stream); + grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(bctl); + finish_batch_step(exec_ctx, bctl); if (release_error) { GRPC_ERROR_UNREF(error); } } } -static void process_data_after_md(batch_control* bctl) { +static void process_data_after_md(grpc_exec_ctx* exec_ctx, + batch_control* bctl) { grpc_call* call = bctl->call; if (call->receiving_stream == nullptr) { *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(bctl); + finish_batch_step(exec_ctx, bctl); } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && @@ -1433,42 +1462,46 @@ static void process_data_after_md(batch_control* bctl) { } GRPC_CLOSURE_INIT(&call->receiving_slice_ready, receiving_slice_ready, bctl, grpc_schedule_on_exec_ctx); - continue_receiving_slices(bctl); + continue_receiving_slices(exec_ctx, bctl); } } -static void receiving_stream_ready(void* bctlp, grpc_error* error) { +static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, + grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; if (error != GRPC_ERROR_NONE) { if (call->receiving_stream != nullptr) { - grpc_byte_stream_destroy(call->receiving_stream); + grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = nullptr; } - add_batch_error(bctl, GRPC_ERROR_REF(error), true); - cancel_with_error(call, STATUS_FROM_SURFACE, GRPC_ERROR_REF(error)); + add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), true); + cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_ERROR_REF(error)); } /* If recv_state is RECV_NONE, we will save the batch_control * object with rel_cas, and will not use it after the cas. Its corresponding * acq_load is in receiving_initial_metadata_ready() */ if (error != GRPC_ERROR_NONE || call->receiving_stream == nullptr || !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) { - process_data_after_md(bctl); + process_data_after_md(exec_ctx, bctl); } } // The recv_message_ready callback used when sending a batch containing // a recv_message op down the filter stack. Yields the call combiner // before processing the received message. -static void receiving_stream_ready_in_call_combiner(void* bctlp, +static void receiving_stream_ready_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_message_ready"); - receiving_stream_ready(bctlp, error); + GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, "recv_message_ready"); + receiving_stream_ready(exec_ctx, bctlp, error); } -static void validate_filtered_metadata(batch_control* bctl) { +static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, + batch_control* bctl) { grpc_call* call = bctl->call; /* validate compression algorithms */ if (call->incoming_stream_compression_algorithm != @@ -1482,8 +1515,8 @@ static void validate_filtered_metadata(batch_control* bctl) { gpr_asprintf(&error_msg, "Invalid stream compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); + cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_STATUS_UNIMPLEMENTED, error_msg); } else if (grpc_compression_options_is_stream_compression_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1492,8 +1525,8 @@ static void validate_filtered_metadata(batch_control* bctl) { gpr_asprintf(&error_msg, "Stream compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); + cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_STATUS_UNIMPLEMENTED, error_msg); } gpr_free(error_msg); @@ -1523,8 +1556,8 @@ static void validate_filtered_metadata(batch_control* bctl) { gpr_asprintf(&error_msg, "Invalid compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); + cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_STATUS_UNIMPLEMENTED, error_msg); } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1533,8 +1566,8 @@ static void validate_filtered_metadata(batch_control* bctl) { gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, - error_msg); + cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, + GRPC_STATUS_UNIMPLEMENTED, error_msg); } else { call->incoming_compression_algorithm = algo; } @@ -1557,31 +1590,34 @@ static void validate_filtered_metadata(batch_control* bctl) { } } -static void add_batch_error(batch_control* bctl, grpc_error* error, - bool has_cancelled) { +static void add_batch_error(grpc_exec_ctx* exec_ctx, batch_control* bctl, + grpc_error* error, bool has_cancelled) { if (error == GRPC_ERROR_NONE) return; int idx = (int)gpr_atm_full_fetch_add(&bctl->num_errors, 1); if (idx == 0 && !has_cancelled) { - cancel_with_error(bctl->call, STATUS_FROM_CORE, GRPC_ERROR_REF(error)); + cancel_with_error(exec_ctx, bctl->call, STATUS_FROM_CORE, + GRPC_ERROR_REF(error)); } bctl->errors[idx] = error; } -static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { +static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, + void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_initial_metadata_ready"); + GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, + "recv_initial_metadata_ready"); - add_batch_error(bctl, GRPC_ERROR_REF(error), false); + add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), false); if (error == GRPC_ERROR_NONE) { grpc_metadata_batch* md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; - recv_initial_filter(call, md); + recv_initial_filter(exec_ctx, call, md); /* TODO(ctiller): this could be moved into recv_initial_filter now */ GPR_TIMER_BEGIN("validate_filtered_metadata", 0); - validate_filtered_metadata(bctl); + validate_filtered_metadata(exec_ctx, bctl); GPR_TIMER_END("validate_filtered_metadata", 0); if (md->deadline != GRPC_MILLIS_INF_FUTURE && !call->is_client) { @@ -1614,25 +1650,28 @@ static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { } } if (saved_rsr_closure != nullptr) { - GRPC_CLOSURE_RUN(saved_rsr_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, saved_rsr_closure, GRPC_ERROR_REF(error)); } - finish_batch_step(bctl); + finish_batch_step(exec_ctx, bctl); } -static void finish_batch(void* bctlp, grpc_error* error) { +static void finish_batch(grpc_exec_ctx* exec_ctx, void* bctlp, + grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(&call->call_combiner, "on_complete"); - add_batch_error(bctl, GRPC_ERROR_REF(error), false); - finish_batch_step(bctl); + GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, "on_complete"); + add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), false); + finish_batch_step(exec_ctx, bctl); } -static void free_no_op_completion(void* p, grpc_cq_completion* completion) { +static void free_no_op_completion(grpc_exec_ctx* exec_ctx, void* p, + grpc_cq_completion* completion) { gpr_free(completion); } -static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, +static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, + grpc_call* call, const grpc_op* ops, size_t nops, void* notify_tag, int is_notify_tag_closure) { size_t i; @@ -1650,10 +1689,11 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, if (!is_notify_tag_closure) { GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); grpc_cq_end_op( - call->cq, notify_tag, GRPC_ERROR_NONE, free_no_op_completion, nullptr, + exec_ctx, call->cq, notify_tag, GRPC_ERROR_NONE, + free_no_op_completion, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); } else { - GRPC_CLOSURE_SCHED((grpc_closure*)notify_tag, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)notify_tag, GRPC_ERROR_NONE); } error = GRPC_CALL_OK; goto done; @@ -1753,7 +1793,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, stream_op->send_initial_metadata = true; call->sent_initial_metadata = true; if (!prepare_application_metadata( - call, (int)op->data.send_initial_metadata.count, + exec_ctx, call, (int)op->data.send_initial_metadata.count, op->data.send_initial_metadata.metadata, 0, call->is_client, &call->compression_md, (int)additional_metadata_count)) { error = GRPC_CALL_ERROR_INVALID_METADATA; @@ -1847,7 +1887,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, GPR_ASSERT(call->send_extra_metadata_count == 0); call->send_extra_metadata_count = 1; call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( - call->channel, op->data.send_status_from_server.status); + exec_ctx, call->channel, op->data.send_status_from_server.status); { grpc_error* override_error = GRPC_ERROR_NONE; if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { @@ -1856,7 +1896,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, } if (op->data.send_status_from_server.status_details != nullptr) { call->send_extra_metadata[1].md = grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_MESSAGE, + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal( *op->data.send_status_from_server.status_details)); call->send_extra_metadata_count++; @@ -1867,15 +1907,16 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, grpc_slice_from_copied_string(msg)); gpr_free(msg); } - set_status_from_error(call, STATUS_FROM_API_OVERRIDE, override_error); + set_status_from_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, + override_error); } if (!prepare_application_metadata( - call, + exec_ctx, call, (int)op->data.send_status_from_server.trailing_metadata_count, op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { - GRPC_MDELEM_UNREF(call->send_extra_metadata[n].md); + GRPC_MDELEM_UNREF(exec_ctx, call->send_extra_metadata[n].md); } call->send_extra_metadata_count = 0; error = GRPC_CALL_ERROR_INVALID_METADATA; @@ -2004,7 +2045,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, stream_op->on_complete = &bctl->finish_batch; gpr_atm_rel_store(&call->any_ops_sent_atm, 1); - execute_batch(call, stream_op, &bctl->start_batch); + execute_batch(exec_ctx, call, stream_op, &bctl->start_batch); done: GPR_TIMER_END("grpc_call_start_batch", 0); @@ -2014,15 +2055,15 @@ done_with_error: /* reverse any mutations that occured */ if (stream_op->send_initial_metadata) { call->sent_initial_metadata = false; - grpc_metadata_batch_clear(&call->metadata_batch[0][0]); + grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][0]); } if (stream_op->send_message) { call->sending_message = false; - grpc_byte_stream_destroy(&call->sending_stream.base); + grpc_byte_stream_destroy(exec_ctx, &call->sending_stream.base); } if (stream_op->send_trailing_metadata) { call->sent_final_op = false; - grpc_metadata_batch_clear(&call->metadata_batch[0][1]); + grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][1]); } if (stream_op->recv_initial_metadata) { call->received_initial_metadata = false; @@ -2038,7 +2079,7 @@ done_with_error: grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* tag, void* reserved) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call_error err; GRPC_API_TRACE( @@ -2049,17 +2090,19 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, if (reserved != nullptr) { err = GRPC_CALL_ERROR; } else { - err = call_start_batch(call, ops, nops, tag, 0); + err = call_start_batch(&exec_ctx, call, ops, nops, tag, 0); } + grpc_exec_ctx_finish(&exec_ctx); return err; } -grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call, +grpc_call_error grpc_call_start_batch_and_execute(grpc_exec_ctx* exec_ctx, + grpc_call* call, const grpc_op* ops, size_t nops, grpc_closure* closure) { - return call_start_batch(call, ops, nops, closure, 1); + return call_start_batch(exec_ctx, call, ops, nops, closure, 1); } void grpc_call_context_set(grpc_call* call, grpc_context_index elem, diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 189329ccc4..1d2e266717 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -26,7 +26,8 @@ #include #include -typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success, +typedef void (*grpc_ioreq_completion_func)(grpc_exec_ctx* exec_ctx, + grpc_call* call, int success, void* user_data); typedef struct grpc_call_create_args { @@ -50,28 +51,33 @@ typedef struct grpc_call_create_args { /* Create a new call based on \a args. Regardless of success or failure, always returns a valid new call into *call */ -grpc_error* grpc_call_create(const grpc_call_create_args* args, +grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, + const grpc_call_create_args* args, grpc_call** call); -void grpc_call_set_completion_queue(grpc_call* call, grpc_completion_queue* cq); +void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, + grpc_completion_queue* cq); #ifndef NDEBUG void grpc_call_internal_ref(grpc_call* call, const char* reason); -void grpc_call_internal_unref(grpc_call* call, const char* reason); +void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* call, + const char* reason); #define GRPC_CALL_INTERNAL_REF(call, reason) \ grpc_call_internal_ref(call, reason) -#define GRPC_CALL_INTERNAL_UNREF(call, reason) \ - grpc_call_internal_unref(call, reason) +#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \ + grpc_call_internal_unref(exec_ctx, call, reason) #else void grpc_call_internal_ref(grpc_call* call); -void grpc_call_internal_unref(grpc_call* call); +void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* call); #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call) -#define GRPC_CALL_INTERNAL_UNREF(call, reason) grpc_call_internal_unref(call) +#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \ + grpc_call_internal_unref(exec_ctx, call) #endif grpc_call_stack* grpc_call_get_call_stack(grpc_call* call); -grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call, +grpc_call_error grpc_call_start_batch_and_execute(grpc_exec_ctx* exec_ctx, + grpc_call* call, const grpc_op* ops, size_t nops, grpc_closure* closure); diff --git a/src/core/lib/surface/call_details.cc b/src/core/lib/surface/call_details.cc index cd0b14586a..ea9208c7e3 100644 --- a/src/core/lib/surface/call_details.cc +++ b/src/core/lib/surface/call_details.cc @@ -34,7 +34,8 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_core::ExecCtx exec_ctx; - grpc_slice_unref_internal(cd->method); - grpc_slice_unref_internal(cd->host); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, cd->method); + grpc_slice_unref_internal(&exec_ctx, cd->host); + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index cf5e8c2150..1be734cdb7 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -69,22 +69,23 @@ struct grpc_channel { #define CHANNEL_FROM_TOP_ELEM(top_elem) \ CHANNEL_FROM_CHANNEL_STACK(grpc_channel_stack_from_top_element(top_elem)) -static void destroy_channel(void* arg, grpc_error* error); +static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); grpc_channel* grpc_channel_create_with_builder( - grpc_channel_stack_builder* builder, + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, grpc_channel_stack_type channel_stack_type) { char* target = gpr_strdup(grpc_channel_stack_builder_get_target(builder)); grpc_channel_args* args = grpc_channel_args_copy( grpc_channel_stack_builder_get_channel_arguments(builder)); grpc_channel* channel; if (channel_stack_type == GRPC_SERVER_CHANNEL) { - GRPC_STATS_INC_SERVER_CHANNELS_CREATED(); + GRPC_STATS_INC_SERVER_CHANNELS_CREATED(exec_ctx); } else { - GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(); + GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(exec_ctx); } grpc_error* error = grpc_channel_stack_builder_finish( - builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, + exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, (void**)&channel); if (error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "channel stack builder failed: %s", @@ -113,10 +114,10 @@ grpc_channel* grpc_channel_create_with_builder( } else { if (!GRPC_MDISNULL(channel->default_authority)) { /* setting this takes precedence over anything else */ - GRPC_MDELEM_UNREF(channel->default_authority); + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } channel->default_authority = grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, + exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern( grpc_slice_from_static_string(args->args[i].value.string))); } @@ -133,7 +134,7 @@ grpc_channel* grpc_channel_create_with_builder( GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { channel->default_authority = grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, + exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern( grpc_slice_from_static_string(args->args[i].value.string))); } @@ -190,23 +191,25 @@ grpc_channel* grpc_channel_create_with_builder( } done: - grpc_channel_args_destroy(args); + grpc_channel_args_destroy(exec_ctx, args); return channel; } -grpc_channel* grpc_channel_create(const char* target, +grpc_channel* grpc_channel_create(grpc_exec_ctx* exec_ctx, const char* target, const grpc_channel_args* input_args, grpc_channel_stack_type channel_stack_type, grpc_transport* optional_transport) { grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_channel_arguments(builder, input_args); + grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, + input_args); grpc_channel_stack_builder_set_target(builder, target); grpc_channel_stack_builder_set_transport(builder, optional_transport); - if (!grpc_channel_init_create_stack(builder, channel_stack_type)) { - grpc_channel_stack_builder_destroy(builder); + if (!grpc_channel_init_create_stack(exec_ctx, builder, channel_stack_type)) { + grpc_channel_stack_builder_destroy(exec_ctx, builder); return nullptr; } - return grpc_channel_create_with_builder(builder, channel_stack_type); + return grpc_channel_create_with_builder(exec_ctx, builder, + channel_stack_type); } size_t grpc_channel_get_call_size_estimate(grpc_channel* channel) { @@ -248,17 +251,18 @@ char* grpc_channel_get_target(grpc_channel* channel) { void grpc_channel_get_info(grpc_channel* channel, const grpc_channel_info* channel_info) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_element* elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); - elem->filter->get_channel_info(elem, channel_info); + elem->filter->get_channel_info(&exec_ctx, elem, channel_info); + grpc_exec_ctx_finish(&exec_ctx); } static grpc_call* grpc_channel_create_call_internal( - grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, - grpc_completion_queue* cq, grpc_pollset_set* pollset_set_alternative, - grpc_mdelem path_mdelem, grpc_mdelem authority_mdelem, - grpc_millis deadline) { + grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, + uint32_t propagation_mask, grpc_completion_queue* cq, + grpc_pollset_set* pollset_set_alternative, grpc_mdelem path_mdelem, + grpc_mdelem authority_mdelem, grpc_millis deadline) { grpc_mdelem send_metadata[2]; size_t num_metadata = 0; @@ -285,7 +289,7 @@ static grpc_call* grpc_channel_create_call_internal( args.send_deadline = deadline; grpc_call* call; - GRPC_LOG_IF_ERROR("call_create", grpc_call_create(&args, &call)); + GRPC_LOG_IF_ERROR("call_create", grpc_call_create(exec_ctx, &args, &call)); return call; } @@ -296,27 +300,29 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel, grpc_slice method, const grpc_slice* host, gpr_timespec deadline, void* reserved) { GPR_ASSERT(!reserved); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call* call = grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, cq, nullptr, - grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), - host != nullptr ? grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + &exec_ctx, channel, parent_call, propagation_mask, cq, nullptr, + grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH, + grpc_slice_ref_internal(method)), + host != nullptr ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, grpc_timespec_to_millis_round_up(deadline)); - + grpc_exec_ctx_finish(&exec_ctx); return call; } grpc_call* grpc_channel_create_pollset_set_call( - grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, - grpc_pollset_set* pollset_set, grpc_slice method, const grpc_slice* host, - grpc_millis deadline, void* reserved) { + grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, + uint32_t propagation_mask, grpc_pollset_set* pollset_set, grpc_slice method, + const grpc_slice* host, grpc_millis deadline, void* reserved) { GPR_ASSERT(!reserved); return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, nullptr, pollset_set, - grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), - host != nullptr ? grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + exec_ctx, channel, parent_call, propagation_mask, nullptr, pollset_set, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, + grpc_slice_ref_internal(method)), + host != nullptr ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, deadline); @@ -329,21 +335,21 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; rc->path = grpc_mdelem_from_slices( - GRPC_MDSTR_PATH, + &exec_ctx, GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string(method))); rc->authority = host ? grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, + &exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string(host))) : GRPC_MDNULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; gpr_mu_unlock(&channel->registered_call_mu); - + grpc_exec_ctx_finish(&exec_ctx); return rc; } @@ -364,12 +370,12 @@ grpc_call* grpc_channel_create_registered_call( registered_call_handle, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call* call = grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, completion_queue, nullptr, - GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), + &exec_ctx, channel, parent_call, propagation_mask, completion_queue, + nullptr, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), grpc_timespec_to_millis_round_up(deadline)); - + grpc_exec_ctx_finish(&exec_ctx); return call; } @@ -384,21 +390,23 @@ void grpc_channel_internal_ref(grpc_channel* c REF_ARG) { GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); } -void grpc_channel_internal_unref(grpc_channel* c REF_ARG) { - GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); +void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, + grpc_channel* c REF_ARG) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); } -static void destroy_channel(void* arg, grpc_error* error) { +static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_channel* channel = (grpc_channel*)arg; - grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel)); + grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CHANNEL(channel)); while (channel->registered_calls) { registered_call* rc = channel->registered_calls; channel->registered_calls = rc->next; - GRPC_MDELEM_UNREF(rc->path); - GRPC_MDELEM_UNREF(rc->authority); + GRPC_MDELEM_UNREF(exec_ctx, rc->path); + GRPC_MDELEM_UNREF(exec_ctx, rc->authority); gpr_free(rc); } - GRPC_MDELEM_UNREF(channel->default_authority); + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); @@ -407,14 +415,16 @@ static void destroy_channel(void* arg, grpc_error* error) { void grpc_channel_destroy(grpc_channel* channel) { grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel)); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Destroyed"); elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(&exec_ctx, elem, op); + + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "channel"); - GRPC_CHANNEL_INTERNAL_UNREF(channel, "channel"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel) { @@ -426,7 +436,8 @@ grpc_compression_options grpc_channel_compression_options( return channel->compression_options; } -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel, int i) { +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx* exec_ctx, + grpc_channel* channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: @@ -437,6 +448,6 @@ grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel, int i) { return GRPC_MDELEM_GRPC_STATUS_2; } gpr_ltoa(i, tmp); - return grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_STATUS, + return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); } diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index 26d8fceb2f..a2e53c777d 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -23,13 +23,13 @@ #include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/surface/channel_stack_type.h" -grpc_channel* grpc_channel_create(const char* target, +grpc_channel* grpc_channel_create(grpc_exec_ctx* exec_ctx, const char* target, const grpc_channel_args* args, grpc_channel_stack_type channel_stack_type, grpc_transport* optional_transport); grpc_channel* grpc_channel_create_with_builder( - grpc_channel_stack_builder* builder, + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, grpc_channel_stack_type channel_stack_type); /** Create a call given a grpc_channel, in order to call \a method. @@ -41,9 +41,9 @@ grpc_channel* grpc_channel_create_with_builder( properties from the server call to this new client call, depending on the value of \a propagation_mask (see propagation_bits.h for possible values) */ grpc_call* grpc_channel_create_pollset_set_call( - grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, - grpc_pollset_set* pollset_set, grpc_slice method, const grpc_slice* host, - grpc_millis deadline, void* reserved); + grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, + uint32_t propagation_mask, grpc_pollset_set* pollset_set, grpc_slice method, + const grpc_slice* host, grpc_millis deadline, void* reserved); /** Get a (borrowed) pointer to this channels underlying channel stack */ grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel); @@ -52,7 +52,8 @@ grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel); status_code. The returned elem is owned by the caller. */ -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel, +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx* exec_ctx, + grpc_channel* channel, int status_code); size_t grpc_channel_get_call_size_estimate(grpc_channel* channel); @@ -60,18 +61,20 @@ void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size); #ifndef NDEBUG void grpc_channel_internal_ref(grpc_channel* channel, const char* reason); -void grpc_channel_internal_unref(grpc_channel* channel, const char* reason); +void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, grpc_channel* channel, + const char* reason); #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \ grpc_channel_internal_ref(channel, reason) -#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \ - grpc_channel_internal_unref(channel, reason) +#define GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, reason) \ + grpc_channel_internal_unref(exec_ctx, channel, reason) #else void grpc_channel_internal_ref(grpc_channel* channel); -void grpc_channel_internal_unref(grpc_channel* channel); +void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, + grpc_channel* channel); #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \ grpc_channel_internal_ref(channel) -#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \ - grpc_channel_internal_unref(channel) +#define GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, reason) \ + grpc_channel_internal_unref(exec_ctx, channel) #endif /** Return the channel's compression options. */ diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 95cbbbd037..b563537f35 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -89,7 +89,8 @@ void grpc_channel_init_shutdown(void) { } } -bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, +bool grpc_channel_init_create_stack(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, grpc_channel_stack_type type) { GPR_ASSERT(g_finalized); @@ -98,7 +99,7 @@ bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, for (size_t i = 0; i < g_slots[type].num_slots; i++) { const stage_slot* slot = &g_slots[type].slots[i]; - if (!slot->fn(builder, slot->arg)) { + if (!slot->fn(exec_ctx, builder, slot->arg)) { return false; } } diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index d702f0f325..556ecc4147 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -32,7 +32,8 @@ /// One stage of mutation: call functions against \a builder to influence the /// finally constructed channel stack -typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder* builder, +typedef bool (*grpc_channel_init_stage)(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg); /// Global initialization of the system @@ -65,7 +66,8 @@ void grpc_channel_init_shutdown(void); /// \a optional_transport is either NULL or a constructed transport object /// Returns a pointer to the base of the memory allocated (the actual channel /// stack object will be prefix_bytes past that pointer) -bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, +bool grpc_channel_init_create_stack(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, grpc_channel_stack_type type); #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */ diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index 616ba9e0ac..e8f47f01cf 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -33,14 +33,15 @@ typedef struct { grpc_cq_completion completion_storage; } ping_result; -static void ping_destroy(void* arg, grpc_cq_completion* storage) { +static void ping_destroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_cq_completion* storage) { gpr_free(arg); } -static void ping_done(void* arg, grpc_error* error) { +static void ping_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { ping_result* pr = (ping_result*)arg; - grpc_cq_end_op(pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, pr, - &pr->completion_storage); + grpc_cq_end_op(exec_ctx, pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, + pr, &pr->completion_storage); } void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, @@ -51,7 +52,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(reserved == nullptr); pr->tag = tag; pr->cq = cq; @@ -59,5 +60,6 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, op->send_ping = &pr->closure; op->bind_pollset = grpc_cq_pollset(cq); GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - top_elem->filter->start_transport_op(top_elem, op); + top_elem->filter->start_transport_op(&exec_ctx, top_elem, op); + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 12385b7130..98d7e35943 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -62,12 +62,13 @@ typedef struct { bool can_listen; size_t (*size)(void); void (*init)(grpc_pollset* pollset, gpr_mu** mu); - grpc_error* (*kick)(grpc_pollset* pollset, + grpc_error* (*kick)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker); - grpc_error* (*work)(grpc_pollset* pollset, grpc_pollset_worker** worker, - grpc_millis deadline); - void (*shutdown)(grpc_pollset* pollset, grpc_closure* closure); - void (*destroy)(grpc_pollset* pollset); + grpc_error* (*work)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker** worker, grpc_millis deadline); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_closure* closure); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); } cq_poller_vtable; typedef struct non_polling_worker { @@ -93,12 +94,14 @@ static void non_polling_poller_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &npp->mu; } -static void non_polling_poller_destroy(grpc_pollset* pollset) { +static void non_polling_poller_destroy(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset) { non_polling_poller* npp = (non_polling_poller*)pollset; gpr_mu_destroy(&npp->mu); } -static grpc_error* non_polling_poller_work(grpc_pollset* pollset, +static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) { non_polling_poller* npp = (non_polling_poller*)pollset; @@ -119,12 +122,12 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset, while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline_ts)) ; - grpc_core::ExecCtx::Get()->InvalidateNow(); + grpc_exec_ctx_invalidate_now(exec_ctx); if (&w == npp->root) { npp->root = w.next; if (&w == npp->root) { if (npp->shutdown) { - GRPC_CLOSURE_SCHED(npp->shutdown, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, npp->shutdown, GRPC_ERROR_NONE); } npp->root = nullptr; } @@ -137,7 +140,8 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset, } static grpc_error* non_polling_poller_kick( - grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { + grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { non_polling_poller* p = (non_polling_poller*)pollset; if (specific_worker == nullptr) specific_worker = (grpc_pollset_worker*)p->root; @@ -151,13 +155,14 @@ static grpc_error* non_polling_poller_kick( return GRPC_ERROR_NONE; } -static void non_polling_poller_shutdown(grpc_pollset* pollset, +static void non_polling_poller_shutdown(grpc_exec_ctx* exec_ctx, + grpc_pollset* pollset, grpc_closure* closure) { non_polling_poller* p = (non_polling_poller*)pollset; GPR_ASSERT(closure != nullptr); p->shutdown = closure; if (p->root == nullptr) { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } else { non_polling_worker* w = p->root; do { @@ -184,11 +189,13 @@ typedef struct cq_vtable { grpc_cq_completion_type cq_completion_type; size_t data_size; void (*init)(void* data); - void (*shutdown)(grpc_completion_queue* cq); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq); void (*destroy)(void* data); bool (*begin_op)(grpc_completion_queue* cq, void* tag); - void (*end_op)(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, grpc_cq_completion* storage), + void (*end_op)(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, void* tag, + grpc_error* error, + void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, + grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); grpc_event (*next)(grpc_completion_queue* cq, gpr_timespec deadline, void* reserved); @@ -273,23 +280,31 @@ struct grpc_completion_queue { }; /* Forward declarations */ -static void cq_finish_shutdown_next(grpc_completion_queue* cq); -static void cq_finish_shutdown_pluck(grpc_completion_queue* cq); -static void cq_shutdown_next(grpc_completion_queue* cq); -static void cq_shutdown_pluck(grpc_completion_queue* cq); +static void cq_finish_shutdown_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq); +static void cq_finish_shutdown_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq); +static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq); +static void cq_shutdown_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq); static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag); static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag); -static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, + void (*done)(grpc_exec_ctx* exec_ctx, + void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); -static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, + void (*done)(grpc_exec_ctx* exec_ctx, + void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); @@ -331,7 +346,8 @@ grpc_core::TraceFlag grpc_cq_event_timeout_trace(true, "queue_timeout"); gpr_free(_ev); \ } -static void on_pollset_shutdown_done(void* cq, grpc_error* error); +static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* cq, + grpc_error* error); void grpc_cq_global_init() { gpr_tls_init(&g_cached_event); @@ -353,18 +369,19 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, if (storage != nullptr && (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; *ok = (storage->next & (uintptr_t)(1)) == 1; - storage->done(storage->done_arg, storage); + storage->done(&exec_ctx, storage->done_arg, storage); ret = 1; cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(cq); + cq_finish_shutdown_next(&exec_ctx, cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "shutting_down"); } + grpc_exec_ctx_finish(&exec_ctx); } gpr_tls_set(&g_cached_event, (intptr_t)0); gpr_tls_set(&g_cached_cq, (intptr_t)0); @@ -389,22 +406,24 @@ static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { grpc_cq_completion* c = nullptr; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; if (gpr_spinlock_trylock(&q->queue_lock)) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(&exec_ctx); bool is_empty = false; c = (grpc_cq_completion*)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); gpr_spinlock_unlock(&q->queue_lock); if (c == nullptr && !is_empty) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(); + GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(&exec_ctx); } } else { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(&exec_ctx); } + grpc_exec_ctx_finish(&exec_ctx); + if (c) { gpr_atm_no_barrier_fetch_add(&q->num_queue_items, -1); } @@ -434,8 +453,9 @@ grpc_completion_queue* grpc_completion_queue_create_internal( const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; - grpc_core::ExecCtx exec_ctx; - GRPC_STATS_INC_CQS_CREATED(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_STATS_INC_CQS_CREATED(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + @@ -517,14 +537,15 @@ void grpc_cq_internal_ref(grpc_completion_queue* cq) { gpr_ref(&cq->owning_refs); } -static void on_pollset_shutdown_done(void* arg, grpc_error* error) { +static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_completion_queue* cq = (grpc_completion_queue*)arg; - GRPC_CQ_INTERNAL_UNREF(cq, "pollset_destroy"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "pollset_destroy"); } #ifndef NDEBUG -void grpc_cq_internal_unref(grpc_completion_queue* cq, const char* reason, - const char* file, int line) { +void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, + const char* reason, const char* file, int line) { if (grpc_trace_cq_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -532,11 +553,12 @@ void grpc_cq_internal_unref(grpc_completion_queue* cq, const char* reason, reason); } #else -void grpc_cq_internal_unref(grpc_completion_queue* cq) { +void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq) { #endif if (gpr_unref(&cq->owning_refs)) { cq->vtable->destroy(DATA_FROM_CQ(cq)); - cq->poller_vtable->destroy(POLLSET_FROM_CQ(cq)); + cq->poller_vtable->destroy(exec_ctx, POLLSET_FROM_CQ(cq)); #ifndef NDEBUG gpr_free(cq->outstanding_tags); #endif @@ -617,9 +639,11 @@ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) { /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_NEXT) */ -static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, + void (*done)(grpc_exec_ctx* exec_ctx, + void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { GPR_TIMER_BEGIN("cq_end_op_for_next", 0); @@ -628,9 +652,9 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_next(cq=%p, tag=%p, error=%s, " + "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 6, (cq, tag, errmsg, done, done_arg, storage)); + 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -665,7 +689,7 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, if (is_first) { gpr_mu_lock(cq->mu); grpc_error* kick_error = - cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), nullptr); + cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); if (kick_error != GRPC_ERROR_NONE) { @@ -677,17 +701,17 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(cq); + cq_finish_shutdown_next(exec_ctx, cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); } } else { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_atm_rel_store(&cqd->pending_events, 0); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(cq); + cq_finish_shutdown_next(exec_ctx, cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); } } @@ -699,9 +723,11 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_PLUCK) */ -static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, + void (*done)(grpc_exec_ctx* exec_ctx, + void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); @@ -713,9 +739,9 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_pluck(cq=%p, tag=%p, error=%s, " + "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 6, (cq, tag, errmsg, done, done_arg, storage)); + 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -736,7 +762,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, cqd->completed_tail = storage; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(cq); + cq_finish_shutdown_pluck(exec_ctx, cq); gpr_mu_unlock(cq->mu); } else { grpc_pollset_worker* pluck_worker = nullptr; @@ -748,7 +774,7 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, } grpc_error* kick_error = - cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), pluck_worker); + cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), pluck_worker); gpr_mu_unlock(cq->mu); @@ -765,10 +791,12 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, GRPC_ERROR_UNREF(error); } -void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, grpc_cq_completion* storage), +void grpc_cq_end_op(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, + void* tag, grpc_error* error, + void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, + grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { - cq->vtable->end_op(cq, tag, error, done, done_arg, storage); + cq->vtable->end_op(exec_ctx, cq, tag, error, done, done_arg, storage); } typedef struct { @@ -780,40 +808,31 @@ typedef struct { bool first_loop; } cq_is_finished_arg; -class ExecCtxNext : public grpc_core::ExecCtx { - public: - ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} +static bool cq_is_next_finished(grpc_exec_ctx* exec_ctx, void* arg) { + cq_is_finished_arg* a = (cq_is_finished_arg*)arg; + grpc_completion_queue* cq = a->cq; + cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + GPR_ASSERT(a->stolen_completion == nullptr); - bool CheckReadyToFinish() override { - cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; - grpc_completion_queue* cq = a->cq; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == nullptr); + gpr_atm current_last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); - gpr_atm current_last_seen_things_queued_ever = + if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { + a->last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - if (current_last_seen_things_queued_ever != - a->last_seen_things_queued_ever) { - a->last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); - - /* Pop a cq_completion from the queue. Returns NULL if the queue is empty - * might return NULL in some cases even if the queue is not empty; but - * that - * is ok and doesn't affect correctness. Might effect the tail latencies a - * bit) */ - a->stolen_completion = cq_event_queue_pop(&cqd->queue); - if (a->stolen_completion != nullptr) { - return true; - } + /* Pop a cq_completion from the queue. Returns NULL if the queue is empty + * might return NULL in some cases even if the queue is not empty; but + * that + * is ok and doesn't affect correctness. Might effect the tail latencies a + * bit) */ + a->stolen_completion = cq_event_queue_pop(&cqd->queue); + if (a->stolen_completion != nullptr) { + return true; } - return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); } - - private: - void* check_ready_to_finish_arg_; -}; + return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); +} #ifndef NDEBUG static void dump_pending_tags(grpc_completion_queue* cq) { @@ -868,7 +887,8 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, nullptr, nullptr, true}; - ExecCtxNext exec_ctx(&is_finished_arg); + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; @@ -878,7 +898,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(c->done_arg, c); + c->done(&exec_ctx, c->done_arg, c); break; } @@ -888,7 +908,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(c->done_arg, c); + c->done(&exec_ctx, c->done_arg, c); break; } else { /* If c == NULL it means either the queue is empty OR in an transient @@ -919,7 +939,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, } if (!is_finished_arg.first_loop && - grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { + grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; dump_pending_tags(cq); @@ -929,8 +949,8 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, /* The main polling work happens in grpc_pollset_work */ gpr_mu_lock(cq->mu); cq->num_polls++; - grpc_error* err = cq->poller_vtable->work(POLLSET_FROM_CQ(cq), nullptr, - iteration_deadline); + grpc_error* err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), + nullptr, iteration_deadline); gpr_mu_unlock(cq->mu); if (err != GRPC_ERROR_NONE) { @@ -949,13 +969,13 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, if (cq_event_queue_num_items(&cqd->queue) > 0 && gpr_atm_acq_load(&cqd->pending_events) > 0) { gpr_mu_lock(cq->mu); - cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), nullptr); + cq->poller_vtable->kick(&exec_ctx, POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); } GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(cq, "next"); - + GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "next"); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_next", 0); @@ -969,16 +989,19 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, - Must be called only once in completion queue's lifetime - grpc_completion_queue_shutdown() MUST have been called before calling this function */ -static void cq_finish_shutdown_next(grpc_completion_queue* cq) { +static void cq_finish_shutdown_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq) { cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0); - cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), + &cq->pollset_shutdown_done); } -static void cq_shutdown_next(grpc_completion_queue* cq) { +static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq) { cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -991,7 +1014,7 @@ static void cq_shutdown_next(grpc_completion_queue* cq) { gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); return; } cqd->shutdown_called = true; @@ -999,10 +1022,10 @@ static void cq_shutdown_next(grpc_completion_queue* cq) { * cq_begin_op_for_next and and cq_end_op_for_next functions which read/write * on this counter without necessarily holding a lock on cq */ if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_next(cq); + cq_finish_shutdown_next(exec_ctx, cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); } grpc_event grpc_completion_queue_next(grpc_completion_queue* cq, @@ -1035,46 +1058,37 @@ static void del_plucker(grpc_completion_queue* cq, void* tag, GPR_UNREACHABLE_CODE(return ); } -class ExecCtxPluck : public grpc_core::ExecCtx { - public: - ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} - - bool CheckReadyToFinish() override { - cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; - grpc_completion_queue* cq = a->cq; - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); +static bool cq_is_pluck_finished(grpc_exec_ctx* exec_ctx, void* arg) { + cq_is_finished_arg* a = (cq_is_finished_arg*)arg; + grpc_completion_queue* cq = a->cq; + cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == nullptr); - gpr_atm current_last_seen_things_queued_ever = + GPR_ASSERT(a->stolen_completion == nullptr); + gpr_atm current_last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); + if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { + gpr_mu_lock(cq->mu); + a->last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - if (current_last_seen_things_queued_ever != - a->last_seen_things_queued_ever) { - gpr_mu_lock(cq->mu); - a->last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); - grpc_cq_completion* c; - grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != - &cqd->completed_head) { - if (c->tag == a->tag) { - prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); - if (c == cqd->completed_tail) { - cqd->completed_tail = prev; - } - gpr_mu_unlock(cq->mu); - a->stolen_completion = c; - return true; + grpc_cq_completion* c; + grpc_cq_completion* prev = &cqd->completed_head; + while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != + &cqd->completed_head) { + if (c->tag == a->tag) { + prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); + if (c == cqd->completed_tail) { + cqd->completed_tail = prev; } - prev = c; + gpr_mu_unlock(cq->mu); + a->stolen_completion = c; + return true; } - gpr_mu_unlock(cq->mu); + prev = c; } - return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); + gpr_mu_unlock(cq->mu); } - - private: - void* check_ready_to_finish_arg_; -}; + return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); +} static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved) { @@ -1111,7 +1125,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, nullptr, tag, true}; - ExecCtxPluck exec_ctx(&is_finished_arg); + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != nullptr) { gpr_mu_unlock(cq->mu); @@ -1120,7 +1135,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(c->done_arg, c); + c->done(&exec_ctx, c->done_arg, c); break; } prev = &cqd->completed_head; @@ -1135,7 +1150,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(c->done_arg, c); + c->done(&exec_ctx, c->done_arg, c); goto done; } prev = c; @@ -1159,7 +1174,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } if (!is_finished_arg.first_loop && - grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { + grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); memset(&ret, 0, sizeof(ret)); @@ -1168,8 +1183,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } cq->num_polls++; - grpc_error* err = - cq->poller_vtable->work(POLLSET_FROM_CQ(cq), &worker, deadline_millis); + grpc_error* err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), + &worker, deadline_millis); if (err != GRPC_ERROR_NONE) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); @@ -1187,8 +1202,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, } done: GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(cq, "pluck"); - + GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "pluck"); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_pluck", 0); @@ -1201,19 +1216,22 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, return cq->vtable->pluck(cq, tag, deadline, reserved); } -static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { +static void cq_finish_shutdown_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown)); gpr_atm_no_barrier_store(&cqd->shutdown, 1); - cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), + &cq->pollset_shutdown_done); } /* NOTE: This function is almost exactly identical to cq_shutdown_next() but * merging them is a bit tricky and probably not worth it */ -static void cq_shutdown_pluck(grpc_completion_queue* cq) { +static void cq_shutdown_pluck(grpc_exec_ctx* exec_ctx, + grpc_completion_queue* cq) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -1226,25 +1244,25 @@ static void cq_shutdown_pluck(grpc_completion_queue* cq) { gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); return; } cqd->shutdown_called = true; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(cq); + cq_finish_shutdown_pluck(exec_ctx, cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); } /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); - cq->vtable->shutdown(cq); - + cq->vtable->shutdown(&exec_ctx, cq); + grpc_exec_ctx_finish(&exec_ctx); GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } @@ -1253,9 +1271,9 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); - grpc_core::ExecCtx exec_ctx; - GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "destroy"); + grpc_exec_ctx_finish(&exec_ctx); GPR_TIMER_END("grpc_completion_queue_destroy", 0); } diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index aea47afaf5..13d3e5807d 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -40,7 +40,8 @@ typedef struct grpc_cq_completion { void* tag; /** done callback - called when this queue element is no longer needed by the completion queue */ - void (*done)(void* done_arg, struct grpc_cq_completion* c); + void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, + struct grpc_cq_completion* c); void* done_arg; /** next pointer; low bit is used to indicate success or not */ uintptr_t next; @@ -49,17 +50,17 @@ typedef struct grpc_cq_completion { #ifndef NDEBUG void grpc_cq_internal_ref(grpc_completion_queue* cc, const char* reason, const char* file, int line); -void grpc_cq_internal_unref(grpc_completion_queue* cc, const char* reason, - const char* file, int line); +void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc, + const char* reason, const char* file, int line); #define GRPC_CQ_INTERNAL_REF(cc, reason) \ grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__) -#define GRPC_CQ_INTERNAL_UNREF(cc, reason) \ - grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__) +#define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) \ + grpc_cq_internal_unref(ec, cc, reason, __FILE__, __LINE__) #else void grpc_cq_internal_ref(grpc_completion_queue* cc); -void grpc_cq_internal_unref(grpc_completion_queue* cc); +void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc); #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc) -#define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc) +#define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) grpc_cq_internal_unref(ec, cc) #endif /* Initializes global variables used by completion queues */ @@ -73,8 +74,10 @@ bool grpc_cq_begin_op(grpc_completion_queue* cc, void* tag); /* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to grpc_cq_begin_op */ -void grpc_cq_end_op(grpc_completion_queue* cc, void* tag, grpc_error* error, - void (*done)(void* done_arg, grpc_cq_completion* storage), +void grpc_cq_end_op(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc, + void* tag, grpc_error* error, + void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, + grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cc); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index c6ce235da7..8ee1383fb8 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -73,12 +73,14 @@ static void do_basic_init(void) { grpc_fork_handlers_auto_register(); } -static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { +static bool append_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } -static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) { +static bool prepend_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } @@ -121,6 +123,7 @@ void grpc_init(void) { int i; gpr_once_init(&g_basic_init, do_basic_init); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); @@ -130,8 +133,7 @@ void grpc_init(void) { grpc_mdctx_global_init(); grpc_channel_init_init(); grpc_security_pre_init(); - grpc_core::ExecCtx::GlobalInit(); - grpc_iomgr_init(); + grpc_iomgr_init(&exec_ctx); gpr_timers_global_init(); grpc_handshaker_factory_registry_init(); grpc_security_init(); @@ -147,44 +149,37 @@ void grpc_init(void) { grpc_tracer_init("GRPC_TRACE"); /* no more changes to channel init pipelines */ grpc_channel_init_finalize(); - grpc_iomgr_start(); + grpc_iomgr_start(&exec_ctx); } gpr_mu_unlock(&g_init_mu); - + grpc_exec_ctx_finish(&exec_ctx); GRPC_API_TRACE("grpc_init(void)", 0, ()); } void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); - if (grpc_core::ExecCtx::Get()) { - grpc_core::ExecCtx::Get()->Flush(); - } + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { - { - grpc_core::ExecCtx exec_ctx(0); - { - grpc_executor_shutdown(); - grpc_timer_manager_set_threading( - false); // shutdown timer_manager thread - for (i = g_number_of_plugins; i >= 0; i--) { - if (g_all_of_the_plugins[i].destroy != nullptr) { - g_all_of_the_plugins[i].destroy(); - } - } + grpc_executor_shutdown(&exec_ctx); + grpc_timer_manager_set_threading(false); // shutdown timer_manager thread + for (i = g_number_of_plugins; i >= 0; i--) { + if (g_all_of_the_plugins[i].destroy != nullptr) { + g_all_of_the_plugins[i].destroy(); } - grpc_iomgr_shutdown(); - gpr_timers_global_destroy(); - grpc_tracer_shutdown(); - grpc_mdctx_global_shutdown(); - grpc_handshaker_factory_registry_shutdown(); - grpc_slice_intern_shutdown(); - grpc_stats_shutdown(); } - grpc_core::ExecCtx::GlobalShutdown(); + grpc_iomgr_shutdown(&exec_ctx); + gpr_timers_global_destroy(); + grpc_tracer_shutdown(); + grpc_mdctx_global_shutdown(&exec_ctx); + grpc_handshaker_factory_registry_shutdown(&exec_ctx); + grpc_slice_intern_shutdown(); + grpc_stats_shutdown(); } gpr_mu_unlock(&g_init_mu); + grpc_exec_ctx_finish(&exec_ctx); } int grpc_is_initialized(void) { diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 75ed9faef0..3eee570fc2 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -37,7 +37,7 @@ void grpc_security_pre_init(void) {} static bool maybe_prepend_client_auth_filter( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { @@ -52,7 +52,7 @@ static bool maybe_prepend_client_auth_filter( } static bool maybe_prepend_server_auth_filter( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 29b4e3f0c7..c32c9af50e 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -49,7 +49,8 @@ struct ChannelData { const char* error_message; }; -static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { +static void fill_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_metadata_batch* mdb) { CallData* calld = reinterpret_cast(elem->call_data); bool expected = false; if (!calld->filled_metadata.compare_exchange_strong( @@ -61,9 +62,9 @@ static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); calld->status.md = grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); + exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); calld->details.md = grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_MESSAGE, + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_from_copied_string(chand->error_message)); calld->status.prev = calld->details.next = nullptr; calld->status.next = &calld->details; @@ -75,61 +76,69 @@ static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { } static void lame_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { CallData* calld = reinterpret_cast(elem->call_data); if (op->recv_initial_metadata) { - fill_metadata(elem, + fill_metadata(exec_ctx, elem, op->payload->recv_initial_metadata.recv_initial_metadata); } else if (op->recv_trailing_metadata) { - fill_metadata(elem, + fill_metadata(exec_ctx, elem, op->payload->recv_trailing_metadata.recv_trailing_metadata); } grpc_transport_stream_op_batch_finish_with_failure( - op, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"), + exec_ctx, op, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"), calld->call_combiner); } -static void lame_get_channel_info(grpc_channel_element* elem, +static void lame_get_channel_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* channel_info) {} -static void lame_start_transport_op(grpc_channel_element* elem, +static void lame_start_transport_op(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) { if (op->on_connectivity_state_change) { GPR_ASSERT(*op->connectivity_state != GRPC_CHANNEL_SHUTDOWN); *op->connectivity_state = GRPC_CHANNEL_SHUTDOWN; - GRPC_CLOSURE_SCHED(op->on_connectivity_state_change, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_connectivity_state_change, + GRPC_ERROR_NONE); } if (op->send_ping != nullptr) { - GRPC_CLOSURE_SCHED(op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "lame client channel")); + GRPC_CLOSURE_SCHED( + exec_ctx, op->send_ping, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel")); } GRPC_ERROR_UNREF(op->disconnect_with_error); if (op->on_consumed != nullptr) { - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } } -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { CallData* calld = reinterpret_cast(elem->call_data); calld->call_combiner = args->call_combiner; return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { - GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); } -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} } // namespace @@ -154,10 +163,10 @@ const grpc_channel_filter grpc_lame_filter = { grpc_channel* grpc_lame_client_channel_create(const char* target, grpc_status_code error_code, const char* error_message) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_element* elem; - grpc_channel* channel = - grpc_channel_create(target, nullptr, GRPC_CLIENT_LAME_CHANNEL, nullptr); + grpc_channel* channel = grpc_channel_create( + &exec_ctx, target, nullptr, GRPC_CLIENT_LAME_CHANNEL, nullptr); elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); GRPC_API_TRACE( "grpc_lame_client_channel_create(target=%s, error_code=%d, " @@ -167,6 +176,6 @@ grpc_channel* grpc_lame_client_channel_create(const char* target, auto chand = reinterpret_cast(elem->channel_data); chand->error_code = error_code; chand->error_message = error_message; - + grpc_exec_ctx_finish(&exec_ctx); return channel; } diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 4f07183180..0f8a057f31 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -46,9 +46,10 @@ typedef struct listener { void* arg; - void (*start)(grpc_server* server, void* arg, grpc_pollset** pollsets, - size_t pollset_count); - void (*destroy)(grpc_server* server, void* arg, grpc_closure* closure); + void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_pollset** pollsets, size_t pollset_count); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_closure* closure); struct listener* next; grpc_closure destroy_done; } listener; @@ -223,12 +224,13 @@ struct grpc_server { #define SERVER_FROM_CALL_ELEM(elem) \ (((channel_data*)(elem)->channel_data)->server) -static void publish_new_rpc(void* calld, grpc_error* error); -static void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc, - grpc_error* error); +static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* calld, + grpc_error* error); +static void fail_call(grpc_exec_ctx* exec_ctx, grpc_server* server, + size_t cq_idx, requested_call* rc, grpc_error* error); /* Before calling maybe_finish_shutdown, we must hold mu_global and not hold mu_call */ -static void maybe_finish_shutdown(grpc_server* server); +static void maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_server* server); /* * channel broadcaster @@ -256,14 +258,15 @@ struct shutdown_cleanup_args { grpc_slice slice; }; -static void shutdown_cleanup(void* arg, grpc_error* error) { +static void shutdown_cleanup(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { struct shutdown_cleanup_args* a = (struct shutdown_cleanup_args*)arg; - grpc_slice_unref_internal(a->slice); + grpc_slice_unref_internal(exec_ctx, a->slice); gpr_free(a); } -static void send_shutdown(grpc_channel* channel, bool send_goaway, - grpc_error* send_disconnect) { +static void send_shutdown(grpc_exec_ctx* exec_ctx, grpc_channel* channel, + bool send_goaway, grpc_error* send_disconnect) { struct shutdown_cleanup_args* sc = (struct shutdown_cleanup_args*)gpr_malloc(sizeof(*sc)); GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc, @@ -281,18 +284,19 @@ static void send_shutdown(grpc_channel* channel, bool send_goaway, op->disconnect_with_error = send_disconnect; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(exec_ctx, elem, op); } -static void channel_broadcaster_shutdown(channel_broadcaster* cb, +static void channel_broadcaster_shutdown(grpc_exec_ctx* exec_ctx, + channel_broadcaster* cb, bool send_goaway, grpc_error* force_disconnect) { size_t i; for (i = 0; i < cb->num_channels; i++) { - send_shutdown(cb->channels[i], send_goaway, + send_shutdown(exec_ctx, cb->channels[i], send_goaway, GRPC_ERROR_REF(force_disconnect)); - GRPC_CHANNEL_INTERNAL_UNREF(cb->channels[i], "broadcast"); + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, cb->channels[i], "broadcast"); } gpr_free(cb->channels); GRPC_ERROR_UNREF(force_disconnect); @@ -320,11 +324,13 @@ static void request_matcher_destroy(request_matcher* rm) { gpr_free(rm->requests_per_cq); } -static void kill_zombie(void* elem, grpc_error* error) { +static void kill_zombie(grpc_exec_ctx* exec_ctx, void* elem, + grpc_error* error) { grpc_call_unref(grpc_call_from_top_element((grpc_call_element*)elem)); } -static void request_matcher_zombify_all_pending_calls(request_matcher* rm) { +static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx* exec_ctx, + request_matcher* rm) { while (rm->pending_head) { call_data* calld = rm->pending_head; rm->pending_head = calld->pending_next; @@ -333,18 +339,19 @@ static void request_matcher_zombify_all_pending_calls(request_matcher* rm) { &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, GRPC_ERROR_NONE); } } -static void request_matcher_kill_requests(grpc_server* server, +static void request_matcher_kill_requests(grpc_exec_ctx* exec_ctx, + grpc_server* server, request_matcher* rm, grpc_error* error) { requested_call* rc; for (size_t i = 0; i < server->cq_count; i++) { while ((rc = (requested_call*)gpr_locked_mpscq_pop( &rm->requests_per_cq[i])) != nullptr) { - fail_call(server, i, rc, GRPC_ERROR_REF(error)); + fail_call(exec_ctx, server, i, rc, GRPC_ERROR_REF(error)); } } GRPC_ERROR_UNREF(error); @@ -358,10 +365,10 @@ static void server_ref(grpc_server* server) { gpr_ref(&server->internal_refcount); } -static void server_delete(grpc_server* server) { +static void server_delete(grpc_exec_ctx* exec_ctx, grpc_server* server) { registered_method* rm; size_t i; - grpc_channel_args_destroy(server->channel_args); + grpc_channel_args_destroy(exec_ctx, server->channel_args); gpr_mu_destroy(&server->mu_global); gpr_mu_destroy(&server->mu_call); gpr_cv_destroy(&server->starting_cv); @@ -378,7 +385,7 @@ static void server_delete(grpc_server* server) { request_matcher_destroy(&server->unregistered_request_matcher); } for (i = 0; i < server->cq_count; i++) { - GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server"); + GRPC_CQ_INTERNAL_UNREF(exec_ctx, server->cqs[i], "server"); } gpr_free(server->cqs); gpr_free(server->pollsets); @@ -386,9 +393,9 @@ static void server_delete(grpc_server* server) { gpr_free(server); } -static void server_unref(grpc_server* server) { +static void server_unref(grpc_exec_ctx* exec_ctx, grpc_server* server) { if (gpr_unref(&server->internal_refcount)) { - server_delete(server); + server_delete(exec_ctx, server); } } @@ -402,19 +409,21 @@ static void orphan_channel(channel_data* chand) { chand->next = chand->prev = chand; } -static void finish_destroy_channel(void* cd, grpc_error* error) { +static void finish_destroy_channel(grpc_exec_ctx* exec_ctx, void* cd, + grpc_error* error) { channel_data* chand = (channel_data*)cd; grpc_server* server = chand->server; - GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server"); - server_unref(server); + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, chand->channel, "server"); + server_unref(exec_ctx, server); } -static void destroy_channel(channel_data* chand, grpc_error* error) { +static void destroy_channel(grpc_exec_ctx* exec_ctx, channel_data* chand, + grpc_error* error) { if (is_channel_orphaned(chand)) return; GPR_ASSERT(chand->server != nullptr); orphan_channel(chand); server_ref(chand->server); - maybe_finish_shutdown(chand->server); + maybe_finish_shutdown(exec_ctx, chand->server); GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, finish_destroy_channel, chand, grpc_schedule_on_exec_ctx); @@ -427,18 +436,20 @@ static void destroy_channel(channel_data* chand, grpc_error* error) { grpc_transport_op* op = grpc_make_transport_op(&chand->finish_destroy_channel_closure); op->set_accept_stream = true; - grpc_channel_next_op(grpc_channel_stack_element( + grpc_channel_next_op(exec_ctx, + grpc_channel_stack_element( grpc_channel_get_channel_stack(chand->channel), 0), op); } -static void done_request_event(void* req, grpc_cq_completion* c) { +static void done_request_event(grpc_exec_ctx* exec_ctx, void* req, + grpc_cq_completion* c) { gpr_free(req); } -static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx, - requested_call* rc) { - grpc_call_set_completion_queue(calld->call, rc->cq_bound_to_call); +static void publish_call(grpc_exec_ctx* exec_ctx, grpc_server* server, + call_data* calld, size_t cq_idx, requested_call* rc) { + grpc_call_set_completion_queue(exec_ctx, calld->call, rc->cq_bound_to_call); grpc_call* call = calld->call; *rc->call = call; calld->cq_new = server->cqs[cq_idx]; @@ -465,11 +476,12 @@ static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx, GPR_UNREACHABLE_CODE(return ); } - grpc_cq_end_op(calld->cq_new, rc->tag, GRPC_ERROR_NONE, done_request_event, - rc, &rc->completion); + grpc_cq_end_op(exec_ctx, calld->cq_new, rc->tag, GRPC_ERROR_NONE, + done_request_event, rc, &rc->completion); } -static void publish_new_rpc(void* arg, grpc_error* error) { +static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* call_elem = (grpc_call_element*)arg; call_data* calld = (call_data*)call_elem->call_data; channel_data* chand = (channel_data*)call_elem->channel_data; @@ -482,7 +494,8 @@ static void publish_new_rpc(void* arg, grpc_error* error) { &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, + GRPC_ERROR_REF(error)); return; } @@ -493,15 +506,15 @@ static void publish_new_rpc(void* arg, grpc_error* error) { if (rc == nullptr) { continue; } else { - GRPC_STATS_INC_SERVER_CQS_CHECKED(i); + GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i); gpr_atm_no_barrier_store(&calld->state, ACTIVATED); - publish_call(server, calld, cq_idx, rc); + publish_call(exec_ctx, server, calld, cq_idx, rc); return; /* early out */ } } /* no cq to take the request found: queue it on the slow list */ - GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(); + GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx); gpr_mu_lock(&server->mu_call); // We need to ensure that all the queues are empty. We do this under @@ -516,9 +529,9 @@ static void publish_new_rpc(void* arg, grpc_error* error) { continue; } else { gpr_mu_unlock(&server->mu_call); - GRPC_STATS_INC_SERVER_CQS_CHECKED(i + server->cq_count); + GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i + server->cq_count); gpr_atm_no_barrier_store(&calld->state, ACTIVATED); - publish_call(server, calld, cq_idx, rc); + publish_call(exec_ctx, server, calld, cq_idx, rc); return; /* early out */ } } @@ -535,7 +548,8 @@ static void publish_new_rpc(void* arg, grpc_error* error) { } static void finish_start_new_rpc( - grpc_server* server, grpc_call_element* elem, request_matcher* rm, + grpc_exec_ctx* exec_ctx, grpc_server* server, grpc_call_element* elem, + request_matcher* rm, grpc_server_register_method_payload_handling payload_handling) { call_data* calld = (call_data*)elem->call_data; @@ -543,7 +557,7 @@ static void finish_start_new_rpc( gpr_atm_no_barrier_store(&calld->state, ZOMBIED); GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, GRPC_ERROR_NONE); return; } @@ -551,7 +565,7 @@ static void finish_start_new_rpc( switch (payload_handling) { case GRPC_SRM_PAYLOAD_NONE: - publish_new_rpc(elem, GRPC_ERROR_NONE); + publish_new_rpc(exec_ctx, elem, GRPC_ERROR_NONE); break; case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: { grpc_op op; @@ -560,13 +574,14 @@ static void finish_start_new_rpc( op.data.recv_message.recv_message = &calld->payload; GRPC_CLOSURE_INIT(&calld->publish, publish_new_rpc, elem, grpc_schedule_on_exec_ctx); - grpc_call_start_batch_and_execute(calld->call, &op, 1, &calld->publish); + grpc_call_start_batch_and_execute(exec_ctx, calld->call, &op, 1, + &calld->publish); break; } } } -static void start_new_rpc(grpc_call_element* elem) { +static void start_new_rpc(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; grpc_server* server = chand->server; @@ -591,7 +606,8 @@ static void start_new_rpc(grpc_call_element* elem) { GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) { continue; } - finish_start_new_rpc(server, elem, &rm->server_registered_method->matcher, + finish_start_new_rpc(exec_ctx, server, elem, + &rm->server_registered_method->matcher, rm->server_registered_method->payload_handling); return; } @@ -608,12 +624,14 @@ static void start_new_rpc(grpc_call_element* elem) { GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) { continue; } - finish_start_new_rpc(server, elem, &rm->server_registered_method->matcher, + finish_start_new_rpc(exec_ctx, server, elem, + &rm->server_registered_method->matcher, rm->server_registered_method->payload_handling); return; } } - finish_start_new_rpc(server, elem, &server->unregistered_request_matcher, + finish_start_new_rpc(exec_ctx, server, elem, + &server->unregistered_request_matcher, GRPC_SRM_PAYLOAD_NONE); } @@ -626,8 +644,9 @@ static int num_listeners(grpc_server* server) { return n; } -static void done_shutdown_event(void* server, grpc_cq_completion* completion) { - server_unref((grpc_server*)server); +static void done_shutdown_event(grpc_exec_ctx* exec_ctx, void* server, + grpc_cq_completion* completion) { + server_unref(exec_ctx, (grpc_server*)server); } static int num_channels(grpc_server* server) { @@ -640,30 +659,34 @@ static int num_channels(grpc_server* server) { return n; } -static void kill_pending_work_locked(grpc_server* server, grpc_error* error) { +static void kill_pending_work_locked(grpc_exec_ctx* exec_ctx, + grpc_server* server, grpc_error* error) { if (server->started) { - request_matcher_kill_requests(server, &server->unregistered_request_matcher, + request_matcher_kill_requests(exec_ctx, server, + &server->unregistered_request_matcher, GRPC_ERROR_REF(error)); request_matcher_zombify_all_pending_calls( - &server->unregistered_request_matcher); + exec_ctx, &server->unregistered_request_matcher); for (registered_method* rm = server->registered_methods; rm; rm = rm->next) { - request_matcher_kill_requests(server, &rm->matcher, + request_matcher_kill_requests(exec_ctx, server, &rm->matcher, GRPC_ERROR_REF(error)); - request_matcher_zombify_all_pending_calls(&rm->matcher); + request_matcher_zombify_all_pending_calls(exec_ctx, &rm->matcher); } } GRPC_ERROR_UNREF(error); } -static void maybe_finish_shutdown(grpc_server* server) { +static void maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, + grpc_server* server) { size_t i; if (!gpr_atm_acq_load(&server->shutdown_flag) || server->shutdown_published) { return; } kill_pending_work_locked( - server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); + exec_ctx, server, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); if (server->root_channel_data.next != &server->root_channel_data || server->listeners_destroyed < num_listeners(server)) { @@ -683,13 +706,15 @@ static void maybe_finish_shutdown(grpc_server* server) { server->shutdown_published = 1; for (i = 0; i < server->num_shutdown_tags; i++) { server_ref(server); - grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag, - GRPC_ERROR_NONE, done_shutdown_event, server, + grpc_cq_end_op(exec_ctx, server->shutdown_tags[i].cq, + server->shutdown_tags[i].tag, GRPC_ERROR_NONE, + done_shutdown_event, server, &server->shutdown_tags[i].completion); } } -static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { +static void server_on_recv_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)ptr; call_data* calld = (call_data*)elem->call_data; grpc_millis op_deadline; @@ -703,10 +728,10 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); calld->path_set = true; calld->host_set = true; - grpc_metadata_batch_remove(calld->recv_initial_metadata, + grpc_metadata_batch_remove(exec_ctx, calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.path); grpc_metadata_batch_remove( - calld->recv_initial_metadata, + exec_ctx, calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.authority); } else { GRPC_ERROR_REF(error); @@ -724,7 +749,7 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { GRPC_ERROR_UNREF(src_error); } - GRPC_CLOSURE_RUN(calld->on_done_recv_initial_metadata, error); + GRPC_CLOSURE_RUN(exec_ctx, calld->on_done_recv_initial_metadata, error); } static void server_mutate_op(grpc_call_element* elem, @@ -745,21 +770,24 @@ static void server_mutate_op(grpc_call_element* elem, } static void server_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { server_mutate_op(elem, op); - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } -static void got_initial_metadata(void* ptr, grpc_error* error) { +static void got_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)ptr; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - start_new_rpc(elem); + start_new_rpc(exec_ctx, elem); } else { if (gpr_atm_full_cas(&calld->state, NOT_STARTED, ZOMBIED)) { GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, + GRPC_ERROR_NONE); } else if (gpr_atm_full_cas(&calld->state, PENDING, ZOMBIED)) { /* zombied call will be destroyed when it's removed from the pending queue... later */ @@ -767,7 +795,8 @@ static void got_initial_metadata(void* ptr, grpc_error* error) { } } -static void accept_stream(void* cd, grpc_transport* transport, +static void accept_stream(grpc_exec_ctx* exec_ctx, void* cd, + grpc_transport* transport, const void* transport_server_data) { channel_data* chand = (channel_data*)cd; /* create a call */ @@ -777,11 +806,11 @@ static void accept_stream(void* cd, grpc_transport* transport, args.server_transport_data = transport_server_data; args.send_deadline = GRPC_MILLIS_INF_FUTURE; grpc_call* call; - grpc_error* error = grpc_call_create(&args, &call); + grpc_error* error = grpc_call_create(exec_ctx, &args, &call); grpc_call_element* elem = grpc_call_stack_element(grpc_call_get_call_stack(call), 0); if (error != GRPC_ERROR_NONE) { - got_initial_metadata(elem, error); + got_initial_metadata(exec_ctx, elem, error); GRPC_ERROR_UNREF(error); return; } @@ -793,28 +822,32 @@ static void accept_stream(void* cd, grpc_transport* transport, &calld->initial_metadata; GRPC_CLOSURE_INIT(&calld->got_initial_metadata, got_initial_metadata, elem, grpc_schedule_on_exec_ctx); - grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata); + grpc_call_start_batch_and_execute(exec_ctx, call, &op, 1, + &calld->got_initial_metadata); } -static void channel_connectivity_changed(void* cd, grpc_error* error) { +static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* cd, + grpc_error* error) { channel_data* chand = (channel_data*)cd; grpc_server* server = chand->server; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(grpc_channel_stack_element( + grpc_channel_next_op(exec_ctx, + grpc_channel_stack_element( grpc_channel_get_channel_stack(chand->channel), 0), op); } else { gpr_mu_lock(&server->mu_global); - destroy_channel(chand, GRPC_ERROR_REF(error)); + destroy_channel(exec_ctx, chand, GRPC_ERROR_REF(error)); gpr_mu_unlock(&server->mu_global); - GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "connectivity"); + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, chand->channel, "connectivity"); } } -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -830,7 +863,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { channel_data* chand = (channel_data*)elem->channel_data; @@ -839,18 +872,19 @@ static void destroy_call_elem(grpc_call_element* elem, GPR_ASSERT(calld->state != PENDING); if (calld->host_set) { - grpc_slice_unref_internal(calld->host); + grpc_slice_unref_internal(exec_ctx, calld->host); } if (calld->path_set) { - grpc_slice_unref_internal(calld->path); + grpc_slice_unref_internal(exec_ctx, calld->path); } grpc_metadata_array_destroy(&calld->initial_metadata); grpc_byte_buffer_destroy(calld->payload); - server_unref(chand->server); + server_unref(exec_ctx, chand->server); } -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_first); @@ -866,14 +900,15 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem, return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { size_t i; channel_data* chand = (channel_data*)elem->channel_data; if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { - grpc_slice_unref_internal(chand->registered_methods[i].method); + grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].method); if (chand->registered_methods[i].has_host) { - grpc_slice_unref_internal(chand->registered_methods[i].host); + grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].host); } } gpr_free(chand->registered_methods); @@ -883,9 +918,9 @@ static void destroy_channel_elem(grpc_channel_element* elem) { chand->next->prev = chand->prev; chand->prev->next = chand->next; chand->next = chand->prev = chand; - maybe_finish_shutdown(chand->server); + maybe_finish_shutdown(exec_ctx, chand->server); gpr_mu_unlock(&chand->server->mu_global); - server_unref(chand->server); + server_unref(exec_ctx, chand->server); } } @@ -999,10 +1034,11 @@ void* grpc_server_register_method( return m; } -static void start_listeners(void* s, grpc_error* error) { +static void start_listeners(grpc_exec_ctx* exec_ctx, void* s, + grpc_error* error) { grpc_server* server = (grpc_server*)s; for (listener* l = server->listeners; l; l = l->next) { - l->start(server, l->arg, server->pollsets, server->pollset_count); + l->start(exec_ctx, server, l->arg, server->pollsets, server->pollset_count); } gpr_mu_lock(&server->mu_global); @@ -1010,12 +1046,12 @@ static void start_listeners(void* s, grpc_error* error) { gpr_cv_signal(&server->starting_cv); gpr_mu_unlock(&server->mu_global); - server_unref(server); + server_unref(exec_ctx, server); } void grpc_server_start(grpc_server* server) { size_t i; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server)); @@ -1037,9 +1073,12 @@ void grpc_server_start(grpc_server* server) { server_ref(server); server->starting = true; GRPC_CLOSURE_SCHED( + &exec_ctx, GRPC_CLOSURE_CREATE(start_listeners, server, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)), GRPC_ERROR_NONE); + + grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, @@ -1048,7 +1087,8 @@ void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, *pollsets = server->pollsets; } -void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, +void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, + grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args) { size_t num_registered_methods; @@ -1063,7 +1103,8 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, uint32_t max_probes = 0; grpc_transport_op* op = nullptr; - channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport); + channel = grpc_channel_create(exec_ctx, nullptr, args, GRPC_SERVER_CHANNEL, + transport); chand = (channel_data*)grpc_channel_stack_element( grpc_channel_get_channel_stack(channel), 0) ->channel_data; @@ -1140,19 +1181,21 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"); } - grpc_transport_perform_op(transport, op); + grpc_transport_perform_op(exec_ctx, transport, op); } -void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) { +void done_published_shutdown(grpc_exec_ctx* exec_ctx, void* done_arg, + grpc_cq_completion* storage) { (void)done_arg; gpr_free(storage); } -static void listener_destroy_done(void* s, grpc_error* error) { +static void listener_destroy_done(grpc_exec_ctx* exec_ctx, void* s, + grpc_error* error) { grpc_server* server = (grpc_server*)s; gpr_mu_lock(&server->mu_global); server->listeners_destroyed++; - maybe_finish_shutdown(server); + maybe_finish_shutdown(exec_ctx, server); gpr_mu_unlock(&server->mu_global); } @@ -1161,7 +1204,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, listener* l; shutdown_tag* sdt; channel_broadcaster broadcaster; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3, (server, cq, tag)); @@ -1176,10 +1219,11 @@ void grpc_server_shutdown_and_notify(grpc_server* server, /* stay locked, and gather up some stuff to do */ GPR_ASSERT(grpc_cq_begin_op(cq, tag)); if (server->shutdown_published) { - grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr, + grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown, + nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); gpr_mu_unlock(&server->mu_global); - return; + goto done; } server->shutdown_tags = (shutdown_tag*)gpr_realloc( server->shutdown_tags, @@ -1189,7 +1233,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, sdt->cq = cq; if (gpr_atm_acq_load(&server->shutdown_flag)) { gpr_mu_unlock(&server->mu_global); - return; + goto done; } server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME); @@ -1201,26 +1245,30 @@ void grpc_server_shutdown_and_notify(grpc_server* server, /* collect all unregistered then registered calls */ gpr_mu_lock(&server->mu_call); kill_pending_work_locked( - server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); + &exec_ctx, server, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); gpr_mu_unlock(&server->mu_call); - maybe_finish_shutdown(server); + maybe_finish_shutdown(&exec_ctx, server); gpr_mu_unlock(&server->mu_global); /* Shutdown listeners */ for (l = server->listeners; l; l = l->next) { GRPC_CLOSURE_INIT(&l->destroy_done, listener_destroy_done, server, grpc_schedule_on_exec_ctx); - l->destroy(server, l->arg, &l->destroy_done); + l->destroy(&exec_ctx, server, l->arg, &l->destroy_done); } - channel_broadcaster_shutdown(&broadcaster, true /* send_goaway */, + channel_broadcaster_shutdown(&exec_ctx, &broadcaster, true /* send_goaway */, GRPC_ERROR_NONE); + +done: + grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_cancel_all_calls(grpc_server* server) { channel_broadcaster broadcaster; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server)); @@ -1229,13 +1277,14 @@ void grpc_server_cancel_all_calls(grpc_server* server) { gpr_mu_unlock(&server->mu_global); channel_broadcaster_shutdown( - &broadcaster, false /* send_goaway */, + &exec_ctx, &broadcaster, false /* send_goaway */, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls")); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_destroy(grpc_server* server) { listener* l; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server)); @@ -1251,15 +1300,16 @@ void grpc_server_destroy(grpc_server* server) { gpr_mu_unlock(&server->mu_global); - server_unref(server); + server_unref(&exec_ctx, server); + grpc_exec_ctx_finish(&exec_ctx); } -void grpc_server_add_listener(grpc_server* server, void* arg, - void (*start)(grpc_server* server, void* arg, - grpc_pollset** pollsets, - size_t pollset_count), - void (*destroy)(grpc_server* server, void* arg, - grpc_closure* on_done)) { +void grpc_server_add_listener( + grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_pollset** pollsets, size_t pollset_count), + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_closure* on_done)) { listener* l = (listener*)gpr_malloc(sizeof(listener)); l->arg = arg; l->start = start; @@ -1268,12 +1318,13 @@ void grpc_server_add_listener(grpc_server* server, void* arg, server->listeners = l; } -static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx, +static grpc_call_error queue_call_request(grpc_exec_ctx* exec_ctx, + grpc_server* server, size_t cq_idx, requested_call* rc) { call_data* calld = nullptr; request_matcher* rm = nullptr; if (gpr_atm_acq_load(&server->shutdown_flag)) { - fail_call(server, cq_idx, rc, + fail_call(exec_ctx, server, cq_idx, rc, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); return GRPC_CALL_OK; } @@ -1300,9 +1351,10 @@ static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx, &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, + GRPC_ERROR_NONE); } else { - publish_call(server, calld, cq_idx, rc); + publish_call(exec_ctx, server, calld, cq_idx, rc); } gpr_mu_lock(&server->mu_call); } @@ -1317,9 +1369,9 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); - GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); + GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); GRPC_API_TRACE( "grpc_server_request_call(" "server=%p, call=%p, details=%p, initial_metadata=%p, " @@ -1352,9 +1404,9 @@ grpc_call_error grpc_server_request_call( rc->call = call; rc->data.batch.details = details; rc->initial_metadata = initial_metadata; - error = queue_call_request(server, cq_idx, rc); + error = queue_call_request(&exec_ctx, server, cq_idx, rc); done: - + grpc_exec_ctx_finish(&exec_ctx); return error; } @@ -1364,10 +1416,10 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); registered_method* rm = (registered_method*)rmp; - GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); + GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); GRPC_API_TRACE( "grpc_server_request_registered_call(" "server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, " @@ -1409,20 +1461,20 @@ grpc_call_error grpc_server_request_registered_call( rc->data.registered.deadline = deadline; rc->initial_metadata = initial_metadata; rc->data.registered.optional_payload = optional_payload; - error = queue_call_request(server, cq_idx, rc); + error = queue_call_request(&exec_ctx, server, cq_idx, rc); done: - + grpc_exec_ctx_finish(&exec_ctx); return error; } -static void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc, - grpc_error* error) { +static void fail_call(grpc_exec_ctx* exec_ctx, grpc_server* server, + size_t cq_idx, requested_call* rc, grpc_error* error) { *rc->call = nullptr; rc->initial_metadata->count = 0; GPR_ASSERT(error != GRPC_ERROR_NONE); - grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc, - &rc->completion); + grpc_cq_end_op(exec_ctx, server->cqs[cq_idx], rc->tag, error, + done_request_event, rc, &rc->completion); } const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) { diff --git a/src/core/lib/surface/server.h b/src/core/lib/surface/server.h index 63b6dff16b..d7ec025d95 100644 --- a/src/core/lib/surface/server.h +++ b/src/core/lib/surface/server.h @@ -31,16 +31,17 @@ extern grpc_core::TraceFlag grpc_server_channel_trace; /* Add a listener to the server: when the server starts, it will call start, and when it shuts down, it will call destroy */ -void grpc_server_add_listener(grpc_server* server, void* listener, - void (*start)(grpc_server* server, void* arg, - grpc_pollset** pollsets, - size_t npollsets), - void (*destroy)(grpc_server* server, void* arg, - grpc_closure* on_done)); +void grpc_server_add_listener( + grpc_exec_ctx* exec_ctx, grpc_server* server, void* listener, + void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_pollset** pollsets, size_t npollsets), + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, + grpc_closure* on_done)); /* Setup a transport - creates a channel stack, binds the transport to the server */ -void grpc_server_setup_transport(grpc_server* server, grpc_transport* transport, +void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* server, + grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args); diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 5fcc62ec43..bb0e583045 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -37,7 +37,7 @@ BdpEstimator::BdpEstimator(const char* name) bw_est_(0), name_(name) {} -grpc_millis BdpEstimator::CompletePing() { +grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx* exec_ctx) { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_); double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec; @@ -78,7 +78,7 @@ grpc_millis BdpEstimator::CompletePing() { } ping_state_ = PingState::UNSCHEDULED; accumulator_ = 0; - return grpc_core::ExecCtx::Get()->Now() + inter_ping_delay_; + return grpc_exec_ctx_now(exec_ctx) + inter_ping_delay_; } } // namespace grpc_core diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index e703af121c..df3a86c5f1 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -73,7 +73,7 @@ class BdpEstimator { } // Completes a previously started ping, returns when to schedule the next one - grpc_millis CompletePing(); + grpc_millis CompletePing(grpc_exec_ctx* exec_ctx); private: enum class PingState { UNSCHEDULED, SCHEDULED, STARTED }; diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc index 8dcb1e0bdb..b8720250e7 100644 --- a/src/core/lib/transport/byte_stream.cc +++ b/src/core/lib/transport/byte_stream.cc @@ -25,28 +25,34 @@ #include "src/core/lib/slice/slice_internal.h" -bool grpc_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, +bool grpc_byte_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - return byte_stream->vtable->next(byte_stream, max_size_hint, on_complete); + return byte_stream->vtable->next(exec_ctx, byte_stream, max_size_hint, + on_complete); } -grpc_error* grpc_byte_stream_pull(grpc_byte_stream* byte_stream, +grpc_error* grpc_byte_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_slice* slice) { - return byte_stream->vtable->pull(byte_stream, slice); + return byte_stream->vtable->pull(exec_ctx, byte_stream, slice); } -void grpc_byte_stream_shutdown(grpc_byte_stream* byte_stream, +void grpc_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_error* error) { - byte_stream->vtable->shutdown(byte_stream, error); + byte_stream->vtable->shutdown(exec_ctx, byte_stream, error); } -void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream) { - byte_stream->vtable->destroy(byte_stream); +void grpc_byte_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream) { + byte_stream->vtable->destroy(exec_ctx, byte_stream); } // grpc_slice_buffer_stream -static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream, +static bool slice_buffer_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; @@ -54,7 +60,8 @@ static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream, return true; } -static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, +static grpc_error* slice_buffer_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_slice* slice) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) { @@ -67,16 +74,18 @@ static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, return GRPC_ERROR_NONE; } -static void slice_buffer_stream_shutdown(grpc_byte_stream* byte_stream, +static void slice_buffer_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_error* error) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = error; } -static void slice_buffer_stream_destroy(grpc_byte_stream* byte_stream) { +static void slice_buffer_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; - grpc_slice_buffer_reset_and_unref_internal(stream->backing_buffer); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, stream->backing_buffer); GRPC_ERROR_UNREF(stream->shutdown_error); } @@ -104,22 +113,25 @@ void grpc_byte_stream_cache_init(grpc_byte_stream_cache* cache, grpc_slice_buffer_init(&cache->cache_buffer); } -void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache) { - grpc_byte_stream_destroy(cache->underlying_stream); - grpc_slice_buffer_destroy_internal(&cache->cache_buffer); +void grpc_byte_stream_cache_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream_cache* cache) { + grpc_byte_stream_destroy(exec_ctx, cache->underlying_stream); + grpc_slice_buffer_destroy_internal(exec_ctx, &cache->cache_buffer); } -static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, +static bool caching_byte_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) return true; if (stream->cursor < stream->cache->cache_buffer.count) return true; - return grpc_byte_stream_next(stream->cache->underlying_stream, max_size_hint, - on_complete); + return grpc_byte_stream_next(exec_ctx, stream->cache->underlying_stream, + max_size_hint, on_complete); } -static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, +static grpc_error* caching_byte_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_slice* slice) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) { @@ -132,7 +144,7 @@ static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, return GRPC_ERROR_NONE; } grpc_error* error = - grpc_byte_stream_pull(stream->cache->underlying_stream, slice); + grpc_byte_stream_pull(exec_ctx, stream->cache->underlying_stream, slice); if (error == GRPC_ERROR_NONE) { ++stream->cursor; grpc_slice_buffer_add(&stream->cache->cache_buffer, @@ -141,15 +153,17 @@ static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, return error; } -static void caching_byte_stream_shutdown(grpc_byte_stream* byte_stream, +static void caching_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_error* error) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = GRPC_ERROR_REF(error); - grpc_byte_stream_shutdown(stream->cache->underlying_stream, error); + grpc_byte_stream_shutdown(exec_ctx, stream->cache->underlying_stream, error); } -static void caching_byte_stream_destroy(grpc_byte_stream* byte_stream) { +static void caching_byte_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); } diff --git a/src/core/lib/transport/byte_stream.h b/src/core/lib/transport/byte_stream.h index 52c7a07f56..6bca154cb5 100644 --- a/src/core/lib/transport/byte_stream.h +++ b/src/core/lib/transport/byte_stream.h @@ -31,11 +31,13 @@ typedef struct grpc_byte_stream grpc_byte_stream; typedef struct { - bool (*next)(grpc_byte_stream* byte_stream, size_t max_size_hint, - grpc_closure* on_complete); - grpc_error* (*pull)(grpc_byte_stream* byte_stream, grpc_slice* slice); - void (*shutdown)(grpc_byte_stream* byte_stream, grpc_error* error); - void (*destroy)(grpc_byte_stream* byte_stream); + bool (*next)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, + size_t max_size_hint, grpc_closure* on_complete); + grpc_error* (*pull)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, + grpc_slice* slice); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, + grpc_error* error); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream); } grpc_byte_stream_vtable; struct grpc_byte_stream { @@ -50,7 +52,8 @@ struct grpc_byte_stream { // // max_size_hint can be set as a hint as to the maximum number // of bytes that would be acceptable to read. -bool grpc_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, +bool grpc_byte_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete); // Returns the next slice in the byte stream when it is ready (indicated by @@ -58,7 +61,8 @@ bool grpc_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, // grpc_byte_stream_next is called). // // Once a slice is returned into *slice, it is owned by the caller. -grpc_error* grpc_byte_stream_pull(grpc_byte_stream* byte_stream, +grpc_error* grpc_byte_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_slice* slice); // Shuts down the byte stream. @@ -68,10 +72,12 @@ grpc_error* grpc_byte_stream_pull(grpc_byte_stream* byte_stream, // // The next call to grpc_byte_stream_pull() (if any) will return the error // passed to grpc_byte_stream_shutdown(). -void grpc_byte_stream_shutdown(grpc_byte_stream* byte_stream, +void grpc_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, grpc_error* error); -void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream); +void grpc_byte_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream); // grpc_slice_buffer_stream // @@ -113,7 +119,8 @@ void grpc_byte_stream_cache_init(grpc_byte_stream_cache* cache, grpc_byte_stream* underlying_stream); // Must not be called while still in use by a grpc_caching_byte_stream. -void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache); +void grpc_byte_stream_cache_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream_cache* cache); typedef struct { grpc_byte_stream base; diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index c42cc9c8d0..e7e5dbd1f1 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -51,7 +51,8 @@ void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, tracker->name = gpr_strdup(name); } -void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { +void grpc_connectivity_state_destroy(grpc_exec_ctx* exec_ctx, + grpc_connectivity_state_tracker* tracker) { grpc_error* error; grpc_connectivity_state_watcher* w; while ((w = tracker->watchers)) { @@ -64,7 +65,7 @@ void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutdown connectivity owner"); } - GRPC_CLOSURE_SCHED(w->notify, error); + GRPC_CLOSURE_SCHED(exec_ctx, w->notify, error); gpr_free(w); } GRPC_ERROR_UNREF(tracker->current_error); @@ -104,8 +105,8 @@ bool grpc_connectivity_state_has_watchers( } bool grpc_connectivity_state_notify_on_state_change( - grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, - grpc_closure* notify) { + grpc_exec_ctx* exec_ctx, grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state* current, grpc_closure* notify) { grpc_connectivity_state cur = (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); @@ -122,7 +123,7 @@ bool grpc_connectivity_state_notify_on_state_change( if (current == nullptr) { grpc_connectivity_state_watcher* w = tracker->watchers; if (w != nullptr && w->notify == notify) { - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); tracker->watchers = w->next; gpr_free(w); return false; @@ -130,7 +131,7 @@ bool grpc_connectivity_state_notify_on_state_change( while (w != nullptr) { grpc_connectivity_state_watcher* rm_candidate = w->next; if (rm_candidate != nullptr && rm_candidate->notify == notify) { - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); w->next = w->next->next; gpr_free(rm_candidate); return false; @@ -141,7 +142,8 @@ bool grpc_connectivity_state_notify_on_state_change( } else { if (cur != *current) { *current = cur; - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_REF(tracker->current_error)); + GRPC_CLOSURE_SCHED(exec_ctx, notify, + GRPC_ERROR_REF(tracker->current_error)); } else { grpc_connectivity_state_watcher* w = (grpc_connectivity_state_watcher*)gpr_malloc(sizeof(*w)); @@ -154,7 +156,8 @@ bool grpc_connectivity_state_notify_on_state_change( } } -void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, +void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* error, const char* reason) { grpc_connectivity_state cur = @@ -192,7 +195,8 @@ void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, gpr_log(GPR_DEBUG, "NOTIFY: %p %s: %p", tracker, tracker->name, w->notify); } - GRPC_CLOSURE_SCHED(w->notify, GRPC_ERROR_REF(tracker->current_error)); + GRPC_CLOSURE_SCHED(exec_ctx, w->notify, + GRPC_ERROR_REF(tracker->current_error)); gpr_free(w); } } diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index c3a50f3211..653637ebea 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -51,11 +51,13 @@ const char* grpc_connectivity_state_name(grpc_connectivity_state state); void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state init_state, const char* name); -void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker); +void grpc_connectivity_state_destroy(grpc_exec_ctx* exec_ctx, + grpc_connectivity_state_tracker* tracker); /** Set connectivity state; not thread safe; access must be serialized with an * external lock */ -void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, +void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* associated_error, const char* reason); @@ -79,7 +81,7 @@ grpc_connectivity_state grpc_connectivity_state_get( case). Access must be serialized with an external lock. */ bool grpc_connectivity_state_notify_on_state_change( - grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, - grpc_closure* notify); + grpc_exec_ctx* exec_ctx, grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state* current, grpc_closure* notify); #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */ diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index ffaf327081..69c8ae6de3 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -40,9 +40,9 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, return nullptr; } -void grpc_error_get_status(grpc_error* error, grpc_millis deadline, - grpc_status_code* code, grpc_slice* slice, - grpc_http2_error_code* http_error, +void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, + grpc_millis deadline, grpc_status_code* code, + grpc_slice* slice, grpc_http2_error_code* http_error, const char** error_string) { // Start with the parent error and recurse through the tree of children // until we find the first one that has a status code. @@ -65,8 +65,8 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, status = (grpc_status_code)integer; } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer, - deadline); + status = grpc_http2_error_to_grpc_status( + exec_ctx, (grpc_http2_error_code)integer, deadline); } if (code != nullptr) *code = status; diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h index 4100f65d6d..8b006ae992 100644 --- a/src/core/lib/transport/error_utils.h +++ b/src/core/lib/transport/error_utils.h @@ -30,8 +30,9 @@ /// be populated with the entire error string. If any of the attributes (code, /// msg, http_status, error_string) are unneeded, they can be passed as /// NULL. -void grpc_error_get_status(grpc_error* error, grpc_millis deadline, - grpc_status_code* code, grpc_slice* slice, +void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, + grpc_millis deadline, grpc_status_code* code, + grpc_slice* slice, grpc_http2_error_code* http_status, const char** error_string); diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 5f0673e014..0f30c7533d 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -108,7 +108,7 @@ typedef struct mdtab_shard { static mdtab_shard g_shards[SHARD_COUNT]; -static void gc_mdtab(mdtab_shard* shard); +static void gc_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard); void grpc_mdctx_global_init(void) { /* initialize shards */ @@ -123,11 +123,11 @@ void grpc_mdctx_global_init(void) { } } -void grpc_mdctx_global_shutdown() { +void grpc_mdctx_global_shutdown(grpc_exec_ctx* exec_ctx) { for (size_t i = 0; i < SHARD_COUNT; i++) { mdtab_shard* shard = &g_shards[i]; gpr_mu_destroy(&shard->mu); - gc_mdtab(shard); + gc_mdtab(exec_ctx, shard); /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ if (shard->count != 0) { gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata elements were leaked", @@ -165,7 +165,7 @@ static void ref_md_locked(mdtab_shard* shard, } } -static void gc_mdtab(mdtab_shard* shard) { +static void gc_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard) { size_t i; interned_metadata** prev_next; interned_metadata *md, *next; @@ -178,8 +178,8 @@ static void gc_mdtab(mdtab_shard* shard) { void* user_data = (void*)gpr_atm_no_barrier_load(&md->user_data); next = md->bucket_next; if (gpr_atm_acq_load(&md->refcnt) == 0) { - grpc_slice_unref_internal(md->key); - grpc_slice_unref_internal(md->value); + grpc_slice_unref_internal(exec_ctx, md->key); + grpc_slice_unref_internal(exec_ctx, md->value); if (md->user_data) { ((destroy_user_data_func)gpr_atm_no_barrier_load( &md->destroy_user_data))(user_data); @@ -228,17 +228,17 @@ static void grow_mdtab(mdtab_shard* shard) { GPR_TIMER_END("grow_mdtab", 0); } -static void rehash_mdtab(mdtab_shard* shard) { +static void rehash_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard) { if (gpr_atm_no_barrier_load(&shard->free_estimate) > (gpr_atm)(shard->capacity / 4)) { - gc_mdtab(shard); + gc_mdtab(exec_ctx, shard); } else { grow_mdtab(shard); } } grpc_mdelem grpc_mdelem_create( - grpc_slice key, grpc_slice value, + grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value, grpc_mdelem_data* compatible_external_backing_store) { if (!grpc_slice_is_interned(key) || !grpc_slice_is_interned(value)) { if (compatible_external_backing_store != nullptr) { @@ -318,7 +318,7 @@ grpc_mdelem grpc_mdelem_create( shard->count++; if (shard->count > shard->capacity * 2) { - rehash_mdtab(shard); + rehash_mdtab(exec_ctx, shard); } gpr_mu_unlock(&shard->mu); @@ -328,20 +328,22 @@ grpc_mdelem grpc_mdelem_create( return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); } -grpc_mdelem grpc_mdelem_from_slices(grpc_slice key, grpc_slice value) { - grpc_mdelem out = grpc_mdelem_create(key, value, nullptr); - grpc_slice_unref_internal(key); - grpc_slice_unref_internal(value); +grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx* exec_ctx, grpc_slice key, + grpc_slice value) { + grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, nullptr); + grpc_slice_unref_internal(exec_ctx, key); + grpc_slice_unref_internal(exec_ctx, value); return out; } -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) { +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx* exec_ctx, + grpc_metadata* metadata) { bool changed = false; grpc_slice key_slice = grpc_slice_maybe_static_intern(metadata->key, &changed); grpc_slice value_slice = grpc_slice_maybe_static_intern(metadata->value, &changed); - return grpc_mdelem_create(key_slice, value_slice, + return grpc_mdelem_create(exec_ctx, key_slice, value_slice, changed ? nullptr : (grpc_mdelem_data*)metadata); } @@ -415,7 +417,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { return gmd; } -void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { +void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { switch (GRPC_MDELEM_STORAGE(gmd)) { case GRPC_MDELEM_STORAGE_EXTERNAL: case GRPC_MDELEM_STORAGE_STATIC: @@ -463,8 +465,8 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); GPR_ASSERT(prev_refcount >= 1); if (1 == prev_refcount) { - grpc_slice_unref_internal(md->key); - grpc_slice_unref_internal(md->value); + grpc_slice_unref_internal(exec_ctx, md->key); + grpc_slice_unref_internal(exec_ctx, md->value); gpr_free(md); } break; diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 78e6beff9b..8d4868d031 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -107,18 +107,20 @@ struct grpc_mdelem { (uintptr_t)GRPC_MDELEM_STORAGE_INTERNED_BIT)) /* Unrefs the slices. */ -grpc_mdelem grpc_mdelem_from_slices(grpc_slice key, grpc_slice value); +grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx* exec_ctx, grpc_slice key, + grpc_slice value); /* Cheaply convert a grpc_metadata to a grpc_mdelem; may use the grpc_metadata object as backing storage (so lifetimes should align) */ -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata); +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx* exec_ctx, + grpc_metadata* metadata); /* Does not unref the slices; if a new non-interned mdelem is needed, allocates one if compatible_external_backing_store is NULL, or uses compatible_external_backing_store if it is non-NULL (in which case it's the users responsibility to ensure that it outlives usage) */ grpc_mdelem grpc_mdelem_create( - grpc_slice key, grpc_slice value, + grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value, grpc_mdelem_data* compatible_external_backing_store); bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b); @@ -134,14 +136,16 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), #ifndef NDEBUG #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) -#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s), __FILE__, __LINE__) +#define GRPC_MDELEM_UNREF(exec_ctx, s) \ + grpc_mdelem_unref((exec_ctx), (s), __FILE__, __LINE__) grpc_mdelem grpc_mdelem_ref(grpc_mdelem md, const char* file, int line); -void grpc_mdelem_unref(grpc_mdelem md, const char* file, int line); +void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem md, + const char* file, int line); #else #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s)) -#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s)) +#define GRPC_MDELEM_UNREF(exec_ctx, s) grpc_mdelem_unref((exec_ctx), (s)) grpc_mdelem grpc_mdelem_ref(grpc_mdelem md); -void grpc_mdelem_unref(grpc_mdelem md); +void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem md); #endif #define GRPC_MDKEY(md) (GRPC_MDELEM_DATA(md)->key) @@ -158,6 +162,6 @@ void grpc_mdelem_unref(grpc_mdelem md); #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) void grpc_mdctx_global_init(void); -void grpc_mdctx_global_shutdown(); +void grpc_mdctx_global_shutdown(grpc_exec_ctx* exec_ctx); #endif /* GRPC_CORE_LIB_TRANSPORT_METADATA_H */ diff --git a/src/core/lib/transport/metadata_batch.cc b/src/core/lib/transport/metadata_batch.cc index 9c95339ba0..5817765aa3 100644 --- a/src/core/lib/transport/metadata_batch.cc +++ b/src/core/lib/transport/metadata_batch.cc @@ -51,7 +51,8 @@ static void assert_valid_list(grpc_mdelem_list* list) { #endif /* NDEBUG */ } -static void assert_valid_callouts(grpc_metadata_batch* batch) { +static void assert_valid_callouts(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch) { #ifndef NDEBUG for (grpc_linked_mdelem* l = batch->list.head; l != nullptr; l = l->next) { grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); @@ -60,7 +61,7 @@ static void assert_valid_callouts(grpc_metadata_batch* batch) { if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { GPR_ASSERT(batch->idx.array[callout_idx] == l); } - grpc_slice_unref_internal(key_interned); + grpc_slice_unref_internal(exec_ctx, key_interned); } #endif } @@ -76,10 +77,11 @@ void grpc_metadata_batch_init(grpc_metadata_batch* batch) { batch->deadline = GRPC_MILLIS_INF_FUTURE; } -void grpc_metadata_batch_destroy(grpc_metadata_batch* batch) { +void grpc_metadata_batch_destroy(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch) { grpc_linked_mdelem* l; for (l = batch->list.head; l; l = l->next) { - GRPC_MDELEM_UNREF(l->md); + GRPC_MDELEM_UNREF(exec_ctx, l->md); } } @@ -124,12 +126,13 @@ static void maybe_unlink_callout(grpc_metadata_batch* batch, batch->idx.array[idx] = nullptr; } -grpc_error* grpc_metadata_batch_add_head(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_add_head(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_head(batch, storage); + return grpc_metadata_batch_link_head(exec_ctx, batch, storage); } static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { @@ -147,25 +150,27 @@ static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); } -grpc_error* grpc_metadata_batch_link_head(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_link_head(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); grpc_error* err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return err; } link_head(&batch->list, storage); - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return GRPC_ERROR_NONE; } -grpc_error* grpc_metadata_batch_add_tail(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_add_tail(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_tail(batch, storage); + return grpc_metadata_batch_link_tail(exec_ctx, batch, storage); } static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { @@ -184,16 +189,17 @@ static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); } -grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_link_tail(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); grpc_error* err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return err; } link_tail(&batch->list, storage); - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return GRPC_ERROR_NONE; } @@ -214,28 +220,31 @@ static void unlink_storage(grpc_mdelem_list* list, assert_valid_list(list); } -void grpc_metadata_batch_remove(grpc_metadata_batch* batch, +void grpc_metadata_batch_remove(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); maybe_unlink_callout(batch, storage); unlink_storage(&batch->list, storage); - GRPC_MDELEM_UNREF(storage->md); - assert_valid_callouts(batch); + GRPC_MDELEM_UNREF(exec_ctx, storage->md); + assert_valid_callouts(exec_ctx, batch); } -void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage, +void grpc_metadata_batch_set_value(grpc_exec_ctx* exec_ctx, + grpc_linked_mdelem* storage, grpc_slice value) { grpc_mdelem old_mdelem = storage->md; grpc_mdelem new_mdelem = grpc_mdelem_from_slices( - grpc_slice_ref_internal(GRPC_MDKEY(old_mdelem)), value); + exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(old_mdelem)), value); storage->md = new_mdelem; - GRPC_MDELEM_UNREF(old_mdelem); + GRPC_MDELEM_UNREF(exec_ctx, old_mdelem); } -grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_substitute(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem new_mdelem) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); grpc_error* error = GRPC_ERROR_NONE; grpc_mdelem old_mdelem = storage->md; if (!grpc_slice_eq(GRPC_MDKEY(new_mdelem), GRPC_MDKEY(old_mdelem))) { @@ -244,18 +253,19 @@ grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch, error = maybe_link_callout(batch, storage); if (error != GRPC_ERROR_NONE) { unlink_storage(&batch->list, storage); - GRPC_MDELEM_UNREF(storage->md); + GRPC_MDELEM_UNREF(exec_ctx, storage->md); } } else { storage->md = new_mdelem; } - GRPC_MDELEM_UNREF(old_mdelem); - assert_valid_callouts(batch); + GRPC_MDELEM_UNREF(exec_ctx, old_mdelem); + assert_valid_callouts(exec_ctx, batch); return error; } -void grpc_metadata_batch_clear(grpc_metadata_batch* batch) { - grpc_metadata_batch_destroy(batch); +void grpc_metadata_batch_clear(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch) { + grpc_metadata_batch_destroy(exec_ctx, batch); grpc_metadata_batch_init(batch); } @@ -282,7 +292,8 @@ static void add_error(grpc_error** composite, grpc_error* error, *composite = grpc_error_add_child(*composite, error); } -grpc_error* grpc_metadata_batch_filter(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_filter(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_metadata_batch_filter_func func, void* user_data, const char* composite_error_string) { @@ -290,12 +301,12 @@ grpc_error* grpc_metadata_batch_filter(grpc_metadata_batch* batch, grpc_error* error = GRPC_ERROR_NONE; while (l) { grpc_linked_mdelem* next = l->next; - grpc_filtered_mdelem new_mdelem = func(user_data, l->md); + grpc_filtered_mdelem new_mdelem = func(exec_ctx, user_data, l->md); add_error(&error, new_mdelem.error, composite_error_string); if (GRPC_MDISNULL(new_mdelem.md)) { - grpc_metadata_batch_remove(batch, l); + grpc_metadata_batch_remove(exec_ctx, batch, l); } else if (new_mdelem.md.payload != l->md.payload) { - grpc_metadata_batch_substitute(batch, l, new_mdelem.md); + grpc_metadata_batch_substitute(exec_ctx, batch, l, new_mdelem.md); } l = next; } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 8353a426f8..adfb2d8069 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -53,23 +53,28 @@ typedef struct grpc_metadata_batch { } grpc_metadata_batch; void grpc_metadata_batch_init(grpc_metadata_batch* batch); -void grpc_metadata_batch_destroy(grpc_metadata_batch* batch); -void grpc_metadata_batch_clear(grpc_metadata_batch* batch); +void grpc_metadata_batch_destroy(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch); +void grpc_metadata_batch_clear(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch); bool grpc_metadata_batch_is_empty(grpc_metadata_batch* batch); /* Returns the transport size of the batch. */ size_t grpc_metadata_batch_size(grpc_metadata_batch* batch); /** Remove \a storage from the batch, unreffing the mdelem contained */ -void grpc_metadata_batch_remove(grpc_metadata_batch* batch, +void grpc_metadata_batch_remove(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage); /** Substitute a new mdelem for an old value */ -grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_substitute(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem new_value); -void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage, +void grpc_metadata_batch_set_value(grpc_exec_ctx* exec_ctx, + grpc_linked_mdelem* storage, grpc_slice value); /** Add \a storage to the beginning of \a batch. storage->md is @@ -77,17 +82,17 @@ void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage, \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error* grpc_metadata_batch_link_head(grpc_metadata_batch* batch, - grpc_linked_mdelem* storage) - GRPC_MUST_USE_RESULT; +grpc_error* grpc_metadata_batch_link_head( + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, + grpc_linked_mdelem* storage) GRPC_MUST_USE_RESULT; /** Add \a storage to the end of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch, - grpc_linked_mdelem* storage) - GRPC_MUST_USE_RESULT; +grpc_error* grpc_metadata_batch_link_tail( + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, + grpc_linked_mdelem* storage) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the first element in \a batch, using \a storage as backing storage for the linked list element. @@ -96,8 +101,8 @@ grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch, for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error* grpc_metadata_batch_add_head( - grpc_metadata_batch* batch, grpc_linked_mdelem* storage, - grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, + grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the @@ -105,8 +110,8 @@ grpc_error* grpc_metadata_batch_add_head( for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error* grpc_metadata_batch_add_tail( - grpc_metadata_batch* batch, grpc_linked_mdelem* storage, - grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, + grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; grpc_error* grpc_attach_md_to_error(grpc_error* src, grpc_mdelem md); @@ -123,10 +128,11 @@ typedef struct { { GRPC_ERROR_NONE, GRPC_MDNULL } typedef grpc_filtered_mdelem (*grpc_metadata_batch_filter_func)( - void* user_data, grpc_mdelem elem); + grpc_exec_ctx* exec_ctx, void* user_data, grpc_mdelem elem); grpc_error* grpc_metadata_batch_filter( - grpc_metadata_batch* batch, grpc_metadata_batch_filter_func func, - void* user_data, const char* composite_error_string) GRPC_MUST_USE_RESULT; + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, + grpc_metadata_batch_filter_func func, void* user_data, + const char* composite_error_string) GRPC_MUST_USE_RESULT; #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch* comd); diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc index cbafc33840..adcec8c444 100644 --- a/src/core/lib/transport/service_config.cc +++ b/src/core/lib/transport/service_config.cc @@ -152,8 +152,10 @@ static char* parse_json_method_name(grpc_json* json) { // each name found, incrementing \a idx for each entry added. // Returns false on error. static bool parse_json_method_config( - grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), void (*unref_value)(void* value), + grpc_exec_ctx* exec_ctx, grpc_json* json, + void* (*create_value)(const grpc_json* method_config_json), + void* (*ref_value)(void* value), + void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value), grpc_slice_hash_table_entry* entries, size_t* idx) { // Construct value. void* method_config = create_value(json); @@ -182,15 +184,16 @@ static bool parse_json_method_config( } success = true; done: - unref_value(method_config); + unref_value(exec_ctx, method_config); gpr_strvec_destroy(&paths); return success; } grpc_slice_hash_table* grpc_service_config_create_method_config_table( - const grpc_service_config* service_config, + grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), void (*unref_value)(void* value)) { + void* (*ref_value)(void* value), + void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value)) { const grpc_json* json = service_config->json_tree; // Traverse parsed JSON tree. if (json->type != GRPC_JSON_OBJECT || json->key != nullptr) return nullptr; @@ -214,11 +217,11 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( size_t idx = 0; for (grpc_json* method = field->child; method != nullptr; method = method->next) { - if (!parse_json_method_config(method, create_value, ref_value, + if (!parse_json_method_config(exec_ctx, method, create_value, ref_value, unref_value, entries, &idx)) { for (size_t i = 0; i < idx; ++i) { - grpc_slice_unref_internal(entries[i].key); - unref_value(entries[i].value); + grpc_slice_unref_internal(exec_ctx, entries[i].key); + unref_value(exec_ctx, entries[i].value); } gpr_free(entries); return nullptr; @@ -237,7 +240,8 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( return method_config_table; } -void* grpc_method_config_table_get(const grpc_slice_hash_table* table, +void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, + const grpc_slice_hash_table* table, grpc_slice path) { void* value = grpc_slice_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard @@ -253,7 +257,7 @@ void* grpc_method_config_table_get(const grpc_slice_hash_table* table, grpc_slice wildcard_path = grpc_slice_from_copied_string(buf); gpr_free(buf); value = grpc_slice_hash_table_get(table, wildcard_path); - grpc_slice_unref_internal(wildcard_path); + grpc_slice_unref_internal(exec_ctx, wildcard_path); gpr_free(path_str); } return value; diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h index 98554b9f0f..75a290bfd8 100644 --- a/src/core/lib/transport/service_config.h +++ b/src/core/lib/transport/service_config.h @@ -45,9 +45,10 @@ const char* grpc_service_config_get_lb_policy_name( /// \a ref_value() and \a unref_value() are used to ref and unref values. /// Returns NULL on error. grpc_slice_hash_table* grpc_service_config_create_method_config_table( - const grpc_service_config* service_config, + grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), void (*unref_value)(void* value)); + void* (*ref_value)(void* value), + void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value)); /// A helper function for looking up values in the table returned by /// \a grpc_service_config_create_method_config_table(). @@ -55,7 +56,8 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( /// the form "/service/method". /// Returns NULL if the method has no config. /// Caller does NOT own a reference to the result. -void* grpc_method_config_table_get(const grpc_slice_hash_table* table, +void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, + const grpc_slice_hash_table* table, grpc_slice path); #endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index 2213b30f56..844724cbeb 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -104,7 +104,7 @@ static uint8_t g_bytes[] = { 101, 44, 103, 122, 105, 112}; static void static_ref(void* unused) {} -static void static_unref(void* unused) {} +static void static_unref(grpc_exec_ctx* exec_ctx, void* unused) {} static const grpc_slice_refcount_vtable static_sub_vtable = { static_ref, static_unref, grpc_slice_default_eq_impl, grpc_slice_default_hash_impl}; diff --git a/src/core/lib/transport/status_conversion.cc b/src/core/lib/transport/status_conversion.cc index 46cba4292b..a0a5f1ba4b 100644 --- a/src/core/lib/transport/status_conversion.cc +++ b/src/core/lib/transport/status_conversion.cc @@ -37,7 +37,8 @@ grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status) { } } -grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, +grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx* exec_ctx, + grpc_http2_error_code error, grpc_millis deadline) { switch (error) { case GRPC_HTTP2_NO_ERROR: @@ -46,7 +47,7 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, case GRPC_HTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ - return grpc_core::ExecCtx::Get()->Now() > deadline + return grpc_exec_ctx_now(exec_ctx) > deadline ? GRPC_STATUS_DEADLINE_EXCEEDED : GRPC_STATUS_CANCELLED; case GRPC_HTTP2_ENHANCE_YOUR_CALM: diff --git a/src/core/lib/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h index 107eb92a53..3637b82801 100644 --- a/src/core/lib/transport/status_conversion.h +++ b/src/core/lib/transport/status_conversion.h @@ -25,7 +25,8 @@ /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status); -grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, +grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx* exec_ctx, + grpc_http2_error_code error, grpc_millis deadline); /* Conversion of HTTP status codes (:status) to grpc status codes */ diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 08aee04ac9..5bda1541a6 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -49,7 +49,8 @@ void grpc_stream_ref(grpc_stream_refcount* refcount) { } #ifndef NDEBUG -void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { +void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, + const char* reason) { if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p UNREF %" PRIdPTR "->%" PRIdPTR " %s", @@ -57,11 +58,11 @@ void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { val - 1, reason); } #else -void grpc_stream_unref(grpc_stream_refcount* refcount) { +void grpc_stream_unref(grpc_exec_ctx* exec_ctx, + grpc_stream_refcount* refcount) { #endif if (gpr_unref(&refcount->refs)) { - if (grpc_core::ExecCtx::Get()->flags() & - GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { + if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { /* Ick. The thread we're running on MAY be owned (indirectly) by a call-stack. If that's the case, destroying the call-stack MAY try to destroy the @@ -72,7 +73,7 @@ void grpc_stream_unref(grpc_stream_refcount* refcount) { refcount->destroy.scheduler = grpc_executor_scheduler(GRPC_EXECUTOR_SHORT); } - GRPC_CLOSURE_SCHED(&refcount->destroy, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &refcount->destroy, GRPC_ERROR_NONE); } } @@ -88,11 +89,11 @@ static void slice_stream_ref(void* p) { #endif } -static void slice_stream_unref(void* p) { +static void slice_stream_unref(grpc_exec_ctx* exec_ctx, void* p) { #ifndef NDEBUG - grpc_stream_unref(STREAM_REF_FROM_SLICE_REF(p), "slice"); + grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p), "slice"); #else - grpc_stream_unref(STREAM_REF_FROM_SLICE_REF(p)); + grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p)); #endif } @@ -150,50 +151,59 @@ size_t grpc_transport_stream_size(grpc_transport* transport) { return transport->vtable->sizeof_stream; } -void grpc_transport_destroy(grpc_transport* transport) { - transport->vtable->destroy(transport); +void grpc_transport_destroy(grpc_exec_ctx* exec_ctx, + grpc_transport* transport) { + transport->vtable->destroy(exec_ctx, transport); } -int grpc_transport_init_stream(grpc_transport* transport, grpc_stream* stream, +int grpc_transport_init_stream(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { - return transport->vtable->init_stream(transport, stream, refcount, + return transport->vtable->init_stream(exec_ctx, transport, stream, refcount, server_data, arena); } -void grpc_transport_perform_stream_op(grpc_transport* transport, +void grpc_transport_perform_stream_op(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_transport_stream_op_batch* op) { - transport->vtable->perform_stream_op(transport, stream, op); + transport->vtable->perform_stream_op(exec_ctx, transport, stream, op); } -void grpc_transport_perform_op(grpc_transport* transport, +void grpc_transport_perform_op(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_transport_op* op) { - transport->vtable->perform_op(transport, op); + transport->vtable->perform_op(exec_ctx, transport, op); } -void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, +void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, + grpc_stream* stream, grpc_polling_entity* pollent) { grpc_pollset* pollset; grpc_pollset_set* pollset_set; if ((pollset = grpc_polling_entity_pollset(pollent)) != nullptr) { - transport->vtable->set_pollset(transport, stream, pollset); + transport->vtable->set_pollset(exec_ctx, transport, stream, pollset); } else if ((pollset_set = grpc_polling_entity_pollset_set(pollent)) != nullptr) { - transport->vtable->set_pollset_set(transport, stream, pollset_set); + transport->vtable->set_pollset_set(exec_ctx, transport, stream, + pollset_set); } else { abort(); } } -void grpc_transport_destroy_stream(grpc_transport* transport, +void grpc_transport_destroy_stream(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_closure* then_schedule_closure) { - transport->vtable->destroy_stream(transport, stream, then_schedule_closure); + transport->vtable->destroy_stream(exec_ctx, transport, stream, + then_schedule_closure); } -grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport) { - return transport->vtable->get_endpoint(transport); +grpc_endpoint* grpc_transport_get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* transport) { + return transport->vtable->get_endpoint(exec_ctx, transport); } // This comment should be sung to the tune of @@ -204,23 +214,25 @@ grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport) { // though it lives in lib, it handles transport stream ops sure // it's grpc_transport_stream_op_batch_finish_with_failure void grpc_transport_stream_op_batch_finish_with_failure( - grpc_transport_stream_op_batch* batch, grpc_error* error, - grpc_call_combiner* call_combiner) { + grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* batch, + grpc_error* error, grpc_call_combiner* call_combiner) { if (batch->send_message) { - grpc_byte_stream_destroy(batch->payload->send_message.send_message); + grpc_byte_stream_destroy(exec_ctx, + batch->payload->send_message.send_message); } if (batch->recv_message) { - GRPC_CALL_COMBINER_START( - call_combiner, batch->payload->recv_message.recv_message_ready, - GRPC_ERROR_REF(error), "failing recv_message_ready"); + GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, + batch->payload->recv_message.recv_message_ready, + GRPC_ERROR_REF(error), + "failing recv_message_ready"); } if (batch->recv_initial_metadata) { GRPC_CALL_COMBINER_START( - call_combiner, + exec_ctx, call_combiner, batch->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_REF(error), "failing recv_initial_metadata_ready"); } - GRPC_CLOSURE_SCHED(batch->on_complete, error); + GRPC_CLOSURE_SCHED(exec_ctx, batch->on_complete, error); if (batch->cancel_stream) { GRPC_ERROR_UNREF(batch->payload->cancel_stream.cancel_error); } @@ -232,9 +244,10 @@ typedef struct { grpc_transport_op op; } made_transport_op; -static void destroy_made_transport_op(void* arg, grpc_error* error) { +static void destroy_made_transport_op(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { made_transport_op* op = (made_transport_op*)arg; - GRPC_CLOSURE_SCHED(op->inner_on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, op->inner_on_complete, GRPC_ERROR_REF(error)); gpr_free(op); } @@ -255,11 +268,12 @@ typedef struct { grpc_transport_stream_op_batch_payload payload; } made_transport_stream_op; -static void destroy_made_transport_stream_op(void* arg, grpc_error* error) { +static void destroy_made_transport_stream_op(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { made_transport_stream_op* op = (made_transport_stream_op*)arg; grpc_closure* c = op->inner_on_complete; gpr_free(op); - GRPC_CLOSURE_RUN(c, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_REF(error)); } grpc_transport_stream_op_batch* grpc_make_transport_stream_op( diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index b03c0218dc..b3cf04c22d 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -55,14 +55,15 @@ void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, grpc_iomgr_cb_func cb, void* cb_arg, const char* object_type); void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason); -void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason); +void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, + const char* reason); #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ grpc_stream_ref_init(rc, ir, cb, cb_arg, objtype) #else void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, grpc_iomgr_cb_func cb, void* cb_arg); void grpc_stream_ref(grpc_stream_refcount* refcount); -void grpc_stream_unref(grpc_stream_refcount* refcount); +void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount); #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ grpc_stream_ref_init(rc, ir, cb, cb_arg) #endif @@ -236,7 +237,8 @@ typedef struct grpc_transport_op { If true, the callback is set to set_accept_stream_fn, with its user_data argument set to set_accept_stream_user_data */ bool set_accept_stream; - void (*set_accept_stream_fn)(void* user_data, grpc_transport* transport, + void (*set_accept_stream_fn)(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_transport* transport, const void* server_data); void* set_accept_stream_user_data; /** add this transport to a pollset */ @@ -267,12 +269,13 @@ size_t grpc_transport_stream_size(grpc_transport* transport); stream - a pointer to uninitialized memory to initialize server_data - either NULL for a client initiated stream, or a pointer supplied from the accept_stream callback function */ -int grpc_transport_init_stream(grpc_transport* transport, grpc_stream* stream, +int grpc_transport_init_stream(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena); -void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, - grpc_polling_entity* pollent); +void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, + grpc_stream* stream, grpc_polling_entity* pollent); /* Destroy transport data for a stream. @@ -284,13 +287,14 @@ void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, transport - the transport on which to create this stream stream - the grpc_stream to destroy (memory is still owned by the caller, but any child memory must be cleaned up) */ -void grpc_transport_destroy_stream(grpc_transport* transport, +void grpc_transport_destroy_stream(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_closure* then_schedule_closure); void grpc_transport_stream_op_batch_finish_with_failure( - grpc_transport_stream_op_batch* op, grpc_error* error, - grpc_call_combiner* call_combiner); + grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* op, + grpc_error* error, grpc_call_combiner* call_combiner); char* grpc_transport_stream_op_batch_string(grpc_transport_stream_op_batch* op); char* grpc_transport_op_string(grpc_transport_op* op); @@ -305,11 +309,13 @@ char* grpc_transport_op_string(grpc_transport_op* op); non-NULL and previously initialized by the same transport. op - a grpc_transport_stream_op_batch specifying the op to perform */ -void grpc_transport_perform_stream_op(grpc_transport* transport, +void grpc_transport_perform_stream_op(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_stream* stream, grpc_transport_stream_op_batch* op); -void grpc_transport_perform_op(grpc_transport* transport, +void grpc_transport_perform_op(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, grpc_transport_op* op); /* Send a ping on a transport @@ -322,10 +328,11 @@ void grpc_transport_goaway(grpc_transport* transport, grpc_status_code status, grpc_slice debug_data); /* Destroy the transport */ -void grpc_transport_destroy(grpc_transport* transport); +void grpc_transport_destroy(grpc_exec_ctx* exec_ctx, grpc_transport* transport); /* Get the endpoint used by \a transport */ -grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport); +grpc_endpoint* grpc_transport_get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* transport); /* Allocate a grpc_transport_op, and preconfigure the on_consumed closure to \a on_consumed and then delete the returned transport op */ diff --git a/src/core/lib/transport/transport_impl.h b/src/core/lib/transport/transport_impl.h index 50b8a5f9b7..46be61427e 100644 --- a/src/core/lib/transport/transport_impl.h +++ b/src/core/lib/transport/transport_impl.h @@ -30,34 +30,37 @@ typedef struct grpc_transport_vtable { const char* name; /* implementation of grpc_transport_init_stream */ - int (*init_stream)(grpc_transport* self, grpc_stream* stream, - grpc_stream_refcount* refcount, const void* server_data, - gpr_arena* arena); + int (*init_stream)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena); /* implementation of grpc_transport_set_pollset */ - void (*set_pollset)(grpc_transport* self, grpc_stream* stream, - grpc_pollset* pollset); + void (*set_pollset)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_pollset* pollset); /* implementation of grpc_transport_set_pollset */ - void (*set_pollset_set)(grpc_transport* self, grpc_stream* stream, - grpc_pollset_set* pollset_set); + void (*set_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_pollset_set* pollset_set); /* implementation of grpc_transport_perform_stream_op */ - void (*perform_stream_op)(grpc_transport* self, grpc_stream* stream, + void (*perform_stream_op)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_transport_stream_op_batch* op); /* implementation of grpc_transport_perform_op */ - void (*perform_op)(grpc_transport* self, grpc_transport_op* op); + void (*perform_op)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_transport_op* op); /* implementation of grpc_transport_destroy_stream */ - void (*destroy_stream)(grpc_transport* self, grpc_stream* stream, + void (*destroy_stream)(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_closure* then_schedule_closure); /* implementation of grpc_transport_destroy */ - void (*destroy)(grpc_transport* self); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_transport* self); /* implementation of grpc_transport_get_endpoint */ - grpc_endpoint* (*get_endpoint)(grpc_transport* self); + grpc_endpoint* (*get_endpoint)(grpc_exec_ctx* exec_ctx, grpc_transport* self); } grpc_transport_vtable; /* an instance of a grpc transport */ diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index b907636f9d..f2f365fc0f 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -399,7 +399,8 @@ static const tsi_frame_protector_vtable frame_protector_vtable = { /* --- tsi_zero_copy_grpc_protector methods implementation. ---*/ static tsi_result fake_zero_copy_grpc_protector_protect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { @@ -423,7 +424,8 @@ static tsi_result fake_zero_copy_grpc_protector_protect( } static tsi_result fake_zero_copy_grpc_protector_unprotect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { @@ -452,18 +454,18 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( impl->parsed_frame_size - TSI_FAKE_FRAME_HEADER_SIZE, unprotected_slices); impl->parsed_frame_size = 0; - grpc_slice_buffer_reset_and_unref_internal(&impl->header_sb); + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &impl->header_sb); } return TSI_OK; } static void fake_zero_copy_grpc_protector_destroy( - tsi_zero_copy_grpc_protector* self) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; tsi_fake_zero_copy_grpc_protector* impl = (tsi_fake_zero_copy_grpc_protector*)self; - grpc_slice_buffer_destroy_internal(&impl->header_sb); - grpc_slice_buffer_destroy_internal(&impl->protected_sb); + grpc_slice_buffer_destroy_internal(exec_ctx, &impl->header_sb); + grpc_slice_buffer_destroy_internal(exec_ctx, &impl->protected_sb); gpr_free(impl); } @@ -495,7 +497,8 @@ static tsi_result fake_handshaker_result_extract_peer( } static tsi_result fake_handshaker_result_create_zero_copy_grpc_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + void* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { *protector = tsi_create_fake_zero_copy_grpc_protector(max_output_protected_frame_size); diff --git a/src/core/tsi/transport_security.h b/src/core/tsi/transport_security.h index ed662d48af..bf3a776b11 100644 --- a/src/core/tsi/transport_security.h +++ b/src/core/tsi/transport_security.h @@ -90,7 +90,7 @@ struct tsi_handshaker { typedef struct { tsi_result (*extract_peer)(const tsi_handshaker_result* self, tsi_peer* peer); tsi_result (*create_zero_copy_grpc_protector)( - const tsi_handshaker_result* self, + void* exec_ctx, const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector); tsi_result (*create_frame_protector)(const tsi_handshaker_result* self, diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index 76f7ae782f..875d367218 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -20,16 +20,18 @@ /* This method creates a tsi_zero_copy_grpc_protector object. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { - if (self == nullptr || self->vtable == nullptr || protector == nullptr) { + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + protector == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->create_zero_copy_grpc_protector == nullptr) { return TSI_UNIMPLEMENTED; } return self->vtable->create_zero_copy_grpc_protector( - self, max_output_protected_frame_size, protector); + exec_ctx, self, max_output_protected_frame_size, protector); } /* --- tsi_zero_copy_grpc_protector common implementation. --- @@ -37,28 +39,33 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( Calls specific implementation after state/input validation. */ tsi_result tsi_zero_copy_grpc_protector_protect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { - if (self == nullptr || self->vtable == nullptr || + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->protect == nullptr) return TSI_UNIMPLEMENTED; - return self->vtable->protect(self, unprotected_slices, protected_slices); + return self->vtable->protect(exec_ctx, self, unprotected_slices, + protected_slices); } tsi_result tsi_zero_copy_grpc_protector_unprotect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { - if (self == nullptr || self->vtable == nullptr || + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || protected_slices == nullptr || unprotected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->unprotect == nullptr) return TSI_UNIMPLEMENTED; - return self->vtable->unprotect(self, protected_slices, unprotected_slices); + return self->vtable->unprotect(exec_ctx, self, protected_slices, + unprotected_slices); } -void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self) { +void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; - self->vtable->destroy(self); + self->vtable->destroy(exec_ctx, self); } diff --git a/src/core/tsi/transport_security_grpc.h b/src/core/tsi/transport_security_grpc.h index 0156ff1c68..9fccfd79dd 100644 --- a/src/core/tsi/transport_security_grpc.h +++ b/src/core/tsi/transport_security_grpc.h @@ -26,7 +26,8 @@ assuming there is no fatal error. The caller is responsible for destroying the protector. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector); /* -- tsi_zero_copy_grpc_protector object -- */ @@ -38,8 +39,8 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - This method returns TSI_OK in case of success or a specific error code in case of failure. */ tsi_result tsi_zero_copy_grpc_protector_protect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices); + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices); /* Outputs unprotected bytes. - protected_slices is the bytes of protected frames. @@ -48,21 +49,24 @@ tsi_result tsi_zero_copy_grpc_protector_protect( there is not enough data to output in which case unprotected_slices has 0 bytes. */ tsi_result tsi_zero_copy_grpc_protector_unprotect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices); + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices); /* Destroys the tsi_zero_copy_grpc_protector object. */ -void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self); +void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self); /* Base for tsi_zero_copy_grpc_protector implementations. */ typedef struct { - tsi_result (*protect)(tsi_zero_copy_grpc_protector* self, + tsi_result (*protect)(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices); - tsi_result (*unprotect)(tsi_zero_copy_grpc_protector* self, + tsi_result (*unprotect)(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices); - void (*destroy)(tsi_zero_copy_grpc_protector* self); + void (*destroy)(grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self); } tsi_zero_copy_grpc_protector_vtable; struct tsi_zero_copy_grpc_protector { diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index b696774243..cae9ef953a 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -66,12 +66,13 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } ChannelArguments::~ChannelArguments() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == GRPC_ARG_POINTER) { - it->value.pointer.vtable->destroy(it->value.pointer.p); + it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); } } + grpc_exec_ctx_finish(&exec_ctx); } void ChannelArguments::Swap(ChannelArguments& other) { @@ -94,17 +95,17 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { } grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator); bool replaced = false; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { GPR_ASSERT(!replaced); - it->value.pointer.vtable->destroy(it->value.pointer.p); + it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); it->value.pointer = mutator_arg.value.pointer; replaced = true; } } - + grpc_exec_ctx_finish(&exec_ctx); if (!replaced) { args_.push_back(mutator_arg); } diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index cbe2a209f5..274079f8dd 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -27,39 +27,43 @@ namespace grpc { // MetadataBatch -grpc_linked_mdelem* MetadataBatch::AddMetadata(const string& key, +grpc_linked_mdelem* MetadataBatch::AddMetadata(grpc_exec_ctx* exec_ctx, + const string& key, const string& value) { grpc_linked_mdelem* storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); - storage->md = grpc_mdelem_from_slices(SliceFromCopiedString(key), + storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), SliceFromCopiedString(value)); GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(batch_, storage)); + grpc_metadata_batch_link_head(exec_ctx, batch_, storage)); return storage; } // ChannelData -void ChannelData::StartTransportOp(grpc_channel_element* elem, +void ChannelData::StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, TransportOp* op) { - grpc_channel_next_op(elem, op->op()); + grpc_channel_next_op(exec_ctx, elem, op->op()); } -void ChannelData::GetInfo(grpc_channel_element* elem, +void ChannelData::GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, const grpc_channel_info* channel_info) { - grpc_channel_next_get_info(elem, channel_info); + grpc_channel_next_get_info(exec_ctx, elem, channel_info); } // CallData -void CallData::StartTransportStreamOpBatch(grpc_call_element* elem, +void CallData::StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, TransportStreamOpBatch* op) { - grpc_call_next_op(elem, op->op()); + grpc_call_next_op(exec_ctx, elem, op->op()); } -void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem, +void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) { - grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent); + grpc_call_stack_ignore_set_pollset_or_pollset_set(exec_ctx, elem, pollent); } // internal code used by RegisterChannelFilter() @@ -71,7 +75,8 @@ std::vector* channel_filters; namespace { -bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) { +bool MaybeAddFilter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { const FilterRecord& filter = *(FilterRecord*)arg; if (filter.include_filter) { const grpc_channel_args* args = diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index a1f42c0b32..9fe9cf0aea 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -54,7 +54,8 @@ class MetadataBatch { /// Adds metadata and returns the newly allocated storage. /// The caller takes ownership of the result, which must exist for the /// lifetime of the gRPC call. - grpc_linked_mdelem* AddMetadata(const string& key, const string& value); + grpc_linked_mdelem* AddMetadata(grpc_exec_ctx* exec_ctx, const string& key, + const string& value); class const_iterator : public std::iterator { @@ -221,17 +222,18 @@ class ChannelData { // TODO(roth): Come up with a more C++-like API for the channel element. /// Initializes the channel data. - virtual grpc_error* Init(grpc_channel_element* elem, + virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_channel_element* elem) {} + virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} - virtual void StartTransportOp(grpc_channel_element* elem, TransportOp* op); + virtual void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, TransportOp* op); - virtual void GetInfo(grpc_channel_element* elem, + virtual void GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, const grpc_channel_info* channel_info); }; @@ -244,22 +246,24 @@ class CallData { // TODO(roth): Come up with a more C++-like API for the call element. /// Initializes the call data. - virtual grpc_error* Init(grpc_call_element* elem, + virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_call_element* elem, + virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_call_closure) {} /// Starts a new stream operation. - virtual void StartTransportStreamOpBatch(grpc_call_element* elem, + virtual void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, TransportStreamOpBatch* op); /// Sets a pollset or pollset set. - virtual void SetPollsetOrPollsetSet(grpc_call_element* elem, + virtual void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent); }; @@ -273,63 +277,71 @@ class ChannelFilter final { public: static const size_t channel_data_size = sizeof(ChannelDataType); - static grpc_error* InitChannelElement(grpc_channel_element* elem, + static grpc_error* InitChannelElement(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { // Construct the object in the already-allocated memory. ChannelDataType* channel_data = new (elem->channel_data) ChannelDataType(); - return channel_data->Init(elem, args); + return channel_data->Init(exec_ctx, elem, args); } - static void DestroyChannelElement(grpc_channel_element* elem) { + static void DestroyChannelElement(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); - channel_data->Destroy(elem); + channel_data->Destroy(exec_ctx, elem); channel_data->~ChannelDataType(); } - static void StartTransportOp(grpc_channel_element* elem, + static void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); TransportOp op_wrapper(op); - channel_data->StartTransportOp(elem, &op_wrapper); + channel_data->StartTransportOp(exec_ctx, elem, &op_wrapper); } - static void GetChannelInfo(grpc_channel_element* elem, + static void GetChannelInfo(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, const grpc_channel_info* channel_info) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); - channel_data->GetInfo(elem, channel_info); + channel_data->GetInfo(exec_ctx, elem, channel_info); } static const size_t call_data_size = sizeof(CallDataType); - static grpc_error* InitCallElement(grpc_call_element* elem, + static grpc_error* InitCallElement(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { // Construct the object in the already-allocated memory. CallDataType* call_data = new (elem->call_data) CallDataType(); - return call_data->Init(elem, args); + return call_data->Init(exec_ctx, elem, args); } - static void DestroyCallElement(grpc_call_element* elem, + static void DestroyCallElement(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_call_closure) { CallDataType* call_data = reinterpret_cast(elem->call_data); - call_data->Destroy(elem, final_info, then_call_closure); + call_data->Destroy(exec_ctx, elem, final_info, then_call_closure); call_data->~CallDataType(); } - static void StartTransportStreamOpBatch(grpc_call_element* elem, + static void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { CallDataType* call_data = reinterpret_cast(elem->call_data); TransportStreamOpBatch op_wrapper(op); - call_data->StartTransportStreamOpBatch(elem, &op_wrapper); + call_data->StartTransportStreamOpBatch(exec_ctx, elem, &op_wrapper); } - static void SetPollsetOrPollsetSet(grpc_call_element* elem, + static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) { CallDataType* call_data = reinterpret_cast(elem->call_data); - call_data->SetPollsetOrPollsetSet(elem, pollent); + call_data->SetPollsetOrPollsetSet(exec_ctx, elem, pollent); } }; diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm index d130971364..d5e668a858 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm @@ -110,12 +110,13 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void cronet_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx ctx = GRPC_EXEC_CTX_INIT; stream_engine *cronetEngine = [Cronet getGlobalEngine]; grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args); cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine); - grpc_channel_args_destroy(new_client_args); + grpc_channel_args_destroy(&ctx, new_client_args); + grpc_exec_ctx_finish(&ctx); } static int fail_server_auth_check(grpc_channel_args *server_args) { diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 6377008a3b..fae77843f0 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -558,7 +558,7 @@ extern grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import; typedef void(*grpc_slice_buffer_move_first_no_ref_type)(grpc_slice_buffer* src, size_t n, grpc_slice_buffer* dst); extern grpc_slice_buffer_move_first_no_ref_type grpc_slice_buffer_move_first_no_ref_import; #define grpc_slice_buffer_move_first_no_ref grpc_slice_buffer_move_first_no_ref_import -typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_slice_buffer* src, size_t n, void* dst); +typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* src, size_t n, void* dst); extern grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import; #define grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer_import typedef grpc_slice(*grpc_slice_buffer_take_first_type)(grpc_slice_buffer* src); diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index d3115fe1dd..ef2de8d638 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -18,7 +18,6 @@ #include "src/core/lib/backoff/backoff.h" -#include #include #include @@ -33,24 +32,23 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + exec_ctx.now = next_deadlines.current_deadline; } + grpc_exec_ctx_finish(&exec_ctx); } static void test_min_connect(void) { @@ -62,16 +60,17 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next = grpc_backoff_begin(&backoff); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next = grpc_backoff_begin(&exec_ctx, &backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == + GPR_ASSERT(next.current_deadline - grpc_exec_ctx_now(&exec_ctx) == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == + GPR_ASSERT(next.next_attempt_start_time - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_jitter_backoff(void) { @@ -85,47 +84,49 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - grpc_core::ExecCtx exec_ctx; - grpc_core::ExecCtx::Get()->TestOnlySetNow(0); - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx.now = 0; + exec_ctx.now_is_valid = true; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); + grpc_exec_ctx_finish(&exec_ctx); } static void test_jitter_backoff(void) { @@ -141,13 +142,12 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); grpc_millis expected_next_lower_bound = @@ -156,11 +156,11 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 + jitter)); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); + next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -169,13 +169,13 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + exec_ctx.now = next_deadlines.current_deadline; } + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); gpr_time_init(); test_constant_backoff(); @@ -183,6 +183,5 @@ int main(int argc, char** argv) { test_no_jitter_backoff(); test_jitter_backoff(); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 4c1642aa5d..d8bb092e14 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -50,19 +50,20 @@ static void thd_func(void* arg) { gpr_event_set(&a->done_thd, (void*)1); } -static void done_write(void* arg, grpc_error* error) { +static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { thd_args* a = (thd_args*)arg; gpr_event_set(&a->done_write, (void*)1); } static void server_setup_transport(void* ts, grpc_transport* transport) { thd_args* a = (thd_args*)ts; - grpc_core::ExecCtx exec_ctx; - grpc_server_setup_transport(a->server, transport, nullptr, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, a->server, transport, nullptr, grpc_server_get_channel_args(a->server)); + grpc_exec_ctx_finish(&exec_ctx); } -static void read_done(void* arg, grpc_error* error) { +static void read_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { gpr_event* read_done = (gpr_event*)arg; gpr_event_set(read_done, (void*)1); } @@ -80,7 +81,7 @@ void grpc_run_bad_client_test( grpc_slice_from_copied_buffer(client_payload, client_payload_length); grpc_slice_buffer outgoing; grpc_closure done_write_closure; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_completion_queue* shutdown_cq; if (client_payload_length < 4 * 1024) { @@ -114,13 +115,15 @@ void grpc_run_bad_client_test( GRPC_BAD_CLIENT_REGISTERED_HOST, GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); grpc_server_start(a.server); - transport = grpc_create_chttp2_transport(nullptr, sfd.server, false); + transport = + grpc_create_chttp2_transport(&exec_ctx, nullptr, sfd.server, false); server_setup_transport(&a, transport); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); /* Bind everything into the same pollset */ - grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); - grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(&exec_ctx, sfd.client, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(&exec_ctx, sfd.server, grpc_cq_pollset(a.cq)); /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); @@ -134,8 +137,8 @@ void grpc_run_bad_client_test( grpc_schedule_on_exec_ctx); /* Write data */ - grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure); - grpc_core::ExecCtx::Get()->Flush(); + grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); + grpc_exec_ctx_finish(&exec_ctx); /* Await completion, unless the request is large and write may not finish * before the peer shuts down. */ @@ -146,9 +149,10 @@ void grpc_run_bad_client_test( if (flags & GRPC_BAD_CLIENT_DISCONNECT) { grpc_endpoint_shutdown( - sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); - grpc_endpoint_destroy(sfd.client); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, sfd.client, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); sfd.client = nullptr; } @@ -167,8 +171,9 @@ void grpc_run_bad_client_test( grpc_closure read_done_closure; GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(sfd.client, &incoming, &read_done_closure); - grpc_core::ExecCtx::Get()->Flush(); + grpc_endpoint_read(&exec_ctx, sfd.client, &incoming, + &read_done_closure); + grpc_exec_ctx_finish(&exec_ctx); do { GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); GPR_ASSERT( @@ -181,13 +186,14 @@ void grpc_run_bad_client_test( "client validator failed; trying additional read " "in case we didn't get all the data"); } - grpc_slice_buffer_destroy_internal(&incoming); + grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); } // Shutdown. grpc_endpoint_shutdown( - sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(sfd.client); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, sfd.client, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT( @@ -201,7 +207,8 @@ void grpc_run_bad_client_test( grpc_completion_queue_destroy(shutdown_cq); grpc_server_destroy(a.server); grpc_completion_queue_destroy(a.cq); - grpc_slice_buffer_destroy_internal(&outgoing); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } diff --git a/test/core/bad_client/tests/badreq.cc b/test/core/bad_client/tests/badreq.cc index eeaf4c9974..c30244e0cd 100644 --- a/test/core/bad_client/tests/badreq.cc +++ b/test/core/bad_client/tests/badreq.cc @@ -20,8 +20,6 @@ #include -#include - #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -40,7 +38,6 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* invalid content type */ GRPC_RUN_BAD_CLIENT_TEST( @@ -129,6 +126,5 @@ int main(int argc, char** argv) { "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", GRPC_BAD_CLIENT_DISCONNECT); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/connection_prefix.cc b/test/core/bad_client/tests/connection_prefix.cc index 4aab234d3e..47252f9f10 100644 --- a/test/core/bad_client/tests/connection_prefix.cc +++ b/test/core/bad_client/tests/connection_prefix.cc @@ -30,7 +30,6 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "X", 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PX", 0); @@ -58,7 +57,5 @@ int main(int argc, char** argv) { 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", 0); - - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc index f56c4d71dd..bbc5611991 100644 --- a/test/core/bad_client/tests/head_of_line_blocking.cc +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -20,7 +20,6 @@ #include -#include #include #include "src/core/lib/surface/server.h" @@ -110,7 +109,6 @@ static void addbuf(const void* data, size_t len) { int main(int argc, char** argv) { int i; grpc_test_init(argc, argv); - grpc_init(); #define NUM_FRAMES 10 #define FRAME_SIZE 1000 @@ -133,7 +131,6 @@ int main(int argc, char** argv) { } grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, 0); gpr_free(g_buffer); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/headers.cc b/test/core/bad_client/tests/headers.cc index 2aa1b280ce..50bb72c493 100644 --- a/test/core/bad_client/tests/headers.cc +++ b/test/core/bad_client/tests/headers.cc @@ -34,7 +34,6 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* partial http2 header prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -336,6 +335,5 @@ int main(int argc, char** argv) { "15 seconds", GRPC_BAD_CLIENT_DISCONNECT); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/initial_settings_frame.cc b/test/core/bad_client/tests/initial_settings_frame.cc index 0220000ece..edc52f503e 100644 --- a/test/core/bad_client/tests/initial_settings_frame.cc +++ b/test/core/bad_client/tests/initial_settings_frame.cc @@ -33,7 +33,6 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* various partial prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -107,6 +106,5 @@ int main(int argc, char** argv) { PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", GRPC_BAD_CLIENT_DISCONNECT); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc index c2dc9c66af..6613c94b41 100644 --- a/test/core/bad_client/tests/server_registered_method.cc +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -77,7 +77,6 @@ static void verifier_fails(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* body generated with * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ @@ -124,6 +123,5 @@ int main(int argc, char** argv) { "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", 0); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc index c80fc5cb4a..9f4a03e69b 100644 --- a/test/core/bad_client/tests/simple_request.cc +++ b/test/core/bad_client/tests/simple_request.cc @@ -20,8 +20,6 @@ #include -#include - #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -124,7 +122,6 @@ static void failure_verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* basic request: check that things are working */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR, 0); @@ -167,6 +164,5 @@ int main(int argc, char** argv) { GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, nullptr, PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/unknown_frame.cc b/test/core/bad_client/tests/unknown_frame.cc index b1b618a43f..d962a4244d 100644 --- a/test/core/bad_client/tests/unknown_frame.cc +++ b/test/core/bad_client/tests/unknown_frame.cc @@ -33,7 +33,6 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, } int main(int argc, char** argv) { - grpc_init(); grpc_test_init(argc, argv); /* test adding prioritization data */ @@ -41,6 +40,5 @@ int main(int argc, char** argv) { PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", GRPC_BAD_CLIENT_DISCONNECT); - grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc index ed8279c951..f4bd81828b 100644 --- a/test/core/bad_client/tests/window_overflow.cc +++ b/test/core/bad_client/tests/window_overflow.cc @@ -20,7 +20,6 @@ #include -#include #include #include "src/core/lib/surface/server.h" @@ -73,7 +72,6 @@ int main(int argc, char** argv) { #define SEND_SIZE (6 * 1024 * 1024) #define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) grpc_test_init(argc, argv); - grpc_init(); addbuf(PFX_STR, sizeof(PFX_STR) - 1); for (i = 0; i < NUM_FRAMES; i++) { @@ -95,7 +93,6 @@ int main(int argc, char** argv) { grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, GRPC_BAD_CLIENT_LARGE_REQUEST); gpr_free(g_buffer); - grpc_shutdown(); return 0; } diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index 4a8195e984..e8b3334185 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -26,7 +26,7 @@ #include "test/core/util/test_config.h" static void test_create(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_arg arg_int; grpc_arg arg_string; @@ -55,11 +55,12 @@ static void test_create(void) { GPR_ASSERT(strcmp(ch_args->args[1].value.string, arg_string.value.string) == 0); - grpc_channel_args_destroy(ch_args); + grpc_channel_args_destroy(&exec_ctx, ch_args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_set_compression_algorithm(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args* ch_args; ch_args = @@ -69,11 +70,12 @@ static void test_set_compression_algorithm(void) { GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER); - grpc_channel_args_destroy(ch_args); + grpc_channel_args_destroy(&exec_ctx, ch_args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_compression_algorithm_states(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; unsigned states_bitset; size_t i; @@ -89,10 +91,10 @@ static void test_compression_algorithm_states(void) { /* disable gzip and deflate */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &ch_args, GRPC_COMPRESS_GZIP, 0); + &exec_ctx, &ch_args, GRPC_COMPRESS_GZIP, 0); GPR_ASSERT(ch_args == ch_args_wo_gzip); ch_args_wo_gzip_deflate = grpc_channel_args_compression_algorithm_set_state( - &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); + &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -107,7 +109,7 @@ static void test_compression_algorithm_states(void) { /* re-enabled gzip only */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); + &exec_ctx, &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -120,7 +122,8 @@ static void test_compression_algorithm_states(void) { } } - grpc_channel_args_destroy(ch_args); + grpc_channel_args_destroy(&exec_ctx, ch_args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_set_socket_mutator(void) { @@ -134,8 +137,9 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(ch_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, ch_args); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/channel/channel_stack_builder_test.cc b/test/core/channel/channel_stack_builder_test.cc index ef6db81b0b..a67f0efafe 100644 --- a/test/core/channel/channel_stack_builder_test.cc +++ b/test/core/channel/channel_stack_builder_test.cc @@ -29,30 +29,34 @@ #include "src/core/lib/surface/channel_init.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_call_element* elem, +static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} -static void call_destroy_func(grpc_call_element* elem, +static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static void call_func(grpc_call_element* elem, +static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op_batch* op) {} -static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { +static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } bool g_replacement_fn_called = false; @@ -102,7 +106,8 @@ const grpc_channel_filter original_filter = { grpc_channel_next_get_info, "filter_name"}; -static bool add_replacement_filter(grpc_channel_stack_builder* builder, +static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_filter* filter = static_cast(arg); @@ -113,7 +118,8 @@ static bool add_replacement_filter(grpc_channel_stack_builder* builder, builder, filter, set_arg_once_fn, &g_replacement_fn_called); } -static bool add_original_filter(grpc_channel_stack_builder* builder, +static bool add_original_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter*)arg, set_arg_once_fn, diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index ef43facd6e..988ea9bac9 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -27,7 +27,8 @@ #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->channel_args->num_args == 1); GPR_ASSERT(args->channel_args->args[0].type == GRPC_ARG_INTEGER); @@ -39,37 +40,42 @@ static grpc_error* channel_init_func(grpc_channel_element* elem, return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_call_element* elem, +static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { ++*(int*)(elem->channel_data); *(int*)(elem->call_data) = 0; return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} -static void call_destroy_func(grpc_call_element* elem, +static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { ++*(int*)(elem->channel_data); } -static void call_func(grpc_call_element* elem, +static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op_batch* op) { ++*(int*)(elem->call_data); } -static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { +static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op) { ++*(int*)(elem->channel_data); } -static void free_channel(void* arg, grpc_error* error) { - grpc_channel_stack_destroy(static_cast(arg)); +static void free_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_channel_stack_destroy(exec_ctx, static_cast(arg)); gpr_free(arg); } -static void free_call(void* arg, grpc_error* error) { - grpc_call_stack_destroy(static_cast(arg), nullptr, nullptr); +static void free_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + grpc_call_stack_destroy(exec_ctx, static_cast(arg), nullptr, + nullptr); gpr_free(arg); } @@ -95,7 +101,7 @@ static void test_create_channel_stack(void) { grpc_channel_args chan_args; int* channel_data; int* call_data; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; @@ -107,8 +113,8 @@ static void test_create_channel_stack(void) { channel_stack = static_cast( gpr_malloc(grpc_channel_stack_size(&filters, 1))); - grpc_channel_stack_init(1, free_channel, channel_stack, &filters, 1, - &chan_args, nullptr, "test", channel_stack); + grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, + 1, &chan_args, nullptr, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_data = (int*)channel_elem->channel_data; @@ -126,8 +132,8 @@ static void test_create_channel_stack(void) { nullptr, /* arena */ nullptr /* call_combiner */ }; - grpc_error* error = - grpc_call_stack_init(channel_stack, 1, free_call, call_stack, &args); + grpc_error* error = grpc_call_stack_init(&exec_ctx, channel_stack, 1, + free_call, call_stack, &args); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); @@ -137,13 +143,14 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); - GRPC_CALL_STACK_UNREF(call_stack, "done"); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CALL_STACK_UNREF(&exec_ctx, call_stack, "done"); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(*channel_data == 2); - GRPC_CHANNEL_STACK_UNREF(channel_stack, "done"); + GRPC_CHANNEL_STACK_UNREF(&exec_ctx, channel_stack, "done"); - grpc_slice_unref_internal(path); + grpc_slice_unref_internal(&exec_ctx, path); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index 3495f603e4..e0cffa39a8 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -125,10 +125,12 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_transport(builder, &fake_transport); } { - grpc_core::ExecCtx exec_ctx; - grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_stack_builder_set_channel_arguments(&exec_ctx, builder, + channel_args); GPR_ASSERT(grpc_channel_init_create_stack( - builder, (grpc_channel_stack_type)channel_stack_type)); + &exec_ctx, builder, (grpc_channel_stack_type)channel_stack_type)); + grpc_exec_ctx_finish(&exec_ctx); } // build up our expectation list @@ -210,9 +212,10 @@ static int check_stack(const char* file, int line, const char* transport_name, gpr_free(expect); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_stack_builder_destroy(builder); - grpc_channel_args_destroy(channel_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_stack_builder_destroy(&exec_ctx, builder); + grpc_channel_args_destroy(&exec_ctx, channel_args); + grpc_exec_ctx_finish(&exec_ctx); } return result; diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 847ea0066b..5f8d3b84cc 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,8 +651,9 @@ static void test_get_channel_info() { grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); @@ -958,7 +959,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; @@ -968,9 +969,9 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_tracer_set_enabled("round_robin", 1); - GPR_ASSERT(grpc_lb_policy_create("this-lb-policy-does-not-exist", nullptr) == - nullptr); - GPR_ASSERT(grpc_lb_policy_create(nullptr, nullptr) == nullptr); + GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist", + nullptr) == nullptr); + GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, nullptr, nullptr) == nullptr); spec = test_spec_create(NUM_ITERS, NUM_SERVERS); /* everything is fine, all servers stay up the whole time and life's peachy @@ -1024,6 +1025,7 @@ int main(int argc, char** argv) { test_ping(); test_get_channel_info(); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 6d56961d84..94f76da920 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -24,7 +24,6 @@ #include #endif -#include #include #include "src/core/lib/iomgr/exec_ctx.h" @@ -34,8 +33,8 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); @@ -44,6 +43,7 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } #else /* GRPC_HAVE_UNIX_SOCKET */ @@ -54,8 +54,8 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) {} static void test_grpc_parse_ipv4(const char* uri_text, const char* host, unsigned short port) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -68,12 +68,13 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, GPR_ASSERT(ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } static void test_grpc_parse_ipv6(const char* uri_text, const char* host, unsigned short port, uint32_t scope_id) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; @@ -87,16 +88,14 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_grpc_parse_unix("unix:/path/name", "/path/name"); test_grpc_parse_ipv4("ipv4:192.0.2.1:12345", "192.0.2.1", 12345); test_grpc_parse_ipv6("ipv6:[2001:db8::1]:12345", "2001:db8::1", 12345, 0); test_grpc_parse_ipv6("ipv6:[2001:db8::1%252]:12345", "2001:db8::1", 12345, 2); - - grpc_shutdown(); } diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index 18a795fbcb..dcf315eba5 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,7 +35,8 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(const char* addr, const char* default_port, +static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -54,13 +55,13 @@ static void my_resolve_address(const char* addr, const char* default_port, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - const char* dns_server, const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** lb_addrs, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", addr)); @@ -75,26 +76,27 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); return nullptr; } -static grpc_resolver* create_resolver(const char* name) { +static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, + const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(name, 0); + grpc_uri* uri = grpc_uri_parse(exec_ctx, name, 0); GPR_ASSERT(uri); grpc_resolver_args args; memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(void* ev, grpc_error* error) { +static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -105,8 +107,9 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - grpc_core::ExecCtx exec_ctx; - grpc_timer_check(nullptr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_check(&exec_ctx, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } return false; } @@ -117,14 +120,16 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(void* arg, +static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error_unused) { next_args* a = static_cast(arg); - grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast(gpr_malloc(sizeof(*a))); @@ -132,6 +137,7 @@ static void call_resolver_next_after_locking(grpc_resolver* resolver, a->result = result; a->on_complete = on_complete; GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a, grpc_combiner_scheduler(resolver->combiner)), GRPC_ERROR_NONE); @@ -147,31 +153,30 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - { - grpc_core::ExecCtx exec_ctx; - grpc_resolver* resolver = create_resolver("dns:test"); - gpr_event ev1; - gpr_event_init(&ev1); - call_resolver_next_after_locking( - resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(wait_loop(5, &ev1)); - GPR_ASSERT(result == nullptr); - - gpr_event ev2; - gpr_event_init(&ev2); - call_resolver_next_after_locking( - resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(wait_loop(30, &ev2)); - GPR_ASSERT(result != nullptr); - - grpc_channel_args_destroy(result); - GRPC_RESOLVER_UNREF(resolver, "test"); - GRPC_COMBINER_UNREF(g_combiner, "test"); - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resolver* resolver = create_resolver(&exec_ctx, "dns:test"); + gpr_event ev1; + gpr_event_init(&ev1); + call_resolver_next_after_locking( + &exec_ctx, resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(5, &ev1)); + GPR_ASSERT(result == nullptr); + + gpr_event ev2; + gpr_event_init(&ev2); + call_resolver_next_after_locking( + &exec_ctx, resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(30, &ev2)); + GPR_ASSERT(result != nullptr); + + grpc_channel_args_destroy(&exec_ctx, result); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_mu_destroy(&g_mu); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 80667908ef..4c040caeb9 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,8 +28,8 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -38,15 +38,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver != nullptr); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -55,9 +56,10 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -80,8 +82,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index d85cbb1d03..d5538e9621 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -33,7 +33,7 @@ #include "test/core/util/test_config.h" static grpc_resolver* build_fake_resolver( - grpc_combiner* combiner, + grpc_exec_ctx* exec_ctx, grpc_combiner* combiner, grpc_fake_resolver_response_generator* response_generator) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("fake"); grpc_arg generator_arg = @@ -44,7 +44,7 @@ static grpc_resolver* build_fake_resolver( args.args = &channel_args; args.combiner = combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); grpc_resolver_factory_unref(factory); return resolver; } @@ -55,7 +55,7 @@ typedef struct on_resolution_arg { gpr_event ev; } on_resolution_arg; -void on_resolution_cb(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { on_resolution_arg* res = static_cast(arg); // We only check the addresses channel arg because that's the only one // explicitly set by the test via @@ -66,23 +66,24 @@ void on_resolution_cb(void* arg, grpc_error* error) { grpc_lb_addresses_find_channel_arg(res->expected_resolver_result); GPR_ASSERT( grpc_lb_addresses_cmp(actual_lb_addresses, expected_lb_addresses) == 0); - grpc_channel_args_destroy(res->resolver_result); - grpc_channel_args_destroy(res->expected_resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->expected_resolver_result); gpr_event_set(&res->ev, (void*)1); } static void test_fake_resolver() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = grpc_fake_resolver_response_generator_create(); - grpc_resolver* resolver = build_fake_resolver(combiner, response_generator); + grpc_resolver* resolver = + build_fake_resolver(&exec_ctx, combiner, response_generator); GPR_ASSERT(resolver != nullptr); // Setup expectations. - grpc_uri* uris[] = {grpc_uri_parse("ipv4:10.2.1.1:1234", true), - grpc_uri_parse("ipv4:127.0.0.1:4321", true)}; + grpc_uri* uris[] = {grpc_uri_parse(&exec_ctx, "ipv4:10.2.1.1:1234", true), + grpc_uri_parse(&exec_ctx, "ipv4:127.0.0.1:4321", true)}; const char* balancer_names[] = {"name1", "name2"}; const bool is_balancer[] = {true, false}; grpc_lb_addresses* addresses = grpc_lb_addresses_create(3, nullptr); @@ -95,7 +96,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* results = grpc_channel_args_copy_and_add(nullptr, &addresses_arg, 1); - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(&exec_ctx, addresses); on_resolution_arg on_res_arg; memset(&on_res_arg, 0, sizeof(on_res_arg)); on_res_arg.expected_resolver_result = results; @@ -105,16 +106,17 @@ static void test_fake_resolver() { // Set resolver results and trigger first resolution. on_resolution_cb // performs the checks. - grpc_fake_resolver_response_generator_set_response(response_generator, - results); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, results); + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Setup update. - grpc_uri* uris_update[] = {grpc_uri_parse("ipv4:192.168.1.0:31416", true)}; + grpc_uri* uris_update[] = { + grpc_uri_parse(&exec_ctx, "ipv4:192.168.1.0:31416", true)}; const char* balancer_names_update[] = {"name3"}; const bool is_balancer_update[] = {false}; grpc_lb_addresses* addresses_update = grpc_lb_addresses_create(1, nullptr); @@ -129,7 +131,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses_update); grpc_channel_args* results_update = grpc_channel_args_copy_and_add(nullptr, &addresses_update_arg, 1); - grpc_lb_addresses_destroy(addresses_update); + grpc_lb_addresses_destroy(&exec_ctx, addresses_update); // Setup expectations for the update. on_resolution_arg on_res_arg_update; @@ -140,27 +142,27 @@ static void test_fake_resolver() { grpc_combiner_scheduler(combiner)); // Set updated resolver results and trigger a second resolution. - grpc_fake_resolver_response_generator_set_response(response_generator, - results_update); - grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, - on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, results_update); + grpc_resolver_next_locked(&exec_ctx, resolver, + &on_res_arg_update.resolver_result, on_resolution); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Requesting a new resolution without re-senting the response shouldn't // trigger the resolution callback. memset(&on_res_arg, 0, sizeof(on_res_arg)); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); - GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); - GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "test_fake_resolver"); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_fake_resolver"); + grpc_exec_ctx_finish(&exec_ctx); grpc_fake_resolver_response_generator_unref(response_generator); } diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index 4d16a77924..dfa2d12b5e 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -35,14 +35,14 @@ typedef struct on_resolution_arg { grpc_channel_args* resolver_result; } on_resolution_arg; -void on_resolution_cb(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { on_resolution_arg* res = static_cast(arg); - grpc_channel_args_destroy(res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -51,7 +51,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver != nullptr); on_resolution_arg on_res_arg; @@ -60,16 +60,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_closure* on_resolution = GRPC_CLOSURE_CREATE( on_resolution_cb, &on_res_arg, grpc_schedule_on_exec_ctx); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); - + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -78,9 +78,10 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -111,8 +112,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index ee38453166..ba31793ff3 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include "src/core/ext/filters/client_channel/uri_parser.h" @@ -34,18 +33,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { memcpy(s, data, size); s[size] = 0; - grpc_init(); - - { - grpc_core::ExecCtx exec_ctx; - grpc_uri* x; - if ((x = grpc_uri_parse(s, 1))) { - grpc_uri_destroy(x); - } - - gpr_free(s); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* x; + if ((x = grpc_uri_parse(&exec_ctx, s, 1))) { + grpc_uri_destroy(x); } - - grpc_shutdown(); + grpc_exec_ctx_finish(&exec_ctx); + gpr_free(s); return 0; } diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 254bfddfb3..30183f9f57 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -20,7 +20,6 @@ #include -#include #include #include "src/core/lib/iomgr/exec_ctx.h" @@ -29,28 +28,29 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); GPR_ASSERT(0 == strcmp(authority, uri->authority)); GPR_ASSERT(0 == strcmp(path, uri->path)); GPR_ASSERT(0 == strcmp(query, uri->query)); GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } static void test_fails(const char* uri_text) { - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(nullptr == grpc_uri_parse(uri_text, 0)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(nullptr == grpc_uri_parse(&exec_ctx, uri_text, 0)); + grpc_exec_ctx_finish(&exec_ctx); } static void test_query_parts() { { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -77,14 +77,14 @@ static void test_query_parts() { GPR_ASSERT(nullptr == grpc_uri_get_query_arg(uri, "")); GPR_ASSERT(0 == strcmp("frag", uri->fragment)); - + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } { /* test the current behavior of multiple query part values */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -96,13 +96,14 @@ static void test_query_parts() { GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } { /* empty query */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://foo/path"; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -113,14 +114,13 @@ static void test_query_parts() { GPR_ASSERT(nullptr == uri->query_parts); GPR_ASSERT(nullptr == uri->query_parts_values); GPR_ASSERT(0 == strcmp("", uri->fragment)); - + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", @@ -148,6 +148,5 @@ int main(int argc, char** argv) { test_fails("http://foo?bar#lol#"); test_query_parts(); - grpc_shutdown(); return 0; } diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index 9e811e9af1..2f1d8bc8eb 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -39,7 +39,7 @@ static void test_algorithm_mesh(void) { grpc_compression_algorithm parsed; grpc_slice mdstr; grpc_mdelem mdelem; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); GPR_ASSERT(grpc_compression_algorithm_parse( @@ -51,8 +51,9 @@ static void test_algorithm_mesh(void) { mdelem = grpc_compression_encoding_mdelem(parsed); GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); - grpc_slice_unref_internal(mdstr); - GRPC_MDELEM_UNREF(mdelem); + grpc_slice_unref_internal(&exec_ctx, mdstr); + GRPC_MDELEM_UNREF(&exec_ctx, mdelem); + grpc_exec_ctx_finish(&exec_ctx); } /* test failure */ @@ -61,7 +62,7 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); @@ -82,7 +83,8 @@ static void test_algorithm_failure(void) { grpc_compression_algorithm_slice(static_cast( static_cast(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)), grpc_empty_slice())); - grpc_slice_unref_internal(mdstr); + grpc_slice_unref_internal(&exec_ctx, mdstr); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 6ca07b70c4..676415ba9d 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -70,8 +70,10 @@ static void assert_passthrough(grpc_slice value, grpc_split_slices_to_buffer(uncompressed_split_mode, &value, 1, &input); { - grpc_core::ExecCtx exec_ctx; - was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + was_compressed = + grpc_msg_compress(&exec_ctx, algorithm, &input, &compressed_raw); + grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT(input.count > 0); @@ -90,9 +92,11 @@ static void assert_passthrough(grpc_slice value, grpc_split_slice_buffer(compressed_split_mode, &compressed_raw, &compressed); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_msg_decompress( - was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); + &exec_ctx, was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, + &output)); + grpc_exec_ctx_finish(&exec_ctx); } final = grpc_slice_merge(output.slices, output.count); @@ -152,11 +156,11 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == - grpc_msg_compress(static_cast(i), - &input, &output)); - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(0 == grpc_msg_compress( + &exec_ctx, static_cast(i), + &input, &output)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == output.count); } @@ -176,9 +180,9 @@ static void test_bad_decompression_data_crc(void) { grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* compress it */ - grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); + grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ GPR_ASSERT(corrupted.count > 1); GPR_ASSERT(GRPC_SLICE_LENGTH(corrupted.slices[1]) > 8); @@ -186,7 +190,9 @@ static void test_bad_decompression_data_crc(void) { memcpy(GRPC_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4); /* try (and fail) to decompress the corrupted compresed buffer */ - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_GZIP, &corrupted, + &output)); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&corrupted); @@ -205,8 +211,10 @@ static void test_bad_decompression_data_trailing_garbage(void) { "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, + &output)); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -222,8 +230,10 @@ static void test_bad_decompression_data_stream(void) { grpc_slice_from_copied_buffer("\x78\xda\xff\xff", 4)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, + &output)); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -239,15 +249,17 @@ static void test_bad_compression_algorithm(void) { grpc_slice_buffer_add( &input, grpc_slice_from_copied_string("Never gonna give you up")); - grpc_core::ExecCtx exec_ctx; - was_compressed = - grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + was_compressed = grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, + &input, &output); GPR_ASSERT(0 == was_compressed); - was_compressed = grpc_msg_compress(static_cast( + was_compressed = grpc_msg_compress(&exec_ctx, + static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_compressed); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -263,16 +275,18 @@ static void test_bad_decompression_algorithm(void) { grpc_slice_buffer_add(&input, grpc_slice_from_copied_string( "I'm not really compressed but it doesn't matter")); - grpc_core::ExecCtx exec_ctx; - was_decompressed = - grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + was_decompressed = grpc_msg_decompress( + &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); was_decompressed = - grpc_msg_decompress(static_cast( + grpc_msg_decompress(&exec_ctx, + static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_decompressed); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index e60e54b2fd..5fae61f8f6 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -49,8 +49,9 @@ TEST(StatsTest, IncCounters) { for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { Snapshot snapshot; - grpc_core::ExecCtx exec_ctx; - GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_STATS_INC_COUNTER(&exec_ctx, (grpc_stats_counters)i); + grpc_exec_ctx_finish(&exec_ctx); EXPECT_EQ(snapshot.delta().counters[i], 1); } @@ -59,8 +60,9 @@ TEST(StatsTest, IncCounters) { TEST(StatsTest, IncSpecificCounter) { Snapshot snapshot; - grpc_core::ExecCtx exec_ctx; - GRPC_STATS_INC_SYSCALL_POLL(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_STATS_INC_SYSCALL_POLL(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); } @@ -92,8 +94,9 @@ TEST_P(HistogramTest, IncHistogram) { for (auto j : test_values) { Snapshot snapshot; - grpc_core::ExecCtx exec_ctx; - grpc_stats_inc_histogram[kHistogram](j); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); + grpc_exec_ctx_finish(&exec_ctx); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 93809ac37a..0fdb637ead 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -91,22 +91,22 @@ static grpc_closure on_write; static void* tag(intptr_t t) { return (void*)t; } -static void done_write(void* arg, grpc_error* error) { +static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); gpr_atm_rel_store(&state.done_atm, 1); } -static void handle_write() { +static void handle_write(grpc_exec_ctx* exec_ctx) { grpc_slice slice = grpc_slice_from_copied_buffer( state.response_payload, state.response_payload_length); grpc_slice_buffer_reset_and_unref(&state.outgoing_buffer); grpc_slice_buffer_add(&state.outgoing_buffer, slice); - grpc_endpoint_write(state.tcp, &state.outgoing_buffer, &on_write); + grpc_endpoint_write(exec_ctx, state.tcp, &state.outgoing_buffer, &on_write); } -static void handle_read(void* arg, grpc_error* error) { +static void handle_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); state.incoming_data_length += state.temp_incoming_buffer.length; @@ -123,13 +123,14 @@ static void handle_read(void* arg, grpc_error* error) { SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD); if (state.incoming_data_length >= SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD) { - handle_write(); + handle_write(exec_ctx); } else { - grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read); + grpc_endpoint_read(exec_ctx, state.tcp, &state.temp_incoming_buffer, + &on_read); } } -static void on_connect(void* arg, grpc_endpoint* tcp, +static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -140,8 +141,8 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_slice_buffer_init(&state.outgoing_buffer); state.tcp = tcp; state.incoming_data_length = 0; - grpc_endpoint_add_to_pollset(tcp, server->pollset); - grpc_endpoint_read(tcp, &state.temp_incoming_buffer, &on_read); + grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); + grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); } static gpr_timespec n_sec_deadline(int seconds) { @@ -216,10 +217,10 @@ static void start_rpc(int target_port, grpc_status_code expected_status, cq_verifier_destroy(cqv); } -static void cleanup_rpc() { +static void cleanup_rpc(grpc_exec_ctx* exec_ctx) { grpc_event ev; - grpc_slice_buffer_destroy_internal(&state.temp_incoming_buffer); - grpc_slice_buffer_destroy_internal(&state.outgoing_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &state.temp_incoming_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &state.outgoing_buffer); grpc_call_unref(state.call); grpc_completion_queue_shutdown(state.cq); do { @@ -269,7 +270,7 @@ static void run_test(const char* response_payload, grpc_status_code expected_status, const char* expected_detail) { test_tcp_server test_server; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_event ev; grpc_init(); @@ -286,11 +287,11 @@ static void run_test(const char* response_payload, gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); /* clean up */ - grpc_endpoint_shutdown(state.tcp, + grpc_endpoint_shutdown(&exec_ctx, state.tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(state.tcp); - cleanup_rpc(); - grpc_core::ExecCtx::Get()->Flush(); + grpc_endpoint_destroy(&exec_ctx, state.tcp); + cleanup_rpc(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); test_tcp_server_destroy(&test_server); grpc_shutdown(); @@ -298,7 +299,6 @@ static void run_test(const char* response_payload, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); /* status defined in hpack static table */ run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_CANCELLED, @@ -337,6 +337,5 @@ int main(int argc, char** argv) { run_test(HTTP1_RESP, sizeof(HTTP1_RESP) - 1, GRPC_STATUS_UNAVAILABLE, HTTP1_DETAIL_MSG); - grpc_shutdown(); return 0; } diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index ca6d17e7c8..f3f2dda91d 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -133,8 +133,9 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_metadata_array_destroy(&trailing_metadata_recv); { - grpc_core::ExecCtx exec_ctx; - if (args != nullptr) grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + if (args != nullptr) grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index 75c80aa1ff..fed8ead5c8 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -75,8 +75,9 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -91,8 +92,9 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index 5b9181586c..ea8990fd0a 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -66,8 +66,9 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->client_args_compression != nullptr) { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(ffd->client_args_compression); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); + grpc_exec_ctx_finish(&exec_ctx); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( client_args, GRPC_COMPRESS_GZIP); @@ -80,8 +81,9 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->server_args_compression != nullptr) { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(ffd->server_args_compression); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); + grpc_exec_ctx_finish(&exec_ctx); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( server_args, GRPC_COMPRESS_GZIP); @@ -95,13 +97,14 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, } void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); - grpc_channel_args_destroy(ffd->client_args_compression); - grpc_channel_args_destroy(ffd->server_args_compression); + grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); + grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); gpr_free(ffd->localaddr); gpr_free(ffd); + grpc_exec_ctx_finish(&exec_ctx); } /* All test configurations */ diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 9157ab04d0..97f4b71bf0 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -68,18 +68,20 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->client); f->client = grpc_insecure_channel_create_from_fd( "fixture_client", sfd->fd_pair[0], client_args); GPR_ASSERT(f->client); + + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); @@ -88,6 +90,8 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_server_start(f->server); grpc_server_add_insecure_channel_from_fd(f->server, nullptr, sfd->fd_pair[1]); + + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index 237841d185..71a497d796 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -72,7 +72,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { int i; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; fullstack_fixture_data* ffd = static_cast(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; @@ -90,7 +90,8 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); - grpc_channel_args_destroy(server_args_new); + grpc_channel_args_destroy(&exec_ctx, server_args_new); + grpc_exec_ctx_finish(&exec_ctx); } void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index fda5f4b052..7486b6af78 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -78,8 +78,9 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 5fed4434de..1642cb0db9 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -143,11 +143,11 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr); grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - "authorization", oauth2_md, true /* is_async */); + &exec_ctx, "authorization", oauth2_md, true /* is_async */); grpc_channel_credentials* ssl_oauth2_creds = grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, nullptr); @@ -158,9 +158,10 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds); - grpc_channel_args_destroy(new_client_args); + grpc_channel_args_destroy(&exec_ctx, new_client_args); grpc_channel_credentials_release(ssl_creds); grpc_call_credentials_release(oauth2_creds); + grpc_exec_ctx_finish(&exec_ctx); } static int fail_server_auth_check(grpc_channel_args* server_args) { diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 9807e929af..9319c401dc 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -50,11 +50,12 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -62,11 +63,13 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(void* ts, grpc_transport* transport) { +static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, + grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = + grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -87,30 +90,34 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, true); - client_setup_transport(&cs, transport); + transport = + grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); + client_setup_transport(&exec_ctx, &cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, false); + transport = + grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { @@ -126,6 +133,7 @@ static grpc_end2end_test_config configs[] = { int main(int argc, char** argv) { size_t i; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* force tracing on, with a value to force many code paths in trace.c to be taken */ @@ -139,6 +147,7 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); grpc_init(); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index b68279fd71..03566aada2 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -44,11 +44,12 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -56,11 +57,13 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(void* ts, grpc_transport* transport) { +static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, + grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = + grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -81,30 +84,34 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, true); - client_setup_transport(&cs, transport); + transport = + grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); + client_setup_transport(&exec_ctx, &cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, false); + transport = + grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 350be138ca..9adba00204 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -44,11 +44,12 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -56,11 +57,13 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(void* ts, grpc_transport* transport) { +static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, + grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = + grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -92,30 +95,34 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, true); - client_setup_transport(&cs, transport); + transport = + grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); + client_setup_transport(&exec_ctx, &cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, false); + transport = + grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index 9a0680c40e..3d7e2e327e 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -110,8 +110,9 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index 5ddbdefc8c..f8d5a699e4 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -66,8 +66,9 @@ static grpc_channel* create_proxy_client(const char* target, grpc_secure_channel_create(ssl_creds, target, new_client_args, nullptr); grpc_channel_credentials_release(ssl_creds); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_exec_ctx_finish(&exec_ctx); } return channel; } @@ -147,8 +148,9 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 137f7c9fa3..3904887026 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -116,21 +116,24 @@ static void proxy_connection_ref(proxy_connection* conn, const char* reason) { } // Helper function to destroy the proxy connection. -static void proxy_connection_unref(proxy_connection* conn, const char* reason) { +static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, + proxy_connection* conn, const char* reason) { if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); - grpc_endpoint_destroy(conn->client_endpoint); + grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); if (conn->server_endpoint != nullptr) { - grpc_endpoint_destroy(conn->server_endpoint); + grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); } - grpc_pollset_set_destroy(conn->pollset_set); - grpc_slice_buffer_destroy_internal(&conn->client_read_buffer); - grpc_slice_buffer_destroy_internal(&conn->client_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(&conn->client_write_buffer); - grpc_slice_buffer_destroy_internal(&conn->server_read_buffer); - grpc_slice_buffer_destroy_internal(&conn->server_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(&conn->server_write_buffer); + grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); + grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, + &conn->client_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_write_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_read_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, + &conn->server_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); gpr_unref(&conn->proxy->users); @@ -147,7 +150,8 @@ enum failure_type { }; // Helper function to shut down the proxy connection. -static void proxy_connection_failed(proxy_connection* conn, +static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, + proxy_connection* conn, failure_type failure, const char* prefix, grpc_error* error) { gpr_log(GPR_INFO, "%s: %s", prefix, grpc_error_string(error)); @@ -171,25 +175,28 @@ static void proxy_connection_failed(proxy_connection* conn, } // If we decided to shut down either one and have not yet done so, do so. if (shutdown_client && !conn->client_shutdown) { - grpc_endpoint_shutdown(conn->client_endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint, + GRPC_ERROR_REF(error)); conn->client_shutdown = true; } if (shutdown_server && !conn->server_shutdown && (conn->server_endpoint != nullptr)) { - grpc_endpoint_shutdown(conn->server_endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, + GRPC_ERROR_REF(error)); conn->server_shutdown = true; } // Unref the connection. - proxy_connection_unref(conn, "conn_failed"); + proxy_connection_unref(exec_ctx, conn, "conn_failed"); GRPC_ERROR_UNREF(error); } // Callback for writing proxy data to the client. -static void on_client_write_done(void* arg, grpc_error* error) { +static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, CLIENT_WRITE_FAILED, + proxy_connection_failed(exec_ctx, conn, CLIENT_WRITE_FAILED, "HTTP proxy client write", GRPC_ERROR_REF(error)); return; } @@ -201,20 +208,22 @@ static void on_client_write_done(void* arg, grpc_error* error) { grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer, &conn->client_write_buffer); conn->client_is_writing = true; - grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, + grpc_endpoint_write(exec_ctx, conn->client_endpoint, + &conn->client_write_buffer, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(conn, "write_done"); + proxy_connection_unref(exec_ctx, conn, "write_done"); } } // Callback for writing proxy data to the backend server. -static void on_server_write_done(void* arg, grpc_error* error) { +static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->server_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SERVER_WRITE_FAILED, + proxy_connection_failed(exec_ctx, conn, SERVER_WRITE_FAILED, "HTTP proxy server write", GRPC_ERROR_REF(error)); return; } @@ -226,21 +235,23 @@ static void on_server_write_done(void* arg, grpc_error* error) { grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer, &conn->server_write_buffer); conn->server_is_writing = true; - grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, + grpc_endpoint_write(exec_ctx, conn->server_endpoint, + &conn->server_write_buffer, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(conn, "server_write"); + proxy_connection_unref(exec_ctx, conn, "server_write"); } } // Callback for reading data from the client, which will be proxied to // the backend server. -static void on_client_read_done(void* arg, grpc_error* error) { +static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, CLIENT_READ_FAILED, "HTTP proxy client read", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, CLIENT_READ_FAILED, + "HTTP proxy client read", GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., server_write_buffer is @@ -257,21 +268,23 @@ static void on_client_read_done(void* arg, grpc_error* error) { &conn->server_write_buffer); proxy_connection_ref(conn, "client_read"); conn->server_is_writing = true; - grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, + grpc_endpoint_write(exec_ctx, conn->server_endpoint, + &conn->server_write_buffer, &conn->on_server_write_done); } // Read more data. - grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); } // Callback for reading data from the backend server, which will be // proxied to the client. -static void on_server_read_done(void* arg, grpc_error* error) { +static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SERVER_READ_FAILED, "HTTP proxy server read", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SERVER_READ_FAILED, + "HTTP proxy server read", GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., client_write_buffer is @@ -288,21 +301,23 @@ static void on_server_read_done(void* arg, grpc_error* error) { &conn->client_write_buffer); proxy_connection_ref(conn, "server_read"); conn->client_is_writing = true; - grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, + grpc_endpoint_write(exec_ctx, conn->client_endpoint, + &conn->client_write_buffer, &conn->on_client_write_done); } // Read more data. - grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to write the HTTP response for the CONNECT request. -static void on_write_response_done(void* arg, grpc_error* error) { +static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy write response", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy write response", GRPC_ERROR_REF(error)); return; } // Clear write buffer. @@ -312,16 +327,17 @@ static void on_write_response_done(void* arg, grpc_error* error) { // for the other one. proxy_connection_ref(conn, "client_read"); proxy_connection_ref(conn, "server_read"); - proxy_connection_unref(conn, "write_response"); - grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + proxy_connection_unref(exec_ctx, conn, "write_response"); + grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); - grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to connect to the backend server specified by the HTTP // CONNECT request. -static void on_server_connect_done(void* arg, grpc_error* error) { +static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { // TODO(roth): Technically, in this case, we should handle the error @@ -329,8 +345,8 @@ static void on_server_connect_done(void* arg, grpc_error* error) { // connection failed. However, for the purposes of this test code, // it's fine to pretend this is a client-side error, which will // cause the client connection to be dropped. - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy server connect", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy server connect", GRPC_ERROR_REF(error)); return; } // We've established a connection, so send back a 200 response code to @@ -340,7 +356,8 @@ static void on_server_connect_done(void* arg, grpc_error* error) { grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n"); grpc_slice_buffer_add(&conn->client_write_buffer, slice); conn->client_is_writing = true; - grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, + grpc_endpoint_write(exec_ctx, conn->client_endpoint, + &conn->client_write_buffer, &conn->on_write_response_done); } @@ -349,7 +366,8 @@ static void on_server_connect_done(void* arg, grpc_error* error) { * Basic * Returns true if it matches, false otherwise */ -static bool proxy_auth_header_matches(char* proxy_auth_header_val, +static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, + char* proxy_auth_header_val, char* expected_cred) { GPR_ASSERT(proxy_auth_header_val != nullptr); GPR_ASSERT(expected_cred != nullptr); @@ -357,10 +375,11 @@ static bool proxy_auth_header_matches(char* proxy_auth_header_val, return false; } proxy_auth_header_val += 6; - grpc_slice decoded_slice = grpc_base64_decode(proxy_auth_header_val, 0); + grpc_slice decoded_slice = + grpc_base64_decode(exec_ctx, proxy_auth_header_val, 0); const bool header_matches = grpc_slice_str_cmp(decoded_slice, expected_cred) == 0; - grpc_slice_unref_internal(decoded_slice); + grpc_slice_unref_internal(exec_ctx, decoded_slice); return header_matches; } @@ -370,13 +389,14 @@ static bool proxy_auth_header_matches(char* proxy_auth_header_val, // the client indicating that the request failed. However, for the purposes // of this test code, it's fine to pretend this is a client-side error, // which will cause the client connection to be dropped. -static void on_read_request_done(void* arg, grpc_error* error) { +static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy read request", GRPC_ERROR_REF(error)); return; } // Read request and feed it to the parser. @@ -385,7 +405,8 @@ static void on_read_request_done(void* arg, grpc_error* error) { error = grpc_http_parser_parse( &conn->http_parser, conn->client_read_buffer.slices[i], nullptr); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy request parse", + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy request parse", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; @@ -395,8 +416,8 @@ static void on_read_request_done(void* arg, grpc_error* error) { grpc_slice_buffer_reset_and_unref(&conn->client_read_buffer); // If we're not done reading the request, read more data. if (conn->http_parser.state != GRPC_HTTP_BODY) { - grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, - &conn->on_read_request_done); + grpc_endpoint_read(exec_ctx, conn->client_endpoint, + &conn->client_read_buffer, &conn->on_read_request_done); return; } // Make sure we got a CONNECT request. @@ -406,8 +427,8 @@ static void on_read_request_done(void* arg, grpc_error* error) { conn->http_request.method); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy read request", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -419,15 +440,16 @@ static void on_read_request_done(void* arg, grpc_error* error) { for (size_t i = 0; i < conn->http_request.hdr_count; i++) { if (strcmp(conn->http_request.hdrs[i].key, "Proxy-Authorization") == 0) { client_authenticated = proxy_auth_header_matches( - conn->http_request.hdrs[i].value, proxy_auth_arg->value.string); + exec_ctx, conn->http_request.hdrs[i].value, + proxy_auth_arg->value.string); break; } } if (!client_authenticated) { const char* msg = "HTTP Connect could not verify authentication"; error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(msg); - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy read request", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -437,8 +459,8 @@ static void on_read_request_done(void* arg, grpc_error* error) { error = grpc_blocking_resolve_address(conn->http_request.path, "80", &resolved_addresses); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy DNS lookup", - GRPC_ERROR_REF(error)); + proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, + "HTTP proxy DNS lookup", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -446,15 +468,15 @@ static void on_read_request_done(void* arg, grpc_error* error) { // Connect to requested address. // The connection callback inherits our reference to conn. const grpc_millis deadline = - grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; - grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, - conn->pollset_set, nullptr, + grpc_exec_ctx_now(exec_ctx) + 10 * GPR_MS_PER_SEC; + grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done, + &conn->server_endpoint, conn->pollset_set, nullptr, &resolved_addresses->addrs[0], deadline); grpc_resolved_addresses_destroy(resolved_addresses); } -static void on_accept(void* arg, grpc_endpoint* endpoint, - grpc_pollset* accepting_pollset, +static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, + grpc_endpoint* endpoint, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; @@ -465,8 +487,8 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(conn->pollset_set, proxy->pollset); - grpc_endpoint_add_to_pollset_set(endpoint, conn->pollset_set); + grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); GRPC_CLOSURE_INIT(&conn->on_read_request_done, on_read_request_done, conn, grpc_combiner_scheduler(conn->proxy->combiner)); GRPC_CLOSURE_INIT(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -491,7 +513,7 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, grpc_slice_buffer_init(&conn->server_write_buffer); grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST, &conn->http_request); - grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, &conn->on_read_request_done); } @@ -501,23 +523,24 @@ static void on_accept(void* arg, grpc_endpoint* endpoint, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; do { gpr_ref(&proxy->users); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(proxy->mu); GRPC_LOG_IF_ERROR( "grpc_pollset_work", - grpc_pollset_work(proxy->pollset, &worker, - grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); + grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, + grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } while (!gpr_unref(&proxy->users)); + grpc_exec_ctx_finish(&exec_ctx); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -529,8 +552,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name); // Create TCP server. proxy->channel_args = grpc_channel_args_copy(args); - grpc_error* error = - grpc_tcp_server_create(nullptr, proxy->channel_args, &proxy->server); + grpc_error* error = grpc_tcp_server_create( + &exec_ctx, nullptr, proxy->channel_args, &proxy->server); GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; @@ -545,8 +568,9 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start server. proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(proxy->pollset, &proxy->mu); - grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); - + grpc_tcp_server_start(&exec_ctx, proxy->server, &proxy->pollset, 1, on_accept, + proxy); + grpc_exec_ctx_finish(&exec_ctx); // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); @@ -555,25 +579,27 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( return proxy; } -static void destroy_pollset(void* arg, grpc_error* error) { +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(pollset); + grpc_pollset_destroy(exec_ctx, pollset); gpr_free(pollset); } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_thd_join(proxy->thd); - grpc_tcp_server_shutdown_listeners(proxy->server); - grpc_tcp_server_unref(proxy->server); + grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); + grpc_tcp_server_unref(&exec_ctx, proxy->server); gpr_free(proxy->proxy_name); - grpc_channel_args_destroy(proxy->channel_args); - grpc_pollset_shutdown(proxy->pollset, + grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); + grpc_pollset_shutdown(&exec_ctx, proxy->pollset, GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset, grpc_schedule_on_exec_ctx)); - GRPC_COMBINER_UNREF(proxy->combiner, "test"); + GRPC_COMBINER_UNREF(&exec_ctx, proxy->combiner, "test"); gpr_free(proxy); + grpc_exec_ctx_finish(&exec_ctx); } const char* grpc_end2end_http_proxy_get_proxy_name( diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 967a6d560f..75117218e4 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -376,7 +376,8 @@ typedef struct addr_req { grpc_lb_addresses** lb_addrs; } addr_req; -static void finish_resolve(void* arg, grpc_error* error) { +static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { addr_req* r = static_cast(arg); if (error == GRPC_ERROR_NONE && 0 == strcmp(r->addr, "server")) { @@ -394,9 +395,9 @@ static void finish_resolve(void* arg, grpc_error* error) { nullptr); *r->lb_addrs = lb_addrs; } - GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, GRPC_ERROR_NONE); } else { - GRPC_CLOSURE_SCHED(r->on_done, + GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Resolution failed", &error, 1)); } @@ -405,7 +406,8 @@ static void finish_resolve(void* arg, grpc_error* error) { gpr_free(r); } -void my_resolve_address(const char* addr, const char* default_port, +void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) { @@ -415,24 +417,22 @@ void my_resolve_address(const char* addr, const char* default_port, r->addrs = addresses; r->lb_addrs = nullptr; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), + exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } -grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, - const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_lb_addresses** lb_addrs, - bool check_grpclb, - char** service_config_json) { +grpc_ares_request* my_dns_lookup_ares( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, + char** service_config_json) { addr_req* r = static_cast(gpr_malloc(sizeof(*r))); r->addr = gpr_strdup(addr); r->on_done = on_done; r->addrs = nullptr; r->lb_addrs = lb_addrs; grpc_timer_init( - &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), + exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); return nullptr; } @@ -442,12 +442,12 @@ grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, // defined in tcp_client_posix.c extern void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, + grpc_exec_ctx* exec_ctx, 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); -static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, - gpr_timespec deadline); +static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_endpoint** ep, gpr_timespec deadline); typedef struct { grpc_timer timer; @@ -456,11 +456,11 @@ typedef struct { gpr_timespec deadline; } future_connect; -static void do_connect(void* arg, grpc_error* error) { +static void do_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { future_connect* fc = static_cast(arg); if (error != GRPC_ERROR_NONE) { *fc->ep = nullptr; - GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_REF(error)); } else if (g_server != nullptr) { grpc_endpoint* client; grpc_endpoint* server; @@ -468,23 +468,25 @@ static void do_connect(void* arg, grpc_error* error) { *fc->ep = client; grpc_transport* transport = - grpc_create_chttp2_transport(nullptr, server, false); - grpc_server_setup_transport(g_server, transport, nullptr, nullptr); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_create_chttp2_transport(exec_ctx, nullptr, server, false); + grpc_server_setup_transport(exec_ctx, g_server, transport, nullptr, + nullptr); + grpc_chttp2_transport_start_reading(exec_ctx, transport, nullptr, nullptr); - GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_NONE); } else { - sched_connect(fc->closure, fc->ep, fc->deadline); + sched_connect(exec_ctx, fc->closure, fc->ep, fc->deadline); } gpr_free(fc); } -static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, - gpr_timespec deadline) { +static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, + grpc_endpoint** ep, gpr_timespec deadline) { if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) { *ep = nullptr; - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Connect deadline exceeded")); + GRPC_CLOSURE_SCHED( + exec_ctx, closure, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connect deadline exceeded")); return; } @@ -493,16 +495,17 @@ static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, fc->ep = ep; fc->deadline = deadline; grpc_timer_init( - &fc->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), + exec_ctx, &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx)); } -static void my_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, +static void my_tcp_client_connect(grpc_exec_ctx* exec_ctx, + 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) { - sched_connect(closure, ep, + sched_connect(exec_ctx, closure, ep, grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); } @@ -748,8 +751,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_timer_manager_set_threading(false); { - grpc_core::ExecCtx exec_ctx; - grpc_executor_set_threading(false); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_executor_set_threading(&exec_ctx, false); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; @@ -842,8 +846,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_insecure_channel_create(target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } gpr_free(target_uri); gpr_free(target); @@ -869,8 +874,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_server = grpc_server_create(args, nullptr); GPR_ASSERT(g_server != nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_server_register_completion_queue(g_server, cq, nullptr); grpc_server_start(g_server); @@ -1199,8 +1205,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_secure_channel_create(creds, target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } gpr_free(target_uri); gpr_free(target); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index c17d581d8b..5871f0f43e 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -43,114 +43,112 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - grpc_executor_set_threading(false); - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("client_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(resource_quota); - - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_transport* transport = - grpc_create_chttp2_transport(nullptr, mock_endpoint, true); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - - grpc_channel* channel = grpc_channel_create( - "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_slice host = grpc_slice_from_static_string("localhost"); - grpc_call* call = grpc_channel_create_call( - channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - - grpc_metadata_array initial_metadata_recv; - grpc_metadata_array_init(&initial_metadata_recv); - grpc_byte_buffer* response_payload_recv = nullptr; - grpc_metadata_array trailing_metadata_recv; - grpc_metadata_array_init(&trailing_metadata_recv); - grpc_status_code status; - grpc_slice details = grpc_empty_slice(); - - grpc_op ops[6]; - memset(ops, 0, sizeof(ops)); - grpc_op* op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = - &initial_metadata_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &response_payload_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; - op->data.recv_status_on_client.status = &status; - op->data.recv_status_on_client.status_details = &details; - op->flags = 0; - op->reserved = nullptr; - op++; - grpc_call_error error = - grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); - int requested_calls = 1; - GPR_ASSERT(GRPC_CALL_OK == error); - - grpc_mock_endpoint_put_read( - mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); - - grpc_event ev; - while (1) { - grpc_core::ExecCtx::Get()->Flush(); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - requested_calls--; - break; - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_executor_set_threading(&exec_ctx, false); + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("client_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_transport* transport = + grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, true); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + + grpc_channel* channel = grpc_channel_create( + &exec_ctx, "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_slice host = grpc_slice_from_static_string("localhost"); + grpc_call* call = grpc_channel_create_call( + channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); + + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array_init(&initial_metadata_recv); + grpc_byte_buffer* response_payload_recv = nullptr; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_status_code status; + grpc_slice details = grpc_empty_slice(); + + grpc_op ops[6]; + memset(ops, 0, sizeof(ops)); + grpc_op* op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->flags = 0; + op->reserved = nullptr; + op++; + grpc_call_error error = + grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); + int requested_calls = 1; + GPR_ASSERT(GRPC_CALL_OK == error); + + grpc_mock_endpoint_put_read( + &exec_ctx, mock_endpoint, + grpc_slice_from_copied_buffer((const char*)data, size)); + + grpc_event ev; + while (1) { + grpc_exec_ctx_flush(&exec_ctx); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + requested_calls--; + break; } + } - done: - if (requested_calls) { - grpc_call_cancel(call, nullptr); - } - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); - } - grpc_call_unref(call); - grpc_completion_queue_destroy(cq); - grpc_metadata_array_destroy(&initial_metadata_recv); - grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); - grpc_channel_destroy(channel); - if (response_payload_recv != nullptr) { - grpc_byte_buffer_destroy(response_payload_recv); - } +done: + if (requested_calls) { + grpc_call_cancel(call, nullptr); + } + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + } + grpc_call_unref(call); + grpc_completion_queue_destroy(cq); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_slice_unref(details); + grpc_channel_destroy(channel); + if (response_payload_recv != nullptr) { + grpc_byte_buffer_destroy(response_payload_recv); } grpc_shutdown(); if (leak_check) { diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 61c55e0afd..67caf4e720 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -41,82 +41,81 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - grpc_executor_set_threading(false); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_executor_set_threading(&exec_ctx, false); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(resource_quota); - grpc_mock_endpoint_put_read( - mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_mock_endpoint_put_read( + &exec_ctx, mock_endpoint, + grpc_slice_from_copied_buffer((const char*)data, size)); - grpc_server* server = grpc_server_create(nullptr, nullptr); - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_server_register_completion_queue(server, cq, nullptr); - // TODO(ctiller): add registered methods (one for POST, one for PUT) - // void *registered_method = - // grpc_server_register_method(server, "/reg", NULL, 0); - grpc_server_start(server); - grpc_transport* transport = - grpc_create_chttp2_transport(nullptr, mock_endpoint, false); - grpc_server_setup_transport(server, transport, nullptr, nullptr); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_server* server = grpc_server_create(nullptr, nullptr); + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_server_register_completion_queue(server, cq, nullptr); + // TODO(ctiller): add registered methods (one for POST, one for PUT) + // void *registered_method = + // grpc_server_register_method(server, "/reg", NULL, 0); + grpc_server_start(server); + grpc_transport* transport = + grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, false); + grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_call* call1 = nullptr; - grpc_call_details call_details1; - grpc_metadata_array request_metadata1; - grpc_call_details_init(&call_details1); - grpc_metadata_array_init(&request_metadata1); - int requested_calls = 0; + grpc_call* call1 = nullptr; + grpc_call_details call_details1; + grpc_metadata_array request_metadata1; + grpc_call_details_init(&call_details1); + grpc_metadata_array_init(&request_metadata1); + int requested_calls = 0; - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(server, &call1, &call_details1, - &request_metadata1, cq, cq, tag(1))); - requested_calls++; + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(server, &call1, &call_details1, + &request_metadata1, cq, cq, tag(1))); + requested_calls++; - grpc_event ev; - while (1) { - grpc_core::ExecCtx::Get()->Flush(); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - switch (detag(ev.tag)) { - case 1: - requested_calls--; - // TODO(ctiller): keep reading that call! - break; - } - } + grpc_event ev; + while (1) { + grpc_exec_ctx_flush(&exec_ctx); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + switch (detag(ev.tag)) { + case 1: + requested_calls--; + // TODO(ctiller): keep reading that call! + break; + } } + } - done: - if (call1 != nullptr) grpc_call_unref(call1); - grpc_call_details_destroy(&call_details1); - grpc_metadata_array_destroy(&request_metadata1); - grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); - grpc_server_cancel_all_calls(server); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); - } - grpc_server_destroy(server); - grpc_completion_queue_destroy(cq); +done: + if (call1 != nullptr) grpc_call_unref(call1); + grpc_call_details_destroy(&call_details1); + grpc_metadata_array_destroy(&request_metadata1); + grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); + grpc_server_cancel_all_calls(server); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); } + grpc_server_destroy(server); + grpc_completion_queue_destroy(cq); grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 94cfbdda7e..2d0db967c3 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -39,15 +39,16 @@ static void* tag(intptr_t i) { return (void*)i; } static gpr_mu g_mu; static int g_resolve_port = -1; -static void (*iomgr_resolve_address)(const char* addr, const char* default_port, +static void (*iomgr_resolve_address)(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses); static grpc_ares_request* (*iomgr_dns_lookup_ares)( - const char* dns_server, const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** addresses, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, char** service_config_json); static void set_resolve_port(int port) { @@ -56,13 +57,14 @@ static void set_resolve_port(int port) { gpr_mu_unlock(&g_mu); } -static void my_resolve_address(const char* addr, const char* default_port, +static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { if (0 != strcmp(addr, "test")) { - iomgr_resolve_address(addr, default_port, interested_parties, on_done, - addrs); + iomgr_resolve_address(exec_ctx, addr, default_port, interested_parties, + on_done, addrs); return; } @@ -84,16 +86,16 @@ static void my_resolve_address(const char* addr, const char* default_port, (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - const char* dns_server, const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_lb_addresses** lb_addrs, bool check_grpclb, + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { if (0 != strcmp(addr, "test")) { - return iomgr_dns_lookup_ares(dns_server, addr, default_port, + return iomgr_dns_lookup_ares(exec_ctx, dns_server, addr, default_port, interested_parties, on_done, lb_addrs, check_grpclb, service_config_json); } @@ -115,7 +117,7 @@ static grpc_ares_request* my_dns_lookup_ares( gpr_free(sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); return nullptr; } diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index d50d1f4d81..9a98c07158 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -181,8 +181,9 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ { \ - grpc_core::ExecCtx exec_ctx; \ - grpc_channel_args_destroy(new_client_args); \ + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; \ + grpc_channel_args_destroy(&exec_ctx, new_client_args); \ + grpc_exec_ctx_finish(&exec_ctx); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index f59caf7e35..83439d71d2 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -245,8 +245,9 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index b10b93978d..ddcec67de5 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -278,8 +278,9 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index 944edc7a70..a8ea0ff2e0 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -129,9 +129,10 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; server_args = grpc_channel_args_compression_algorithm_set_state( - &server_args, algorithm_to_disable, false); + &exec_ctx, &server_args, algorithm_to_disable, false); + grpc_exec_ctx_finish(&exec_ctx); } f = begin_test(config, test_name, client_args, server_args); @@ -256,9 +257,10 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } end_test(&f); @@ -537,9 +539,10 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } end_test(&f); diff --git a/test/core/end2end/tests/filter_call_init_fails.cc b/test/core/end2end/tests/filter_call_init_fails.cc index 8f46f0bb91..6eed68a2f9 100644 --- a/test/core/end2end/tests/filter_call_init_fails.cc +++ b/test/core/end2end/tests/filter_call_init_fails.cc @@ -399,23 +399,26 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { * Test filter - always fails to initialize a call */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { return grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("access denied"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED); } -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { grpc_call_next_op, @@ -434,7 +437,8 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_server_channel_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { if (g_enable_server_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -453,7 +457,8 @@ static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder, } } -static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder, +static bool maybe_add_client_channel_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -473,7 +478,7 @@ static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder, } static bool maybe_add_client_subchannel_filter( - grpc_channel_stack_builder* builder, void* arg) { + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_subchannel_filter) { // Want to add the filter as close to the end as possible, to make // sure that all of the filters work well together. However, we diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index ec8f9dbe00..793f590686 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -197,11 +197,12 @@ typedef struct { uint8_t unused; } channel_data; -static void recv_im_ready(void* arg, grpc_error* error) { +static void recv_im_ready(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; GRPC_CLOSURE_RUN( - calld->recv_im_ready, + exec_ctx, calld->recv_im_ready, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failure that's not preventable.", &error, 1), GRPC_ERROR_INT_GRPC_STATUS, @@ -209,7 +210,8 @@ static void recv_im_ready(void* arg, grpc_error* error) { } static void start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; if (op->recv_initial_metadata) { calld->recv_im_ready = @@ -217,24 +219,27 @@ static void start_transport_stream_op_batch( op->payload->recv_initial_metadata.recv_initial_metadata_ready = GRPC_CLOSURE_CREATE(recv_im_ready, elem, grpc_schedule_on_exec_ctx); } - grpc_call_next_op(elem, op); + grpc_call_next_op(exec_ctx, elem, op); } -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_call_element* elem, +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { start_transport_stream_op_batch, @@ -253,7 +258,8 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { if (g_enable_filter) { return grpc_channel_stack_builder_prepend_filter(builder, &test_filter, nullptr, nullptr); diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index 845cbc01cf..c4d96ebfe2 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -247,12 +247,14 @@ static void test_request(grpc_end2end_test_config config) { * Test latency filter */ -static grpc_error* init_call_elem(grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void client_destroy_call_elem(grpc_call_element* elem, +static void client_destroy_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -260,7 +262,8 @@ static void client_destroy_call_elem(grpc_call_element* elem, gpr_mu_unlock(&g_mu); } -static void server_destroy_call_elem(grpc_call_element* elem, +static void server_destroy_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -268,12 +271,14 @@ static void server_destroy_call_elem(grpc_call_element* elem, gpr_mu_unlock(&g_mu); } -static grpc_error* init_channel_elem(grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} static const grpc_channel_filter test_client_filter = { grpc_call_next_op, @@ -305,7 +310,8 @@ static const grpc_channel_filter test_server_filter = { * Registration */ -static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { grpc_channel_filter* filter = (grpc_channel_filter*)arg; if (g_enable_filter) { // Want to add the filter as close to the end as possible, to make diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index e056bd547b..faabec34cb 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -300,8 +300,9 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { &trailing_lr_metadata); end_test(&f); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(lr_server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, lr_server_args); + grpc_exec_ctx_finish(&exec_ctx); } config.tear_down_data(&f); } diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index e581f1fc20..f1ac27fa7c 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -173,9 +173,12 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, f = begin_test(config, "test_max_request_message_length", client_args, server_args); { - grpc_core::ExecCtx exec_ctx; - if (client_args != nullptr) grpc_channel_args_destroy(client_args); - if (server_args != nullptr) grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + if (client_args != nullptr) + grpc_channel_args_destroy(&exec_ctx, client_args); + if (server_args != nullptr) + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } cqv = cq_verifier_create(f.cq); @@ -363,9 +366,12 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, f = begin_test(config, "test_max_response_message_length", client_args, server_args); { - grpc_core::ExecCtx exec_ctx; - if (client_args != nullptr) grpc_channel_args_destroy(client_args); - if (server_args != nullptr) grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + if (client_args != nullptr) + grpc_channel_args_destroy(&exec_ctx, client_args); + if (server_args != nullptr) + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } cqv = cq_verifier_create(f.cq); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index ec3050ad45..d73346468a 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -129,9 +129,10 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_stream_compression_algorithm( nullptr, GRPC_STREAM_COMPRESS_NONE); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; server_args = grpc_channel_args_stream_compression_algorithm_set_state( - &server_args, algorithm_to_disable, false); + &exec_ctx, &server_args, algorithm_to_disable, false); + grpc_exec_ctx_finish(&exec_ctx); } f = begin_test(config, test_name, client_args, server_args); @@ -257,9 +258,10 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } end_test(&f); @@ -545,9 +547,10 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } end_test(&f); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index b95e6528cd..924961ea55 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -277,9 +277,10 @@ static void test_invoke_request_response_with_payload( end_test(&f); config.tear_down_data(&f); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index 2a8799ee67..d3b526f04e 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -275,9 +275,10 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, end_test(&f); config.tear_down_data(&f); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index d4decce0aa..bc4d5079d8 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -142,14 +142,15 @@ static void request_with_payload_template( nullptr, default_server_channel_compression_algorithm); if (user_agent_override) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args* client_args_old = client_args; grpc_arg arg; arg.key = const_cast(GRPC_ARG_PRIMARY_USER_AGENT_STRING); arg.type = GRPC_ARG_STRING; arg.value.string = user_agent_override; client_args = grpc_channel_args_copy_and_add(client_args_old, &arg, 1); - grpc_channel_args_destroy(client_args_old); + grpc_channel_args_destroy(&exec_ctx, client_args_old); + grpc_exec_ctx_finish(&exec_ctx); } f = begin_test(config, test_name, client_args, server_args); @@ -350,9 +351,10 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(client_args); - grpc_channel_args_destroy(server_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(&exec_ctx, server_args); + grpc_exec_ctx_finish(&exec_ctx); } end_test(&f); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 599e0e16e2..2810082837 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -49,37 +49,41 @@ * to the security_handshaker). This test is meant to protect code relying on * this functionality that lives outside of this repo. */ -static void readahead_handshaker_destroy(grpc_handshaker* handshaker) { +static void readahead_handshaker_destroy(grpc_exec_ctx* ctx, + grpc_handshaker* handshaker) { gpr_free(handshaker); } -static void readahead_handshaker_shutdown(grpc_handshaker* handshaker, +static void readahead_handshaker_shutdown(grpc_exec_ctx* ctx, + grpc_handshaker* handshaker, grpc_error* error) {} static void readahead_handshaker_do_handshake( - grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, - grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - grpc_endpoint_read(args->endpoint, args->read_buffer, on_handshake_done); + grpc_exec_ctx* ctx, grpc_handshaker* handshaker, + grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, + grpc_handshaker_args* args) { + grpc_endpoint_read(ctx, args->endpoint, args->read_buffer, on_handshake_done); } const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_destroy, readahead_handshaker_shutdown, readahead_handshaker_do_handshake}; -static grpc_handshaker* readahead_handshaker_create() { +static grpc_handshaker* readahead_handshaker_create(grpc_exec_ctx* ctx) { grpc_handshaker* h = (grpc_handshaker*)gpr_zalloc(sizeof(grpc_handshaker)); grpc_handshaker_init(&readahead_handshaker_vtable, h); return h; } static void readahead_handshaker_factory_add_handshakers( - grpc_handshaker_factory* hf, const grpc_channel_args* args, - grpc_handshake_manager* handshake_mgr) { - grpc_handshake_manager_add(handshake_mgr, readahead_handshaker_create()); + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* hf, + const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshake_manager_add(handshake_mgr, + readahead_handshaker_create(exec_ctx)); } static void readahead_handshaker_factory_destroy( - grpc_handshaker_factory* handshaker_factory) {} + grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) {} static const grpc_handshaker_factory_vtable readahead_handshaker_factory_vtable = { diff --git a/test/core/http/format_request_test.cc b/test/core/http/format_request_test.cc index 353e138b2a..684738a997 100644 --- a/test/core/http/format_request_test.cc +++ b/test/core/http/format_request_test.cc @@ -139,13 +139,11 @@ static void test_format_post_request_content_type_override(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_format_get_request(); test_format_post_request(); test_format_post_request_no_body(); test_format_post_request_content_type_override(); - grpc_shutdown(); return 0; } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 259e3aa463..81e9374819 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(void* arg, grpc_error* error) { +static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { const char* expect = "Hello world!" "

This is a test

"; @@ -53,14 +53,15 @@ static void on_finish(void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), + nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -77,18 +78,19 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -99,7 +101,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -116,18 +118,20 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), + &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, + n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -135,69 +139,69 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(void* p, grpc_error* error) { - grpc_pollset_destroy( - grpc_polling_entity_pollset(static_cast(p))); +static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { + grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( + static_cast(p))); } int main(int argc, char** argv) { + grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; + char* me = argv[0]; + char* lslash = strrchr(me, '/'); + char* args[4]; + int port = grpc_pick_unused_port_or_die(); + int arg_shift = 0; + /* figure out where we are */ + char* root; + if (lslash) { + root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); + memcpy(root, me, (size_t)(lslash - me)); + root[lslash - me] = 0; + } else { + root = gpr_strdup("."); + } + + GPR_ASSERT(argc <= 2); + if (argc == 2) { + args[0] = gpr_strdup(argv[1]); + } else { + arg_shift = 1; + gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); + gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); + } + + /* start the server */ + args[1 + arg_shift] = const_cast("--port"); + gpr_asprintf(&args[2 + arg_shift], "%d", port); + server = gpr_subprocess_create(3 + arg_shift, (const char**)args); + GPR_ASSERT(server); + gpr_free(args[0]); + if (arg_shift) gpr_free(args[1]); + gpr_free(args[2 + arg_shift]); + gpr_free(root); + + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); + grpc_test_init(argc, argv); grpc_init(); - { - grpc_closure destroyed; - grpc_core::ExecCtx exec_ctx; - char* me = argv[0]; - char* lslash = strrchr(me, '/'); - char* args[4]; - int port = grpc_pick_unused_port_or_die(); - int arg_shift = 0; - /* figure out where we are */ - char* root; - if (lslash) { - root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); - memcpy(root, me, (size_t)(lslash - me)); - root[lslash - me] = 0; - } else { - root = gpr_strdup("."); - } - - GPR_ASSERT(argc <= 2); - if (argc == 2) { - args[0] = gpr_strdup(argv[1]); - } else { - arg_shift = 1; - gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); - gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); - } - - /* start the server */ - args[1 + arg_shift] = const_cast("--port"); - gpr_asprintf(&args[2 + arg_shift], "%d", port); - server = gpr_subprocess_create(3 + arg_shift, (const char**)args); - GPR_ASSERT(server); - gpr_free(args[0]); - if (arg_shift) gpr_free(args[1]); - gpr_free(args[2 + arg_shift]); - gpr_free(root); - - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(5, GPR_TIMESPAN))); - - grpc_httpcli_context_init(&g_context); - grpc_pollset* pollset = - static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollset, &g_mu); - g_pops = grpc_polling_entity_create_from_pollset(pollset); - - test_get(port); - test_post(port); - - grpc_httpcli_context_destroy(&g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - } + grpc_httpcli_context_init(&g_context); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(pollset, &g_mu); + g_pops = grpc_polling_entity_create_from_pollset(pollset); + + test_get(port); + test_post(port); + + grpc_httpcli_context_destroy(&exec_ctx, &g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index adf69f1b16..da8405c049 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(void* arg, grpc_error* error) { +static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { const char* expect = "Hello world!" "

This is a test

"; @@ -53,14 +53,15 @@ static void on_finish(void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), + nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -78,18 +79,19 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -100,7 +102,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -118,18 +120,20 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), + &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, + n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -137,13 +141,14 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(void* p, grpc_error* error) { - grpc_pollset_destroy( - grpc_polling_entity_pollset(static_cast(p))); +static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { + grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( + static_cast(p))); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; char* me = argv[0]; char* lslash = strrchr(me, '/'); @@ -194,13 +199,12 @@ int main(int argc, char** argv) { test_get(port); test_post(port); - { - grpc_core::ExecCtx exec_ctx; - grpc_httpcli_context_destroy(&g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - } + grpc_httpcli_context_destroy(&exec_ctx, &g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), + &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/parser_test.cc b/test/core/http/parser_test.cc index 18f19856bd..0b60e369b7 100644 --- a/test/core/http/parser_test.cc +++ b/test/core/http/parser_test.cc @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -218,7 +217,6 @@ int main(int argc, char** argv) { char *tmp1, *tmp2; grpc_test_init(argc, argv); - grpc_init(); for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) { test_succeeds(split_modes[i], @@ -302,6 +300,5 @@ int main(int argc, char** argv) { gpr_free(tmp2); } - grpc_shutdown(); return 0; } diff --git a/test/core/http/request_fuzzer.cc b/test/core/http/request_fuzzer.cc index 9798cfb33c..368ac1b49d 100644 --- a/test/core/http/request_fuzzer.cc +++ b/test/core/http/request_fuzzer.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include "src/core/lib/http/parser.h" @@ -31,7 +30,6 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_request request; - grpc_init(); memset(&request, 0, sizeof(request)); grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -40,6 +38,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_request_destroy(&request); - grpc_shutdown(); return 0; } diff --git a/test/core/http/response_fuzzer.cc b/test/core/http/response_fuzzer.cc index fc0904b1db..2a793fddd4 100644 --- a/test/core/http/response_fuzzer.cc +++ b/test/core/http/response_fuzzer.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include "src/core/lib/http/parser.h" @@ -30,7 +29,6 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_response response; - grpc_init(); memset(&response, 0, sizeof(response)); grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -39,6 +37,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_response_destroy(&response); - grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 891008c774..33d892fa06 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -28,11 +28,13 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, grpc_combiner_create(), "test_no_op"); + grpc_exec_ctx_finish(&exec_ctx); } -static void set_event_to_true(void* value, grpc_error* error) { +static void set_event_to_true(grpc_exec_ctx* exec_ctx, void* value, + grpc_error* error) { gpr_event_set(static_cast(value), (void*)1); } @@ -42,14 +44,16 @@ static void test_execute_one(void) { grpc_combiner* lock = grpc_combiner_create(); gpr_event done; gpr_event_init(&done); - grpc_core::ExecCtx exec_ctx; - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CLOSURE_SCHED(&exec_ctx, + GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(lock, "test_execute_one"); + GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_one"); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -63,7 +67,7 @@ typedef struct { size_t value; } ex_args; -static void check_one(void* a, grpc_error* error) { +static void check_one(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { ex_args* args = static_cast(a); GPR_ASSERT(*args->ctr == args->value - 1); *args->ctr = args->value; @@ -72,25 +76,28 @@ static void check_one(void* a, grpc_error* error) { static void execute_many_loop(void* a) { thd_args* args = static_cast(a); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; size_t n = 1; for (size_t i = 0; i < 10; i++) { for (size_t j = 0; j < 10000; j++) { ex_args* c = static_cast(gpr_malloc(sizeof(*c))); c->ctr = &args->ctr; c->value = n++; - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE( + GRPC_CLOSURE_SCHED(&exec_ctx, + GRPC_CLOSURE_CREATE( check_one, c, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } // sleep for a little bit, to test a combiner draining and another thread // picking it up gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); } - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, + GRPC_CLOSURE_SCHED(&exec_ctx, + GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); + grpc_exec_ctx_finish(&exec_ctx); } static void test_execute_many(void) { @@ -113,18 +120,20 @@ static void test_execute_many(void) { gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr); gpr_thd_join(thds[i]); } - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(lock, "test_execute_many"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_many"); + grpc_exec_ctx_finish(&exec_ctx); } static gpr_event got_in_finally; -static void in_finally(void* arg, grpc_error* error) { +static void in_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { gpr_event_set(&got_in_finally, (void*)1); } -static void add_finally(void* arg, grpc_error* error) { - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(in_finally, arg, +static void add_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + GRPC_CLOSURE_SCHED(exec_ctx, + GRPC_CLOSURE_CREATE(in_finally, arg, grpc_combiner_finally_scheduler( static_cast(arg))), GRPC_ERROR_NONE); @@ -134,15 +143,17 @@ static void test_execute_finally(void) { gpr_log(GPR_DEBUG, "test_execute_finally"); grpc_combiner* lock = grpc_combiner_create(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_event_init(&got_in_finally); GRPC_CLOSURE_SCHED( + &exec_ctx, GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&got_in_finally, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(lock, "test_execute_finally"); + GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_finally"); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 90dd40d9c4..30a0cb5924 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -32,7 +32,7 @@ static void clean_up(void) {} static grpc_endpoint_test_fixture create_fixture_endpoint_pair( size_t slice_size) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_endpoint_test_fixture f; grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); @@ -43,8 +43,9 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( f.client_ep = p.client; f.server_ep = p.server; - grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); + grpc_exec_ctx_finish(&exec_ctx); return f; } @@ -53,23 +54,23 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, }; -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - } + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 8ccae52067..026e34105d 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -115,7 +115,8 @@ struct read_and_write_test_state { grpc_closure done_write; }; -static void read_and_write_test_read_handler(void* data, grpc_error* error) { +static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx, + void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; @@ -125,14 +126,17 @@ static void read_and_write_test_read_handler(void* data, grpc_error* error) { gpr_log(GPR_INFO, "Read handler done"); gpr_mu_lock(g_mu); state->read_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); gpr_mu_unlock(g_mu); } else if (error == GRPC_ERROR_NONE) { - grpc_endpoint_read(state->read_ep, &state->incoming, &state->done_read); + grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, + &state->done_read); } } -static void read_and_write_test_write_handler(void* data, grpc_error* error) { +static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, + void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; grpc_slice* slices = nullptr; @@ -149,7 +153,7 @@ static void read_and_write_test_write_handler(void* data, grpc_error* error) { &state->current_write_data); grpc_slice_buffer_reset_and_unref(&state->outgoing); grpc_slice_buffer_addn(&state->outgoing, slices, nslices); - grpc_endpoint_write(state->write_ep, &state->outgoing, + grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing, &state->done_write); gpr_free(slices); return; @@ -159,7 +163,8 @@ static void read_and_write_test_write_handler(void* data, grpc_error* error) { gpr_log(GPR_INFO, "Write handler done"); gpr_mu_lock(g_mu); state->write_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); gpr_mu_unlock(g_mu); } @@ -173,7 +178,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, struct read_and_write_test_state state; grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, @@ -212,57 +217,66 @@ static void read_and_write_test(grpc_endpoint_test_config config, for the first iteration as for later iterations. It does the right thing even when bytes_written is unsigned. */ state.bytes_written -= state.current_write_size; - read_and_write_test_write_handler(&state, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + read_and_write_test_write_handler(&exec_ctx, &state, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); - grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read); + grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming, + &state.done_read); if (shutdown) { gpr_log(GPR_DEBUG, "shutdown read"); grpc_endpoint_shutdown( - state.read_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + &exec_ctx, state.read_ep, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); gpr_log(GPR_DEBUG, "shutdown write"); grpc_endpoint_shutdown( - state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + &exec_ctx, state.write_ep, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = nullptr; - GPR_ASSERT(grpc_core::ExecCtx::Get()->Now() < deadline); + GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); end_test(config); - grpc_slice_buffer_destroy_internal(&state.outgoing); - grpc_slice_buffer_destroy_internal(&state.incoming); - grpc_endpoint_destroy(state.read_ep); - grpc_endpoint_destroy(state.write_ep); + grpc_slice_buffer_destroy_internal(&exec_ctx, &state.outgoing); + grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); + grpc_endpoint_destroy(&exec_ctx, state.read_ep); + grpc_endpoint_destroy(&exec_ctx, state.write_ep); + grpc_exec_ctx_finish(&exec_ctx); } -static void inc_on_failure(void* arg, grpc_error* error) { +static void inc_on_failure(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { gpr_mu_lock(g_mu); *(int*)arg += (error != GRPC_ERROR_NONE); - GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void wait_for_fail_count(int* fail_count, int want_fail_count) { - grpc_core::ExecCtx::Get()->Flush(); +static void wait_for_fail_count(grpc_exec_ctx* exec_ctx, int* fail_count, + int want_fail_count) { + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(g_mu); grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); - while (grpc_core::ExecCtx::Get()->Now() < deadline && + while (grpc_exec_ctx_now(exec_ctx) < deadline && *fail_count < want_fail_count) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(g_mu); } GPR_ASSERT(*fail_count == want_fail_count); @@ -277,32 +291,33 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_slice_buffer slice_buffer; grpc_slice_buffer_init(&slice_buffer); - grpc_core::ExecCtx exec_ctx; - grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); - grpc_endpoint_read(f.client_ep, &slice_buffer, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); + grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&fail_count, 0); - grpc_endpoint_shutdown(f.client_ep, + wait_for_fail_count(&exec_ctx, &fail_count, 0); + grpc_endpoint_shutdown(&exec_ctx, f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&fail_count, 1); - grpc_endpoint_read(f.client_ep, &slice_buffer, + wait_for_fail_count(&exec_ctx, &fail_count, 1); + grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&fail_count, 2); + wait_for_fail_count(&exec_ctx, &fail_count, 2); grpc_slice_buffer_add(&slice_buffer, grpc_slice_from_copied_string("a")); - grpc_endpoint_write(f.client_ep, &slice_buffer, + grpc_endpoint_write(&exec_ctx, f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&fail_count, 3); - grpc_endpoint_shutdown(f.client_ep, + wait_for_fail_count(&exec_ctx, &fail_count, 3); + grpc_endpoint_shutdown(&exec_ctx, f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&fail_count, 3); + wait_for_fail_count(&exec_ctx, &fail_count, 3); - grpc_slice_buffer_destroy_internal(&slice_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, &slice_buffer); - grpc_endpoint_destroy(f.client_ep); - grpc_endpoint_destroy(f.server_ep); + grpc_endpoint_destroy(&exec_ctx, f.client_ep); + grpc_endpoint_destroy(&exec_ctx, f.server_ep); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_endpoint_tests(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index e767e01f21..94f387164a 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -70,18 +70,19 @@ static void test_fd_init(test_fd* tfds, int* fds, int num_fds) { } } -static void test_fd_cleanup(test_fd* tfds, int num_fds) { +static void test_fd_cleanup(grpc_exec_ctx* exec_ctx, test_fd* tfds, + int num_fds) { int release_fd; int i; for (i = 0; i < num_fds; i++) { - grpc_fd_shutdown(tfds[i].fd, + grpc_fd_shutdown(exec_ctx, tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); - grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, - "test_fd_cleanup"); - grpc_core::ExecCtx::Get()->Flush(); + grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, + false /* already_closed */, "test_fd_cleanup"); + grpc_exec_ctx_flush(exec_ctx); GPR_ASSERT(release_fd == tfds[i].inner_fd); close(tfds[i].inner_fd); @@ -97,20 +98,22 @@ static void test_pollset_init(test_pollset* pollsets, int num_pollsets) { } } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); } -static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { +static void test_pollset_cleanup(grpc_exec_ctx* exec_ctx, + test_pollset* pollsets, int num_pollsets) { grpc_closure destroyed; int i; for (i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); + grpc_pollset_shutdown(exec_ctx, pollsets[i].pollset, &destroyed); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_free(pollsets[i].pollset); } } @@ -130,7 +133,7 @@ static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { #define NUM_POLLSETS 4 static void test_add_fd_to_pollset() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; test_fd tfds[NUM_FDS]; int fds[NUM_FDS]; test_pollset pollsets[NUM_POLLSETS]; @@ -167,33 +170,33 @@ static void test_add_fd_to_pollset() { /* == Step 1 == */ for (i = 0; i <= 2; i++) { - grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); } for (i = 3; i <= 4; i++) { - grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); } for (i = 5; i <= 7; i++) { - grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); } /* == Step 2 == */ for (i = 0; i <= 1; i++) { - grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[3].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); } /* == Step 3 == */ - grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[0].fd); + grpc_exec_ctx_flush(&exec_ctx); /* == Step 4 == */ - grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[3].fd); + grpc_exec_ctx_flush(&exec_ctx); /* All polling islands are merged at this point */ @@ -210,8 +213,9 @@ static void test_add_fd_to_pollset() { expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); } - test_fd_cleanup(tfds, NUM_FDS); - test_pollset_cleanup(pollsets, NUM_POLLSETS); + test_fd_cleanup(&exec_ctx, tfds, NUM_FDS); + test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS); + grpc_exec_ctx_finish(&exec_ctx); } #undef NUM_FDS @@ -231,24 +235,26 @@ static __thread int thread_wakeups = 0; static void test_threading_loop(void* arg) { threading_shared* shared = static_cast(arg); while (thread_wakeups < 1000000) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker* worker; gpr_mu_lock(shared->mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(shared->pollset, &worker, GRPC_MILLIS_INF_FUTURE))); + "pollset_work", grpc_pollset_work(&exec_ctx, shared->pollset, &worker, + GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(shared->mu); + grpc_exec_ctx_finish(&exec_ctx); } } -static void test_threading_wakeup(void* arg, grpc_error* error) { +static void test_threading_wakeup(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { threading_shared* shared = static_cast(arg); ++shared->wakeups; ++thread_wakeups; if (error == GRPC_ERROR_NONE) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "consume_wakeup", grpc_wakeup_fd_consume_wakeup(shared->wakeup_fd))); - grpc_fd_notify_on_read(shared->wakeup_desc, &shared->on_wakeup); + grpc_fd_notify_on_read(exec_ctx, shared->wakeup_desc, &shared->on_wakeup); GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_next", grpc_wakeup_fd_wakeup(shared->wakeup_fd))); } @@ -271,12 +277,13 @@ static void test_threading(void) { shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup"); shared.wakeups = 0; { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_pollset_add_fd(&exec_ctx, shared.pollset, shared.wakeup_desc); grpc_fd_notify_on_read( - shared.wakeup_desc, + &exec_ctx, shared.wakeup_desc, GRPC_CLOSURE_INIT(&shared.on_wakeup, test_threading_wakeup, &shared, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", grpc_wakeup_fd_wakeup(shared.wakeup_fd))); @@ -286,13 +293,14 @@ static void test_threading(void) { fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); { - grpc_core::ExecCtx exec_ctx; - grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); - grpc_fd_orphan(shared.wakeup_desc, nullptr, nullptr, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_fd_shutdown(&exec_ctx, shared.wakeup_desc, GRPC_ERROR_CANCELLED); + grpc_fd_orphan(&exec_ctx, shared.wakeup_desc, nullptr, nullptr, false /* already_closed */, "done"); - grpc_pollset_shutdown(shared.pollset, + grpc_pollset_shutdown(&exec_ctx, shared.pollset, GRPC_CLOSURE_CREATE(destroy_pollset, shared.pollset, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_finish(&exec_ctx); } gpr_free(shared.pollset); } @@ -301,21 +309,20 @@ int main(int argc, char** argv) { const char* poll_strategy = nullptr; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - - poll_strategy = grpc_get_poll_strategy_name(); - if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { - test_add_fd_to_pollset(); - test_threading(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epollsig' " - "strategy. and the current strategy is: '%s'", - poll_strategy); - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + poll_strategy = grpc_get_poll_strategy_name(); + if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { + test_add_fd_to_pollset(); + test_threading(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epollsig' " + "strategy. and the current strategy is: '%s'", + poll_strategy); } + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index aaa14010f8..f46430c611 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -31,27 +31,26 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - - /* set max # of file descriptors to a low value, and - verify we can create and destroy many more than this number - of descriptors */ - rlim.rlim_cur = rlim.rlim_max = 10; - GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("fd_conservation_posix_test"); - - for (i = 0; i < 100; i++) { - p = grpc_iomgr_create_endpoint_pair("test", NULL); - grpc_endpoint_destroy(p.client); - grpc_endpoint_destroy(p.server); - grpc_core::ExecCtx::Get()->Flush(); - } - - grpc_resource_quota_unref(resource_quota); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + /* set max # of file descriptors to a low value, and + verify we can create and destroy many more than this number + of descriptors */ + rlim.rlim_cur = rlim.rlim_max = 10; + GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("fd_conservation_posix_test"); + + for (i = 0; i < 100; i++) { + p = grpc_iomgr_create_endpoint_pair("test", nullptr); + grpc_endpoint_destroy(&exec_ctx, p.client); + grpc_endpoint_destroy(&exec_ctx, p.server); + grpc_exec_ctx_flush(&exec_ctx); } + grpc_resource_quota_unref(resource_quota); + + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index cf75517538..a03d841ecd 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -111,19 +111,20 @@ typedef struct { /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ -static void session_shutdown_cb(void* arg, /*session */ +static void session_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ bool success) { session* se = static_cast(arg); server* sv = se->sv; - grpc_fd_orphan(se->em_fd, nullptr, nullptr, false /* already_closed */, "a"); + grpc_fd_orphan(exec_ctx, se->em_fd, nullptr, nullptr, + false /* already_closed */, "a"); gpr_free(se); /* Start to shutdown listen fd. */ - grpc_fd_shutdown(sv->em_fd, + grpc_fd_shutdown(exec_ctx, sv->em_fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("session_shutdown_cb")); } /* Called when data become readable in a session. */ -static void session_read_cb(void* arg, /*session */ +static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ grpc_error* error) { session* se = static_cast(arg); int fd = grpc_fd_wrapped_fd(se->em_fd); @@ -132,7 +133,7 @@ static void session_read_cb(void* arg, /*session */ ssize_t read_total = 0; if (error != GRPC_ERROR_NONE) { - session_shutdown_cb(arg, 1); + session_shutdown_cb(exec_ctx, arg, 1); return; } @@ -147,7 +148,7 @@ static void session_read_cb(void* arg, /*session */ It is possible to read nothing due to spurious edge event or data has been drained, In such a case, read() returns -1 and set errno to EAGAIN. */ if (read_once == 0) { - session_shutdown_cb(arg, 1); + session_shutdown_cb(exec_ctx, arg, 1); } else if (read_once == -1) { if (errno == EAGAIN) { /* An edge triggered event is cached in the kernel until next poll. @@ -158,7 +159,7 @@ static void session_read_cb(void* arg, /*session */ TODO(chenw): in multi-threaded version, callback and polling can be run in different threads. polling may catch a persist read edge event before notify_on_read is called. */ - grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); } else { gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); abort(); @@ -168,20 +169,22 @@ static void session_read_cb(void* arg, /*session */ /* Called when the listen FD can be safely shutdown. Close listen FD and signal that server can be shutdown. */ -static void listen_shutdown_cb(void* arg /*server */, int success) { +static void listen_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg /*server */, + int success) { server* sv = static_cast(arg); - grpc_fd_orphan(sv->em_fd, nullptr, nullptr, false /* already_closed */, "b"); + grpc_fd_orphan(exec_ctx, sv->em_fd, nullptr, nullptr, + false /* already_closed */, "b"); gpr_mu_lock(g_mu); sv->done = 1; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } /* Called when a new TCP connection request arrives in the listening port. */ -static void listen_cb(void* arg, /*=sv_arg*/ +static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ grpc_error* error) { server* sv = static_cast(arg); int fd; @@ -192,7 +195,7 @@ static void listen_cb(void* arg, /*=sv_arg*/ grpc_fd* listen_em_fd = sv->em_fd; if (error != GRPC_ERROR_NONE) { - listen_shutdown_cb(arg, 1); + listen_shutdown_cb(exec_ctx, arg, 1); return; } @@ -204,12 +207,12 @@ static void listen_cb(void* arg, /*=sv_arg*/ se = static_cast(gpr_malloc(sizeof(*se))); se->sv = sv; se->em_fd = grpc_fd_create(fd, "listener"); - grpc_pollset_add_fd(g_pollset, se->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, se->em_fd); GRPC_CLOSURE_INIT(&se->session_read_closure, session_read_cb, se, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); - grpc_fd_notify_on_read(listen_em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(exec_ctx, listen_em_fd, &sv->listen_closure); } /* Max number of connections pending to be accepted by listen(). */ @@ -219,7 +222,7 @@ static void listen_cb(void* arg, /*=sv_arg*/ listen_cb() is registered to be interested in reading from listen_fd. When connection request arrives, listen_cb() is called to accept the connection request. */ -static int server_start(server* sv) { +static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { int port = 0; int fd; struct sockaddr_in sin; @@ -233,11 +236,11 @@ static int server_start(server* sv) { GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); sv->em_fd = grpc_fd_create(fd, "server"); - grpc_pollset_add_fd(g_pollset, sv->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, sv->em_fd); /* Register to be interested in reading from listen_fd. */ GRPC_CLOSURE_INIT(&sv->listen_closure, listen_cb, sv, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(sv->em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(exec_ctx, sv->em_fd, &sv->listen_closure); return port; } @@ -246,13 +249,13 @@ static int server_start(server* sv) { static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -286,16 +289,18 @@ static void client_init(client* cl) { } /* Called when a client upload session is ready to shutdown. */ -static void client_session_shutdown_cb(void* arg /*client */, int success) { +static void client_session_shutdown_cb(grpc_exec_ctx* exec_ctx, + void* arg /*client */, int success) { client* cl = static_cast(arg); - grpc_fd_orphan(cl->em_fd, nullptr, nullptr, false /* already_closed */, "c"); + grpc_fd_orphan(exec_ctx, cl->em_fd, nullptr, nullptr, + false /* already_closed */, "c"); cl->done = 1; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); } /* Write as much as possible, then register notify_on_write. */ -static void client_session_write(void* arg, /*client */ +static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ grpc_error* error) { client* cl = static_cast(arg); int fd = grpc_fd_wrapped_fd(cl->em_fd); @@ -303,7 +308,7 @@ static void client_session_write(void* arg, /*client */ if (error != GRPC_ERROR_NONE) { gpr_mu_lock(g_mu); - client_session_shutdown_cb(arg, 1); + client_session_shutdown_cb(exec_ctx, arg, 1); gpr_mu_unlock(g_mu); return; } @@ -318,10 +323,10 @@ static void client_session_write(void* arg, /*client */ if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { GRPC_CLOSURE_INIT(&cl->write_closure, client_session_write, cl, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_write(cl->em_fd, &cl->write_closure); + grpc_fd_notify_on_write(exec_ctx, cl->em_fd, &cl->write_closure); cl->client_write_cnt++; } else { - client_session_shutdown_cb(arg, 1); + client_session_shutdown_cb(exec_ctx, arg, 1); } gpr_mu_unlock(g_mu); } else { @@ -331,7 +336,7 @@ static void client_session_write(void* arg, /*client */ } /* Start a client to send a stream of bytes. */ -static void client_start(client* cl, int port) { +static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); @@ -352,9 +357,9 @@ static void client_start(client* cl, int port) { } cl->em_fd = grpc_fd_create(fd, "client"); - grpc_pollset_add_fd(g_pollset, cl->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd); - client_session_write(cl, GRPC_ERROR_NONE); + client_session_write(exec_ctx, cl, GRPC_ERROR_NONE); } /* Wait for the signal to shutdown a client. */ @@ -362,12 +367,12 @@ static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -380,13 +385,13 @@ static void test_grpc_fd(void) { server sv; client cl; int port; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; server_init(&sv); - port = server_start(&sv); + port = server_start(&exec_ctx, &sv); client_init(&cl); - client_start(&cl, port); - + client_start(&exec_ctx, &cl, port); + grpc_exec_ctx_finish(&exec_ctx); client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); @@ -401,25 +406,27 @@ void init_change_data(fd_change_data* fdc) { fdc->cb_that_ran = nullptr; } void destroy_change_data(fd_change_data* fdc) {} -static void first_read_callback(void* arg /* fd_change_data */, +static void first_read_callback(grpc_exec_ctx* exec_ctx, + void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void second_read_callback(void* arg /* fd_change_data */, +static void second_read_callback(grpc_exec_ctx* exec_ctx, + void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -436,7 +443,7 @@ static void test_grpc_fd_change(void) { ssize_t result; grpc_closure first_closure; grpc_closure second_closure; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_CLOSURE_INIT(&first_closure, first_read_callback, &a, grpc_schedule_on_exec_ctx); @@ -453,10 +460,10 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change"); - grpc_pollset_add_fd(g_pollset, em_fd); + grpc_pollset_add_fd(&exec_ctx, g_pollset, em_fd); /* Register the first callback, then make its FD readable */ - grpc_fd_notify_on_read(em_fd, &first_closure); + grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -466,10 +473,10 @@ static void test_grpc_fd_change(void) { while (a.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); @@ -481,7 +488,7 @@ static void test_grpc_fd_change(void) { /* Now register a second callback with distinct change data, and do the same thing again. */ - grpc_fd_notify_on_read(em_fd, &second_closure); + grpc_fd_notify_on_read(&exec_ctx, em_fd, &second_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -490,43 +497,44 @@ static void test_grpc_fd_change(void) { while (b.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); gpr_mu_unlock(g_mu); - grpc_fd_orphan(em_fd, nullptr, nullptr, false /* already_closed */, "d"); - + grpc_fd_orphan(&exec_ctx, em_fd, nullptr, nullptr, false /* already_closed */, + "d"); + grpc_exec_ctx_finish(&exec_ctx); destroy_change_data(&a); destroy_change_data(&b); close(sv[1]); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - test_grpc_fd(); - test_grpc_fd_change(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(g_pollset); - } + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + test_grpc_fd(); + test_grpc_fd_change(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_flush(&exec_ctx); + gpr_free(g_pollset); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/load_file_test.cc b/test/core/iomgr/load_file_test.cc index 797d0ef1a4..9f360badcc 100644 --- a/test/core/iomgr/load_file_test.cc +++ b/test/core/iomgr/load_file_test.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -153,11 +152,9 @@ static void test_load_big_file(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_load_empty_file(); test_load_failure(); test_load_small_file(); test_load_big_file(); - grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index f27079134b..719eab91fe 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -47,10 +47,11 @@ void init_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { } } -void cleanup_test_pollset_sets(test_pollset_set* pollset_sets, +void cleanup_test_pollset_sets(grpc_exec_ctx* exec_ctx, + test_pollset_set* pollset_sets, const int num_pss) { for (int i = 0; i < num_pss; i++) { - grpc_pollset_set_destroy(pollset_sets[i].pss); + grpc_pollset_set_destroy(exec_ctx, pollset_sets[i].pss); pollset_sets[i].pss = nullptr; } } @@ -72,19 +73,21 @@ static void init_test_pollsets(test_pollset* pollsets, const int num_pollsets) { } } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } -static void cleanup_test_pollsets(test_pollset* pollsets, +static void cleanup_test_pollsets(grpc_exec_ctx* exec_ctx, + test_pollset* pollsets, const int num_pollsets) { grpc_closure destroyed; for (int i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(pollsets[i].ps, &destroyed); + grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_free(pollsets[i].ps); pollsets[i].ps = nullptr; } @@ -102,43 +105,45 @@ typedef struct test_fd { grpc_closure on_readable; /* Closure to call when this fd is readable */ } test_fd; -void on_readable(void* tfd, grpc_error* error) { +void on_readable(grpc_exec_ctx* exec_ctx, void* tfd, grpc_error* error) { ((test_fd*)tfd)->is_on_readable_called = true; } -static void reset_test_fd(test_fd* tfd) { +static void reset_test_fd(grpc_exec_ctx* exec_ctx, test_fd* tfd) { tfd->is_on_readable_called = false; GRPC_CLOSURE_INIT(&tfd->on_readable, on_readable, tfd, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(tfd->fd, &tfd->on_readable); + grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); } -static void init_test_fds(test_fd* tfds, const int num_fds) { +static void init_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, + const int num_fds) { for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), "test_fd"); - reset_test_fd(&tfds[i]); + reset_test_fd(exec_ctx, &tfds[i]); } } -static void cleanup_test_fds(test_fd* tfds, const int num_fds) { +static void cleanup_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, + const int num_fds) { int release_fd; for (int i = 0; i < num_fds; i++) { - grpc_fd_shutdown(tfds[i].fd, + grpc_fd_shutdown(exec_ctx, tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also * calls close() on the underlying fd. In our case, we are using * grpc_wakeup_fd and we would like to destroy it ourselves (by calling * grpc_wakeup_fd_destroy). To prevent grpc_fd from calling close() on the * underlying fd, call it with a non-NULL 'release_fd' parameter */ - grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, - "test_fd_cleanup"); - grpc_core::ExecCtx::Get()->Flush(); + grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, + false /* already_closed */, "test_fd_cleanup"); + grpc_exec_ctx_flush(exec_ctx); grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); } @@ -150,7 +155,8 @@ static void make_test_fds_readable(test_fd* tfds, const int num_fds) { } } -static void verify_readable_and_reset(test_fd* tfds, const int num_fds) { +static void verify_readable_and_reset(grpc_exec_ctx* exec_ctx, test_fd* tfds, + const int num_fds) { for (int i = 0; i < num_fds; i++) { /* Verify that the on_readable callback was called */ GPR_ASSERT(tfds[i].is_on_readable_called); @@ -158,7 +164,7 @@ static void verify_readable_and_reset(test_fd* tfds, const int num_fds) { /* Reset the tfd[i] structure */ GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_consume_wakeup(&tfds[i].wakeup_fd)); - reset_test_fd(&tfds[i]); + reset_test_fd(exec_ctx, &tfds[i]); } } @@ -199,7 +205,7 @@ static void pollset_set_test_basic() { * | * +---> FD9 (Added after PS2 is added to PSS0) */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker* worker; grpc_millis deadline; @@ -210,33 +216,34 @@ static void pollset_set_test_basic() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(tfds, num_fds); + init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the pollset_set/pollset/fd tree (see diagram above) */ - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(pollsets[0].ps, tfds[2].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[3].fd); - grpc_pollset_add_fd(pollsets[2].ps, tfds[4].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[2].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[3].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[4].fd); - grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); - grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[2].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[6].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); - grpc_pollset_add_fd(pollsets[0].ps, tfds[7].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); - grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[7].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[8].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[9].fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); /* Test that if any FD in the above structure is readable, it is observable by * doing grpc_pollset_work on any pollset @@ -256,32 +263,34 @@ static void pollset_set_test_basic() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollsets[i].ps, &worker, deadline)); + grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, deadline)); gpr_mu_unlock(pollsets[i].mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); } /* Test tear down */ - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); - grpc_core::ExecCtx::Get()->Flush(); - - grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); - - grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(pollsets, num_ps); - cleanup_test_pollset_sets(pollset_sets, num_pss); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); + grpc_exec_ctx_flush(&exec_ctx); + + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); + + grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); + cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); + grpc_exec_ctx_finish(&exec_ctx); } /* Same FD added multiple times to the pollset_set tree */ @@ -301,7 +310,7 @@ void pollset_set_test_dup_fds() { * | +--> FD2 * +---> FD1 */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker* worker; grpc_millis deadline; @@ -312,20 +321,21 @@ void pollset_set_test_dup_fds() { const int num_ps = 1; const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(tfds, num_fds); + init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(&pollset, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(pollset.ps, tfds[1].fd); - grpc_pollset_add_fd(pollset.ps, tfds[2].fd); + grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[1].fd); + grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[2].fd); - grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); /* Test. Make all FDs readable and make sure that can be observed by doing a * grpc_pollset_work on the pollset 'PS' */ @@ -335,25 +345,27 @@ void pollset_set_test_dup_fds() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollset.ps, &worker, deadline)); + grpc_pollset_work(&exec_ctx, pollset.ps, &worker, deadline)); gpr_mu_unlock(pollset.mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); /* Tear down */ - grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(&pollset, num_ps); - cleanup_test_pollset_sets(pollset_sets, num_pss); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, &pollset, num_ps); + cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); + grpc_exec_ctx_finish(&exec_ctx); } /* Pollset_set with an empty pollset */ @@ -371,7 +383,7 @@ void pollset_set_test_empty_pollset() { * | * +---> FD2 */ - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker* worker; grpc_millis deadline; @@ -382,17 +394,17 @@ void pollset_set_test_empty_pollset() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = 1; - init_test_fds(tfds, num_fds); + init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(&pollset_set, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(pollset_set.pss, tfds[0].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[1].fd); - grpc_pollset_add_fd(pollsets[1].ps, tfds[2].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[1].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[2].fd); - grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); /* Test. Make all FDs readable and make sure that can be observed by doing * grpc_pollset_work on the empty pollset 'PS0' */ @@ -402,44 +414,45 @@ void pollset_set_test_empty_pollset() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(pollsets[0].ps, &worker, deadline)); + grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, deadline)); gpr_mu_unlock(pollsets[0].mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); - verify_readable_and_reset(tfds, num_fds); - grpc_core::ExecCtx::Get()->Flush(); + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); /* Tear down */ - grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); - grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); - grpc_core::ExecCtx::Get()->Flush(); - - cleanup_test_fds(tfds, num_fds); - cleanup_test_pollsets(pollsets, num_ps); - cleanup_test_pollset_sets(&pollset_set, num_pss); + grpc_pollset_set_del_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); + cleanup_test_pollset_sets(&exec_ctx, &pollset_set, num_pss); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - const char* poll_strategy = grpc_get_poll_strategy_name(); - - if (poll_strategy != nullptr && - (strcmp(poll_strategy, "epollsig") == 0 || - strcmp(poll_strategy, "epoll-threadpool") == 0)) { - pollset_set_test_basic(); - pollset_set_test_dup_fds(); - pollset_set_test_empty_pollset(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epoll' " - "strategy. and the current strategy is: '%s'", - poll_strategy); - } + const char* poll_strategy = grpc_get_poll_strategy_name(); + + if (poll_strategy != nullptr && + (strcmp(poll_strategy, "epollsig") == 0 || + strcmp(poll_strategy, "epoll-threadpool") == 0)) { + pollset_set_test_basic(); + pollset_set_test_dup_fds(); + pollset_set_test_empty_pollset(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epoll' " + "strategy. and the current strategy is: '%s'", + poll_strategy); } + + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index e36315333c..836de423bd 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -46,29 +46,29 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -void args_init(args_struct* args) { +void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); args->addrs = nullptr; } -void args_finish(args_struct* args) { +void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); - grpc_pollset_set_destroy(args->pollset_set); + grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_destroy(exec_ctx, args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_core::ExecCtx::Get()->Flush(); - grpc_pollset_destroy(args->pollset); + grpc_exec_ctx_flush(exec_ctx); + grpc_pollset_destroy(exec_ctx, args->pollset); gpr_free(args->pollset); } @@ -79,24 +79,26 @@ static grpc_millis n_sec_deadline(int seconds) { static void actually_poll(void* argsp) { args_struct* args = static_cast(argsp); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = n_sec_deadline(10); while (true) { - grpc_core::ExecCtx exec_ctx; bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); + grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(&exec_ctx, args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } gpr_event_set(&args->ev, (void*)1); + grpc_exec_ctx_finish(&exec_ctx); } static void poll_pollset_until_request_done(args_struct* args) { @@ -105,7 +107,8 @@ static void poll_pollset_until_request_done(args_struct* args) { gpr_thd_new(&id, "grpc_poll_pollset", actually_poll, args, nullptr); } -static void must_succeed(void* argsp, grpc_error* err) { +static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, + grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); @@ -113,28 +116,29 @@ static void must_succeed(void* argsp, grpc_error* err) { gpr_atm_rel_store(&args->done_atm, 1); } -static void must_fail(void* argsp, grpc_error* err) { +static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); } static void test_unix_socket(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); poll_pollset_until_request_done(&args); grpc_resolve_address( - "unix:/path/name", nullptr, args.pollset_set, + &exec_ctx, "unix:/path/name", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_unix_socket_path_name_too_long(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); const char prefix[] = "unix:/path/name"; size_t path_name_length = GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) + 6; @@ -146,23 +150,22 @@ static void test_unix_socket_path_name_too_long(void) { poll_pollset_until_request_done(&args); grpc_resolve_address( - path_name, nullptr, args.pollset_set, + &exec_ctx, path_name, nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); gpr_free(path_name); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - - { - grpc_core::ExecCtx exec_ctx; - test_unix_socket(); - test_unix_socket_path_name_too_long(); - } - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + test_unix_socket(); + test_unix_socket_path_name_too_long(); + grpc_executor_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index a0dc484f3e..1c5aa38a95 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -39,32 +39,32 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -void args_init(args_struct* args) { +void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); args->addrs = nullptr; gpr_atm_rel_store(&args->done_atm, 0); } -void args_finish(args_struct* args) { +void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); - grpc_pollset_set_destroy(args->pollset_set); + grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_destroy(exec_ctx, args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); gpr_mu_lock(args->mu); - grpc_pollset_shutdown(args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); gpr_mu_unlock(args->mu); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_core::ExecCtx::Get()->Flush(); - grpc_pollset_destroy(args->pollset); + grpc_exec_ctx_flush(exec_ctx); + grpc_pollset_destroy(exec_ctx, args->pollset); gpr_free(args->pollset); } @@ -74,109 +74,119 @@ static grpc_millis n_sec_deadline(int seconds) { } static void poll_pollset_until_request_done(args_struct* args) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); + grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(&exec_ctx, args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } gpr_event_set(&args->ev, (void*)1); + grpc_exec_ctx_finish(&exec_ctx); } -static void must_succeed(void* argsp, grpc_error* err) { +static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, + grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); GPR_ASSERT(args->addrs->naddrs > 0); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); gpr_mu_unlock(args->mu); } -static void must_fail(void* argsp, grpc_error* err) { +static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); gpr_mu_unlock(args->mu); } static void test_localhost(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - "localhost:1", nullptr, args.pollset_set, + &exec_ctx, "localhost:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_default_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - "localhost", "1", args.pollset_set, + &exec_ctx, "localhost", "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_non_numeric_default_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - "localhost", "https", args.pollset_set, + &exec_ctx, "localhost", "https", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_missing_default_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - "localhost", nullptr, args.pollset_set, + &exec_ctx, "localhost", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_ipv6_with_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - "[2001:db8::1]:1", nullptr, args.pollset_set, + &exec_ctx, "[2001:db8::1]:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } static void test_ipv6_without_port(void) { @@ -187,16 +197,17 @@ static void test_ipv6_without_port(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - kCases[i], "80", args.pollset_set, + &exec_ctx, kCases[i], "80", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -207,16 +218,17 @@ static void test_invalid_ip_addresses(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - kCases[i], nullptr, args.pollset_set, + &exec_ctx, kCases[i], nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -226,35 +238,34 @@ static void test_unparseable_hostports(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; args_struct args; - args_init(&args); + args_init(&exec_ctx, &args); grpc_resolve_address( - kCases[i], "1", args.pollset_set, + &exec_ctx, kCases[i], "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); poll_pollset_until_request_done(&args); - args_finish(&args); + args_finish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - test_localhost(); - test_default_port(); - test_non_numeric_default_port(); - test_missing_default_port(); - test_ipv6_with_port(); - test_ipv6_without_port(); - test_invalid_ip_addresses(); - test_unparseable_hostports(); - grpc_executor_shutdown(); - } - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + test_localhost(); + test_default_port(); + test_non_numeric_default_port(); + test_missing_default_port(); + test_ipv6_with_port(); + test_ipv6_without_port(); + test_invalid_ip_addresses(); + test_unparseable_hostports(); + grpc_executor_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index ae26f72701..6851702e67 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -27,7 +27,7 @@ gpr_mu g_mu; gpr_cv g_cv; -static void inc_int_cb(void* a, grpc_error* error) { +static void inc_int_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { gpr_mu_lock(&g_mu); ++*(int*)a; gpr_cv_signal(&g_cv); @@ -43,7 +43,7 @@ static void assert_counter_becomes(int* ctr, int value) { gpr_mu_unlock(&g_mu); } -static void set_event_cb(void* a, grpc_error* error) { +static void set_event_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { gpr_event_set((gpr_event*)a, (void*)1); } grpc_closure* set_event(gpr_event* ev) { @@ -56,12 +56,13 @@ typedef struct { grpc_closure* then; } reclaimer_args; -static void reclaimer_cb(void* args, grpc_error* error) { +static void reclaimer_cb(grpc_exec_ctx* exec_ctx, void* args, + grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); reclaimer_args* a = static_cast(args); - grpc_resource_user_free(a->resource_user, a->size); - grpc_resource_user_finish_reclamation(a->resource_user); - GRPC_CLOSURE_RUN(a->then, GRPC_ERROR_NONE); + grpc_resource_user_free(exec_ctx, a->resource_user, a->size); + grpc_resource_user_finish_reclamation(exec_ctx, a->resource_user); + GRPC_CLOSURE_RUN(exec_ctx, a->then, GRPC_ERROR_NONE); gpr_free(a); } @@ -74,9 +75,10 @@ grpc_closure* make_reclaimer(grpc_resource_user* resource_user, size_t size, return GRPC_CLOSURE_CREATE(reclaimer_cb, a, grpc_schedule_on_exec_ctx); } -static void unused_reclaimer_cb(void* arg, grpc_error* error) { +static void unused_reclaimer_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_RUN(static_cast(arg), GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(exec_ctx, static_cast(arg), GRPC_ERROR_NONE); } grpc_closure* make_unused_reclaimer(grpc_closure* then) { return GRPC_CLOSURE_CREATE(unused_reclaimer_cb, then, @@ -84,8 +86,9 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { } static void destroy_user(grpc_resource_user* usr) { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_unref(usr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_unref(&exec_ctx, usr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op(void) { @@ -117,12 +120,14 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -135,9 +140,10 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -152,15 +158,16 @@ static void test_simple_async_alloc(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -175,9 +182,9 @@ static void test_async_alloc_blocked_by_size(void) { gpr_event ev; gpr_event_init(&ev); { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } @@ -186,8 +193,9 @@ static void test_async_alloc_blocked_by_size(void) { nullptr); ; { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -202,30 +210,32 @@ static void test_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr1, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr1, 1024); + grpc_exec_ctx_finish(&exec_ctx); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr2, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr2, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -241,32 +251,33 @@ static void test_scavenge_blocked(void) { gpr_event ev; { gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr1, 1024); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr1, 1024); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr2, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr2, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -282,9 +293,9 @@ static void test_blocked_until_scheduled_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -292,16 +303,18 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 1024, set_event(&reclaim_done))); + grpc_exec_ctx_finish(&exec_ctx); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -309,8 +322,9 @@ static void test_blocked_until_scheduled_reclaim(void) { ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -326,9 +340,9 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -336,16 +350,18 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); + &exec_ctx, usr1, false, + make_reclaimer(usr1, 1024, set_event(&reclaim_done))); + grpc_exec_ctx_finish(&exec_ctx); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -353,8 +369,9 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr2, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr2, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -370,9 +387,9 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -380,16 +397,18 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); + &exec_ctx, usr, true, + make_reclaimer(usr, 1024, set_event(&reclaim_done))); + grpc_exec_ctx_finish(&exec_ctx); } { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -397,8 +416,9 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -415,12 +435,13 @@ static void test_unused_reclaim_is_cancelled(void) { gpr_event destructive_done; gpr_event_init(&destructive_done); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_unused_reclaimer(set_event(&benign_done))); + &exec_ctx, usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( - usr, true, make_unused_reclaimer(set_event(&destructive_done))); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, usr, true, + make_unused_reclaimer(set_event(&destructive_done))); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -449,20 +470,22 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - usr, true, make_unused_reclaimer(set_event(&destructive_done))); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, usr, true, + make_unused_reclaimer(set_event(&destructive_done))); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -473,9 +496,9 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -485,8 +508,9 @@ static void test_benign_reclaim_is_preferred(void) { nullptr); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -509,20 +533,22 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - usr, true, make_reclaimer(usr, 512, set_event(&destructive_done))); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, usr, true, + make_reclaimer(usr, 512, set_event(&destructive_done))); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -533,9 +559,9 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&ev)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -545,8 +571,9 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -564,17 +591,20 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_quota_unref(q); - grpc_resource_user_unref(usr); + grpc_resource_user_unref(&exec_ctx, usr); + grpc_exec_ctx_finish(&exec_ctx); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -594,10 +624,11 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event reclaimer_cancelled; gpr_event_init(&reclaimer_cancelled); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, usr, false, + make_unused_reclaimer(set_event(&reclaimer_cancelled))); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -605,27 +636,27 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(gpr_event_wait(&allocated, - grpc_timeout_seconds_to_deadline(5)) != NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( + 5)) != nullptr); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_unref(usr); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_unref(&exec_ctx, usr); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_seconds_to_deadline(5)) != nullptr); @@ -643,9 +674,9 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != nullptr); } @@ -653,10 +684,11 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event reclaimer_done; gpr_event_init(&reclaimer_done); { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, usr, false, + make_reclaimer(usr, 1024, set_event(&reclaimer_done))); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -664,19 +696,20 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(gpr_event_wait(&allocated, - grpc_timeout_seconds_to_deadline(5)) != NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( + 5)) != nullptr); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); } } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_free(usr, 1024); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_free(&exec_ctx, usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -699,15 +732,16 @@ static void test_one_slice(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); + grpc_exec_ctx_finish(&exec_ctx); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_destroy_internal(&buffer); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -731,21 +765,23 @@ static void test_one_slice_deleted_late(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); + grpc_exec_ctx_finish(&exec_ctx); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_unref(usr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_unref(&exec_ctx, usr); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_destroy_internal(&buffer); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -773,9 +809,9 @@ static void test_negative_rq_free_pool(void) { { const int start_allocs = num_allocs; - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); + grpc_exec_ctx_finish(&exec_ctx); assert_counter_becomes(&num_allocs, start_allocs + 1); } @@ -786,14 +822,16 @@ static void test_negative_rq_free_pool(void) { GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps); { - grpc_core::ExecCtx exec_ctx; - grpc_resource_user_unref(usr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resource_user_unref(&exec_ctx, usr); + grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_destroy_internal(&buffer); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 40a050ed9f..9fb1a2d770 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -53,24 +53,26 @@ static grpc_millis test_deadline(void) { static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); - + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(&exec_ctx, g_pollset, nullptr))); + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_unlock(g_mu); } -static void must_succeed(void* arg, grpc_error* error) { +static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { GPR_ASSERT(g_connecting != nullptr); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "must_succeed called")); - grpc_endpoint_destroy(g_connecting); + grpc_endpoint_shutdown( + exec_ctx, g_connecting, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); + grpc_endpoint_destroy(exec_ctx, g_connecting); g_connecting = nullptr; finish_connection(); } -static void must_fail(void* arg, grpc_error* error) { +static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == nullptr); GPR_ASSERT(error != GRPC_ERROR_NONE); finish_connection(); @@ -83,7 +85,7 @@ void test_succeeds(void) { int r; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -106,8 +108,8 @@ void test_succeeds(void) { GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, + nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); /* await the connection */ do { @@ -123,15 +125,17 @@ void test_succeeds(void) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(g_pollset, &worker, + grpc_pollset_work(&exec_ctx, g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); + + grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -139,7 +143,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_fails"); @@ -153,8 +157,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, + nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -162,7 +166,7 @@ void test_fails(void) { while (g_connections_complete == connections_complete_before) { grpc_pollset_worker* worker = nullptr; grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&polling_deadline)) { + switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -170,43 +174,42 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, polling_deadline))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); + grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - - { - grpc_core::ExecCtx exec_ctx; - g_pollset_set = grpc_pollset_set_create(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_pollset_set_add_pollset(g_pollset_set, g_pollset); - - test_succeeds(); - gpr_log(GPR_ERROR, "End of first test"); - test_fails(); - grpc_pollset_set_destroy(g_pollset_set); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - } - + g_pollset_set = grpc_pollset_set_create(); + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset); + grpc_exec_ctx_finish(&exec_ctx); + test_succeeds(); + gpr_log(GPR_ERROR, "End of first test"); + test_fails(); + grpc_pollset_set_destroy(&exec_ctx, g_pollset_set); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index 0c6250ed7f..101d7bf6b5 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -46,28 +46,30 @@ static grpc_millis test_deadline(void) { return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); } -static void finish_connection() { +static void finish_connection(grpc_exec_ctx* exec_ctx) { gpr_mu_lock(g_mu); g_connections_complete++; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, g_pollset, NULL))); gpr_mu_unlock(g_mu); } -static void must_succeed(void* arg, grpc_error* error) { +static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { GPR_ASSERT(g_connecting != NULL); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "must_succeed called")); - grpc_endpoint_destroy(g_connecting); + grpc_endpoint_shutdown( + exec_ctx, g_connecting, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); + grpc_endpoint_destroy(exec_ctx, g_connecting); g_connecting = NULL; - finish_connection(); + finish_connection(exec_ctx); } -static void must_fail(void* arg, grpc_error* error) { +static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == NULL); GPR_ASSERT(error != GRPC_ERROR_NONE); - finish_connection(); + finish_connection(exec_ctx); } static void close_cb(uv_handle_t* handle) { gpr_free(handle); } @@ -87,7 +89,7 @@ void test_succeeds(void) { uv_tcp_t* svr_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -108,8 +110,8 @@ void test_succeeds(void) { GPR_ASSERT(uv_tcp_getsockname(svr_handle, (struct sockaddr*)addr, (int*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, - GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -117,11 +119,11 @@ void test_succeeds(void) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(g_pollset, &worker, + grpc_pollset_work(&exec_ctx, g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } @@ -129,6 +131,8 @@ void test_succeeds(void) { uv_close((uv_handle_t*)svr_handle, close_cb); gpr_mu_unlock(g_mu); + + grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -136,7 +140,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_fails"); @@ -150,8 +154,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, - GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -160,7 +164,7 @@ void test_fails(void) { grpc_pollset_worker* worker = NULL; gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&polling_deadline)) { + switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -168,37 +172,39 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(g_pollset, &worker, polling_deadline))); + "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, + polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); + grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); - + grpc_exec_ctx_finish(&exec_ctx); test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index f4acba8302..7986dc2b19 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -131,7 +131,8 @@ static size_t count_slices(grpc_slice* slices, size_t nslices, return num_bytes; } -static void read_cb(void* user_data, grpc_error* error) { +static void read_cb(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* error) { struct read_socket_state* state = (struct read_socket_state*)user_data; size_t read_bytes; int current_data; @@ -146,11 +147,11 @@ static void read_cb(void* user_data, grpc_error* error) { gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { - GPR_ASSERT( - GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } else { - grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb); + grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); gpr_mu_unlock(g_mu); } } @@ -163,7 +164,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, num_bytes, slice_size); @@ -174,8 +175,9 @@ static void read_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); - grpc_endpoint_add_to_pollset(ep, g_pollset); + ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, + "test"); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -186,22 +188,24 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&state.incoming); - grpc_endpoint_destroy(ep); + grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); + grpc_endpoint_destroy(&exec_ctx, ep); + grpc_exec_ctx_finish(&exec_ctx); } /* Write to a socket until it fills up, then read from it using the grpc_tcp @@ -213,7 +217,7 @@ static void large_read_test(size_t slice_size) { ssize_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -224,8 +228,9 @@ static void large_read_test(size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), &args, "test"); - grpc_endpoint_add_to_pollset(ep, g_pollset); + ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "large_read_test"), + &args, "test"); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -236,22 +241,24 @@ static void large_read_test(size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&state.incoming); - grpc_endpoint_destroy(ep); + grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); + grpc_endpoint_destroy(&exec_ctx, ep); + grpc_exec_ctx_finish(&exec_ctx); } struct write_socket_state { @@ -282,15 +289,16 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, return slices; } -static void write_done(void* user_data /* write_socket_state */, +static void write_done(grpc_exec_ctx* exec_ctx, + void* user_data /* write_socket_state */, grpc_error* error) { struct write_socket_state* state = (struct write_socket_state*)user_data; gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); state->write_done = 1; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -301,7 +309,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { int flags; int current = 0; int i; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -311,11 +319,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { gpr_mu_lock(g_mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(g_pollset, &worker, + grpc_pollset_work(&exec_ctx, g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(10))))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); do { bytes_read = read(fd, buf, bytes_left > read_size ? read_size : bytes_left); @@ -348,7 +356,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_closure write_done_closure; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, @@ -360,8 +368,9 @@ static void write_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), &args, "test"); - grpc_endpoint_add_to_pollset(ep, g_pollset); + ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "write_test"), &args, + "test"); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); state.ep = ep; state.write_done = 0; @@ -373,7 +382,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { GRPC_CLOSURE_INIT(&write_done_closure, write_done, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_write(ep, &outgoing, &write_done_closure); + grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); drain_socket_blocking(sv[0], num_bytes, num_bytes); gpr_mu_lock(g_mu); for (;;) { @@ -382,23 +391,25 @@ static void write_test(size_t num_bytes, size_t slice_size) { break; } GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&outgoing); - grpc_endpoint_destroy(ep); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); + grpc_endpoint_destroy(&exec_ctx, ep); gpr_free(slices); + grpc_exec_ctx_finish(&exec_ctx); } -void on_fd_released(void* arg, grpc_error* errors) { +void on_fd_released(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* errors) { int* done = (int*)arg; *done = 1; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); } /* Do a read_test, then release fd and try to read/write again. Verify that @@ -411,7 +422,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure fd_released_cb; int fd_released_done = 0; GRPC_CLOSURE_INIT(&fd_released_cb, &on_fd_released, &fd_released_done, @@ -428,9 +439,10 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); + ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, + "test"); GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0); - grpc_endpoint_add_to_pollset(ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -441,35 +453,38 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR, state.read_bytes, state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&state.incoming); - grpc_tcp_destroy_and_release_fd(ep, &fd, &fd_released_cb); - grpc_core::ExecCtx::Get()->Flush(); + grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); + grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done); } gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); + grpc_exec_ctx_finish(&exec_ctx); written_bytes = fill_socket_partial(sv[0], num_bytes); drain_socket_blocking(fd, written_bytes, written_bytes); @@ -507,7 +522,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( size_t slice_size) { int sv[2]; grpc_endpoint_test_fixture f; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; create_sockets(sv); grpc_resource_quota* resource_quota = @@ -517,13 +532,15 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - f.client_ep = - grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), &args, "test"); - f.server_ep = - grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), &args, "test"); - grpc_resource_quota_unref_internal(resource_quota); - grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); + f.client_ep = grpc_tcp_create( + &exec_ctx, grpc_fd_create(sv[0], "fixture:client"), &args, "test"); + f.server_ep = grpc_tcp_create( + &exec_ctx, grpc_fd_create(sv[1], "fixture:server"), &args, "test"); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); + + grpc_exec_ctx_finish(&exec_ctx); return f; } @@ -532,26 +549,24 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - run_tests(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - - grpc_core::ExecCtx::Get()->Flush(); - } + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + run_tests(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 3c9ca2109e..48d8d425a5 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -110,7 +110,8 @@ static void on_connect_result_set(on_connect_result* result, result->server, acceptor->port_index, acceptor->fd_index); } -static void server_weak_ref_shutdown(void* arg, grpc_error* error) { +static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { server_weak_ref* weak_ref = static_cast(arg); weak_ref->server = nullptr; } @@ -144,11 +145,12 @@ static void test_addr_init_str(test_addr* addr) { } } -static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, +static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, + grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(tcp, + grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(tcp); + grpc_endpoint_destroy(exec_ctx, tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -157,33 +159,38 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); - grpc_tcp_server_unref(s); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(s); + grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -194,15 +201,17 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port_and_start(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port = -1; @@ -213,12 +222,13 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } -static grpc_error* tcp_connect(const test_addr* remote, +static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, on_connect_result* result) { grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); @@ -244,17 +254,17 @@ static grpc_error* tcp_connect(const test_addr* remote, } gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && - deadline > grpc_core::ExecCtx::Get()->Now()) { + deadline > grpc_exec_ctx_now(exec_ctx)) { grpc_pollset_worker* worker = nullptr; grpc_error* err; - if ((err = grpc_pollset_work(g_pollset, &worker, deadline)) != + if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)) != GRPC_ERROR_NONE) { gpr_mu_unlock(g_mu); close(clifd); return err; } gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(exec_ctx); gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -269,7 +279,7 @@ static grpc_error* tcp_connect(const test_addr* remote, gpr_mu_unlock(g_mu); gpr_log(GPR_INFO, "Result (%d, %d) fd %d", result->port_index, result->fd_index, result->server_fd); - grpc_tcp_server_unref(result->server); + grpc_tcp_server_unref(exec_ctx, result->server); return GRPC_ERROR_NONE; } @@ -282,7 +292,7 @@ static grpc_error* tcp_connect(const test_addr* remote, static void test_connect(size_t num_connects, const grpc_channel_args* channel_args, test_addrs* dst_addrs, bool test_dst_addrs) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = @@ -297,7 +307,7 @@ static void test_connect(size_t num_connects, grpc_tcp_server* s; const unsigned num_ports = 2; GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(nullptr, channel_args, &s)); + grpc_tcp_server_create(&exec_ctx, nullptr, channel_args, &s)); unsigned port_num; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -342,7 +352,7 @@ static void test_connect(size_t num_connects, svr1_fd_count = grpc_tcp_server_port_fd_count(s, 1); GPR_ASSERT(svr1_fd_count >= 1); - grpc_tcp_server_start(s, &g_pollset, 1, on_connect, nullptr); + grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, nullptr); if (dst_addrs != nullptr) { int ports[] = {svr_port, svr1_port}; @@ -362,7 +372,7 @@ static void test_connect(size_t num_connects, test_addr_init_str(&dst); ++num_tested; on_connect_result_init(&result); - if ((err = tcp_connect(&dst, &result)) == GRPC_ERROR_NONE && + if ((err = tcp_connect(&exec_ctx, &dst, &result)) == GRPC_ERROR_NONE && result.server_fd >= 0 && result.server == s) { continue; } @@ -393,8 +403,8 @@ static void test_connect(size_t num_connects, for (connect_num = 0; connect_num < num_connects; ++connect_num) { on_connect_result result; on_connect_result_init(&result); - GPR_ASSERT( - GRPC_LOG_IF_ERROR("tcp_connect", tcp_connect(&dst, &result))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("tcp_connect", + tcp_connect(&exec_ctx, &dst, &result))); GPR_ASSERT(result.server_fd == fd); GPR_ASSERT(result.port_index == port_num); GPR_ASSERT(result.fd_index == fd_num); @@ -410,19 +420,21 @@ static void test_connect(size_t num_connects, GPR_ASSERT(weak_ref.server != nullptr); GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 0) >= 0); - grpc_tcp_server_unref(s); - grpc_core::ExecCtx::Get()->Flush(); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == nullptr); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_arg chan_args[1]; chan_args[0].type = GRPC_ARG_INTEGER; chan_args[0].key = const_cast(GRPC_ARG_EXPAND_WILDCARD_ADDRS); @@ -435,61 +447,58 @@ int main(int argc, char** argv) { static_cast(gpr_zalloc(sizeof(*dst_addrs))); grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_start(); - - if (getifaddrs(&ifa) != 0 || ifa == nullptr) { - gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); - return EXIT_FAILURE; - } - dst_addrs->naddrs = 0; - for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; - ifa_it = ifa_it->ifa_next) { - if (ifa_it->ifa_addr == nullptr) { - continue; - } else if (ifa_it->ifa_addr->sa_family == AF_INET) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = - sizeof(struct sockaddr_in); - } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = - sizeof(struct sockaddr_in6); - } else { - continue; - } - memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, - dst_addrs->addrs[dst_addrs->naddrs].addr.len); - GPR_ASSERT( - grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); - test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); - ++dst_addrs->naddrs; - } - freeifaddrs(ifa); - ifa = nullptr; - - /* Connect to same addresses as listeners. */ - test_connect(1, nullptr, nullptr, false); - test_connect(10, nullptr, nullptr, false); + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); - /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a - "::" listener. */ - test_connect(1, nullptr, dst_addrs, true); + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_start(); - /* Test connect(2) with dst_addrs. */ - test_connect(1, &channel_args, dst_addrs, false); - /* Test connect(2) with dst_addrs. */ - test_connect(10, &channel_args, dst_addrs, false); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); + if (getifaddrs(&ifa) != 0 || ifa == nullptr) { + gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); + return EXIT_FAILURE; + } + dst_addrs->naddrs = 0; + for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; + ifa_it = ifa_it->ifa_next) { + if (ifa_it->ifa_addr == nullptr) { + continue; + } else if (ifa_it->ifa_addr->sa_family == AF_INET) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = sizeof(struct sockaddr_in); + } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = + sizeof(struct sockaddr_in6); + } else { + continue; + } + memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, + dst_addrs->addrs[dst_addrs->naddrs].addr.len); + GPR_ASSERT( + grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); + test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); + ++dst_addrs->naddrs; } + freeifaddrs(ifa); + ifa = nullptr; + + /* Connect to same addresses as listeners. */ + test_connect(1, nullptr, nullptr, false); + test_connect(10, nullptr, nullptr, false); + + /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a + "::" listener. */ + test_connect(1, nullptr, dst_addrs, true); + + /* Test connect(2) with dst_addrs. */ + test_connect(1, &channel_args, dst_addrs, false); + /* Test connect(2) with dst_addrs. */ + test_connect(10, &channel_args, dst_addrs, false); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(dst_addrs); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index 35d62b51b7..dd047a0498 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -74,7 +74,8 @@ static void on_connect_result_set(on_connect_result* result, result->fd_index = acceptor->fd_index; } -static void server_weak_ref_shutdown(void* arg, grpc_error* error) { +static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { server_weak_ref* weak_ref = static_cast(arg); weak_ref->server = NULL; } @@ -96,11 +97,12 @@ static void server_weak_ref_set(server_weak_ref* weak_ref, weak_ref->server = server; } -static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, +static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, + grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(tcp, + grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(tcp); + grpc_endpoint_destroy(exec_ctx, tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -109,33 +111,38 @@ static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, g_pollset, NULL))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); - grpc_tcp_server_unref(s); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(s); + grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -146,15 +153,17 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port_and_start(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port; @@ -165,9 +174,10 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); + grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); } static void connect_cb(uv_connect_t* req, int status) { @@ -177,8 +187,8 @@ static void connect_cb(uv_connect_t* req, int status) { static void close_cb(uv_handle_t* handle) { gpr_free(handle); } -static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, - on_connect_result* result) { +static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, + socklen_t remote_len, on_connect_result* result) { gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10); uv_tcp_t* client_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); @@ -198,10 +208,10 @@ static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(g_pollset, &worker, + grpc_pollset_work(exec_ctx, g_pollset, &worker, grpc_timespec_to_millis_round_up(deadline)))); gpr_mu_unlock(g_mu); - + grpc_exec_ctx_finish(exec_ctx); gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -214,7 +224,7 @@ static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, /* Tests a tcp server with multiple ports. */ static void test_connect(unsigned n) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -223,7 +233,8 @@ static void test_connect(unsigned n) { int svr_port; int svr1_port; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); unsigned i; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -246,45 +257,48 @@ static void test_connect(unsigned n) { GRPC_ERROR_NONE && svr_port == svr1_port); - grpc_tcp_server_start(s, &g_pollset, 1, on_connect, NULL); + grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, NULL); GPR_ASSERT(uv_ip6_addr("::", svr_port, (struct sockaddr_in6*)addr1) == 0); for (i = 0; i < n; i++) { on_connect_result result; on_connect_result_init(&result); - tcp_connect((struct sockaddr*)addr, (socklen_t)resolved_addr.len, &result); + tcp_connect(&exec_ctx, (struct sockaddr*)addr, (socklen_t)resolved_addr.len, + &result); GPR_ASSERT(result.port_index == 0); GPR_ASSERT(result.server == s); if (weak_ref.server == NULL) { server_weak_ref_set(&weak_ref, result.server); } - grpc_tcp_server_unref(result.server); + grpc_tcp_server_unref(&exec_ctx, result.server); on_connect_result_init(&result); - tcp_connect((struct sockaddr*)addr1, (socklen_t)resolved_addr1.len, - &result); + tcp_connect(&exec_ctx, (struct sockaddr*)addr1, + (socklen_t)resolved_addr1.len, &result); GPR_ASSERT(result.port_index == 1); GPR_ASSERT(result.server == s); - grpc_tcp_server_unref(result.server); + grpc_tcp_server_unref(&exec_ctx, result.server); } /* Weak ref to server valid until final unref. */ GPR_ASSERT(weak_ref.server != NULL); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + grpc_exec_ctx_finish(&exec_ctx); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); @@ -299,8 +313,8 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index deb8c4d87e..d74ea4fc96 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -25,7 +25,6 @@ #include -#include #include #include "src/core/lib/debug/trace.h" #include "test/core/util/test_config.h" @@ -38,125 +37,127 @@ extern grpc_core::TraceFlag grpc_timer_check_trace; static int cb_called[MAX_CB][2]; -static void cb(void* arg, grpc_error* error) { +static void cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { cb_called[(intptr_t)arg][error == GRPC_ERROR_NONE]++; } static void add_test(void) { int i; grpc_timer timers[20]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "add_test"); - grpc_timer_list_init(); + grpc_timer_list_init(&exec_ctx); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); - grpc_millis start = grpc_core::ExecCtx::Get()->Now(); + grpc_millis start = grpc_exec_ctx_now(&exec_ctx); /* 10 ms timers. will expire in the current epoch */ for (i = 0; i < 10; i++) { grpc_timer_init( - &timers[i], start + 10, + &exec_ctx, &timers[i], start + 10, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* 1010 ms timers. will expire in the next epoch */ for (i = 10; i < 20; i++) { grpc_timer_init( - &timers[i], start + 1010, + &exec_ctx, &timers[i], start + 1010, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* collect timers. Only the first batch should be ready. */ - grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 500); - GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); - grpc_core::ExecCtx::Get()->Flush(); + exec_ctx.now = start + 500; + GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); + grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 600); - GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); - grpc_core::ExecCtx::Get()->Flush(); + exec_ctx.now = start + 600; + GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == + GRPC_TIMERS_CHECKED_AND_EMPTY); + grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the timers */ - grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1500); - GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); - grpc_core::ExecCtx::Get()->Flush(); + exec_ctx.now = start + 1500; + GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); + grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1600); - GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); + exec_ctx.now = start + 1600; + GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == + GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - grpc_timer_list_shutdown(); + grpc_timer_list_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); } /* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "destruction_test"); - grpc_core::ExecCtx::Get()->TestOnlySetNow(0); - grpc_timer_list_init(); + exec_ctx.now_is_valid = true; + exec_ctx.now = 0; + grpc_timer_list_init(&exec_ctx); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( - &timers[0], 100, + &exec_ctx, &timers[0], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)0, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &timers[1], 3, + &exec_ctx, &timers[1], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)1, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &timers[2], 100, + &exec_ctx, &timers[2], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)2, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &timers[3], 3, + &exec_ctx, &timers[3], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)3, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &timers[4], 1, + &exec_ctx, &timers[4], 1, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)4, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->TestOnlySetNow(2); - GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); - grpc_core::ExecCtx::Get()->Flush(); + exec_ctx.now = 2; + GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[4][1]); - grpc_timer_cancel(&timers[0]); - grpc_timer_cancel(&timers[3]); - grpc_core::ExecCtx::Get()->Flush(); + grpc_timer_cancel(&exec_ctx, &timers[0]); + grpc_timer_cancel(&exec_ctx, &timers[3]); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); - grpc_timer_list_shutdown(); - grpc_core::ExecCtx::Get()->Flush(); + grpc_timer_list_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_core::ExecCtx::GlobalInit(); gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); add_test(); destruction_test(); - grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 0deb534abd..6e17be9cd6 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -50,7 +50,7 @@ static int g_number_of_writes = 0; static int g_number_of_bytes_read = 0; static int g_number_of_orphan_calls = 0; -static bool on_read(grpc_fd* emfd, void* user_data) { +static bool on_read(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data) { char read_buffer[512]; ssize_t byte_count; @@ -61,27 +61,27 @@ static bool on_read(grpc_fd* emfd, void* user_data) { g_number_of_reads++; g_number_of_bytes_read += (int)byte_count; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); return false; } -static void on_write(grpc_fd* emfd, void* user_data, +static void on_write(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data, grpc_closure* notify_on_write_closure) { gpr_mu_lock(g_mu); g_number_of_writes++; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void on_fd_orphaned(grpc_fd* emfd, grpc_closure* closure, - void* user_data) { +static void on_fd_orphaned(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, + grpc_closure* closure, void* user_data) { gpr_log(GPR_INFO, "gRPC FD about to be orphaned: %d", grpc_fd_wrapped_fd(emfd)); - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); g_number_of_orphan_calls++; } @@ -130,22 +130,24 @@ static test_socket_factory* test_socket_factory_create(void) { } static void test_no_op(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_udp_server* s = grpc_udp_server_create(nullptr); - grpc_udp_server_destroy(s, nullptr); + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_start(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_start"); - grpc_udp_server_start(s, nullptr, 0, nullptr); - grpc_udp_server_destroy(s, nullptr); + grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -157,7 +159,8 @@ static void test_no_op_with_port(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_destroy(s, nullptr); + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); @@ -165,7 +168,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; @@ -175,7 +178,7 @@ static void test_no_op_with_port_and_socket_factory(void) { grpc_channel_args* channel_args = grpc_channel_args_copy_and_add(nullptr, &socket_factory_arg, 1); grpc_udp_server* s = grpc_udp_server_create(channel_args); - grpc_channel_args_destroy(channel_args); + grpc_channel_args_destroy(&exec_ctx, channel_args); LOG_TEST("test_no_op_with_port_and_socket_factory"); @@ -187,8 +190,8 @@ static void test_no_op_with_port_and_socket_factory(void) { GPR_ASSERT(socket_factory->number_of_socket_calls == 1); GPR_ASSERT(socket_factory->number_of_bind_calls == 1); - grpc_udp_server_destroy(s, nullptr); - + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); grpc_socket_factory_unref(&socket_factory->base); /* The server had a single FD, which should have been orphaned. */ @@ -197,7 +200,7 @@ static void test_no_op_with_port_and_socket_factory(void) { static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -209,9 +212,10 @@ static void test_no_op_with_port_and_start(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_start(s, nullptr, 0, nullptr); + grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); - grpc_udp_server_destroy(s, nullptr); + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ @@ -219,7 +223,7 @@ static void test_no_op_with_port_and_start(void) { } static void test_receive(int number_of_clients) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int clifd, svrfd; @@ -246,7 +250,7 @@ static void test_receive(int number_of_clients) { GPR_ASSERT(resolved_addr.len <= sizeof(struct sockaddr_storage)); pollsets[0] = g_pollset; - grpc_udp_server_start(s, pollsets, 1, nullptr); + grpc_udp_server_start(&exec_ctx, s, pollsets, 1, nullptr); gpr_mu_lock(g_mu); @@ -262,12 +266,13 @@ static void test_receive(int number_of_clients) { (socklen_t)resolved_addr.len) == 0); GPR_ASSERT(5 == write(clifd, "hello", 5)); while (g_number_of_bytes_read < (number_of_bytes_read_before + 5) && - deadline > grpc_core::ExecCtx::Get()->Now()) { + deadline > grpc_exec_ctx_now(&exec_ctx)) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + "pollset_work", + grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); } close(clifd); @@ -276,40 +281,40 @@ static void test_receive(int number_of_clients) { gpr_mu_unlock(g_mu); - grpc_udp_server_destroy(s, nullptr); + grpc_udp_server_destroy(&exec_ctx, s, nullptr); + grpc_exec_ctx_finish(&exec_ctx); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ GPR_ASSERT(g_number_of_orphan_calls == 1); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast(p)); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_socket_factory(); - test_no_op_with_port_and_start(); - test_receive(1); - test_receive(10); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(g_pollset); - } + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_socket_factory(); + test_no_op_with_port_and_start(); + test_receive(1); + test_receive(10); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); + gpr_free(g_pollset); grpc_shutdown(); return 0; } diff --git a/test/core/nanopb/fuzzer_response.cc b/test/core/nanopb/fuzzer_response.cc index 3a70dea5e9..7039c801cb 100644 --- a/test/core/nanopb/fuzzer_response.cc +++ b/test/core/nanopb/fuzzer_response.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -30,7 +29,6 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_initial_response* response; @@ -38,6 +36,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_initial_response_destroy(response); } grpc_slice_unref(slice); - grpc_shutdown(); return 0; } diff --git a/test/core/nanopb/fuzzer_serverlist.cc b/test/core/nanopb/fuzzer_serverlist.cc index d0af117ef9..0a6b1767a1 100644 --- a/test/core/nanopb/fuzzer_serverlist.cc +++ b/test/core/nanopb/fuzzer_serverlist.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -30,7 +29,6 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_serverlist* serverlist; @@ -38,6 +36,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_destroy_serverlist(serverlist); } grpc_slice_unref(slice); - grpc_shutdown(); return 0; } diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index ecc61928f5..64d383ad0a 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -148,37 +148,41 @@ static grpc_httpcli_response http_response(int status, const char* body) { /* -- Tests. -- */ static void test_empty_md_array(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); GPR_ASSERT(md_array.md == nullptr); GPR_ASSERT(md_array.size == 0); - grpc_credentials_mdelem_array_destroy(&md_array); + grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); + grpc_exec_ctx_finish(&exec_ctx); } static void test_add_to_empty_md_array(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = grpc_mdelem_from_slices( - grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); + grpc_mdelem md = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); grpc_credentials_mdelem_array_add(&md_array, md); GPR_ASSERT(md_array.size == 1); GPR_ASSERT(grpc_mdelem_eq(md, md_array.md[0])); - GRPC_MDELEM_UNREF(md); - grpc_credentials_mdelem_array_destroy(&md_array); + GRPC_MDELEM_UNREF(&exec_ctx, md); + grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); + grpc_exec_ctx_finish(&exec_ctx); } static void test_add_abunch_to_md_array(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = grpc_mdelem_from_slices( - grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); + grpc_mdelem md = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); size_t num_entries = 1000; for (size_t i = 0; i < num_entries; ++i) { grpc_credentials_mdelem_array_add(&md_array, md); @@ -186,52 +190,57 @@ static void test_add_abunch_to_md_array(void) { for (size_t i = 0; i < num_entries; ++i) { GPR_ASSERT(grpc_mdelem_eq(md_array.md[i], md)); } - GRPC_MDELEM_UNREF(md); - grpc_credentials_mdelem_array_destroy(&md_array); + GRPC_MDELEM_UNREF(&exec_ctx, md); + grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_OK); + &exec_ctx, &response, &token_md, &token_lifetime) == + GRPC_CREDENTIALS_OK); GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md), "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); - GRPC_MDELEM_UNREF(token_md); + GRPC_MDELEM_UNREF(&exec_ctx, token_md); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(401, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, ""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -240,13 +249,14 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, @@ -254,13 +264,14 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -269,14 +280,15 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { " \"expires_in\":3599, " "}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -284,9 +296,10 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( "{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\"," " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &response, &token_md, &token_lifetime) == + &exec_ctx, &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -323,7 +336,8 @@ static void check_metadata(const expected_md* expected, } } -static void check_request_metadata(void* arg, grpc_error* error) { +static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { request_metadata_state* state = (request_metadata_state*)arg; gpr_log(GPR_INFO, "expected_error: %s", grpc_error_string(state->expected_error)); @@ -344,8 +358,9 @@ static void check_request_metadata(void* arg, grpc_error* error) { state->expected_size, state->md_array.size); GPR_ASSERT(state->md_array.size == state->expected_size); check_metadata(state->expected, &state->md_array); - grpc_credentials_mdelem_array_destroy(&state->md_array); - grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&state->pollent)); + grpc_credentials_mdelem_array_destroy(exec_ctx, &state->md_array); + grpc_pollset_set_destroy(exec_ctx, + grpc_polling_entity_pollset_set(&state->pollent)); gpr_free(state); } @@ -364,21 +379,22 @@ static request_metadata_state* make_request_metadata_state( return state; } -static void run_request_metadata_test(grpc_call_credentials* creds, +static void run_request_metadata_test(grpc_exec_ctx* exec_ctx, + grpc_call_credentials* creds, grpc_auth_metadata_context auth_md_ctx, request_metadata_state* state) { grpc_error* error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - creds, &state->pollent, auth_md_ctx, &state->md_array, + exec_ctx, creds, &state->pollent, auth_md_ctx, &state->md_array, &state->on_request_metadata, &error)) { // Synchronous result. Invoke the callback directly. - check_request_metadata(state, error); + check_request_metadata(exec_ctx, state, error); GRPC_ERROR_UNREF(error); } } static void test_google_iam_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -390,12 +406,13 @@ static void test_google_iam_creds(void) { nullptr); grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_call_credentials_unref(creds); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_call_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } static void test_access_token_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); @@ -404,14 +421,16 @@ static void test_access_token_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_call_credentials_unref(creds); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_call_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } static grpc_security_status check_channel_oauth2_create_security_connector( - grpc_channel_credentials* c, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); @@ -419,7 +438,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector( } static void test_channel_oauth2_composite_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_create_security_connector, nullptr}; @@ -433,13 +452,14 @@ static void test_channel_oauth2_composite_creds(void) { grpc_channel_credentials_release(channel_creds); grpc_call_credentials_release(oauth2_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - channel_oauth2_creds, nullptr, nullptr, nullptr, &new_args) == - GRPC_SECURITY_OK); + &exec_ctx, channel_oauth2_creds, nullptr, nullptr, nullptr, + &new_args) == GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_creds); + grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_google_iam_composite_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -451,15 +471,15 @@ static void test_oauth2_google_iam_composite_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - "authorization", test_oauth2_bearer_token, 0); + &exec_ctx, "authorization", test_oauth2_bearer_token, 0); grpc_call_credentials* google_iam_creds = grpc_google_iam_credentials_create( test_google_iam_authorization_token, test_google_iam_authority_selector, nullptr); grpc_call_credentials* composite_creds = grpc_composite_call_credentials_create(oauth2_creds, google_iam_creds, nullptr); - grpc_call_credentials_unref(oauth2_creds); - grpc_call_credentials_unref(google_iam_creds); + grpc_call_credentials_unref(&exec_ctx, oauth2_creds); + grpc_call_credentials_unref(&exec_ctx, google_iam_creds); GPR_ASSERT( strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); const grpc_call_credentials_array* creds_array = @@ -469,15 +489,17 @@ static void test_oauth2_google_iam_composite_creds(void) { GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); - run_request_metadata_test(composite_creds, auth_md_ctx, state); - grpc_call_credentials_unref(composite_creds); + run_request_metadata_test(&exec_ctx, composite_creds, auth_md_ctx, state); + grpc_call_credentials_unref(&exec_ctx, composite_creds); + grpc_exec_ctx_finish(&exec_ctx); } static grpc_security_status check_channel_oauth2_google_iam_create_security_connector( - grpc_channel_credentials* c, grpc_call_credentials* call_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, + grpc_call_credentials* call_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { const grpc_call_credentials_array* creds_array; GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); @@ -492,7 +514,7 @@ check_channel_oauth2_google_iam_create_security_connector( } static void test_channel_oauth2_google_iam_composite_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_google_iam_create_security_connector, @@ -516,10 +538,11 @@ static void test_channel_oauth2_google_iam_composite_creds(void) { grpc_call_credentials_release(google_iam_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - channel_oauth2_iam_creds, nullptr, nullptr, nullptr, + &exec_ctx, channel_oauth2_iam_creds, nullptr, nullptr, nullptr, &new_args) == GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_iam_creds); + grpc_exec_ctx_finish(&exec_ctx); } static void validate_compute_engine_http_request( @@ -536,32 +559,35 @@ static void validate_compute_engine_http_request( } static int compute_engine_httpcli_get_success_override( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static int compute_engine_httpcli_get_failure_override( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static int httpcli_post_should_not_be_called( - const grpc_httpcli_request* request, const char* body_bytes, - size_t body_size, grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + const char* body_bytes, size_t body_size, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } -static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -570,7 +596,7 @@ static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, } static void test_compute_engine_creds_success(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_call_credentials* creds = @@ -583,23 +609,24 @@ static void test_compute_engine_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); - grpc_call_credentials_unref(creds); + grpc_call_credentials_unref(&exec_ctx, creds); grpc_httpcli_set_override(nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_compute_engine_creds_failure(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -610,9 +637,10 @@ static void test_compute_engine_creds_failure(void) { grpc_google_compute_engine_credentials_create(nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override, httpcli_post_should_not_be_called); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_call_credentials_unref(creds); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_call_credentials_unref(&exec_ctx, creds); grpc_httpcli_set_override(nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void validate_refresh_token_http_request( @@ -639,27 +667,27 @@ static void validate_refresh_token_http_request( } static int refresh_token_httpcli_post_success( - const grpc_httpcli_request* request, const char* body, size_t body_size, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + const char* body, size_t body_size, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static int refresh_token_httpcli_post_failure( - const grpc_httpcli_request* request, const char* body, size_t body_size, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + const char* body, size_t body_size, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static void test_refresh_token_creds_success(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, @@ -672,23 +700,24 @@ static void test_refresh_token_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); - grpc_call_credentials_unref(creds); + grpc_call_credentials_unref(&exec_ctx, creds); grpc_httpcli_set_override(nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_refresh_token_creds_failure(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -699,9 +728,10 @@ static void test_refresh_token_creds_failure(void) { test_refresh_token_str, nullptr); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_failure); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_call_credentials_unref(creds); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_call_credentials_unref(&exec_ctx, creds); grpc_httpcli_set_override(nullptr, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void validate_jwt_encode_and_sign_params( @@ -791,7 +821,7 @@ static void test_jwt_creds_lifetime(void) { static void test_jwt_creds_success(void) { char* json_key_string = test_json_key_str(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_md_value; @@ -805,16 +835,16 @@ static void test_jwt_creds_success(void) { request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ @@ -822,18 +852,19 @@ static void test_jwt_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); auth_md_ctx.service_url = other_test_service_url; grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); - grpc_call_credentials_unref(creds); + grpc_call_credentials_unref(&exec_ctx, creds); gpr_free(json_key_string); gpr_free(expected_md_value); grpc_jwt_encode_and_sign_set_override(nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_jwt_creds_signing_failure(void) { char* json_key_string = test_json_key_str(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* state = make_request_metadata_state( @@ -844,11 +875,12 @@ static void test_jwt_creds_signing_failure(void) { json_key_string, grpc_max_auth_token_lifetime(), nullptr); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); - run_request_metadata_test(creds, auth_md_ctx, state); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); gpr_free(json_key_string); - grpc_call_credentials_unref(creds); + grpc_call_credentials_unref(&exec_ctx, creds); grpc_jwt_encode_and_sign_set_override(nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void set_google_default_creds_env_var_with_file_contents( @@ -865,7 +897,7 @@ static void set_google_default_creds_env_var_with_file_contents( } static void test_google_default_creds_auth_key(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_service_account_jwt_access_credentials* jwt; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); @@ -881,12 +913,13 @@ static void test_google_default_creds_auth_key(void) { strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&creds->base); + grpc_channel_credentials_unref(&exec_ctx, &creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + grpc_exec_ctx_finish(&exec_ctx); } static void test_google_default_creds_refresh_token(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_google_refresh_token_credentials* refresh; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); @@ -898,13 +931,15 @@ static void test_google_default_creds_refresh_token(void) { refresh = (grpc_google_refresh_token_credentials*)creds->call_creds; GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&creds->base); + grpc_channel_credentials_unref(&exec_ctx, &creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_success_override( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { *response = http_response(200, ""); grpc_http_header* headers = static_cast(gpr_malloc(sizeof(*headers) * 1)); @@ -914,14 +949,14 @@ static int default_creds_gce_detection_httpcli_get_success_override( response->hdrs = headers; GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static char* null_well_known_creds_path_getter(void) { return nullptr; } static void test_google_default_creds_gce(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; request_metadata_state* state = @@ -946,8 +981,8 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(creds->call_creds != nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(creds->call_creds, auth_md_ctx, state); - grpc_core::ExecCtx::Get()->Flush(); + run_request_metadata_test(&exec_ctx, creds->call_creds, auth_md_ctx, state); + grpc_exec_ctx_flush(&exec_ctx); /* Check that we get a cached creds if we call grpc_google_default_credentials_create again. @@ -959,20 +994,22 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(cached_creds == &creds->base); /* Cleanup. */ - grpc_channel_credentials_unref(cached_creds); - grpc_channel_credentials_unref(&creds->base); + grpc_channel_credentials_unref(&exec_ctx, cached_creds); + grpc_channel_credentials_unref(&exec_ctx, &creds->base); grpc_httpcli_set_override(nullptr, nullptr); grpc_override_well_known_credentials_path_getter(nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_failure_override( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { /* No magic header. */ GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); *response = http_response(200, ""); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } @@ -1056,7 +1093,7 @@ static void plugin_destroy(void* state) { static void test_metadata_plugin_success(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* md_state = make_request_metadata_state( @@ -1069,17 +1106,17 @@ static void test_metadata_plugin_success(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(creds, auth_md_ctx, md_state); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(creds); - + grpc_call_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } static void test_metadata_plugin_failure(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_error; @@ -1097,10 +1134,10 @@ static void test_metadata_plugin_failure(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(creds, auth_md_ctx, md_state); + run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(creds); - + grpc_call_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } @@ -1121,7 +1158,7 @@ static void test_get_well_known_google_credentials_file_path(void) { } static void test_channel_creds_duplicate_without_call_creds(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_credentials* channel_creds = grpc_fake_transport_security_credentials_create(); @@ -1130,21 +1167,23 @@ static void test_channel_creds_duplicate_without_call_creds(void) { grpc_channel_credentials_duplicate_without_call_credentials( channel_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(dup); + grpc_channel_credentials_unref(&exec_ctx, dup); grpc_call_credentials* call_creds = grpc_access_token_credentials_create("blah", nullptr); grpc_channel_credentials* composite_creds = grpc_composite_channel_credentials_create(channel_creds, call_creds, nullptr); - grpc_call_credentials_unref(call_creds); + grpc_call_credentials_unref(&exec_ctx, call_creds); dup = grpc_channel_credentials_duplicate_without_call_credentials( composite_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(dup); + grpc_channel_credentials_unref(&exec_ctx, dup); + + grpc_channel_credentials_unref(&exec_ctx, channel_creds); + grpc_channel_credentials_unref(&exec_ctx, composite_creds); - grpc_channel_credentials_unref(channel_creds); - grpc_channel_credentials_unref(composite_creds); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index aac9cc0029..0b6ccd5e37 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -207,7 +207,7 @@ static void test_parse_json_key_failure_no_private_key(void) { static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, char** scratchpad) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; char* b64; char* decoded; grpc_json* json; @@ -215,7 +215,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, b64 = static_cast(gpr_malloc(len + 1)); strncpy(b64, str, len); b64[len] = '\0'; - slice = grpc_base64_decode(b64, 1); + slice = grpc_base64_decode(&exec_ctx, b64, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice)); decoded = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); strncpy(decoded, (const char*)GRPC_SLICE_START_PTR(slice), @@ -225,7 +225,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_free(b64); *scratchpad = decoded; grpc_slice_unref(slice); - + grpc_exec_ctx_finish(&exec_ctx); return json; } @@ -327,12 +327,12 @@ static void check_jwt_claim(grpc_json* claim, const char* expected_audience, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, const char* signed_data, size_t signed_data_size) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); EVP_PKEY* key = EVP_PKEY_new(); - grpc_slice sig = grpc_base64_decode(b64_signature, 1); + grpc_slice sig = grpc_base64_decode(&exec_ctx, b64_signature, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); GPR_ASSERT(GRPC_SLICE_LENGTH(sig) == 128); @@ -347,9 +347,11 @@ static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, GPR_ASSERT(EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(sig), GRPC_SLICE_LENGTH(sig)) == 1); - grpc_slice_unref_internal(sig); + grpc_slice_unref_internal(&exec_ctx, sig); if (key != nullptr) EVP_PKEY_free(key); if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); + + grpc_exec_ctx_finish(&exec_ctx); } static char* service_account_creds_jwt_encode_and_sign( @@ -483,7 +485,6 @@ static void test_parse_refresh_token_failure_no_refresh_token(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_parse_json_key_success(); test_parse_json_key_failure_bad_json(); test_parse_json_key_failure_no_type(); @@ -498,6 +499,5 @@ int main(int argc, char** argv) { test_parse_refresh_token_failure_no_client_id(); test_parse_refresh_token_failure_no_client_secret(); test_parse_refresh_token_failure_no_refresh_token(); - grpc_shutdown(); return 0; } diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index e219260b1d..df0ebe5607 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -209,8 +209,8 @@ static void test_claims_success(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx exec_ctx; - claims = grpc_jwt_claims_from_json(json, s); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -219,7 +219,8 @@ static void test_claims_success(void) { GPR_ASSERT(strcmp(grpc_jwt_claims_id(claims), "jwtuniqueid") == 0); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_OK); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(&exec_ctx, claims); + grpc_exec_ctx_finish(&exec_ctx); } static void test_expired_claims_failure(void) { @@ -231,8 +232,8 @@ static void test_expired_claims_failure(void) { gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx exec_ctx; - claims = grpc_jwt_claims_from_json(json, s); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -245,15 +246,17 @@ static void test_expired_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(&exec_ctx, claims); + grpc_exec_ctx_finish(&exec_ctx); } static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(grpc_jwt_claims_from_json(&exec_ctx, json, s) == nullptr); + grpc_exec_ctx_finish(&exec_ctx); } static void test_bad_audience_claims_failure(void) { @@ -262,12 +265,13 @@ static void test_bad_audience_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx exec_ctx; - claims = grpc_jwt_claims_from_json(json, s); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == GRPC_JWT_VERIFIER_BAD_AUDIENCE); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(&exec_ctx, claims); + grpc_exec_ctx_finish(&exec_ctx); } static void test_bad_subject_claims_failure(void) { @@ -276,12 +280,13 @@ static void test_bad_subject_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_core::ExecCtx exec_ctx; - claims = grpc_jwt_claims_from_json(json, s); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_BAD_SUBJECT); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(&exec_ctx, claims); + grpc_exec_ctx_finish(&exec_ctx); } static char* json_key_str(const char* last_part) { @@ -318,16 +323,17 @@ static grpc_httpcli_response http_response(int status, char* body) { } static int httpcli_post_should_not_be_called( - const grpc_httpcli_request* request, const char* body_bytes, - size_t body_size, grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + const char* body_bytes, size_t body_size, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } static int httpcli_get_google_keys_for_email( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { *response = http_response(200, good_google_email_keys()); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); @@ -335,22 +341,22 @@ static int httpcli_get_google_keys_for_email( "/robot/v1/metadata/x509/" "777-abaslkan11hlb6nmim3bpspl31ud@developer." "gserviceaccount.com") == 0); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } -static void on_verification_success(void* user_data, +static void on_verification_success(grpc_exec_ctx* exec_ctx, void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_OK); GPR_ASSERT(claims != nullptr); GPR_ASSERT(user_data == (void*)expected_user_data); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), expected_audience) == 0); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(exec_ctx, claims); } static void test_jwt_verifier_google_email_issuer_success(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -363,27 +369,28 @@ static void test_jwt_verifier_google_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static int httpcli_get_custom_keys_for_email( - const grpc_httpcli_request* request, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "keys.bar.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/jwk/foo@bar.com") == 0); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_custom_email_issuer_success(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -396,26 +403,28 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_jwk_set(const grpc_httpcli_request* request, +static int httpcli_get_jwk_set(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/oauth2/v3/certs") == 0); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } -static int httpcli_get_openid_config(const grpc_httpcli_request* request, +static int httpcli_get_openid_config(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -425,12 +434,12 @@ static int httpcli_get_openid_config(const grpc_httpcli_request* request, GPR_ASSERT(strcmp(request->http.path, GRPC_OPENID_CONFIG_URL_SUFFIX) == 0); grpc_httpcli_set_override(httpcli_get_jwk_set, httpcli_post_should_not_be_called); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_success(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -443,15 +452,16 @@ static void test_jwt_verifier_url_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static void on_verification_key_retrieval_error(void* user_data, +static void on_verification_key_retrieval_error(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR); @@ -459,17 +469,18 @@ static void on_verification_key_retrieval_error(void* user_data, GPR_ASSERT(user_data == (void*)expected_user_data); } -static int httpcli_get_bad_json(const grpc_httpcli_request* request, +static int httpcli_get_bad_json(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}")); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); - GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_bad_config(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -482,17 +493,17 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static void test_jwt_verifier_bad_json_key(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -505,11 +516,11 @@ static void test_jwt_verifier_bad_json_key(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } @@ -521,8 +532,9 @@ static void corrupt_jwt_sig(char* jwt) { char* last_dot = strrchr(jwt, '.'); GPR_ASSERT(last_dot != nullptr); { - grpc_core::ExecCtx exec_ctx; - sig = grpc_base64_decode(last_dot + 1, 1); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + sig = grpc_base64_decode(&exec_ctx, last_dot + 1, 1); + grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); sig_bytes = GRPC_SLICE_START_PTR(sig); @@ -534,7 +546,8 @@ static void corrupt_jwt_sig(char* jwt) { grpc_slice_unref(sig); } -static void on_verification_bad_signature(void* user_data, +static void on_verification_bad_signature(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_SIGNATURE); @@ -543,7 +556,7 @@ static void on_verification_bad_signature(void* user_data, } static void test_jwt_verifier_bad_signature(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -557,16 +570,17 @@ static void test_jwt_verifier_bad_signature(void) { grpc_auth_json_key_destruct(&key); corrupt_jwt_sig(jwt); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, on_verification_bad_signature, (void*)expected_user_data); gpr_free(jwt); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, + const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -574,7 +588,7 @@ static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, return 1; } -static void on_verification_bad_format(void* user_data, +static void on_verification_bad_format(grpc_exec_ctx* exec_ctx, void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_FORMAT); @@ -583,15 +597,15 @@ static void on_verification_bad_format(void* user_data, } static void test_jwt_verifier_bad_format(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_jwt_verifier_verify(verifier, nullptr, "bad jwt", expected_audience, - on_verification_bad_format, + grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, "bad jwt", + expected_audience, on_verification_bad_format, (void*)expected_user_data); - grpc_jwt_verifier_destroy(verifier); - grpc_core::ExecCtx::Get()->Flush(); + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); grpc_httpcli_set_override(nullptr, nullptr); } diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 0d3a1279af..602041eecc 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -39,7 +39,8 @@ typedef struct { grpc_closure closure; } oauth2_request; -static void on_oauth2_response(void* arg, grpc_error* error) { +static void on_oauth2_response(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { oauth2_request* request = (oauth2_request*)arg; char* token = nullptr; grpc_slice token_slice; @@ -53,23 +54,25 @@ static void on_oauth2_response(void* arg, grpc_error* error) { GRPC_SLICE_LENGTH(token_slice)); token[GRPC_SLICE_LENGTH(token_slice)] = '\0'; } - grpc_credentials_mdelem_array_destroy(&request->md_array); + grpc_credentials_mdelem_array_destroy(exec_ctx, &request->md_array); gpr_mu_lock(request->mu); request->is_done = true; request->token = token; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&request->pops), nullptr)); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&request->pops), + nullptr)); gpr_mu_unlock(request->mu); } -static void do_nothing(void* unused, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* unused, + grpc_error* error) {} char* grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials* creds) { oauth2_request request; memset(&request, 0, sizeof(request)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; @@ -85,30 +88,31 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_schedule_on_exec_ctx); grpc_error* error = GRPC_ERROR_NONE; - if (grpc_call_credentials_get_request_metadata(creds, &request.pops, null_ctx, - &request.md_array, - &request.closure, &error)) { + if (grpc_call_credentials_get_request_metadata( + &exec_ctx, creds, &request.pops, null_ctx, &request.md_array, + &request.closure, &error)) { // Synchronous result; invoke callback directly. - on_oauth2_response(&request, error); + on_oauth2_response(&exec_ctx, &request, error); GRPC_ERROR_UNREF(error); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(request.mu); while (!request.is_done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(grpc_polling_entity_pollset(&request.pops), + grpc_pollset_work(&exec_ctx, + grpc_polling_entity_pollset(&request.pops), &worker, GRPC_MILLIS_INF_FUTURE))) { request.is_done = true; } } gpr_mu_unlock(request.mu); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&request.pops), + grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&request.pops), &do_nothing_closure); - + grpc_exec_ctx_finish(&exec_ctx); gpr_free(grpc_polling_entity_pollset(&request.pops)); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index b3742f58a8..f4acf023bd 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -41,7 +41,8 @@ typedef struct { grpc_closure on_request_metadata; } synchronizer; -static void on_metadata_response(void* arg, grpc_error* error) { +static void on_metadata_response(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { synchronizer* sync = static_cast(arg); if (error != GRPC_ERROR_NONE) { fprintf(stderr, "Fetching token failed: %s\n", grpc_error_string(error)); @@ -56,13 +57,14 @@ static void on_metadata_response(void* arg, grpc_error* error) { sync->is_done = true; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&sync->pops), nullptr)); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&sync->pops), + nullptr)); gpr_mu_unlock(sync->mu); } int main(int argc, char** argv) { int result = 0; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; synchronizer sync; grpc_channel_credentials* creds = nullptr; const char* service_url = "https://test.foo.google.com/Foo"; @@ -95,10 +97,11 @@ int main(int argc, char** argv) { error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - ((grpc_composite_channel_credentials*)creds)->call_creds, &sync.pops, - context, &sync.md_array, &sync.on_request_metadata, &error)) { + &exec_ctx, ((grpc_composite_channel_credentials*)creds)->call_creds, + &sync.pops, context, &sync.md_array, &sync.on_request_metadata, + &error)) { // Synchronous response. Invoke callback directly. - on_metadata_response(&sync, error); + on_metadata_response(&exec_ctx, &sync, error); GRPC_ERROR_UNREF(error); } @@ -107,15 +110,18 @@ int main(int argc, char** argv) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(grpc_polling_entity_pollset(&sync.pops), &worker, + grpc_pollset_work(&exec_ctx, + grpc_polling_entity_pollset(&sync.pops), &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); + grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_credentials_release(creds); gpr_free(grpc_polling_entity_pollset(&sync.pops)); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index 38c78fed42..a12af02479 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -38,7 +38,7 @@ static grpc_pollset* g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, grpc_slice* leftover_slices, size_t leftover_nslices, bool use_zero_copy_protector) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; tsi_frame_protector* fake_read_protector = tsi_create_fake_frame_protector(nullptr); tsi_frame_protector* fake_write_protector = @@ -60,8 +60,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; tcp = grpc_iomgr_create_endpoint_pair("fixture", &args); - grpc_endpoint_add_to_pollset(tcp.client, g_pollset); - grpc_endpoint_add_to_pollset(tcp.server, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset); if (leftover_nslices == 0) { f.client_ep = grpc_secure_endpoint_create(fake_read_protector, @@ -117,7 +117,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( f.server_ep = grpc_secure_endpoint_create(fake_write_protector, fake_write_zero_copy_protector, tcp.server, nullptr, 0); - + grpc_exec_ctx_finish(&exec_ctx); return f; } @@ -165,62 +165,65 @@ static grpc_endpoint_test_config configs[] = { clean_up}, }; -static void inc_call_ctr(void* arg, grpc_error* error) { ++*(int*)arg; } +static void inc_call_ctr(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + ++*(int*)arg; +} static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_endpoint_test_fixture f = config.create_fixture(slice_size); grpc_slice_buffer incoming; grpc_slice s = grpc_slice_from_copied_string("hello world 12345678900987654321"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; int n = 0; grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); grpc_slice_buffer_init(&incoming); GRPC_CLOSURE_INIT(&done_closure, inc_call_ctr, &n, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(f.client_ep, &incoming, &done_closure); - - grpc_core::ExecCtx::Get()->Flush(); + grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, &done_closure); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); grpc_endpoint_shutdown( - f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + &exec_ctx, f.client_ep, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); grpc_endpoint_shutdown( - f.server_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); - grpc_endpoint_destroy(f.client_ep); - grpc_endpoint_destroy(f.server_ep); - - grpc_slice_unref_internal(s); - grpc_slice_buffer_destroy_internal(&incoming); + &exec_ctx, f.server_ep, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + grpc_endpoint_destroy(&exec_ctx, f.client_ep); + grpc_endpoint_destroy(&exec_ctx, f.server_ep); + grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(&exec_ctx, s); + grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); clean_up(); } -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy((grpc_pollset*)p); +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); - grpc_init(); - - { - grpc_core::ExecCtx exec_ctx; - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - grpc_endpoint_tests(configs[1], g_pollset, g_mu); - test_leftover(configs[2], 1); - test_leftover(configs[3], 1); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - } + grpc_init(); + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + grpc_endpoint_tests(configs[1], g_pollset, g_mu); + test_leftover(configs[2], 1); + test_leftover(configs[3], 1); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index 6e30698562..d83ebb18d2 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -40,7 +40,8 @@ struct handshake_state { bool done_callback_called; }; -static void on_handshake_done(void* arg, grpc_error* error) { +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_handshaker_args* args = static_cast(arg); struct handshake_state* state = static_cast(args->user_data); @@ -55,70 +56,67 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("ssl_server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(resource_quota); - - grpc_mock_endpoint_put_read( - mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); - - // Load key pair and establish server SSL credentials. - grpc_ssl_pem_key_cert_pair pem_key_cert_pair; - grpc_slice ca_slice, cert_slice, key_slice; - ca_slice = grpc_slice_from_static_string(test_root_cert); - cert_slice = grpc_slice_from_static_string(test_server1_cert); - key_slice = grpc_slice_from_static_string(test_server1_key); - const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = - (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = - (const char*)GRPC_SLICE_START_PTR(cert_slice); - grpc_server_credentials* creds = grpc_ssl_server_credentials_create( - ca_cert, &pem_key_cert_pair, 1, 0, nullptr); - - // Create security connector - grpc_server_security_connector* sc = nullptr; - grpc_security_status status = - grpc_server_credentials_create_security_connector(creds, &sc); - GPR_ASSERT(status == GRPC_SECURITY_OK); - grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(); - - struct handshake_state state; - state.done_callback_called = false; - grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); - grpc_server_security_connector_add_handshakers(sc, handshake_mgr); - grpc_handshake_manager_do_handshake( - handshake_mgr, nullptr /* interested_parties */, mock_endpoint, - nullptr /* channel_args */, deadline, nullptr /* acceptor */, - on_handshake_done, &state); - grpc_core::ExecCtx::Get()->Flush(); - - // If the given string happens to be part of the correct client hello, the - // server will wait for more data. Explicitly fail the server by shutting - // down the endpoint. - if (!state.done_callback_called) { - grpc_endpoint_shutdown( - mock_endpoint, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); - grpc_core::ExecCtx::Get()->Flush(); - } - - GPR_ASSERT(state.done_callback_called); - - grpc_handshake_manager_destroy(handshake_mgr); - GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test"); - grpc_server_credentials_release(creds); - grpc_slice_unref(cert_slice); - grpc_slice_unref(key_slice); - grpc_slice_unref(ca_slice); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("ssl_server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + + grpc_mock_endpoint_put_read( + &exec_ctx, mock_endpoint, + grpc_slice_from_copied_buffer((const char*)data, size)); + + // Load key pair and establish server SSL credentials. + grpc_ssl_pem_key_cert_pair pem_key_cert_pair; + grpc_slice ca_slice, cert_slice, key_slice; + ca_slice = grpc_slice_from_static_string(test_root_cert); + cert_slice = grpc_slice_from_static_string(test_server1_cert); + key_slice = grpc_slice_from_static_string(test_server1_key); + const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); + grpc_server_credentials* creds = grpc_ssl_server_credentials_create( + ca_cert, &pem_key_cert_pair, 1, 0, nullptr); + + // Create security connector + grpc_server_security_connector* sc = nullptr; + grpc_security_status status = + grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); + GPR_ASSERT(status == GRPC_SECURITY_OK); + grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(&exec_ctx); + + struct handshake_state state; + state.done_callback_called = false; + grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); + grpc_server_security_connector_add_handshakers(&exec_ctx, sc, handshake_mgr); + grpc_handshake_manager_do_handshake( + &exec_ctx, handshake_mgr, nullptr /* interested_parties */, mock_endpoint, + nullptr /* channel_args */, deadline, nullptr /* acceptor */, + on_handshake_done, &state); + grpc_exec_ctx_flush(&exec_ctx); + + // If the given string happens to be part of the correct client hello, the + // server will wait for more data. Explicitly fail the server by shutting down + // the endpoint. + if (!state.done_callback_called) { + grpc_endpoint_shutdown( + &exec_ctx, mock_endpoint, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); + grpc_exec_ctx_flush(&exec_ctx); } + GPR_ASSERT(state.done_callback_called); + + grpc_handshake_manager_destroy(&exec_ctx, handshake_mgr); + GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "test"); + grpc_server_credentials_release(creds); + grpc_slice_unref(cert_slice); + grpc_slice_unref(key_slice); + grpc_slice_unref(ca_slice); + grpc_exec_ctx_flush(&exec_ctx); + grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index e039970c67..787d58bc37 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -44,7 +44,7 @@ static void print_usage_and_exit(gpr_cmdline* cl, const char* argv0) { exit(1); } -static void on_jwt_verification_done(void* user_data, +static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { synchronizer* sync = static_cast(user_data); @@ -57,7 +57,7 @@ static void on_jwt_verification_done(void* user_data, grpc_json_dump_to_string((grpc_json*)grpc_jwt_claims_json(claims), 2); printf("Claims: \n\n%s\n", claims_str); gpr_free(claims_str); - grpc_jwt_claims_destroy(claims); + grpc_jwt_claims_destroy(exec_ctx, claims); } else { GPR_ASSERT(claims == nullptr); fprintf(stderr, "Verification failed with error %s\n", @@ -66,7 +66,8 @@ static void on_jwt_verification_done(void* user_data, gpr_mu_lock(sync->mu); sync->is_done = 1; - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(sync->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, sync->pollset, nullptr)); gpr_mu_unlock(sync->mu); } @@ -76,7 +77,7 @@ int main(int argc, char** argv) { gpr_cmdline* cl; const char* jwt = nullptr; const char* aud = nullptr; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_init(); cl = gpr_cmdline_create("JWT verifier tool"); @@ -95,26 +96,26 @@ int main(int argc, char** argv) { grpc_pollset_init(sync.pollset, &sync.mu); sync.is_done = 0; - grpc_jwt_verifier_verify(verifier, sync.pollset, jwt, aud, + grpc_jwt_verifier_verify(&exec_ctx, verifier, sync.pollset, jwt, aud, on_jwt_verification_done, &sync); gpr_mu_lock(sync.mu); while (!sync.is_done) { grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(sync.pollset, &worker, GRPC_MILLIS_INF_FUTURE))) + if (!GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(&exec_ctx, sync.pollset, &worker, + GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); gpr_free(sync.pollset); - grpc_jwt_verifier_destroy(verifier); - + grpc_jwt_verifier_destroy(&exec_ctx, verifier); + grpc_exec_ctx_finish(&exec_ctx); gpr_cmdline_destroy(cl); grpc_shutdown(); return !sync.success; diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 94785fd1e2..479198f9f9 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -20,7 +20,6 @@ #include -#include #include #include #include @@ -45,14 +44,14 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char* hello = "hello"; char* hello_b64 = grpc_base64_encode(hello, strlen(hello), url_safe, multiline); - grpc_core::ExecCtx exec_ctx; - grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice hello_slice = grpc_base64_decode(&exec_ctx, hello_b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello)); GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello, GRPC_SLICE_LENGTH(hello_slice)) == 0); - grpc_slice_unref_internal(hello_slice); - + grpc_slice_unref_internal(&exec_ctx, hello_slice); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(hello_b64); } @@ -65,14 +64,15 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { /* Try all the different paddings. */ for (i = 0; i < 3; i++) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline); - orig_decoded = grpc_base64_decode(b64, url_safe); + orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i)); GPR_ASSERT(buffers_are_equal(orig, GRPC_SLICE_START_PTR(orig_decoded), sizeof(orig) - i)); - grpc_slice_unref_internal(orig_decoded); + grpc_slice_unref_internal(&exec_ctx, orig_decoded); gpr_free(b64); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -116,18 +116,19 @@ static void test_url_safe_unsafe_mismatch_failure(void) { int url_safe = 1; for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); - orig_decoded = grpc_base64_decode(b64, !url_safe); + orig_decoded = grpc_base64_decode(&exec_ctx, b64, !url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(orig_decoded); + grpc_slice_unref_internal(&exec_ctx, orig_decoded); b64 = grpc_base64_encode(orig, sizeof(orig), !url_safe, 0); - orig_decoded = grpc_base64_decode(b64, url_safe); + orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(orig_decoded); + grpc_slice_unref_internal(&exec_ctx, orig_decoded); + grpc_exec_ctx_finish(&exec_ctx); } static void test_rfc4648_test_vectors(void) { @@ -165,44 +166,44 @@ static void test_rfc4648_test_vectors(void) { static void test_unpadded_decode(void) { grpc_slice decoded; - grpc_core::ExecCtx exec_ctx; - decoded = grpc_base64_decode("Zm9vYmFy", 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmFy", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("Zm9vYmE", 0); + decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmE", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fooba") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("Zm9vYg", 0); + decoded = grpc_base64_decode(&exec_ctx, "Zm9vYg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foob") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("Zm9v", 0); + decoded = grpc_base64_decode(&exec_ctx, "Zm9v", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("Zm8", 0); + decoded = grpc_base64_decode(&exec_ctx, "Zm8", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("Zg", 0); + decoded = grpc_base64_decode(&exec_ctx, "Zg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "f") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode("", 0); + decoded = grpc_base64_decode(&exec_ctx, "", 0); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded)); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_simple_encode_decode_b64_no_multiline(); test_simple_encode_decode_b64_multiline(); test_simple_encode_decode_b64_urlsafe_no_multiline(); @@ -214,6 +215,5 @@ int main(int argc, char** argv) { test_url_safe_unsafe_mismatch_failure(); test_rfc4648_test_vectors(); test_unpadded_decode(); - grpc_shutdown(); return 0; } diff --git a/test/core/slice/percent_decode_fuzzer.cc b/test/core/slice/percent_decode_fuzzer.cc index 81eb031014..3603177c47 100644 --- a/test/core/slice/percent_decode_fuzzer.cc +++ b/test/core/slice/percent_decode_fuzzer.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { struct grpc_memory_counters counters; - grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output; @@ -48,7 +46,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(input); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); - grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); return 0; } diff --git a/test/core/slice/percent_encode_fuzzer.cc b/test/core/slice/percent_encode_fuzzer.cc index 201ae2790e..c8e3849fc8 100644 --- a/test/core/slice/percent_encode_fuzzer.cc +++ b/test/core/slice/percent_encode_fuzzer.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -32,7 +31,6 @@ bool leak_check = true; static void test(const uint8_t* data, size_t size, const uint8_t* dict) { struct grpc_memory_counters counters; - grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output = grpc_percent_encode_slice(input, dict); @@ -50,7 +48,6 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) { grpc_slice_unref(permissive_decoded_output); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); - grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); } diff --git a/test/core/slice/percent_encoding_test.cc b/test/core/slice/percent_encoding_test.cc index 11f3995f98..253240faad 100644 --- a/test/core/slice/percent_encoding_test.cc +++ b/test/core/slice/percent_encoding_test.cc @@ -18,7 +18,6 @@ #include "src/core/lib/slice/percent_encoding.h" -#include #include #include @@ -119,7 +118,6 @@ static void test_nonconformant_vector(const char* encoded, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); TEST_VECTOR( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", @@ -142,6 +140,5 @@ int main(int argc, char** argv) { grpc_url_percent_encoding_unreserved_bytes); TEST_NONCONFORMANT_VECTOR("\0", "\0", grpc_url_percent_encoding_unreserved_bytes); - grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_buffer_test.cc b/test/core/slice/slice_buffer_test.cc index e59986730b..338e8079dc 100644 --- a/test/core/slice/slice_buffer_test.cc +++ b/test/core/slice/slice_buffer_test.cc @@ -16,7 +16,6 @@ * */ -#include #include #include #include "test/core/util/test_config.h" @@ -107,11 +106,9 @@ void test_slice_buffer_move_first() { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_slice_buffer_add(); test_slice_buffer_move_first(); - grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index 9fad9a614e..0ee4e8617d 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -59,7 +59,9 @@ static void check_non_existent_value(const char* key_string, grpc_slice_unref(key); } -static void destroy_string(void* value) { gpr_free(value); } +static void destroy_string(grpc_exec_ctx* exec_ctx, void* value) { + gpr_free(value); +} static grpc_slice_hash_table* create_table_from_entries( const test_entry* test_entries, size_t num_test_entries, @@ -119,8 +121,9 @@ static void test_slice_hash_table() { check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); // Clean up. - grpc_core::ExecCtx exec_ctx; - grpc_slice_hash_table_unref(table); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_hash_table_unref(&exec_ctx, table); + grpc_exec_ctx_finish(&exec_ctx); } static int value_cmp_fn(void* a, void* b) { @@ -146,9 +149,10 @@ static void test_slice_hash_table_eq() { create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0); - grpc_core::ExecCtx exec_ctx; - grpc_slice_hash_table_unref(table_a); - grpc_slice_hash_table_unref(table_b); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_hash_table_unref(&exec_ctx, table_a); + grpc_slice_hash_table_unref(&exec_ctx, table_b); + grpc_exec_ctx_finish(&exec_ctx); } static void test_slice_hash_table_not_eq() { @@ -217,24 +221,23 @@ static void test_slice_hash_table_not_eq() { create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0); - grpc_core::ExecCtx exec_ctx; - grpc_slice_hash_table_unref(table_a); - grpc_slice_hash_table_unref(table_b_larger); - grpc_slice_hash_table_unref(table_b_smaller); - grpc_slice_hash_table_unref(table_c); - grpc_slice_hash_table_unref(table_d); - grpc_slice_hash_table_unref(table_e); - grpc_slice_hash_table_unref(table_f); - grpc_slice_hash_table_unref(table_g); - grpc_slice_hash_table_unref(table_h); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_hash_table_unref(&exec_ctx, table_a); + grpc_slice_hash_table_unref(&exec_ctx, table_b_larger); + grpc_slice_hash_table_unref(&exec_ctx, table_b_smaller); + grpc_slice_hash_table_unref(&exec_ctx, table_c); + grpc_slice_hash_table_unref(&exec_ctx, table_d); + grpc_slice_hash_table_unref(&exec_ctx, table_e); + grpc_slice_hash_table_unref(&exec_ctx, table_f); + grpc_slice_hash_table_unref(&exec_ctx, table_g); + grpc_slice_hash_table_unref(&exec_ctx, table_h); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_core::ExecCtx::GlobalInit(); test_slice_hash_table(); test_slice_hash_table_eq(); test_slice_hash_table_not_eq(); - grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/slice/slice_string_helpers_test.cc b/test/core/slice/slice_string_helpers_test.cc index f1d470461a..260f8c80d5 100644 --- a/test/core/slice/slice_string_helpers_test.cc +++ b/test/core/slice/slice_string_helpers_test.cc @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -131,9 +130,7 @@ static void test_strsplit(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_dump_slice(); test_strsplit(); - grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index e40154dd0e..02f6b1ea79 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -292,7 +292,6 @@ static void test_static_slice_copy_interning(void) { int main(int argc, char** argv) { unsigned length; grpc_test_init(argc, argv); - grpc_init(); test_slice_malloc_returns_something_sensible(); test_slice_new_returns_something_sensible(); test_slice_new_with_user_data(); @@ -306,6 +305,5 @@ int main(int argc, char** argv) { test_slice_interning(); test_static_slice_interning(); test_static_slice_copy_interning(); - grpc_shutdown(); return 0; } diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index 94a8615b3c..e5d2d7c78d 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -132,8 +132,10 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, memset(GRPC_SLICE_START_PTR(input_slice), 'a', input_size); grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT( + grpc_msg_compress(&exec_ctx, algorithm, &sliceb_in, &sliceb_out)); + grpc_exec_ctx_finish(&exec_ctx); } buffer = grpc_raw_compressed_byte_buffer_create(sliceb_out.slices, @@ -265,7 +267,6 @@ static void test_byte_buffer_copy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_read_one_slice(); test_read_one_slice_malloc(); test_read_none_compressed_slice(); @@ -275,6 +276,5 @@ int main(int argc, char** argv) { test_byte_buffer_from_reader(); test_byte_buffer_copy(); test_readall(); - grpc_shutdown(); return 0; } diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index 37247f89d0..f358b0fc8d 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -35,10 +35,11 @@ void test_unknown_scheme_target(void) { chan = grpc_insecure_channel_create("blah://blah", nullptr, nullptr); GPR_ASSERT(chan != nullptr); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); + grpc_exec_ctx_finish(&exec_ctx); grpc_channel_destroy(chan); } diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index fefbb3c185..c6e13d2386 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -121,7 +121,8 @@ static void test_wait_empty(void) { } } -static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} +static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, + grpc_cq_completion* c) {} static void test_cq_end_op(void) { grpc_event ev; @@ -130,6 +131,8 @@ static void test_cq_end_op(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; + grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); LOG_TEST("test_cq_end_op"); @@ -137,14 +140,14 @@ static void test_cq_end_op(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx exec_ctx; + exec_ctx = init_exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, - &completion); + grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, + do_nothing_end_completion, nullptr, &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -153,6 +156,7 @@ static void test_cq_end_op(void) { GPR_ASSERT(ev.success); shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -163,6 +167,8 @@ static void test_cq_tls_cache_full(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; + grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); void* res_tag; int ok; @@ -172,15 +178,15 @@ static void test_cq_tls_cache_full(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx exec_ctx; // Reset exec_ctx + exec_ctx = init_exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); grpc_completion_queue_thread_local_cache_init(cc); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, - &completion); + grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, + do_nothing_end_completion, nullptr, &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -196,6 +202,7 @@ static void test_cq_tls_cache_full(void) { GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -204,6 +211,8 @@ static void test_cq_tls_cache_empty(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; + grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx exec_ctx; void* res_tag; int ok; @@ -212,7 +221,7 @@ static void test_cq_tls_cache_empty(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - grpc_core::ExecCtx exec_ctx; // Reset exec_ctx + exec_ctx = init_exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -223,6 +232,7 @@ static void test_cq_tls_cache_empty(void) { GPR_ASSERT( grpc_completion_queue_thread_local_cache_flush(cc, &res_tag, &ok) == 0); shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } } @@ -279,6 +289,8 @@ static void test_pluck(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; + grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx exec_ctx; unsigned i, j; LOG_TEST("test_pluck"); @@ -293,15 +305,15 @@ static void test_pluck(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_PLUCK; for (size_t pidx = 0; pidx < GPR_ARRAY_SIZE(polling_types); pidx++) { - grpc_core::ExecCtx exec_ctx; // reset exec_ctx + exec_ctx = init_exec_ctx; // reset exec_ctx attr.cq_polling_type = polling_types[pidx]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, - nullptr, &completions[i]); + grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, + do_nothing_end_completion, nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -312,8 +324,8 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, - nullptr, &completions[i]); + grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, + do_nothing_end_completion, nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -324,6 +336,7 @@ static void test_pluck(void) { } shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 4a9e818b45..126d363f83 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -59,7 +59,8 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { grpc_completion_queue_destroy(cc); } -static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} +static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, + grpc_cq_completion* c) {} struct thread_state { grpc_completion_queue* cc; @@ -80,7 +81,7 @@ static void test_too_many_plucks(void) { gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; gpr_thd_options thread_options = gpr_thd_options_default(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; unsigned i, j; LOG_TEST("test_too_many_plucks"); @@ -108,8 +109,8 @@ static void test_too_many_plucks(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, - nullptr, &completions[i]); + grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, + do_nothing_end_completion, nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -117,6 +118,7 @@ static void test_too_many_plucks(void) { } shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } #define TEST_THREAD_EVENTS 10000 @@ -136,13 +138,15 @@ gpr_timespec ten_seconds_time(void) { return grpc_timeout_seconds_to_deadline(10); } -static void free_completion(void* arg, grpc_cq_completion* completion) { +static void free_completion(grpc_exec_ctx* exec_ctx, void* arg, + grpc_cq_completion* completion) { gpr_free(completion); } static void producer_thread(void* arg) { test_thread_options* opt = static_cast(arg); int i; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "producer %d started", opt->id); gpr_event_set(&opt->on_started, (void*)(intptr_t)1); @@ -159,16 +163,17 @@ static void producer_thread(void* arg) { gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { - grpc_core::ExecCtx exec_ctx; - grpc_cq_end_op(opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, + grpc_cq_end_op(&exec_ctx, opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, free_completion, nullptr, static_cast( gpr_malloc(sizeof(grpc_cq_completion)))); opt->events_triggered++; + grpc_exec_ctx_finish(&exec_ctx); } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); gpr_event_set(&opt->on_finished, (void*)(intptr_t)1); + grpc_exec_ctx_finish(&exec_ctx); } static void consumer_thread(void* arg) { diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 235d136376..2ff1ca3d79 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -103,28 +103,29 @@ void server_thread(void* vargs) { GPR_ASSERT(detag(ev.tag) == 0xd1e); } -static void on_connect(void* vargs, grpc_endpoint* tcp, +static void on_connect(grpc_exec_ctx* exec_ctx, void* vargs, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_endpoint_shutdown(tcp, + grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(tcp); + grpc_endpoint_destroy(exec_ctx, tcp); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); gpr_mu_unlock(args->mu); } void bad_server_thread(void* vargs) { struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int port; grpc_tcp_server* s; - grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); + grpc_error* error = grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s); GPR_ASSERT(error == GRPC_ERROR_NONE); memset(&resolved_addr, 0, sizeof(resolved_addr)); addr->ss_family = AF_INET; @@ -133,32 +134,35 @@ void bad_server_thread(void* vargs) { GPR_ASSERT(port > 0); gpr_asprintf(&args->addr, "localhost:%d", port); - grpc_tcp_server_start(s, &args->pollset, 1, on_connect, args); + grpc_tcp_server_start(&exec_ctx, s, &args->pollset, 1, on_connect, args); gpr_event_set(&args->ready, (void*)1); gpr_mu_lock(args->mu); while (gpr_atm_acq_load(&args->stop) == 0) { - grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 100; + grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 100; grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(args->pollset, &worker, deadline))) { + grpc_pollset_work(&exec_ctx, args->pollset, &worker, deadline))) { gpr_atm_rel_store(&args->stop, 1); } gpr_mu_unlock(args->mu); - + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(args->mu); } gpr_mu_unlock(args->mu); - grpc_tcp_server_unref(s); + grpc_tcp_server_unref(&exec_ctx, s); + + grpc_exec_ctx_finish(&exec_ctx); gpr_free(args->addr); } -static void done_pollset_shutdown(void* pollset, grpc_error* error) { - grpc_pollset_destroy(static_cast(pollset)); +static void done_pollset_shutdown(grpc_exec_ctx* exec_ctx, void* pollset, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(pollset)); gpr_free(pollset); } @@ -230,12 +234,11 @@ int run_concurrent_connectivity_test() { gpr_atm_rel_store(&args.stop, 1); gpr_thd_join(server); - { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_shutdown( - args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, - grpc_schedule_on_exec_ctx)); - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_pollset_shutdown(&exec_ctx, args.pollset, + GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, + grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 4bf40569e6..f3df7f35a7 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -32,19 +32,20 @@ grpc_closure transport_op_cb; static void* tag(intptr_t x) { return (void*)x; } -void verify_connectivity(void* arg, grpc_error* error) { +void verify_connectivity(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_connectivity_state* state = static_cast(arg); GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *state); GPR_ASSERT(error == GRPC_ERROR_NONE); } -void do_nothing(void* arg, grpc_error* error) {} +void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { grpc_transport_op* op; grpc_channel_element* elem; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, grpc_schedule_on_exec_ctx); @@ -53,12 +54,14 @@ void test_transport_op(grpc_channel* channel) { op->on_connectivity_state_change = &transport_op_cb; op->connectivity_state = &state; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(&exec_ctx, elem, op); + grpc_exec_ctx_finish(&exec_ctx); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); op = grpc_make_transport_op(&transport_op_cb); - elem->filter->start_transport_op(elem, op); + elem->filter->start_transport_op(&exec_ctx, elem, op); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index 9cdd299ae3..f78d333673 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -178,8 +178,9 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index fa22cd6873..c31c61430c 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -37,9 +37,10 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx exec_ctx; - GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); - grpc_channel_credentials_unref(creds); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); + grpc_channel_credentials_unref(&exec_ctx, creds); + grpc_exec_ctx_finish(&exec_ctx); } void test_security_connector_already_in_arg(void) { @@ -55,8 +56,9 @@ void test_security_connector_already_in_arg(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx exec_ctx; - GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); + grpc_exec_ctx_finish(&exec_ctx); } void test_null_creds(void) { @@ -65,8 +67,9 @@ void test_null_creds(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_core::ExecCtx exec_ctx; - GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index ac49bd9823..11d0aa705d 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -156,8 +156,9 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_exec_ctx_finish(&exec_ctx); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index 445823b628..d1272607f2 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -58,7 +58,7 @@ namespace { void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { estimator->AddIncomingBytes(1234567); inc_time(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; estimator->SchedulePing(); estimator->StartPing(); for (size_t i = 0; i < n; i++) { @@ -66,8 +66,9 @@ void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { } gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1, GPR_TIMESPAN))); - grpc_core::ExecCtx::Get()->InvalidateNow(); - estimator->CompletePing(); + grpc_exec_ctx_invalidate_now(&exec_ctx); + estimator->CompletePing(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); } void AddSample(BdpEstimator* estimator, int64_t sample) { diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 2aab6e9262..0e34fd7651 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -18,7 +18,6 @@ #include "src/core/lib/transport/byte_stream.h" -#include #include #include #include @@ -31,13 +30,14 @@ // grpc_slice_buffer_stream tests // -static void not_called_closure(void* arg, grpc_error* error) { +static void not_called_closure(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { GPR_ASSERT(false); } static void test_slice_buffer_stream_basic(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_basic"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -57,21 +57,23 @@ static void test_slice_buffer_stream_basic(void) { grpc_schedule_on_exec_ctx); // Read each slice. Note that next() always returns synchronously. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); } // Clean up. - grpc_byte_stream_destroy(&stream.base); - grpc_slice_buffer_destroy_internal(&buffer); + grpc_byte_stream_destroy(&exec_ctx, &stream.base); + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } static void test_slice_buffer_stream_shutdown(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_shutdown"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -90,25 +92,29 @@ static void test_slice_buffer_stream_shutdown(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read the first slice. - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); // Now shutdown. grpc_error* shutdown_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown error"); - grpc_byte_stream_shutdown(&stream.base, GRPC_ERROR_REF(shutdown_error)); + grpc_byte_stream_shutdown(&exec_ctx, &stream.base, + GRPC_ERROR_REF(shutdown_error)); // After shutdown, the next pull() should return the error. - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&stream.base, &output); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == shutdown_error); GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(shutdown_error); // Clean up. - grpc_byte_stream_destroy(&stream.base); - grpc_slice_buffer_destroy_internal(&buffer); + grpc_byte_stream_destroy(&exec_ctx, &stream.base); + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } // @@ -117,7 +123,7 @@ static void test_slice_buffer_stream_shutdown(void) { static void test_caching_byte_stream_basic(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_basic"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -141,22 +147,24 @@ static void test_caching_byte_stream_basic(void) { // Read each slice. Note that next() always returns synchronously, // because the underlying byte stream always does. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); } // Clean up. - grpc_byte_stream_destroy(&stream.base); - grpc_byte_stream_cache_destroy(&cache); - grpc_slice_buffer_destroy_internal(&buffer); + grpc_byte_stream_destroy(&exec_ctx, &stream.base); + grpc_byte_stream_cache_destroy(&exec_ctx, &cache); + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } static void test_caching_byte_stream_reset(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_reset"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -178,31 +186,34 @@ static void test_caching_byte_stream_reset(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice. - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); // Reset the caching stream. The reads should start over from the // first slice. grpc_caching_byte_stream_reset(&stream); for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&stream.base, &output); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); } // Clean up. - grpc_byte_stream_destroy(&stream.base); - grpc_byte_stream_cache_destroy(&cache); - grpc_slice_buffer_destroy_internal(&buffer); + grpc_byte_stream_destroy(&exec_ctx, &stream.base); + grpc_byte_stream_cache_destroy(&exec_ctx, &cache); + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } static void test_caching_byte_stream_shared_cache(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_shared_cache"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -226,41 +237,43 @@ static void test_caching_byte_stream_shared_cache(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice from stream1. - GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&stream1.base, &output); + grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); // Read all slices from stream2. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT(grpc_byte_stream_next(&stream2.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&stream2.base, &output); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream2.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&exec_ctx, &stream2.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); } // Now read the second slice from stream1. - GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&stream1.base, &output); + GPR_ASSERT( + grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[1], output)); - grpc_slice_unref_internal(output); + grpc_slice_unref_internal(&exec_ctx, output); // Clean up. - grpc_byte_stream_destroy(&stream1.base); - grpc_byte_stream_destroy(&stream2.base); - grpc_byte_stream_cache_destroy(&cache); - grpc_slice_buffer_destroy_internal(&buffer); + grpc_byte_stream_destroy(&exec_ctx, &stream1.base); + grpc_byte_stream_destroy(&exec_ctx, &stream2.base); + grpc_byte_stream_cache_destroy(&exec_ctx, &cache); + grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { - grpc_init(); grpc_test_init(argc, argv); test_slice_buffer_stream_basic(); test_slice_buffer_stream_shutdown(); test_caching_byte_stream_basic(); test_caching_byte_stream_reset(); test_caching_byte_stream_shared_cache(); - grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 6d70a4261b..a29ec8a13f 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -20,7 +20,6 @@ #include -#include #include #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" @@ -30,8 +29,8 @@ static int all_ok = 1; -static void expect_slice_eq(grpc_slice expected, grpc_slice slice, - const char* debug, int line) { +static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected, + grpc_slice slice, const char* debug, int line) { if (!grpc_slice_eq(slice, expected)) { char* hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char* he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -41,97 +40,104 @@ static void expect_slice_eq(grpc_slice expected, grpc_slice slice, gpr_free(he); all_ok = 0; } - grpc_slice_unref_internal(expected); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, expected); + grpc_slice_unref_internal(exec_ctx, slice); } -static grpc_slice base64_encode(const char* s) { +static grpc_slice base64_encode(grpc_exec_ctx* exec_ctx, const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); grpc_slice out = grpc_chttp2_base64_encode(ss); - grpc_slice_unref_internal(ss); + grpc_slice_unref_internal(exec_ctx, ss); return out; } -static grpc_slice base64_decode(const char* s) { +static grpc_slice base64_decode(grpc_exec_ctx* exec_ctx, const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = grpc_chttp2_base64_decode(ss); - grpc_slice_unref_internal(ss); + grpc_slice out = grpc_chttp2_base64_decode(exec_ctx, ss); + grpc_slice_unref_internal(exec_ctx, ss); return out; } -static grpc_slice base64_decode_with_length(const char* s, +static grpc_slice base64_decode_with_length(grpc_exec_ctx* exec_ctx, + const char* s, size_t output_length) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); - grpc_slice_unref_internal(ss); + grpc_slice out = + grpc_chttp2_base64_decode_with_length(exec_ctx, ss, output_length); + grpc_slice_unref_internal(exec_ctx, ss); return out; } -#define EXPECT_SLICE_EQ(expected, slice) \ - expect_slice_eq( \ - grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \ - #slice, __LINE__); +#define EXPECT_SLICE_EQ(exec_ctx, expected, slice) \ + expect_slice_eq( \ + exec_ctx, grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), \ + slice, #slice, __LINE__); -#define ENCODE_AND_DECODE(s) \ - EXPECT_SLICE_EQ( \ - s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); +#define ENCODE_AND_DECODE(exec_ctx, s) \ + EXPECT_SLICE_EQ(exec_ctx, s, \ + grpc_chttp2_base64_decode_with_length( \ + exec_ctx, base64_encode(exec_ctx, s), strlen(s))); int main(int argc, char** argv) { - grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - - /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which - takes encoded base64 strings without pad chars, but output length is - required. */ - /* Base64 test vectors from RFC 4648 */ - ENCODE_AND_DECODE(""); - ENCODE_AND_DECODE("f"); - ENCODE_AND_DECODE("foo"); - ENCODE_AND_DECODE("fo"); - ENCODE_AND_DECODE("foob"); - ENCODE_AND_DECODE("fooba"); - ENCODE_AND_DECODE("foobar"); - - ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); - - /* Base64 test vectors from RFC 4648, with pad chars */ - /* BASE64("") = "" */ - EXPECT_SLICE_EQ("", base64_decode("")); - /* BASE64("f") = "Zg==" */ - EXPECT_SLICE_EQ("f", base64_decode("Zg==")); - /* BASE64("fo") = "Zm8=" */ - EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); - /* BASE64("foo") = "Zm9v" */ - EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); - /* BASE64("foob") = "Zm9vYg==" */ - EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); - /* BASE64("fooba") = "Zm9vYmE=" */ - EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); - /* BASE64("foobar") = "Zm9vYmFy" */ - EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); - - EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); - - // Test illegal input length in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ("", base64_decode("a")); - EXPECT_SLICE_EQ("", base64_decode("ab")); - EXPECT_SLICE_EQ("", base64_decode("abc")); - - // Test illegal charactors in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ("", base64_decode("Zm:v")); - EXPECT_SLICE_EQ("", base64_decode("Zm=v")); - - // Test output_length longer than max possible output length in - // grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); - EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); - EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); - - // Test illegal charactors in grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); - EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); - } - grpc_shutdown(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which + takes encoded base64 strings without pad chars, but output length is + required. */ + /* Base64 test vectors from RFC 4648 */ + ENCODE_AND_DECODE(&exec_ctx, ""); + ENCODE_AND_DECODE(&exec_ctx, "f"); + ENCODE_AND_DECODE(&exec_ctx, "foo"); + ENCODE_AND_DECODE(&exec_ctx, "fo"); + ENCODE_AND_DECODE(&exec_ctx, "foob"); + ENCODE_AND_DECODE(&exec_ctx, "fooba"); + ENCODE_AND_DECODE(&exec_ctx, "foobar"); + + ENCODE_AND_DECODE(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5"); + + /* Base64 test vectors from RFC 4648, with pad chars */ + /* BASE64("") = "" */ + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "")); + /* BASE64("f") = "Zg==" */ + EXPECT_SLICE_EQ(&exec_ctx, "f", base64_decode(&exec_ctx, "Zg==")); + /* BASE64("fo") = "Zm8=" */ + EXPECT_SLICE_EQ(&exec_ctx, "fo", base64_decode(&exec_ctx, "Zm8=")); + /* BASE64("foo") = "Zm9v" */ + EXPECT_SLICE_EQ(&exec_ctx, "foo", base64_decode(&exec_ctx, "Zm9v")); + /* BASE64("foob") = "Zm9vYg==" */ + EXPECT_SLICE_EQ(&exec_ctx, "foob", base64_decode(&exec_ctx, "Zm9vYg==")); + /* BASE64("fooba") = "Zm9vYmE=" */ + EXPECT_SLICE_EQ(&exec_ctx, "fooba", base64_decode(&exec_ctx, "Zm9vYmE=")); + /* BASE64("foobar") = "Zm9vYmFy" */ + EXPECT_SLICE_EQ(&exec_ctx, "foobar", base64_decode(&exec_ctx, "Zm9vYmFy")); + + EXPECT_SLICE_EQ(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5", + base64_decode(&exec_ctx, "wMHCw8TF")); + + // Test illegal input length in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "a")); + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "ab")); + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "abc")); + + // Test illegal charactors in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm:v")); + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm=v")); + + // Test output_length longer than max possible output length in + // grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode_with_length(&exec_ctx, "Zg", 2)); + EXPECT_SLICE_EQ(&exec_ctx, "", + base64_decode_with_length(&exec_ctx, "Zm8", 3)); + EXPECT_SLICE_EQ(&exec_ctx, "", + base64_decode_with_length(&exec_ctx, "Zm9v", 4)); + + // Test illegal charactors in grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ(&exec_ctx, "", + base64_decode_with_length(&exec_ctx, "Zm:v", 3)); + EXPECT_SLICE_EQ(&exec_ctx, "", + base64_decode_with_length(&exec_ctx, "Zm=v", 3)); + + grpc_exec_ctx_finish(&exec_ctx); + return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 44f5de8a50..78b8808c41 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -99,8 +99,6 @@ static void expect_binary_header(const char* hdr, int binary) { } int main(int argc, char** argv) { - grpc_init(); - /* Base64 test vectors from RFC 4648, with padding removed */ /* BASE64("") = "" */ EXPECT_SLICE_EQ("", B64("")); @@ -171,6 +169,5 @@ int main(int argc, char** argv) { expect_binary_header("foo-bar", 0); expect_binary_header("-bin", 0); - grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index d2dbd4a798..2d18b72504 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -51,8 +51,8 @@ typedef struct { /* verify that the output generated by encoding the stream matches the hexstring passed in */ -static void verify(const verify_params params, const char* expected, - size_t nheaders, ...) { +static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, + const char* expected, size_t nheaders, ...) { grpc_slice_buffer output; grpc_slice merged; grpc_slice expect = parse_hexstring(expected); @@ -77,7 +77,8 @@ static void verify(const verify_params params, const char* expected, value_slice = grpc_slice_intern(value_slice); } e[i].md = grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string(key)), value_slice); + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + value_slice); } e[0].prev = nullptr; e[nheaders - 1].next = nullptr; @@ -105,10 +106,11 @@ static void verify(const verify_params params, const char* expected, 16384, /* max_frame_size */ &stats /* stats */ }; - grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); + grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, + &output); merged = grpc_slice_merge(output.slices, output.count); - grpc_slice_buffer_destroy_internal(&output); - grpc_metadata_batch_destroy(&b); + grpc_slice_buffer_destroy_internal(exec_ctx, &output); + grpc_metadata_batch_destroy(exec_ctx, &b); if (!grpc_slice_eq(merged, expect)) { char* expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -121,11 +123,11 @@ static void verify(const verify_params params, const char* expected, g_failure = 1; } - grpc_slice_unref_internal(merged); - grpc_slice_unref_internal(expect); + grpc_slice_unref_internal(exec_ctx, merged); + grpc_slice_unref_internal(exec_ctx, expect); } -static void test_basic_headers() { +static void test_basic_headers(grpc_exec_ctx* exec_ctx) { int i; verify_params params = { @@ -133,22 +135,24 @@ static void test_basic_headers() { false, false, }; - verify(params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); - verify(params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", "c"); - verify(params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); - verify(params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); + verify(exec_ctx, params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); + verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(exec_ctx, params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", + "b", "c"); + verify(exec_ctx, params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); + verify(exec_ctx, params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); /* flush out what's there to make a few values look very popular */ for (i = 0; i < 350; i++) { - verify(params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", "c", "a", - "d"); + verify(exec_ctx, params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", + "c", "a", "d"); } - verify(params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", "k", "v"); + verify(exec_ctx, params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", + "k", "v"); /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify(params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); + verify(exec_ctx, params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); } static void encode_int_to_str(int i, char* p) { @@ -159,7 +163,7 @@ static void encode_int_to_str(int i, char* p) { p[2] = 0; } -static void test_decode_table_overflow() { +static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) { int i; char key[3], value[3]; char* expect; @@ -188,24 +192,26 @@ static void test_decode_table_overflow() { } if (i > 0) { - verify(params, expect, 2, "aa", "ba", key, value); + verify(exec_ctx, params, expect, 2, "aa", "ba", key, value); } else { - verify(params, expect, 1, key, value); + verify(exec_ctx, params, expect, 1, key, value); } gpr_free(expect); } /* if the above passes, then we must have just knocked this pair out of the decoder stack, and so we'll be forced to re-encode it */ - verify(params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", "ba"); + verify(exec_ctx, params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", + "ba"); } -static void verify_table_size_change_match_elem_size(const char* key, +static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx, + const char* key, const char* value, bool use_true_binary) { grpc_slice_buffer output; grpc_mdelem elem = grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string(key)), + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, use_true_binary); size_t initial_table_size = g_compressor.table_size; @@ -229,38 +235,41 @@ static void verify_table_size_change_match_elem_size(const char* key, use_true_binary, /* use_true_binary_metadata */ 16384, /* max_frame_size */ &stats /* stats */}; - grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); - grpc_slice_buffer_destroy_internal(&output); - grpc_metadata_batch_destroy(&b); + grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, + &output); + grpc_slice_buffer_destroy_internal(exec_ctx, &output); + grpc_metadata_batch_destroy(exec_ctx, &b); GPR_ASSERT(g_compressor.table_size == elem_size + initial_table_size); gpr_free(e); } -static void test_encode_header_size() { - verify_table_size_change_match_elem_size("hello", "world", false); - verify_table_size_change_match_elem_size("hello-bin", "world", false); - verify_table_size_change_match_elem_size("true-binary-bin", +static void test_encode_header_size(grpc_exec_ctx* exec_ctx) { + verify_table_size_change_match_elem_size(exec_ctx, "hello", "world", false); + verify_table_size_change_match_elem_size(exec_ctx, "hello-bin", "world", + false); + verify_table_size_change_match_elem_size(exec_ctx, "true-binary-bin", "I_am_true_binary_value", true); } -static void test_interned_key_indexed() { +static void test_interned_key_indexed(grpc_exec_ctx* exec_ctx) { int i; verify_params params = {false, false, true}; - verify(params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, "a", "b", - "a", "c"); + verify(exec_ctx, params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, + "a", "b", "a", "c"); for (i = 0; i < 10; i++) { - verify(params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", "b", "a", - "c"); + verify(exec_ctx, params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", + "b", "a", "c"); } } -static void run_test(void (*test)(), const char* name) { +static void run_test(void (*test)(grpc_exec_ctx* exec_ctx), const char* name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_compressor_init(&g_compressor); - test(); - grpc_chttp2_hpack_compressor_destroy(&g_compressor); + test(&exec_ctx); + grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &g_compressor); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index 9a195daee0..942f25e0b7 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -29,7 +29,9 @@ bool squelch = true; bool leak_check = true; -static void onhdr(void* ud, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } +static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { + GRPC_MDELEM_UNREF(exec_ctx, md); +} static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { @@ -37,14 +39,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; - { - grpc_core::ExecCtx exec_ctx; - grpc_chttp2_hpack_parser_init(&parser); - parser.on_header = onhdr; - GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &parser, grpc_slice_from_static_buffer(data, size))); - grpc_chttp2_hpack_parser_destroy(&parser); - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + parser.on_header = onhdr; + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 9d3456a873..82fb20aced 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -32,7 +32,7 @@ typedef struct { va_list args; } test_checker; -static void onhdr(void* ud, grpc_mdelem md) { +static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { const char *ekey, *evalue; test_checker* chk = static_cast(ud); ekey = va_arg(chk->args, char*); @@ -41,7 +41,7 @@ static void onhdr(void* ud, grpc_mdelem md) { GPR_ASSERT(evalue); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } static void test_vector(grpc_chttp2_hpack_parser* parser, @@ -62,9 +62,10 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == GRPC_ERROR_NONE); + grpc_exec_ctx_finish(&exec_ctx); } for (i = 0; i < nslices; i++) { @@ -79,9 +80,9 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); /* D.2.1 */ test_vector(&parser, mode, "400a 6375 7374 6f6d 2d6b 6579 0d63 7573" @@ -97,9 +98,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "password", "secret", NULL); /* D.2.4 */ test_vector(&parser, mode, "82", ":method", "GET", NULL); - grpc_chttp2_hpack_parser_destroy(&parser); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); /* D.3.1 */ test_vector(&parser, mode, "8286 8441 0f77 7777 2e65 7861 6d70 6c65" @@ -117,9 +118,9 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&parser); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); /* D.4.1 */ test_vector(&parser, mode, "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4" @@ -137,11 +138,11 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&parser); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_chttp2_hpack_parser_init(&parser); - grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); /* D.5.1 */ test_vector(&parser, mode, "4803 3330 3258 0770 7269 7661 7465 611d" @@ -171,11 +172,11 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&parser); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_chttp2_hpack_parser_init(&parser); - grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); + grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); /* D.6.1 */ test_vector(&parser, mode, "4882 6402 5885 aec3 771a 4b61 96d0 7abe" @@ -202,7 +203,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&parser); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index 3f3cb2ee9d..ff7c2de538 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -44,10 +44,10 @@ static void assert_index(const grpc_chttp2_hptbl* tbl, uint32_t idx, } static void test_static_lookup(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hptbl tbl; - grpc_chttp2_hptbl_init(&tbl); + grpc_chttp2_hptbl_init(&exec_ctx, &tbl); LOG_TEST("test_static_lookup"); assert_index(&tbl, 1, ":authority", ""); @@ -112,7 +112,8 @@ static void test_static_lookup(void) { assert_index(&tbl, 60, "via", ""); assert_index(&tbl, 61, "www-authenticate", ""); - grpc_chttp2_hptbl_destroy(&tbl); + grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); + grpc_exec_ctx_finish(&exec_ctx); } static void test_many_additions(void) { @@ -123,17 +124,18 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - grpc_core::ExecCtx exec_ctx; - grpc_chttp2_hptbl_init(&tbl); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_chttp2_hptbl_init(&exec_ctx, &tbl); for (i = 0; i < 100000; i++) { grpc_mdelem elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = grpc_mdelem_from_slices(grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(elem); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); + GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(&exec_ctx, elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); gpr_free(key); gpr_free(value); @@ -146,23 +148,25 @@ static void test_many_additions(void) { } } - grpc_chttp2_hptbl_destroy(&tbl); + grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); + grpc_exec_ctx_finish(&exec_ctx); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, const char* key, const char* value) { - grpc_core::ExecCtx exec_ctx; - grpc_mdelem md = grpc_mdelem_from_slices( - grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem md = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); - GRPC_MDELEM_UNREF(md); - + GRPC_MDELEM_UNREF(&exec_ctx, md); + grpc_exec_ctx_finish(&exec_ctx); return r; } static void test_find(void) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; @@ -171,19 +175,21 @@ static void test_find(void) { LOG_TEST("test_find"); - grpc_chttp2_hptbl_init(&tbl); - elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("xyz")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(elem); - elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("123")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(elem); - elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("x"), + grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("xyz")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(&exec_ctx, elem); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("123")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(&exec_ctx, elem); + elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), grpc_slice_from_static_string("1")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(&exec_ctx, elem); r = find_simple(&tbl, "abc", "123"); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); @@ -232,10 +238,11 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("test"), + elem = grpc_mdelem_from_slices(&exec_ctx, + grpc_slice_from_static_string("test"), grpc_slice_from_copied_string(buffer)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(&exec_ctx, elem); } r = find_simple(&tbl, "abc", "123"); @@ -263,7 +270,8 @@ static void test_find(void) { GPR_ASSERT(r.index != 0); GPR_ASSERT(r.has_value == 0); - grpc_chttp2_hptbl_destroy(&tbl); + grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 08473c72b6..670eae1f79 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -97,7 +97,7 @@ class Client { : server_address_(server_address) {} void Connect() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resolved_addresses* server_addresses = nullptr; grpc_error* error = grpc_blocking_resolve_address(server_address_, "80", &server_addresses); @@ -106,53 +106,56 @@ class Client { pollset_ = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(pollset_, &mu_); grpc_pollset_set* pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(pollset_set, pollset_); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_set, pollset_); EventState state; - grpc_tcp_client_connect(state.closure(), &endpoint_, pollset_set, + grpc_tcp_client_connect(&exec_ctx, state.closure(), &endpoint_, pollset_set, nullptr /* channel_args */, server_addresses->addrs, 1000); ASSERT_TRUE(PollUntilDone( - &state, + &exec_ctx, &state, grpc_timespec_to_millis_round_up(gpr_inf_future(GPR_CLOCK_MONOTONIC)))); ASSERT_EQ(GRPC_ERROR_NONE, state.error()); - grpc_pollset_set_destroy(pollset_set); - grpc_endpoint_add_to_pollset(endpoint_, pollset_); + grpc_pollset_set_destroy(&exec_ctx, pollset_set); + grpc_endpoint_add_to_pollset(&exec_ctx, endpoint_, pollset_); grpc_resolved_addresses_destroy(server_addresses); + grpc_exec_ctx_finish(&exec_ctx); } // Reads until an error is returned. // Returns true if an error was encountered before the deadline. bool ReadUntilError() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice_buffer read_buffer; grpc_slice_buffer_init(&read_buffer); bool retval = true; // Use a deadline of 3 seconds, which is a lot more than we should // need for a 1-second timeout, but this helps avoid flakes. - grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 3000; + grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 3000; while (true) { EventState state; - grpc_endpoint_read(endpoint_, &read_buffer, state.closure()); - if (!PollUntilDone(&state, deadline)) { + grpc_endpoint_read(&exec_ctx, endpoint_, &read_buffer, state.closure()); + if (!PollUntilDone(&exec_ctx, &state, deadline)) { retval = false; break; } if (state.error() != GRPC_ERROR_NONE) break; gpr_log(GPR_INFO, "client read %" PRIuPTR " bytes", read_buffer.length); - grpc_slice_buffer_reset_and_unref_internal(&read_buffer); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &read_buffer); } - grpc_endpoint_shutdown(endpoint_, + grpc_endpoint_shutdown(&exec_ctx, endpoint_, GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown")); - grpc_slice_buffer_destroy_internal(&read_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, &read_buffer); + grpc_exec_ctx_finish(&exec_ctx); return retval; } void Shutdown() { - grpc_core::ExecCtx exec_ctx; - grpc_endpoint_destroy(endpoint_); - grpc_pollset_shutdown(pollset_, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_endpoint_destroy(&exec_ctx, endpoint_); + grpc_pollset_shutdown(&exec_ctx, pollset_, GRPC_CLOSURE_CREATE(&Client::PollsetDestroy, pollset_, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_finish(&exec_ctx); } private: @@ -174,7 +177,8 @@ class Client { grpc_error* error() const { return error_; } private: - static void OnEventDone(void* arg, grpc_error* error) { + static void OnEventDone(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { gpr_log(GPR_INFO, "OnEventDone(): %s", grpc_error_string(error)); EventState* state = (EventState*)arg; state->error_ = GRPC_ERROR_REF(error); @@ -187,23 +191,24 @@ class Client { }; // Returns true if done, or false if deadline exceeded. - bool PollUntilDone(EventState* state, grpc_millis deadline) { + bool PollUntilDone(grpc_exec_ctx* exec_ctx, EventState* state, + grpc_millis deadline) { while (true) { grpc_pollset_worker* worker = nullptr; gpr_mu_lock(mu_); - GRPC_LOG_IF_ERROR( - "grpc_pollset_work", - grpc_pollset_work(pollset_, &worker, - grpc_core::ExecCtx::Get()->Now() + 1000)); + GRPC_LOG_IF_ERROR("grpc_pollset_work", + grpc_pollset_work(exec_ctx, pollset_, &worker, + grpc_exec_ctx_now(exec_ctx) + 1000)); gpr_mu_unlock(mu_); if (state != nullptr && state->done()) return true; - if (grpc_core::ExecCtx::Get()->Now() >= deadline) return false; + if (grpc_exec_ctx_now(exec_ctx) >= deadline) return false; } } - static void PollsetDestroy(void* arg, grpc_error* error) { + static void PollsetDestroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(pollset); + grpc_pollset_destroy(exec_ctx, pollset); gpr_free(pollset); } diff --git a/test/core/transport/chttp2/varint_test.cc b/test/core/transport/chttp2/varint_test.cc index 36760d0c72..413b461b3a 100644 --- a/test/core/transport/chttp2/varint_test.cc +++ b/test/core/transport/chttp2/varint_test.cc @@ -18,7 +18,6 @@ #include "src/core/ext/transport/chttp2/transport/varint.h" -#include #include #include @@ -45,13 +44,11 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); TEST_VARINT(0, 1, 0, "\x00"); TEST_VARINT(128, 1, 0, "\x7f\x01"); TEST_VARINT(16384, 1, 0, "\x7f\x81\x7f"); TEST_VARINT(2097152, 1, 0, "\x7f\x81\xff\x7f"); TEST_VARINT(268435456, 1, 0, "\x7f\x81\xff\xff\x7f"); TEST_VARINT(0xffffffff, 1, 0, "\x7f\x80\xff\xff\xff\x0f"); - grpc_shutdown(); return 0; } diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index f5894599e5..11046e126e 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -29,13 +29,14 @@ int g_counter; -static void must_succeed(void* arg, grpc_error* error) { +static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; } -static void must_fail(void* arg, grpc_error* error) { +static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GPR_ASSERT(error != GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; @@ -58,7 +59,7 @@ static void test_connectivity_state_name(void) { static void test_check(void) { grpc_connectivity_state_tracker tracker; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_error* error; gpr_log(GPR_DEBUG, "test_check"); grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -66,7 +67,8 @@ static void test_check(void) { GRPC_CHANNEL_IDLE); GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_connectivity_state_destroy(&tracker); + grpc_connectivity_state_destroy(&exec_ctx, &tracker); + grpc_exec_ctx_finish(&exec_ctx); } static void test_subscribe_then_unsubscribe(void) { @@ -74,21 +76,23 @@ static void test_subscribe_then_unsubscribe(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, - closure)); - grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, + &state, closure)); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_notify_on_state_change(&tracker, nullptr, closure); - grpc_core::ExecCtx::Get()->Flush(); + grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, nullptr, + closure); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 1); - grpc_connectivity_state_destroy(&tracker); + grpc_connectivity_state_destroy(&exec_ctx, &tracker); + grpc_exec_ctx_finish(&exec_ctx); } static void test_subscribe_then_destroy(void) { @@ -96,18 +100,17 @@ static void test_subscribe_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, - closure)); - grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, + &state, closure)); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&tracker); - - grpc_core::ExecCtx::Get()->Flush(); + grpc_connectivity_state_destroy(&exec_ctx, &tracker); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } @@ -117,30 +120,28 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( - &tracker, &state, closure)); - grpc_core::ExecCtx::Get()->Flush(); + &exec_ctx, &tracker, &state, closure)); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&tracker); - grpc_core::ExecCtx::Get()->Flush(); + grpc_connectivity_state_destroy(&exec_ctx, &tracker); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); test_subscribe_then_destroy(); test_subscribe_with_failure_then_destroy(); - grpc_shutdown(); return 0; } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 5c52ae8d5f..b60a9619fb 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -60,15 +60,15 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; m1 = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m2 = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m3 = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("c"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(m1, m2)); GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); @@ -77,10 +77,10 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); - GRPC_MDELEM_UNREF(m1); - GRPC_MDELEM_UNREF(m2); - GRPC_MDELEM_UNREF(m3); - + GRPC_MDELEM_UNREF(&exec_ctx, m1); + GRPC_MDELEM_UNREF(&exec_ctx, m2); + GRPC_MDELEM_UNREF(&exec_ctx, m3); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -95,15 +95,19 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF(grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_from_slices( + &exec_ctx, + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_copied_string(buffer), + intern_values))); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -117,28 +121,28 @@ static void test_create_many_persistant_metadata(void) { gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); created[i] = grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("a")), + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); md = grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("a")), + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); GPR_ASSERT(grpc_mdelem_eq(md, created[i])); - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(&exec_ctx, md); } /* cleanup phase */ for (i = 0; i < MANY; i++) { - GRPC_MDELEM_UNREF(created[i]); + GRPC_MDELEM_UNREF(&exec_ctx, created[i]); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(created); @@ -151,25 +155,31 @@ static void test_spin_creating_the_same_thing(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( + &exec_ctx, a = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( + &exec_ctx, b = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( + &exec_ctx, c = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); if (intern_keys && intern_values) { GPR_ASSERT(a.payload == b.payload); GPR_ASSERT(a.payload == c.payload); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -178,16 +188,16 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem a, b, c; a = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); b = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); c = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(a, a)); GPR_ASSERT(grpc_mdelem_eq(b, b)); @@ -206,10 +216,10 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { GPR_ASSERT(a.payload != c.payload); GPR_ASSERT(b.payload != c.payload); } - GRPC_MDELEM_UNREF(a); - GRPC_MDELEM_UNREF(b); - GRPC_MDELEM_UNREF(c); - + GRPC_MDELEM_UNREF(&exec_ctx, a); + GRPC_MDELEM_UNREF(&exec_ctx, b); + GRPC_MDELEM_UNREF(&exec_ctx, c); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -225,7 +235,7 @@ static void test_things_stick_around(void) { gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); @@ -236,7 +246,7 @@ static void test_things_stick_around(void) { for (i = 0; i < nstrs; i++) { grpc_slice_ref_internal(strs[i]); - grpc_slice_unref_internal(strs[i]); + grpc_slice_unref_internal(&exec_ctx, strs[i]); } for (i = 0; i < nstrs; i++) { @@ -248,17 +258,18 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - grpc_slice_unref_internal(strs[shuf[i]]); + grpc_slice_unref_internal(&exec_ctx, strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); test = grpc_slice_intern(grpc_slice_from_static_string(buffer)); GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); - grpc_slice_unref_internal(test); + grpc_slice_unref_internal(&exec_ctx, test); gpr_free(buffer); } } + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(strs); gpr_free(shuf); @@ -271,38 +282,39 @@ static void test_user_data_works(void) { gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; ud1 = static_cast(gpr_malloc(sizeof(int))); *ud1 = 1; ud2 = static_cast(gpr_malloc(sizeof(int))); *ud2 = 2; md = grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("abc")), + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("123"))); grpc_mdelem_set_user_data(md, gpr_free, ud1); grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); - GRPC_MDELEM_UNREF(md); - + GRPC_MDELEM_UNREF(&exec_ctx, md); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } -static void verify_ascii_header_size(const char* key, const char* value, - bool intern_key, bool intern_value) { +static void verify_ascii_header_size(grpc_exec_ctx* exec_ctx, const char* key, + const char* value, bool intern_key, + bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string(key), intern_key), + exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_string(value), intern_value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); - GRPC_MDELEM_UNREF(elem); + GRPC_MDELEM_UNREF(exec_ctx, elem); } -static void verify_binary_header_size(const char* key, const uint8_t* value, - size_t value_len, bool intern_key, - bool intern_value) { +static void verify_binary_header_size(grpc_exec_ctx* exec_ctx, const char* key, + const uint8_t* value, size_t value_len, + bool intern_key, bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - maybe_intern(grpc_slice_from_static_string(key), intern_key), + exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_buffer(value, value_len), intern_value)); GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); @@ -312,9 +324,9 @@ static void verify_binary_header_size(const char* key, const uint8_t* value, grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice); size_t expected_size = 32 + strlen(key) + GRPC_SLICE_LENGTH(base64_encoded); GPR_ASSERT(expected_size == elem_size); - grpc_slice_unref_internal(value_slice); - grpc_slice_unref_internal(base64_encoded); - GRPC_MDELEM_UNREF(elem); + grpc_slice_unref_internal(exec_ctx, value_slice); + grpc_slice_unref_internal(exec_ctx, base64_encoded); + GRPC_MDELEM_UNREF(exec_ctx, elem); } #define BUFFER_SIZE 64 @@ -322,23 +334,27 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", intern_key, intern_value); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; uint8_t binary_value[BUFFER_SIZE] = {0}; for (uint8_t i = 0; i < BUFFER_SIZE; i++) { binary_value[i] = i; } - verify_ascii_header_size("hello", "world", intern_key, intern_value); - verify_ascii_header_size("hello", "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - intern_key, intern_value); - verify_ascii_header_size(":scheme", "http", intern_key, intern_value); + verify_ascii_header_size(&exec_ctx, "hello", "world", intern_key, + intern_value); + verify_ascii_header_size(&exec_ctx, "hello", + "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", intern_key, + intern_value); + verify_ascii_header_size(&exec_ctx, ":scheme", "http", intern_key, + intern_value); for (uint8_t i = 0; i < BUFFER_SIZE; i++) { - verify_binary_header_size("hello-bin", binary_value, i, intern_key, - intern_value); + verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i, + intern_key, intern_value); } + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -346,13 +362,13 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, dup_value); grpc_init(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], GRPC_MDELEM_STORAGE_STATIC); grpc_mdelem q = - grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), + grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), maybe_dup(GRPC_MDVALUE(p), dup_value)); GPR_ASSERT(grpc_mdelem_eq(p, q)); if (dup_key || dup_value) { @@ -360,16 +376,16 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { } else { GPR_ASSERT(p.payload == q.payload); } - GRPC_MDELEM_UNREF(p); - GRPC_MDELEM_UNREF(q); + GRPC_MDELEM_UNREF(&exec_ctx, p); + GRPC_MDELEM_UNREF(&exec_ctx, q); } + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); test_no_op(); for (int k = 0; k <= 1; k++) { for (int v = 0; v <= 1; v++) { @@ -384,6 +400,5 @@ int main(int argc, char** argv) { test_create_many_persistant_metadata(); test_things_stick_around(); test_user_data_works(); - grpc_shutdown(); return 0; } diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 1ed6ccfba6..7af5d12cb7 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -22,11 +22,12 @@ #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \ GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) -#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ - do { \ - grpc_core::ExecCtx exec_ctx; \ - GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ - \ +#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ + do { \ + grpc_exec_ctx my_exec_ctx = GRPC_EXEC_CTX_INIT; \ + GPR_ASSERT(grpc_http2_error_to_grpc_status(&my_exec_ctx, a, deadline) == \ + (b)); \ + grpc_exec_ctx_finish(&my_exec_ctx); \ } while (0) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) diff --git a/test/core/transport/stream_owned_slice_test.cc b/test/core/transport/stream_owned_slice_test.cc index 7831f67a04..e82df2117d 100644 --- a/test/core/transport/stream_owned_slice_test.cc +++ b/test/core/transport/stream_owned_slice_test.cc @@ -20,14 +20,12 @@ #include "test/core/util/test_config.h" -#include #include -static void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); uint8_t buffer[] = "abc123"; grpc_stream_refcount r; @@ -41,6 +39,5 @@ int main(int argc, char** argv) { grpc_slice_unref(slice); GPR_ASSERT(r.refs.count == 1); - grpc_shutdown(); return 0; } diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index 4b35a581b1..d9545efa49 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -40,13 +40,13 @@ typedef struct grpc_mock_endpoint { grpc_resource_user* resource_user; } grpc_mock_endpoint; -static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -54,41 +54,44 @@ static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, gpr_mu_unlock(&m->mu); } -static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); } -static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read) { - GRPC_CLOSURE_SCHED(m->on_read, + GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Endpoint Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->mu); - grpc_resource_user_shutdown(m->resource_user); + grpc_resource_user_shutdown(exec_ctx, m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_endpoint* ep) { +static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; grpc_slice_buffer_destroy(&m->read_buffer); - grpc_resource_user_unref(m->resource_user); + grpc_resource_user_unref(exec_ctx, m->resource_user); gpr_free(m); } @@ -131,12 +134,13 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), return &m->base; } -void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) { +void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice slice) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read != nullptr) { grpc_slice_buffer_add(m->on_read_out, slice); - GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { grpc_slice_buffer_add(&m->read_buffer, slice); diff --git a/test/core/util/mock_endpoint.h b/test/core/util/mock_endpoint.h index 6521d3e8e8..ccabaf7c3b 100644 --- a/test/core/util/mock_endpoint.h +++ b/test/core/util/mock_endpoint.h @@ -23,7 +23,8 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota); -void grpc_mock_endpoint_put_read(grpc_endpoint* mock_endpoint, +void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, + grpc_endpoint* mock_endpoint, grpc_slice slice); #endif diff --git a/test/core/util/one_corpus_entry_fuzzer.cc b/test/core/util/one_corpus_entry_fuzzer.cc index c745eb5dc6..c0b67da1e2 100644 --- a/test/core/util/one_corpus_entry_fuzzer.cc +++ b/test/core/util/one_corpus_entry_fuzzer.cc @@ -18,10 +18,7 @@ #include -#include - #include -#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/load_file.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); @@ -33,15 +30,10 @@ int main(int argc, char** argv) { grpc_slice buffer; squelch = false; leak_check = false; - /* TODO(yashkt) Calling grpc_init breaks tests. Fix the tests and replace - * grpc_core::ExecCtx::GlobalInit with grpc_init and GlobalShutdown with - * grpc_shutdown */ GPR_ASSERT( GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer))); LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), GRPC_SLICE_LENGTH(buffer)); - grpc_core::ExecCtx::GlobalInit(); grpc_slice_unref(buffer); - grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index 5f127cb960..a9efe22b69 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -49,22 +49,22 @@ struct passthru_endpoint { int halves; grpc_passthru_endpoint_stats* stats; grpc_passthru_endpoint_stats - dummy_stats; // used if constructor stats == nullptr + dummy_stats; // used if constructor stats == NULL bool shutdown; half client; half server; }; -static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { GRPC_CLOSURE_SCHED( - cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); + exec_ctx, cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); } else if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -77,8 +77,8 @@ static half* other_half(half* h) { return &h->parent->client; } -static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { half* m = other_half((half*)ep); gpr_mu_lock(&m->parent->mu); grpc_error* error = GRPC_ERROR_NONE; @@ -89,7 +89,7 @@ static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, for (size_t i = 0; i < slices->count; i++) { grpc_slice_buffer_add(m->on_read_out, grpc_slice_copy(slices->slices[i])); } - GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { for (size_t i = 0; i < slices->count; i++) { @@ -98,49 +98,52 @@ static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, } } gpr_mu_unlock(&m->parent->mu); - GRPC_CLOSURE_SCHED(cb, error); + GRPC_CLOSURE_SCHED(exec_ctx, cb, error); } -static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { GRPC_CLOSURE_SCHED( - m->on_read, + exec_ctx, m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } m = other_half(m); if (m->on_read) { GRPC_CLOSURE_SCHED( - m->on_read, + exec_ctx, m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->parent->mu); - grpc_resource_user_shutdown(m->resource_user); + grpc_resource_user_shutdown(exec_ctx, m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_endpoint* ep) { +static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { passthru_endpoint* p = ((half*)ep)->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { gpr_mu_unlock(&p->mu); gpr_mu_destroy(&p->mu); - grpc_slice_buffer_destroy_internal(&p->client.read_buffer); - grpc_slice_buffer_destroy_internal(&p->server.read_buffer); - grpc_resource_user_unref(p->client.resource_user); - grpc_resource_user_unref(p->server.resource_user); + grpc_slice_buffer_destroy_internal(exec_ctx, &p->client.read_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &p->server.read_buffer); + grpc_resource_user_unref(exec_ctx, p->client.resource_user); + grpc_resource_user_unref(exec_ctx, p->server.resource_user); gpr_free(p); } else { gpr_mu_unlock(&p->mu); diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 7e76c8063f..edec50b424 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -40,19 +40,22 @@ typedef struct freereq { int done; } freereq; -static void destroy_pops_and_shutdown(void* p, grpc_error* error) { +static void destroy_pops_and_shutdown(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { grpc_pollset* pollset = grpc_polling_entity_pollset((grpc_polling_entity*)p); - grpc_pollset_destroy(pollset); + grpc_pollset_destroy(exec_ctx, pollset); gpr_free(pollset); } -static void freed_port_from_server(void* arg, grpc_error* error) { +static void freed_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { freereq* pr = (freereq*)arg; gpr_mu_lock(pr->mu); pr->done = 1; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), + nullptr)); gpr_mu_unlock(pr->mu); } @@ -62,7 +65,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_response rsp; freereq pr; char* path; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure* shutdown_closure; grpc_init(); @@ -84,30 +87,30 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_context_init(&context); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/free"); - grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, + grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); - grpc_resource_quota_unref_internal(resource_quota); - grpc_core::ExecCtx::Get()->Flush(); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work( - grpc_polling_entity_pollset(&pr.pops), &worker, - grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), + &worker, + grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { pr.done = 1; } } gpr_mu_unlock(pr.mu); - grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), + grpc_httpcli_context_destroy(&exec_ctx, &context); + grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), shutdown_closure); - + grpc_exec_ctx_finish(&exec_ctx); gpr_free(path); grpc_http_response_destroy(&rsp); @@ -124,7 +127,8 @@ typedef struct portreq { grpc_httpcli_response response; } portreq; -static void got_port_from_server(void* arg, grpc_error* error) { +static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { size_t i; int port = 0; portreq* pr = (portreq*)arg; @@ -150,7 +154,8 @@ static void got_port_from_server(void* arg, grpc_error* error) { pr->port = 0; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), + nullptr)); gpr_mu_unlock(pr->mu); return; } @@ -167,12 +172,12 @@ static void got_port_from_server(void* arg, grpc_error* error) { memset(&pr->response, 0, sizeof(pr->response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/pick_retry"); - grpc_httpcli_get(pr->ctx, &pr->pops, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req, + grpc_exec_ctx_now(exec_ctx) + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, pr, grpc_schedule_on_exec_ctx), &pr->response); - grpc_resource_quota_unref_internal(resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); return; } GPR_ASSERT(response); @@ -186,7 +191,8 @@ static void got_port_from_server(void* arg, grpc_error* error) { pr->port = port; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); + grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), + nullptr)); gpr_mu_unlock(pr->mu); } @@ -194,55 +200,53 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure* shutdown_closure; grpc_init(); - { - grpc_core::ExecCtx exec_ctx; - memset(&pr, 0, sizeof(pr)); - memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(pollset, &pr.mu); - pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, - grpc_schedule_on_exec_ctx); - pr.port = -1; - pr.server = const_cast(GRPC_PORT_SERVER_ADDRESS); - pr.ctx = &context; - - req.host = const_cast(GRPC_PORT_SERVER_ADDRESS); - req.http.path = const_cast("/get"); - grpc_httpcli_context_init(&context); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("port_server_client/pick"); - grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, - GRPC_CLOSURE_CREATE(got_port_from_server, &pr, - grpc_schedule_on_exec_ctx), - &pr.response); - grpc_resource_quota_unref_internal(resource_quota); - grpc_core::ExecCtx::Get()->Flush(); - gpr_mu_lock(pr.mu); - while (pr.port == -1) { - grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work( - grpc_polling_entity_pollset(&pr.pops), &worker, - grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { - pr.port = 0; - } - } - gpr_mu_unlock(pr.mu); + memset(&pr, 0, sizeof(pr)); + memset(&req, 0, sizeof(req)); + grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(pollset, &pr.mu); + pr.pops = grpc_polling_entity_create_from_pollset(pollset); + shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); + pr.port = -1; + pr.server = const_cast(GRPC_PORT_SERVER_ADDRESS); + pr.ctx = &context; - grpc_http_response_destroy(&pr.response); - grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), - shutdown_closure); + req.host = const_cast(GRPC_PORT_SERVER_ADDRESS); + req.http.path = const_cast("/get"); - grpc_core::ExecCtx::Get()->Flush(); + grpc_httpcli_context_init(&context); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("port_server_client/pick"); + grpc_httpcli_get( + &exec_ctx, &context, &pr.pops, resource_quota, &req, + grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, + GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), + &pr.response); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_exec_ctx_flush(&exec_ctx); + gpr_mu_lock(pr.mu); + while (pr.port == -1) { + grpc_pollset_worker* worker = nullptr; + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), + &worker, + grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { + pr.port = 0; + } } + gpr_mu_unlock(pr.mu); + + grpc_http_response_destroy(&pr.response); + grpc_httpcli_context_destroy(&exec_ctx, &context); + grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), + shutdown_closure); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return pr.port; diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index bcafc4e898..4775b074eb 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -55,7 +55,7 @@ static void pretty_print_backoffs(reconnect_server* server) { } } -static void on_connect(void* arg, grpc_endpoint* tcp, +static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -65,9 +65,9 @@ static void on_connect(void* arg, grpc_endpoint* tcp, gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; peer = grpc_endpoint_get_peer(tcp); - grpc_endpoint_shutdown(tcp, + grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(tcp); + grpc_endpoint_destroy(exec_ctx, tcp); if (peer) { last_colon = strrchr(peer, ':'); if (server->peer == nullptr) { diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index 5f6af4e707..da34da6fd0 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -33,7 +33,8 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static void on_server_destroyed(void* data, grpc_error* error) { +static void on_server_destroyed(grpc_exec_ctx* exec_ctx, void* data, + grpc_error* error) { test_tcp_server* server = static_cast(data); server->shutdown = 1; } @@ -55,46 +56,51 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int port_added; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; addr->sin_family = AF_INET; addr->sin_port = htons((uint16_t)port); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); - grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, - nullptr, &server->tcp_server); + grpc_error* error = grpc_tcp_server_create( + &exec_ctx, &server->shutdown_complete, nullptr, &server->tcp_server); GPR_ASSERT(error == GRPC_ERROR_NONE); error = grpc_tcp_server_add_port(server->tcp_server, &resolved_addr, &port_added); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(port_added == port); - grpc_tcp_server_start(server->tcp_server, &server->pollset, 1, + grpc_tcp_server_start(&exec_ctx, server->tcp_server, &server->pollset, 1, server->on_connect, server->cb_data); gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port); + + grpc_exec_ctx_finish(&exec_ctx); } void test_tcp_server_poll(test_tcp_server* server, int seconds) { grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); - GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(server->pollset, &worker, deadline)); + GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work(&exec_ctx, server->pollset, &worker, deadline)); gpr_mu_unlock(server->mu); + grpc_exec_ctx_finish(&exec_ctx); } -static void do_nothing(void* arg, grpc_error* error) {} -static void finish_pollset(void* arg, grpc_error* error) { - grpc_pollset_destroy(static_cast(arg)); +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void finish_pollset(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(arg)); } void test_tcp_server_destroy(test_tcp_server* server) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; - grpc_tcp_server_unref(server->tcp_server); + grpc_tcp_server_unref(&exec_ctx, server->tcp_server); GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), @@ -103,10 +109,10 @@ void test_tcp_server_destroy(test_tcp_server* server) { gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), shutdown_deadline) < 0) { test_tcp_server_poll(server, 1); } - grpc_pollset_shutdown(server->pollset, + grpc_pollset_shutdown(&exec_ctx, server->pollset, GRPC_CLOSURE_CREATE(finish_pollset, server->pollset, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index f95ed62463..4544fb7f49 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -45,23 +45,24 @@ typedef struct { grpc_closure* write_cb; } trickle_endpoint; -static void te_read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void te_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_read(te->wrapped, slices, cb); + grpc_endpoint_read(exec_ctx, te->wrapped, slices, cb); } -static void maybe_call_write_cb_locked(trickle_endpoint* te) { +static void maybe_call_write_cb_locked(grpc_exec_ctx* exec_ctx, + trickle_endpoint* te) { if (te->write_cb != nullptr && (te->error != GRPC_ERROR_NONE || te->write_buffer.length <= WRITE_BUFFER_SIZE)) { - GRPC_CLOSURE_SCHED(te->write_cb, GRPC_ERROR_REF(te->error)); + GRPC_CLOSURE_SCHED(exec_ctx, te->write_cb, GRPC_ERROR_REF(te->error)); te->write_cb = nullptr; } } -static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { +static void te_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); GPR_ASSERT(te->write_cb == nullptr); @@ -73,44 +74,47 @@ static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_slice_copy(slices->slices[i])); } te->write_cb = cb; - maybe_call_write_cb_locked(te); + maybe_call_write_cb_locked(exec_ctx, te); gpr_mu_unlock(&te->mu); } -static void te_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { +static void te_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset(te->wrapped, pollset); + grpc_endpoint_add_to_pollset(exec_ctx, te->wrapped, pollset); } -static void te_add_to_pollset_set(grpc_endpoint* ep, +static void te_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset_set(te->wrapped, pollset_set); + grpc_endpoint_add_to_pollset_set(exec_ctx, te->wrapped, pollset_set); } -static void te_delete_from_pollset_set(grpc_endpoint* ep, +static void te_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_delete_from_pollset_set(te->wrapped, pollset_set); + grpc_endpoint_delete_from_pollset_set(exec_ctx, te->wrapped, pollset_set); } -static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { +static void te_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (te->error == GRPC_ERROR_NONE) { te->error = GRPC_ERROR_REF(why); } - maybe_call_write_cb_locked(te); + maybe_call_write_cb_locked(exec_ctx, te); gpr_mu_unlock(&te->mu); - grpc_endpoint_shutdown(te->wrapped, why); + grpc_endpoint_shutdown(exec_ctx, te->wrapped, why); } -static void te_destroy(grpc_endpoint* ep) { +static void te_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_destroy(te->wrapped); + grpc_endpoint_destroy(exec_ctx, te->wrapped); gpr_mu_destroy(&te->mu); - grpc_slice_buffer_destroy_internal(&te->write_buffer); - grpc_slice_buffer_destroy_internal(&te->writing_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &te->write_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &te->writing_buffer); GRPC_ERROR_UNREF(te->error); gpr_free(te); } @@ -130,7 +134,8 @@ static int te_get_fd(grpc_endpoint* ep) { return grpc_endpoint_get_fd(te->wrapped); } -static void te_finish_write(void* arg, grpc_error* error) { +static void te_finish_write(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { trickle_endpoint* te = (trickle_endpoint*)arg; gpr_mu_lock(&te->mu); te->writing = false; @@ -168,7 +173,8 @@ static double ts2dbl(gpr_timespec s) { return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; } -size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { +size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (!te->writing && te->write_buffer.length > 0) { @@ -183,9 +189,9 @@ size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { te->writing = true; te->last_write = now; grpc_endpoint_write( - te->wrapped, &te->writing_buffer, + exec_ctx, te->wrapped, &te->writing_buffer, GRPC_CLOSURE_CREATE(te_finish_write, te, grpc_schedule_on_exec_ctx)); - maybe_call_write_cb_locked(te); + maybe_call_write_cb_locked(exec_ctx, te); } } size_t backlog = te->write_buffer.length; diff --git a/test/core/util/trickle_endpoint.h b/test/core/util/trickle_endpoint.h index cd07de905a..11c113bda8 100644 --- a/test/core/util/trickle_endpoint.h +++ b/test/core/util/trickle_endpoint.h @@ -25,7 +25,8 @@ grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second); /* Allow up to \a bytes through the endpoint. Returns the new backlog. */ -size_t grpc_trickle_endpoint_trickle(grpc_endpoint* endpoint); +size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, + grpc_endpoint* endpoint); size_t grpc_trickle_get_backlog(grpc_endpoint* endpoint); diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index e829d5278b..0954b28df0 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -212,13 +212,13 @@ class ClientChannelStressTest { }; void SetNextResolution(const std::vector& address_data) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port); - grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri( addresses, i, lb_uri, address_data[i].is_balancer, @@ -228,9 +228,10 @@ class ClientChannelStressTest { } grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args fake_result = {1, &fake_addresses}; - grpc_fake_resolver_response_generator_set_response(response_generator_, - &fake_result); - grpc_lb_addresses_destroy(addresses); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator_, &fake_result); + grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_exec_ctx_finish(&exec_ctx); } void KeepSendingRequests() { diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index f330c01281..d6ed2e5aa2 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -249,8 +249,5 @@ TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - grpc_init(); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; + return RUN_ALL_TESTS(); } diff --git a/test/cpp/common/channel_filter_test.cc b/test/cpp/common/channel_filter_test.cc index 7bdd53f9e7..638518107b 100644 --- a/test/cpp/common/channel_filter_test.cc +++ b/test/cpp/common/channel_filter_test.cc @@ -28,7 +28,7 @@ class MyChannelData : public ChannelData { public: MyChannelData() {} - grpc_error* Init(grpc_channel_element* elem, + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) override { (void)args->channel_args; // Make sure field is available. return GRPC_ERROR_NONE; @@ -39,7 +39,7 @@ class MyCallData : public CallData { public: MyCallData() {} - grpc_error* Init(grpc_call_element* elem, + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_element_args* args) override { (void)args->path; // Make sure field is available. return GRPC_ERROR_NONE; diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index e6e6e71f42..f8bb12fde1 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -112,13 +112,13 @@ class ClientLbEnd2endTest : public ::testing::Test { } void SetNextResolution(const std::vector& ports) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_lb_addresses* addresses = grpc_lb_addresses_create(ports.size(), nullptr); for (size_t i = 0; i < ports.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", ports[i]); - grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri(addresses, i, lb_uri, false /* is balancer */, @@ -130,10 +130,11 @@ class ClientLbEnd2endTest : public ::testing::Test { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* fake_result = grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1); - grpc_fake_resolver_response_generator_set_response(response_generator_, - fake_result); - grpc_channel_args_destroy(fake_result); - grpc_lb_addresses_destroy(addresses); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator_, fake_result); + grpc_channel_args_destroy(&exec_ctx, fake_result); + grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_exec_ctx_finish(&exec_ctx); } void ResetStub(const grpc::string& lb_policy_name = "") { diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index c4430379db..f260ea0016 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -100,7 +100,7 @@ int GetCallCounterValue() { class ChannelDataImpl : public ChannelData { public: - grpc_error* Init(grpc_channel_element* elem, + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) { IncrementConnectionCounter(); return GRPC_ERROR_NONE; @@ -109,12 +109,13 @@ class ChannelDataImpl : public ChannelData { class CallDataImpl : public CallData { public: - void StartTransportStreamOpBatch(grpc_call_element* elem, + void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, TransportStreamOpBatch* op) override { // Incrementing the counter could be done from Init(), but we want // to test that the individual methods are actually called correctly. if (op->recv_initial_metadata() != nullptr) IncrementCallCounter(); - grpc_call_next_op(elem, op->op()); + grpc_call_next_op(exec_ctx, elem, op->op()); } }; diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index d4ee6b429f..bbf3da4663 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -454,13 +454,13 @@ class GrpclbEnd2endTest : public ::testing::Test { }; void SetNextResolution(const std::vector& address_data) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port); - grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri( addresses, i, lb_uri, address_data[i].is_balancer, @@ -470,9 +470,10 @@ class GrpclbEnd2endTest : public ::testing::Test { } grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args fake_result = {1, &fake_addresses}; - grpc_fake_resolver_response_generator_set_response(response_generator_, - &fake_result); - grpc_lb_addresses_destroy(addresses); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator_, &fake_result); + grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_exec_ctx_finish(&exec_ctx); } const std::vector GetBackendPorts(const size_t start_index = 0) const { diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index a494d6f519..7b62080b49 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -17,7 +17,6 @@ */ #include -#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -136,8 +135,5 @@ TEST_F(GrpclbTest, ParseResponseServerList) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - grpc_init(); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; + return RUN_ALL_TESTS(); } diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 64c53b1442..a469fbb7e3 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -562,7 +562,7 @@ static void perform_request(client_fixture* cf) { #define BALANCERS_NAME "lb.name" static void setup_client(const server_fixture* lb_server, const server_fixture* backends, client_fixture* cf) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; char* expected_target_names = nullptr; const char* backends_name = lb_server->servers_hostport; @@ -574,7 +574,7 @@ static void setup_client(const server_fixture* lb_server, grpc_lb_addresses* addresses = grpc_lb_addresses_create(1, nullptr); char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:%s", lb_server->servers_hostport); - grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri(addresses, 0, lb_uri, true, lb_server->balancer_name, nullptr); @@ -586,7 +586,7 @@ static void setup_client(const server_fixture* lb_server, grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* fake_result = grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1); - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(&exec_ctx, addresses); const grpc_arg new_args[] = { grpc_fake_transport_expected_targets_arg(expected_target_names), @@ -601,12 +601,13 @@ static void setup_client(const server_fixture* lb_server, grpc_fake_transport_security_credentials_create(); cf->client = grpc_secure_channel_create(fake_creds, cf->server_uri, args, nullptr); - grpc_fake_resolver_response_generator_set_response(response_generator, - fake_result); - grpc_channel_args_destroy(fake_result); - grpc_channel_credentials_unref(fake_creds); - grpc_channel_args_destroy(args); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, fake_result); + grpc_channel_args_destroy(&exec_ctx, fake_result); + grpc_channel_credentials_unref(&exec_ctx, fake_creds); + grpc_channel_args_destroy(&exec_ctx, args); grpc_fake_resolver_response_generator_unref(response_generator); + grpc_exec_ctx_finish(&exec_ctx); } static void teardown_client(client_fixture* cf) { diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 5c2c38c27d..a45c577320 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -311,9 +311,12 @@ static void BM_LameChannelCallCreateCoreSeparateBatch(benchmark::State& state) { } BENCHMARK(BM_LameChannelCallCreateCoreSeparateBatch); -static void FilterDestroy(void* arg, grpc_error* error) { gpr_free(arg); } +static void FilterDestroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + gpr_free(arg); +} -static void DoNothing(void* arg, grpc_error* error) {} +static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} class FakeClientChannelFactory : public grpc_client_channel_factory { public: @@ -321,12 +324,15 @@ class FakeClientChannelFactory : public grpc_client_channel_factory { private: static void NoRef(grpc_client_channel_factory* factory) {} - static void NoUnref(grpc_client_channel_factory* factory) {} - static grpc_subchannel* CreateSubchannel(grpc_client_channel_factory* factory, + static void NoUnref(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory) {} + static grpc_subchannel* CreateSubchannel(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, const grpc_subchannel_args* args) { return nullptr; } - static grpc_channel* CreateClientChannel(grpc_client_channel_factory* factory, + static grpc_channel* CreateClientChannel(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args) { @@ -360,32 +366,36 @@ struct Fixture { namespace dummy_filter { -static void StartTransportStreamOp(grpc_call_element* elem, +static void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* op) {} -static void StartTransportOp(grpc_channel_element* elem, +static void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) {} -static grpc_error* InitCallElem(grpc_call_element* elem, +static grpc_error* InitCallElem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void SetPollsetOrPollsetSet(grpc_call_element* elem, +static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) {} -static void DestroyCallElem(grpc_call_element* elem, +static void DestroyCallElem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_sched_closure) {} -grpc_error* InitChannelElem(grpc_channel_element* elem, +grpc_error* InitChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -void DestroyChannelElem(grpc_channel_element* elem) {} +void DestroyChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} -void GetChannelInfo(grpc_channel_element* elem, +void GetChannelInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, const grpc_channel_info* channel_info) {} static const grpc_channel_filter dummy_filter = {StartTransportStreamOp, @@ -412,38 +422,41 @@ size_t sizeof_stream; /* = sizeof(transport stream) */ const char* name; /* implementation of grpc_transport_init_stream */ -int InitStream(grpc_transport* self, grpc_stream* stream, - grpc_stream_refcount* refcount, const void* server_data, - gpr_arena* arena) { +int InitStream(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { return 0; } /* implementation of grpc_transport_set_pollset */ -void SetPollset(grpc_transport* self, grpc_stream* stream, - grpc_pollset* pollset) {} +void SetPollset(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_pollset* pollset) {} /* implementation of grpc_transport_set_pollset */ -void SetPollsetSet(grpc_transport* self, grpc_stream* stream, - grpc_pollset_set* pollset_set) {} +void SetPollsetSet(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_pollset_set* pollset_set) {} /* implementation of grpc_transport_perform_stream_op */ -void PerformStreamOp(grpc_transport* self, grpc_stream* stream, - grpc_transport_stream_op_batch* op) { - GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_NONE); +void PerformStreamOp(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_transport_stream_op_batch* op) { + GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_NONE); } /* implementation of grpc_transport_perform_op */ -void PerformOp(grpc_transport* self, grpc_transport_op* op) {} +void PerformOp(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_transport_op* op) {} /* implementation of grpc_transport_destroy_stream */ -void DestroyStream(grpc_transport* self, grpc_stream* stream, - grpc_closure* then_sched_closure) {} +void DestroyStream(grpc_exec_ctx* exec_ctx, grpc_transport* self, + grpc_stream* stream, grpc_closure* then_sched_closure) {} /* implementation of grpc_transport_destroy */ -void Destroy(grpc_transport* self) {} +void Destroy(grpc_exec_ctx* exec_ctx, grpc_transport* self) {} /* implementation of grpc_transport_get_endpoint */ -grpc_endpoint* GetEndpoint(grpc_transport* self) { return nullptr; } +grpc_endpoint* GetEndpoint(grpc_exec_ctx* exec_ctx, grpc_transport* self) { + return nullptr; +} static const grpc_transport_vtable dummy_transport_vtable = { 0, "dummy_http2", InitStream, @@ -459,8 +472,8 @@ class NoOp { public: class Op { public: - Op(NoOp* p, grpc_call_stack* s) {} - void Finish() {} + Op(grpc_exec_ctx* exec_ctx, NoOp* p, grpc_call_stack* s) {} + void Finish(grpc_exec_ctx* exec_ctx) {} }; }; @@ -476,11 +489,13 @@ class SendEmptyMetadata { class Op { public: - Op(SendEmptyMetadata* p, grpc_call_stack* s) { + Op(grpc_exec_ctx* exec_ctx, SendEmptyMetadata* p, grpc_call_stack* s) { grpc_metadata_batch_init(&batch_); p->op_payload_.send_initial_metadata.send_initial_metadata = &batch_; } - void Finish() { grpc_metadata_batch_destroy(&batch_); } + void Finish(grpc_exec_ctx* exec_ctx) { + grpc_metadata_batch_destroy(exec_ctx, &batch_); + } private: grpc_metadata_batch batch_; @@ -521,20 +536,20 @@ static void BM_IsolatedFilter(benchmark::State& state) { label << " #has_dummy_filter"; } - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; size_t channel_size = grpc_channel_stack_size( filters.size() == 0 ? nullptr : &filters[0], filters.size()); grpc_channel_stack* channel_stack = static_cast(gpr_zalloc(channel_size)); GPR_ASSERT(GRPC_LOG_IF_ERROR( "channel_stack_init", - grpc_channel_stack_init(1, FilterDestroy, channel_stack, &filters[0], - filters.size(), &channel_args, + grpc_channel_stack_init(&exec_ctx, 1, FilterDestroy, channel_stack, + &filters[0], filters.size(), &channel_args, fixture.flags & REQUIRES_TRANSPORT ? &dummy_transport::dummy_transport : nullptr, "CHANNEL", channel_stack))); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); grpc_call_stack* call_stack = static_cast(gpr_zalloc(channel_stack->call_stack_size)); grpc_millis deadline = GRPC_MILLIS_INF_FUTURE; @@ -553,12 +568,12 @@ static void BM_IsolatedFilter(benchmark::State& state) { call_args.arena = gpr_arena_create(kArenaSize); while (state.KeepRunning()) { GPR_TIMER_SCOPE("BenchmarkCycle", 0); - GRPC_ERROR_UNREF( - grpc_call_stack_init(channel_stack, 1, DoNothing, nullptr, &call_args)); - typename TestOp::Op op(&test_op_data, call_stack); - grpc_call_stack_destroy(call_stack, &final_info, nullptr); - op.Finish(); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_ERROR_UNREF(grpc_call_stack_init(&exec_ctx, channel_stack, 1, + DoNothing, nullptr, &call_args)); + typename TestOp::Op op(&exec_ctx, &test_op_data, call_stack); + grpc_call_stack_destroy(&exec_ctx, call_stack, &final_info, nullptr); + op.Finish(&exec_ctx); + grpc_exec_ctx_flush(&exec_ctx); // recreate arena every 64k iterations to avoid oom if (0 == (state.iterations() & 0xffff)) { gpr_arena_destroy(call_args.arena); @@ -566,8 +581,8 @@ static void BM_IsolatedFilter(benchmark::State& state) { } } gpr_arena_destroy(call_args.arena); - grpc_channel_stack_destroy(channel_stack); - + grpc_channel_stack_destroy(&exec_ctx, channel_stack); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(channel_stack); gpr_free(call_stack); @@ -617,55 +632,59 @@ typedef struct { grpc_call_combiner* call_combiner; } call_data; -static void StartTransportStreamOp(grpc_call_element* elem, +static void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = static_cast(elem->call_data); if (op->recv_initial_metadata) { GRPC_CALL_COMBINER_START( - calld->call_combiner, + exec_ctx, calld->call_combiner, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE, "recv_initial_metadata"); } if (op->recv_message) { - GRPC_CALL_COMBINER_START(calld->call_combiner, + GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE, "recv_message"); } - GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_NONE); } -static void StartTransportOp(grpc_channel_element* elem, +static void StartTransportOp(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } -static grpc_error* InitCallElem(grpc_call_element* elem, +static grpc_error* InitCallElem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = static_cast(elem->call_data); calld->call_combiner = args->call_combiner; return GRPC_ERROR_NONE; } -static void SetPollsetOrPollsetSet(grpc_call_element* elem, +static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_polling_entity* pollent) {} -static void DestroyCallElem(grpc_call_element* elem, +static void DestroyCallElem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_sched_closure) { - GRPC_CLOSURE_SCHED(then_sched_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, then_sched_closure, GRPC_ERROR_NONE); } -grpc_error* InitChannelElem(grpc_channel_element* elem, +grpc_error* InitChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -void DestroyChannelElem(grpc_channel_element* elem) {} +void DestroyChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} -void GetChannelInfo(grpc_channel_element* elem, +void GetChannelInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, const grpc_channel_info* channel_info) {} static const grpc_channel_filter isolated_call_filter = { @@ -692,8 +711,10 @@ class IsolatedCallFixture : public TrackCounters { builder, &isolated_call_filter::isolated_call_filter, nullptr, nullptr)); { - grpc_core::ExecCtx exec_ctx; - channel_ = grpc_channel_create_with_builder(builder, GRPC_CLIENT_CHANNEL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + channel_ = grpc_channel_create_with_builder(&exec_ctx, builder, + GRPC_CLIENT_CHANNEL); + grpc_exec_ctx_finish(&exec_ctx); } cq_ = grpc_completion_queue_create_for_next(nullptr); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 4b7310389c..3fff8b02d6 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -50,22 +50,22 @@ static grpc_slice MakeSlice(std::vector bytes) { static void BM_HpackEncoderInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_compressor c; while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); - grpc_chttp2_hpack_compressor_destroy(&c); - grpc_core::ExecCtx::Get()->Flush(); + grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_HpackEncoderInitDestroy); static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; - grpc_millis saved_now = grpc_core::ExecCtx::Get()->Now(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_millis saved_now = grpc_exec_ctx_now(&exec_ctx); grpc_metadata_batch b; grpc_metadata_batch_init(&b); @@ -85,13 +85,14 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { (size_t)1024, &stats, }; - grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); - grpc_slice_buffer_reset_and_unref_internal(&outbuf); - grpc_core::ExecCtx::Get()->Flush(); + grpc_chttp2_encode_header(&exec_ctx, &c, nullptr, 0, &b, &hopt, &outbuf); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &outbuf); + grpc_exec_ctx_flush(&exec_ctx); } - grpc_metadata_batch_destroy(&b); - grpc_chttp2_hpack_compressor_destroy(&c); - grpc_slice_buffer_destroy_internal(&outbuf); + grpc_metadata_batch_destroy(&exec_ctx, &b); + grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outbuf); + grpc_exec_ctx_finish(&exec_ctx); std::ostringstream label; label << "framing_bytes/iter:" @@ -108,16 +109,17 @@ BENCHMARK(BM_HpackEncoderEncodeDeadline); template static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; static bool logged_representative_output = false; grpc_metadata_batch b; grpc_metadata_batch_init(&b); - std::vector elems = Fixture::GetElems(); + std::vector elems = Fixture::GetElems(&exec_ctx); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); + "addmd", + grpc_metadata_batch_add_tail(&exec_ctx, &b, &storage[i], elems[i]))); } grpc_chttp2_hpack_compressor c; @@ -134,7 +136,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { (size_t)state.range(1), &stats, }; - grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); + grpc_chttp2_encode_header(&exec_ctx, &c, nullptr, 0, &b, &hopt, &outbuf); if (!logged_representative_output && state.iterations() > 3) { logged_representative_output = true; for (size_t i = 0; i < outbuf.count; i++) { @@ -143,12 +145,13 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { gpr_free(s); } } - grpc_slice_buffer_reset_and_unref_internal(&outbuf); - grpc_core::ExecCtx::Get()->Flush(); + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &outbuf); + grpc_exec_ctx_flush(&exec_ctx); } - grpc_metadata_batch_destroy(&b); - grpc_chttp2_hpack_compressor_destroy(&c); - grpc_slice_buffer_destroy_internal(&outbuf); + grpc_metadata_batch_destroy(&exec_ctx, &b); + grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outbuf); + grpc_exec_ctx_finish(&exec_ctx); std::ostringstream label; label << "framing_bytes/iter:" @@ -166,13 +169,15 @@ namespace hpack_encoder_fixtures { class EmptyBatch { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems() { return {}; } + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + return {}; + } }; class SingleStaticElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return {GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE}; } }; @@ -180,9 +185,9 @@ class SingleStaticElem { class SingleInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return {grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("abc")), + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("def")))}; } }; @@ -191,10 +196,10 @@ template class SingleInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { grpc_slice bytes = MakeBytes(); std::vector out = {grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), grpc_slice_intern(bytes))}; grpc_slice_unref(bytes); return out; @@ -213,9 +218,9 @@ class SingleInternedBinaryElem { class SingleInternedKeyElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return {grpc_mdelem_from_slices( - grpc_slice_intern(grpc_slice_from_static_string("abc")), + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_from_static_string("def"))}; } }; @@ -223,8 +228,9 @@ class SingleInternedKeyElem { class SingleNonInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems() { - return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + return {grpc_mdelem_from_slices(exec_ctx, + grpc_slice_from_static_string("abc"), grpc_slice_from_static_string("def"))}; } }; @@ -233,9 +239,9 @@ template class SingleNonInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector GetElems() { - return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc-bin"), - MakeBytes())}; + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + return {grpc_mdelem_from_slices( + exec_ctx, grpc_slice_from_static_string("abc-bin"), MakeBytes())}; } private: @@ -251,21 +257,21 @@ class SingleNonInternedBinaryElem { class RepresentativeClientInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( - GRPC_MDSTR_PATH, + exec_ctx, GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), - grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP, GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - GRPC_MDSTR_USER_AGENT, + exec_ctx, GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -277,18 +283,18 @@ class RepresentativeClientInitialMetadata { class MoreRepresentativeClientInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, - grpc_mdelem_from_slices(GRPC_MDSTR_PATH, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string( "/grpc.test.FooService/BarMethod"))), - grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_TRACE_BIN, + exec_ctx, GRPC_MDSTR_GRPC_TRACE_BIN, grpc_slice_from_static_string("\x00\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f" "\x10\x11\x12\x13\x14\x15\x16\x17\x18" @@ -297,7 +303,7 @@ class MoreRepresentativeClientInitialMetadata { "\x29\x2a\x2b\x2c\x2d\x2e\x2f" "\x30")), grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_TAGS_BIN, + exec_ctx, GRPC_MDSTR_GRPC_TAGS_BIN, grpc_slice_from_static_string("\x00\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f" "\x10\x11\x12\x13")), @@ -305,7 +311,7 @@ class MoreRepresentativeClientInitialMetadata { GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - GRPC_MDSTR_USER_AGENT, + exec_ctx, GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -314,7 +320,7 @@ class MoreRepresentativeClientInitialMetadata { class RepresentativeServerInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return {GRPC_MDELEM_STATUS_200, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP}; @@ -324,7 +330,7 @@ class RepresentativeServerInitialMetadata { class RepresentativeServerTrailingMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return {GRPC_MDELEM_GRPC_STATUS_0}; } }; @@ -425,45 +431,48 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, static void BM_HpackParserInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_parser p; while (state.KeepRunning()) { - grpc_chttp2_hpack_parser_init(&p); - grpc_chttp2_hpack_parser_destroy(&p); - grpc_core::ExecCtx::Get()->Flush(); + grpc_chttp2_hpack_parser_init(&exec_ctx, &p); + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_HpackParserInitDestroy); -static void UnrefHeader(void* user_data, grpc_mdelem md) { - GRPC_MDELEM_UNREF(md); +static void UnrefHeader(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_mdelem md) { + GRPC_MDELEM_UNREF(exec_ctx, md); } -template +template static void BM_HpackParserParseHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; std::vector init_slices = Fixture::GetInitSlices(); std::vector benchmark_slices = Fixture::GetBenchmarkSlices(); grpc_chttp2_hpack_parser p; - grpc_chttp2_hpack_parser_init(&p); + grpc_chttp2_hpack_parser_init(&exec_ctx, &p); p.on_header = OnHeader; p.on_header_user_data = nullptr; for (auto slice : init_slices) { - GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice)); } while (state.KeepRunning()) { for (auto slice : benchmark_slices) { - GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice)); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } for (auto slice : init_slices) grpc_slice_unref(slice); for (auto slice : benchmark_slices) grpc_slice_unref(slice); - grpc_chttp2_hpack_parser_destroy(&p); - + grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } @@ -760,7 +769,8 @@ class RepresentativeServerTrailingMetadata { static void free_timeout(void* p) { gpr_free(p); } // New implementation. -static void OnHeaderNew(void* user_data, grpc_mdelem md) { +static void OnHeaderNew(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_mdelem md) { if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT)) { grpc_millis* cached_timeout = static_cast(grpc_mdelem_get_user_data(md, free_timeout)); @@ -783,7 +793,7 @@ static void OnHeaderNew(void* user_data, grpc_mdelem md) { } } benchmark::DoNotOptimize(timeout); - GRPC_MDELEM_UNREF(md); + GRPC_MDELEM_UNREF(exec_ctx, md); } else { GPR_ASSERT(0); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index fcb1677d09..be4da4d0bd 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -58,7 +58,7 @@ class DummyEndpoint : public grpc_endpoint { ru_ = grpc_resource_user_create(Library::get().rq(), "dummy_endpoint"); } - void PushInput(grpc_slice slice) { + void PushInput(grpc_exec_ctx* exec_ctx, grpc_slice slice) { if (read_cb_ == nullptr) { GPR_ASSERT(!have_slice_); buffered_slice_ = slice; @@ -66,7 +66,7 @@ class DummyEndpoint : public grpc_endpoint { return; } grpc_slice_buffer_add(slices_, slice); - GRPC_CLOSURE_SCHED(read_cb_, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, read_cb_, GRPC_ERROR_NONE); read_cb_ = nullptr; } @@ -77,45 +77,50 @@ class DummyEndpoint : public grpc_endpoint { bool have_slice_ = false; grpc_slice buffered_slice_; - void QueueRead(grpc_slice_buffer* slices, grpc_closure* cb) { + void QueueRead(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* slices, + grpc_closure* cb) { GPR_ASSERT(read_cb_ == nullptr); if (have_slice_) { have_slice_ = false; grpc_slice_buffer_add(slices, buffered_slice_); - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); return; } read_cb_ = cb; slices_ = slices; } - static void read(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { - static_cast(ep)->QueueRead(slices, cb); + static void read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { + static_cast(ep)->QueueRead(exec_ctx, slices, cb); } - static void write(grpc_endpoint* ep, grpc_slice_buffer* slices, - grpc_closure* cb) { - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + static void write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { + GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); } static grpc_workqueue* get_workqueue(grpc_endpoint* ep) { return nullptr; } - static void add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} + static void add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) {} - static void add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) { - } + static void add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset_set* pollset) {} - static void delete_from_pollset_set(grpc_endpoint* ep, + static void delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, grpc_pollset_set* pollset) {} - static void shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_resource_user_shutdown(static_cast(ep)->ru_); - GRPC_CLOSURE_SCHED(static_cast(ep)->read_cb_, why); + static void shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { + grpc_resource_user_shutdown(exec_ctx, static_cast(ep)->ru_); + GRPC_CLOSURE_SCHED(exec_ctx, static_cast(ep)->read_cb_, + why); } - static void destroy(grpc_endpoint* ep) { - grpc_resource_user_unref(static_cast(ep)->ru_); + static void destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { + grpc_resource_user_unref(exec_ctx, static_cast(ep)->ru_); delete static_cast(ep); } @@ -131,24 +136,29 @@ class Fixture { Fixture(const grpc::ChannelArguments& args, bool client) { grpc_channel_args c_args = args.c_channel_args(); ep_ = new DummyEndpoint; - t_ = grpc_create_chttp2_transport(&c_args, ep_, client); - grpc_chttp2_transport_start_reading(t_, nullptr, nullptr); + t_ = grpc_create_chttp2_transport(exec_ctx(), &c_args, ep_, client); + grpc_chttp2_transport_start_reading(exec_ctx(), t_, nullptr, nullptr); FlushExecCtx(); } - void FlushExecCtx() { grpc_core::ExecCtx::Get()->Flush(); } + void FlushExecCtx() { grpc_exec_ctx_flush(&exec_ctx_); } - ~Fixture() { grpc_transport_destroy(t_); } + ~Fixture() { + grpc_transport_destroy(&exec_ctx_, t_); + grpc_exec_ctx_finish(&exec_ctx_); + } grpc_chttp2_transport* chttp2_transport() { return reinterpret_cast(t_); } grpc_transport* transport() { return t_; } + grpc_exec_ctx* exec_ctx() { return &exec_ctx_; } - void PushInput(grpc_slice slice) { ep_->PushInput(slice); } + void PushInput(grpc_slice slice) { ep_->PushInput(exec_ctx(), slice); } private: DummyEndpoint* ep_; + grpc_exec_ctx exec_ctx_ = GRPC_EXEC_CTX_INIT; grpc_transport* t_; }; @@ -165,8 +175,8 @@ std::unique_ptr MakeClosure( GRPC_CLOSURE_INIT(this, Execute, this, sched); } F f_; - static void Execute(void* arg, grpc_error* error) { - static_cast(arg)->f_(error); + static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static_cast(arg)->f_(exec_ctx, error); } }; return std::unique_ptr(new C(f, sched)); @@ -178,8 +188,8 @@ grpc_closure* MakeOnceClosure( struct C : public grpc_closure { C(const F& f) : f_(f) {} F f_; - static void Execute(void* arg, grpc_error* error) { - static_cast(arg)->f_(error); + static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static_cast(arg)->f_(exec_ctx, error); delete static_cast(arg); } }; @@ -210,22 +220,22 @@ class Stream { gpr_arena_destroy(arena_); arena_ = gpr_arena_create(4096); } - grpc_transport_init_stream(f_->transport(), + grpc_transport_init_stream(f_->exec_ctx(), f_->transport(), static_cast(stream_), &refcount_, nullptr, arena_); } - void DestroyThen(grpc_closure* closure) { + void DestroyThen(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { destroy_closure_ = closure; #ifndef NDEBUG - grpc_stream_unref(&refcount_, "DestroyThen"); + grpc_stream_unref(exec_ctx, &refcount_, "DestroyThen"); #else - grpc_stream_unref(&refcount_); + grpc_stream_unref(exec_ctx, &refcount_); #endif } - void Op(grpc_transport_stream_op_batch* op) { - grpc_transport_perform_stream_op(f_->transport(), + void Op(grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* op) { + grpc_transport_perform_stream_op(exec_ctx, f_->transport(), static_cast(stream_), op); } @@ -234,9 +244,10 @@ class Stream { } private: - static void FinishDestroy(void* arg, grpc_error* error) { + static void FinishDestroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { auto stream = static_cast(arg); - grpc_transport_destroy_stream(stream->f_->transport(), + grpc_transport_destroy_stream(exec_ctx, stream->f_->transport(), static_cast(stream->stream_), stream->destroy_closure_); gpr_event_set(&stream->done_, (void*)1); @@ -257,7 +268,6 @@ class Stream { static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -266,13 +276,14 @@ static void BM_StreamCreateDestroy(benchmark::State& state) { op.cancel_stream = true; op.payload = &op_payload; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - std::unique_ptr next = MakeClosure([&](grpc_error* error) { - if (!state.KeepRunning()) return; - s.Init(state); - s.Op(&op); - s.DestroyThen(next.get()); - }); - GRPC_CLOSURE_RUN(next.get(), GRPC_ERROR_NONE); + std::unique_ptr next = + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + if (!state.KeepRunning()) return; + s.Init(state); + s.Op(exec_ctx, &op); + s.DestroyThen(exec_ctx, next.get()); + }); + GRPC_CLOSURE_RUN(f.exec_ctx(), next.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); track_counters.Finish(state); } @@ -280,21 +291,21 @@ BENCHMARK(BM_StreamCreateDestroy); class RepresentativeClientInitialMetadata { public: - static std::vector GetElems() { + static std::vector GetElems(grpc_exec_ctx* exec_ctx) { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( - GRPC_MDSTR_PATH, + exec_ctx, GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), - grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP, GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - GRPC_MDSTR_USER_AGENT, + exec_ctx, GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -303,7 +314,6 @@ class RepresentativeClientInitialMetadata { template static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -320,33 +330,34 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { grpc_metadata_batch b; grpc_metadata_batch_init(&b); b.deadline = GRPC_MILLIS_INF_FUTURE; - std::vector elems = Metadata::GetElems(); + std::vector elems = Metadata::GetElems(f.exec_ctx()); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); + "addmd", + grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); } f.FlushExecCtx(); - start = MakeClosure([&](grpc_error* error) { + start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) return; s.Init(state); reset_op(); op.on_complete = done.get(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; - s.Op(&op); + s.Op(exec_ctx, &op); }); - done = MakeClosure([&](grpc_error* error) { + done = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(&op); - s.DestroyThen(start.get()); + s.Op(exec_ctx, &op); + s.DestroyThen(exec_ctx, start.get()); }); - GRPC_CLOSURE_SCHED(start.get(), GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(f.exec_ctx(), start.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); - grpc_metadata_batch_destroy(&b); + grpc_metadata_batch_destroy(f.exec_ctx(), &b); track_counters.Finish(state); } BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, @@ -354,7 +365,6 @@ BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -365,19 +375,21 @@ static void BM_TransportEmptyOp(benchmark::State& state) { memset(&op, 0, sizeof(op)); op.payload = &op_payload; }; - std::unique_ptr c = MakeClosure([&](grpc_error* error) { - if (!state.KeepRunning()) return; - reset_op(); - op.on_complete = c.get(); - s.Op(&op); - }); - GRPC_CLOSURE_SCHED(c.get(), GRPC_ERROR_NONE); + std::unique_ptr c = + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + if (!state.KeepRunning()) return; + reset_op(); + op.on_complete = c.get(); + s.Op(exec_ctx, &op); + }); + GRPC_CLOSURE_SCHED(f.exec_ctx(), c.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); reset_op(); op.cancel_stream = true; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(&op); - s.DestroyThen(MakeOnceClosure([](grpc_error* error) {})); + s.Op(f.exec_ctx(), &op); + s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); } @@ -387,7 +399,6 @@ std::vector> done_events; static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr(new Stream(&f)); s->Init(state); @@ -409,37 +420,39 @@ static void BM_TransportStreamSend(benchmark::State& state) { grpc_metadata_batch_init(&b); b.deadline = GRPC_MILLIS_INF_FUTURE; std::vector elems = - RepresentativeClientInitialMetadata::GetElems(); + RepresentativeClientInitialMetadata::GetElems(f.exec_ctx()); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); + "addmd", + grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); } gpr_event* bm_done = new gpr_event; gpr_event_init(bm_done); - std::unique_ptr c = MakeClosure([&](grpc_error* error) { - if (!state.KeepRunning()) { - gpr_event_set(bm_done, (void*)1); - return; - } - // force outgoing window to be yuge - s->chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); - f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); - grpc_slice_buffer_stream_init(&send_stream, &send_buffer, 0); - reset_op(); - op.on_complete = c.get(); - op.send_message = true; - op.payload->send_message.send_message = &send_stream.base; - s->Op(&op); - }); + std::unique_ptr c = + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + if (!state.KeepRunning()) { + gpr_event_set(bm_done, (void*)1); + return; + } + // force outgoing window to be yuge + s->chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); + f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); + grpc_slice_buffer_stream_init(&send_stream, &send_buffer, 0); + reset_op(); + op.on_complete = c.get(); + op.send_message = true; + op.payload->send_message.send_message = &send_stream.base; + s->Op(exec_ctx, &op); + }); reset_op(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; op.on_complete = c.get(); - s->Op(&op); + s->Op(f.exec_ctx(), &op); f.FlushExecCtx(); gpr_event_wait(bm_done, gpr_inf_future(GPR_CLOCK_REALTIME)); @@ -448,12 +461,13 @@ static void BM_TransportStreamSend(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s->Op(&op); - s->DestroyThen(MakeOnceClosure([](grpc_error* error) {})); + s->Op(f.exec_ctx(), &op); + s->DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); s.reset(); track_counters.Finish(state); - grpc_metadata_batch_destroy(&b); + grpc_metadata_batch_destroy(f.exec_ctx(), &b); grpc_slice_buffer_destroy(&send_buffer); } BENCHMARK(BM_TransportStreamSend)->Range(0, 128 * 1024 * 1024); @@ -517,7 +531,6 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -538,14 +551,16 @@ static void BM_TransportStreamRecv(benchmark::State& state) { grpc_metadata_batch_init(&b_recv); b.deadline = GRPC_MILLIS_INF_FUTURE; std::vector elems = - RepresentativeClientInitialMetadata::GetElems(); + RepresentativeClientInitialMetadata::GetElems(f.exec_ctx()); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); + "addmd", + grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); } - std::unique_ptr do_nothing = MakeClosure([](grpc_error* error) {}); + std::unique_ptr do_nothing = + MakeClosure([](grpc_exec_ctx* exec_ctx, grpc_error* error) {}); uint32_t received; @@ -554,49 +569,51 @@ static void BM_TransportStreamRecv(benchmark::State& state) { std::unique_ptr drain_continue; grpc_slice recv_slice; - std::unique_ptr c = MakeClosure([&](grpc_error* error) { - if (!state.KeepRunning()) return; - // force outgoing window to be yuge - s.chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); - f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); - received = 0; - reset_op(); - op.on_complete = do_nothing.get(); - op.recv_message = true; - op.payload->recv_message.recv_message = &recv_stream; - op.payload->recv_message.recv_message_ready = drain_start.get(); - s.Op(&op); - f.PushInput(grpc_slice_ref(incoming_data)); - }); - - drain_start = MakeClosure([&](grpc_error* error) { + std::unique_ptr c = + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + if (!state.KeepRunning()) return; + // force outgoing window to be yuge + s.chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); + f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); + received = 0; + reset_op(); + op.on_complete = do_nothing.get(); + op.recv_message = true; + op.payload->recv_message.recv_message = &recv_stream; + op.payload->recv_message.recv_message_ready = drain_start.get(); + s.Op(exec_ctx, &op); + f.PushInput(grpc_slice_ref(incoming_data)); + }); + + drain_start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (recv_stream == nullptr) { GPR_ASSERT(!state.KeepRunning()); return; } - GRPC_CLOSURE_RUN(drain.get(), GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(exec_ctx, drain.get(), GRPC_ERROR_NONE); }); - drain = MakeClosure([&](grpc_error* error) { + drain = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { do { if (received == recv_stream->length) { - grpc_byte_stream_destroy(recv_stream); - GRPC_CLOSURE_SCHED(c.get(), GRPC_ERROR_NONE); + grpc_byte_stream_destroy(exec_ctx, recv_stream); + GRPC_CLOSURE_SCHED(exec_ctx, c.get(), GRPC_ERROR_NONE); return; } - } while (grpc_byte_stream_next(recv_stream, recv_stream->length - received, + } while (grpc_byte_stream_next(exec_ctx, recv_stream, + recv_stream->length - received, drain_continue.get()) && GRPC_ERROR_NONE == - grpc_byte_stream_pull(recv_stream, &recv_slice) && + grpc_byte_stream_pull(exec_ctx, recv_stream, &recv_slice) && (received += GRPC_SLICE_LENGTH(recv_slice), - grpc_slice_unref_internal(recv_slice), true)); + grpc_slice_unref_internal(exec_ctx, recv_slice), true)); }); - drain_continue = MakeClosure([&](grpc_error* error) { - grpc_byte_stream_pull(recv_stream, &recv_slice); + drain_continue = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + grpc_byte_stream_pull(exec_ctx, recv_stream, &recv_slice); received += GRPC_SLICE_LENGTH(recv_slice); - grpc_slice_unref_internal(recv_slice); - GRPC_CLOSURE_RUN(drain.get(), GRPC_ERROR_NONE); + grpc_slice_unref_internal(exec_ctx, recv_slice); + GRPC_CLOSURE_RUN(exec_ctx, drain.get(), GRPC_ERROR_NONE); }); reset_op(); @@ -607,7 +624,7 @@ static void BM_TransportStreamRecv(benchmark::State& state) { op.payload->recv_initial_metadata.recv_initial_metadata_ready = do_nothing.get(); op.on_complete = c.get(); - s.Op(&op); + s.Op(f.exec_ctx(), &op); f.PushInput(SLICE_FROM_BUFFER( "\x00\x00\x00\x04\x00\x00\x00\x00\x00" // Generated using: @@ -625,12 +642,13 @@ static void BM_TransportStreamRecv(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(&op); - s.DestroyThen(MakeOnceClosure([](grpc_error* error) {})); + s.Op(f.exec_ctx(), &op); + s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); - grpc_metadata_batch_destroy(&b); - grpc_metadata_batch_destroy(&b_recv); + grpc_metadata_batch_destroy(f.exec_ctx(), &b); + grpc_metadata_batch_destroy(f.exec_ctx(), &b_recv); grpc_slice_unref(incoming_data); } BENCHMARK(BM_TransportStreamRecv)->Range(0, 128 * 1024 * 1024); diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index 4d5a82c3f6..2434d4e84e 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -34,7 +34,8 @@ auto& force_library_initialization = Library::get(); static void BM_NoOpExecCtx(benchmark::State& state) { TrackCounters track_counters; while (state.KeepRunning()) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx_finish(&exec_ctx); } track_counters.Finish(state); } @@ -42,16 +43,16 @@ BENCHMARK(BM_NoOpExecCtx); static void BM_WellFlushed(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_WellFlushed); -static void DoNothing(void* arg, grpc_error* error) {} +static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) { TrackCounters track_counters; @@ -68,13 +69,13 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { TrackCounters track_counters; grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { benchmark::DoNotOptimize(GRPC_CLOSURE_INIT( &c, DoNothing, nullptr, grpc_combiner_scheduler(combiner))); } - GRPC_COMBINER_UNREF(combiner, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAgainstCombiner); @@ -83,39 +84,41 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_RUN(&exec_ctx, &c, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureRunOnExecCtx); static void BM_ClosureCreateAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( + &exec_ctx, GRPC_CLOSURE_CREATE(DoNothing, nullptr, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureCreateAndRun); static void BM_ClosureInitAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure c; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( + &exec_ctx, GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAndRun); @@ -124,12 +127,12 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnExecCtx); @@ -140,13 +143,13 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnExecCtx); @@ -159,14 +162,14 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnExecCtx); @@ -176,13 +179,13 @@ static void BM_AcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { gpr_mu_lock(&mu); - DoNothing(nullptr, GRPC_ERROR_NONE); + DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); gpr_mu_unlock(&mu); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_AcquireMutex); @@ -192,16 +195,16 @@ static void BM_TryAcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { if (gpr_mu_trylock(&mu)) { - DoNothing(nullptr, GRPC_ERROR_NONE); + DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); gpr_mu_unlock(&mu); } else { abort(); } } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_TryAcquireMutex); @@ -210,13 +213,13 @@ static void BM_AcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { gpr_spinlock_lock(&mu); - DoNothing(nullptr, GRPC_ERROR_NONE); + DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); gpr_spinlock_unlock(&mu); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_AcquireSpinlock); @@ -225,16 +228,16 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { if (gpr_spinlock_trylock(&mu)) { - DoNothing(nullptr, GRPC_ERROR_NONE); + DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); gpr_spinlock_unlock(&mu); } else { abort(); } } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_TryAcquireSpinlock); @@ -244,13 +247,13 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - GRPC_COMBINER_UNREF(combiner, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnCombiner); @@ -262,14 +265,14 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - GRPC_COMBINER_UNREF(combiner, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnCombiner); @@ -283,15 +286,15 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - GRPC_COMBINER_UNREF(combiner, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnCombiner); @@ -306,15 +309,15 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - GRPC_COMBINER_UNREF(combiner1, "finished"); - GRPC_COMBINER_UNREF(combiner2, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); + GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnTwoCombiners); @@ -335,17 +338,17 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c4, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&c4, GRPC_ERROR_NONE); - grpc_core::ExecCtx::Get()->Flush(); + GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&exec_ctx, &c4, GRPC_ERROR_NONE); + grpc_exec_ctx_flush(&exec_ctx); } - GRPC_COMBINER_UNREF(combiner1, "finished"); - GRPC_COMBINER_UNREF(combiner2, "finished"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); + GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureSched4OnTwoCombiners); @@ -359,11 +362,13 @@ class Rescheduler { GRPC_CLOSURE_INIT(&closure_, Step, this, scheduler); } - void ScheduleFirst() { GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); } + void ScheduleFirst(grpc_exec_ctx* exec_ctx) { + GRPC_CLOSURE_SCHED(exec_ctx, &closure_, GRPC_ERROR_NONE); + } void ScheduleFirstAgainstDifferentScheduler( - grpc_closure_scheduler* scheduler) { - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(Step, this, scheduler), + grpc_exec_ctx* exec_ctx, grpc_closure_scheduler* scheduler) { + GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(Step, this, scheduler), GRPC_ERROR_NONE); } @@ -371,46 +376,47 @@ class Rescheduler { benchmark::State& state_; grpc_closure closure_; - static void Step(void* arg, grpc_error* error) { + static void Step(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { Rescheduler* self = static_cast(arg); if (self->state_.KeepRunning()) { - GRPC_CLOSURE_SCHED(&self->closure_, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(exec_ctx, &self->closure_, GRPC_ERROR_NONE); } } }; static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; Rescheduler r(state, grpc_schedule_on_exec_ctx); - r.ScheduleFirst(); - + r.ScheduleFirst(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnExecCtx); static void BM_ClosureReschedOnCombiner(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_scheduler(combiner)); - r.ScheduleFirst(); - grpc_core::ExecCtx::Get()->Flush(); - GRPC_COMBINER_UNREF(combiner, "finished"); - + r.ScheduleFirst(&exec_ctx); + grpc_exec_ctx_flush(&exec_ctx); + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombiner); static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_finally_scheduler(combiner)); - r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner)); - grpc_core::ExecCtx::Get()->Flush(); - GRPC_COMBINER_UNREF(combiner, "finished"); - + r.ScheduleFirstAgainstDifferentScheduler(&exec_ctx, + grpc_combiner_scheduler(combiner)); + grpc_exec_ctx_flush(&exec_ctx); + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombinerFinally); diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index 97242598f1..f0dede7333 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -66,7 +66,7 @@ static void BM_CreateDestroyCore(benchmark::State& state) { } BENCHMARK(BM_CreateDestroyCore); -static void DoneWithCompletionOnStack(void* arg, +static void DoneWithCompletionOnStack(grpc_exec_ctx* exec_ctx, void* arg, grpc_cq_completion* completion) {} class DummyTag final : public internal::CompletionQueueTag { @@ -81,11 +81,11 @@ static void BM_Pass1Cpp(benchmark::State& state) { while (state.KeepRunning()) { grpc_cq_completion completion; DummyTag dummy_tag; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag)); - grpc_cq_end_op(c_cq, &dummy_tag, GRPC_ERROR_NONE, DoneWithCompletionOnStack, - nullptr, &completion); - + grpc_cq_end_op(&exec_ctx, c_cq, &dummy_tag, GRPC_ERROR_NONE, + DoneWithCompletionOnStack, nullptr, &completion); + grpc_exec_ctx_finish(&exec_ctx); void* tag; bool ok; cq.Next(&tag, &ok); @@ -101,11 +101,11 @@ static void BM_Pass1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); - grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, - nullptr, &completion); - + grpc_cq_end_op(&exec_ctx, cq, nullptr, GRPC_ERROR_NONE, + DoneWithCompletionOnStack, nullptr, &completion); + grpc_exec_ctx_finish(&exec_ctx); grpc_completion_queue_next(cq, deadline, nullptr); } grpc_completion_queue_destroy(cq); @@ -120,11 +120,11 @@ static void BM_Pluck1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); - grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, - nullptr, &completion); - + grpc_cq_end_op(&exec_ctx, cq, nullptr, GRPC_ERROR_NONE, + DoneWithCompletionOnStack, nullptr, &completion); + grpc_exec_ctx_finish(&exec_ctx); grpc_completion_queue_pluck(cq, nullptr, deadline, nullptr); } grpc_completion_queue_destroy(cq); diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 874c834931..7ccebb55ee 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -43,8 +43,9 @@ static grpc_completion_queue* g_cq; static grpc_event_engine_vtable g_vtable; static const grpc_event_engine_vtable* g_old_vtable; -static void pollset_shutdown(grpc_pollset* ps, grpc_closure* closure) { - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); +static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, + grpc_closure* closure) { + GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } static void pollset_init(grpc_pollset* ps, gpr_mu** mu) { @@ -52,20 +53,25 @@ static void pollset_init(grpc_pollset* ps, gpr_mu** mu) { *mu = &ps->mu; } -static void pollset_destroy(grpc_pollset* ps) { gpr_mu_destroy(&ps->mu); } +static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* ps) { + gpr_mu_destroy(&ps->mu); +} -static grpc_error* pollset_kick(grpc_pollset* p, grpc_pollset_worker* worker) { +static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, + grpc_pollset_worker* worker) { return GRPC_ERROR_NONE; } /* Callback when the tag is dequeued from the completion queue. Does nothing */ -static void cq_done_cb(void* done_arg, grpc_cq_completion* cq_completion) { +static void cq_done_cb(grpc_exec_ctx* exec_ctx, void* done_arg, + grpc_cq_completion* cq_completion) { gpr_free(cq_completion); } /* Queues a completion tag if deadline is > 0. * Does nothing if deadline is 0 (i.e gpr_time_0(GPR_CLOCK_MONOTONIC)) */ -static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, +static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, + grpc_pollset_worker** worker, grpc_millis deadline) { if (deadline == 0) { gpr_log(GPR_DEBUG, "no-op"); @@ -74,9 +80,9 @@ static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, gpr_mu_unlock(&ps->mu); GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); - grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, + grpc_cq_end_op(exec_ctx, g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; } diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index d12f475a49..bbd8b3c339 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -246,14 +246,14 @@ template static void BM_ErrorGetStatus(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { grpc_status_code status; grpc_slice slice; - grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice, - nullptr, nullptr); + grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), + &status, &slice, nullptr, nullptr); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } @@ -261,13 +261,13 @@ template static void BM_ErrorGetStatusCode(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { grpc_status_code status; - grpc_error_get_status(fixture.error(), fixture.deadline(), &status, nullptr, - nullptr, nullptr); + grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), + &status, nullptr, nullptr, nullptr); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } @@ -275,13 +275,13 @@ template static void BM_ErrorHttpError(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { grpc_http2_error_code error; - grpc_error_get_status(fixture.error(), fixture.deadline(), nullptr, nullptr, - &error, nullptr); + grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), + nullptr, nullptr, &error, nullptr); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index d6d7d41e5e..5e72213823 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -177,13 +177,13 @@ class TrickledCHTTP2 : public EndpointPairFixture { } void Step(bool update_stats) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; inc_time(); size_t client_backlog = - grpc_trickle_endpoint_trickle(endpoint_pair_.client); + grpc_trickle_endpoint_trickle(&exec_ctx, endpoint_pair_.client); size_t server_backlog = - grpc_trickle_endpoint_trickle(endpoint_pair_.server); - + grpc_trickle_endpoint_trickle(&exec_ctx, endpoint_pair_.server); + grpc_exec_ctx_finish(&exec_ctx); if (update_stats) { UpdateStats((grpc_chttp2_transport*)client_transport_, &client_stats_, client_backlog); diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc index f1e7890fc0..73bce08466 100644 --- a/test/cpp/microbenchmarks/bm_metadata.cc +++ b/test/cpp/microbenchmarks/bm_metadata.cc @@ -90,11 +90,11 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlices); @@ -103,11 +103,11 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -119,13 +119,13 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex( TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_core::ExecCtx exec_ctx; - grpc_mdelem seed = grpc_mdelem_create(k, v, nullptr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem seed = grpc_mdelem_create(&exec_ctx, k, v, nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - GRPC_MDELEM_UNREF(seed); - + GRPC_MDELEM_UNREF(&exec_ctx, seed); + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -136,11 +136,11 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); track_counters.Finish(state); } @@ -152,12 +152,14 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create( - k, v, reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_create(&exec_ctx, k, v, + reinterpret_cast(backing_store))); } - + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlicesWithBackingStore); @@ -168,12 +170,14 @@ static void BM_MetadataFromInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create( - k, v, reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_create(&exec_ctx, k, v, + reinterpret_cast(backing_store))); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -186,12 +190,14 @@ static void BM_MetadataFromInternedKeyWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create( - k, v, reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_create(&exec_ctx, k, v, + reinterpret_cast(backing_store))); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); track_counters.Finish(state); } @@ -201,11 +207,11 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_200; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); track_counters.Finish(state); } @@ -216,11 +222,11 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed( TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_GZIP; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); } - + grpc_exec_ctx_finish(&exec_ctx); grpc_slice_unref(k); track_counters.Finish(state); } @@ -229,15 +235,16 @@ BENCHMARK(BM_MetadataFromStaticMetadataStringsNotIndexed); static void BM_MetadataRefUnrefExternal(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx exec_ctx; - grpc_mdelem el = grpc_mdelem_create( - grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), - reinterpret_cast(backing_store)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem el = + grpc_mdelem_create(&exec_ctx, grpc_slice_from_static_string("a"), + grpc_slice_from_static_string("b"), + reinterpret_cast(backing_store)); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(el); - + GRPC_MDELEM_UNREF(&exec_ctx, el); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefExternal); @@ -245,47 +252,47 @@ BENCHMARK(BM_MetadataRefUnrefExternal); static void BM_MetadataRefUnrefInterned(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); grpc_mdelem el = grpc_mdelem_create( - k, v, reinterpret_cast(backing_store)); + &exec_ctx, k, v, reinterpret_cast(backing_store)); grpc_slice_unref(k); grpc_slice_unref(v); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(el); - + GRPC_MDELEM_UNREF(&exec_ctx, el); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefInterned); static void BM_MetadataRefUnrefAllocated(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem el = - grpc_mdelem_create(grpc_slice_from_static_string("a"), + grpc_mdelem_create(&exec_ctx, grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(el); - + GRPC_MDELEM_UNREF(&exec_ctx, el); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefAllocated); static void BM_MetadataRefUnrefStatic(benchmark::State& state) { TrackCounters track_counters; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_mdelem el = - grpc_mdelem_create(GRPC_MDSTR_STATUS, GRPC_MDSTR_200, nullptr); + grpc_mdelem_create(&exec_ctx, GRPC_MDSTR_STATUS, GRPC_MDSTR_200, nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(el); - + GRPC_MDELEM_UNREF(&exec_ctx, el); + grpc_exec_ctx_finish(&exec_ctx); track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefStatic); diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index d9d5164cce..4da79693f1 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -41,8 +41,8 @@ auto& force_library_initialization = Library::get(); -static void shutdown_ps(void* ps, grpc_error* error) { - grpc_pollset_destroy(static_cast(ps)); +static void shutdown_ps(grpc_exec_ctx* exec_ctx, void* ps, grpc_error* error) { + grpc_pollset_destroy(exec_ctx, static_cast(ps)); } static void BM_CreateDestroyPollset(benchmark::State& state) { @@ -50,7 +50,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { size_t ps_sz = grpc_pollset_size(); grpc_pollset* ps = static_cast(gpr_malloc(ps_sz)); gpr_mu* mu; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); @@ -58,11 +58,11 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { memset(ps, 0, ps_sz); grpc_pollset_init(ps, &mu); gpr_mu_lock(mu); - grpc_pollset_shutdown(ps, &shutdown_ps_closure); + grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); } - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(ps); track_counters.Finish(state); } @@ -114,17 +114,17 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(mu); while (state.KeepRunning()) { - GRPC_ERROR_UNREF(grpc_pollset_work(ps, nullptr, 0)); + GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, nullptr, 0)); } grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(ps, &shutdown_ps_closure); + grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(ps); track_counters.Finish(state); } @@ -136,23 +136,24 @@ static void BM_PollAddFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_wakeup_fd wakeup_fd; GPR_ASSERT( GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&wakeup_fd))); grpc_fd* fd = grpc_fd_create(wakeup_fd.read_fd, "xxx"); while (state.KeepRunning()) { - grpc_pollset_add_fd(ps, fd); - grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_add_fd(&exec_ctx, ps, fd); + grpc_exec_ctx_flush(&exec_ctx); } - grpc_fd_orphan(fd, nullptr, nullptr, false /* already_closed */, "xxx"); + grpc_fd_orphan(&exec_ctx, fd, nullptr, nullptr, false /* already_closed */, + "xxx"); grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); gpr_mu_lock(mu); - grpc_pollset_shutdown(ps, &shutdown_ps_closure); + grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(ps); track_counters.Finish(state); } @@ -169,7 +170,7 @@ Closure* MakeClosure(F f, grpc_closure_scheduler* scheduler) { C(F f, grpc_closure_scheduler* scheduler) : f_(f) { GRPC_CLOSURE_INIT(this, C::cbfn, this, scheduler); } - static void cbfn(void* arg, grpc_error* error) { + static void cbfn(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { C* p = static_cast(arg); p->f_(); } @@ -218,11 +219,11 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_wakeup_fd wakeup_fd; GRPC_ERROR_UNREF(grpc_wakeup_fd_init(&wakeup_fd)); grpc_fd* wakeup = grpc_fd_create(wakeup_fd.read_fd, "wakeup_read"); - grpc_pollset_add_fd(ps, wakeup); + grpc_pollset_add_fd(&exec_ctx, ps, wakeup); bool done = false; Closure* continue_closure = MakeClosure( [&]() { @@ -232,23 +233,25 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { return; } GRPC_ERROR_UNREF(grpc_wakeup_fd_wakeup(&wakeup_fd)); - grpc_fd_notify_on_read(wakeup, continue_closure); + grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure); }, grpc_schedule_on_exec_ctx); GRPC_ERROR_UNREF(grpc_wakeup_fd_wakeup(&wakeup_fd)); - grpc_fd_notify_on_read(wakeup, continue_closure); + grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure); gpr_mu_lock(mu); while (!done) { - GRPC_ERROR_UNREF(grpc_pollset_work(ps, nullptr, GRPC_MILLIS_INF_FUTURE)); + GRPC_ERROR_UNREF( + grpc_pollset_work(&exec_ctx, ps, nullptr, GRPC_MILLIS_INF_FUTURE)); } - grpc_fd_orphan(wakeup, nullptr, nullptr, false /* already_closed */, "done"); + grpc_fd_orphan(&exec_ctx, wakeup, nullptr, nullptr, + false /* already_closed */, "done"); wakeup_fd.read_fd = 0; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(ps, &shutdown_ps_closure); + grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_finish(&exec_ctx); grpc_wakeup_fd_destroy(&wakeup_fd); gpr_free(ps); track_counters.Finish(state); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index d1ede755a5..7e20843875 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -166,7 +166,7 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add server endpoint to server_ * */ @@ -174,19 +174,20 @@ class EndpointPairFixture : public BaseFixture { const grpc_channel_args* server_args = grpc_server_get_channel_args(server_->c_server()); server_transport_ = grpc_create_chttp2_transport( - server_args, endpoints.server, false /* is_client */); + &exec_ctx, server_args, endpoints.server, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server_->c_server(), &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(endpoints.server, pollsets[i]); + grpc_endpoint_add_to_pollset(&exec_ctx, endpoints.server, pollsets[i]); } - grpc_server_setup_transport(server_->c_server(), server_transport_, - nullptr, server_args); - grpc_chttp2_transport_start_reading(server_transport_, nullptr, nullptr); + grpc_server_setup_transport(&exec_ctx, server_->c_server(), + server_transport_, nullptr, server_args); + grpc_chttp2_transport_start_reading(&exec_ctx, server_transport_, nullptr, + nullptr); } /* create channel */ @@ -196,15 +197,19 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonChannelArguments(&args); grpc_channel_args c_args = args.c_channel_args(); - client_transport_ = - grpc_create_chttp2_transport(&c_args, endpoints.client, true); + client_transport_ = grpc_create_chttp2_transport(&exec_ctx, &c_args, + endpoints.client, true); GPR_ASSERT(client_transport_); - grpc_channel* channel = grpc_channel_create( - "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport_); - grpc_chttp2_transport_start_reading(client_transport_, nullptr, nullptr); + grpc_channel* channel = + grpc_channel_create(&exec_ctx, "target", &c_args, + GRPC_CLIENT_DIRECT_CHANNEL, client_transport_); + grpc_chttp2_transport_start_reading(&exec_ctx, client_transport_, nullptr, + nullptr); channel_ = CreateChannelInternal("", channel); } + + grpc_exec_ctx_finish(&exec_ctx); } virtual ~EndpointPairFixture() { diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 3481d9d1aa..6f1f0c44b9 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -149,33 +149,33 @@ struct ArgsStruct { std::string expected_lb_policy; }; -void ArgsInit(ArgsStruct* args) { +void ArgsInit(grpc_exec_ctx* exec_ctx, ArgsStruct* args) { gpr_event_init(&args->ev); args->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); args->lock = grpc_combiner_create(); gpr_atm_rel_store(&args->done_atm, 0); args->channel_args = nullptr; } -void DoNothing(void* arg, grpc_error* error) {} +void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -void ArgsFinish(ArgsStruct* args) { +void ArgsFinish(grpc_exec_ctx* exec_ctx, ArgsStruct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, TestDeadline())); - grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); - grpc_pollset_set_destroy(args->pollset_set); + grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_destroy(exec_ctx, args->pollset_set); grpc_closure DoNothing_cb; GRPC_CLOSURE_INIT(&DoNothing_cb, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(args->pollset, &DoNothing_cb); + grpc_pollset_shutdown(exec_ctx, args->pollset, &DoNothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_channel_args_destroy(args->channel_args); - grpc_core::ExecCtx::Get()->Flush(); - grpc_pollset_destroy(args->pollset); + grpc_channel_args_destroy(exec_ctx, args->channel_args); + grpc_exec_ctx_flush(exec_ctx); + grpc_pollset_destroy(exec_ctx, args->pollset); gpr_free(args->pollset); - GRPC_COMBINER_UNREF(args->lock, nullptr); + GRPC_COMBINER_UNREF(exec_ctx, args->lock, NULL); } gpr_timespec NSecondDeadline(int seconds) { @@ -196,13 +196,14 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { time_left.tv_sec, time_left.tv_nsec); GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0); grpc_pollset_worker* worker = nullptr; - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(args->mu); GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(args->pollset, &worker, + grpc_pollset_work(&exec_ctx, args->pollset, &worker, grpc_timespec_to_millis_round_up( NSecondDeadline(1)))); gpr_mu_unlock(args->mu); + grpc_exec_ctx_finish(&exec_ctx); } gpr_event_set(&args->ev, (void*)1); } @@ -234,7 +235,8 @@ void CheckLBPolicyResultLocked(grpc_channel_args* channel_args, } } -void CheckResolverResultLocked(void* argsp, grpc_error* err) { +void CheckResolverResultLocked(grpc_exec_ctx* exec_ctx, void* argsp, + grpc_error* err) { ArgsStruct* args = (ArgsStruct*)argsp; grpc_channel_args* channel_args = args->channel_args; const grpc_arg* channel_arg = @@ -270,14 +272,15 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) { } gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", + grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); gpr_mu_unlock(args->mu); } TEST(ResolverComponentTest, TestResolvesRelevantRecords) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; ArgsStruct args; - ArgsInit(&args); + ArgsInit(&exec_ctx, &args); args.expected_addrs = ParseExpectedAddrs(FLAGS_expected_addrs); args.expected_service_config_string = FLAGS_expected_chosen_service_config; args.expected_lb_policy = FLAGS_expected_lb_policy; @@ -287,18 +290,19 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecords) { FLAGS_local_dns_server_address.c_str(), FLAGS_target_name.c_str())); // create resolver and resolve - grpc_resolver* resolver = - grpc_resolver_create(whole_uri, nullptr, args.pollset_set, args.lock); + grpc_resolver* resolver = grpc_resolver_create(&exec_ctx, whole_uri, nullptr, + args.pollset_set, args.lock); gpr_free(whole_uri); grpc_closure on_resolver_result_changed; GRPC_CLOSURE_INIT(&on_resolver_result_changed, CheckResolverResultLocked, (void*)&args, grpc_combiner_scheduler(args.lock)); - grpc_resolver_next_locked(resolver, &args.channel_args, + grpc_resolver_next_locked(&exec_ctx, resolver, &args.channel_args, &on_resolver_result_changed); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); PollPollsetUntilRequestDone(&args); - GRPC_RESOLVER_UNREF(resolver, nullptr); - ArgsFinish(&args); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, NULL); + ArgsFinish(&exec_ctx, &args); + grpc_exec_ctx_finish(&exec_ctx); } } // namespace diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 0b9dc83f2b..1c6f44dd7d 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -82,26 +82,27 @@ class EndpointPairFixture { ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add server endpoint to server_ */ { const grpc_channel_args* server_args = grpc_server_get_channel_args(server_->c_server()); grpc_transport* transport = grpc_create_chttp2_transport( - server_args, endpoints.server, false /* is_client */); + &exec_ctx, server_args, endpoints.server, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server_->c_server(), &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(endpoints.server, pollsets[i]); + grpc_endpoint_add_to_pollset(&exec_ctx, endpoints.server, pollsets[i]); } - grpc_server_setup_transport(server_->c_server(), transport, nullptr, - server_args); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + grpc_server_setup_transport(&exec_ctx, server_->c_server(), transport, + nullptr, server_args); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, + nullptr); } /* create channel */ @@ -111,15 +112,18 @@ class EndpointPairFixture { ApplyCommonChannelArguments(&args); grpc_channel_args c_args = args.c_channel_args(); - grpc_transport* transport = - grpc_create_chttp2_transport(&c_args, endpoints.client, true); + grpc_transport* transport = grpc_create_chttp2_transport( + &exec_ctx, &c_args, endpoints.client, true); GPR_ASSERT(transport); grpc_channel* channel = grpc_channel_create( - "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + &exec_ctx, "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, + nullptr); channel_ = CreateChannelInternal("", channel); } + + grpc_exec_ctx_finish(&exec_ctx); } virtual ~EndpointPairFixture() { diff --git a/test/cpp/server/server_builder_test.cc b/test/cpp/server/server_builder_test.cc index 694ce549c0..d18459cec9 100644 --- a/test/cpp/server/server_builder_test.cc +++ b/test/cpp/server/server_builder_test.cc @@ -22,8 +22,6 @@ #include #include -#include - #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -79,8 +77,5 @@ TEST(ServerBuilderTest, CreateServerRepeatedPortWithDisallowedReusePort) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - grpc_init(); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; + return RUN_ALL_TESTS(); } diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc index d603b289c8..8fb51bc663 100644 --- a/test/cpp/util/byte_buffer_test.cc +++ b/test/cpp/util/byte_buffer_test.cc @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -110,8 +109,5 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - grpc_init(); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; + return RUN_ALL_TESTS(); } diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc index c2e55f3374..8a8962d7ee 100644 --- a/test/cpp/util/slice_test.cc +++ b/test/cpp/util/slice_test.cc @@ -18,7 +18,6 @@ #include -#include #include #include @@ -128,8 +127,5 @@ TEST_F(SliceTest, Cslice) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - grpc_init(); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; + return RUN_ALL_TESTS(); } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 7847b8ed1d..355f3f4e23 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -395,7 +395,7 @@ print >> C, 'static uint8_t g_bytes[] = {%s};' % ( ','.join('%d' % ord(c) for c in ''.join(all_strs))) print >> C print >> C, 'static void static_ref(void *unused) {}' -print >> C, 'static void static_unref(void *unused) {}' +print >> C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' print >> C, ('static const grpc_slice_refcount_vtable static_sub_vtable = ' '{static_ref, static_unref, grpc_slice_default_eq_impl, ' 'grpc_slice_default_hash_impl};') diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index d439d99a8c..072a677615 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -150,11 +150,11 @@ def gen_bucket_code(histogram): code = 'value = GPR_CLAMP(value, 0, %d);\n' % histogram.max map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: - code += ('GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, value);\n' + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) else: code += 'if (value < %d) {\n' % first_nontrivial - code += ('GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, value);\n' + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) code += 'return;\n' code += '}' @@ -168,11 +168,11 @@ def gen_bucket_code(histogram): code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d;\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial) code += '_bkt.dbl = grpc_stats_table_%d[bucket];\n' % bounds_idx code += 'bucket -= (_val.uint < _bkt.uint);\n' - code += 'GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, bucket);\n' % histogram.name.upper() + code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, bucket);\n' % histogram.name.upper() code += 'return;\n' code += '}\n' - code += 'GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_%d, %d));\n' % (bounds_idx, histogram.buckets) + code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_%d, %d));\n' % (bounds_idx, histogram.buckets) return (code, bounds_idx) # utility: print a big comment block into a set of files @@ -240,13 +240,13 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "} grpc_stats_histogram_constants;" for ctr in inst_map['Counter']: - print >>H, ("#define GRPC_STATS_INC_%s() " + - "GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_%s)") % ( + print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx) " + + "GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)") % ( ctr.name.upper(), ctr.name.upper()) for histogram in inst_map['Histogram']: - print >>H, "#define GRPC_STATS_INC_%s(value) grpc_stats_inc_%s( (int)(value))" % ( + print >>H, "#define GRPC_STATS_INC_%s(exec_ctx, value) grpc_stats_inc_%s((exec_ctx), (int)(value))" % ( histogram.name.upper(), histogram.name.lower()) - print >>H, "void grpc_stats_inc_%s(int x);" % histogram.name.lower() + print >>H, "void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int x);" % histogram.name.lower() for i, tbl in enumerate(static_tables): print >>H, "extern const %s grpc_stats_table_%d[%d];" % (tbl[0], i, len(tbl[1])) @@ -254,7 +254,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) print >>H, "extern const int *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) - print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(int x);" % len(inst_map['Histogram']) + print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x);" % len(inst_map['Histogram']) print >>H print >>H, "#ifdef __cplusplus" @@ -309,7 +309,7 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C: tbl[0], i, len(tbl[1]), ','.join('%s' % x for x in tbl[1])) for histogram, code in zip(inst_map['Histogram'], histo_code): - print >>C, ("void grpc_stats_inc_%s(int value) {%s}") % ( + print >>C, ("void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int value) {%s}") % ( histogram.name.lower(), code) @@ -319,7 +319,7 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C: len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) print >>C, "const int *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) - print >>C, "void (*const grpc_stats_inc_histogram[%d])(int x) = {%s};" % ( + print >>C, "void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x) = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_inc_%s' % histogram.name.lower() for histogram in inst_map['Histogram'])) # patch qps_test bigquery schema -- cgit v1.2.3 From 8cf1470a51ea276ca84825e7495d4ee24743540d Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 6 Dec 2017 09:47:54 -0800 Subject: Revert "Revert "All instances of exec_ctx being passed around in src/core removed"" --- include/grpc++/support/channel_arguments.h | 2 +- include/grpc/impl/codegen/grpc_types.h | 2 +- include/grpc/impl/codegen/slice.h | 2 +- include/grpc/slice_buffer.h | 3 +- include/grpc/support/tls.h | 6 + include/grpc/support/tls_gcc.h | 5 + include/grpc/support/tls_msvc.h | 9 + include/grpc/support/tls_pthread.h | 9 + .../ext/filters/client_channel/backup_poller.cc | 47 +- .../ext/filters/client_channel/backup_poller.h | 4 +- .../filters/client_channel/channel_connectivity.cc | 52 +- .../ext/filters/client_channel/client_channel.cc | 409 ++++---- .../ext/filters/client_channel/client_channel.h | 8 +- .../client_channel/client_channel_factory.cc | 23 +- .../client_channel/client_channel_factory.h | 19 +- .../client_channel/client_channel_plugin.cc | 13 +- src/core/ext/filters/client_channel/connector.cc | 13 +- src/core/ext/filters/client_channel/connector.h | 14 +- .../client_channel/http_connect_handshaker.cc | 84 +- src/core/ext/filters/client_channel/http_proxy.cc | 18 +- src/core/ext/filters/client_channel/lb_policy.cc | 79 +- src/core/ext/filters/client_channel/lb_policy.h | 80 +- .../grpclb/client_load_reporting_filter.cc | 27 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 434 ++++---- .../lb_policy/grpclb/grpclb_channel.cc | 6 +- .../lb_policy/grpclb/grpclb_channel.h | 4 +- .../lb_policy/grpclb/grpclb_channel_secure.cc | 10 +- .../lb_policy/pick_first/pick_first.cc | 190 ++-- .../lb_policy/round_robin/round_robin.cc | 140 ++- .../client_channel/lb_policy/subchannel_list.cc | 54 +- .../client_channel/lb_policy/subchannel_list.h | 18 +- .../filters/client_channel/lb_policy_factory.cc | 15 +- .../ext/filters/client_channel/lb_policy_factory.h | 11 +- .../filters/client_channel/lb_policy_registry.cc | 4 +- .../filters/client_channel/lb_policy_registry.h | 2 +- .../ext/filters/client_channel/proxy_mapper.cc | 14 +- src/core/ext/filters/client_channel/proxy_mapper.h | 14 +- .../client_channel/proxy_mapper_registry.cc | 30 +- .../filters/client_channel/proxy_mapper_registry.h | 6 +- src/core/ext/filters/client_channel/resolver.cc | 24 +- src/core/ext/filters/client_channel/resolver.h | 31 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 94 +- .../resolver/dns/c_ares/grpc_ares_ev_driver.h | 6 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 52 +- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 70 +- .../resolver/dns/c_ares/grpc_ares_wrapper.h | 12 +- .../dns/c_ares/grpc_ares_wrapper_fallback.cc | 20 +- .../resolver/dns/native/dns_resolver.cc | 90 +- .../client_channel/resolver/fake/fake_resolver.cc | 52 +- .../client_channel/resolver/fake/fake_resolver.h | 2 +- .../resolver/sockaddr/sockaddr_resolver.cc | 55 +- .../ext/filters/client_channel/resolver_factory.cc | 5 +- .../ext/filters/client_channel/resolver_factory.h | 6 +- .../filters/client_channel/resolver_registry.cc | 27 +- .../ext/filters/client_channel/resolver_registry.h | 7 +- src/core/ext/filters/client_channel/subchannel.cc | 239 ++--- src/core/ext/filters/client_channel/subchannel.h | 75 +- .../ext/filters/client_channel/subchannel_index.cc | 63 +- .../ext/filters/client_channel/subchannel_index.h | 12 +- src/core/ext/filters/client_channel/uri_parser.cc | 28 +- src/core/ext/filters/client_channel/uri_parser.h | 3 +- src/core/ext/filters/deadline/deadline_filter.cc | 112 +- src/core/ext/filters/deadline/deadline_filter.h | 10 +- .../ext/filters/http/client/http_client_filter.cc | 125 +-- src/core/ext/filters/http/http_filters_plugin.cc | 6 +- .../message_compress/message_compress_filter.cc | 126 +-- .../ext/filters/http/server/http_server_filter.cc | 118 +-- .../load_reporting/server_load_reporting_filter.cc | 33 +- .../load_reporting/server_load_reporting_plugin.cc | 2 +- src/core/ext/filters/max_age/max_age_filter.cc | 101 +- .../filters/message_size/message_size_filter.cc | 36 +- .../workaround_cronet_compression_filter.cc | 23 +- .../transport/chttp2/client/chttp2_connector.cc | 70 +- .../chttp2/client/insecure/channel_create.cc | 32 +- .../chttp2/client/insecure/channel_create_posix.cc | 16 +- .../chttp2/client/secure/secure_channel_create.cc | 51 +- .../ext/transport/chttp2/server/chttp2_server.cc | 108 +- .../ext/transport/chttp2/server/chttp2_server.h | 3 +- .../chttp2/server/insecure/server_chttp2.cc | 6 +- .../chttp2/server/insecure/server_chttp2_posix.cc | 17 +- .../chttp2/server/secure/server_secure_chttp2.cc | 11 +- .../ext/transport/chttp2/transport/bin_decoder.cc | 14 +- .../ext/transport/chttp2/transport/bin_decoder.h | 5 +- .../ext/transport/chttp2/transport/bin_encoder.h | 2 +- .../transport/chttp2/transport/chttp2_transport.cc | 1088 +++++++++----------- .../transport/chttp2/transport/chttp2_transport.h | 7 +- .../ext/transport/chttp2/transport/flow_control.cc | 15 +- .../ext/transport/chttp2/transport/flow_control.h | 7 +- .../ext/transport/chttp2/transport/frame_data.cc | 62 +- .../ext/transport/chttp2/transport/frame_data.h | 7 +- .../ext/transport/chttp2/transport/frame_goaway.cc | 5 +- .../ext/transport/chttp2/transport/frame_goaway.h | 3 +- .../ext/transport/chttp2/transport/frame_ping.cc | 11 +- .../ext/transport/chttp2/transport/frame_ping.h | 2 +- .../transport/chttp2/transport/frame_rst_stream.cc | 5 +- .../transport/chttp2/transport/frame_rst_stream.h | 3 +- .../transport/chttp2/transport/frame_settings.cc | 5 +- .../transport/chttp2/transport/frame_settings.h | 3 +- .../chttp2/transport/frame_window_update.cc | 16 +- .../chttp2/transport/frame_window_update.h | 8 +- .../transport/chttp2/transport/hpack_encoder.cc | 144 ++- .../ext/transport/chttp2/transport/hpack_encoder.h | 6 +- .../ext/transport/chttp2/transport/hpack_parser.cc | 546 ++++------ .../ext/transport/chttp2/transport/hpack_parser.h | 17 +- .../ext/transport/chttp2/transport/hpack_table.cc | 32 +- .../ext/transport/chttp2/transport/hpack_table.h | 13 +- .../chttp2/transport/incoming_metadata.cc | 19 +- .../transport/chttp2/transport/incoming_metadata.h | 9 +- src/core/ext/transport/chttp2/transport/internal.h | 106 +- src/core/ext/transport/chttp2/transport/parsing.cc | 185 ++-- src/core/ext/transport/chttp2/transport/writing.cc | 121 ++- .../cronet/client/secure/cronet_channel_create.cc | 5 +- .../transport/cronet/transport/cronet_transport.cc | 173 ++-- src/core/ext/transport/inproc/inproc_transport.cc | 342 +++--- src/core/lib/backoff/backoff.cc | 10 +- src/core/lib/backoff/backoff.h | 6 +- src/core/lib/channel/channel_args.cc | 16 +- src/core/lib/channel/channel_args.h | 9 +- src/core/lib/channel/channel_stack.cc | 46 +- src/core/lib/channel/channel_stack.h | 64 +- src/core/lib/channel/channel_stack_builder.cc | 25 +- src/core/lib/channel/channel_stack_builder.h | 11 +- src/core/lib/channel/connected_channel.cc | 57 +- src/core/lib/channel/connected_channel.h | 3 +- src/core/lib/channel/handshaker.cc | 77 +- src/core/lib/channel/handshaker.h | 33 +- src/core/lib/channel/handshaker_factory.cc | 12 +- src/core/lib/channel/handshaker_factory.h | 12 +- src/core/lib/channel/handshaker_registry.cc | 22 +- src/core/lib/channel/handshaker_registry.h | 5 +- src/core/lib/compression/message_compress.cc | 42 +- src/core/lib/compression/message_compress.h | 6 +- .../lib/compression/stream_compression_gzip.cc | 20 +- src/core/lib/debug/stats.cc | 6 +- src/core/lib/debug/stats.h | 20 +- src/core/lib/debug/stats_data.cc | 201 ++-- src/core/lib/debug/stats_data.h | 540 +++++----- src/core/lib/http/httpcli.cc | 127 +-- src/core/lib/http/httpcli.h | 27 +- src/core/lib/http/httpcli_security_connector.cc | 55 +- src/core/lib/iomgr/block_annotate.h | 19 +- src/core/lib/iomgr/call_combiner.cc | 31 +- src/core/lib/iomgr/call_combiner.h | 40 +- src/core/lib/iomgr/closure.h | 58 +- src/core/lib/iomgr/combiner.cc | 128 ++- src/core/lib/iomgr/combiner.h | 12 +- src/core/lib/iomgr/endpoint.cc | 36 +- src/core/lib/iomgr/endpoint.h | 41 +- src/core/lib/iomgr/endpoint_pair_posix.cc | 7 +- src/core/lib/iomgr/endpoint_pair_windows.cc | 10 +- src/core/lib/iomgr/error.cc | 6 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 196 ++-- src/core/lib/iomgr/ev_epollex_linux.cc | 238 ++--- src/core/lib/iomgr/ev_epollsig_linux.cc | 180 ++-- src/core/lib/iomgr/ev_poll_posix.cc | 199 ++-- src/core/lib/iomgr/ev_posix.cc | 80 +- src/core/lib/iomgr/ev_posix.h | 72 +- src/core/lib/iomgr/exec_ctx.cc | 124 +-- src/core/lib/iomgr/exec_ctx.h | 182 +++- src/core/lib/iomgr/executor.cc | 58 +- src/core/lib/iomgr/executor.h | 6 +- src/core/lib/iomgr/fork_posix.cc | 17 +- src/core/lib/iomgr/iocp_windows.cc | 30 +- src/core/lib/iomgr/iocp_windows.h | 3 +- src/core/lib/iomgr/iomgr.cc | 115 ++- src/core/lib/iomgr/iomgr.h | 6 +- src/core/lib/iomgr/iomgr_uv.cc | 5 +- src/core/lib/iomgr/lockfree_event.cc | 15 +- src/core/lib/iomgr/lockfree_event.h | 6 +- src/core/lib/iomgr/polling_entity.cc | 16 +- src/core/lib/iomgr/polling_entity.h | 6 +- src/core/lib/iomgr/pollset.h | 9 +- src/core/lib/iomgr/pollset_set.h | 15 +- src/core/lib/iomgr/pollset_set_uv.cc | 15 +- src/core/lib/iomgr/pollset_set_windows.cc | 15 +- src/core/lib/iomgr/pollset_uv.cc | 17 +- src/core/lib/iomgr/pollset_windows.cc | 29 +- src/core/lib/iomgr/resolve_address.h | 3 +- src/core/lib/iomgr/resolve_address_posix.cc | 20 +- src/core/lib/iomgr/resolve_address_uv.cc | 15 +- src/core/lib/iomgr/resolve_address_windows.cc | 15 +- src/core/lib/iomgr/resource_quota.cc | 182 ++-- src/core/lib/iomgr/resource_quota.h | 25 +- src/core/lib/iomgr/socket_factory_posix.cc | 2 +- src/core/lib/iomgr/socket_mutator.cc | 2 +- src/core/lib/iomgr/socket_windows.cc | 19 +- src/core/lib/iomgr/socket_windows.h | 9 +- src/core/lib/iomgr/tcp_client.h | 3 +- src/core/lib/iomgr/tcp_client_posix.cc | 64 +- src/core/lib/iomgr/tcp_client_posix.h | 3 +- src/core/lib/iomgr/tcp_client_uv.cc | 37 +- src/core/lib/iomgr/tcp_client_windows.cc | 45 +- src/core/lib/iomgr/tcp_posix.cc | 262 +++-- src/core/lib/iomgr/tcp_posix.h | 7 +- src/core/lib/iomgr/tcp_server.h | 15 +- src/core/lib/iomgr/tcp_server_posix.cc | 64 +- src/core/lib/iomgr/tcp_server_uv.cc | 57 +- src/core/lib/iomgr/tcp_server_windows.cc | 58 +- src/core/lib/iomgr/tcp_uv.cc | 99 +- src/core/lib/iomgr/tcp_windows.cc | 93 +- src/core/lib/iomgr/tcp_windows.h | 2 +- src/core/lib/iomgr/timer.h | 13 +- src/core/lib/iomgr/timer_generic.cc | 47 +- src/core/lib/iomgr/timer_manager.cc | 30 +- src/core/lib/iomgr/timer_uv.cc | 26 +- src/core/lib/iomgr/udp_server.cc | 83 +- src/core/lib/iomgr/udp_server.h | 17 +- src/core/lib/security/context/security_context.cc | 17 +- .../credentials/composite/composite_credentials.cc | 51 +- src/core/lib/security/credentials/credentials.cc | 73 +- src/core/lib/security/credentials/credentials.h | 59 +- .../security/credentials/credentials_metadata.cc | 4 +- .../security/credentials/fake/fake_credentials.cc | 36 +- .../google_default/google_default_credentials.cc | 58 +- .../security/credentials/iam/iam_credentials.cc | 22 +- .../security/credentials/jwt/jwt_credentials.cc | 34 +- .../lib/security/credentials/jwt/jwt_credentials.h | 3 +- .../lib/security/credentials/jwt/jwt_verifier.cc | 126 +-- .../lib/security/credentials/jwt/jwt_verifier.h | 14 +- .../credentials/oauth2/oauth2_credentials.cc | 102 +- .../credentials/oauth2/oauth2_credentials.h | 7 +- .../credentials/plugin/plugin_credentials.cc | 51 +- .../security/credentials/ssl/ssl_credentials.cc | 21 +- .../lib/security/transport/client_auth_filter.cc | 85 +- src/core/lib/security/transport/lb_targets_info.cc | 4 +- src/core/lib/security/transport/secure_endpoint.cc | 120 +-- .../lib/security/transport/security_connector.cc | 144 ++- .../lib/security/transport/security_connector.h | 53 +- .../lib/security/transport/security_handshaker.cc | 189 ++-- .../lib/security/transport/security_handshaker.h | 3 +- .../lib/security/transport/server_auth_filter.cc | 55 +- src/core/lib/slice/b64.cc | 11 +- src/core/lib/slice/b64.h | 7 +- src/core/lib/slice/slice.cc | 17 +- src/core/lib/slice/slice_buffer.cc | 27 +- src/core/lib/slice/slice_hash_table.cc | 12 +- src/core/lib/slice/slice_hash_table.h | 6 +- src/core/lib/slice/slice_intern.cc | 7 +- src/core/lib/slice/slice_internal.h | 11 +- src/core/lib/surface/alarm.cc | 25 +- src/core/lib/surface/byte_buffer.cc | 5 +- src/core/lib/surface/byte_buffer_reader.cc | 16 +- src/core/lib/surface/call.cc | 429 ++++---- src/core/lib/surface/call.h | 24 +- src/core/lib/surface/call_details.cc | 7 +- src/core/lib/surface/channel.cc | 115 +-- src/core/lib/surface/channel.h | 27 +- src/core/lib/surface/channel_init.cc | 5 +- src/core/lib/surface/channel_init.h | 6 +- src/core/lib/surface/channel_ping.cc | 14 +- src/core/lib/surface/completion_queue.cc | 328 +++--- src/core/lib/surface/completion_queue.h | 21 +- src/core/lib/surface/init.cc | 51 +- src/core/lib/surface/init_secure.cc | 4 +- src/core/lib/surface/lame_client.cc | 53 +- src/core/lib/surface/server.cc | 322 +++--- src/core/lib/surface/server.h | 15 +- src/core/lib/transport/bdp_estimator.cc | 4 +- src/core/lib/transport/bdp_estimator.h | 2 +- src/core/lib/transport/byte_stream.cc | 62 +- src/core/lib/transport/byte_stream.h | 27 +- src/core/lib/transport/connectivity_state.cc | 22 +- src/core/lib/transport/connectivity_state.h | 10 +- src/core/lib/transport/error_utils.cc | 10 +- src/core/lib/transport/error_utils.h | 5 +- src/core/lib/transport/metadata.cc | 40 +- src/core/lib/transport/metadata.h | 20 +- src/core/lib/transport/metadata_batch.cc | 79 +- src/core/lib/transport/metadata_batch.h | 42 +- src/core/lib/transport/service_config.cc | 24 +- src/core/lib/transport/service_config.h | 8 +- src/core/lib/transport/static_metadata.cc | 2 +- src/core/lib/transport/status_conversion.cc | 5 +- src/core/lib/transport/status_conversion.h | 3 +- src/core/lib/transport/transport.cc | 84 +- src/core/lib/transport/transport.h | 33 +- src/core/lib/transport/transport_impl.h | 27 +- src/core/tsi/fake_transport_security.cc | 17 +- src/core/tsi/transport_security.h | 2 +- src/core/tsi/transport_security_grpc.cc | 29 +- src/core/tsi/transport_security_grpc.h | 22 +- src/cpp/common/channel_arguments.cc | 11 +- src/cpp/common/channel_filter.cc | 29 +- src/cpp/common/channel_filter.h | 62 +- .../CoreCronetEnd2EndTests.mm | 5 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 2 +- test/core/backoff/backoff_test.cc | 99 +- test/core/bad_client/bad_client.cc | 49 +- test/core/bad_client/tests/badreq.cc | 4 + test/core/bad_client/tests/connection_prefix.cc | 3 + .../core/bad_client/tests/head_of_line_blocking.cc | 3 + test/core/bad_client/tests/headers.cc | 2 + .../bad_client/tests/initial_settings_frame.cc | 2 + .../bad_client/tests/server_registered_method.cc | 2 + test/core/bad_client/tests/simple_request.cc | 4 + test/core/bad_client/tests/unknown_frame.cc | 2 + test/core/bad_client/tests/window_overflow.cc | 3 + test/core/channel/channel_args_test.cc | 26 +- test/core/channel/channel_stack_builder_test.cc | 24 +- test/core/channel/channel_stack_test.cc | 45 +- test/core/channel/minimal_stack_is_minimal_test.cc | 15 +- test/core/client_channel/lb_policies_test.cc | 14 +- test/core/client_channel/parse_address_test.cc | 19 +- .../resolvers/dns_resolver_connectivity_test.cc | 85 +- .../client_channel/resolvers/dns_resolver_test.cc | 21 +- .../client_channel/resolvers/fake_resolver_test.cc | 54 +- .../resolvers/sockaddr_resolver_test.cc | 28 +- test/core/client_channel/uri_fuzzer_test.cc | 19 +- test/core/client_channel/uri_parser_test.cc | 31 +- test/core/compression/algorithm_test.cc | 12 +- test/core/compression/message_compress_test.cc | 62 +- test/core/debug/stats_test.cc | 15 +- test/core/end2end/bad_server_response_test.cc | 37 +- test/core/end2end/connection_refused_test.cc | 5 +- test/core/end2end/fixtures/h2_census.cc | 10 +- test/core/end2end/fixtures/h2_compress.cc | 17 +- test/core/end2end/fixtures/h2_fd.cc | 8 +- test/core/end2end/fixtures/h2_full+workarounds.cc | 5 +- test/core/end2end/fixtures/h2_load_reporting.cc | 5 +- test/core/end2end/fixtures/h2_oauth2.cc | 7 +- test/core/end2end/fixtures/h2_sockpair+trace.cc | 35 +- test/core/end2end/fixtures/h2_sockpair.cc | 33 +- test/core/end2end/fixtures/h2_sockpair_1byte.cc | 33 +- test/core/end2end/fixtures/h2_ssl.cc | 5 +- test/core/end2end/fixtures/h2_ssl_proxy.cc | 10 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 192 ++-- test/core/end2end/fuzzers/api_fuzzer.cc | 83 +- test/core/end2end/fuzzers/client_fuzzer.cc | 210 ++-- test/core/end2end/fuzzers/server_fuzzer.cc | 135 +-- test/core/end2end/goaway_server_test.cc | 28 +- test/core/end2end/h2_ssl_cert_test.cc | 5 +- test/core/end2end/tests/cancel_after_accept.cc | 5 +- test/core/end2end/tests/cancel_after_round_trip.cc | 5 +- test/core/end2end/tests/compressed_payload.cc | 19 +- test/core/end2end/tests/filter_call_init_fails.cc | 19 +- test/core/end2end/tests/filter_causes_close.cc | 24 +- test/core/end2end/tests/filter_latency.cc | 18 +- test/core/end2end/tests/load_reporting_hook.cc | 5 +- test/core/end2end/tests/max_message_length.cc | 18 +- .../tests/stream_compression_compressed_payload.cc | 19 +- .../end2end/tests/stream_compression_payload.cc | 7 +- .../stream_compression_ping_pong_streaming.cc | 7 +- .../end2end/tests/workaround_cronet_compression.cc | 12 +- .../handshake/readahead_handshaker_server_ssl.cc | 24 +- test/core/http/format_request_test.cc | 2 + test/core/http/httpcli_test.cc | 146 ++- test/core/http/httpscli_test.cc | 52 +- test/core/http/parser_test.cc | 3 + test/core/http/request_fuzzer.cc | 3 + test/core/http/response_fuzzer.cc | 3 + test/core/iomgr/combiner_test.cc | 51 +- test/core/iomgr/endpoint_pair_test.cc | 29 +- test/core/iomgr/endpoint_tests.cc | 99 +- test/core/iomgr/ev_epollsig_linux_test.cc | 109 +- test/core/iomgr/fd_conservation_posix_test.cc | 37 +- test/core/iomgr/fd_posix_test.cc | 156 ++- test/core/iomgr/load_file_test.cc | 3 + test/core/iomgr/pollset_set_test.cc | 245 +++-- test/core/iomgr/resolve_address_posix_test.cc | 65 +- test/core/iomgr/resolve_address_test.cc | 153 ++- test/core/iomgr/resource_quota_test.cc | 354 +++---- test/core/iomgr/tcp_client_posix_test.cc | 83 +- test/core/iomgr/tcp_client_uv_test.cc | 62 +- test/core/iomgr/tcp_posix_test.cc | 153 ++- test/core/iomgr/tcp_server_posix_test.cc | 183 ++-- test/core/iomgr/tcp_server_uv_test.cc | 90 +- test/core/iomgr/timer_list_test.cc | 75 +- test/core/iomgr/udp_server_test.cc | 105 +- test/core/nanopb/fuzzer_response.cc | 3 + test/core/nanopb/fuzzer_serverlist.cc | 3 + test/core/security/credentials_test.cc | 303 +++--- test/core/security/json_token_test.cc | 16 +- test/core/security/jwt_verifier_test.cc | 146 ++- test/core/security/oauth2_utils.cc | 30 +- .../security/print_google_default_creds_token.cc | 22 +- test/core/security/secure_endpoint_test.cc | 67 +- test/core/security/ssl_server_fuzzer.cc | 124 +-- test/core/security/verify_jwt.cc | 23 +- test/core/slice/b64_test.cc | 46 +- test/core/slice/percent_decode_fuzzer.cc | 3 + test/core/slice/percent_encode_fuzzer.cc | 3 + test/core/slice/percent_encoding_test.cc | 3 + test/core/slice/slice_buffer_test.cc | 3 + test/core/slice/slice_hash_table_test.cc | 39 +- test/core/slice/slice_string_helpers_test.cc | 3 + test/core/slice/slice_test.cc | 2 + test/core/surface/byte_buffer_reader_test.cc | 8 +- test/core/surface/channel_create_test.cc | 3 +- test/core/surface/completion_queue_test.cc | 39 +- .../surface/completion_queue_threading_test.cc | 19 +- test/core/surface/concurrent_connectivity_test.cc | 41 +- test/core/surface/lame_client_test.cc | 13 +- .../num_external_connectivity_watchers_test.cc | 5 +- test/core/surface/secure_channel_create_test.cc | 17 +- test/core/surface/sequential_connectivity_test.cc | 5 +- test/core/transport/bdp_estimator_test.cc | 7 +- test/core/transport/byte_stream_test.cc | 113 +- test/core/transport/chttp2/bin_decoder_test.cc | 158 ++- test/core/transport/chttp2/bin_encoder_test.cc | 3 + test/core/transport/chttp2/hpack_encoder_test.cc | 91 +- .../transport/chttp2/hpack_parser_fuzzer_test.cc | 19 +- test/core/transport/chttp2/hpack_parser_test.cc | 41 +- test/core/transport/chttp2/hpack_table_test.cc | 72 +- .../core/transport/chttp2/settings_timeout_test.cc | 55 +- test/core/transport/chttp2/varint_test.cc | 3 + test/core/transport/connectivity_state_test.cc | 51 +- test/core/transport/metadata_test.cc | 137 ++- test/core/transport/status_conversion_test.cc | 11 +- test/core/transport/stream_owned_slice_test.cc | 5 +- test/core/util/mock_endpoint.cc | 36 +- test/core/util/mock_endpoint.h | 3 +- test/core/util/one_corpus_entry_fuzzer.cc | 8 + test/core/util/passthru_endpoint.cc | 45 +- test/core/util/port_server_client.cc | 130 ++- test/core/util/reconnect_server.cc | 6 +- test/core/util/test_tcp_server.cc | 36 +- test/core/util/trickle_endpoint.cc | 56 +- test/core/util/trickle_endpoint.h | 3 +- test/cpp/client/client_channel_stress_test.cc | 11 +- test/cpp/common/channel_arguments_test.cc | 5 +- test/cpp/common/channel_filter_test.cc | 4 +- test/cpp/end2end/client_lb_end2end_test.cc | 13 +- test/cpp/end2end/filter_end2end_test.cc | 7 +- test/cpp/end2end/grpclb_end2end_test.cc | 11 +- test/cpp/grpclb/grpclb_api_test.cc | 6 +- test/cpp/grpclb/grpclb_test.cc | 17 +- test/cpp/microbenchmarks/bm_call_create.cc | 139 ++- test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 136 ++- test/cpp/microbenchmarks/bm_chttp2_transport.cc | 270 +++-- test/cpp/microbenchmarks/bm_closure.cc | 196 ++-- test/cpp/microbenchmarks/bm_cq.cc | 26 +- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 22 +- test/cpp/microbenchmarks/bm_error.cc | 24 +- test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 8 +- test/cpp/microbenchmarks/bm_metadata.cc | 115 +-- test/cpp/microbenchmarks/bm_pollset.cc | 53 +- test/cpp/microbenchmarks/fullstack_fixtures.h | 27 +- test/cpp/naming/resolver_component_test.cc | 50 +- test/cpp/performance/writes_per_rpc_test.cc | 24 +- test/cpp/server/server_builder_test.cc | 7 +- test/cpp/util/byte_buffer_test.cc | 6 +- test/cpp/util/slice_test.cc | 6 +- tools/codegen/core/gen_static_metadata.py | 2 +- tools/codegen/core/gen_stats_data.py | 24 +- 444 files changed, 10022 insertions(+), 12454 deletions(-) (limited to 'src/core/lib/surface/completion_queue.cc') diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h index 9dc505f008..c9879d8a28 100644 --- a/include/grpc++/support/channel_arguments.h +++ b/include/grpc++/support/channel_arguments.h @@ -122,7 +122,7 @@ class ChannelArguments { /// Default pointer argument operations. struct PointerVtableMembers { static void* Copy(void* in) { return in; } - static void Destroy(grpc_exec_ctx* exec_ctx, void* in) {} + static void Destroy(void* in) {} static int Compare(void* a, void* b) { if (a < b) return -1; if (a > b) return 1; diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 77844aa2af..fcbc8ac5a1 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -85,7 +85,7 @@ typedef enum { typedef struct grpc_arg_pointer_vtable { void* (*copy)(void* p); - void (*destroy)(grpc_exec_ctx* exec_ctx, void* p); + void (*destroy)(void* p); int (*cmp)(void* p, void* q); } grpc_arg_pointer_vtable; diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 11997fcb56..ad026b685e 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -43,7 +43,7 @@ typedef struct grpc_slice grpc_slice; typedef struct grpc_slice_refcount_vtable { void (*ref)(void*); - void (*unref)(grpc_exec_ctx* exec_ctx, void*); + void (*unref)(void*); int (*eq)(grpc_slice a, grpc_slice b); uint32_t (*hash)(grpc_slice slice); } grpc_slice_refcount_vtable; diff --git a/include/grpc/slice_buffer.h b/include/grpc/slice_buffer.h index 6510c151b3..30833d02db 100644 --- a/include/grpc/slice_buffer.h +++ b/include/grpc/slice_buffer.h @@ -67,8 +67,7 @@ GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, grpc_slice_buffer* dst); /** move the first n bytes of src into dst (copying them) */ -GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* src, +GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, void* dst); /** take the first slice in the slice buffer */ GPRAPI grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* src); diff --git a/include/grpc/support/tls.h b/include/grpc/support/tls.h index 8519a8350b..4c9e79b6cf 100644 --- a/include/grpc/support/tls.h +++ b/include/grpc/support/tls.h @@ -32,6 +32,12 @@ GPR_TLS_DECL(foo); Thread locals always have static scope. + Declaring a thread local class variable 'foo': + GPR_TLS_CLASS_DECL(foo); + + Defining the thread local class variable: + GPR_TLS_CLASS_DEF(foo); + Initializing a thread local (must be done at library initialization time): gpr_tls_init(&foo); diff --git a/include/grpc/support/tls_gcc.h b/include/grpc/support/tls_gcc.h index 1b91d22be1..b44f0f1c8c 100644 --- a/include/grpc/support/tls_gcc.h +++ b/include/grpc/support/tls_gcc.h @@ -33,6 +33,11 @@ struct gpr_gcc_thread_local { #define GPR_TLS_DECL(name) \ static __thread struct gpr_gcc_thread_local name = {0} +#define GPR_TLS_CLASS_DECL(name) \ + static __thread struct gpr_gcc_thread_local name + +#define GPR_TLS_CLASS_DEF(name) __thread struct gpr_gcc_thread_local name = {0} + #define gpr_tls_init(tls) \ do { \ } while (0) diff --git a/include/grpc/support/tls_msvc.h b/include/grpc/support/tls_msvc.h index e5f2205fc1..68a411f5d4 100644 --- a/include/grpc/support/tls_msvc.h +++ b/include/grpc/support/tls_msvc.h @@ -26,9 +26,18 @@ struct gpr_msvc_thread_local { intptr_t value; }; +/** Use GPR_TLS_DECL to declare tls static variables outside a class */ #define GPR_TLS_DECL(name) \ static __declspec(thread) struct gpr_msvc_thread_local name = {0} +/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. + * GPR_TLS_CLASS_DEF needs to be called to define this member. */ +#define GPR_TLS_CLASS_DECL(name) \ + static __declspec(thread) struct gpr_msvc_thread_local name + +#define GPR_TLS_CLASS_DEF(name) \ + __declspec(thread) struct gpr_msvc_thread_local name = {0} + #define gpr_tls_init(tls) \ do { \ } while (0) diff --git a/include/grpc/support/tls_pthread.h b/include/grpc/support/tls_pthread.h index fb0edd8e74..249c8b16f8 100644 --- a/include/grpc/support/tls_pthread.h +++ b/include/grpc/support/tls_pthread.h @@ -29,8 +29,17 @@ struct gpr_pthread_thread_local { pthread_key_t key; }; +/** Use GPR_TLS_DECL to declare tls static variables outside a class */ #define GPR_TLS_DECL(name) static struct gpr_pthread_thread_local name = {0} +/** Use GPR_TLS_CLASS_DECL to declare tls static variable members of a class. + * GPR_TLS_CLASS_DEF needs to be called to define this member. */ +#define GPR_TLS_CLASS_DECL(name) static struct gpr_pthread_thread_local name + +/** Use GPR_TLS_CLASS_DEF to declare tls static variable members of a class. + * GPR_TLS_CLASS_DEF needs to be called to define this member. */ +#define GPR_TLS_CLASS_DEF(name) struct gpr_pthread_thread_local name = {0} + #define gpr_tls_init(tls) GPR_ASSERT(0 == pthread_key_create(&(tls)->key, NULL)) #define gpr_tls_destroy(tls) pthread_key_delete((tls)->key) #define gpr_tls_get(tls) ((intptr_t)pthread_getspecific((tls)->key)) diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index ed437d255c..339a79b0fb 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -69,20 +69,19 @@ static void init_globals() { gpr_free(env); } -static void backup_poller_shutdown_unref(grpc_exec_ctx* exec_ctx, - backup_poller* p) { +static void backup_poller_shutdown_unref(backup_poller* p) { if (gpr_unref(&p->shutdown_refs)) { - grpc_pollset_destroy(exec_ctx, p->pollset); + grpc_pollset_destroy(p->pollset); gpr_free(p->pollset); gpr_free(p); } } -static void done_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - backup_poller_shutdown_unref(exec_ctx, (backup_poller*)arg); +static void done_poller(void* arg, grpc_error* error) { + backup_poller_shutdown_unref((backup_poller*)arg); } -static void g_poller_unref(grpc_exec_ctx* exec_ctx) { +static void g_poller_unref() { if (gpr_unref(&g_poller->refs)) { gpr_mu_lock(&g_poller_mu); backup_poller* p = g_poller; @@ -90,40 +89,40 @@ static void g_poller_unref(grpc_exec_ctx* exec_ctx) { gpr_mu_unlock(&g_poller_mu); gpr_mu_lock(p->pollset_mu); p->shutting_down = true; - grpc_pollset_shutdown(exec_ctx, p->pollset, - GRPC_CLOSURE_INIT(&p->shutdown_closure, done_poller, - p, grpc_schedule_on_exec_ctx)); + grpc_pollset_shutdown( + p->pollset, GRPC_CLOSURE_INIT(&p->shutdown_closure, done_poller, p, + grpc_schedule_on_exec_ctx)); gpr_mu_unlock(p->pollset_mu); - grpc_timer_cancel(exec_ctx, &p->polling_timer); + grpc_timer_cancel(&p->polling_timer); } } -static void run_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void run_poller(void* arg, grpc_error* error) { backup_poller* p = (backup_poller*)arg; if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("run_poller", GRPC_ERROR_REF(error)); } - backup_poller_shutdown_unref(exec_ctx, p); + backup_poller_shutdown_unref(p); return; } gpr_mu_lock(p->pollset_mu); if (p->shutting_down) { gpr_mu_unlock(p->pollset_mu); - backup_poller_shutdown_unref(exec_ctx, p); + backup_poller_shutdown_unref(p); return; } - grpc_error* err = grpc_pollset_work(exec_ctx, p->pollset, nullptr, - grpc_exec_ctx_now(exec_ctx)); + grpc_error* err = + grpc_pollset_work(p->pollset, nullptr, grpc_core::ExecCtx::Get()->Now()); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); - grpc_timer_init(exec_ctx, &p->polling_timer, - grpc_exec_ctx_now(exec_ctx) + g_poll_interval_ms, + grpc_timer_init(&p->polling_timer, + grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, &p->run_poller_closure); } void grpc_client_channel_start_backup_polling( - grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { + grpc_pollset_set* interested_parties) { gpr_once_init(&g_once, init_globals); if (g_poll_interval_ms == 0) { return; @@ -139,8 +138,8 @@ void grpc_client_channel_start_backup_polling( gpr_ref_init(&g_poller->shutdown_refs, 2); GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &g_poller->polling_timer, - grpc_exec_ctx_now(exec_ctx) + g_poll_interval_ms, + grpc_timer_init(&g_poller->polling_timer, + grpc_core::ExecCtx::Get()->Now() + g_poll_interval_ms, &g_poller->run_poller_closure); } @@ -152,14 +151,14 @@ void grpc_client_channel_start_backup_polling( grpc_pollset* pollset = g_poller->pollset; gpr_mu_unlock(&g_poller_mu); - grpc_pollset_set_add_pollset(exec_ctx, interested_parties, pollset); + grpc_pollset_set_add_pollset(interested_parties, pollset); } void grpc_client_channel_stop_backup_polling( - grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { + grpc_pollset_set* interested_parties) { if (g_poll_interval_ms == 0) { return; } - grpc_pollset_set_del_pollset(exec_ctx, interested_parties, g_poller->pollset); - g_poller_unref(exec_ctx); + grpc_pollset_set_del_pollset(interested_parties, g_poller->pollset); + g_poller_unref(); } diff --git a/src/core/ext/filters/client_channel/backup_poller.h b/src/core/ext/filters/client_channel/backup_poller.h index e993d50639..551e0331dc 100644 --- a/src/core/ext/filters/client_channel/backup_poller.h +++ b/src/core/ext/filters/client_channel/backup_poller.h @@ -25,10 +25,10 @@ /* Start polling \a interested_parties periodically in the timer thread */ void grpc_client_channel_start_backup_polling( - grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); + grpc_pollset_set* interested_parties); /* Stop polling \a interested_parties */ void grpc_client_channel_stop_backup_polling( - grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties); + grpc_pollset_set* interested_parties); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_BACKUP_POLLER_H */ diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 7eaf5d98cd..20693ba419 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -33,22 +33,22 @@ grpc_connectivity_state grpc_channel_check_connectivity_state( /* forward through to the underlying client channel */ grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_connectivity_state state; GRPC_API_TRACE( "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, (channel, try_to_connect)); if (client_channel_elem->filter == &grpc_client_channel_filter) { - state = grpc_client_channel_check_connectivity_state( - &exec_ctx, client_channel_elem, try_to_connect); - grpc_exec_ctx_finish(&exec_ctx); + state = grpc_client_channel_check_connectivity_state(client_channel_elem, + try_to_connect); + return state; } gpr_log(GPR_ERROR, "grpc_channel_check_connectivity_state called on something that is " "not a client channel, but '%s'", client_channel_elem->filter->name); - grpc_exec_ctx_finish(&exec_ctx); + return GRPC_CHANNEL_SHUTDOWN; } @@ -73,12 +73,11 @@ typedef struct { void* tag; } state_watcher; -static void delete_state_watcher(grpc_exec_ctx* exec_ctx, state_watcher* w) { +static void delete_state_watcher(state_watcher* w) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, - "watch_channel_connectivity"); + GRPC_CHANNEL_INTERNAL_UNREF(w->channel, "watch_channel_connectivity"); } else { abort(); } @@ -86,8 +85,7 @@ static void delete_state_watcher(grpc_exec_ctx* exec_ctx, state_watcher* w) { gpr_free(w); } -static void finished_completion(grpc_exec_ctx* exec_ctx, void* pw, - grpc_cq_completion* ignored) { +static void finished_completion(void* pw, grpc_cq_completion* ignored) { bool should_delete = false; state_watcher* w = (state_watcher*)pw; gpr_mu_lock(&w->mu); @@ -102,19 +100,19 @@ static void finished_completion(grpc_exec_ctx* exec_ctx, void* pw, gpr_mu_unlock(&w->mu); if (should_delete) { - delete_state_watcher(exec_ctx, w); + delete_state_watcher(w); } } -static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, - bool due_to_completion, grpc_error* error) { +static void partly_done(state_watcher* w, bool due_to_completion, + grpc_error* error) { if (due_to_completion) { - grpc_timer_cancel(exec_ctx, &w->alarm); + grpc_timer_cancel(&w->alarm); } else { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, + client_channel_elem, grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), nullptr, &w->on_complete, nullptr); } @@ -149,7 +147,7 @@ static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, w->error = error; } w->phase = CALLING_BACK_AND_FINISHED; - grpc_cq_end_op(exec_ctx, w->cq, w->tag, w->error, finished_completion, w, + grpc_cq_end_op(w->cq, w->tag, w->error, finished_completion, w, &w->completion_storage); break; case CALLING_BACK_AND_FINISHED: @@ -161,14 +159,12 @@ static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, GRPC_ERROR_UNREF(error); } -static void watch_complete(grpc_exec_ctx* exec_ctx, void* pw, - grpc_error* error) { - partly_done(exec_ctx, (state_watcher*)pw, true, GRPC_ERROR_REF(error)); +static void watch_complete(void* pw, grpc_error* error) { + partly_done((state_watcher*)pw, true, GRPC_ERROR_REF(error)); } -static void timeout_complete(grpc_exec_ctx* exec_ctx, void* pw, - grpc_error* error) { - partly_done(exec_ctx, (state_watcher*)pw, false, GRPC_ERROR_REF(error)); +static void timeout_complete(void* pw, grpc_error* error) { + partly_done((state_watcher*)pw, false, GRPC_ERROR_REF(error)); } int grpc_channel_num_external_connectivity_watchers(grpc_channel* channel) { @@ -183,12 +179,10 @@ typedef struct watcher_timer_init_arg { gpr_timespec deadline; } watcher_timer_init_arg; -static void watcher_timer_init(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error_ignored) { +static void watcher_timer_init(void* arg, grpc_error* error_ignored) { watcher_timer_init_arg* wa = (watcher_timer_init_arg*)arg; - grpc_timer_init(exec_ctx, &wa->w->alarm, - grpc_timespec_to_millis_round_up(wa->deadline), + grpc_timer_init(&wa->w->alarm, grpc_timespec_to_millis_round_up(wa->deadline), &wa->w->on_timeout); gpr_free(wa); } @@ -204,7 +198,7 @@ void grpc_channel_watch_connectivity_state( gpr_timespec deadline, grpc_completion_queue* cq, void* tag) { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( @@ -241,12 +235,10 @@ void grpc_channel_watch_connectivity_state( if (client_channel_elem->filter == &grpc_client_channel_filter) { GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); grpc_client_channel_watch_connectivity_state( - &exec_ctx, client_channel_elem, + client_channel_elem, grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)), &w->state, &w->on_complete, &w->watcher_timer_init); } else { abort(); } - - grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index aced9adf9f..ba82c88eb7 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -91,8 +91,7 @@ static void method_parameters_unref(method_parameters* method_params) { static void* method_parameters_ref_wrapper(void* value) { return method_parameters_ref((method_parameters*)value); } -static void method_parameters_unref_wrapper(grpc_exec_ctx* exec_ctx, - void* value) { +static void method_parameters_unref_wrapper(void* value) { method_parameters_unref((method_parameters*)value); } @@ -228,12 +227,11 @@ typedef struct { grpc_lb_policy* lb_policy; } lb_policy_connectivity_watcher; -static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, +static void watch_lb_policy_locked(channel_data* chand, grpc_lb_policy* lb_policy, grpc_connectivity_state current_state); -static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, - channel_data* chand, +static void set_channel_connectivity_state_locked(channel_data* chand, grpc_connectivity_state state, grpc_error* error, const char* reason) { @@ -245,12 +243,12 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { /* cancel picks with wait_for_ready=false */ grpc_lb_policy_cancel_picks_locked( - exec_ctx, chand->lb_policy, + chand->lb_policy, /* mask= */ GRPC_INITIAL_METADATA_WAIT_FOR_READY, /* check= */ 0, GRPC_ERROR_REF(error)); } else if (state == GRPC_CHANNEL_SHUTDOWN) { /* cancel all picks */ - grpc_lb_policy_cancel_picks_locked(exec_ctx, chand->lb_policy, + grpc_lb_policy_cancel_picks_locked(chand->lb_policy, /* mask= */ 0, /* check= */ 0, GRPC_ERROR_REF(error)); } @@ -259,12 +257,10 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: setting connectivity state to %s", chand, grpc_connectivity_state_name(state)); } - grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state, error, - reason); + grpc_connectivity_state_set(&chand->state_tracker, state, error, reason); } -static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void on_lb_policy_state_changed_locked(void* arg, grpc_error* error) { lb_policy_connectivity_watcher* w = (lb_policy_connectivity_watcher*)arg; /* check if the notification is for the latest policy */ if (w->lb_policy == w->chand->lb_policy) { @@ -272,17 +268,17 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, w->lb_policy, grpc_connectivity_state_name(w->state)); } - set_channel_connectivity_state_locked(exec_ctx, w->chand, w->state, + set_channel_connectivity_state_locked(w->chand, w->state, GRPC_ERROR_REF(error), "lb_changed"); if (w->state != GRPC_CHANNEL_SHUTDOWN) { - watch_lb_policy_locked(exec_ctx, w->chand, w->lb_policy, w->state); + watch_lb_policy_locked(w->chand, w->lb_policy, w->state); } } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "watch_lb_policy"); + GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, "watch_lb_policy"); gpr_free(w); } -static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, +static void watch_lb_policy_locked(channel_data* chand, grpc_lb_policy* lb_policy, grpc_connectivity_state current_state) { lb_policy_connectivity_watcher* w = @@ -293,19 +289,18 @@ static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, grpc_combiner_scheduler(chand->combiner)); w->state = current_state; w->lb_policy = lb_policy; - grpc_lb_policy_notify_on_state_change_locked(exec_ctx, lb_policy, &w->state, + grpc_lb_policy_notify_on_state_change_locked(lb_policy, &w->state, &w->on_changed); } -static void start_resolving_locked(grpc_exec_ctx* exec_ctx, - channel_data* chand) { +static void start_resolving_locked(channel_data* chand) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand); } GPR_ASSERT(!chand->started_resolving); chand->started_resolving = true; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next_locked(exec_ctx, chand->resolver, &chand->resolver_result, + grpc_resolver_next_locked(chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } @@ -369,29 +364,26 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { } } -static void request_reresolution_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void request_reresolution_locked(void* arg, grpc_error* error) { reresolution_request_args* args = (reresolution_request_args*)arg; channel_data* chand = args->chand; // If this invocation is for a stale LB policy, treat it as an LB shutdown // signal. if (args->lb_policy != chand->lb_policy || error != GRPC_ERROR_NONE || chand->resolver == nullptr) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "re-resolution"); + GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "re-resolution"); gpr_free(args); return; } if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: started name re-resolving", chand); } - grpc_resolver_channel_saw_error_locked(exec_ctx, chand->resolver); + grpc_resolver_channel_saw_error_locked(chand->resolver); // Give back the closure to the LB policy. - grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, chand->lb_policy, - &args->closure); + grpc_lb_policy_set_reresolve_closure_locked(chand->lb_policy, &args->closure); } -static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, @@ -458,12 +450,10 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, if (chand->lb_policy != nullptr && !lb_policy_name_changed) { // Continue using the same LB policy. Update with new addresses. lb_policy_updated = true; - grpc_lb_policy_update_locked(exec_ctx, chand->lb_policy, - &lb_policy_args); + grpc_lb_policy_update_locked(chand->lb_policy, &lb_policy_args); } else { // Instantiate new LB policy. - new_lb_policy = - grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); + new_lb_policy = grpc_lb_policy_create(lb_policy_name, &lb_policy_args); if (new_lb_policy == nullptr) { gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", lb_policy_name); @@ -475,7 +465,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&args->closure, request_reresolution_locked, args, grpc_combiner_scheduler(chand->combiner)); GRPC_CHANNEL_STACK_REF(chand->owning_stack, "re-resolution"); - grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, new_lb_policy, + grpc_lb_policy_set_reresolve_closure_locked(new_lb_policy, &args->closure); } } @@ -492,8 +482,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, GRPC_ARG_SERVER_URI); GPR_ASSERT(channel_arg != nullptr); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); - grpc_uri* uri = - grpc_uri_parse(exec_ctx, channel_arg->value.string, true); + grpc_uri* uri = grpc_uri_parse(channel_arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); service_config_parsing_state parsing_state; memset(&parsing_state, 0, sizeof(parsing_state)); @@ -504,7 +493,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, grpc_uri_destroy(uri); retry_throttle_data = parsing_state.retry_throttle_data; method_params_table = grpc_service_config_create_method_config_table( - exec_ctx, service_config, method_parameters_create_from_json, + service_config, method_parameters_create_from_json, method_parameters_ref_wrapper, method_parameters_unref_wrapper); grpc_service_config_destroy(service_config); } @@ -514,7 +503,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // The copy will be saved in chand->lb_policy_name below. lb_policy_name_dup = gpr_strdup(lb_policy_name); } - grpc_channel_args_destroy(exec_ctx, chand->resolver_result); + grpc_channel_args_destroy(chand->resolver_result); chand->resolver_result = nullptr; } if (grpc_client_channel_trace.enabled()) { @@ -546,7 +535,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, chand->retry_throttle_data = retry_throttle_data; // Swap out the method params table. if (chand->method_params_table != nullptr) { - grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_slice_hash_table_unref(chand->method_params_table); } chand->method_params_table = method_params_table; // If we have a new LB policy or are shutting down (in which case @@ -562,10 +551,9 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, chand->lb_policy); } - grpc_pollset_set_del_pollset_set(exec_ctx, - chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); } chand->lb_policy = new_lb_policy; } @@ -579,21 +567,20 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); } - grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); - GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); + grpc_resolver_shutdown_locked(chand->resolver); + GRPC_RESOLVER_UNREF(chand->resolver, "channel"); chand->resolver = nullptr; } set_channel_connectivity_state_locked( - exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, + chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Got resolver result after disconnection", &error, 1), "resolver_gone"); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "resolver"); + GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "resolver"); grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Channel disconnected", &error, 1)); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, - &chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); } else { // Not shutting down. grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_error* state_error = @@ -603,33 +590,28 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); } GRPC_ERROR_UNREF(state_error); - state = grpc_lb_policy_check_connectivity_locked(exec_ctx, new_lb_policy, - &state_error); - grpc_pollset_set_add_pollset_set(exec_ctx, - new_lb_policy->interested_parties, + state = + grpc_lb_policy_check_connectivity_locked(new_lb_policy, &state_error); + grpc_pollset_set_add_pollset_set(new_lb_policy->interested_parties, chand->interested_parties); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, - &chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); if (chand->exit_idle_when_lb_policy_arrives) { - grpc_lb_policy_exit_idle_locked(exec_ctx, new_lb_policy); + grpc_lb_policy_exit_idle_locked(new_lb_policy); chand->exit_idle_when_lb_policy_arrives = false; } - watch_lb_policy_locked(exec_ctx, chand, new_lb_policy, state); + watch_lb_policy_locked(chand, new_lb_policy, state); } if (!lb_policy_updated) { - set_channel_connectivity_state_locked(exec_ctx, chand, state, - GRPC_ERROR_REF(state_error), - "new_lb+resolver"); + set_channel_connectivity_state_locked( + chand, state, GRPC_ERROR_REF(state_error), "new_lb+resolver"); } - grpc_resolver_next_locked(exec_ctx, chand->resolver, - &chand->resolver_result, + grpc_resolver_next_locked(chand->resolver, &chand->resolver_result, &chand->on_resolver_result_changed); GRPC_ERROR_UNREF(state_error); } } -static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error_ignored) { +static void start_transport_op_locked(void* arg, grpc_error* error_ignored) { grpc_transport_op* op = (grpc_transport_op*)arg; grpc_channel_element* elem = (grpc_channel_element*)op->handler_private.extra_arg; @@ -637,7 +619,7 @@ static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( - exec_ctx, &chand->state_tracker, op->connectivity_state, + &chand->state_tracker, op->connectivity_state, op->on_connectivity_state_change); op->on_connectivity_state_change = nullptr; op->connectivity_state = nullptr; @@ -645,11 +627,10 @@ static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, if (op->send_ping != nullptr) { if (chand->lb_policy == nullptr) { - GRPC_CLOSURE_SCHED( - exec_ctx, op->send_ping, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Ping with no load balancing")); + GRPC_CLOSURE_SCHED(op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Ping with no load balancing")); } else { - grpc_lb_policy_ping_one_locked(exec_ctx, chand->lb_policy, op->send_ping); + grpc_lb_policy_ping_one_locked(chand->lb_policy, op->send_ping); op->bind_pollset = nullptr; } op->send_ping = nullptr; @@ -658,54 +639,48 @@ static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, if (op->disconnect_with_error != GRPC_ERROR_NONE) { if (chand->resolver != nullptr) { set_channel_connectivity_state_locked( - exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, + chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); - grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); - GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); + grpc_resolver_shutdown_locked(chand->resolver); + GRPC_RESOLVER_UNREF(chand->resolver, "channel"); chand->resolver = nullptr; if (!chand->started_resolving) { grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_REF(op->disconnect_with_error)); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, - &chand->waiting_for_resolver_result_closures); + GRPC_CLOSURE_LIST_SCHED(&chand->waiting_for_resolver_result_closures); } if (chand->lb_policy != nullptr) { - grpc_pollset_set_del_pollset_set(exec_ctx, - chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); chand->lb_policy = nullptr; } } GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "start_transport_op"); + GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "start_transport_op"); - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } -static void cc_start_transport_op(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void cc_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(op->set_accept_stream == false); if (op->bind_pollset != nullptr) { - grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, - op->bind_pollset); + grpc_pollset_set_add_pollset(chand->interested_parties, op->bind_pollset); } op->handler_private.extra_arg = elem; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "start_transport_op"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&op->handler_private.closure, start_transport_op_locked, op, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } -static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void cc_get_channel_info(grpc_channel_element* elem, const grpc_channel_info* info) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_lock(&chand->info_mu); @@ -724,8 +699,7 @@ static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, } /* Constructor for channel_data */ -static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); @@ -746,7 +720,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, chand->interested_parties = grpc_pollset_set_create(); grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, "client_channel"); - grpc_client_channel_start_backup_polling(exec_ctx, chand->interested_parties); + grpc_client_channel_start_backup_polling(chand->interested_parties); // Record client channel factory. const grpc_arg* arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); @@ -774,15 +748,15 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, } char* proxy_name = nullptr; grpc_channel_args* new_args = nullptr; - grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, + grpc_proxy_mappers_map_name(arg->value.string, args->channel_args, &proxy_name, &new_args); // Instantiate resolver. chand->resolver = grpc_resolver_create( - exec_ctx, proxy_name != nullptr ? proxy_name : arg->value.string, + proxy_name != nullptr ? proxy_name : arg->value.string, new_args != nullptr ? new_args : args->channel_args, chand->interested_parties, chand->combiner); if (proxy_name != nullptr) gpr_free(proxy_name); - if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); + if (new_args != nullptr) grpc_channel_args_destroy(new_args); if (chand->resolver == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed"); } @@ -791,32 +765,28 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void shutdown_resolver_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void shutdown_resolver_locked(void* arg, grpc_error* error) { grpc_resolver* resolver = (grpc_resolver*)arg; - grpc_resolver_shutdown_locked(exec_ctx, resolver); - GRPC_RESOLVER_UNREF(exec_ctx, resolver, "channel"); + grpc_resolver_shutdown_locked(resolver); + GRPC_RESOLVER_UNREF(resolver, "channel"); } /* Destructor for channel_data */ -static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void cc_destroy_channel_elem(grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; if (chand->resolver != nullptr) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } if (chand->client_channel_factory != nullptr) { - grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); + grpc_client_channel_factory_unref(chand->client_channel_factory); } if (chand->lb_policy != nullptr) { - grpc_pollset_set_del_pollset_set(exec_ctx, - chand->lb_policy->interested_parties, + grpc_pollset_set_del_pollset_set(chand->lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); + GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); } gpr_free(chand->info_lb_policy_name); gpr_free(chand->info_service_config_json); @@ -824,12 +794,12 @@ static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } if (chand->method_params_table != nullptr) { - grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_slice_hash_table_unref(chand->method_params_table); } - grpc_client_channel_stop_backup_polling(exec_ctx, chand->interested_parties); - grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); - grpc_pollset_set_destroy(exec_ctx, chand->interested_parties); - GRPC_COMBINER_UNREF(exec_ctx, chand->combiner, "client_channel"); + grpc_client_channel_stop_backup_polling(chand->interested_parties); + grpc_connectivity_state_destroy(&chand->state_tracker); + grpc_pollset_set_destroy(chand->interested_parties); + GRPC_COMBINER_UNREF(chand->combiner, "client_channel"); gpr_mu_destroy(&chand->info_mu); gpr_mu_destroy(&chand->external_connectivity_watcher_list_mu); } @@ -916,21 +886,18 @@ static void waiting_for_pick_batches_add( } // This is called via the call combiner, so access to calld is synchronized. -static void fail_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void fail_pending_batch_in_call_combiner(void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count], GRPC_ERROR_REF(error), calld->call_combiner); } } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void waiting_for_pick_batches_fail(grpc_call_element* elem, grpc_error* error) { call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -943,37 +910,34 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], fail_pending_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, - &calld->handle_pending_batch_in_call_combiner[i], - GRPC_ERROR_REF(error), - "waiting_for_pick_batches_fail"); + GRPC_CALL_COMBINER_START( + calld->call_combiner, &calld->handle_pending_batch_in_call_combiner[i], + GRPC_ERROR_REF(error), "waiting_for_pick_batches_fail"); } if (calld->initial_metadata_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->initial_metadata_batch, GRPC_ERROR_REF(error), + calld->initial_metadata_batch, GRPC_ERROR_REF(error), calld->call_combiner); } else { - GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, + GRPC_CALL_COMBINER_STOP(calld->call_combiner, "waiting_for_pick_batches_fail"); } GRPC_ERROR_UNREF(error); } // This is called via the call combiner, so access to calld is synchronized. -static void run_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* ignored) { +static void run_pending_batch_in_call_combiner(void* arg, grpc_error* ignored) { call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_subchannel_call_process_op( - exec_ctx, calld->subchannel_call, + calld->subchannel_call, calld->waiting_for_pick_batches[calld->waiting_for_pick_batches_count]); } } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void waiting_for_pick_batches_resume(grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -987,20 +951,18 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&calld->handle_pending_batch_in_call_combiner[i], run_pending_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, - &calld->handle_pending_batch_in_call_combiner[i], - GRPC_ERROR_NONE, - "waiting_for_pick_batches_resume"); + GRPC_CALL_COMBINER_START( + calld->call_combiner, &calld->handle_pending_batch_in_call_combiner[i], + GRPC_ERROR_NONE, "waiting_for_pick_batches_resume"); } GPR_ASSERT(calld->initial_metadata_batch != nullptr); - grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, + grpc_subchannel_call_process_op(calld->subchannel_call, calld->initial_metadata_batch); } // Applies service config to the call. Must be invoked once we know // that the resolver has returned results to the channel. -static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void apply_service_config_to_call_locked(grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -1013,7 +975,7 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, } if (chand->method_params_table != nullptr) { calld->method_params = (method_parameters*)grpc_method_config_table_get( - exec_ctx, chand->method_params_table, calld->path); + chand->method_params_table, calld->path); if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one @@ -1025,15 +987,14 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, calld->method_params->timeout; if (per_method_deadline < calld->deadline) { calld->deadline = per_method_deadline; - grpc_deadline_state_reset(exec_ctx, elem, calld->deadline); + grpc_deadline_state_reset(elem, calld->deadline); } } } } } -static void create_subchannel_call_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void create_subchannel_call_locked(grpc_call_element* elem, grpc_error* error) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1047,24 +1008,22 @@ static void create_subchannel_call_locked(grpc_exec_ctx* exec_ctx, calld->call_combiner // call_combiner }; grpc_error* new_error = grpc_connected_subchannel_create_call( - exec_ctx, calld->connected_subchannel, &call_args, - &calld->subchannel_call); + calld->connected_subchannel, &call_args, &calld->subchannel_call); if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: create subchannel_call=%p: error=%s", chand, calld, calld->subchannel_call, grpc_error_string(new_error)); } if (new_error != GRPC_ERROR_NONE) { new_error = grpc_error_add_child(new_error, error); - waiting_for_pick_batches_fail(exec_ctx, elem, new_error); + waiting_for_pick_batches_fail(elem, new_error); } else { - waiting_for_pick_batches_resume(exec_ctx, elem); + waiting_for_pick_batches_resume(elem); } GRPC_ERROR_UNREF(error); } // Invoked when a pick is completed, on both success or failure. -static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_error* error) { +static void pick_done_locked(grpc_call_element* elem, grpc_error* error) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (calld->connected_subchannel == nullptr) { @@ -1080,10 +1039,10 @@ static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, "chand=%p calld=%p: failed to create subchannel: error=%s", chand, calld, grpc_error_string(calld->error)); } - waiting_for_pick_batches_fail(exec_ctx, elem, GRPC_ERROR_REF(calld->error)); + waiting_for_pick_batches_fail(elem, GRPC_ERROR_REF(calld->error)); } else { /* Create call on subchannel. */ - create_subchannel_call_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); + create_subchannel_call_locked(elem, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } @@ -1092,19 +1051,17 @@ static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, // either (a) the pick was deferred pending a resolver result or (b) the // pick was done asynchronously. Removes the call's polling entity from // chand->interested_parties before invoking pick_done_locked(). -static void async_pick_done_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, grpc_error* error) { +static void async_pick_done_locked(grpc_call_element* elem, grpc_error* error) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; - grpc_polling_entity_del_from_pollset_set(exec_ctx, calld->pollent, + grpc_polling_entity_del_from_pollset_set(calld->pollent, chand->interested_parties); - pick_done_locked(exec_ctx, elem, error); + pick_done_locked(elem, error); } // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void pick_callback_cancel_locked(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1113,17 +1070,15 @@ static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", chand, calld, calld->lb_policy); } - grpc_lb_policy_cancel_pick_locked(exec_ctx, calld->lb_policy, - &calld->connected_subchannel, - GRPC_ERROR_REF(error)); + grpc_lb_policy_cancel_pick_locked( + calld->lb_policy, &calld->connected_subchannel, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_callback_cancel"); + GRPC_CALL_STACK_UNREF(calld->owning_call, "pick_callback_cancel"); } // Callback invoked by grpc_lb_policy_pick_locked() for async picks. // Unrefs the LB policy and invokes async_pick_done_locked(). -static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void pick_callback_done_locked(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -1132,23 +1087,22 @@ static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, chand, calld); } GPR_ASSERT(calld->lb_policy != nullptr); - GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); + GRPC_LB_POLICY_UNREF(calld->lb_policy, "pick_subchannel"); calld->lb_policy = nullptr; - async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); + async_pick_done_locked(elem, GRPC_ERROR_REF(error)); } // Takes a ref to chand->lb_policy and calls grpc_lb_policy_pick_locked(). // If the pick was completed synchronously, unrefs the LB policy and // returns true. -static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static bool pick_callback_start_locked(grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", chand, calld, chand->lb_policy); } - apply_service_config_to_call_locked(exec_ctx, elem); + apply_service_config_to_call_locked(elem); // If the application explicitly set wait_for_ready, use that. // Otherwise, if the service config specified a value for this // method, use that. @@ -1178,7 +1132,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&calld->lb_pick_closure, pick_callback_done_locked, elem, grpc_combiner_scheduler(chand->combiner)); const bool pick_done = grpc_lb_policy_pick_locked( - exec_ctx, chand->lb_policy, &inputs, &calld->connected_subchannel, + chand->lb_policy, &inputs, &calld->connected_subchannel, calld->subchannel_call_context, nullptr, &calld->lb_pick_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ @@ -1186,12 +1140,12 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed synchronously", chand, calld); } - GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); + GRPC_LB_POLICY_UNREF(calld->lb_policy, "pick_subchannel"); calld->lb_policy = nullptr; } else { GRPC_CALL_STACK_REF(calld->owning_call, "pick_callback_cancel"); grpc_call_combiner_set_notify_on_cancel( - exec_ctx, calld->call_combiner, + calld->call_combiner, GRPC_CLOSURE_INIT(&calld->lb_pick_cancel_closure, pick_callback_cancel_locked, elem, grpc_combiner_scheduler(chand->combiner))); @@ -1208,8 +1162,7 @@ typedef struct { // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx* exec_ctx, - void* arg, +static void pick_after_resolver_result_cancel_locked(void* arg, grpc_error* error) { pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { @@ -1237,16 +1190,13 @@ static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx* exec_ctx, // it's safe to call async_pick_done_locked() here -- we are // essentially calling it here instead of calling it in // pick_after_resolver_result_done_locked(). - async_pick_done_locked(exec_ctx, elem, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Pick cancelled", &error, 1)); + async_pick_done_locked(elem, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Pick cancelled", &error, 1)); } -static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem); +static void pick_after_resolver_result_start_locked(grpc_call_element* elem); -static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, - void* arg, +static void pick_after_resolver_result_done_locked(void* arg, grpc_error* error) { pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { @@ -1266,19 +1216,19 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", chand, calld); } - async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); + async_pick_done_locked(elem, GRPC_ERROR_REF(error)); } else if (chand->lb_policy != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", chand, calld); } - if (pick_callback_start_locked(exec_ctx, elem)) { + if (pick_callback_start_locked(elem)) { // Even if the LB policy returns a result synchronously, we have // already added our polling entity to chand->interested_parties // in order to wait for the resolver result, so we need to // remove it here. Therefore, we call async_pick_done_locked() // instead of pick_done_locked(). - async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); + async_pick_done_locked(elem, GRPC_ERROR_NONE); } } // TODO(roth): It should be impossible for chand->lb_policy to be NULL @@ -1296,19 +1246,18 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, "trying again", chand, calld); } - pick_after_resolver_result_start_locked(exec_ctx, elem); + pick_after_resolver_result_start_locked(elem); } else { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver disconnected", chand, calld); } async_pick_done_locked( - exec_ctx, elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); + elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); } } -static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void pick_after_resolver_result_start_locked(grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (grpc_client_channel_trace.enabled()) { @@ -1324,47 +1273,46 @@ static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, grpc_closure_list_append(&chand->waiting_for_resolver_result_closures, &args->closure, GRPC_ERROR_NONE); grpc_call_combiner_set_notify_on_cancel( - exec_ctx, calld->call_combiner, + calld->call_combiner, GRPC_CLOSURE_INIT(&args->cancel_closure, pick_after_resolver_result_cancel_locked, args, grpc_combiner_scheduler(chand->combiner))); } -static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* ignored) { +static void start_pick_locked(void* arg, grpc_error* ignored) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(calld->connected_subchannel == nullptr); if (chand->lb_policy != nullptr) { // We already have an LB policy, so ask it for a pick. - if (pick_callback_start_locked(exec_ctx, elem)) { + if (pick_callback_start_locked(elem)) { // Pick completed synchronously. - pick_done_locked(exec_ctx, elem, GRPC_ERROR_NONE); + pick_done_locked(elem, GRPC_ERROR_NONE); return; } } else { // We do not yet have an LB policy, so wait for a resolver result. if (chand->resolver == nullptr) { - pick_done_locked(exec_ctx, elem, + pick_done_locked(elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); return; } if (!chand->started_resolving) { - start_resolving_locked(exec_ctx, chand); + start_resolving_locked(chand); } - pick_after_resolver_result_start_locked(exec_ctx, elem); + pick_after_resolver_result_start_locked(elem); } // We need to wait for either a resolver result or for an async result // from the LB policy. Add the polling entity from call_data to the // channel_data's interested_parties, so that the I/O of the LB policy // and resolver can be done under it. The polling entity will be // removed in async_pick_done_locked(). - grpc_polling_entity_add_to_pollset_set(exec_ctx, calld->pollent, + grpc_polling_entity_add_to_pollset_set(calld->pollent, chand->interested_parties); } -static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_complete(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (calld->retry_throttle_data != nullptr) { @@ -1380,18 +1328,15 @@ static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { calld->retry_throttle_data); } } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_on_complete, - GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(calld->original_on_complete, GRPC_ERROR_REF(error)); } static void cc_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { - grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, - batch); + grpc_deadline_state_client_start_transport_stream_op_batch(elem, batch); } GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0); // If we've previously been cancelled, immediately fail any new batches. @@ -1401,7 +1346,7 @@ static void cc_start_transport_stream_op_batch( chand, calld, grpc_error_string(calld->error)); } grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, batch, GRPC_ERROR_REF(calld->error), calld->call_combiner); + batch, GRPC_ERROR_REF(calld->error), calld->call_combiner); goto done; } if (batch->cancel_stream) { @@ -1419,11 +1364,10 @@ static void cc_start_transport_stream_op_batch( // If we have a subchannel call, send the cancellation batch down. // Otherwise, fail all pending batches. if (calld->subchannel_call != nullptr) { - grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); + grpc_subchannel_call_process_op(calld->subchannel_call, batch); } else { waiting_for_pick_batches_add(calld, batch); - waiting_for_pick_batches_fail(exec_ctx, elem, - GRPC_ERROR_REF(calld->error)); + waiting_for_pick_batches_fail(elem, GRPC_ERROR_REF(calld->error)); } goto done; } @@ -1446,7 +1390,7 @@ static void cc_start_transport_stream_op_batch( "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, calld, calld->subchannel_call); } - grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); + grpc_subchannel_call_process_op(calld->subchannel_call, batch); goto done; } // We do not yet have a subchannel call. @@ -1460,7 +1404,6 @@ static void cc_start_transport_stream_op_batch( chand, calld); } GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&batch->handler_private.closure, start_pick_locked, elem, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); @@ -1471,7 +1414,7 @@ static void cc_start_transport_stream_op_batch( "chand=%p calld=%p: saved batch, yeilding call combiner", chand, calld); } - GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, + GRPC_CALL_COMBINER_STOP(calld->call_combiner, "batch does not include send_initial_metadata"); } done: @@ -1479,8 +1422,7 @@ done: } /* Constructor for call_data */ -static grpc_error* cc_init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* cc_init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -1492,23 +1434,22 @@ static grpc_error* cc_init_call_elem(grpc_exec_ctx* exec_ctx, calld->owning_call = args->call_stack; calld->call_combiner = args->call_combiner; if (chand->deadline_checking_enabled) { - grpc_deadline_state_init(exec_ctx, elem, args->call_stack, - args->call_combiner, calld->deadline); + grpc_deadline_state_init(elem, args->call_stack, args->call_combiner, + calld->deadline); } return GRPC_ERROR_NONE; } /* Destructor for call_data */ -static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void cc_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { - grpc_deadline_state_destroy(exec_ctx, elem); + grpc_deadline_state_destroy(elem); } - grpc_slice_unref_internal(exec_ctx, calld->path); + grpc_slice_unref_internal(calld->path); if (calld->method_params != nullptr) { method_parameters_unref(calld->method_params); } @@ -1517,14 +1458,13 @@ static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_subchannel_call_set_cleanup_closure(calld->subchannel_call, then_schedule_closure); then_schedule_closure = nullptr; - GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, calld->subchannel_call, + GRPC_SUBCHANNEL_CALL_UNREF(calld->subchannel_call, "client_channel_destroy_call"); } GPR_ASSERT(calld->lb_policy == nullptr); GPR_ASSERT(calld->waiting_for_pick_batches_count == 0); if (calld->connected_subchannel != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, calld->connected_subchannel, - "picked"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(calld->connected_subchannel, "picked"); } for (size_t i = 0; i < GRPC_CONTEXT_COUNT; ++i) { if (calld->subchannel_call_context[i].value != nullptr) { @@ -1532,11 +1472,10 @@ static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, calld->subchannel_call_context[i].value); } } - GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); } -static void cc_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void cc_set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; calld->pollent = pollent; @@ -1560,29 +1499,27 @@ const grpc_channel_filter grpc_client_channel_filter = { "client-channel", }; -static void try_to_connect_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error_ignored) { +static void try_to_connect_locked(void* arg, grpc_error* error_ignored) { channel_data* chand = (channel_data*)arg; if (chand->lb_policy != nullptr) { - grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); + grpc_lb_policy_exit_idle_locked(chand->lb_policy); } else { chand->exit_idle_when_lb_policy_arrives = true; if (!chand->started_resolving && chand->resolver != nullptr) { - start_resolving_locked(exec_ctx, chand); + start_resolving_locked(chand); } } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "try_to_connect"); + GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "try_to_connect"); } grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect) { + grpc_channel_element* elem, int try_to_connect) { channel_data* chand = (channel_data*)elem->channel_data; grpc_connectivity_state out = grpc_connectivity_state_check(&chand->state_tracker); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { GRPC_CHANNEL_STACK_REF(chand->owning_stack, "try_to_connect"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(try_to_connect_locked, chand, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); @@ -1663,50 +1600,49 @@ int grpc_client_channel_num_external_connectivity_watchers( return count; } -static void on_external_watch_complete_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void on_external_watch_complete_locked(void* arg, grpc_error* error) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; grpc_closure* follow_up = w->on_complete; - grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, + grpc_polling_entity_del_from_pollset_set(&w->pollent, w->chand->interested_parties); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, + GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, "external_connectivity_watcher"); external_connectivity_watcher_list_remove(w->chand, w); gpr_free(w); - GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(follow_up, GRPC_ERROR_REF(error)); } -static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, +static void watch_connectivity_state_locked(void* arg, grpc_error* error_ignored) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; external_connectivity_watcher* found = nullptr; if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); - GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(w->watcher_timer_init, GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete_locked, w, grpc_combiner_scheduler(w->chand->combiner)); - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &w->chand->state_tracker, w->state, &w->my_closure); + grpc_connectivity_state_notify_on_state_change(&w->chand->state_tracker, + w->state, &w->my_closure); } else { GPR_ASSERT(w->watcher_timer_init == nullptr); found = lookup_external_connectivity_watcher(w->chand, w->on_complete); if (found) { GPR_ASSERT(found->on_complete == w->on_complete); grpc_connectivity_state_notify_on_state_change( - exec_ctx, &found->chand->state_tracker, nullptr, &found->my_closure); + &found->chand->state_tracker, nullptr, &found->my_closure); } - grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, + grpc_polling_entity_del_from_pollset_set(&w->pollent, w->chand->interested_parties); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, + GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack, "external_connectivity_watcher"); gpr_free(w); } } void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_polling_entity pollent, grpc_connectivity_state* state, - grpc_closure* closure, grpc_closure* watcher_timer_init) { + grpc_channel_element* elem, grpc_polling_entity pollent, + grpc_connectivity_state* state, grpc_closure* closure, + grpc_closure* watcher_timer_init) { channel_data* chand = (channel_data*)elem->channel_data; external_connectivity_watcher* w = (external_connectivity_watcher*)gpr_zalloc(sizeof(*w)); @@ -1715,12 +1651,11 @@ void grpc_client_channel_watch_connectivity_state( w->on_complete = closure; w->state = state; w->watcher_timer_init = watcher_timer_init; - grpc_polling_entity_add_to_pollset_set(exec_ctx, &w->pollent, + grpc_polling_entity_add_to_pollset_set(&w->pollent, chand->interested_parties); GRPC_CHANNEL_STACK_REF(w->chand->owning_stack, "external_connectivity_watcher"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&w->my_closure, watch_connectivity_state_locked, w, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 48e4637a82..9670405cbe 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -38,15 +38,15 @@ extern grpc_core::TraceFlag grpc_client_channel_trace; extern const grpc_channel_filter grpc_client_channel_filter; grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect); + grpc_channel_element* elem, int try_to_connect); int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem); void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_polling_entity pollent, grpc_connectivity_state* state, - grpc_closure* on_complete, grpc_closure* watcher_timer_init); + grpc_channel_element* elem, grpc_polling_entity pollent, + grpc_connectivity_state* state, grpc_closure* on_complete, + grpc_closure* watcher_timer_init); /* Debug helper: pull the subchannel call from a call stack element */ grpc_subchannel_call* grpc_client_channel_get_subchannel_call( diff --git a/src/core/ext/filters/client_channel/client_channel_factory.cc b/src/core/ext/filters/client_channel/client_channel_factory.cc index 57eac8f875..60c95d7dc9 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.cc +++ b/src/core/ext/filters/client_channel/client_channel_factory.cc @@ -23,23 +23,19 @@ void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory) { factory->vtable->ref(factory); } -void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory) { - factory->vtable->unref(exec_ctx, factory); +void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory) { + factory->vtable->unref(factory); } grpc_subchannel* grpc_client_channel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - const grpc_subchannel_args* args) { - return factory->vtable->create_subchannel(exec_ctx, factory, args); + grpc_client_channel_factory* factory, const grpc_subchannel_args* args) { + return factory->vtable->create_subchannel(factory, args); } grpc_channel* grpc_client_channel_factory_create_channel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - const char* target, grpc_client_channel_type type, - const grpc_channel_args* args) { - return factory->vtable->create_client_channel(exec_ctx, factory, target, type, - args); + grpc_client_channel_factory* factory, const char* target, + grpc_client_channel_type type, const grpc_channel_args* args) { + return factory->vtable->create_client_channel(factory, target, type, args); } static void* factory_arg_copy(void* factory) { @@ -47,9 +43,8 @@ static void* factory_arg_copy(void* factory) { return factory; } -static void factory_arg_destroy(grpc_exec_ctx* exec_ctx, void* factory) { - grpc_client_channel_factory_unref(exec_ctx, - (grpc_client_channel_factory*)factory); +static void factory_arg_destroy(void* factory) { + grpc_client_channel_factory_unref((grpc_client_channel_factory*)factory); } static int factory_arg_cmp(void* factory1, void* factory2) { diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h index db82b733ce..766ebb9389 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.h +++ b/src/core/ext/filters/client_channel/client_channel_factory.h @@ -45,31 +45,26 @@ struct grpc_client_channel_factory { struct grpc_client_channel_factory_vtable { void (*ref)(grpc_client_channel_factory* factory); - void (*unref)(grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory); - grpc_subchannel* (*create_subchannel)(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory, + void (*unref)(grpc_client_channel_factory* factory); + grpc_subchannel* (*create_subchannel)(grpc_client_channel_factory* factory, const grpc_subchannel_args* args); - grpc_channel* (*create_client_channel)(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory, + grpc_channel* (*create_client_channel)(grpc_client_channel_factory* factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args); }; void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory); -void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory); +void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory); /** Create a new grpc_subchannel */ grpc_subchannel* grpc_client_channel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - const grpc_subchannel_args* args); + grpc_client_channel_factory* factory, const grpc_subchannel_args* args); /** Create a new grpc_channel */ grpc_channel* grpc_client_channel_factory_create_channel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - const char* target, grpc_client_channel_type type, - const grpc_channel_args* args); + grpc_client_channel_factory* factory, const char* target, + grpc_client_channel_type type, const grpc_channel_args* args); grpc_arg grpc_client_channel_factory_create_channel_arg( grpc_client_channel_factory* factory); diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 7a5bb18157..ea630d2917 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -34,14 +34,12 @@ #include "src/core/ext/filters/client_channel/subchannel_index.h" #include "src/core/lib/surface/channel_init.h" -static bool append_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } -static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool set_default_host_if_unset(grpc_channel_stack_builder* builder, void* unused) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); @@ -52,15 +50,14 @@ static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, } } char* default_authority = grpc_get_default_authority( - exec_ctx, grpc_channel_stack_builder_get_target(builder)); + grpc_channel_stack_builder_get_target(builder)); if (default_authority != nullptr) { grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_DEFAULT_AUTHORITY, default_authority); grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, - new_args); + grpc_channel_stack_builder_set_channel_arguments(builder, new_args); gpr_free(default_authority); - grpc_channel_args_destroy(exec_ctx, new_args); + grpc_channel_args_destroy(new_args); } return true; } diff --git a/src/core/ext/filters/client_channel/connector.cc b/src/core/ext/filters/client_channel/connector.cc index c258468e58..c8bf2f3e1c 100644 --- a/src/core/ext/filters/client_channel/connector.cc +++ b/src/core/ext/filters/client_channel/connector.cc @@ -23,18 +23,17 @@ grpc_connector* grpc_connector_ref(grpc_connector* connector) { return connector; } -void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector) { - connector->vtable->unref(exec_ctx, connector); +void grpc_connector_unref(grpc_connector* connector) { + connector->vtable->unref(connector); } -void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, +void grpc_connector_connect(grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify) { - connector->vtable->connect(exec_ctx, connector, in_args, out_args, notify); + connector->vtable->connect(connector, in_args, out_args, notify); } -void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector, - grpc_error* why) { - connector->vtable->shutdown(exec_ctx, connector, why); +void grpc_connector_shutdown(grpc_connector* connector, grpc_error* why) { + connector->vtable->shutdown(connector, why); } diff --git a/src/core/ext/filters/client_channel/connector.h b/src/core/ext/filters/client_channel/connector.h index 239ed8a8bd..d657658d67 100644 --- a/src/core/ext/filters/client_channel/connector.h +++ b/src/core/ext/filters/client_channel/connector.h @@ -49,25 +49,23 @@ typedef struct { struct grpc_connector_vtable { void (*ref)(grpc_connector* connector); - void (*unref)(grpc_exec_ctx* exec_ctx, grpc_connector* connector); + void (*unref)(grpc_connector* connector); /** Implementation of grpc_connector_shutdown */ - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, - grpc_error* why); + void (*shutdown)(grpc_connector* connector, grpc_error* why); /** Implementation of grpc_connector_connect */ - void (*connect)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + void (*connect)(grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify); }; grpc_connector* grpc_connector_ref(grpc_connector* connector); -void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector); +void grpc_connector_unref(grpc_connector* connector); /** Connect using the connector: max one outstanding call at a time */ -void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, +void grpc_connector_connect(grpc_connector* connector, const grpc_connect_in_args* in_args, grpc_connect_out_args* out_args, grpc_closure* notify); /** Cancel any pending connection */ -void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector, - grpc_error* why); +void grpc_connector_shutdown(grpc_connector* connector, grpc_error* why); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H */ diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc index b7cb2e3eba..556a3bc6a1 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -61,41 +61,38 @@ typedef struct http_connect_handshaker { } http_connect_handshaker; // Unref and clean up handshaker. -static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx, - http_connect_handshaker* handshaker) { +static void http_connect_handshaker_unref(http_connect_handshaker* handshaker) { if (gpr_unref(&handshaker->refcount)) { gpr_mu_destroy(&handshaker->mu); if (handshaker->endpoint_to_destroy != nullptr) { - grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy); + grpc_endpoint_destroy(handshaker->endpoint_to_destroy); } if (handshaker->read_buffer_to_destroy != nullptr) { - grpc_slice_buffer_destroy_internal(exec_ctx, - handshaker->read_buffer_to_destroy); + grpc_slice_buffer_destroy_internal(handshaker->read_buffer_to_destroy); gpr_free(handshaker->read_buffer_to_destroy); } - grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer); + grpc_slice_buffer_destroy_internal(&handshaker->write_buffer); grpc_http_parser_destroy(&handshaker->http_parser); grpc_http_response_destroy(&handshaker->http_response); gpr_free(handshaker); } } -// Set args fields to NULL, saving the endpoint and read buffer for +// Set args fields to nullptr, saving the endpoint and read buffer for // later destruction. static void cleanup_args_for_failure_locked( - grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) { + http_connect_handshaker* handshaker) { handshaker->endpoint_to_destroy = handshaker->args->endpoint; handshaker->args->endpoint = nullptr; handshaker->read_buffer_to_destroy = handshaker->args->read_buffer; handshaker->args->read_buffer = nullptr; - grpc_channel_args_destroy(exec_ctx, handshaker->args->args); + grpc_channel_args_destroy(handshaker->args->args); handshaker->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the // callback with the error. -static void handshake_failed_locked(grpc_exec_ctx* exec_ctx, - http_connect_handshaker* handshaker, +static void handshake_failed_locked(http_connect_handshaker* handshaker, grpc_error* error) { if (error == GRPC_ERROR_NONE) { // If we were shut down after an endpoint operation succeeded but @@ -108,34 +105,32 @@ static void handshake_failed_locked(grpc_exec_ctx* exec_ctx, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint, - GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(error)); // Not shutting down, so the handshake failed. Clean up before // invoking the callback. - cleanup_args_for_failure_locked(exec_ctx, handshaker); + cleanup_args_for_failure_locked(handshaker); // Set shutdown to true so that subsequent calls to // http_connect_handshaker_shutdown() do nothing. handshaker->shutdown = true; } // Invoke callback. - GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error); + GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error); } // Callback invoked when finished writing HTTP CONNECT request. -static void on_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_write_done(void* arg, grpc_error* error) { http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the write failed or we're shutting down, clean up and invoke the // callback with the error. - handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error)); + handshake_failed_locked(handshaker, GRPC_ERROR_REF(error)); gpr_mu_unlock(&handshaker->mu); - http_connect_handshaker_unref(exec_ctx, handshaker); + http_connect_handshaker_unref(handshaker); } else { // Otherwise, read the response. // The read callback inherits our ref to the handshaker. - grpc_endpoint_read(exec_ctx, handshaker->args->endpoint, + grpc_endpoint_read(handshaker->args->endpoint, handshaker->args->read_buffer, &handshaker->response_read_closure); gpr_mu_unlock(&handshaker->mu); @@ -143,14 +138,13 @@ static void on_write_done(grpc_exec_ctx* exec_ctx, void* arg, } // Callback invoked for reading HTTP CONNECT response. -static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_read_done(void* arg, grpc_error* error) { http_connect_handshaker* handshaker = (http_connect_handshaker*)arg; gpr_mu_lock(&handshaker->mu); if (error != GRPC_ERROR_NONE || handshaker->shutdown) { // If the read failed or we're shutting down, clean up and invoke the // callback with the error. - handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error)); + handshake_failed_locked(handshaker, GRPC_ERROR_REF(error)); goto done; } // Add buffer to parser. @@ -161,7 +155,7 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, handshaker->args->read_buffer->slices[i], &body_start_offset); if (error != GRPC_ERROR_NONE) { - handshake_failed_locked(exec_ctx, handshaker, error); + handshake_failed_locked(handshaker, error); goto done; } if (handshaker->http_parser.state == GRPC_HTTP_BODY) { @@ -180,7 +174,7 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, &handshaker->args->read_buffer->slices[i + 1], handshaker->args->read_buffer->count - i - 1); grpc_slice_buffer_swap(handshaker->args->read_buffer, &tmp_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &tmp_buffer); + grpc_slice_buffer_destroy_internal(&tmp_buffer); break; } } @@ -197,9 +191,8 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, // complete (e.g., handling chunked transfer encoding or looking // at the Content-Length: header). if (handshaker->http_parser.state != GRPC_HTTP_BODY) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - handshaker->args->read_buffer); - grpc_endpoint_read(exec_ctx, handshaker->args->endpoint, + grpc_slice_buffer_reset_and_unref_internal(handshaker->args->read_buffer); + grpc_endpoint_read(handshaker->args->endpoint, handshaker->args->read_buffer, &handshaker->response_read_closure); gpr_mu_unlock(&handshaker->mu); @@ -213,48 +206,44 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg, handshaker->http_response.status); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - handshake_failed_locked(exec_ctx, handshaker, error); + handshake_failed_locked(handshaker, error); goto done; } // Success. Invoke handshake-done callback. - GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error); + GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error); done: // Set shutdown to true so that subsequent calls to // http_connect_handshaker_shutdown() do nothing. handshaker->shutdown = true; gpr_mu_unlock(&handshaker->mu); - http_connect_handshaker_unref(exec_ctx, handshaker); + http_connect_handshaker_unref(handshaker); } // // Public handshaker methods // -static void http_connect_handshaker_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker_in) { +static void http_connect_handshaker_destroy(grpc_handshaker* handshaker_in) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; - http_connect_handshaker_unref(exec_ctx, handshaker); + http_connect_handshaker_unref(handshaker); } -static void http_connect_handshaker_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker_in, +static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in, grpc_error* why) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; gpr_mu_lock(&handshaker->mu); if (!handshaker->shutdown) { handshaker->shutdown = true; - grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint, - GRPC_ERROR_REF(why)); - cleanup_args_for_failure_locked(exec_ctx, handshaker); + grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(why)); + cleanup_args_for_failure_locked(handshaker); } gpr_mu_unlock(&handshaker->mu); GRPC_ERROR_UNREF(why); } static void http_connect_handshaker_do_handshake( - grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker_in, - grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, - grpc_handshaker_args* args) { + grpc_handshaker* handshaker_in, grpc_tcp_server_acceptor* acceptor, + grpc_closure* on_handshake_done, grpc_handshaker_args* args) { http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in; // Check for HTTP CONNECT channel arg. // If not found, invoke on_handshake_done without doing anything. @@ -266,7 +255,7 @@ static void http_connect_handshaker_do_handshake( gpr_mu_lock(&handshaker->mu); handshaker->shutdown = true; gpr_mu_unlock(&handshaker->mu); - GRPC_CLOSURE_SCHED(exec_ctx, on_handshake_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_handshake_done, GRPC_ERROR_NONE); return; } GPR_ASSERT(arg->type == GRPC_ARG_STRING); @@ -324,7 +313,7 @@ static void http_connect_handshaker_do_handshake( gpr_free(header_strings); // Take a new ref to be held by the write callback. gpr_ref(&handshaker->refcount); - grpc_endpoint_write(exec_ctx, args->endpoint, &handshaker->write_buffer, + grpc_endpoint_write(args->endpoint, &handshaker->write_buffer, &handshaker->request_done_closure); gpr_mu_unlock(&handshaker->mu); } @@ -355,14 +344,13 @@ static grpc_handshaker* grpc_http_connect_handshaker_create() { // static void handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* factory, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshaker_factory* factory, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add(handshake_mgr, grpc_http_connect_handshaker_create()); } -static void handshaker_factory_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker_factory* factory) {} +static void handshaker_factory_destroy(grpc_handshaker_factory* factory) {} static const grpc_handshaker_factory_vtable handshaker_factory_vtable = { handshaker_factory_add_handshakers, handshaker_factory_destroy}; diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 405d8c0e55..2eafeee702 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -36,19 +36,18 @@ /** * Parses the 'http_proxy' env var and returns the proxy hostname to resolve or - * NULL on error. Also sets 'user_cred' to user credentials if present in the + * nullptr on error. Also sets 'user_cred' to user credentials if present in the * 'http_proxy' env var, otherwise leaves it unchanged. It is caller's * responsibility to gpr_free user_cred. */ -static char* get_http_proxy_server(grpc_exec_ctx* exec_ctx, char** user_cred) { +static char* get_http_proxy_server(char** user_cred) { GPR_ASSERT(user_cred != nullptr); char* proxy_name = nullptr; char* uri_str = gpr_getenv("http_proxy"); char** authority_strs = nullptr; size_t authority_nstrs; if (uri_str == nullptr) return nullptr; - grpc_uri* uri = - grpc_uri_parse(exec_ctx, uri_str, false /* suppress_errors */); + grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); if (uri == nullptr || uri->authority == nullptr) { gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); goto done; @@ -82,18 +81,16 @@ done: return proxy_name; } -static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { char* user_cred = nullptr; - *name_to_resolve = get_http_proxy_server(exec_ctx, &user_cred); + *name_to_resolve = get_http_proxy_server(&user_cred); if (*name_to_resolve == nullptr) return false; char* no_proxy_str = nullptr; - grpc_uri* uri = - grpc_uri_parse(exec_ctx, server_uri, false /* suppress_errors */); + grpc_uri* uri = grpc_uri_parse(server_uri, false /* suppress_errors */); if (uri == nullptr || uri->path[0] == '\0') { gpr_log(GPR_ERROR, "'http_proxy' environment variable set, but cannot " @@ -174,8 +171,7 @@ no_use_proxy: return false; } -static bool proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +static bool proxy_mapper_map_address(grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index db566f1b56..b97aa319f7 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -63,15 +63,13 @@ void grpc_lb_policy_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF")); } -static void shutdown_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void shutdown_locked(void* arg, grpc_error* error) { grpc_lb_policy* policy = (grpc_lb_policy*)arg; - policy->vtable->shutdown_locked(exec_ctx, policy); - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, policy, "strong-unref"); + policy->vtable->shutdown_locked(policy); + GRPC_LB_POLICY_WEAK_UNREF(policy, "strong-unref"); } -void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_unref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, (gpr_atm)1 - (gpr_atm)(1 << WEAK_REF_BITS), 1 REF_MUTATE_PASS_ARGS("STRONG_UNREF")); @@ -79,13 +77,11 @@ void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, gpr_atm check = 1 << WEAK_REF_BITS; if ((old_val & mask) == check) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(shutdown_locked, policy, grpc_combiner_scheduler(policy->combiner)), GRPC_ERROR_NONE); } else { - grpc_lb_policy_weak_unref(exec_ctx, - policy REF_FUNC_PASS_ARGS("strong-unref")); + grpc_lb_policy_weak_unref(policy REF_FUNC_PASS_ARGS("strong-unref")); } } @@ -93,88 +89,75 @@ void grpc_lb_policy_weak_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1, 0 REF_MUTATE_PASS_ARGS("WEAK_REF")); } -void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_weak_unref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF")); if (old_val == 1) { - grpc_pollset_set_destroy(exec_ctx, policy->interested_parties); + grpc_pollset_set_destroy(policy->interested_parties); grpc_combiner* combiner = policy->combiner; - policy->vtable->destroy(exec_ctx, policy); - GRPC_COMBINER_UNREF(exec_ctx, combiner, "lb_policy"); + policy->vtable->destroy(policy); + GRPC_COMBINER_UNREF(combiner, "lb_policy"); } } -int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, +int grpc_lb_policy_pick_locked(grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { - return policy->vtable->pick_locked(exec_ctx, policy, pick_args, target, - context, user_data, on_complete); + return policy->vtable->pick_locked(policy, pick_args, target, context, + user_data, on_complete); } -void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_cancel_pick_locked(grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error) { - policy->vtable->cancel_pick_locked(exec_ctx, policy, target, error); + policy->vtable->cancel_pick_locked(policy, target, error); } -void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_cancel_picks_locked(grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { - policy->vtable->cancel_picks_locked(exec_ctx, policy, - initial_metadata_flags_mask, + policy->vtable->cancel_picks_locked(policy, initial_metadata_flags_mask, initial_metadata_flags_eq, error); } -void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy) { - policy->vtable->exit_idle_locked(exec_ctx, policy); +void grpc_lb_policy_exit_idle_locked(grpc_lb_policy* policy) { + policy->vtable->exit_idle_locked(policy); } -void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_ping_one_locked(grpc_lb_policy* policy, grpc_closure* closure) { - policy->vtable->ping_one_locked(exec_ctx, policy, closure); + policy->vtable->ping_one_locked(policy, closure); } void grpc_lb_policy_notify_on_state_change_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_connectivity_state* state, grpc_closure* closure) { - policy->vtable->notify_on_state_change_locked(exec_ctx, policy, state, - closure); + grpc_lb_policy* policy, grpc_connectivity_state* state, + grpc_closure* closure) { + policy->vtable->notify_on_state_change_locked(policy, state, closure); } grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_error** connectivity_error) { - return policy->vtable->check_connectivity_locked(exec_ctx, policy, - connectivity_error); + grpc_lb_policy* policy, grpc_error** connectivity_error) { + return policy->vtable->check_connectivity_locked(policy, connectivity_error); } -void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* lb_policy_args) { - policy->vtable->update_locked(exec_ctx, policy, lb_policy_args); + policy->vtable->update_locked(policy, lb_policy_args); } void grpc_lb_policy_set_reresolve_closure_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* request_reresolution) { - policy->vtable->set_reresolve_closure_locked(exec_ctx, policy, - request_reresolution); + grpc_lb_policy* policy, grpc_closure* request_reresolution) { + policy->vtable->set_reresolve_closure_locked(policy, request_reresolution); } -void grpc_lb_policy_try_reresolve(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_try_reresolve(grpc_lb_policy* policy, grpc_core::TraceFlag* grpc_lb_trace, grpc_error* error) { if (policy->request_reresolution != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, policy->request_reresolution, error); + GRPC_CLOSURE_SCHED(policy->request_reresolution, error); policy->request_reresolution = nullptr; if (grpc_lb_trace->enabled()) { gpr_log(GPR_DEBUG, diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index d3159eebf3..fd28a2b623 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -55,53 +55,49 @@ typedef struct grpc_lb_policy_pick_args { } grpc_lb_policy_pick_args; struct grpc_lb_policy_vtable { - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); - void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); + void (*destroy)(grpc_lb_policy* policy); + void (*shutdown_locked)(grpc_lb_policy* policy); /** \see grpc_lb_policy_pick */ - int (*pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + int (*pick_locked)(grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete); /** \see grpc_lb_policy_cancel_pick */ - void (*cancel_pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + void (*cancel_pick_locked)(grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error); /** \see grpc_lb_policy_cancel_picks */ - void (*cancel_picks_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + void (*cancel_picks_locked)(grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error); /** \see grpc_lb_policy_ping_one */ - void (*ping_one_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* closure); + void (*ping_one_locked)(grpc_lb_policy* policy, grpc_closure* closure); /** Try to enter a READY connectivity state */ - void (*exit_idle_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); + void (*exit_idle_locked)(grpc_lb_policy* policy); /** check the current connectivity of the lb_policy */ grpc_connectivity_state (*check_connectivity_locked)( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_error** connectivity_error); + grpc_lb_policy* policy, grpc_error** connectivity_error); /** call notify when the connectivity state of a channel changes from *state. Updates *state with the new state of the policy. Calling with a NULL \a state cancels the subscription. */ - void (*notify_on_state_change_locked)(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, + void (*notify_on_state_change_locked)(grpc_lb_policy* policy, grpc_connectivity_state* state, grpc_closure* closure); - void (*update_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + void (*update_locked)(grpc_lb_policy* policy, const grpc_lb_policy_args* args); /** \see grpc_lb_policy_set_reresolve_closure */ - void (*set_reresolve_closure_locked)(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, + void (*set_reresolve_closure_locked)(grpc_lb_policy* policy, grpc_closure* request_reresolution); }; @@ -110,33 +106,33 @@ struct grpc_lb_policy_vtable { /* Strong references: the policy will shutdown when they reach zero */ #define GRPC_LB_POLICY_REF(p, r) \ grpc_lb_policy_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_UNREF(exec_ctx, p, r) \ - grpc_lb_policy_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_UNREF(p, r) \ + grpc_lb_policy_unref((p), __FILE__, __LINE__, (r)) /* Weak references: they don't prevent the shutdown of the LB policy. When no * strong references are left but there are still weak ones, shutdown is called. * Once the weak reference also reaches zero, the LB policy is destroyed. */ #define GRPC_LB_POLICY_WEAK_REF(p, r) \ grpc_lb_policy_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, p, r) \ - grpc_lb_policy_weak_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_WEAK_UNREF(p, r) \ + grpc_lb_policy_weak_unref((p), __FILE__, __LINE__, (r)) void grpc_lb_policy_ref(grpc_lb_policy* policy, const char* file, int line, const char* reason); -void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - const char* file, int line, const char* reason); +void grpc_lb_policy_unref(grpc_lb_policy* policy, const char* file, int line, + const char* reason); void grpc_lb_policy_weak_ref(grpc_lb_policy* policy, const char* file, int line, const char* reason); -void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - const char* file, int line, const char* reason); +void grpc_lb_policy_weak_unref(grpc_lb_policy* policy, const char* file, + int line, const char* reason); #else #define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p)) -#define GRPC_LB_POLICY_UNREF(cl, p, r) grpc_lb_policy_unref((cl), (p)) +#define GRPC_LB_POLICY_UNREF(p, r) grpc_lb_policy_unref((p)) #define GRPC_LB_POLICY_WEAK_REF(p, r) grpc_lb_policy_weak_ref((p)) -#define GRPC_LB_POLICY_WEAK_UNREF(cl, p, r) grpc_lb_policy_weak_unref((cl), (p)) +#define GRPC_LB_POLICY_WEAK_UNREF(p, r) grpc_lb_policy_weak_unref((p)) void grpc_lb_policy_ref(grpc_lb_policy* policy); -void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); +void grpc_lb_policy_unref(grpc_lb_policy* policy); void grpc_lb_policy_weak_ref(grpc_lb_policy* policy); -void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); +void grpc_lb_policy_weak_unref(grpc_lb_policy* policy); #endif /** called by concrete implementations to initialize the base struct */ @@ -161,7 +157,7 @@ void grpc_lb_policy_init(grpc_lb_policy* policy, Any IO should be done under the \a interested_parties \a grpc_pollset_set in the \a grpc_lb_policy struct. */ -int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, +int grpc_lb_policy_pick_locked(grpc_lb_policy* policy, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, @@ -169,55 +165,47 @@ int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, /** Perform a connected subchannel ping (see \a grpc_connected_subchannel_ping) against one of the connected subchannels managed by \a policy. */ -void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_ping_one_locked(grpc_lb_policy* policy, grpc_closure* closure); /** Cancel picks for \a target. The \a on_complete callback of the pending picks will be invoked with \a *target set to NULL. */ -void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_cancel_pick_locked(grpc_lb_policy* policy, grpc_connected_subchannel** target, grpc_error* error); /** Cancel all pending picks for which their \a initial_metadata_flags (as given in the call to \a grpc_lb_policy_pick) matches \a initial_metadata_flags_eq when AND'd with \a initial_metadata_flags_mask */ -void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_cancel_picks_locked(grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error); /** Try to enter a READY connectivity state */ -void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy); +void grpc_lb_policy_exit_idle_locked(grpc_lb_policy* policy); /* Call notify when the connectivity state of a channel changes from \a *state. * Updates \a *state with the new state of the policy */ void grpc_lb_policy_notify_on_state_change_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_connectivity_state* state, grpc_closure* closure); + grpc_lb_policy* policy, grpc_connectivity_state* state, + grpc_closure* closure); grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_error** connectivity_error); + grpc_lb_policy* policy, grpc_error** connectivity_error); /** Update \a policy with \a lb_policy_args. */ -void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* lb_policy_args); /** Set the re-resolution closure to \a request_reresolution. */ void grpc_lb_policy_set_reresolve_closure_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* request_reresolution); + grpc_lb_policy* policy, grpc_closure* request_reresolution); /** Try to request a re-resolution. It's NOT a public API; it's only for use by the LB policy implementations. */ -void grpc_lb_policy_try_reresolve(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* policy, +void grpc_lb_policy_try_reresolve(grpc_lb_policy* policy, grpc_core::TraceFlag* grpc_lb_trace, grpc_error* error); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index 6d9fadaf30..3eedb08ecc 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -25,14 +25,12 @@ #include "src/core/lib/iomgr/error.h" #include "src/core/lib/profiling/timers.h" -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} typedef struct { // Stats object to update. @@ -47,28 +45,24 @@ typedef struct { bool recv_initial_metadata_succeeded; } call_data; -static void on_complete_for_send(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_complete_for_send(void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->send_initial_metadata_succeeded = true; } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_on_complete_for_send, - GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(calld->original_on_complete_for_send, GRPC_ERROR_REF(error)); } -static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void recv_initial_metadata_ready(void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->recv_initial_metadata_succeeded = true; } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; // Get stats object from context and take a ref. @@ -81,7 +75,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; @@ -96,8 +90,7 @@ static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, } static void start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("clr_start_transport_stream_op_batch", 0); // Intercept send_initial_metadata. @@ -118,7 +111,7 @@ static void start_transport_stream_op_batch( &calld->recv_initial_metadata_ready; } // Chain to next filter. - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); GPR_TIMER_END("clr_start_transport_stream_op_batch", 0); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index db06fc20b6..eadeea0368 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -131,12 +131,12 @@ grpc_core::TraceFlag grpc_lb_glb_trace(false, "glb"); /* add lb_token of selected subchannel (address) to the call's initial * metadata */ static grpc_error* initial_metadata_add_lb_token( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* initial_metadata, + grpc_metadata_batch* initial_metadata, grpc_linked_mdelem* lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != nullptr); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); - return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, - lb_token_mdelem_storage, lb_token); + return grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, + lb_token); } static void destroy_client_stats(void* arg) { @@ -186,20 +186,19 @@ typedef struct wrapped_rr_closure_arg { /* The \a on_complete closure passed as part of the pick requires keeping a * reference to its associated round robin instance. We wrap this closure in * order to unref the round robin instance upon its invocation */ -static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void wrapped_rr_closure(void* arg, grpc_error* error) { wrapped_rr_closure_arg* wc_arg = (wrapped_rr_closure_arg*)arg; GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); if (wc_arg->rr_policy != nullptr) { - /* if *target is NULL, no pick has been made by the RR policy (eg, all + /* if *target is nullptr, no pick has been made by the RR policy (eg, all * addresses failed to connect). There won't be any user_data/token * available */ if (*wc_arg->target != nullptr) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { - initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, + initial_metadata_add_lb_token(wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); } else { @@ -221,7 +220,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p", wc_arg->glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); + GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "wrapped_rr_closure"); } GPR_ASSERT(wc_arg->free_when_done != nullptr); gpr_free(wc_arg->free_when_done); @@ -241,8 +240,8 @@ typedef struct pending_pick { /* original pick()'s arguments */ grpc_lb_policy_pick_args pick_args; - /* output argument where to store the pick()ed connected subchannel, or NULL - * upon error. */ + /* output argument where to store the pick()ed connected subchannel, or + * nullptr upon error. */ grpc_connected_subchannel** target; /* args for wrapped_on_complete */ @@ -328,8 +327,8 @@ typedef struct glb_lb_policy { /** connectivity state of the LB channel */ grpc_connectivity_state lb_channel_connectivity; - /** stores the deserialized response from the LB. May be NULL until one such - * response has arrived. */ + /** stores the deserialized response from the LB. May be nullptr until one + * such response has arrived. */ grpc_grpclb_serverlist* serverlist; /** Index into serverlist for next pick. @@ -459,9 +458,9 @@ static void* lb_token_copy(void* token) { ? nullptr : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; } -static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) { +static void lb_token_destroy(void* token) { if (token != nullptr) { - GRPC_MDELEM_UNREF(exec_ctx, grpc_mdelem{(uintptr_t)token}); + GRPC_MDELEM_UNREF(grpc_mdelem{(uintptr_t)token}); } } static int lb_token_cmp(void* token1, void* token2) { @@ -497,7 +496,7 @@ static void parse_server(const grpc_grpclb_server* server, /* Returns addresses extracted from \a serverlist. */ static grpc_lb_addresses* process_serverlist_locked( - grpc_exec_ctx* exec_ctx, const grpc_grpclb_serverlist* serverlist) { + const grpc_grpclb_serverlist* serverlist) { size_t num_valid = 0; /* first pass: count how many are valid in order to allocate the necessary * memory in a single block */ @@ -528,9 +527,9 @@ static grpc_lb_addresses* process_serverlist_locked( strnlen(server->load_balance_token, lb_token_max_length); grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( server->load_balance_token, lb_token_length); - user_data = (void*)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, - lb_token_mdstr) - .payload; + user_data = + (void*)grpc_mdelem_from_slices(GRPC_MDSTR_LB_TOKEN, lb_token_mdstr) + .payload; } else { char* uri = grpc_sockaddr_to_uri(&addr); gpr_log(GPR_INFO, @@ -552,7 +551,7 @@ static grpc_lb_addresses* process_serverlist_locked( /* Returns the backend addresses extracted from the given addresses */ static grpc_lb_addresses* extract_backend_addresses_locked( - grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses) { + const grpc_lb_addresses* addresses) { /* first pass: count the number of backend addresses */ size_t num_backends = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -577,8 +576,8 @@ static grpc_lb_addresses* extract_backend_addresses_locked( } static void update_lb_connectivity_status_locked( - grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, - grpc_connectivity_state rr_state, grpc_error* rr_state_error) { + glb_lb_policy* glb_policy, grpc_connectivity_state rr_state, + grpc_error* rr_state_error) { const grpc_connectivity_state curr_glb_state = grpc_connectivity_state_check(&glb_policy->state_tracker); @@ -630,7 +629,7 @@ static void update_lb_connectivity_status_locked( glb_policy, grpc_connectivity_state_name(rr_state), glb_policy->rr_policy); } - grpc_connectivity_state_set(exec_ctx, &glb_policy->state_tracker, rr_state, + grpc_connectivity_state_set(&glb_policy->state_tracker, rr_state, rr_state_error, "update_lb_connectivity_status_locked"); } @@ -641,9 +640,9 @@ static void update_lb_connectivity_status_locked( * If \a force_async is true, then we will manually schedule the * completion callback even if the pick is available immediately. */ static bool pick_from_internal_rr_locked( - grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, - const grpc_lb_policy_pick_args* pick_args, bool force_async, - grpc_connected_subchannel** target, wrapped_rr_closure_arg* wc_arg) { + glb_lb_policy* glb_policy, const grpc_lb_policy_pick_args* pick_args, + bool force_async, grpc_connected_subchannel** target, + wrapped_rr_closure_arg* wc_arg) { // Check for drops if we are not using fallback backend addresses. if (glb_policy->serverlist != nullptr) { // Look at the index into the serverlist to see if we should drop this call. @@ -658,7 +657,7 @@ static bool pick_from_internal_rr_locked( gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p for drop", glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); + GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "glb_pick_sync"); // Update client load reporting stats to indicate the number of // dropped calls. Note that we have to do this here instead of in // the client_load_reporting filter, because we do not create a @@ -670,7 +669,7 @@ static bool pick_from_internal_rr_locked( grpc_grpclb_client_stats_unref(wc_arg->client_stats); if (force_async) { GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; } @@ -680,7 +679,7 @@ static bool pick_from_internal_rr_locked( } // Pick via the RR policy. const bool pick_done = grpc_lb_policy_pick_locked( - exec_ctx, wc_arg->rr_policy, pick_args, target, wc_arg->context, + wc_arg->rr_policy, pick_args, target, wc_arg->context, (void**)&wc_arg->lb_token, &wc_arg->wrapper_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the RR policy. */ @@ -688,9 +687,9 @@ static bool pick_from_internal_rr_locked( gpr_log(GPR_INFO, "[grpclb %p] Unreffing RR %p", glb_policy, wc_arg->rr_policy); } - GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); + GRPC_LB_POLICY_UNREF(wc_arg->rr_policy, "glb_pick_sync"); /* add the load reporting initial metadata */ - initial_metadata_add_lb_token(exec_ctx, pick_args->initial_metadata, + initial_metadata_add_lb_token(pick_args->initial_metadata, pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); // Pass on client stats via context. Passes ownership of the reference. @@ -699,7 +698,7 @@ static bool pick_from_internal_rr_locked( wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; if (force_async) { GPR_ASSERT(wc_arg->wrapped_closure != nullptr); - GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; } @@ -712,12 +711,11 @@ static bool pick_from_internal_rr_locked( return pick_done; } -static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static grpc_lb_policy_args* lb_policy_args_create(glb_lb_policy* glb_policy) { grpc_lb_addresses* addresses; if (glb_policy->serverlist != nullptr) { GPR_ASSERT(glb_policy->serverlist->num_servers > 0); - addresses = process_serverlist_locked(exec_ctx, glb_policy->serverlist); + addresses = process_serverlist_locked(glb_policy->serverlist); } else { // If rr_handover_locked() is invoked when we haven't received any // serverlist from the balancer, we use the fallback backends returned by @@ -737,24 +735,21 @@ static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, args->args = grpc_channel_args_copy_and_add_and_remove( glb_policy->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, 1); - grpc_lb_addresses_destroy(exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); return args; } -static void lb_policy_args_destroy(grpc_exec_ctx* exec_ctx, - grpc_lb_policy_args* args) { - grpc_channel_args_destroy(exec_ctx, args->args); +static void lb_policy_args_destroy(grpc_lb_policy_args* args) { + grpc_channel_args_destroy(args->args); gpr_free(args); } -static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error); -static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, +static void glb_rr_connectivity_changed_locked(void* arg, grpc_error* error); +static void create_rr_locked(glb_lb_policy* glb_policy, grpc_lb_policy_args* args) { GPR_ASSERT(glb_policy->rr_policy == nullptr); - grpc_lb_policy* new_rr_policy = - grpc_lb_policy_create(exec_ctx, "round_robin", args); + grpc_lb_policy* new_rr_policy = grpc_lb_policy_create("round_robin", args); if (new_rr_policy == nullptr) { gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy for serverlist " @@ -767,21 +762,19 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, return; } grpc_lb_policy_set_reresolve_closure_locked( - exec_ctx, new_rr_policy, glb_policy->base.request_reresolution); + new_rr_policy, glb_policy->base.request_reresolution); glb_policy->base.request_reresolution = nullptr; glb_policy->rr_policy = new_rr_policy; grpc_error* rr_state_error = nullptr; const grpc_connectivity_state rr_state = - grpc_lb_policy_check_connectivity_locked(exec_ctx, glb_policy->rr_policy, + grpc_lb_policy_check_connectivity_locked(glb_policy->rr_policy, &rr_state_error); /* Connectivity state is a function of the RR policy updated/created */ - update_lb_connectivity_status_locked(exec_ctx, glb_policy, rr_state, - rr_state_error); + update_lb_connectivity_status_locked(glb_policy, rr_state, rr_state_error); /* Add the gRPC LB's interested_parties pollset_set to that of the newly * created RR policy. This will make the RR policy progress upon activity on * gRPC LB, which in turn is tied to the application's call */ - grpc_pollset_set_add_pollset_set(exec_ctx, - glb_policy->rr_policy->interested_parties, + grpc_pollset_set_add_pollset_set(glb_policy->rr_policy->interested_parties, glb_policy->base.interested_parties); /* Allocate the data for the tracking of the new RR policy's connectivity. @@ -796,10 +789,10 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, /* Subscribe to changes to the connectivity of the new RR */ GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "glb_rr_connectivity_cb"); - grpc_lb_policy_notify_on_state_change_locked(exec_ctx, glb_policy->rr_policy, + grpc_lb_policy_notify_on_state_change_locked(glb_policy->rr_policy, &rr_connectivity->state, &rr_connectivity->on_change); - grpc_lb_policy_exit_idle_locked(exec_ctx, glb_policy->rr_policy); + grpc_lb_policy_exit_idle_locked(glb_policy->rr_policy); /* Update picks and pings in wait */ pending_pick* pp; @@ -814,7 +807,7 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, "[grpclb %p] Pending pick about to (async) PICK from RR %p", glb_policy, glb_policy->rr_policy); } - pick_from_internal_rr_locked(exec_ctx, glb_policy, &pp->pick_args, + pick_from_internal_rr_locked(glb_policy, &pp->pick_args, true /* force_async */, pp->target, &pp->wrapped_on_complete_arg); } @@ -828,40 +821,37 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, gpr_log(GPR_INFO, "[grpclb %p] Pending ping about to PING from RR %p", glb_policy, glb_policy->rr_policy); } - grpc_lb_policy_ping_one_locked(exec_ctx, glb_policy->rr_policy, + grpc_lb_policy_ping_one_locked(glb_policy->rr_policy, &pping->wrapped_notify_arg.wrapper_closure); } } -/* glb_policy->rr_policy may be NULL (initial handover) */ -static void rr_handover_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +/* glb_policy->rr_policy may be nullptr (initial handover) */ +static void rr_handover_locked(glb_lb_policy* glb_policy) { if (glb_policy->shutting_down) return; - grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); + grpc_lb_policy_args* args = lb_policy_args_create(glb_policy); GPR_ASSERT(args != nullptr); if (glb_policy->rr_policy != nullptr) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Updating RR policy %p", glb_policy, glb_policy->rr_policy); } - grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args); + grpc_lb_policy_update_locked(glb_policy->rr_policy, args); } else { - create_rr_locked(exec_ctx, glb_policy, args); + create_rr_locked(glb_policy, args); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Created new RR policy %p", glb_policy, glb_policy->rr_policy); } } - lb_policy_args_destroy(exec_ctx, args); + lb_policy_args_destroy(args); } -static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void glb_rr_connectivity_changed_locked(void* arg, grpc_error* error) { rr_connectivity_data* rr_connectivity = (rr_connectivity_data*)arg; glb_lb_policy* glb_policy = rr_connectivity->glb_policy; if (glb_policy->shutting_down) { - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, - "glb_rr_connectivity_cb"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); return; } @@ -869,25 +859,22 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, /* An RR policy that has transitioned into the SHUTDOWN connectivity state * should not be considered for picks or updates: the SHUTDOWN state is a * sink, policies can't transition back from it. .*/ - GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, - "rr_connectivity_shutdown"); + GRPC_LB_POLICY_UNREF(glb_policy->rr_policy, "rr_connectivity_shutdown"); glb_policy->rr_policy = nullptr; - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, - "glb_rr_connectivity_cb"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); return; } /* rr state != SHUTDOWN && !glb_policy->shutting down: biz as usual */ - update_lb_connectivity_status_locked( - exec_ctx, glb_policy, rr_connectivity->state, GRPC_ERROR_REF(error)); + update_lb_connectivity_status_locked(glb_policy, rr_connectivity->state, + GRPC_ERROR_REF(error)); /* Resubscribe. Reuse the "glb_rr_connectivity_cb" weak ref. */ - grpc_lb_policy_notify_on_state_change_locked(exec_ctx, glb_policy->rr_policy, + grpc_lb_policy_notify_on_state_change_locked(glb_policy->rr_policy, &rr_connectivity->state, &rr_connectivity->on_change); } -static void destroy_balancer_name(grpc_exec_ctx* exec_ctx, - void* balancer_name) { +static void destroy_balancer_name(void* balancer_name) { gpr_free(balancer_name); } @@ -914,7 +901,7 @@ static int balancer_name_cmp_fn(void* a, void* b) { * above the grpclb policy. * - \a args: other args inherited from the grpclb policy. */ static grpc_channel_args* build_lb_channel_args( - grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses, + const grpc_lb_addresses* addresses, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { size_t num_grpclb_addrs = 0; @@ -957,7 +944,7 @@ static grpc_channel_args* build_lb_channel_args( gpr_free(targets_info_entries); grpc_channel_args* lb_channel_args = - grpc_lb_policy_grpclb_build_lb_channel_args(exec_ctx, targets_info, + grpc_lb_policy_grpclb_build_lb_channel_args(targets_info, response_generator, args); grpc_arg lb_channel_addresses_arg = @@ -965,34 +952,34 @@ static grpc_channel_args* build_lb_channel_args( grpc_channel_args* result = grpc_channel_args_copy_and_add( lb_channel_args, &lb_channel_addresses_arg, 1); - grpc_slice_hash_table_unref(exec_ctx, targets_info); - grpc_channel_args_destroy(exec_ctx, lb_channel_args); - grpc_lb_addresses_destroy(exec_ctx, lb_addresses); + grpc_slice_hash_table_unref(targets_info); + grpc_channel_args_destroy(lb_channel_args); + grpc_lb_addresses_destroy(lb_addresses); return result; } -static void glb_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void glb_destroy(grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; GPR_ASSERT(glb_policy->pending_picks == nullptr); GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); - grpc_channel_args_destroy(exec_ctx, glb_policy->args); + grpc_channel_args_destroy(glb_policy->args); if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } - grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); + grpc_connectivity_state_destroy(&glb_policy->state_tracker); if (glb_policy->serverlist != nullptr) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } if (glb_policy->fallback_backend_addresses != nullptr) { - grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); } grpc_fake_resolver_response_generator_unref(glb_policy->response_generator); grpc_subchannel_index_unref(); gpr_free(glb_policy); } -static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void glb_shutdown_locked(grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); glb_policy->shutting_down = true; @@ -1011,11 +998,11 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { /* lb_on_server_status_received will pick up the cancel and clean up */ } if (glb_policy->retry_timer_active) { - grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); + grpc_timer_cancel(&glb_policy->lb_call_retry_timer); glb_policy->retry_timer_active = false; } if (glb_policy->fallback_timer_active) { - grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); + grpc_timer_cancel(&glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; } @@ -1024,10 +1011,9 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pending_ping* pping = glb_policy->pending_pings; glb_policy->pending_pings = nullptr; if (glb_policy->rr_policy != nullptr) { - GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "glb_shutdown"); + GRPC_LB_POLICY_UNREF(glb_policy->rr_policy, "glb_shutdown"); } else { - grpc_lb_policy_try_reresolve(exec_ctx, pol, &grpc_lb_glb_trace, - GRPC_ERROR_CANCELLED); + grpc_lb_policy_try_reresolve(pol, &grpc_lb_glb_trace, GRPC_ERROR_CANCELLED); } // We destroy the LB channel here because // glb_lb_channel_on_connectivity_changed_cb needs a valid glb_policy @@ -1037,14 +1023,13 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { grpc_channel_destroy(glb_policy->lb_channel); glb_policy->lb_channel = nullptr; } - grpc_connectivity_state_set(exec_ctx, &glb_policy->state_tracker, - GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), - "glb_shutdown"); + grpc_connectivity_state_set(&glb_policy->state_tracker, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_REF(error), "glb_shutdown"); while (pp != nullptr) { pending_pick* next = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_REF(error)); gpr_free(pp); pp = next; @@ -1052,7 +1037,7 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { while (pping != nullptr) { pending_ping* next = pping->next; - GRPC_CLOSURE_SCHED(exec_ctx, &pping->wrapped_notify_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(&pping->wrapped_notify_arg.wrapper_closure, GRPC_ERROR_REF(error)); gpr_free(pping); pping = next; @@ -1069,8 +1054,8 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { // pick needs also be cancelled by the RR instance. // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, -// we invoke the completion closure and set *target to NULL right here. -static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +// we invoke the completion closure and set *target to nullptr right here. +static void glb_cancel_pick_locked(grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; @@ -1080,7 +1065,7 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); } else { @@ -1090,7 +1075,7 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, pp = next; } if (glb_policy->rr_policy != nullptr) { - grpc_lb_policy_cancel_pick_locked(exec_ctx, glb_policy->rr_policy, target, + grpc_lb_policy_cancel_pick_locked(glb_policy->rr_policy, target, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); @@ -1105,9 +1090,8 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, // pick needs also be cancelled by the RR instance. // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, -// we invoke the completion closure and set *target to NULL right here. -static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* pol, +// we invoke the completion closure and set *target to nullptr right here. +static void glb_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -1118,7 +1102,7 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, pending_pick* next = pp->next; if ((pp->pick_args.initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, + GRPC_CLOSURE_SCHED(&pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); } else { @@ -1129,52 +1113,49 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, } if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_picks_locked( - exec_ctx, glb_policy->rr_policy, initial_metadata_flags_mask, + glb_policy->rr_policy, initial_metadata_flags_mask, initial_metadata_flags_eq, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } -static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); -static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy); -static void start_picking_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void lb_on_fallback_timer_locked(void* arg, grpc_error* error); +static void query_for_backends_locked(glb_lb_policy* glb_policy); +static void start_picking_locked(glb_lb_policy* glb_policy) { /* start a timer to fall back */ if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == nullptr && !glb_policy->fallback_timer_active) { grpc_millis deadline = - grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_fallback_timeout_ms; + grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); GRPC_CLOSURE_INIT(&glb_policy->lb_on_fallback, lb_on_fallback_timer_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); glb_policy->fallback_timer_active = true; - grpc_timer_init(exec_ctx, &glb_policy->lb_fallback_timer, deadline, + grpc_timer_init(&glb_policy->lb_fallback_timer, deadline, &glb_policy->lb_on_fallback); } glb_policy->started_picking = true; grpc_backoff_reset(&glb_policy->lb_call_backoff_state); - query_for_backends_locked(exec_ctx, glb_policy); + query_for_backends_locked(glb_policy); } -static void glb_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void glb_exit_idle_locked(grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (!glb_policy->started_picking) { - start_picking_locked(exec_ctx, glb_policy); + start_picking_locked(glb_policy); } } -static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static int glb_pick_locked(grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { if (pick_args->lb_token_mdelem_storage == nullptr) { *target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, on_complete, + GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No mdelem storage for the LB token. Load reporting " "won't work without it. Failing")); @@ -1184,8 +1165,8 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, bool pick_done = false; if (glb_policy->rr_policy != nullptr) { const grpc_connectivity_state rr_connectivity_state = - grpc_lb_policy_check_connectivity_locked( - exec_ctx, glb_policy->rr_policy, nullptr); + grpc_lb_policy_check_connectivity_locked(glb_policy->rr_policy, + nullptr); // The glb_policy->rr_policy may have transitioned to SHUTDOWN but the // callback registered to capture this event // (glb_rr_connectivity_changed_locked) may not have been invoked yet. We @@ -1222,9 +1203,8 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, wc_arg->initial_metadata = pick_args->initial_metadata; wc_arg->free_when_done = wc_arg; wc_arg->glb_policy = pol; - pick_done = - pick_from_internal_rr_locked(exec_ctx, glb_policy, pick_args, - false /* force_async */, target, wc_arg); + pick_done = pick_from_internal_rr_locked( + glb_policy, pick_args, false /* force_async */, target, wc_arg); } } else { // glb_policy->rr_policy == NULL if (grpc_lb_glb_trace.enabled()) { @@ -1235,7 +1215,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, add_pending_pick(&glb_policy->pending_picks, pick_args, target, context, on_complete); if (!glb_policy->started_picking) { - start_picking_locked(exec_ctx, glb_policy); + start_picking_locked(glb_policy); } pick_done = false; } @@ -1243,37 +1223,33 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } static grpc_connectivity_state glb_check_connectivity_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, - grpc_error** connectivity_error) { + grpc_lb_policy* pol, grpc_error** connectivity_error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; return grpc_connectivity_state_get(&glb_policy->state_tracker, connectivity_error); } -static void glb_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, - grpc_closure* closure) { +static void glb_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (glb_policy->rr_policy) { - grpc_lb_policy_ping_one_locked(exec_ctx, glb_policy->rr_policy, closure); + grpc_lb_policy_ping_one_locked(glb_policy->rr_policy, closure); } else { add_pending_ping(&glb_policy->pending_pings, closure); if (!glb_policy->started_picking) { - start_picking_locked(exec_ctx, glb_policy); + start_picking_locked(glb_policy); } } } -static void glb_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* pol, +static void glb_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &glb_policy->state_tracker, current, notify); + grpc_connectivity_state_notify_on_state_change(&glb_policy->state_tracker, + current, notify); } -static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void lb_call_on_retry_timer_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->retry_timer_active = false; if (!glb_policy->shutting_down && glb_policy->lb_call == nullptr && @@ -1281,28 +1257,26 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", glb_policy); } - query_for_backends_locked(exec_ctx, glb_policy); + query_for_backends_locked(glb_policy); } - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "grpclb_retry_timer"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "grpclb_retry_timer"); } -static void maybe_restart_lb_call(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void maybe_restart_lb_call(glb_lb_policy* glb_policy) { if (glb_policy->started_picking && glb_policy->updating_lb_call) { if (glb_policy->retry_timer_active) { - grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); + grpc_timer_cancel(&glb_policy->lb_call_retry_timer); } - if (!glb_policy->shutting_down) start_picking_locked(exec_ctx, glb_policy); + if (!glb_policy->shutting_down) start_picking_locked(glb_policy); glb_policy->updating_lb_call = false; } else if (!glb_policy->shutting_down) { /* if we aren't shutting down, restart the LB client call after some time */ - grpc_millis next_try = - grpc_backoff_step(exec_ctx, &glb_policy->lb_call_backoff_state) - .next_attempt_start_time; + grpc_millis next_try = grpc_backoff_step(&glb_policy->lb_call_backoff_state) + .next_attempt_start_time; if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); - grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); if (timeout > 0) { gpr_log(GPR_DEBUG, "[grpclb %p] ... retry_timer_active in %" PRIuPTR "ms.", @@ -1317,43 +1291,40 @@ static void maybe_restart_lb_call(grpc_exec_ctx* exec_ctx, lb_call_on_retry_timer_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); glb_policy->retry_timer_active = true; - grpc_timer_init(exec_ctx, &glb_policy->lb_call_retry_timer, next_try, + grpc_timer_init(&glb_policy->lb_call_retry_timer, next_try, &glb_policy->lb_on_call_retry); } - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "lb_on_server_status_received_locked"); } -static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +static void send_client_load_report_locked(void* arg, grpc_error* error); -static void schedule_next_client_load_report(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void schedule_next_client_load_report(glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = - grpc_exec_ctx_now(exec_ctx) + glb_policy->client_stats_report_interval; + grpc_core::ExecCtx::Get()->Now() + + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, send_client_load_report_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); - grpc_timer_init(exec_ctx, &glb_policy->client_load_report_timer, + grpc_timer_init(&glb_policy->client_load_report_timer, next_client_load_report_time, &glb_policy->client_load_report_closure); } -static void client_load_report_done_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void client_load_report_done_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); glb_policy->client_load_report_payload = nullptr; if (error != GRPC_ERROR_NONE || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, - "client_load_report"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "client_load_report"); if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(exec_ctx, glb_policy); + maybe_restart_lb_call(glb_policy); } return; } - schedule_next_client_load_report(exec_ctx, glb_policy); + schedule_next_client_load_report(glb_policy); } static bool load_report_counters_are_zero(grpc_grpclb_request* request) { @@ -1368,15 +1339,13 @@ static bool load_report_counters_are_zero(grpc_grpclb_request* request) { (drop_entries == nullptr || drop_entries->num_entries == 0); } -static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void send_client_load_report_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, - "client_load_report"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "client_load_report"); if (glb_policy->lb_call == nullptr) { - maybe_restart_lb_call(exec_ctx, glb_policy); + maybe_restart_lb_call(glb_policy); } return; } @@ -1389,7 +1358,7 @@ static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, if (load_report_counters_are_zero(request)) { if (glb_policy->last_client_load_report_counters_were_zero) { grpc_grpclb_request_destroy(request); - schedule_next_client_load_report(exec_ctx, glb_policy); + schedule_next_client_load_report(glb_policy); return; } glb_policy->last_client_load_report_counters_were_zero = true; @@ -1399,7 +1368,7 @@ static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); glb_policy->client_load_report_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_slice_unref_internal(exec_ctx, request_payload_slice); + grpc_slice_unref_internal(request_payload_slice); grpc_grpclb_request_destroy(request); // Send load report message. grpc_op op; @@ -1410,20 +1379,16 @@ static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, client_load_report_done_locked, glb_policy, grpc_combiner_scheduler(glb_policy->base.combiner)); grpc_call_error call_error = grpc_call_start_batch_and_execute( - exec_ctx, glb_policy->lb_call, &op, 1, - &glb_policy->client_load_report_closure); + glb_policy->lb_call, &op, 1, &glb_policy->client_load_report_closure); if (call_error != GRPC_CALL_OK) { gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", glb_policy, call_error); GPR_ASSERT(GRPC_CALL_OK == call_error); } } -static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error); -static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); -static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void lb_on_server_status_received_locked(void* arg, grpc_error* error); +static void lb_on_response_received_locked(void* arg, grpc_error* error); +static void lb_call_init_locked(glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->server_name != nullptr); GPR_ASSERT(glb_policy->server_name[0] != '\0'); GPR_ASSERT(glb_policy->lb_call == nullptr); @@ -1436,13 +1401,13 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, grpc_millis deadline = glb_policy->lb_call_timeout_ms == 0 ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_call_timeout_ms; + : grpc_core::ExecCtx::Get()->Now() + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( - exec_ctx, glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, + glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, &host, deadline, nullptr); - grpc_slice_unref_internal(exec_ctx, host); + grpc_slice_unref_internal(host); if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); @@ -1457,7 +1422,7 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); glb_policy->lb_request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_slice_unref_internal(exec_ctx, request_payload_slice); + grpc_slice_unref_internal(request_payload_slice); grpc_grpclb_request_destroy(request); GRPC_CLOSURE_INIT(&glb_policy->lb_on_server_status_received, @@ -1478,8 +1443,7 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, glb_policy->last_client_load_report_counters_were_zero = false; } -static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void lb_call_destroy_locked(glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_unref(glb_policy->lb_call); glb_policy->lb_call = nullptr; @@ -1488,22 +1452,21 @@ static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); grpc_byte_buffer_destroy(glb_policy->lb_request_payload); - grpc_slice_unref_internal(exec_ctx, glb_policy->lb_call_status_details); + grpc_slice_unref_internal(glb_policy->lb_call_status_details); if (glb_policy->client_load_report_timer_pending) { - grpc_timer_cancel(exec_ctx, &glb_policy->client_load_report_timer); + grpc_timer_cancel(&glb_policy->client_load_report_timer); } } /* * Auxiliary functions and LB client callbacks. */ -static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy) { +static void query_for_backends_locked(glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_channel != nullptr); if (glb_policy->shutting_down) return; - lb_call_init_locked(exec_ctx, glb_policy); + lb_call_init_locked(glb_policy); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, @@ -1534,8 +1497,8 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->flags = 0; op->reserved = nullptr; op++; - call_error = grpc_call_start_batch_and_execute( - exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), nullptr); + call_error = grpc_call_start_batch_and_execute(glb_policy->lb_call, ops, + (size_t)(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); op = ops; @@ -1553,7 +1516,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "lb_on_server_status_received_locked"); call_error = grpc_call_start_batch_and_execute( - exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_server_status_received); GPR_ASSERT(GRPC_CALL_OK == call_error); @@ -1567,13 +1530,12 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, * lb_on_response_received_locked */ GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "lb_on_response_received_locked"); call_error = grpc_call_start_batch_and_execute( - exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_response_received); GPR_ASSERT(GRPC_CALL_OK == call_error); } -static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void lb_on_response_received_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_op ops[2]; memset(ops, 0, sizeof(ops)); @@ -1607,7 +1569,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, * send_client_load_report_locked() */ glb_policy->client_load_report_timer_pending = true; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "client_load_report"); - schedule_next_client_load_report(exec_ctx, glb_policy); + schedule_next_client_load_report(glb_policy); } else if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Received initial LB response message; client load " @@ -1652,11 +1614,10 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } else { /* or dispose of the fallback */ - grpc_lb_addresses_destroy(exec_ctx, - glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = nullptr; if (glb_policy->fallback_timer_active) { - grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); + grpc_timer_cancel(&glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; } } @@ -1665,7 +1626,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, * update or in glb_destroy() */ glb_policy->serverlist = serverlist; glb_policy->serverlist_index = 0; - rr_handover_locked(exec_ctx, glb_policy); + rr_handover_locked(glb_policy); } } else { if (grpc_lb_glb_trace.enabled()) { @@ -1675,14 +1636,14 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, } grpc_grpclb_destroy_serverlist(serverlist); } - } else { /* serverlist == NULL */ + } else { /* serverlist == nullptr */ gpr_log(GPR_ERROR, "[grpclb %p] Invalid LB response received: '%s'. Ignoring.", glb_policy, grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX)); } } - grpc_slice_unref_internal(exec_ctx, response_slice); + grpc_slice_unref_internal(response_slice); if (!glb_policy->shutting_down) { /* keep listening for serverlist updates */ op->op = GRPC_OP_RECV_MESSAGE; @@ -1693,23 +1654,22 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, /* reuse the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() */ const grpc_call_error call_error = grpc_call_start_batch_and_execute( - exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), + glb_policy->lb_call, ops, (size_t)(op - ops), &glb_policy->lb_on_response_received); /* loop */ GPR_ASSERT(GRPC_CALL_OK == call_error); } else { - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "lb_on_response_received_locked_shutdown"); } } else { /* empty payload: call cancelled. */ /* dispose of the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() and reused in every reception loop */ - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "lb_on_response_received_locked_empty_payload"); } } -static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void lb_on_fallback_timer_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->fallback_timer_active = false; /* If we receive a serverlist after the timer fires but before this callback @@ -1722,15 +1682,13 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy); } GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); - rr_handover_locked(exec_ctx, glb_policy); + rr_handover_locked(glb_policy); } } - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, - "grpclb_fallback_timer"); + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "grpclb_fallback_timer"); } -static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void lb_on_server_status_received_locked(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; GPR_ASSERT(glb_policy->lb_call != nullptr); if (grpc_lb_glb_trace.enabled()) { @@ -1744,29 +1702,28 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, gpr_free(status_details); } /* We need to perform cleanups no matter what. */ - lb_call_destroy_locked(exec_ctx, glb_policy); + lb_call_destroy_locked(glb_policy); // If the load report timer is still pending, we wait for it to be // called before restarting the call. Otherwise, we restart the call // here. if (!glb_policy->client_load_report_timer_pending) { - maybe_restart_lb_call(exec_ctx, glb_policy); + maybe_restart_lb_call(glb_policy); } } -static void fallback_update_locked(grpc_exec_ctx* exec_ctx, - glb_lb_policy* glb_policy, +static void fallback_update_locked(glb_lb_policy* glb_policy, const grpc_lb_addresses* addresses) { GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); - grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); + grpc_lb_addresses_destroy(glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = - extract_backend_addresses_locked(exec_ctx, addresses); + extract_backend_addresses_locked(addresses); if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->rr_policy != nullptr) { - rr_handover_locked(exec_ctx, glb_policy); + rr_handover_locked(glb_policy); } } -static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, +static void glb_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { glb_lb_policy* glb_policy = (glb_lb_policy*)policy; const grpc_arg* arg = @@ -1776,7 +1733,7 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // If we don't have a current channel to the LB, go into TRANSIENT // FAILURE. grpc_connectivity_state_set( - exec_ctx, &glb_policy->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &glb_policy->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "glb_update_missing"); } else { @@ -1793,16 +1750,16 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. if (glb_policy->serverlist == nullptr) { - fallback_update_locked(exec_ctx, glb_policy, addresses); + fallback_update_locked(glb_policy, addresses); } GPR_ASSERT(glb_policy->lb_channel != nullptr); // Propagate updates to the LB channel (pick_first) through the fake // resolver. grpc_channel_args* lb_channel_args = build_lb_channel_args( - exec_ctx, addresses, glb_policy->response_generator, args->args); + addresses, glb_policy->response_generator, args->args); grpc_fake_resolver_response_generator_set_response( - exec_ctx, glb_policy->response_generator, lb_channel_args); - grpc_channel_args_destroy(exec_ctx, lb_channel_args); + glb_policy->response_generator, lb_channel_args); + grpc_channel_args_destroy(lb_channel_args); // Start watching the LB channel connectivity for connection, if not // already doing so. if (!glb_policy->watching_lb_channel) { @@ -1814,7 +1771,7 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, glb_policy->watching_lb_channel = true; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "watch_lb_channel_connectivity"); grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, + client_channel_elem, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, @@ -1825,8 +1782,7 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // Invoked as part of the update process. It continues watching the LB channel // until it shuts down or becomes READY. It's invoked even if the LB channel // stayed READY throughout the update (for example if the update is identical). -static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, - void* arg, +static void glb_lb_channel_on_connectivity_changed_cb(void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (glb_policy->shutting_down) goto done; @@ -1842,7 +1798,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, grpc_channel_get_channel_stack(glb_policy->lb_channel)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); grpc_client_channel_watch_connectivity_state( - exec_ctx, client_channel_elem, + client_channel_elem, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, @@ -1861,29 +1817,28 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, // lb_call. } else if (glb_policy->started_picking) { if (glb_policy->retry_timer_active) { - grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); + grpc_timer_cancel(&glb_policy->lb_call_retry_timer); glb_policy->retry_timer_active = false; } - start_picking_locked(exec_ctx, glb_policy); + start_picking_locked(glb_policy); } /* fallthrough */ case GRPC_CHANNEL_SHUTDOWN: done: glb_policy->watching_lb_channel = false; - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, + GRPC_LB_POLICY_WEAK_UNREF(&glb_policy->base, "watch_lb_channel_connectivity_cb_shutdown"); break; } } static void glb_set_reresolve_closure_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* request_reresolution) { + grpc_lb_policy* policy, grpc_closure* request_reresolution) { glb_lb_policy* glb_policy = (glb_lb_policy*)policy; GPR_ASSERT(!glb_policy->shutting_down); GPR_ASSERT(glb_policy->base.request_reresolution == nullptr); if (glb_policy->rr_policy != nullptr) { - grpc_lb_policy_set_reresolve_closure_locked(exec_ctx, glb_policy->rr_policy, + grpc_lb_policy_set_reresolve_closure_locked(glb_policy->rr_policy, request_reresolution); } else { glb_policy->base.request_reresolution = request_reresolution; @@ -1904,8 +1859,7 @@ static const grpc_lb_policy_vtable glb_lb_policy_vtable = { glb_update_locked, glb_set_reresolve_closure_locked}; -static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, - grpc_lb_policy_factory* factory, +static grpc_lb_policy* glb_create(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { /* Count the number of gRPC-LB addresses. There must be at least one. */ const grpc_arg* arg = @@ -1926,7 +1880,7 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg->type == GRPC_ARG_STRING); - grpc_uri* uri = grpc_uri_parse(exec_ctx, arg->value.string, true); + grpc_uri* uri = grpc_uri_parse(arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); glb_policy->server_name = gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path); @@ -1959,26 +1913,26 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, /* Extract the backend addresses (may be empty) from the resolver for * fallback. */ glb_policy->fallback_backend_addresses = - extract_backend_addresses_locked(exec_ctx, addresses); + extract_backend_addresses_locked(addresses); /* Create a client channel over them to communicate with a LB service */ glb_policy->response_generator = grpc_fake_resolver_response_generator_create(); grpc_channel_args* lb_channel_args = build_lb_channel_args( - exec_ctx, addresses, glb_policy->response_generator, args->args); + addresses, glb_policy->response_generator, args->args); char* uri_str; gpr_asprintf(&uri_str, "fake:///%s", glb_policy->server_name); glb_policy->lb_channel = grpc_lb_policy_grpclb_create_lb_channel( - exec_ctx, uri_str, args->client_channel_factory, lb_channel_args); + uri_str, args->client_channel_factory, lb_channel_args); /* Propagate initial resolution */ grpc_fake_resolver_response_generator_set_response( - exec_ctx, glb_policy->response_generator, lb_channel_args); - grpc_channel_args_destroy(exec_ctx, lb_channel_args); + glb_policy->response_generator, lb_channel_args); + grpc_channel_args_destroy(lb_channel_args); gpr_free(uri_str); if (glb_policy->lb_channel == nullptr) { gpr_free((void*)glb_policy->server_name); - grpc_channel_args_destroy(exec_ctx, glb_policy->args); + grpc_channel_args_destroy(glb_policy->args); gpr_free(glb_policy); return nullptr; } @@ -2009,7 +1963,7 @@ grpc_lb_policy_factory* grpc_glb_lb_factory_create() { // Only add client_load_reporting filter if the grpclb LB policy is used. static bool maybe_add_client_load_reporting_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* channel_arg = diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc index aacaec197d..a8ecea4212 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc @@ -26,17 +26,17 @@ #include "src/core/lib/support/string.h" grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args) { grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( - exec_ctx, client_channel_factory, lb_service_target_addresses, + client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args); return lb_channel; } grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { const grpc_arg to_add[] = { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h index 70b1c28b0d..56104b2ec0 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h @@ -31,12 +31,12 @@ * \a client_channel_factory will be used for the creation of the LB channel, * alongside the channel args passed in \a args. */ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args); grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 8eaa90e97b..76bcddf945 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -29,7 +29,7 @@ #include "src/core/lib/support/string.h" grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + const char* lb_service_target_addresses, grpc_client_channel_factory* client_channel_factory, grpc_channel_args* args) { grpc_channel_args* new_args = args; @@ -50,19 +50,19 @@ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( new_args = grpc_channel_args_copy_and_add_and_remove( args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add, GPR_ARRAY_SIZE(args_to_add)); - grpc_channel_credentials_unref(exec_ctx, creds_sans_call_creds); + grpc_channel_credentials_unref(creds_sans_call_creds); } grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( - exec_ctx, client_channel_factory, lb_service_target_addresses, + client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); if (channel_credentials != nullptr) { - grpc_channel_args_destroy(exec_ctx, new_args); + grpc_channel_args_destroy(new_args); } return lb_channel; } grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_slice_hash_table* targets_info, grpc_fake_resolver_response_generator* response_generator, const grpc_channel_args* args) { const grpc_arg to_add[] = { diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 228a77d9db..5e75b64843 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -57,12 +57,12 @@ typedef struct { grpc_connectivity_state_tracker state_tracker; } pick_first_lb_policy; -static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void pf_destroy(grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; GPR_ASSERT(p->subchannel_list == nullptr); GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); GPR_ASSERT(p->pending_picks == nullptr); - grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); + grpc_connectivity_state_destroy(&p->state_tracker); gpr_free(p); grpc_subchannel_index_unref(); if (grpc_lb_pick_first_trace.enabled()) { @@ -70,7 +70,7 @@ static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { } } -static void pf_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void pf_shutdown_locked(grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_pick_first_trace.enabled()) { @@ -81,28 +81,27 @@ static void pf_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), - "shutdown"); + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_REF(error), "shutdown"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "pf_shutdown"); p->subchannel_list = nullptr; } if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->latest_pending_subchannel_list, "pf_shutdown"); + p->latest_pending_subchannel_list, "pf_shutdown"); p->latest_pending_subchannel_list = nullptr; } - grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_pick_first_trace, + grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_CANCELLED); GRPC_ERROR_UNREF(error); } -static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static void pf_cancel_pick_locked(grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; @@ -112,7 +111,7 @@ static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); gpr_free(pp); @@ -125,7 +124,7 @@ static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static void pf_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -136,7 +135,7 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); gpr_free(pp); @@ -149,8 +148,7 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(grpc_exec_ctx* exec_ctx, - pick_first_lb_policy* p) { +static void start_picking_locked(pick_first_lb_policy* p) { p->started_picking = true; if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) { @@ -160,21 +158,21 @@ static void start_picking_locked(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list_ref_for_connectivity_watch( p->subchannel_list, "connectivity_watch+start_picking"); grpc_lb_subchannel_data_start_connectivity_watch( - exec_ctx, &p->subchannel_list->subchannels[i]); + &p->subchannel_list->subchannels[i]); break; } } } } -static void pf_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void pf_exit_idle_locked(grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (!p->started_picking) { - start_picking_locked(exec_ctx, p); + start_picking_locked(p); } } -static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static int pf_pick_locked(grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, @@ -188,7 +186,7 @@ static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } // No subchannel selected yet, so handle asynchronously. if (!p->started_picking) { - start_picking_locked(exec_ctx, p); + start_picking_locked(p); } pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; @@ -199,48 +197,43 @@ static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, return 0; } -static void destroy_unselected_subchannels_locked(grpc_exec_ctx* exec_ctx, - pick_first_lb_policy* p) { +static void destroy_unselected_subchannels_locked(pick_first_lb_policy* p) { for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { grpc_lb_subchannel_data* sd = &p->subchannel_list->subchannels[i]; if (p->selected != sd) { - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, + grpc_lb_subchannel_data_unref_subchannel(sd, "selected_different_subchannel"); } } } static grpc_connectivity_state pf_check_connectivity_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { + grpc_lb_policy* pol, grpc_error** error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void pf_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* pol, +static void pf_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, - current, notify); + grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, + notify); } -static void pf_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, - grpc_closure* closure) { +static void pf_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (p->selected) { - grpc_connected_subchannel_ping(exec_ctx, p->selected->connected_subchannel, - closure); + grpc_connected_subchannel_ping(p->selected->connected_subchannel, closure); } else { - GRPC_CLOSURE_SCHED(exec_ctx, closure, + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Not connected")); } } -static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +static void pf_connectivity_changed_locked(void* arg, grpc_error* error); -static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, +static void pf_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { pick_first_lb_policy* p = (pick_first_lb_policy*)policy; const grpc_arg* arg = @@ -249,7 +242,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, if (p->subchannel_list == nullptr) { // If we don't have a current subchannel list, go into TRANSIENT FAILURE. grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "pf_update_missing"); } else { @@ -268,17 +261,17 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, (void*)p, (unsigned long)addresses->num_addresses); } grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( - exec_ctx, &p->base, &grpc_lb_pick_first_trace, addresses, args, + &p->base, &grpc_lb_pick_first_trace, addresses, args, pf_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { // Empty update or no valid subchannels. Unsubscribe from all current // subchannels and put the channel in TRANSIENT_FAILURE. grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "pf_update_empty"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // Empty list. @@ -289,7 +282,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // We don't yet have a selected subchannel, so replace the current // subchannel list immediately. if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "pf_update_before_selected"); } p->subchannel_list = subchannel_list; @@ -314,19 +307,19 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, p->selected = sd; if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->subchannel_list, "pf_update_includes_selected"); + p->subchannel_list, "pf_update_includes_selected"); } p->subchannel_list = subchannel_list; - destroy_unselected_subchannels_locked(exec_ctx, p); + destroy_unselected_subchannels_locked(p); grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+replace_selected"); - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); // If there was a previously pending update (which may or may // not have contained the currently selected subchannel), drop // it, so that it doesn't override what we've done here. if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->latest_pending_subchannel_list, + p->latest_pending_subchannel_list, "pf_update_includes_selected+outdated"); p->latest_pending_subchannel_list = nullptr; } @@ -346,8 +339,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->latest_pending_subchannel_list, - "sl_outdated_dont_smash"); + p->latest_pending_subchannel_list, "sl_outdated_dont_smash"); } p->latest_pending_subchannel_list = subchannel_list; } @@ -357,12 +349,11 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+update"); grpc_lb_subchannel_data_start_connectivity_watch( - exec_ctx, &subchannel_list->subchannels[0]); + &subchannel_list->subchannels[0]); } } -static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void pf_connectivity_changed_locked(void* arg, grpc_error* error) { grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy; if (grpc_lb_pick_first_trace.enabled()) { @@ -380,18 +371,18 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } // If the policy is shutting down, unref and return. if (p->shutdown) { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "pf_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "pf_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, + "pf_shutdown"); return; } // If the subchannel list is shutting down, stop watching. if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_sl_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "pf_sl_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "pf_sl_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, + "pf_sl_shutdown"); return; } // If we're still here, the notification must be for a subchannel in @@ -407,15 +398,15 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, if (sd->curr_connectivity_state != GRPC_CHANNEL_READY && p->latest_pending_subchannel_list != nullptr) { p->selected = nullptr; - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "selected_not_ready+switch_to_update"); + sd->subchannel_list, "selected_not_ready+switch_to_update"); grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->subchannel_list, "selected_not_ready+switch_to_update"); + p->subchannel_list, "selected_not_ready+switch_to_update"); p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update"); } else { // TODO(juanlishen): we re-resolve when the selected subchannel goes to @@ -426,27 +417,26 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, if (sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN || sd->curr_connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { // If the selected channel goes bad, request a re-resolution. - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, + GRPC_ERROR_NONE, "selected_changed+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve( - exec_ctx, &p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_NONE); + grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, + GRPC_ERROR_NONE); } else { - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + grpc_connectivity_state_set(&p->state_tracker, sd->curr_connectivity_state, GRPC_ERROR_REF(error), "selected_changed"); } if (sd->curr_connectivity_state != GRPC_CHANNEL_SHUTDOWN) { // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); } else { p->selected = nullptr; - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "pf_selected_shutdown"); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, - "pf_selected_shutdown"); + sd->subchannel_list, "pf_selected_shutdown"); + grpc_lb_subchannel_data_unref_subchannel(sd, "pf_selected_shutdown"); } } return; @@ -466,15 +456,14 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // p->subchannel_list. if (sd->subchannel_list == p->latest_pending_subchannel_list) { GPR_ASSERT(p->subchannel_list != nullptr); - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "finish_update"); p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; } // Cases 1 and 2. - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_READY, GRPC_ERROR_NONE, - "connecting_ready"); + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_READY, + GRPC_ERROR_NONE, "connecting_ready"); sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( grpc_subchannel_get_connected_subchannel(sd->subchannel), "connected"); @@ -484,7 +473,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, (void*)sd->subchannel); } // Drop all other subchannels, since we are now connected. - destroy_unselected_subchannels_locked(exec_ctx, p); + destroy_unselected_subchannels_locked(p); // Update any calls that were waiting for a pick. pending_pick* pp; while ((pp = p->pending_picks)) { @@ -496,15 +485,15 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, "Servicing pending pick with selected subchannel %p", (void*)p->selected); } - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); break; } case GRPC_CHANNEL_TRANSIENT_FAILURE: { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); do { sd->subchannel_list->checking_subchannel = (sd->subchannel_list->checking_subchannel + 1) % @@ -517,29 +506,28 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, if (sd->subchannel_list->checking_subchannel == 0 && sd->subchannel_list == p->subchannel_list) { grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "connecting_transient_failure"); } // Reuses the connectivity refs from the previous watch. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); break; } case GRPC_CHANNEL_CONNECTING: case GRPC_CHANNEL_IDLE: { // Only update connectivity state in case 1. if (sd->subchannel_list == p->subchannel_list) { - grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_CONNECTING, - GRPC_ERROR_REF(error), "connecting_changed"); + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_CONNECTING, + GRPC_ERROR_REF(error), + "connecting_changed"); } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); break; } case GRPC_CHANNEL_SHUTDOWN: { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, - "pf_candidate_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "pf_candidate_shutdown"); // Advance to next subchannel and check its state. grpc_lb_subchannel_data* original_sd = sd; do { @@ -551,31 +539,30 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } while (sd->subchannel == nullptr && sd != original_sd); if (sd == original_sd) { grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "pf_exhausted_subchannels"); + sd->subchannel_list, "pf_exhausted_subchannels"); if (sd->subchannel_list == p->subchannel_list) { - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, + GRPC_ERROR_NONE, "exhausted_subchannels+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve( - exec_ctx, &p->base, &grpc_lb_pick_first_trace, GRPC_ERROR_NONE); + grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_pick_first_trace, + GRPC_ERROR_NONE); } } else { if (sd->subchannel_list == p->subchannel_list) { grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "subchannel_failed"); } // Reuses the connectivity refs from the previous watch. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); } } } } static void pf_set_reresolve_closure_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* request_reresolution) { + grpc_lb_policy* policy, grpc_closure* request_reresolution) { pick_first_lb_policy* p = (pick_first_lb_policy*)policy; GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); @@ -599,15 +586,14 @@ static void pick_first_factory_ref(grpc_lb_policy_factory* factory) {} static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, - grpc_lb_policy_factory* factory, +static grpc_lb_policy* create_pick_first(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); } - pf_update_locked(exec_ctx, &p->base, args); + pf_update_locked(&p->base, args); grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); return &p->base; diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index f68daba474..6958b72693 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -154,7 +154,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, } } -static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void rr_destroy(grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", @@ -162,12 +162,12 @@ static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { } GPR_ASSERT(p->subchannel_list == nullptr); GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); - grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); + grpc_connectivity_state_destroy(&p->state_tracker); grpc_subchannel_index_unref(); gpr_free(p); } -static void rr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void rr_shutdown_locked(grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown"); if (grpc_lb_round_robin_trace.enabled()) { @@ -178,29 +178,27 @@ static void rr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; *pp->target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), - "rr_shutdown"); + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_REF(error), "rr_shutdown"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "sl_shutdown_rr_shutdown"); p->subchannel_list = nullptr; } if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->latest_pending_subchannel_list, - "sl_shutdown_pending_rr_shutdown"); + p->latest_pending_subchannel_list, "sl_shutdown_pending_rr_shutdown"); p->latest_pending_subchannel_list = nullptr; } - grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_round_robin_trace, + grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_round_robin_trace, GRPC_ERROR_CANCELLED); GRPC_ERROR_UNREF(error); } -static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static void rr_cancel_pick_locked(grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; @@ -210,7 +208,7 @@ static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, pending_pick* next = pp->next; if (pp->target == target) { *target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); gpr_free(pp); @@ -223,7 +221,7 @@ static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static void rr_cancel_picks_locked(grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, grpc_error* error) { @@ -235,7 +233,7 @@ static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { *pp->target = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); gpr_free(pp); @@ -248,27 +246,26 @@ static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(grpc_exec_ctx* exec_ctx, - round_robin_lb_policy* p) { +static void start_picking_locked(round_robin_lb_policy* p) { p->started_picking = true; for (size_t i = 0; i < p->subchannel_list->num_subchannels; i++) { if (p->subchannel_list->subchannels[i].subchannel != nullptr) { grpc_lb_subchannel_list_ref_for_connectivity_watch(p->subchannel_list, "connectivity_watch"); grpc_lb_subchannel_data_start_connectivity_watch( - exec_ctx, &p->subchannel_list->subchannels[i]); + &p->subchannel_list->subchannels[i]); } } } -static void rr_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { +static void rr_exit_idle_locked(grpc_lb_policy* pol) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (!p->started_picking) { - start_picking_locked(exec_ctx, p); + start_picking_locked(p); } } -static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, +static int rr_pick_locked(grpc_lb_policy* pol, const grpc_lb_policy_pick_args* pick_args, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, @@ -305,7 +302,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } /* no pick currently available. Save for later in list of pending picks */ if (!p->started_picking) { - start_picking_locked(exec_ctx, p); + start_picking_locked(p); } pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; @@ -348,8 +345,7 @@ static void update_state_counters_locked(grpc_lb_subchannel_data* sd) { * (the grpc_lb_subchannel_data associated with the updated subchannel) and the * subchannel list \a sd belongs to (sd->subchannel_list). \a error will be used * only if the policy transitions to state TRANSIENT_FAILURE. */ -static void update_lb_connectivity_status_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_data* sd, +static void update_lb_connectivity_status_locked(grpc_lb_subchannel_data* sd, grpc_error* error) { /* In priority order. The first rule to match terminates the search (ie, if we * are on rule n, all previous rules were unfulfilled). @@ -382,38 +378,36 @@ static void update_lb_connectivity_status_locked(grpc_exec_ctx* exec_ctx, round_robin_lb_policy* p = (round_robin_lb_policy*)subchannel_list->policy; if (subchannel_list->num_ready > 0) { /* 1) READY */ - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_READY, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "rr_ready"); } else if (sd->curr_connectivity_state == GRPC_CHANNEL_CONNECTING) { /* 2) CONNECTING */ - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, - GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, - "rr_connecting"); + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_CONNECTING, + GRPC_ERROR_NONE, "rr_connecting"); } else if (subchannel_list->num_shutdown == subchannel_list->num_subchannels) { /* 3) IDLE and re-resolve */ - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_IDLE, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "rr_exhausted_subchannels+reresolve"); p->started_picking = false; - grpc_lb_policy_try_reresolve(exec_ctx, &p->base, &grpc_lb_round_robin_trace, + grpc_lb_policy_try_reresolve(&p->base, &grpc_lb_round_robin_trace, GRPC_ERROR_NONE); } else if (subchannel_list->num_transient_failures == subchannel_list->num_subchannels) { /* 4) TRANSIENT_FAILURE */ - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "rr_transient_failure"); } else if (subchannel_list->num_idle == subchannel_list->num_subchannels) { /* 5) IDLE */ - grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_IDLE, + grpc_connectivity_state_set(&p->state_tracker, GRPC_CHANNEL_IDLE, GRPC_ERROR_NONE, "rr_idle"); } GRPC_ERROR_UNREF(error); } -static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void rr_connectivity_changed_locked(void* arg, grpc_error* error) { grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; round_robin_lb_policy* p = (round_robin_lb_policy*)sd->subchannel_list->policy; @@ -431,18 +425,18 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } // If the policy is shutting down, unref and return. if (p->shutdown) { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "rr_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "rr_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "rr_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, + "rr_shutdown"); return; } // If the subchannel list is shutting down, stop watching. if (sd->subchannel_list->shutting_down || error == GRPC_ERROR_CANCELLED) { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "rr_sl_shutdown"); - grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "rr_sl_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "rr_sl_shutdown"); + grpc_lb_subchannel_list_unref_for_connectivity_watch(sd->subchannel_list, + "rr_sl_shutdown"); return; } // If we're still here, the notification must be for a subchannel in @@ -455,14 +449,13 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, sd->curr_connectivity_state = sd->pending_connectivity_state_unsafe; // Update state counters and new overall state. update_state_counters_locked(sd); - update_lb_connectivity_status_locked(exec_ctx, sd, GRPC_ERROR_REF(error)); + update_lb_connectivity_status_locked(sd, GRPC_ERROR_REF(error)); // If the sd's new state is SHUTDOWN, unref the subchannel. if (sd->curr_connectivity_state == GRPC_CHANNEL_SHUTDOWN) { - grpc_lb_subchannel_data_stop_connectivity_watch(exec_ctx, sd); - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, - "rr_connectivity_shutdown"); + grpc_lb_subchannel_data_stop_connectivity_watch(sd); + grpc_lb_subchannel_data_unref_subchannel(sd, "rr_connectivity_shutdown"); grpc_lb_subchannel_list_unref_for_connectivity_watch( - exec_ctx, sd->subchannel_list, "rr_connectivity_shutdown"); + sd->subchannel_list, "rr_connectivity_shutdown"); } else { // sd not in SHUTDOWN if (sd->curr_connectivity_state == GRPC_CHANNEL_READY) { if (sd->connected_subchannel == nullptr) { @@ -490,8 +483,8 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } if (p->subchannel_list != nullptr) { // dispose of the current subchannel_list - grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->subchannel_list, "sl_phase_out_shutdown"); + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, + "sl_phase_out_shutdown"); } p->subchannel_list = p->latest_pending_subchannel_list; p->latest_pending_subchannel_list = nullptr; @@ -523,32 +516,30 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, (void*)p, (void*)selected->subchannel, (void*)p->subchannel_list, (unsigned long)next_ready_index); } - GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); } } // Renew notification. - grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); + grpc_lb_subchannel_data_start_connectivity_watch(sd); } } static grpc_connectivity_state rr_check_connectivity_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { + grpc_lb_policy* pol, grpc_error** error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void rr_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, - grpc_lb_policy* pol, +static void rr_notify_on_state_change_locked(grpc_lb_policy* pol, grpc_connectivity_state* current, grpc_closure* notify) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; - grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, - current, notify); + grpc_connectivity_state_notify_on_state_change(&p->state_tracker, current, + notify); } -static void rr_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, - grpc_closure* closure) { +static void rr_ping_one_locked(grpc_lb_policy* pol, grpc_closure* closure) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { @@ -556,16 +547,15 @@ static void rr_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, &p->subchannel_list->subchannels[next_ready_index]; grpc_connected_subchannel* target = GRPC_CONNECTED_SUBCHANNEL_REF( selected->connected_subchannel, "rr_ping"); - grpc_connected_subchannel_ping(exec_ctx, target, closure); - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, target, "rr_ping"); + grpc_connected_subchannel_ping(target, closure); + GRPC_CONNECTED_SUBCHANNEL_UNREF(target, "rr_ping"); } else { - GRPC_CLOSURE_SCHED( - exec_ctx, closure, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Round Robin not connected")); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Round Robin not connected")); } } -static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, +static void rr_update_locked(grpc_lb_policy* policy, const grpc_lb_policy_args* args) { round_robin_lb_policy* p = (round_robin_lb_policy*)policy; const grpc_arg* arg = @@ -576,7 +566,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // Otherwise, keep using the current subchannel list (ignore this update). if (p->subchannel_list == nullptr) { grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), "rr_update_missing"); } @@ -588,15 +578,15 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, addresses->num_addresses); } grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( - exec_ctx, &p->base, &grpc_lb_round_robin_trace, addresses, args, + &p->base, &grpc_lb_round_robin_trace, addresses, args, rr_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { grpc_connectivity_state_set( - exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "rr_update_empty"); if (p->subchannel_list != nullptr) { - grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, + grpc_lb_subchannel_list_shutdown_and_unref(p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // empty list @@ -612,7 +602,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->latest_pending_subchannel_list, "sl_outdated"); + p->latest_pending_subchannel_list, "sl_outdated"); } p->latest_pending_subchannel_list = subchannel_list; for (size_t i = 0; i < subchannel_list->num_subchannels; ++i) { @@ -623,22 +613,21 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch(subchannel_list, "connectivity_watch"); grpc_lb_subchannel_data_start_connectivity_watch( - exec_ctx, &subchannel_list->subchannels[i]); + &subchannel_list->subchannels[i]); } } else { // The policy isn't picking yet. Save the update for later, disposing of // previous version if any. if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( - exec_ctx, p->subchannel_list, "rr_update_before_started_picking"); + p->subchannel_list, "rr_update_before_started_picking"); } p->subchannel_list = subchannel_list; } } static void rr_set_reresolve_closure_locked( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, - grpc_closure* request_reresolution) { + grpc_lb_policy* policy, grpc_closure* request_reresolution) { round_robin_lb_policy* p = (round_robin_lb_policy*)policy; GPR_ASSERT(!p->shutdown); GPR_ASSERT(policy->request_reresolution == nullptr); @@ -662,8 +651,7 @@ static void round_robin_factory_ref(grpc_lb_policy_factory* factory) {} static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, - grpc_lb_policy_factory* factory, +static grpc_lb_policy* round_robin_create(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); @@ -671,7 +659,7 @@ static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, grpc_subchannel_index_ref(); grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, "round_robin"); - rr_update_locked(exec_ctx, &p->base, args); + rr_update_locked(&p->base, args); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void*)p, (unsigned long)p->subchannel_list->num_subchannels); diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index b6fce4d207..a3b4c8e524 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -28,8 +28,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_data* sd, +void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, const char* reason) { if (sd->subchannel != nullptr) { if (sd->subchannel_list->tracer->enabled()) { @@ -41,23 +40,22 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); } - GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, reason); + GRPC_SUBCHANNEL_UNREF(sd->subchannel, reason); sd->subchannel = nullptr; if (sd->connected_subchannel != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, sd->connected_subchannel, - reason); + GRPC_CONNECTED_SUBCHANNEL_UNREF(sd->connected_subchannel, reason); sd->connected_subchannel = nullptr; } if (sd->user_data != nullptr) { GPR_ASSERT(sd->user_data_vtable != nullptr); - sd->user_data_vtable->destroy(exec_ctx, sd->user_data); + sd->user_data_vtable->destroy(sd->user_data); sd->user_data = nullptr; } } } void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { + grpc_lb_subchannel_data* sd) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -69,13 +67,13 @@ void grpc_lb_subchannel_data_start_connectivity_watch( } sd->connectivity_notification_pending = true; grpc_subchannel_notify_on_state_change( - exec_ctx, sd->subchannel, sd->subchannel_list->policy->interested_parties, + sd->subchannel, sd->subchannel_list->policy->interested_parties, &sd->pending_connectivity_state_unsafe, &sd->connectivity_changed_closure); } void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { + grpc_lb_subchannel_data* sd) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -90,7 +88,7 @@ void grpc_lb_subchannel_data_stop_connectivity_watch( } grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, + grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { grpc_lb_subchannel_list* subchannel_list = @@ -124,8 +122,8 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( gpr_free(addr_arg.value.string); sc_args.args = new_args; grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel( - exec_ctx, args->client_channel_factory, &sc_args); - grpc_channel_args_destroy(exec_ctx, new_args); + args->client_channel_factory, &sc_args); + grpc_channel_args_destroy(new_args); if (subchannel == nullptr) { // Subchannel could not be created. if (tracer->enabled()) { @@ -172,8 +170,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( return subchannel_list; } -static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_list* subchannel_list) { +static void subchannel_list_destroy(grpc_lb_subchannel_list* subchannel_list) { if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", subchannel_list->tracer->name(), subchannel_list->policy, @@ -181,8 +178,7 @@ static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, } for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, - "subchannel_list_destroy"); + grpc_lb_subchannel_data_unref_subchannel(sd, "subchannel_list_destroy"); } gpr_free(subchannel_list->subchannels); gpr_free(subchannel_list); @@ -200,8 +196,7 @@ void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, } } -void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_list* subchannel_list, +void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, const char* reason) { const bool done = gpr_unref(&subchannel_list->refcount); if (subchannel_list->tracer->enabled()) { @@ -212,7 +207,7 @@ void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, reason); } if (done) { - subchannel_list_destroy(exec_ctx, subchannel_list); + subchannel_list_destroy(subchannel_list); } } @@ -223,14 +218,13 @@ void grpc_lb_subchannel_list_ref_for_connectivity_watch( } void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, - const char* reason) { - GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, subchannel_list->policy, reason); - grpc_lb_subchannel_list_unref(exec_ctx, subchannel_list, reason); + grpc_lb_subchannel_list* subchannel_list, const char* reason) { + GRPC_LB_POLICY_WEAK_UNREF(subchannel_list->policy, reason); + grpc_lb_subchannel_list_unref(subchannel_list, reason); } static void subchannel_data_cancel_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { + grpc_lb_subchannel_data* sd, const char* reason) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -240,14 +234,12 @@ static void subchannel_data_cancel_connectivity_watch( (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } - grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, - nullptr, + grpc_subchannel_notify_on_state_change(sd->subchannel, nullptr, nullptr, &sd->connectivity_changed_closure); } void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, - const char* reason) { + grpc_lb_subchannel_list* subchannel_list, const char* reason) { if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)", subchannel_list->tracer->name(), subchannel_list->policy, @@ -261,10 +253,10 @@ void grpc_lb_subchannel_list_shutdown_and_unref( // the callback is responsible for unreffing the subchannel. // Otherwise, unref the subchannel directly. if (sd->connectivity_notification_pending) { - subchannel_data_cancel_connectivity_watch(exec_ctx, sd, reason); + subchannel_data_cancel_connectivity_watch(sd, reason); } else if (sd->subchannel != nullptr) { - grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, reason); + grpc_lb_subchannel_data_unref_subchannel(sd, reason); } } - grpc_lb_subchannel_list_unref(exec_ctx, subchannel_list, reason); + grpc_lb_subchannel_list_unref(subchannel_list, reason); } diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index e3e5eba56a..0f8cea9347 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -65,8 +65,7 @@ typedef struct { } grpc_lb_subchannel_data; /// Unrefs the subchannel contained in sd. -void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_data* sd, +void grpc_lb_subchannel_data_unref_subchannel(grpc_lb_subchannel_data* sd, const char* reason); /// Starts watching the connectivity state of the subchannel. @@ -74,11 +73,11 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, /// grpc_lb_subchannel_data_stop_connectivity_watch() or again call /// grpc_lb_subchannel_data_start_connectivity_watch(). void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); + grpc_lb_subchannel_data* sd); /// Stops watching the connectivity state of the subchannel. void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); + grpc_lb_subchannel_data* sd); struct grpc_lb_subchannel_list { /** backpointer to owning policy */ @@ -117,15 +116,14 @@ struct grpc_lb_subchannel_list { }; grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, + grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb); void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, const char* reason); -void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, - grpc_lb_subchannel_list* subchannel_list, +void grpc_lb_subchannel_list_unref(grpc_lb_subchannel_list* subchannel_list, const char* reason); /// Takes and releases refs needed for a connectivity notification. @@ -133,13 +131,11 @@ void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, void grpc_lb_subchannel_list_ref_for_connectivity_watch( grpc_lb_subchannel_list* subchannel_list, const char* reason); void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, - const char* reason); + grpc_lb_subchannel_list* subchannel_list, const char* reason); /// Mark subchannel_list as discarded. Unsubscribes all its subchannels. The /// connectivity state notification callback will ultimately unref it. void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, - const char* reason); + grpc_lb_subchannel_list* subchannel_list, const char* reason); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_SUBCHANNEL_LIST_H */ diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.cc b/src/core/ext/filters/client_channel/lb_policy_factory.cc index d43f9fd1b9..dbf69fdcba 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.cc +++ b/src/core/ext/filters/client_channel/lb_policy_factory.cc @@ -112,13 +112,11 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, return 0; } -void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, - grpc_lb_addresses* addresses) { +void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { for (size_t i = 0; i < addresses->num_addresses; ++i) { gpr_free(addresses->addresses[i].balancer_name); if (addresses->addresses[i].user_data != nullptr) { - addresses->user_data_vtable->destroy(exec_ctx, - addresses->addresses[i].user_data); + addresses->user_data_vtable->destroy(addresses->addresses[i].user_data); } } gpr_free(addresses->addresses); @@ -128,8 +126,8 @@ void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, static void* lb_addresses_copy(void* addresses) { return grpc_lb_addresses_copy((grpc_lb_addresses*)addresses); } -static void lb_addresses_destroy(grpc_exec_ctx* exec_ctx, void* addresses) { - grpc_lb_addresses_destroy(exec_ctx, (grpc_lb_addresses*)addresses); +static void lb_addresses_destroy(void* addresses) { + grpc_lb_addresses_destroy((grpc_lb_addresses*)addresses); } static int lb_addresses_cmp(void* addresses1, void* addresses2) { return grpc_lb_addresses_cmp((grpc_lb_addresses*)addresses1, @@ -162,8 +160,7 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory) { } grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( - grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, - grpc_lb_policy_args* args) { + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { if (factory == nullptr) return nullptr; - return factory->vtable->create_lb_policy(exec_ctx, factory, args); + return factory->vtable->create_lb_policy(factory, args); } diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.h b/src/core/ext/filters/client_channel/lb_policy_factory.h index 8f6d8c1b08..9da231b657 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.h +++ b/src/core/ext/filters/client_channel/lb_policy_factory.h @@ -50,7 +50,7 @@ typedef struct grpc_lb_address { typedef struct grpc_lb_user_data_vtable { void* (*copy)(void*); - void (*destroy)(grpc_exec_ctx* exec_ctx, void*); + void (*destroy)(void*); int (*cmp)(void*, void*); } grpc_lb_user_data_vtable; @@ -91,8 +91,7 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, const grpc_lb_addresses* addresses2); /** Destroys \a addresses. */ -void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, - grpc_lb_addresses* addresses); +void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses); /** Returns a channel arg containing \a addresses. */ grpc_arg grpc_lb_addresses_create_channel_arg( @@ -114,8 +113,7 @@ struct grpc_lb_policy_factory_vtable { void (*unref)(grpc_lb_policy_factory* factory); /** Implementation of grpc_lb_policy_factory_create_lb_policy */ - grpc_lb_policy* (*create_lb_policy)(grpc_exec_ctx* exec_ctx, - grpc_lb_policy_factory* factory, + grpc_lb_policy* (*create_lb_policy)(grpc_lb_policy_factory* factory, grpc_lb_policy_args* args); /** Name for the LB policy this factory implements */ @@ -127,7 +125,6 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory); /** Create a lb_policy instance. */ grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( - grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, - grpc_lb_policy_args* args); + grpc_lb_policy_factory* factory, grpc_lb_policy_args* args); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_FACTORY_H */ diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.cc b/src/core/ext/filters/client_channel/lb_policy_registry.cc index 6e710e86d9..edd0330c6a 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.cc +++ b/src/core/ext/filters/client_channel/lb_policy_registry.cc @@ -61,10 +61,10 @@ static grpc_lb_policy_factory* lookup_factory(const char* name) { return nullptr; } -grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, +grpc_lb_policy* grpc_lb_policy_create(const char* name, grpc_lb_policy_args* args) { grpc_lb_policy_factory* factory = lookup_factory(name); grpc_lb_policy* lb_policy = - grpc_lb_policy_factory_create_lb_policy(exec_ctx, factory, args); + grpc_lb_policy_factory_create_lb_policy(factory, args); return lb_policy; } diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.h b/src/core/ext/filters/client_channel/lb_policy_registry.h index acddc90fdd..5aff79376b 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.h +++ b/src/core/ext/filters/client_channel/lb_policy_registry.h @@ -34,7 +34,7 @@ void grpc_register_lb_policy(grpc_lb_policy_factory* factory); * * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init * will be returned. */ -grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, +grpc_lb_policy* grpc_lb_policy_create(const char* name, grpc_lb_policy_args* args); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_REGISTRY_H */ diff --git a/src/core/ext/filters/client_channel/proxy_mapper.cc b/src/core/ext/filters/client_channel/proxy_mapper.cc index c6ea5fc680..be85cfcced 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper.cc +++ b/src/core/ext/filters/client_channel/proxy_mapper.cc @@ -23,24 +23,22 @@ void grpc_proxy_mapper_init(const grpc_proxy_mapper_vtable* vtable, mapper->vtable = vtable; } -bool grpc_proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_name(grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { - return mapper->vtable->map_name(exec_ctx, mapper, server_uri, args, - name_to_resolve, new_args); + return mapper->vtable->map_name(mapper, server_uri, args, name_to_resolve, + new_args); } -bool grpc_proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_address(grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args) { - return mapper->vtable->map_address(exec_ctx, mapper, address, args, - new_address, new_args); + return mapper->vtable->map_address(mapper, address, args, new_address, + new_args); } void grpc_proxy_mapper_destroy(grpc_proxy_mapper* mapper) { diff --git a/src/core/ext/filters/client_channel/proxy_mapper.h b/src/core/ext/filters/client_channel/proxy_mapper.h index a13861ccaf..ce3e65ee46 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper.h +++ b/src/core/ext/filters/client_channel/proxy_mapper.h @@ -32,14 +32,14 @@ typedef struct { /// If no proxy is needed, returns false. /// Otherwise, sets \a name_to_resolve, optionally sets \a new_args, /// and returns true. - bool (*map_name)(grpc_exec_ctx* exec_ctx, grpc_proxy_mapper* mapper, - const char* server_uri, const grpc_channel_args* args, - char** name_to_resolve, grpc_channel_args** new_args); + bool (*map_name)(grpc_proxy_mapper* mapper, const char* server_uri, + const grpc_channel_args* args, char** name_to_resolve, + grpc_channel_args** new_args); /// Determines the proxy address to use to contact \a address. /// If no proxy is needed, returns false. /// Otherwise, sets \a new_address, optionally sets \a new_args, and /// returns true. - bool (*map_address)(grpc_exec_ctx* exec_ctx, grpc_proxy_mapper* mapper, + bool (*map_address)(grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, @@ -55,15 +55,13 @@ struct grpc_proxy_mapper { void grpc_proxy_mapper_init(const grpc_proxy_mapper_vtable* vtable, grpc_proxy_mapper* mapper); -bool grpc_proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_name(grpc_proxy_mapper* mapper, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args); -bool grpc_proxy_mapper_map_address(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper* mapper, +bool grpc_proxy_mapper_map_address(grpc_proxy_mapper* mapper, const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, diff --git a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc index 09967eea3c..51778a20cc 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +++ b/src/core/ext/filters/client_channel/proxy_mapper_registry.cc @@ -46,14 +46,13 @@ static void grpc_proxy_mapper_list_register(grpc_proxy_mapper_list* list, ++list->num_mappers; } -static bool grpc_proxy_mapper_list_map_name(grpc_exec_ctx* exec_ctx, - grpc_proxy_mapper_list* list, +static bool grpc_proxy_mapper_list_map_name(grpc_proxy_mapper_list* list, const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { for (size_t i = 0; i < list->num_mappers; ++i) { - if (grpc_proxy_mapper_map_name(exec_ctx, list->list[i], server_uri, args, + if (grpc_proxy_mapper_map_name(list->list[i], server_uri, args, name_to_resolve, new_args)) { return true; } @@ -62,12 +61,12 @@ static bool grpc_proxy_mapper_list_map_name(grpc_exec_ctx* exec_ctx, } static bool grpc_proxy_mapper_list_map_address( - grpc_exec_ctx* exec_ctx, grpc_proxy_mapper_list* list, - const grpc_resolved_address* address, const grpc_channel_args* args, - grpc_resolved_address** new_address, grpc_channel_args** new_args) { + grpc_proxy_mapper_list* list, const grpc_resolved_address* address, + const grpc_channel_args* args, grpc_resolved_address** new_address, + grpc_channel_args** new_args) { for (size_t i = 0; i < list->num_mappers; ++i) { - if (grpc_proxy_mapper_map_address(exec_ctx, list->list[i], address, args, - new_address, new_args)) { + if (grpc_proxy_mapper_map_address(list->list[i], address, args, new_address, + new_args)) { return true; } } @@ -105,20 +104,17 @@ void grpc_proxy_mapper_register(bool at_start, grpc_proxy_mapper* mapper) { grpc_proxy_mapper_list_register(&g_proxy_mapper_list, at_start, mapper); } -bool grpc_proxy_mappers_map_name(grpc_exec_ctx* exec_ctx, - const char* server_uri, +bool grpc_proxy_mappers_map_name(const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { - return grpc_proxy_mapper_list_map_name(exec_ctx, &g_proxy_mapper_list, - server_uri, args, name_to_resolve, - new_args); + return grpc_proxy_mapper_list_map_name(&g_proxy_mapper_list, server_uri, args, + name_to_resolve, new_args); } -bool grpc_proxy_mappers_map_address(grpc_exec_ctx* exec_ctx, - const grpc_resolved_address* address, +bool grpc_proxy_mappers_map_address(const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args) { - return grpc_proxy_mapper_list_map_address( - exec_ctx, &g_proxy_mapper_list, address, args, new_address, new_args); + return grpc_proxy_mapper_list_map_address(&g_proxy_mapper_list, address, args, + new_address, new_args); } diff --git a/src/core/ext/filters/client_channel/proxy_mapper_registry.h b/src/core/ext/filters/client_channel/proxy_mapper_registry.h index 99e54d1a78..2ad6c04e1d 100644 --- a/src/core/ext/filters/client_channel/proxy_mapper_registry.h +++ b/src/core/ext/filters/client_channel/proxy_mapper_registry.h @@ -29,14 +29,12 @@ void grpc_proxy_mapper_registry_shutdown(); /// the list. Otherwise, it will be added to the end. void grpc_proxy_mapper_register(bool at_start, grpc_proxy_mapper* mapper); -bool grpc_proxy_mappers_map_name(grpc_exec_ctx* exec_ctx, - const char* server_uri, +bool grpc_proxy_mappers_map_name(const char* server_uri, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args); -bool grpc_proxy_mappers_map_address(grpc_exec_ctx* exec_ctx, - const grpc_resolved_address* address, +bool grpc_proxy_mappers_map_address(const grpc_resolved_address* address, const grpc_channel_args* args, grpc_resolved_address** new_address, grpc_channel_args** new_args); diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index c16b1515c7..ff54e7179d 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -46,8 +46,8 @@ void grpc_resolver_ref(grpc_resolver* resolver) { } #ifndef NDEBUG -void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, - const char* file, int line, const char* reason) { +void grpc_resolver_unref(grpc_resolver* resolver, const char* file, int line, + const char* reason) { if (grpc_trace_resolver_refcount.enabled()) { gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -55,27 +55,25 @@ void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, old_refs, old_refs - 1, reason); } #else -void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { +void grpc_resolver_unref(grpc_resolver* resolver) { #endif if (gpr_unref(&resolver->refs)) { grpc_combiner* combiner = resolver->combiner; - resolver->vtable->destroy(exec_ctx, resolver); - GRPC_COMBINER_UNREF(exec_ctx, combiner, "resolver"); + resolver->vtable->destroy(resolver); + GRPC_COMBINER_UNREF(combiner, "resolver"); } } -void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { - resolver->vtable->shutdown_locked(exec_ctx, resolver); +void grpc_resolver_shutdown_locked(grpc_resolver* resolver) { + resolver->vtable->shutdown_locked(resolver); } -void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { - resolver->vtable->channel_saw_error_locked(exec_ctx, resolver); +void grpc_resolver_channel_saw_error_locked(grpc_resolver* resolver) { + resolver->vtable->channel_saw_error_locked(resolver); } -void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, +void grpc_resolver_next_locked(grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { - resolver->vtable->next_locked(exec_ctx, resolver, result, on_complete); + resolver->vtable->next_locked(resolver, result, on_complete); } diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 4e8cfbe417..f6a4af01d6 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -35,43 +35,40 @@ struct grpc_resolver { }; struct grpc_resolver_vtable { - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); - void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); - void (*channel_saw_error_locked)(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver); - void (*next_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, - grpc_channel_args** result, grpc_closure* on_complete); + void (*destroy)(grpc_resolver* resolver); + void (*shutdown_locked)(grpc_resolver* resolver); + void (*channel_saw_error_locked)(grpc_resolver* resolver); + void (*next_locked)(grpc_resolver* resolver, grpc_channel_args** result, + grpc_closure* on_complete); }; #ifndef NDEBUG #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_RESOLVER_UNREF(e, p, r) \ - grpc_resolver_unref((e), (p), __FILE__, __LINE__, (r)) +#define GRPC_RESOLVER_UNREF(p, r) \ + grpc_resolver_unref((p), __FILE__, __LINE__, (r)) void grpc_resolver_ref(grpc_resolver* policy, const char* file, int line, const char* reason); -void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy, - const char* file, int line, const char* reason); +void grpc_resolver_unref(grpc_resolver* policy, const char* file, int line, + const char* reason); #else #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) -#define GRPC_RESOLVER_UNREF(e, p, r) grpc_resolver_unref((e), (p)) +#define GRPC_RESOLVER_UNREF(p, r) grpc_resolver_unref((p)) void grpc_resolver_ref(grpc_resolver* policy); -void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy); +void grpc_resolver_unref(grpc_resolver* policy); #endif void grpc_resolver_init(grpc_resolver* resolver, const grpc_resolver_vtable* vtable, grpc_combiner* combiner); -void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver); +void grpc_resolver_shutdown_locked(grpc_resolver* resolver); /** Notification that the channel has seen an error on some address. Can be used as a hint that re-resolution is desirable soon. Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver); +void grpc_resolver_channel_saw_error_locked(grpc_resolver* resolver); /** Get the next result from the resolver. Expected to set \a *result with new channel args and then schedule \a on_complete for execution. @@ -81,7 +78,7 @@ void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, +void grpc_resolver_next_locked(grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 3a16b3492d..4ec4477c82 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -97,17 +97,14 @@ typedef struct { char* service_config_json; } ares_dns_resolver; -static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_ares_destroy(grpc_resolver* r); -static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, - ares_dns_resolver* r); -static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - ares_dns_resolver* r); +static void dns_ares_start_resolving_locked(ares_dns_resolver* r); +static void dns_ares_maybe_finish_next_locked(ares_dns_resolver* r); -static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* r); -static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, +static void dns_ares_shutdown_locked(grpc_resolver* r); +static void dns_ares_channel_saw_error_locked(grpc_resolver* r); +static void dns_ares_next_locked(grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); @@ -115,43 +112,39 @@ static const grpc_resolver_vtable dns_ares_resolver_vtable = { dns_ares_destroy, dns_ares_shutdown_locked, dns_ares_channel_saw_error_locked, dns_ares_next_locked}; -static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void dns_ares_shutdown_locked(grpc_resolver* resolver) { ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (r->have_retry_timer) { - grpc_timer_cancel(exec_ctx, &r->retry_timer); + grpc_timer_cancel(&r->retry_timer); } if (r->pending_request != nullptr) { - grpc_cancel_ares_request(exec_ctx, r->pending_request); + grpc_cancel_ares_request(r->pending_request); } if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, r->next_completion, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Resolver Shutdown")); r->next_completion = nullptr; } } -static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void dns_ares_channel_saw_error_locked(grpc_resolver* resolver) { ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_ares_start_resolving_locked(exec_ctx, r); + dns_ares_start_resolving_locked(r); } } -static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void dns_ares_on_retry_timer_locked(void* arg, grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { if (!r->resolving) { - dns_ares_start_resolving_locked(exec_ctx, r); + dns_ares_start_resolving_locked(r); } } - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); + GRPC_RESOLVER_UNREF(&r->base, "retry-timer"); } static bool value_in_json_array(grpc_json* array, const char* value) { @@ -226,8 +219,7 @@ static char* choose_service_config(char* service_config_choice_json) { return service_config; } -static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); @@ -268,13 +260,13 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, num_args_to_add); if (service_config != nullptr) grpc_service_config_destroy(service_config); gpr_free(service_config_string); - grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); + grpc_lb_addresses_destroy(r->lb_addresses); } else { const char* msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = - grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); + grpc_backoff_step(&r->backoff_state).next_attempt_start_time; + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); @@ -285,20 +277,19 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, } else { gpr_log(GPR_DEBUG, "retrying immediately"); } - grpc_timer_init(exec_ctx, &r->retry_timer, next_try, + grpc_timer_init(&r->retry_timer, next_try, &r->dns_ares_on_retry_timer_locked); } if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } r->resolved_result = result; r->resolved_version++; - dns_ares_maybe_finish_next_locked(exec_ctx, r); - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); + dns_ares_maybe_finish_next_locked(r); + GRPC_RESOLVER_UNREF(&r->base, "dns-resolving"); } -static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void dns_ares_next_locked(grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { gpr_log(GPR_DEBUG, "dns_ares_next is called."); @@ -308,56 +299,53 @@ static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, r->target_result = target_result; if (r->resolved_version == 0 && !r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_ares_start_resolving_locked(exec_ctx, r); + dns_ares_start_resolving_locked(r); } else { - dns_ares_maybe_finish_next_locked(exec_ctx, r); + dns_ares_maybe_finish_next_locked(r); } } -static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, - ares_dns_resolver* r) { +static void dns_ares_start_resolving_locked(ares_dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; r->lb_addresses = nullptr; r->service_config_json = nullptr; r->pending_request = grpc_dns_lookup_ares( - exec_ctx, r->dns_server, r->name_to_resolve, r->default_port, - r->interested_parties, &r->dns_ares_on_resolved_locked, &r->lb_addresses, + r->dns_server, r->name_to_resolve, r->default_port, r->interested_parties, + &r->dns_ares_on_resolved_locked, &r->lb_addresses, true /* check_grpclb */, r->request_service_config ? &r->service_config_json : nullptr); } -static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - ares_dns_resolver* r) { +static void dns_ares_maybe_finish_next_locked(ares_dns_resolver* r) { if (r->next_completion != nullptr && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == nullptr ? nullptr : grpc_channel_args_copy(r->resolved_result); gpr_log(GPR_DEBUG, "dns_ares_maybe_finish_next_locked"); - GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; r->published_version = r->resolved_version; } } -static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { +static void dns_ares_destroy(grpc_resolver* gr) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); ares_dns_resolver* r = (ares_dns_resolver*)gr; if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } - grpc_pollset_set_destroy(exec_ctx, r->interested_parties); + grpc_pollset_set_destroy(r->interested_parties); gpr_free(r->dns_server); gpr_free(r->name_to_resolve); gpr_free(r->default_port); - grpc_channel_args_destroy(exec_ctx, r->channel_args); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } -static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, - grpc_resolver_args* args, +static grpc_resolver* dns_ares_create(grpc_resolver_args* args, const char* default_port) { /* Get name from args. */ const char* path = args->uri->path; @@ -378,8 +366,7 @@ static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, arg, (grpc_integer_options){false, false, true}); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != nullptr) { - grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, - args->pollset_set); + grpc_pollset_set_add_pollset_set(r->interested_parties, args->pollset_set); } grpc_backoff_init( &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, @@ -404,9 +391,8 @@ static void dns_ares_factory_ref(grpc_resolver_factory* factory) {} static void dns_ares_factory_unref(grpc_resolver_factory* factory) {} static grpc_resolver* dns_factory_create_resolver( - grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, - grpc_resolver_args* args) { - return dns_ares_create(exec_ctx, args, "https"); + grpc_resolver_factory* factory, grpc_resolver_args* args) { + return dns_ares_create(args, "https"); } static char* dns_ares_factory_get_default_host_name( diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h index 03ea36bfcc..ba7dad63cf 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h @@ -28,8 +28,7 @@ typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; /* Start \a ev_driver. It will keep working until all IO on its ares_channel is done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks bound to its ares_channel when necessary. */ -void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver); +void grpc_ares_ev_driver_start(grpc_ares_ev_driver* ev_driver); /* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to \a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the @@ -47,8 +46,7 @@ grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver); /* Shutdown all the grpc_fds used by \a ev_driver */ -void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver); +void grpc_ares_ev_driver_shutdown(grpc_ares_ev_driver* ev_driver); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \ */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index 4cb068a41d..40e264504c 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -77,8 +77,7 @@ struct grpc_ares_ev_driver { bool shutting_down; }; -static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver); +static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver); static grpc_ares_ev_driver* grpc_ares_ev_driver_ref( grpc_ares_ev_driver* ev_driver) { @@ -98,7 +97,7 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { } } -static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { +static void fd_node_destroy(fd_node* fdn) { gpr_log(GPR_DEBUG, "delete fd: %d", grpc_fd_wrapped_fd(fdn->fd)); GPR_ASSERT(!fdn->readable_registered); GPR_ASSERT(!fdn->writable_registered); @@ -106,21 +105,20 @@ static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { /* c-ares library has closed the fd inside grpc_fd. This fd may be picked up immediately by another thread, and should not be closed by the following grpc_fd_orphan. */ - grpc_fd_orphan(exec_ctx, fdn->fd, nullptr, nullptr, true /* already_closed */, + grpc_fd_orphan(fdn->fd, nullptr, nullptr, true /* already_closed */, "c-ares query finished"); gpr_free(fdn); } -static void fd_node_shutdown(grpc_exec_ctx* exec_ctx, fd_node* fdn) { +static void fd_node_shutdown(fd_node* fdn) { gpr_mu_lock(&fdn->mu); fdn->shutting_down = true; if (!fdn->readable_registered && !fdn->writable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(exec_ctx, fdn); + fd_node_destroy(fdn); } else { grpc_fd_shutdown( - exec_ctx, fdn->fd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("c-ares fd shutdown")); + fdn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("c-ares fd shutdown")); gpr_mu_unlock(&fdn->mu); } } @@ -160,15 +158,13 @@ void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver) { grpc_ares_ev_driver_unref(ev_driver); } -void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver) { +void grpc_ares_ev_driver_shutdown(grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); ev_driver->shutting_down = true; fd_node* fn = ev_driver->fds; while (fn != nullptr) { - grpc_fd_shutdown( - exec_ctx, fn->fd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_ares_ev_driver_shutdown")); + grpc_fd_shutdown(fn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "grpc_ares_ev_driver_shutdown")); fn = fn->next; } gpr_mu_unlock(&ev_driver->mu); @@ -199,8 +195,7 @@ static bool grpc_ares_is_fd_still_readable(grpc_ares_ev_driver* ev_driver, return ioctl(fd, FIONREAD, &bytes_available) == 0 && bytes_available > 0; } -static void on_readable_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_readable_cb(void* arg, grpc_error* error) { fd_node* fdn = (fd_node*)arg; grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); @@ -208,7 +203,7 @@ static void on_readable_cb(grpc_exec_ctx* exec_ctx, void* arg, fdn->readable_registered = false; if (fdn->shutting_down && !fdn->writable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(exec_ctx, fdn); + fd_node_destroy(fdn); grpc_ares_ev_driver_unref(ev_driver); return; } @@ -229,13 +224,12 @@ static void on_readable_cb(grpc_exec_ctx* exec_ctx, void* arg, ares_cancel(ev_driver->channel); } gpr_mu_lock(&ev_driver->mu); - grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); + grpc_ares_notify_on_event_locked(ev_driver); gpr_mu_unlock(&ev_driver->mu); grpc_ares_ev_driver_unref(ev_driver); } -static void on_writable_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_writable_cb(void* arg, grpc_error* error) { fd_node* fdn = (fd_node*)arg; grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); @@ -243,7 +237,7 @@ static void on_writable_cb(grpc_exec_ctx* exec_ctx, void* arg, fdn->writable_registered = false; if (fdn->shutting_down && !fdn->readable_registered) { gpr_mu_unlock(&fdn->mu); - fd_node_destroy(exec_ctx, fdn); + fd_node_destroy(fdn); grpc_ares_ev_driver_unref(ev_driver); return; } @@ -262,7 +256,7 @@ static void on_writable_cb(grpc_exec_ctx* exec_ctx, void* arg, ares_cancel(ev_driver->channel); } gpr_mu_lock(&ev_driver->mu); - grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); + grpc_ares_notify_on_event_locked(ev_driver); gpr_mu_unlock(&ev_driver->mu); grpc_ares_ev_driver_unref(ev_driver); } @@ -273,8 +267,7 @@ ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver) { // Get the file descriptors used by the ev_driver's ares channel, register // driver_closure with these filedescriptors. -static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver) { +static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { fd_node* new_list = nullptr; if (!ev_driver->shutting_down) { ares_socket_t socks[ARES_GETSOCK_MAXNUM]; @@ -300,7 +293,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&fdn->write_closure, on_writable_cb, fdn, grpc_schedule_on_exec_ctx); - grpc_pollset_set_add_fd(exec_ctx, ev_driver->pollset_set, fdn->fd); + grpc_pollset_set_add_fd(ev_driver->pollset_set, fdn->fd); gpr_free(fd_name); } fdn->next = new_list; @@ -312,7 +305,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, !fdn->readable_registered) { grpc_ares_ev_driver_ref(ev_driver); gpr_log(GPR_DEBUG, "notify read on: %d", grpc_fd_wrapped_fd(fdn->fd)); - grpc_fd_notify_on_read(exec_ctx, fdn->fd, &fdn->read_closure); + grpc_fd_notify_on_read(fdn->fd, &fdn->read_closure); fdn->readable_registered = true; } // Register write_closure if the socket is writable and write_closure @@ -322,7 +315,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "notify write on: %d", grpc_fd_wrapped_fd(fdn->fd)); grpc_ares_ev_driver_ref(ev_driver); - grpc_fd_notify_on_write(exec_ctx, fdn->fd, &fdn->write_closure); + grpc_fd_notify_on_write(fdn->fd, &fdn->write_closure); fdn->writable_registered = true; } gpr_mu_unlock(&fdn->mu); @@ -335,7 +328,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, while (ev_driver->fds != nullptr) { fd_node* cur = ev_driver->fds; ev_driver->fds = ev_driver->fds->next; - fd_node_shutdown(exec_ctx, cur); + fd_node_shutdown(cur); } ev_driver->fds = new_list; // If the ev driver has no working fd, all the tasks are done. @@ -345,12 +338,11 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, } } -void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, - grpc_ares_ev_driver* ev_driver) { +void grpc_ares_ev_driver_start(grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); if (!ev_driver->working) { ev_driver->working = true; - grpc_ares_notify_on_event_locked(exec_ctx, ev_driver); + grpc_ares_notify_on_event_locked(ev_driver); } gpr_mu_unlock(&ev_driver->mu); } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 7846576c11..3a870b2d06 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -96,24 +96,12 @@ static void grpc_ares_request_ref(grpc_ares_request* r) { gpr_ref(&r->pending_queries); } -static void grpc_ares_request_unref(grpc_exec_ctx* exec_ctx, - grpc_ares_request* r) { +static void grpc_ares_request_unref(grpc_ares_request* r) { /* If there are no pending queries, invoke on_done callback and destroy the request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - if (exec_ctx == nullptr) { - /* A new exec_ctx is created here, as the c-ares interface does not - provide one in ares_host_callback. It's safe to schedule on_done with - the newly created exec_ctx, since the caller has been warned not to - acquire locks in on_done. ares_dns_resolver is using combiner to - protect resources needed by on_done. */ - grpc_exec_ctx new_exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_SCHED(&new_exec_ctx, r->on_done, r->error); - grpc_exec_ctx_finish(&new_exec_ctx); - } else { - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, r->error); - } + GRPC_CLOSURE_SCHED(r->on_done, r->error); gpr_mu_destroy(&r->mu); grpc_ares_ev_driver_destroy(r->ev_driver); gpr_free(r); @@ -133,9 +121,8 @@ static grpc_ares_hostbyname_request* create_hostbyname_request( return hr; } -static void destroy_hostbyname_request(grpc_exec_ctx* exec_ctx, - grpc_ares_hostbyname_request* hr) { - grpc_ares_request_unref(exec_ctx, hr->parent_request); +static void destroy_hostbyname_request(grpc_ares_hostbyname_request* hr) { + grpc_ares_request_unref(hr->parent_request); gpr_free(hr->host); gpr_free(hr); } @@ -220,13 +207,13 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, } } gpr_mu_unlock(&r->mu); - destroy_hostbyname_request(nullptr, hr); + destroy_hostbyname_request(hr); } static void on_srv_query_done_cb(void* arg, int status, int timeouts, unsigned char* abuf, int alen) { grpc_ares_request* r = (grpc_ares_request*)arg; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { gpr_log(GPR_DEBUG, "on_query_srv_done_cb ARES_SUCCESS"); @@ -246,7 +233,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, r, srv_it->host, htons(srv_it->port), true /* is_balancer */); ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_cb, hr); - grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); + grpc_ares_ev_driver_start(r->ev_driver); } } if (reply != nullptr) { @@ -264,8 +251,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, r->error = grpc_error_add_child(error, r->error); } } - grpc_ares_request_unref(&exec_ctx, r); - grpc_exec_ctx_finish(&exec_ctx); + grpc_ares_request_unref(r); } static const char g_service_config_attribute_prefix[] = "grpc_config="; @@ -323,14 +309,13 @@ fail: } done: gpr_mu_unlock(&r->mu); - grpc_ares_request_unref(nullptr, r); + grpc_ares_request_unref(r); } static grpc_ares_request* grpc_dns_lookup_ares_impl( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, - char** service_config_json) { + const char* dns_server, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) { grpc_error* error = GRPC_ERROR_NONE; grpc_ares_hostbyname_request* hr = nullptr; grpc_ares_request* r = nullptr; @@ -437,28 +422,28 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( gpr_free(config_name); } /* TODO(zyc): Handle CNAME records here. */ - grpc_ares_ev_driver_start(exec_ctx, r->ev_driver); - grpc_ares_request_unref(exec_ctx, r); + grpc_ares_ev_driver_start(r->ev_driver); + grpc_ares_request_unref(r); gpr_free(host); gpr_free(port); return r; error_cleanup: - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); gpr_free(host); gpr_free(port); return nullptr; } grpc_ares_request* (*grpc_dns_lookup_ares)( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + const char* dns_server, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) { +void grpc_cancel_ares_request(grpc_ares_request* r) { if (grpc_dns_lookup_ares == grpc_dns_lookup_ares_impl) { - grpc_ares_ev_driver_shutdown(exec_ctx, r->ev_driver); + grpc_ares_ev_driver_shutdown(r->ev_driver); } } @@ -501,8 +486,7 @@ typedef struct grpc_resolve_address_ares_request { grpc_closure on_dns_lookup_done; } grpc_resolve_address_ares_request; -static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_dns_lookup_done_cb(void* arg, grpc_error* error) { grpc_resolve_address_ares_request* r = (grpc_resolve_address_ares_request*)arg; grpc_resolved_addresses** resolved_addresses = r->addrs_out; @@ -520,14 +504,12 @@ static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, &r->lb_addrs->addresses[i].address, sizeof(grpc_resolved_address)); } } - GRPC_CLOSURE_SCHED(exec_ctx, r->on_resolve_address_done, - GRPC_ERROR_REF(error)); - grpc_lb_addresses_destroy(exec_ctx, r->lb_addrs); + GRPC_CLOSURE_SCHED(r->on_resolve_address_done, GRPC_ERROR_REF(error)); + grpc_lb_addresses_destroy(r->lb_addrs); gpr_free(r); } -static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, - const char* name, +static void grpc_resolve_address_ares_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -539,14 +521,14 @@ static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, grpc_schedule_on_exec_ctx); - grpc_dns_lookup_ares(exec_ctx, nullptr /* dns_server */, name, default_port, + grpc_dns_lookup_ares(nullptr /* dns_server */, name, default_port, interested_parties, &r->on_dns_lookup_done, &r->lb_addrs, false /* check_grpclb */, nullptr /* service_config_json */); } void (*grpc_resolve_address_ares)( - grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h index 72db622954..86d870e0a6 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h @@ -32,8 +32,7 @@ typedef struct grpc_ares_request grpc_ares_request; must be called at least once before this function. \a on_done may be called directly in this function without being scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ -extern void (*grpc_resolve_address_ares)(grpc_exec_ctx* exec_ctx, - const char* name, +extern void (*grpc_resolve_address_ares)(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -47,14 +46,13 @@ extern void (*grpc_resolve_address_ares)(grpc_exec_ctx* exec_ctx, scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ extern grpc_ares_request* (*grpc_dns_lookup_ares)( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, + const char* dns_server, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addresses, bool check_grpclb, char** service_config_json); /* Cancel the pending grpc_ares_request \a request */ -void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, - grpc_ares_request* request); +void grpc_cancel_ares_request(grpc_ares_request* request); /* Initialize gRPC ares wrapper. Must be called at least once before grpc_resolve_address_ares(). */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc index a68a7c47fb..a184cf2d57 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc @@ -26,34 +26,32 @@ struct grpc_ares_request { }; static grpc_ares_request* grpc_dns_lookup_ares_impl( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, - char** service_config_json) { + const char* dns_server, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) { return NULL; } grpc_ares_request* (*grpc_dns_lookup_ares)( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + const char* dns_server, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) {} +void grpc_cancel_ares_request(grpc_ares_request* r) {} grpc_error* grpc_ares_init(void) { return GRPC_ERROR_NONE; } void grpc_ares_cleanup(void) {} -static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, - const char* name, +static void grpc_resolve_address_ares_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) {} void (*grpc_resolve_address_ares)( - grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index fc40ce6966..77698e97aa 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -76,49 +76,42 @@ typedef struct { grpc_resolved_addresses* addresses; } dns_resolver; -static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_destroy(grpc_resolver* r); -static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, - dns_resolver* r); -static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - dns_resolver* r); +static void dns_start_resolving_locked(dns_resolver* r); +static void dns_maybe_finish_next_locked(dns_resolver* r); -static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* r); -static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, - grpc_channel_args** target_result, +static void dns_shutdown_locked(grpc_resolver* r); +static void dns_channel_saw_error_locked(grpc_resolver* r); +static void dns_next_locked(grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); static const grpc_resolver_vtable dns_resolver_vtable = { dns_destroy, dns_shutdown_locked, dns_channel_saw_error_locked, dns_next_locked}; -static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void dns_shutdown_locked(grpc_resolver* resolver) { dns_resolver* r = (dns_resolver*)resolver; if (r->have_retry_timer) { - grpc_timer_cancel(exec_ctx, &r->retry_timer); + grpc_timer_cancel(&r->retry_timer); } if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, r->next_completion, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Resolver Shutdown")); r->next_completion = nullptr; } } -static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void dns_channel_saw_error_locked(grpc_resolver* resolver) { dns_resolver* r = (dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_start_resolving_locked(exec_ctx, r); + dns_start_resolving_locked(r); } } -static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, +static void dns_next_locked(grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { dns_resolver* r = (dns_resolver*)resolver; @@ -127,28 +120,26 @@ static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, r->target_result = target_result; if (r->resolved_version == 0 && !r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_start_resolving_locked(exec_ctx, r); + dns_start_resolving_locked(r); } else { - dns_maybe_finish_next_locked(exec_ctx, r); + dns_maybe_finish_next_locked(r); } } -static void dns_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void dns_on_retry_timer_locked(void* arg, grpc_error* error) { dns_resolver* r = (dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { if (!r->resolving) { - dns_start_resolving_locked(exec_ctx, r); + dns_start_resolving_locked(r); } } - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); + GRPC_RESOLVER_UNREF(&r->base, "retry-timer"); } -static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void dns_on_resolved_locked(void* arg, grpc_error* error) { dns_resolver* r = (dns_resolver*)arg; grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); @@ -168,11 +159,11 @@ static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); grpc_resolved_addresses_destroy(r->addresses); - grpc_lb_addresses_destroy(exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); } else { grpc_millis next_try = - grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; - grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); + grpc_backoff_step(&r->backoff_state).next_attempt_start_time; + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); @@ -185,59 +176,56 @@ static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, } GRPC_CLOSURE_INIT(&r->on_retry, dns_on_retry_timer_locked, r, grpc_combiner_scheduler(r->base.combiner)); - grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->on_retry); + grpc_timer_init(&r->retry_timer, next_try, &r->on_retry); } if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } r->resolved_result = result; r->resolved_version++; - dns_maybe_finish_next_locked(exec_ctx, r); + dns_maybe_finish_next_locked(r); GRPC_ERROR_UNREF(error); - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); + GRPC_RESOLVER_UNREF(&r->base, "dns-resolving"); } -static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, - dns_resolver* r) { +static void dns_start_resolving_locked(dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; r->addresses = nullptr; grpc_resolve_address( - exec_ctx, r->name_to_resolve, r->default_port, r->interested_parties, + r->name_to_resolve, r->default_port, r->interested_parties, GRPC_CLOSURE_CREATE(dns_on_resolved_locked, r, grpc_combiner_scheduler(r->base.combiner)), &r->addresses); } -static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - dns_resolver* r) { +static void dns_maybe_finish_next_locked(dns_resolver* r) { if (r->next_completion != nullptr && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == nullptr ? nullptr : grpc_channel_args_copy(r->resolved_result); - GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; r->published_version = r->resolved_version; } } -static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { +static void dns_destroy(grpc_resolver* gr) { dns_resolver* r = (dns_resolver*)gr; if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } - grpc_pollset_set_destroy(exec_ctx, r->interested_parties); + grpc_pollset_set_destroy(r->interested_parties); gpr_free(r->name_to_resolve); gpr_free(r->default_port); - grpc_channel_args_destroy(exec_ctx, r->channel_args); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } -static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, - grpc_resolver_args* args, +static grpc_resolver* dns_create(grpc_resolver_args* args, const char* default_port) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based dns uri's not supported"); @@ -254,8 +242,7 @@ static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, r->channel_args = grpc_channel_args_copy(args->args); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != nullptr) { - grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, - args->pollset_set); + grpc_pollset_set_add_pollset_set(r->interested_parties, args->pollset_set); } grpc_backoff_init( &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, @@ -274,9 +261,8 @@ static void dns_factory_ref(grpc_resolver_factory* factory) {} static void dns_factory_unref(grpc_resolver_factory* factory) {} static grpc_resolver* dns_factory_create_resolver( - grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, - grpc_resolver_args* args) { - return dns_create(exec_ctx, args, "https"); + grpc_resolver_factory* factory, grpc_resolver_args* args) { + return dns_create(args, "https"); } static char* dns_factory_get_default_host_name(grpc_resolver_factory* factory, diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc index 44798ca434..fe3ad1403c 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -67,57 +67,52 @@ typedef struct { grpc_channel_args** target_result; } fake_resolver; -static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { +static void fake_resolver_destroy(grpc_resolver* gr) { fake_resolver* r = (fake_resolver*)gr; - grpc_channel_args_destroy(exec_ctx, r->next_results); - grpc_channel_args_destroy(exec_ctx, r->results_upon_error); - grpc_channel_args_destroy(exec_ctx, r->channel_args); + grpc_channel_args_destroy(r->next_results); + grpc_channel_args_destroy(r->results_upon_error); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } -static void fake_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void fake_resolver_shutdown_locked(grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, r->next_completion, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Resolver Shutdown")); r->next_completion = nullptr; } } -static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - fake_resolver* r) { +static void fake_resolver_maybe_finish_next_locked(fake_resolver* r) { if (r->next_completion != nullptr && r->next_results != nullptr) { *r->target_result = grpc_channel_args_union(r->next_results, r->channel_args); - grpc_channel_args_destroy(exec_ctx, r->next_results); + grpc_channel_args_destroy(r->next_results); r->next_results = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; } } -static void fake_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void fake_resolver_channel_saw_error_locked(grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; if (r->next_results == nullptr && r->results_upon_error != nullptr) { // Pretend we re-resolved. r->next_results = grpc_channel_args_copy(r->results_upon_error); } - fake_resolver_maybe_finish_next_locked(exec_ctx, r); + fake_resolver_maybe_finish_next_locked(r); } -static void fake_resolver_next_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void fake_resolver_next_locked(grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { fake_resolver* r = (fake_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; - fake_resolver_maybe_finish_next_locked(exec_ctx, r); + fake_resolver_maybe_finish_next_locked(r); } static const grpc_resolver_vtable fake_resolver_vtable = { @@ -157,33 +152,31 @@ typedef struct set_response_closure_arg { grpc_channel_args* next_response; } set_response_closure_arg; -static void set_response_closure_fn(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void set_response_closure_fn(void* arg, grpc_error* error) { set_response_closure_arg* closure_arg = (set_response_closure_arg*)arg; grpc_fake_resolver_response_generator* generator = closure_arg->generator; fake_resolver* r = generator->resolver; if (r->next_results != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->next_results); + grpc_channel_args_destroy(r->next_results); } r->next_results = closure_arg->next_response; if (r->results_upon_error != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->results_upon_error); + grpc_channel_args_destroy(r->results_upon_error); } r->results_upon_error = grpc_channel_args_copy(closure_arg->next_response); gpr_free(closure_arg); - fake_resolver_maybe_finish_next_locked(exec_ctx, r); + fake_resolver_maybe_finish_next_locked(r); } void grpc_fake_resolver_response_generator_set_response( - grpc_exec_ctx* exec_ctx, grpc_fake_resolver_response_generator* generator, + grpc_fake_resolver_response_generator* generator, grpc_channel_args* next_response) { GPR_ASSERT(generator->resolver != nullptr); set_response_closure_arg* closure_arg = (set_response_closure_arg*)gpr_zalloc(sizeof(*closure_arg)); closure_arg->generator = generator; closure_arg->next_response = grpc_channel_args_copy(next_response); - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, set_response_closure_fn, closure_arg, grpc_combiner_scheduler( generator->resolver->base.combiner)), @@ -195,7 +188,7 @@ static void* response_generator_arg_copy(void* p) { (grpc_fake_resolver_response_generator*)p); } -static void response_generator_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { +static void response_generator_arg_destroy(void* p) { grpc_fake_resolver_response_generator_unref( (grpc_fake_resolver_response_generator*)p); } @@ -232,8 +225,7 @@ static void fake_resolver_factory_ref(grpc_resolver_factory* factory) {} static void fake_resolver_factory_unref(grpc_resolver_factory* factory) {} -static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx, - grpc_resolver_factory* factory, +static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, grpc_resolver_args* args) { fake_resolver* r = (fake_resolver*)gpr_zalloc(sizeof(*r)); r->channel_args = grpc_channel_args_copy(args->args); diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h index 7035cdda01..a8977e5980 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h @@ -39,7 +39,7 @@ grpc_fake_resolver_response_generator_create(); // Instruct the fake resolver associated with the \a response_generator instance // to trigger a new resolution for \a uri and \a args. void grpc_fake_resolver_response_generator_set_response( - grpc_exec_ctx* exec_ctx, grpc_fake_resolver_response_generator* generator, + grpc_fake_resolver_response_generator* generator, grpc_channel_args* next_response); // Return a \a grpc_arg for a \a grpc_fake_resolver_response_generator instance. diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc index f0934b5943..7d1e283fa3 100644 --- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc @@ -52,15 +52,13 @@ typedef struct { grpc_channel_args** target_result; } sockaddr_resolver; -static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void sockaddr_destroy(grpc_resolver* r); -static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - sockaddr_resolver* r); +static void sockaddr_maybe_finish_next_locked(sockaddr_resolver* r); -static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* r); -static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, +static void sockaddr_shutdown_locked(grpc_resolver* r); +static void sockaddr_channel_saw_error_locked(grpc_resolver* r); +static void sockaddr_next_locked(grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); @@ -68,52 +66,47 @@ static const grpc_resolver_vtable sockaddr_resolver_vtable = { sockaddr_destroy, sockaddr_shutdown_locked, sockaddr_channel_saw_error_locked, sockaddr_next_locked}; -static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void sockaddr_shutdown_locked(grpc_resolver* resolver) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, r->next_completion, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Resolver Shutdown")); r->next_completion = nullptr; } } -static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void sockaddr_channel_saw_error_locked(grpc_resolver* resolver) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; r->published = false; - sockaddr_maybe_finish_next_locked(exec_ctx, r); + sockaddr_maybe_finish_next_locked(r); } -static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void sockaddr_next_locked(grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; - sockaddr_maybe_finish_next_locked(exec_ctx, r); + sockaddr_maybe_finish_next_locked(r); } -static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, - sockaddr_resolver* r) { +static void sockaddr_maybe_finish_next_locked(sockaddr_resolver* r) { if (r->next_completion != nullptr && !r->published) { r->published = true; grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); *r->target_result = grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); - GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; } } -static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { +static void sockaddr_destroy(grpc_resolver* gr) { sockaddr_resolver* r = (sockaddr_resolver*)gr; - grpc_lb_addresses_destroy(exec_ctx, r->addresses); - grpc_channel_args_destroy(exec_ctx, r->channel_args); + grpc_lb_addresses_destroy(r->addresses); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } @@ -142,8 +135,7 @@ char* unix_get_default_authority(grpc_resolver_factory* factory, static void do_nothing(void* ignored) {} -static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, - grpc_resolver_args* args, +static grpc_resolver* sockaddr_create(grpc_resolver_args* args, bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) { if (0 != strcmp(args->uri->authority, "")) { @@ -170,10 +162,10 @@ static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, gpr_free(part_str); if (errors_found) break; } - grpc_slice_buffer_destroy_internal(exec_ctx, &path_parts); - grpc_slice_unref_internal(exec_ctx, path_slice); + grpc_slice_buffer_destroy_internal(&path_parts); + grpc_slice_unref_internal(path_slice); if (errors_found) { - grpc_lb_addresses_destroy(exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); return nullptr; } /* Instantiate resolver. */ @@ -195,9 +187,8 @@ static void sockaddr_factory_unref(grpc_resolver_factory* factory) {} #define DECL_FACTORY(name) \ static grpc_resolver* name##_factory_create_resolver( \ - grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, \ - grpc_resolver_args* args) { \ - return sockaddr_create(exec_ctx, args, grpc_parse_##name); \ + grpc_resolver_factory* factory, grpc_resolver_args* args) { \ + return sockaddr_create(args, grpc_parse_##name); \ } \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \ sockaddr_factory_ref, sockaddr_factory_unref, \ diff --git a/src/core/ext/filters/client_channel/resolver_factory.cc b/src/core/ext/filters/client_channel/resolver_factory.cc index 1a289d9771..9b3ec2f1c4 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.cc +++ b/src/core/ext/filters/client_channel/resolver_factory.cc @@ -28,10 +28,9 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* factory) { /** Create a resolver instance for a name */ grpc_resolver* grpc_resolver_factory_create_resolver( - grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, - grpc_resolver_args* args) { + grpc_resolver_factory* factory, grpc_resolver_args* args) { if (factory == nullptr) return nullptr; - return factory->vtable->create_resolver(exec_ctx, factory, args); + return factory->vtable->create_resolver(factory, args); } char* grpc_resolver_factory_get_default_authority( diff --git a/src/core/ext/filters/client_channel/resolver_factory.h b/src/core/ext/filters/client_channel/resolver_factory.h index fcf8ec425e..170ecc0b48 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.h +++ b/src/core/ext/filters/client_channel/resolver_factory.h @@ -43,8 +43,7 @@ struct grpc_resolver_factory_vtable { void (*unref)(grpc_resolver_factory* factory); /** Implementation of grpc_resolver_factory_create_resolver */ - grpc_resolver* (*create_resolver)(grpc_exec_ctx* exec_ctx, - grpc_resolver_factory* factory, + grpc_resolver* (*create_resolver)(grpc_resolver_factory* factory, grpc_resolver_args* args); /** Implementation of grpc_resolver_factory_get_default_authority */ @@ -59,8 +58,7 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* resolver); /** Create a resolver instance for a name */ grpc_resolver* grpc_resolver_factory_create_resolver( - grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, - grpc_resolver_args* args); + grpc_resolver_factory* factory, grpc_resolver_args* args); /** Return a (freshly allocated with gpr_malloc) string representing the default authority to use for this scheme. */ diff --git a/src/core/ext/filters/client_channel/resolver_registry.cc b/src/core/ext/filters/client_channel/resolver_registry.cc index 5da6114a3d..3f8451de6b 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.cc +++ b/src/core/ext/filters/client_channel/resolver_registry.cc @@ -92,23 +92,22 @@ static grpc_resolver_factory* lookup_factory_by_uri(grpc_uri* uri) { return lookup_factory(uri->scheme); } -static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx, - const char* target, +static grpc_resolver_factory* resolve_factory(const char* target, grpc_uri** uri, char** canonical_target) { grpc_resolver_factory* factory = nullptr; GPR_ASSERT(uri != nullptr); - *uri = grpc_uri_parse(exec_ctx, target, 1); + *uri = grpc_uri_parse(target, 1); factory = lookup_factory_by_uri(*uri); if (factory == nullptr) { grpc_uri_destroy(*uri); gpr_asprintf(canonical_target, "%s%s", g_default_resolver_prefix, target); - *uri = grpc_uri_parse(exec_ctx, *canonical_target, 1); + *uri = grpc_uri_parse(*canonical_target, 1); factory = lookup_factory_by_uri(*uri); if (factory == nullptr) { - grpc_uri_destroy(grpc_uri_parse(exec_ctx, target, 0)); - grpc_uri_destroy(grpc_uri_parse(exec_ctx, *canonical_target, 0)); + grpc_uri_destroy(grpc_uri_parse(target, 0)); + grpc_uri_destroy(grpc_uri_parse(*canonical_target, 0)); gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, *canonical_target); } @@ -116,14 +115,14 @@ static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx, return factory; } -grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, +grpc_resolver* grpc_resolver_create(const char* target, const grpc_channel_args* args, grpc_pollset_set* pollset_set, grpc_combiner* combiner) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; grpc_resolver_factory* factory = - resolve_factory(exec_ctx, target, &uri, &canonical_target); + resolve_factory(target, &uri, &canonical_target); grpc_resolver* resolver; grpc_resolver_args resolver_args; memset(&resolver_args, 0, sizeof(resolver_args)); @@ -131,29 +130,27 @@ grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, resolver_args.args = args; resolver_args.pollset_set = pollset_set; resolver_args.combiner = combiner; - resolver = - grpc_resolver_factory_create_resolver(exec_ctx, factory, &resolver_args); + resolver = grpc_resolver_factory_create_resolver(factory, &resolver_args); grpc_uri_destroy(uri); gpr_free(canonical_target); return resolver; } -char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) { +char* grpc_get_default_authority(const char* target) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; grpc_resolver_factory* factory = - resolve_factory(exec_ctx, target, &uri, &canonical_target); + resolve_factory(target, &uri, &canonical_target); char* authority = grpc_resolver_factory_get_default_authority(factory, uri); grpc_uri_destroy(uri); gpr_free(canonical_target); return authority; } -char* grpc_resolver_factory_add_default_prefix_if_needed( - grpc_exec_ctx* exec_ctx, const char* target) { +char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target) { grpc_uri* uri = nullptr; char* canonical_target = nullptr; - resolve_factory(exec_ctx, target, &uri, &canonical_target); + resolve_factory(target, &uri, &canonical_target); grpc_uri_destroy(uri); return canonical_target == nullptr ? gpr_strdup(target) : canonical_target; } diff --git a/src/core/ext/filters/client_channel/resolver_registry.h b/src/core/ext/filters/client_channel/resolver_registry.h index ecc9f824e8..bbd30df8da 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.h +++ b/src/core/ext/filters/client_channel/resolver_registry.h @@ -48,7 +48,7 @@ void grpc_register_resolver_type(grpc_resolver_factory* factory); (typically the set of arguments passed in from the client API). \a pollset_set is used to drive IO in the name resolution process, it should not be NULL. */ -grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, +grpc_resolver* grpc_resolver_create(const char* target, const grpc_channel_args* args, grpc_pollset_set* pollset_set, grpc_combiner* combiner); @@ -59,11 +59,10 @@ grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name); /** Given a target, return a (freshly allocated with gpr_malloc) string representing the default authority to pass from a client. */ -char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target); +char* grpc_get_default_authority(const char* target); /** Returns a newly allocated string containing \a target, adding the default prefix if needed. */ -char* grpc_resolver_factory_add_default_prefix_if_needed( - grpc_exec_ctx* exec_ctx, const char* target); +char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target); #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H */ diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 58e294d597..0d2be2a3f7 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -139,8 +139,7 @@ struct grpc_subchannel_call { #define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ (((grpc_subchannel_call*)(callstack)) - 1) -static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel, - grpc_error* error); +static void subchannel_connected(void* subchannel, grpc_error* error); #ifndef NDEBUG #define REF_REASON reason @@ -157,10 +156,9 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel, * connection implementation */ -static void connection_destroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void connection_destroy(void* arg, grpc_error* error) { grpc_connected_subchannel* c = (grpc_connected_subchannel*)arg; - grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); + grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CONNECTION(c)); gpr_free(c); } @@ -170,26 +168,23 @@ grpc_connected_subchannel* grpc_connected_subchannel_ref( return c; } -void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, - grpc_connected_subchannel* c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), - REF_REASON); +void grpc_connected_subchannel_unref( + grpc_connected_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); } /* * grpc_subchannel implementation */ -static void subchannel_destroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void subchannel_destroy(void* arg, grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; gpr_free((void*)c->filters); - grpc_channel_args_destroy(exec_ctx, c->args); - grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); - grpc_connector_unref(exec_ctx, c->connector); - grpc_pollset_set_destroy(exec_ctx, c->pollset_set); - grpc_subchannel_key_destroy(exec_ctx, c->key); + grpc_channel_args_destroy(c->args); + grpc_connectivity_state_destroy(&c->state_tracker); + grpc_connector_unref(c->connector); + grpc_pollset_set_destroy(c->pollset_set); + grpc_subchannel_key_destroy(c->key); gpr_mu_destroy(&c->mu); gpr_free(c); } @@ -241,59 +236,54 @@ grpc_subchannel* grpc_subchannel_ref_from_weak_ref( } } -static void disconnect(grpc_exec_ctx* exec_ctx, grpc_subchannel* c) { +static void disconnect(grpc_subchannel* c) { grpc_connected_subchannel* con; - grpc_subchannel_index_unregister(exec_ctx, c->key, c); + grpc_subchannel_index_unregister(c->key, c); gpr_mu_lock(&c->mu); GPR_ASSERT(!c->disconnected); c->disconnected = true; - grpc_connector_shutdown( - exec_ctx, c->connector, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected")); + grpc_connector_shutdown(c->connector, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Subchannel disconnected")); con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); if (con != nullptr) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(con, "connection"); gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef); } gpr_mu_unlock(&c->mu); } -void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; // add a weak ref and subtract a strong ref (atomically) old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { - disconnect(exec_ctx, c); + disconnect(c); } - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "strong-unref"); } -void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel* c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +void grpc_subchannel_weak_unref( + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); if (old_refs == 1) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } } -grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, - grpc_connector* connector, +grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, const grpc_subchannel_args* args) { grpc_subchannel_key* key = grpc_subchannel_key_create(args); - grpc_subchannel* c = grpc_subchannel_index_find(exec_ctx, key); + grpc_subchannel* c = grpc_subchannel_index_find(key); if (c) { - grpc_subchannel_key_destroy(exec_ctx, key); + grpc_subchannel_key_destroy(key); return c; } - GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx); + GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(); c = (grpc_subchannel*)gpr_zalloc(sizeof(*c)); c->key = key; gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS); @@ -311,10 +301,10 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, c->pollset_set = grpc_pollset_set_create(); grpc_resolved_address* addr = (grpc_resolved_address*)gpr_malloc(sizeof(*addr)); - grpc_get_subchannel_address_arg(exec_ctx, args->args, addr); + grpc_get_subchannel_address_arg(args->args, addr); grpc_resolved_address* new_address = nullptr; grpc_channel_args* new_args = nullptr; - if (grpc_proxy_mappers_map_address(exec_ctx, addr, args->args, &new_address, + if (grpc_proxy_mappers_map_address(addr, args->args, &new_address, &new_args)) { GPR_ASSERT(new_address != nullptr); gpr_free(addr); @@ -327,7 +317,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, new_args != nullptr ? new_args : args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); gpr_free(new_arg.value.string); - if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); + if (new_args != nullptr) grpc_channel_args_destroy(new_args); c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; GRPC_CLOSURE_INIT(&c->connected, subchannel_connected, c, @@ -373,21 +363,19 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, min_backoff_ms, max_backoff_ms); gpr_mu_init(&c->mu); - return grpc_subchannel_index_register(exec_ctx, key, c); + return grpc_subchannel_index_register(key, c); } -static void continue_connect_locked(grpc_exec_ctx* exec_ctx, - grpc_subchannel* c) { +static void continue_connect_locked(grpc_subchannel* c) { grpc_connect_in_args args; args.interested_parties = c->pollset_set; args.deadline = c->backoff_result.current_deadline; args.channel_args = c->args; - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, - GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, - "state_change"); - grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result, + grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_CONNECTING, + GRPC_ERROR_NONE, "state_change"); + grpc_connector_connect(c->connector, &args, &c->connecting_result, &c->connected); } @@ -400,24 +388,23 @@ grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c, return state; } -static void on_external_state_watcher_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_external_state_watcher_done(void* arg, grpc_error* error) { external_state_watcher* w = (external_state_watcher*)arg; grpc_closure* follow_up = w->notify; if (w->pollset_set != nullptr) { - grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, + grpc_pollset_set_del_pollset_set(w->subchannel->pollset_set, w->pollset_set); } gpr_mu_lock(&w->subchannel->mu); w->next->prev = w->prev; w->prev->next = w->next; gpr_mu_unlock(&w->subchannel->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher"); + GRPC_SUBCHANNEL_WEAK_UNREF(w->subchannel, "external_state_watcher"); gpr_free(w); - GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(follow_up, GRPC_ERROR_REF(error)); } -static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_alarm(void* arg, grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; gpr_mu_lock(&c->mu); c->have_alarm = false; @@ -429,18 +416,17 @@ static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { } if (error == GRPC_ERROR_NONE) { gpr_log(GPR_INFO, "Failed to connect to channel, retrying"); - c->backoff_result = grpc_backoff_step(exec_ctx, &c->backoff_state); - continue_connect_locked(exec_ctx, c); + c->backoff_result = grpc_backoff_step(&c->backoff_state); + continue_connect_locked(c); gpr_mu_unlock(&c->mu); } else { gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); } GRPC_ERROR_UNREF(error); } -static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx, - grpc_subchannel* c) { +static void maybe_start_connecting_locked(grpc_subchannel* c) { if (c->disconnected) { /* Don't try to connect if we're already disconnected */ return; @@ -466,28 +452,28 @@ static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx, if (!c->backoff_begun) { c->backoff_begun = true; - c->backoff_result = grpc_backoff_begin(exec_ctx, &c->backoff_state); - continue_connect_locked(exec_ctx, c); + c->backoff_result = grpc_backoff_begin(&c->backoff_state); + continue_connect_locked(c); } else { GPR_ASSERT(!c->have_alarm); c->have_alarm = true; const grpc_millis time_til_next = - c->backoff_result.next_attempt_start_time - grpc_exec_ctx_now(exec_ctx); + c->backoff_result.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now(); if (time_til_next <= 0) { gpr_log(GPR_INFO, "Retry immediately"); } else { gpr_log(GPR_INFO, "Retry in %" PRIdPTR " milliseconds", time_til_next); } GRPC_CLOSURE_INIT(&c->on_alarm, on_alarm, c, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &c->alarm, - c->backoff_result.next_attempt_start_time, &c->on_alarm); + grpc_timer_init(&c->alarm, c->backoff_result.next_attempt_start_time, + &c->on_alarm); } } void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_subchannel* c, - grpc_pollset_set* interested_parties, grpc_connectivity_state* state, - grpc_closure* notify) { + grpc_subchannel* c, grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, grpc_closure* notify) { external_state_watcher* w; if (state == nullptr) { @@ -495,8 +481,8 @@ void grpc_subchannel_notify_on_state_change( for (w = c->root_external_state_watcher.next; w != &c->root_external_state_watcher; w = w->next) { if (w->notify == notify) { - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &c->state_tracker, nullptr, &w->closure); + grpc_connectivity_state_notify_on_state_change(&c->state_tracker, + nullptr, &w->closure); } } gpr_mu_unlock(&c->mu); @@ -508,31 +494,28 @@ void grpc_subchannel_notify_on_state_change( GRPC_CLOSURE_INIT(&w->closure, on_external_state_watcher_done, w, grpc_schedule_on_exec_ctx); if (interested_parties != nullptr) { - grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, - interested_parties); + grpc_pollset_set_add_pollset_set(c->pollset_set, interested_parties); } GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher"); gpr_mu_lock(&c->mu); w->next = &c->root_external_state_watcher; w->prev = w->next->prev; w->next->prev = w->prev->next = w; - grpc_connectivity_state_notify_on_state_change(exec_ctx, &c->state_tracker, - state, &w->closure); - maybe_start_connecting_locked(exec_ctx, c); + grpc_connectivity_state_notify_on_state_change(&c->state_tracker, state, + &w->closure); + maybe_start_connecting_locked(c); gpr_mu_unlock(&c->mu); } } void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, - grpc_transport_op* op) { + grpc_connected_subchannel* con, grpc_transport_op* op) { grpc_channel_stack* channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); grpc_channel_element* top_elem = grpc_channel_stack_element(channel_stack, 0); - top_elem->filter->start_transport_op(exec_ctx, top_elem, op); + top_elem->filter->start_transport_op(top_elem, op); } -static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { +static void subchannel_on_child_state_changed(void* p, grpc_error* error) { state_watcher* sw = (state_watcher*)p; grpc_subchannel* c = sw->subchannel; gpr_mu* mu = &c->mu; @@ -544,24 +527,22 @@ static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p, /* any errors on a subchannel ==> we're done, create a new one */ sw->connectivity_state = GRPC_CHANNEL_SHUTDOWN; } - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, - sw->connectivity_state, GRPC_ERROR_REF(error), - "reflect_child"); + grpc_connectivity_state_set(&c->state_tracker, sw->connectivity_state, + GRPC_ERROR_REF(error), "reflect_child"); if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_connected_subchannel_notify_on_state_change( - exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr, + GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr, &sw->connectivity_state, &sw->closure); GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); sw = nullptr; } gpr_mu_unlock(mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher"); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "state_watcher"); gpr_free(sw); } -static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx, - grpc_connected_subchannel* con, +static void connected_subchannel_state_op(grpc_connected_subchannel* con, grpc_pollset_set* interested_parties, grpc_connectivity_state* state, grpc_closure* closure) { @@ -571,29 +552,25 @@ static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx, op->on_connectivity_state_change = closure; op->bind_pollset_set = interested_parties; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, - grpc_pollset_set* interested_parties, grpc_connectivity_state* state, - grpc_closure* closure) { - connected_subchannel_state_op(exec_ctx, con, interested_parties, state, - closure); + grpc_connected_subchannel* con, grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, grpc_closure* closure) { + connected_subchannel_state_op(con, interested_parties, state, closure); } -void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, - grpc_connected_subchannel* con, +void grpc_connected_subchannel_ping(grpc_connected_subchannel* con, grpc_closure* closure) { grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; op->send_ping = closure; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } -static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, - grpc_subchannel* c) { +static bool publish_transport_locked(grpc_subchannel* c) { grpc_connected_subchannel* con; grpc_channel_stack* stk; state_watcher* sw_subchannel; @@ -601,19 +578,18 @@ static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, /* construct channel stack */ grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); grpc_channel_stack_builder_set_channel_arguments( - exec_ctx, builder, c->connecting_result.channel_args); + builder, c->connecting_result.channel_args); grpc_channel_stack_builder_set_transport(builder, c->connecting_result.transport); - if (!grpc_channel_init_create_stack(exec_ctx, builder, - GRPC_CLIENT_SUBCHANNEL)) { - grpc_channel_stack_builder_destroy(exec_ctx, builder); + if (!grpc_channel_init_create_stack(builder, GRPC_CLIENT_SUBCHANNEL)) { + grpc_channel_stack_builder_destroy(builder); return false; } grpc_error* error = grpc_channel_stack_builder_finish( - exec_ctx, builder, 0, 1, connection_destroy, nullptr, (void**)&con); + builder, 0, 1, connection_destroy, nullptr, (void**)&con); if (error != GRPC_ERROR_NONE) { - grpc_transport_destroy(exec_ctx, c->connecting_result.transport); + grpc_transport_destroy(c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", grpc_error_string(error)); GRPC_ERROR_UNREF(error); @@ -631,7 +607,7 @@ static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, if (c->disconnected) { gpr_free(sw_subchannel); - grpc_channel_stack_destroy(exec_ctx, stk); + grpc_channel_stack_destroy(stk); gpr_free(con); return false; } @@ -647,19 +623,18 @@ static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, /* setup subchannel watching connected subchannel for changes; subchannel ref for connecting is donated to the state watcher */ GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); grpc_connected_subchannel_notify_on_state_change( - exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state, + con, c->pollset_set, &sw_subchannel->connectivity_state, &sw_subchannel->closure); /* signal completion */ - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, + grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "connected"); return true; } -static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void subchannel_connected(void* arg, grpc_error* error) { grpc_subchannel* c = (grpc_subchannel*)arg; grpc_channel_args* delete_channel_args = c->connecting_result.channel_args; @@ -667,13 +642,13 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, gpr_mu_lock(&c->mu); c->connecting = false; if (c->connecting_result.transport != nullptr && - publish_transport_locked(exec_ctx, c)) { + publish_transport_locked(c)) { /* do nothing, transport was published */ } else if (c->disconnected) { - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); } else { grpc_connectivity_state_set( - exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Connect Failed", &error, 1), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE), @@ -682,27 +657,26 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, const char* errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); - maybe_start_connecting_locked(exec_ctx, c); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + maybe_start_connecting_locked(c); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting"); } gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connected"); - grpc_channel_args_destroy(exec_ctx, delete_channel_args); + GRPC_SUBCHANNEL_WEAK_UNREF(c, "connected"); + grpc_channel_args_destroy(delete_channel_args); } /* * grpc_subchannel_call implementation */ -static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call, - grpc_error* error) { +static void subchannel_call_destroy(void* call, grpc_error* error) { grpc_subchannel_call* c = (grpc_subchannel_call*)call; GPR_ASSERT(c->schedule_closure_after_destroy != nullptr); GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); grpc_connected_subchannel* connection = c->connection; - grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, + grpc_call_stack_destroy(SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, c->schedule_closure_after_destroy); - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); + GRPC_CONNECTED_SUBCHANNEL_UNREF(connection, "subchannel_call"); GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); } @@ -718,20 +692,18 @@ void grpc_subchannel_call_ref( GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel_call* c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); +void grpc_subchannel_call_unref( + grpc_subchannel_call* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CALL_STACK_UNREF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, - grpc_subchannel_call* call, +void grpc_subchannel_call_process_op(grpc_subchannel_call* call, grpc_transport_stream_op_batch* batch) { GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0); grpc_call_stack* call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); grpc_call_element* top_elem = grpc_call_stack_element(call_stack, 0); GRPC_CALL_LOG_OP(GPR_INFO, top_elem, batch); - top_elem->filter->start_transport_stream_op_batch(exec_ctx, top_elem, batch); + top_elem->filter->start_transport_stream_op_batch(top_elem, batch); GPR_TIMER_END("grpc_subchannel_call_process_op", 0); } @@ -746,7 +718,7 @@ const grpc_subchannel_key* grpc_subchannel_get_key( } grpc_error* grpc_connected_subchannel_create_call( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + grpc_connected_subchannel* con, const grpc_connected_subchannel_call_args* args, grpc_subchannel_call** call) { grpc_channel_stack* chanstk = CHANNEL_STACK_FROM_CONNECTION(con); @@ -764,14 +736,14 @@ grpc_error* grpc_connected_subchannel_create_call( args->arena, /* arena */ args->call_combiner /* call_combiner */ }; - grpc_error* error = grpc_call_stack_init( - exec_ctx, chanstk, 1, subchannel_call_destroy, *call, &call_args); + grpc_error* error = grpc_call_stack_init(chanstk, 1, subchannel_call_destroy, + *call, &call_args); if (error != GRPC_ERROR_NONE) { const char* error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); return error; } - grpc_call_stack_set_pollset_or_pollset_set(exec_ctx, callstk, args->pollent); + grpc_call_stack_set_pollset_or_pollset_set(callstk, args->pollent); return GRPC_ERROR_NONE; } @@ -780,21 +752,20 @@ grpc_call_stack* grpc_subchannel_call_get_call_stack( return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); } -static void grpc_uri_to_sockaddr(grpc_exec_ctx* exec_ctx, const char* uri_str, +static void grpc_uri_to_sockaddr(const char* uri_str, grpc_resolved_address* addr) { - grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */); + grpc_uri* uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */); GPR_ASSERT(uri != nullptr); if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr)); grpc_uri_destroy(uri); } -void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, - const grpc_channel_args* args, +void grpc_get_subchannel_address_arg(const grpc_channel_args* args, grpc_resolved_address* addr) { const char* addr_uri_str = grpc_get_subchannel_address_uri_arg(args); memset(addr, 0, sizeof(*addr)); if (*addr_uri_str != '\0') { - grpc_uri_to_sockaddr(exec_ctx, addr_uri_str, addr); + grpc_uri_to_sockaddr(addr_uri_str, addr); } } diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 1f326fc1d2..84d9fa27a1 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -42,36 +42,34 @@ typedef struct grpc_subchannel_key grpc_subchannel_key; grpc_subchannel_ref((p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_UNREF(cl, p, r) \ - grpc_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_UNREF(p, r) \ + grpc_subchannel_unref((p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_WEAK_REF(p, r) \ grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ - grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) \ + grpc_subchannel_weak_unref((p), __FILE__, __LINE__, (r)) #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ - grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(p, r) \ + grpc_connected_subchannel_unref((p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_CALL_REF(p, r) \ grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ - grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_CALL_UNREF(p, r) \ + grpc_subchannel_call_unref((p), __FILE__, __LINE__, (r)) #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ , const char *file, int line, const char *reason #else #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p)) #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ grpc_subchannel_ref_from_weak_ref((p)) -#define GRPC_SUBCHANNEL_UNREF(cl, p, r) grpc_subchannel_unref((cl), (p)) +#define GRPC_SUBCHANNEL_UNREF(p, r) grpc_subchannel_unref((p)) #define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p)) -#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ - grpc_subchannel_weak_unref((cl), (p)) +#define GRPC_SUBCHANNEL_WEAK_UNREF(p, r) grpc_subchannel_weak_unref((p)) #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ - grpc_connected_subchannel_unref((cl), (p)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(p, r) \ + grpc_connected_subchannel_unref((p)) #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) -#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ - grpc_subchannel_call_unref((cl), (p)) +#define GRPC_SUBCHANNEL_CALL_UNREF(p, r) grpc_subchannel_call_unref((p)) #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS #endif @@ -79,24 +77,20 @@ grpc_subchannel* grpc_subchannel_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_subchannel* grpc_subchannel_ref_from_weak_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel* channel - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_unref( + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_subchannel* grpc_subchannel_weak_ref( grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel* channel - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_weak_unref( + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); grpc_connected_subchannel* grpc_connected_subchannel_ref( grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, - grpc_connected_subchannel* channel - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_connected_subchannel_unref( + grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); void grpc_subchannel_call_ref( grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel_call* call - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_call_unref( + grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); /** construct a subchannel call */ typedef struct { @@ -110,14 +104,13 @@ typedef struct { } grpc_connected_subchannel_call_args; grpc_error* grpc_connected_subchannel_create_call( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* connected_subchannel, + grpc_connected_subchannel* connected_subchannel, const grpc_connected_subchannel_call_args* args, grpc_subchannel_call** subchannel_call); /** process a transport level op */ void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* subchannel, - grpc_transport_op* op); + grpc_connected_subchannel* subchannel, grpc_transport_op* op); /** poll the current connectivity state of a channel */ grpc_connectivity_state grpc_subchannel_check_connectivity( @@ -126,15 +119,12 @@ grpc_connectivity_state grpc_subchannel_check_connectivity( /** Calls notify when the connectivity state of a channel becomes different from *state. Updates *state with the new state of the channel. */ void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_subchannel* channel, - grpc_pollset_set* interested_parties, grpc_connectivity_state* state, - grpc_closure* notify); + grpc_subchannel* channel, grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, grpc_closure* notify); void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* channel, - grpc_pollset_set* interested_parties, grpc_connectivity_state* state, - grpc_closure* notify); -void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, - grpc_connected_subchannel* channel, + grpc_connected_subchannel* channel, grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, grpc_closure* notify); +void grpc_connected_subchannel_ping(grpc_connected_subchannel* channel, grpc_closure* notify); /** retrieve the grpc_connected_subchannel - or NULL if called before @@ -147,8 +137,7 @@ const grpc_subchannel_key* grpc_subchannel_get_key( const grpc_subchannel* subchannel); /** continue processing a transport op */ -void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, - grpc_subchannel_call* subchannel_call, +void grpc_subchannel_call_process_op(grpc_subchannel_call* subchannel_call, grpc_transport_stream_op_batch* op); /** Must be called once per call. Sets the 'then_schedule_closure' argument for @@ -172,13 +161,11 @@ struct grpc_subchannel_args { }; /** create a subchannel given a connector */ -grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, - grpc_connector* connector, +grpc_subchannel* grpc_subchannel_create(grpc_connector* connector, const grpc_subchannel_args* args); /// Sets \a addr from \a args. -void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, - const grpc_channel_args* args, +void grpc_get_subchannel_address_arg(const grpc_channel_args* args, grpc_resolved_address* addr); /// Returns the URI string for the address to connect to. diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 1624643d0b..052b047f43 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -81,16 +81,14 @@ int grpc_subchannel_key_compare(const grpc_subchannel_key* a, return grpc_channel_args_compare(a->args.args, b->args.args); } -void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* k) { +void grpc_subchannel_key_destroy(grpc_subchannel_key* k) { gpr_free((grpc_channel_args*)k->args.filters); - grpc_channel_args_destroy(exec_ctx, (grpc_channel_args*)k->args.args); + grpc_channel_args_destroy((grpc_channel_args*)k->args.args); gpr_free(k); } static void sck_avl_destroy(void* p, void* user_data) { - grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; - grpc_subchannel_key_destroy(exec_ctx, (grpc_subchannel_key*)p); + grpc_subchannel_key_destroy((grpc_subchannel_key*)p); } static void* sck_avl_copy(void* p, void* unused) { @@ -103,8 +101,7 @@ static long sck_avl_compare(void* a, void* b, void* unused) { } static void scv_avl_destroy(void* p, void* user_data) { - grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, (grpc_subchannel*)p, "subchannel_index"); + GRPC_SUBCHANNEL_WEAK_UNREF((grpc_subchannel*)p, "subchannel_index"); } static void* scv_avl_copy(void* p, void* unused) { @@ -135,32 +132,29 @@ void grpc_subchannel_index_shutdown(void) { void grpc_subchannel_index_unref(void) { if (gpr_unref(&g_refcount)) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index, &exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + gpr_avl_unref(g_subchannel_index, grpc_core::ExecCtx::Get()); } } void grpc_subchannel_index_ref(void) { gpr_ref_non_zero(&g_refcount); } -grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key) { +grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx), "index_find"); - gpr_avl_unref(index, exec_ctx); + (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()), + "index_find"); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); return c; } -grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key, +grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, grpc_subchannel* constructed) { grpc_subchannel* c = nullptr; bool need_to_unref_constructed = false; @@ -171,11 +165,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + c = (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); if (c != nullptr) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -184,9 +178,11 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, need_to_unref_constructed = true; } else { // no -> update the avl and compare/swap - gpr_avl updated = gpr_avl_add( - gpr_avl_ref(index, exec_ctx), subchannel_key_copy(key), - GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), exec_ctx); + gpr_avl updated = + gpr_avl_add(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), + subchannel_key_copy(key), + GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"), + grpc_core::ExecCtx::Get()); // it may happen (but it's expected to be unlikely) // that some other thread has changed the index: @@ -198,41 +194,42 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); + gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); } - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); } if (need_to_unref_constructed) { - GRPC_SUBCHANNEL_UNREF(exec_ctx, constructed, "index_register"); + GRPC_SUBCHANNEL_UNREF(constructed, "index_register"); } return c; } -void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key, +void grpc_subchannel_index_unregister(grpc_subchannel_key* key, grpc_subchannel* constructed) { bool done = false; while (!done) { // Compare and swap loop: // - take a reference to the current index gpr_mu_lock(&g_mu); - gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); + gpr_avl index = gpr_avl_ref(g_subchannel_index, grpc_core::ExecCtx::Get()); gpr_mu_unlock(&g_mu); // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel* c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); + grpc_subchannel* c = + (grpc_subchannel*)gpr_avl_get(index, key, grpc_core::ExecCtx::Get()); if (c != constructed) { - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); break; } // compare and swap the update (some other thread may have // mutated the index behind us) gpr_avl updated = - gpr_avl_remove(gpr_avl_ref(index, exec_ctx), key, exec_ctx); + gpr_avl_remove(gpr_avl_ref(index, grpc_core::ExecCtx::Get()), key, + grpc_core::ExecCtx::Get()); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -241,8 +238,8 @@ void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, } gpr_mu_unlock(&g_mu); - gpr_avl_unref(updated, exec_ctx); - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(updated, grpc_core::ExecCtx::Get()); + gpr_avl_unref(index, grpc_core::ExecCtx::Get()); } } diff --git a/src/core/ext/filters/client_channel/subchannel_index.h b/src/core/ext/filters/client_channel/subchannel_index.h index 6a4d06ef8f..bd160a3b13 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.h +++ b/src/core/ext/filters/client_channel/subchannel_index.h @@ -29,26 +29,22 @@ grpc_subchannel_key* grpc_subchannel_key_create( const grpc_subchannel_args* args); /** Destroy a subchannel key */ -void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key); +void grpc_subchannel_key_destroy(grpc_subchannel_key* key); /** Given a subchannel key, find the subchannel registered for it. Returns NULL if no such channel exists. Thread-safe. */ -grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key); +grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key); /** Register a subchannel against a key. Takes ownership of \a constructed. Returns the registered subchannel. This may be different from \a constructed in the case of a registration race. */ -grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key, +grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key, grpc_subchannel* constructed); /** Remove \a constructed as the registered subchannel for \a key. */ -void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, - grpc_subchannel_key* key, +void grpc_subchannel_index_unregister(grpc_subchannel_key* key, grpc_subchannel* constructed); int grpc_subchannel_key_compare(const grpc_subchannel_key* a, diff --git a/src/core/ext/filters/client_channel/uri_parser.cc b/src/core/ext/filters/client_channel/uri_parser.cc index b76dcbe4e3..3428f4b54c 100644 --- a/src/core/ext/filters/client_channel/uri_parser.cc +++ b/src/core/ext/filters/client_channel/uri_parser.cc @@ -56,8 +56,8 @@ static grpc_uri* bad_uri(const char* uri_text, size_t pos, const char* section, } /** Returns a copy of percent decoded \a src[begin, end) */ -static char* decode_and_copy_component(grpc_exec_ctx* exec_ctx, const char* src, - size_t begin, size_t end) { +static char* decode_and_copy_component(const char* src, size_t begin, + size_t end) { grpc_slice component = (begin == NOT_SET || end == NOT_SET) ? grpc_empty_slice() @@ -65,8 +65,8 @@ static char* decode_and_copy_component(grpc_exec_ctx* exec_ctx, const char* src, grpc_slice decoded_component = grpc_permissive_percent_decode_slice(component); char* out = grpc_dump_slice(decoded_component, GPR_DUMP_ASCII); - grpc_slice_unref_internal(exec_ctx, component); - grpc_slice_unref_internal(exec_ctx, decoded_component); + grpc_slice_unref_internal(component); + grpc_slice_unref_internal(decoded_component); return out; } @@ -184,8 +184,7 @@ static void parse_query_parts(grpc_uri* uri) { } } -grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, - bool suppress_errors) { +grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors) { grpc_uri* uri; size_t scheme_begin = 0; size_t scheme_end = NOT_SET; @@ -273,16 +272,13 @@ grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, } uri = (grpc_uri*)gpr_zalloc(sizeof(*uri)); - uri->scheme = - decode_and_copy_component(exec_ctx, uri_text, scheme_begin, scheme_end); - uri->authority = decode_and_copy_component(exec_ctx, uri_text, - authority_begin, authority_end); - uri->path = - decode_and_copy_component(exec_ctx, uri_text, path_begin, path_end); - uri->query = - decode_and_copy_component(exec_ctx, uri_text, query_begin, query_end); - uri->fragment = decode_and_copy_component(exec_ctx, uri_text, fragment_begin, - fragment_end); + uri->scheme = decode_and_copy_component(uri_text, scheme_begin, scheme_end); + uri->authority = + decode_and_copy_component(uri_text, authority_begin, authority_end); + uri->path = decode_and_copy_component(uri_text, path_begin, path_end); + uri->query = decode_and_copy_component(uri_text, query_begin, query_end); + uri->fragment = + decode_and_copy_component(uri_text, fragment_begin, fragment_end); parse_query_parts(uri); return uri; diff --git a/src/core/ext/filters/client_channel/uri_parser.h b/src/core/ext/filters/client_channel/uri_parser.h index 84752905e8..24ff06c0b5 100644 --- a/src/core/ext/filters/client_channel/uri_parser.h +++ b/src/core/ext/filters/client_channel/uri_parser.h @@ -37,8 +37,7 @@ typedef struct { } grpc_uri; /** parse a uri, return NULL on failure */ -grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, - bool suppress_errors); +grpc_uri* grpc_uri_parse(const char* uri_text, bool suppress_errors); /** return the part of a query string after the '=' in "?key=xxx&...", or NULL * if key is not present */ diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index 5db7584a59..c430f3d2d4 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -36,18 +36,16 @@ // The on_complete callback used when sending a cancel_error batch down the // filter stack. Yields the call combiner when the batch returns. -static void yield_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* ignored) { +static void yield_call_combiner(void* arg, grpc_error* ignored) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; - GRPC_CALL_COMBINER_STOP(exec_ctx, deadline_state->call_combiner, + GRPC_CALL_COMBINER_STOP(deadline_state->call_combiner, "got on_complete from cancel_stream batch"); - GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); + GRPC_CALL_STACK_UNREF(deadline_state->call_stack, "deadline_timer"); } // This is called via the call combiner, so access to deadline_state is // synchronized. -static void send_cancel_op_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void send_cancel_op_in_call_combiner(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; grpc_transport_stream_op_batch* batch = grpc_make_transport_stream_op( @@ -55,37 +53,34 @@ static void send_cancel_op_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, deadline_state, grpc_schedule_on_exec_ctx)); batch->cancel_stream = true; batch->payload->cancel_stream.cancel_error = GRPC_ERROR_REF(error); - elem->filter->start_transport_stream_op_batch(exec_ctx, elem, batch); + elem->filter->start_transport_stream_op_batch(elem, batch); } // Timer callback. -static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void timer_callback(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; if (error != GRPC_ERROR_CANCELLED) { error = grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Deadline Exceeded"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_DEADLINE_EXCEEDED); - grpc_call_combiner_cancel(exec_ctx, deadline_state->call_combiner, + grpc_call_combiner_cancel(deadline_state->call_combiner, GRPC_ERROR_REF(error)); GRPC_CLOSURE_INIT(&deadline_state->timer_callback, send_cancel_op_in_call_combiner, elem, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(exec_ctx, deadline_state->call_combiner, + GRPC_CALL_COMBINER_START(deadline_state->call_combiner, &deadline_state->timer_callback, error, "deadline exceeded -- sending cancel_stream op"); } else { - GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, - "deadline_timer"); + GRPC_CALL_STACK_UNREF(deadline_state->call_stack, "deadline_timer"); } } // Starts the deadline timer. // This is called via the call combiner, so access to deadline_state is // synchronized. -static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void start_timer_if_needed(grpc_call_element* elem, grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return; @@ -113,17 +108,16 @@ static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, } GPR_ASSERT(closure != nullptr); GRPC_CALL_STACK_REF(deadline_state->call_stack, "deadline_timer"); - grpc_timer_init(exec_ctx, &deadline_state->timer, deadline, closure); + grpc_timer_init(&deadline_state->timer, deadline, closure); } // Cancels the deadline timer. // This is called via the call combiner, so access to deadline_state is // synchronized. -static void cancel_timer_if_needed(grpc_exec_ctx* exec_ctx, - grpc_deadline_state* deadline_state) { +static void cancel_timer_if_needed(grpc_deadline_state* deadline_state) { if (deadline_state->timer_state == GRPC_DEADLINE_STATE_PENDING) { deadline_state->timer_state = GRPC_DEADLINE_STATE_FINISHED; - grpc_timer_cancel(exec_ctx, &deadline_state->timer); + grpc_timer_cancel(&deadline_state->timer); } else { // timer was either in STATE_INITAL (nothing to cancel) // OR in STATE_FINISHED (again nothing to cancel) @@ -131,12 +125,11 @@ static void cancel_timer_if_needed(grpc_exec_ctx* exec_ctx, } // Callback run when the call is complete. -static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_complete(void* arg, grpc_error* error) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)arg; - cancel_timer_if_needed(exec_ctx, deadline_state); + cancel_timer_if_needed(deadline_state); // Invoke the next callback. - GRPC_CLOSURE_RUN(exec_ctx, deadline_state->next_on_complete, - GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(deadline_state->next_on_complete, GRPC_ERROR_REF(error)); } // Inject our own on_complete callback into op. @@ -156,8 +149,7 @@ struct start_timer_after_init_state { grpc_millis deadline; grpc_closure closure; }; -static void start_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void start_timer_after_init(void* arg, grpc_error* error) { struct start_timer_after_init_state* state = (struct start_timer_after_init_state*)arg; grpc_deadline_state* deadline_state = @@ -166,18 +158,18 @@ static void start_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, // We are initially called without holding the call combiner, so we // need to bounce ourselves into it. state->in_call_combiner = true; - GRPC_CALL_COMBINER_START(exec_ctx, deadline_state->call_combiner, - &state->closure, GRPC_ERROR_REF(error), + GRPC_CALL_COMBINER_START(deadline_state->call_combiner, &state->closure, + GRPC_ERROR_REF(error), "scheduling deadline timer"); return; } - start_timer_if_needed(exec_ctx, state->elem, state->deadline); + start_timer_if_needed(state->elem, state->deadline); gpr_free(state); - GRPC_CALL_COMBINER_STOP(exec_ctx, deadline_state->call_combiner, + GRPC_CALL_COMBINER_STOP(deadline_state->call_combiner, "done scheduling deadline timer"); } -void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_deadline_state_init(grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline) { @@ -200,29 +192,27 @@ void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, state->deadline = deadline; GRPC_CLOSURE_INIT(&state->closure, start_timer_after_init, state, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &state->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&state->closure, GRPC_ERROR_NONE); } } -void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +void grpc_deadline_state_destroy(grpc_call_element* elem) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; - cancel_timer_if_needed(exec_ctx, deadline_state); + cancel_timer_if_needed(deadline_state); } -void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_deadline_state_reset(grpc_call_element* elem, grpc_millis new_deadline) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; - cancel_timer_if_needed(exec_ctx, deadline_state); - start_timer_if_needed(exec_ctx, elem, new_deadline); + cancel_timer_if_needed(deadline_state); + start_timer_if_needed(elem, new_deadline); } void grpc_deadline_state_client_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; if (op->cancel_stream) { - cancel_timer_if_needed(exec_ctx, deadline_state); + cancel_timer_if_needed(deadline_state); } else { // Make sure we know when the call is complete, so that we can cancel // the timer. @@ -237,16 +227,14 @@ void grpc_deadline_state_client_start_transport_stream_op_batch( // // Constructor for channel_data. Used for both client and server filters. -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } // Destructor for channel_data. Used for both client and server filters. -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} // Call data used for both client and server filter. typedef struct base_call_data { @@ -266,50 +254,45 @@ typedef struct server_call_data { } server_call_data; // Constructor for call_data. Used for both client and server filters. -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { - grpc_deadline_state_init(exec_ctx, elem, args->call_stack, - args->call_combiner, args->deadline); + grpc_deadline_state_init(elem, args->call_stack, args->call_combiner, + args->deadline); return GRPC_ERROR_NONE; } // Destructor for call_data. Used for both client and server filters. -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { - grpc_deadline_state_destroy(exec_ctx, elem); + grpc_deadline_state_destroy(elem); } // Method for starting a call op for client filter. static void client_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { - grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, - op); + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { + grpc_deadline_state_client_start_transport_stream_op_batch(elem, op); // Chain to next filter. - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } // Callback for receiving initial metadata on the server. -static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void recv_initial_metadata_ready(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; server_call_data* calld = (server_call_data*)elem->call_data; // Get deadline from metadata and start the timer if needed. - start_timer_if_needed(exec_ctx, elem, calld->recv_initial_metadata->deadline); + start_timer_if_needed(elem, calld->recv_initial_metadata->deadline); // Invoke the next callback. calld->next_recv_initial_metadata_ready->cb( - exec_ctx, calld->next_recv_initial_metadata_ready->cb_arg, error); + calld->next_recv_initial_metadata_ready->cb_arg, error); } // Method for starting a call op for server filter. static void server_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { server_call_data* calld = (server_call_data*)elem->call_data; if (op->cancel_stream) { - cancel_timer_if_needed(exec_ctx, &calld->base.deadline_state); + cancel_timer_if_needed(&calld->base.deadline_state); } else { // If we're receiving initial metadata, we need to get the deadline // from the recv_initial_metadata_ready callback. So we inject our @@ -335,7 +318,7 @@ static void server_start_transport_stream_op_batch( } } // Chain to next filter. - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } const grpc_channel_filter grpc_client_deadline_filter = { @@ -372,8 +355,7 @@ bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) { !grpc_channel_args_want_minimal_stack(channel_args)); } -static bool maybe_add_deadline_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_deadline_checking_enabled( grpc_channel_stack_builder_get_channel_arguments(builder)) diff --git a/src/core/ext/filters/deadline/deadline_filter.h b/src/core/ext/filters/deadline/deadline_filter.h index 8d835d0382..4de817ef54 100644 --- a/src/core/ext/filters/deadline/deadline_filter.h +++ b/src/core/ext/filters/deadline/deadline_filter.h @@ -49,13 +49,12 @@ typedef struct grpc_deadline_state { // // assumes elem->call_data is zero'd -void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_deadline_state_init(grpc_call_element* elem, grpc_call_stack* call_stack, grpc_call_combiner* call_combiner, grpc_millis deadline); -void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem); +void grpc_deadline_state_destroy(grpc_call_element* elem); // Cancels the existing timer and starts a new one with new_deadline. // @@ -66,7 +65,7 @@ void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx, // deadline may result in the timer being called twice. // // Note: Must be called while holding the call combiner. -void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_deadline_state_reset(grpc_call_element* elem, grpc_millis new_deadline); // To be called from the client-side filter's start_transport_stream_op_batch() @@ -78,8 +77,7 @@ void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, // // Note: Must be called while holding the call combiner. void grpc_deadline_state_client_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op); + grpc_call_element* elem, grpc_transport_stream_op_batch* op); // Should deadline checking be performed (according to channel args) bool grpc_deadline_checking_enabled(const grpc_channel_args* args); diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index a625369b02..a1fb10f5b8 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -68,12 +68,11 @@ typedef struct channel_data { size_t max_payload_size_for_get; } channel_data; -static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* client_filter_incoming_metadata(grpc_call_element* elem, grpc_metadata_batch* b) { if (b->idx.named.status != nullptr) { if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); + grpc_metadata_batch_remove(b, b->idx.named.status); } else { char* val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), GPR_DUMP_ASCII); @@ -98,10 +97,9 @@ static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_MDVALUE(b->idx.named.grpc_message->md)); if (grpc_slice_is_equivalent(pct_decoded_msg, GRPC_MDVALUE(b->idx.named.grpc_message->md))) { - grpc_slice_unref_internal(exec_ctx, pct_decoded_msg); + grpc_slice_unref_internal(pct_decoded_msg); } else { - grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, - pct_decoded_msg); + grpc_metadata_batch_set_value(b->idx.named.grpc_message, pct_decoded_msg); } } @@ -131,60 +129,53 @@ static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, gpr_free(val); } } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); + grpc_metadata_batch_remove(b, b->idx.named.content_type); } return GRPC_ERROR_NONE; } -static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, - void* user_data, grpc_error* error) { +static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - error = client_filter_incoming_metadata(exec_ctx, elem, - calld->recv_initial_metadata); + error = client_filter_incoming_metadata(elem, calld->recv_initial_metadata); } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, - error); + GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, error); } -static void recv_trailing_metadata_on_complete(grpc_exec_ctx* exec_ctx, - void* user_data, +static void recv_trailing_metadata_on_complete(void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - error = client_filter_incoming_metadata(exec_ctx, elem, - calld->recv_trailing_metadata); + error = + client_filter_incoming_metadata(elem, calld->recv_trailing_metadata); } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_trailing_metadata_on_complete, - error); + GRPC_CLOSURE_RUN(calld->original_recv_trailing_metadata_on_complete, error); } -static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void send_message_on_complete(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - grpc_byte_stream_cache_destroy(exec_ctx, &calld->send_message_cache); - GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, + grpc_byte_stream_cache_destroy(&calld->send_message_cache); + GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } // Pulls a slice from the send_message byte stream, updating // calld->send_message_bytes_read. -static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, - call_data* calld) { +static grpc_error* pull_slice_from_send_message(call_data* calld) { grpc_slice incoming_slice; grpc_error* error = grpc_byte_stream_pull( - exec_ctx, &calld->send_message_caching_stream.base, &incoming_slice); + &calld->send_message_caching_stream.base, &incoming_slice); if (error == GRPC_ERROR_NONE) { calld->send_message_bytes_read += GRPC_SLICE_LENGTH(incoming_slice); - grpc_slice_unref_internal(exec_ctx, incoming_slice); + grpc_slice_unref_internal(incoming_slice); } return error; } @@ -194,12 +185,10 @@ static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, // calld->send_message_caching_stream.base.length, then we have completed // reading from the byte stream; otherwise, an async read has been dispatched // and on_send_message_next_done() will be invoked when it is complete. -static grpc_error* read_all_available_send_message_data(grpc_exec_ctx* exec_ctx, - call_data* calld) { - while (grpc_byte_stream_next(exec_ctx, - &calld->send_message_caching_stream.base, +static grpc_error* read_all_available_send_message_data(call_data* calld) { + while (grpc_byte_stream_next(&calld->send_message_caching_stream.base, ~(size_t)0, &calld->on_send_message_next_done)) { - grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); + grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) return error; if (calld->send_message_bytes_read == calld->send_message_caching_stream.base.length) { @@ -210,19 +199,18 @@ static grpc_error* read_all_available_send_message_data(grpc_exec_ctx* exec_ctx, } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_send_message_next_done(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->send_message_batch, error, calld->call_combiner); + calld->send_message_batch, error, calld->call_combiner); return; } - error = pull_slice_from_send_message(exec_ctx, calld); + error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->send_message_batch, error, calld->call_combiner); + calld->send_message_batch, error, calld->call_combiner); return; } // There may or may not be more to read, but we don't care. If we got @@ -230,7 +218,7 @@ static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, // synchronously, so we were not able to do a cached call. Instead, // we just reset the byte stream and then send down the batch as-is. grpc_caching_byte_stream_reset(&calld->send_message_caching_stream); - grpc_call_next_op(exec_ctx, elem, calld->send_message_batch); + grpc_call_next_op(elem, calld->send_message_batch); } static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { @@ -248,8 +236,7 @@ static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { // Modifies the path entry in the batch's send_initial_metadata to // append the base64-encoded query for a GET request. -static grpc_error* update_path_for_get(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* update_path_for_get(grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; grpc_slice path_slice = @@ -282,24 +269,22 @@ static grpc_error* update_path_for_get(grpc_exec_ctx* exec_ctx, grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t)); /* substitute previous path with the new path+query */ grpc_mdelem mdelem_path_and_query = - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, path_with_query_slice); + grpc_mdelem_from_slices(GRPC_MDSTR_PATH, path_with_query_slice); grpc_metadata_batch* b = batch->payload->send_initial_metadata.send_initial_metadata; - return grpc_metadata_batch_substitute(exec_ctx, b, b->idx.named.path, + return grpc_metadata_batch_substitute(b, b->idx.named.path, mdelem_path_and_query); } -static void remove_if_present(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +static void remove_if_present(grpc_metadata_batch* batch, grpc_metadata_batch_callouts_index idx) { if (batch->idx.array[idx] != nullptr) { - grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); + grpc_metadata_batch_remove(batch, batch->idx.array[idx]); } } static void hc_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* channeld = (channel_data*)elem->channel_data; GPR_TIMER_BEGIN("hc_start_transport_stream_op_batch", 0); @@ -345,17 +330,16 @@ static void hc_start_transport_stream_op_batch( calld->original_send_message_on_complete = batch->on_complete; batch->on_complete = &calld->send_message_on_complete; calld->send_message_batch = batch; - error = read_all_available_send_message_data(exec_ctx, calld); + error = read_all_available_send_message_data(calld); if (error != GRPC_ERROR_NONE) goto done; // If all the data has been read, then we can use GET. if (calld->send_message_bytes_read == calld->send_message_caching_stream.base.length) { method = GRPC_MDELEM_METHOD_GET; - error = update_path_for_get(exec_ctx, elem, batch); + error = update_path_for_get(elem, batch); if (error != GRPC_ERROR_NONE) goto done; batch->send_message = false; - grpc_byte_stream_destroy(exec_ctx, - &calld->send_message_caching_stream.base); + grpc_byte_stream_destroy(&calld->send_message_caching_stream.base); } else { // Not all data is available. The batch will be sent down // asynchronously in on_send_message_next_done(). @@ -372,41 +356,41 @@ static void hc_start_transport_stream_op_batch( } remove_if_present( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_METHOD); remove_if_present( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_SCHEME); remove_if_present( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_TE); remove_if_present( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_CONTENT_TYPE); remove_if_present( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, GRPC_BATCH_USER_AGENT); /* Send : prefixed headers, which have to be before any application layer headers. */ error = grpc_metadata_batch_add_head( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, &calld->method, method); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_head( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, &calld->scheme, channeld->static_scheme); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, &calld->te_trailers, GRPC_MDELEM_TE_TRAILERS); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); if (error != GRPC_ERROR_NONE) goto done; error = grpc_metadata_batch_add_tail( - exec_ctx, batch->payload->send_initial_metadata.send_initial_metadata, + batch->payload->send_initial_metadata.send_initial_metadata, &calld->user_agent, GRPC_MDELEM_REF(channeld->user_agent)); if (error != GRPC_ERROR_NONE) goto done; } @@ -414,16 +398,15 @@ static void hc_start_transport_stream_op_batch( done: if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->send_message_batch, error, calld->call_combiner); + calld->send_message_batch, error, calld->call_combiner); } else if (!batch_will_be_handled_asynchronously) { - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); } GPR_TIMER_END("hc_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; @@ -441,7 +424,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} @@ -533,8 +516,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args, } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(!args->is_last); @@ -543,17 +525,16 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, chand->max_payload_size_for_get = max_payload_size_from_args(args->channel_args); chand->user_agent = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_USER_AGENT, + GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args, args->optional_transport->vtable->name)); return GRPC_ERROR_NONE; } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - GRPC_MDELEM_UNREF(exec_ctx, chand->user_agent); + GRPC_MDELEM_UNREF(chand->user_agent); } const grpc_channel_filter grpc_http_client_filter = { diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 483eb021e8..deec77c96f 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -40,8 +40,7 @@ static bool is_building_http_like_transport( return t != nullptr && strstr(t->vtable->name, "http"); } -static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder, void* arg) { if (!is_building_http_like_transport(builder)) return true; optional_filter* filtarg = (optional_filter*)arg; @@ -55,8 +54,7 @@ static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, : true; } -static bool maybe_add_required_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_required_filter(grpc_channel_stack_builder* builder, void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index d070b56b6a..9ae13d2ed2 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -100,12 +100,11 @@ static bool skip_compression(grpc_call_element* elem, uint32_t flags, /** Filter initial metadata */ static grpc_error* process_send_initial_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_metadata_batch* initial_metadata, + grpc_call_element* elem, grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) GRPC_MUST_USE_RESULT; static grpc_error* process_send_initial_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) { + grpc_call_element* elem, grpc_metadata_batch* initial_metadata, + bool* has_compression_algorithm) { call_data* calld = (call_data*)elem->call_data; channel_data* channeld = (channel_data*)elem->channel_data; *has_compression_algorithm = false; @@ -137,13 +136,13 @@ static grpc_error* process_send_initial_metadata( } *has_compression_algorithm = true; grpc_metadata_batch_remove( - exec_ctx, initial_metadata, + initial_metadata, initial_metadata->idx.named.grpc_internal_stream_encoding_request); /* Disable message-wise compression */ calld->compression_algorithm = GRPC_COMPRESS_NONE; if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { grpc_metadata_batch_remove( - exec_ctx, initial_metadata, + initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } } else if (initial_metadata->idx.named.grpc_internal_encoding_request != @@ -160,7 +159,7 @@ static grpc_error* process_send_initial_metadata( } *has_compression_algorithm = true; grpc_metadata_batch_remove( - exec_ctx, initial_metadata, + initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } else { /* If no algorithm was found in the metadata and we aren't @@ -181,12 +180,11 @@ static grpc_error* process_send_initial_metadata( /* hint compression algorithm */ if (stream_compression_algorithm != GRPC_STREAM_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, - &calld->stream_compression_algorithm_storage, + initial_metadata, &calld->stream_compression_algorithm_storage, grpc_stream_compression_encoding_mdelem(stream_compression_algorithm)); } else if (calld->compression_algorithm != GRPC_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, &calld->compression_algorithm_storage, + initial_metadata, &calld->compression_algorithm_storage, grpc_compression_encoding_mdelem(calld->compression_algorithm)); } @@ -194,7 +192,7 @@ static grpc_error* process_send_initial_metadata( /* convey supported compression algorithms */ error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, &calld->accept_encoding_storage, + initial_metadata, &calld->accept_encoding_storage, GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( channeld->supported_compression_algorithms)); @@ -203,7 +201,7 @@ static grpc_error* process_send_initial_metadata( /* Do not overwrite accept-encoding header if it already presents. */ if (!initial_metadata->idx.named.accept_encoding) { error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, &calld->accept_stream_encoding_storage, + initial_metadata, &calld->accept_stream_encoding_storage, GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS( channeld->supported_stream_compression_algorithms)); } @@ -211,17 +209,15 @@ static grpc_error* process_send_initial_metadata( return error; } -static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void send_message_on_complete(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &calld->slices); - GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, + grpc_slice_buffer_reset_and_unref_internal(&calld->slices); + GRPC_CLOSURE_RUN(calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } -static void send_message_batch_continue(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void send_message_batch_continue(grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; // Note: The call to grpc_call_next_op() results in yielding the // call combiner, so we need to clear calld->send_message_batch @@ -229,19 +225,18 @@ static void send_message_batch_continue(grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* send_message_batch = calld->send_message_batch; calld->send_message_batch = nullptr; - grpc_call_next_op(exec_ctx, elem, send_message_batch); + grpc_call_next_op(elem, send_message_batch); } -static void finish_send_message(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void finish_send_message(grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; // Compress the data if appropriate. grpc_slice_buffer tmp; grpc_slice_buffer_init(&tmp); uint32_t send_flags = calld->send_message_batch->payload->send_message.send_message->flags; - bool did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm, - &calld->slices, &tmp); + bool did_compress = + grpc_msg_compress(calld->compression_algorithm, &calld->slices, &tmp); if (did_compress) { if (grpc_compression_trace.enabled()) { const char* algo_name; @@ -268,11 +263,11 @@ static void finish_send_message(grpc_exec_ctx* exec_ctx, algo_name, calld->slices.length); } } - grpc_slice_buffer_destroy_internal(exec_ctx, &tmp); + grpc_slice_buffer_destroy_internal(&tmp); // Swap out the original byte stream with our new one and send the // batch down. grpc_byte_stream_destroy( - exec_ctx, calld->send_message_batch->payload->send_message.send_message); + calld->send_message_batch->payload->send_message.send_message); grpc_slice_buffer_stream_init(&calld->replacement_stream, &calld->slices, send_flags); calld->send_message_batch->payload->send_message.send_message = @@ -280,27 +275,24 @@ static void finish_send_message(grpc_exec_ctx* exec_ctx, calld->original_send_message_on_complete = calld->send_message_batch->on_complete; calld->send_message_batch->on_complete = &calld->send_message_on_complete; - send_message_batch_continue(exec_ctx, elem); + send_message_batch_continue(elem); } -static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, - void* arg, +static void fail_send_message_batch_in_call_combiner(void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; if (calld->send_message_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, calld->send_message_batch, GRPC_ERROR_REF(error), - calld->call_combiner); + calld->send_message_batch, GRPC_ERROR_REF(error), calld->call_combiner); calld->send_message_batch = nullptr; } } // Pulls a slice from the send_message byte stream and adds it to calld->slices. -static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, - call_data* calld) { +static grpc_error* pull_slice_from_send_message(call_data* calld) { grpc_slice incoming_slice; grpc_error* error = grpc_byte_stream_pull( - exec_ctx, calld->send_message_batch->payload->send_message.send_message, + calld->send_message_batch->payload->send_message.send_message, &incoming_slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&calld->slices, incoming_slice); @@ -312,69 +304,65 @@ static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, // If all data has been read, invokes finish_send_message(). Otherwise, // an async call to grpc_byte_stream_next() has been started, which will // eventually result in calling on_send_message_next_done(). -static void continue_reading_send_message(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem) { +static void continue_reading_send_message(grpc_call_element* elem) { call_data* calld = (call_data*)elem->call_data; while (grpc_byte_stream_next( - exec_ctx, calld->send_message_batch->payload->send_message.send_message, - ~(size_t)0, &calld->on_send_message_next_done)) { - grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); + calld->send_message_batch->payload->send_message.send_message, ~(size_t)0, + &calld->on_send_message_next_done)) { + grpc_error* error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); + fail_send_message_batch_in_call_combiner(calld, error); GRPC_ERROR_UNREF(error); return; } if (calld->slices.length == calld->send_message_batch->payload->send_message.send_message->length) { - finish_send_message(exec_ctx, elem); + finish_send_message(elem); break; } } } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_send_message_next_done(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); + fail_send_message_batch_in_call_combiner(calld, error); return; } - error = pull_slice_from_send_message(exec_ctx, calld); + error = pull_slice_from_send_message(calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. - fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); + fail_send_message_batch_in_call_combiner(calld, error); GRPC_ERROR_UNREF(error); return; } if (calld->slices.length == calld->send_message_batch->payload->send_message.send_message->length) { - finish_send_message(exec_ctx, elem); + finish_send_message(elem); } else { - continue_reading_send_message(exec_ctx, elem); + continue_reading_send_message(elem); } } -static void start_send_message_batch(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* unused) { +static void start_send_message_batch(void* arg, grpc_error* unused) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (skip_compression( elem, calld->send_message_batch->payload->send_message.send_message->flags, calld->send_initial_metadata_state == HAS_COMPRESSION_ALGORITHM)) { - send_message_batch_continue(exec_ctx, elem); + send_message_batch_continue(elem); } else { - continue_reading_send_message(exec_ctx, elem); + continue_reading_send_message(elem); } } static void compress_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("compress_start_transport_stream_op_batch", 0); // Handle cancel_stream. @@ -385,21 +373,19 @@ static void compress_start_transport_stream_op_batch( if (calld->send_message_batch != nullptr) { if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { GRPC_CALL_COMBINER_START( - exec_ctx, calld->call_combiner, + calld->call_combiner, GRPC_CLOSURE_CREATE(fail_send_message_batch_in_call_combiner, calld, grpc_schedule_on_exec_ctx), GRPC_ERROR_REF(calld->cancel_error), "failing send_message op"); } else { grpc_byte_stream_shutdown( - exec_ctx, calld->send_message_batch->payload->send_message.send_message, GRPC_ERROR_REF(calld->cancel_error)); } } } else if (calld->cancel_error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, batch, GRPC_ERROR_REF(calld->cancel_error), - calld->call_combiner); + batch, GRPC_ERROR_REF(calld->cancel_error), calld->call_combiner); goto done; } // Handle send_initial_metadata. @@ -407,11 +393,10 @@ static void compress_start_transport_stream_op_batch( GPR_ASSERT(calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN); bool has_compression_algorithm; grpc_error* error = process_send_initial_metadata( - exec_ctx, elem, - batch->payload->send_initial_metadata.send_initial_metadata, + elem, batch->payload->send_initial_metadata.send_initial_metadata, &has_compression_algorithm); if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, batch, error, + grpc_transport_stream_op_batch_finish_with_failure(batch, error, calld->call_combiner); goto done; } @@ -425,7 +410,7 @@ static void compress_start_transport_stream_op_batch( // the call stack) will release the call combiner for each batch it sees. if (calld->send_message_batch != nullptr) { GRPC_CALL_COMBINER_START( - exec_ctx, calld->call_combiner, + calld->call_combiner, &calld->start_send_message_batch_in_call_combiner, GRPC_ERROR_NONE, "starting send_message after send_initial_metadata"); } @@ -440,22 +425,21 @@ static void compress_start_transport_stream_op_batch( // send_initial_metadata. if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { GRPC_CALL_COMBINER_STOP( - exec_ctx, calld->call_combiner, + calld->call_combiner, "send_message batch pending send_initial_metadata"); goto done; } - start_send_message_batch(exec_ctx, elem, GRPC_ERROR_NONE); + start_send_message_batch(elem, GRPC_ERROR_NONE); } else { // Pass control down the stack. - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); } done: GPR_TIMER_END("compress_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; @@ -471,17 +455,16 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices); + grpc_slice_buffer_destroy_internal(&calld->slices); GRPC_ERROR_UNREF(calld->cancel_error); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* channeld = (channel_data*)elem->channel_data; @@ -531,8 +514,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} const grpc_channel_filter grpc_message_compress_filter = { compress_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 4f3897915c..b872dc98f5 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -66,8 +66,7 @@ typedef struct channel_data { uint8_t unused; } channel_data; -static grpc_error* server_filter_outgoing_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* server_filter_outgoing_metadata(grpc_call_element* elem, grpc_metadata_batch* b) { if (b->idx.named.grpc_message != nullptr) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( @@ -75,10 +74,9 @@ static grpc_error* server_filter_outgoing_metadata(grpc_exec_ctx* exec_ctx, grpc_compatible_percent_encoding_unreserved_bytes); if (grpc_slice_is_equivalent(pct_encoded_msg, GRPC_MDVALUE(b->idx.named.grpc_message->md))) { - grpc_slice_unref_internal(exec_ctx, pct_encoded_msg); + grpc_slice_unref_internal(pct_encoded_msg); } else { - grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, - pct_encoded_msg); + grpc_metadata_batch_set_value(b->idx.named.grpc_message, pct_encoded_msg); } } return GRPC_ERROR_NONE; @@ -93,8 +91,7 @@ static void add_error(const char* error_name, grpc_error** cumulative, *cumulative = grpc_error_add_child(*cumulative, new_err); } -static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* server_filter_incoming_metadata(grpc_call_element* elem, grpc_metadata_batch* b) { call_data* calld = (call_data*)elem->call_data; grpc_error* error = GRPC_ERROR_NONE; @@ -123,7 +120,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.method->md)); } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.method); + grpc_metadata_batch_remove(b, b->idx.named.method); } else { add_error( error_name, &error, @@ -139,7 +136,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.te->md)); } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.te); + grpc_metadata_batch_remove(b, b->idx.named.te); } else { add_error(error_name, &error, grpc_error_set_str( @@ -156,7 +153,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad header"), b->idx.named.scheme->md)); } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.scheme); + grpc_metadata_batch_remove(b, b->idx.named.scheme); } else { add_error( error_name, &error, @@ -191,7 +188,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, gpr_free(val); } } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); + grpc_metadata_batch_remove(b, b->idx.named.content_type); } if (b->idx.named.path == nullptr) { @@ -218,22 +215,21 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, /* substitute path metadata with just the path (not query) */ grpc_mdelem mdelem_path_without_query = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_PATH, grpc_slice_sub(path_slice, 0, offset)); + GRPC_MDSTR_PATH, grpc_slice_sub(path_slice, 0, offset)); - grpc_metadata_batch_substitute(exec_ctx, b, b->idx.named.path, + grpc_metadata_batch_substitute(b, b->idx.named.path, mdelem_path_without_query); /* decode payload from query and add to the slice buffer to be returned */ const int k_url_safe = 1; - grpc_slice_buffer_add( - &calld->read_slice_buffer, - grpc_base64_decode_with_len( - exec_ctx, (const char*)GRPC_SLICE_START_PTR(query_slice), - GRPC_SLICE_LENGTH(query_slice), k_url_safe)); + grpc_slice_buffer_add(&calld->read_slice_buffer, + grpc_base64_decode_with_len( + (const char*)GRPC_SLICE_START_PTR(query_slice), + GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); calld->seen_path_with_query = true; - grpc_slice_unref_internal(exec_ctx, query_slice); + grpc_slice_unref_internal(query_slice); } else { gpr_log(GPR_ERROR, "GET request without QUERY"); } @@ -242,14 +238,14 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, if (b->idx.named.host != nullptr && b->idx.named.authority == nullptr) { grpc_linked_mdelem* el = b->idx.named.host; grpc_mdelem md = GRPC_MDELEM_REF(el->md); - grpc_metadata_batch_remove(exec_ctx, b, el); + grpc_metadata_batch_remove(b, el); add_error(error_name, &error, grpc_metadata_batch_add_head( - exec_ctx, b, el, + b, el, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, + GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(GRPC_MDVALUE(md))))); - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } if (b->idx.named.authority == nullptr) { @@ -263,21 +259,18 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, return error; } -static void hs_on_recv(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* err) { +static void hs_on_recv(void* user_data, grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (err == GRPC_ERROR_NONE) { - err = server_filter_incoming_metadata(exec_ctx, elem, - calld->recv_initial_metadata); + err = server_filter_incoming_metadata(elem, calld->recv_initial_metadata); } else { GRPC_ERROR_REF(err); } - GRPC_CLOSURE_RUN(exec_ctx, calld->on_done_recv, err); + GRPC_CLOSURE_RUN(calld->on_done_recv, err); } -static void hs_on_complete(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* err) { +static void hs_on_complete(void* user_data, grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; /* Call recv_message_ready if we got the payload via the path field */ @@ -287,17 +280,16 @@ static void hs_on_complete(grpc_exec_ctx* exec_ctx, void* user_data, : (grpc_byte_stream*)&calld->read_stream; // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. - GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, - calld->recv_message_ready, GRPC_ERROR_REF(err), + GRPC_CALL_COMBINER_START(calld->call_combiner, calld->recv_message_ready, + GRPC_ERROR_REF(err), "resuming recv_message_ready from on_complete"); calld->recv_message_ready = nullptr; calld->payload_bin_delivered = true; } - GRPC_CLOSURE_RUN(exec_ctx, calld->on_complete, GRPC_ERROR_REF(err)); + GRPC_CLOSURE_RUN(calld->on_complete, GRPC_ERROR_REF(err)); } -static void hs_recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* err) { +static void hs_recv_message_ready(void* user_data, grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (calld->seen_path_with_query) { @@ -305,15 +297,14 @@ static void hs_recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, // returned in hs_on_complete callback. // Note that we release the call combiner here, so that other // callbacks can run. - GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, + GRPC_CALL_COMBINER_STOP(calld->call_combiner, "pausing recv_message_ready until on_complete"); } else { - GRPC_CLOSURE_RUN(exec_ctx, calld->recv_message_ready, GRPC_ERROR_REF(err)); + GRPC_CLOSURE_RUN(calld->recv_message_ready, GRPC_ERROR_REF(err)); } } -static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* hs_mutate_op(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { /* grab pointers to our data from the call element */ call_data* calld = (call_data*)elem->call_data; @@ -321,21 +312,19 @@ static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, if (op->send_initial_metadata) { grpc_error* error = GRPC_ERROR_NONE; static const char* error_name = "Failed sending initial metadata"; + add_error(error_name, &error, + grpc_metadata_batch_add_head( + op->payload->send_initial_metadata.send_initial_metadata, + &calld->status, GRPC_MDELEM_STATUS_200)); + add_error(error_name, &error, + grpc_metadata_batch_add_tail( + op->payload->send_initial_metadata.send_initial_metadata, + &calld->content_type, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); add_error( error_name, &error, - grpc_metadata_batch_add_head( - exec_ctx, op->payload->send_initial_metadata.send_initial_metadata, - &calld->status, GRPC_MDELEM_STATUS_200)); - add_error( - error_name, &error, - grpc_metadata_batch_add_tail( - exec_ctx, op->payload->send_initial_metadata.send_initial_metadata, - &calld->content_type, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); - add_error(error_name, &error, - server_filter_outgoing_metadata( - exec_ctx, elem, - op->payload->send_initial_metadata.send_initial_metadata)); + server_filter_outgoing_metadata( + elem, op->payload->send_initial_metadata.send_initial_metadata)); if (error != GRPC_ERROR_NONE) return error; } @@ -367,8 +356,7 @@ static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, if (op->send_trailing_metadata) { grpc_error* error = server_filter_outgoing_metadata( - exec_ctx, elem, - op->payload->send_trailing_metadata.send_trailing_metadata); + elem, op->payload->send_trailing_metadata.send_trailing_metadata); if (error != GRPC_ERROR_NONE) return error; } @@ -376,23 +364,21 @@ static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, } static void hs_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("hs_start_transport_stream_op_batch", 0); - grpc_error* error = hs_mutate_op(exec_ctx, elem, op); + grpc_error* error = hs_mutate_op(elem, op); if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, op, error, + grpc_transport_stream_op_batch_finish_with_failure(op, error, calld->call_combiner); } else { - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } GPR_TIMER_END("hs_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { /* grab pointers to our data from the call element */ call_data* calld = (call_data*)elem->call_data; @@ -409,24 +395,22 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_slice_buffer_destroy_internal(exec_ctx, &calld->read_slice_buffer); + grpc_slice_buffer_destroy_internal(&calld->read_slice_buffer); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} const grpc_channel_filter grpc_http_server_filter = { hs_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index 762198f034..f50a928fcd 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -54,8 +54,7 @@ typedef struct channel_data { intptr_t id; /**< an id unique to the channel */ } channel_data; -static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* err) { +static void on_initial_md_ready(void* user_data, grpc_error* err) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -73,20 +72,19 @@ static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); calld->have_initial_md_string = true; grpc_metadata_batch_remove( - exec_ctx, calld->recv_initial_metadata, + calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.lb_token); } } else { GRPC_ERROR_REF(err); } calld->ops_recv_initial_metadata_ready->cb( - exec_ctx, calld->ops_recv_initial_metadata_ready->cb_arg, err); + calld->ops_recv_initial_metadata_ready->cb_arg, err); GRPC_ERROR_UNREF(err); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->id = (intptr_t)args->call_stack; @@ -108,7 +106,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; @@ -125,19 +123,18 @@ static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, */ if (calld->have_initial_md_string) { - grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); + grpc_slice_unref_internal(calld->initial_md_string); } if (calld->have_trailing_md_string) { - grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); + grpc_slice_unref_internal(calld->trailing_md_string); } if (calld->have_service_method) { - grpc_slice_unref_internal(exec_ctx, calld->service_method); + grpc_slice_unref_internal(calld->service_method); } } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); @@ -158,8 +155,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { /* TODO(dgq): do something with the data channel_data *chand = elem->channel_data; grpc_load_reporting_call_data lr_call_data = { @@ -173,8 +169,7 @@ static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, */ } -static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx* exec_ctx, - void* user_data, +static grpc_filtered_mdelem lr_trailing_md_filter(void* user_data, grpc_mdelem md) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -186,8 +181,7 @@ static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx* exec_ctx, } static void lr_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { GPR_TIMER_BEGIN("lr_start_transport_stream_op_batch", 0); call_data* calld = (call_data*)elem->call_data; @@ -203,12 +197,11 @@ static void lr_start_transport_stream_op_batch( GRPC_LOG_IF_ERROR( "grpc_metadata_batch_filter", grpc_metadata_batch_filter( - exec_ctx, op->payload->send_trailing_metadata.send_trailing_metadata, lr_trailing_md_filter, elem, "LR trailing metadata filtering error")); } - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); GPR_TIMER_END("lr_start_transport_stream_op_batch", 0); } diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index accb7797dd..9d1dfcbb4c 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -38,7 +38,7 @@ static bool is_load_reporting_enabled(const grpc_channel_args* a) { } static bool maybe_add_server_load_reporting_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_channel_filter* filter = (const grpc_channel_filter*)arg; diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 917fbd9198..0499c6ecfc 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -88,73 +88,69 @@ typedef struct channel_data { /* Increase the nubmer of active calls. Before the increasement, if there are no calls, the max_idle_timer should be cancelled. */ -static void increase_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) { +static void increase_call_count(channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, 1) == 0) { - grpc_timer_cancel(exec_ctx, &chand->max_idle_timer); + grpc_timer_cancel(&chand->max_idle_timer); } } /* Decrease the nubmer of active calls. After the decrement, if there are no calls, the max_idle_timer should be started. */ -static void decrease_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) { +static void decrease_call_count(channel_data* chand) { if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer"); - grpc_timer_init(exec_ctx, &chand->max_idle_timer, - grpc_exec_ctx_now(exec_ctx) + chand->max_connection_idle, - &chand->close_max_idle_channel); + grpc_timer_init( + &chand->max_idle_timer, + grpc_core::ExecCtx::Get()->Now() + chand->max_connection_idle, + &chand->close_max_idle_channel); } } -static void start_max_idle_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; /* Decrease call_count. If there are no active calls at this time, max_idle_timer will start here. If the number of active calls is not 0, max_idle_timer will start after all the active calls end. */ - decrease_call_count(exec_ctx, chand); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + decrease_call_count(chand); + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_idle_timer_after_init"); } -static void start_max_age_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void start_max_age_timer_after_init(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); - grpc_timer_init(exec_ctx, &chand->max_age_timer, - grpc_exec_ctx_now(exec_ctx) + chand->max_connection_age, + grpc_timer_init(&chand->max_age_timer, + grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(exec_ctx, - grpc_channel_stack_element(chand->channel_stack, 0), op); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), op); + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_age_timer_after_init"); } -static void start_max_age_grace_timer_after_goaway_op(grpc_exec_ctx* exec_ctx, - void* arg, +static void start_max_age_grace_timer_after_goaway_op(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = true; GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); grpc_timer_init( - exec_ctx, &chand->max_age_grace_timer, + &chand->max_age_grace_timer, chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE ? GRPC_MILLIS_INF_FUTURE - : grpc_exec_ctx_now(exec_ctx) + chand->max_connection_age_grace, + : grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age_grace, &chand->force_close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_age_grace_timer_after_goaway_op"); } -static void close_max_idle_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void close_max_idle_channel(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; if (error == GRPC_ERROR_NONE) { /* Prevent the max idle timer from being set again */ @@ -165,16 +161,14 @@ static void close_max_idle_channel(grpc_exec_ctx* exec_ctx, void* arg, GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("close_max_idle_channel", error); } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, - "max_age max_idle_timer"); + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_idle_timer"); } -static void close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void close_max_age_channel(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_timer_pending = false; @@ -189,16 +183,14 @@ static void close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("close_max_age_channel", error); } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, - "max_age max_age_timer"); + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_timer"); } -static void force_close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void force_close_max_age_channel(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; gpr_mu_lock(&chand->max_age_timer_mu); chand->max_age_grace_timer_pending = false; @@ -209,38 +201,36 @@ static void force_close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel reaches max age"); grpc_channel_element* elem = grpc_channel_stack_element(chand->channel_stack, 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } else if (error != GRPC_ERROR_CANCELLED) { GRPC_LOG_IF_ERROR("force_close_max_age_channel", error); } - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack, - "max_age max_age_grace_timer"); + GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_grace_timer"); } -static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void channel_connectivity_changed(void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op( - exec_ctx, grpc_channel_stack_element(chand->channel_stack, 0), op); + grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), + op); } else { gpr_mu_lock(&chand->max_age_timer_mu); if (chand->max_age_timer_pending) { - grpc_timer_cancel(exec_ctx, &chand->max_age_timer); + grpc_timer_cancel(&chand->max_age_timer); chand->max_age_timer_pending = false; } if (chand->max_age_grace_timer_pending) { - grpc_timer_cancel(exec_ctx, &chand->max_age_grace_timer); + grpc_timer_cancel(&chand->max_age_grace_timer); chand->max_age_grace_timer_pending = false; } gpr_mu_unlock(&chand->max_age_timer_mu); /* If there are no active calls, this increasement will cancel max_idle_timer, and prevent max_idle_timer from being started in the future. */ - increase_call_count(exec_ctx, chand); + increase_call_count(chand); } } @@ -263,25 +253,23 @@ add_random_max_connection_age_jitter_and_convert_to_grpc_millis(int value) { } /* Constructor for call_data. */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; - increase_call_count(exec_ctx, chand); + increase_call_count(chand); return GRPC_ERROR_NONE; } /* Destructor for call_data. */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { channel_data* chand = (channel_data*)elem->channel_data; - decrease_call_count(exec_ctx, chand); + decrease_call_count(chand); } /* Constructor for channel_data. */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_init(&chand->max_age_timer_mu); @@ -351,8 +339,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, initialization is done. */ GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age start_max_age_timer_after_init"); - GRPC_CLOSURE_SCHED(exec_ctx, &chand->start_max_age_timer_after_init, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&chand->start_max_age_timer_after_init, GRPC_ERROR_NONE); } /* Initialize the number of calls as 1, so that the max_idle_timer will not @@ -361,15 +348,14 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, if (chand->max_connection_idle != GRPC_MILLIS_INF_FUTURE) { GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age start_max_idle_timer_after_init"); - GRPC_CLOSURE_SCHED(exec_ctx, &chand->start_max_idle_timer_after_init, + GRPC_CLOSURE_SCHED(&chand->start_max_idle_timer_after_init, GRPC_ERROR_NONE); } return GRPC_ERROR_NONE; } /* Destructor for channel_data. */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} const grpc_channel_filter grpc_max_age_filter = { grpc_call_next_op, @@ -384,8 +370,7 @@ const grpc_channel_filter grpc_max_age_filter = { grpc_channel_next_get_info, "max_age"}; -static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index 3d2252af2e..f8487f9a9e 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -47,8 +47,7 @@ static void* refcounted_message_size_limits_ref(void* value) { return value; } -static void refcounted_message_size_limits_unref(grpc_exec_ctx* exec_ctx, - void* value) { +static void refcounted_message_size_limits_unref(void* value) { refcounted_message_size_limits* limits = (refcounted_message_size_limits*)value; if (gpr_unref(&limits->refs)) { @@ -108,8 +107,7 @@ typedef struct channel_data { // Callback invoked when we receive a message. Here we check the max // receive message size. -static void recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void recv_message_ready(void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; if (*calld->recv_message != nullptr && calld->limits.max_recv_size >= 0 && @@ -132,13 +130,12 @@ static void recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, GRPC_ERROR_REF(error); } // Invoke the next callback. - GRPC_CLOSURE_RUN(exec_ctx, calld->next_recv_message_ready, error); + GRPC_CLOSURE_RUN(calld->next_recv_message_ready, error); } // Start transport stream op. static void start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; // Check max send message size. if (op->send_message && calld->limits.max_send_size >= 0 && @@ -149,7 +146,7 @@ static void start_transport_stream_op_batch( op->payload->send_message.send_message->length, calld->limits.max_send_size); grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, op, + op, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(message_string), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED), @@ -165,12 +162,11 @@ static void start_transport_stream_op_batch( op->payload->recv_message.recv_message_ready = &calld->recv_message_ready; } // Chain to the next filter. - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } // Constructor for call_data. -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -186,7 +182,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, if (chand->method_limit_table != nullptr) { refcounted_message_size_limits* limits = (refcounted_message_size_limits*)grpc_method_config_table_get( - exec_ctx, chand->method_limit_table, args->path); + chand->method_limit_table, args->path); if (limits != nullptr) { if (limits->limits.max_send_size >= 0 && (limits->limits.max_send_size < calld->limits.max_send_size || @@ -204,7 +200,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } // Destructor for call_data. -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} @@ -241,8 +237,7 @@ message_size_limits get_message_size_limits( } // Constructor for channel_data. -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); channel_data* chand = (channel_data*)elem->channel_data; @@ -257,8 +252,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, if (service_config != nullptr) { chand->method_limit_table = grpc_service_config_create_method_config_table( - exec_ctx, service_config, - refcounted_message_size_limits_create_from_json, + service_config, refcounted_message_size_limits_create_from_json, refcounted_message_size_limits_ref, refcounted_message_size_limits_unref); grpc_service_config_destroy(service_config); @@ -268,10 +262,9 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } // Destructor for channel_data. -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - grpc_slice_hash_table_unref(exec_ctx, chand->method_limit_table); + grpc_slice_hash_table_unref(chand->method_limit_table); } const grpc_channel_filter grpc_message_size_filter = { @@ -287,8 +280,7 @@ const grpc_channel_filter grpc_message_size_filter = { grpc_channel_next_get_info, "message_size"}; -static bool maybe_add_message_size_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); diff --git a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc index 4ab1ee4e79..555a9134a2 100644 --- a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +++ b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc @@ -50,8 +50,7 @@ static bool get_user_agent_mdelem(const grpc_metadata_batch* batch, } // Callback invoked when we receive an initial metadata. -static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, - void* user_data, grpc_error* error) { +static void recv_initial_metadata_ready(void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -67,14 +66,13 @@ static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, } // Invoke the next callback. - GRPC_CLOSURE_RUN(exec_ctx, calld->next_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(calld->next_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } // Start transport stream op. static void start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; // Inject callback for receiving initial metadata @@ -96,12 +94,11 @@ static void start_transport_stream_op_batch( } // Chain to the next filter. - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } // Constructor for call_data. -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->next_recv_initial_metadata_ready = nullptr; @@ -113,20 +110,18 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } // Destructor for call_data. -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} // Constructor for channel_data. -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } // Destructor for channel_data. -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} // Parse the user agent static bool parse_user_agent(grpc_mdelem md) { @@ -181,7 +176,7 @@ const grpc_channel_filter grpc_workaround_cronet_compression_filter = { "workaround_cronet_compression"}; static bool register_workaround_cronet_compression( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* a = grpc_channel_args_find( diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 819f66aec3..db5962e7fd 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -61,38 +61,34 @@ static void chttp2_connector_ref(grpc_connector* con) { gpr_ref(&c->refs); } -static void chttp2_connector_unref(grpc_exec_ctx* exec_ctx, - grpc_connector* con) { +static void chttp2_connector_unref(grpc_connector* con) { chttp2_connector* c = (chttp2_connector*)con; if (gpr_unref(&c->refs)) { gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. // Otherwise, the handshaker will do this for us. - if (c->endpoint != nullptr) grpc_endpoint_destroy(exec_ctx, c->endpoint); + if (c->endpoint != nullptr) grpc_endpoint_destroy(c->endpoint); gpr_free(c); } } -static void chttp2_connector_shutdown(grpc_exec_ctx* exec_ctx, - grpc_connector* con, grpc_error* why) { +static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { chttp2_connector* c = (chttp2_connector*)con; gpr_mu_lock(&c->mu); c->shutdown = true; if (c->handshake_mgr != nullptr) { - grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr, - GRPC_ERROR_REF(why)); + grpc_handshake_manager_shutdown(c->handshake_mgr, GRPC_ERROR_REF(why)); } // If handshaking is not yet in progress, shutdown the endpoint. // Otherwise, the handshaker will do this for us. if (!c->connecting && c->endpoint != nullptr) { - grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(why)); + grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(why)); } gpr_mu_unlock(&c->mu); GRPC_ERROR_UNREF(why); } -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; chttp2_connector* c = (chttp2_connector*)args->user_data; gpr_mu_lock(&c->mu); @@ -105,20 +101,20 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(exec_ctx, args->endpoint, GRPC_ERROR_REF(error)); - grpc_endpoint_destroy(exec_ctx, args->endpoint); - grpc_channel_args_destroy(exec_ctx, args->args); - grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); + grpc_endpoint_shutdown(args->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_destroy(args->endpoint); + grpc_channel_args_destroy(args->args); + grpc_slice_buffer_destroy_internal(args->read_buffer); gpr_free(args->read_buffer); } else { error = GRPC_ERROR_REF(error); } memset(c->result, 0, sizeof(*c->result)); } else { - grpc_endpoint_delete_from_pollset_set(exec_ctx, args->endpoint, + grpc_endpoint_delete_from_pollset_set(args->endpoint, c->args.interested_parties); - c->result->transport = grpc_create_chttp2_transport(exec_ctx, args->args, - args->endpoint, true); + c->result->transport = + grpc_create_chttp2_transport(args->args, args->endpoint, true); GPR_ASSERT(c->result->transport); // TODO(roth): We ideally want to wait until we receive HTTP/2 // settings from the server before we consider the connection @@ -144,34 +140,32 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, // so until after transparent retries is implemented. Otherwise, any // RPC that we attempt to send on the connection before the timeout // would fail instead of being retried on a subsequent attempt. - grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, - args->read_buffer, nullptr); + grpc_chttp2_transport_start_reading(c->result->transport, args->read_buffer, + nullptr); c->result->channel_args = args->args; } grpc_closure* notify = c->notify; c->notify = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, notify, error); - grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); + GRPC_CLOSURE_SCHED(notify, error); + grpc_handshake_manager_destroy(c->handshake_mgr); c->handshake_mgr = nullptr; gpr_mu_unlock(&c->mu); - chttp2_connector_unref(exec_ctx, (grpc_connector*)c); + chttp2_connector_unref((grpc_connector*)c); } -static void start_handshake_locked(grpc_exec_ctx* exec_ctx, - chttp2_connector* c) { +static void start_handshake_locked(chttp2_connector* c) { c->handshake_mgr = grpc_handshake_manager_create(); - grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, c->args.channel_args, + grpc_handshakers_add(HANDSHAKER_CLIENT, c->args.channel_args, c->handshake_mgr); - grpc_endpoint_add_to_pollset_set(exec_ctx, c->endpoint, - c->args.interested_parties); + grpc_endpoint_add_to_pollset_set(c->endpoint, c->args.interested_parties); grpc_handshake_manager_do_handshake( - exec_ctx, c->handshake_mgr, c->args.interested_parties, c->endpoint, + c->handshake_mgr, c->args.interested_parties, c->endpoint, c->args.channel_args, c->args.deadline, nullptr /* acceptor */, on_handshake_done, c); c->endpoint = nullptr; // Endpoint handed off to handshake manager. } -static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void connected(void* arg, grpc_error* error) { chttp2_connector* c = (chttp2_connector*)arg; gpr_mu_lock(&c->mu); GPR_ASSERT(c->connecting); @@ -185,27 +179,26 @@ static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { memset(c->result, 0, sizeof(*c->result)); grpc_closure* notify = c->notify; c->notify = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, notify, error); + GRPC_CLOSURE_SCHED(notify, error); if (c->endpoint != nullptr) { - grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); - chttp2_connector_unref(exec_ctx, (grpc_connector*)arg); + chttp2_connector_unref((grpc_connector*)arg); } else { GPR_ASSERT(c->endpoint != nullptr); - start_handshake_locked(exec_ctx, c); + start_handshake_locked(c); gpr_mu_unlock(&c->mu); } } -static void chttp2_connector_connect(grpc_exec_ctx* exec_ctx, - grpc_connector* con, +static void chttp2_connector_connect(grpc_connector* con, const grpc_connect_in_args* args, grpc_connect_out_args* result, grpc_closure* notify) { chttp2_connector* c = (chttp2_connector*)con; grpc_resolved_address addr; - grpc_get_subchannel_address_arg(exec_ctx, args->channel_args, &addr); + grpc_get_subchannel_address_arg(args->channel_args, &addr); gpr_mu_lock(&c->mu); GPR_ASSERT(c->notify == nullptr); c->notify = notify; @@ -216,9 +209,8 @@ static void chttp2_connector_connect(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&c->connected, connected, c, grpc_schedule_on_exec_ctx); GPR_ASSERT(!c->connecting); c->connecting = true; - grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint, - args->interested_parties, args->channel_args, &addr, - args->deadline); + grpc_tcp_client_connect(&c->connected, &c->endpoint, args->interested_parties, + args->channel_args, &addr, args->deadline); gpr_mu_unlock(&c->mu); } diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 028b69e5ff..6a1b70964d 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -34,21 +34,19 @@ static void client_channel_factory_ref( grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} + grpc_client_channel_factory* cc_factory) {} static grpc_subchannel* client_channel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, - const grpc_subchannel_args* args) { + grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { grpc_connector* connector = grpc_chttp2_connector_create(); - grpc_subchannel* s = grpc_subchannel_create(exec_ctx, connector, args); - grpc_connector_unref(exec_ctx, connector); + grpc_subchannel* s = grpc_subchannel_create(connector, args); + grpc_connector_unref(connector); return s; } static grpc_channel* client_channel_factory_create_channel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, - const char* target, grpc_client_channel_type type, - const grpc_channel_args* args) { + grpc_client_channel_factory* cc_factory, const char* target, + grpc_client_channel_type type, const grpc_channel_args* args) { if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return nullptr; @@ -56,14 +54,14 @@ static grpc_channel* client_channel_factory_create_channel( // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); + grpc_resolver_factory_add_default_prefix_if_needed(target)); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); - grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, - GRPC_CLIENT_CHANNEL, nullptr); - grpc_channel_args_destroy(exec_ctx, new_args); + grpc_channel* channel = + grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); + grpc_channel_args_destroy(new_args); return channel; } @@ -82,7 +80,7 @@ static grpc_client_channel_factory client_channel_factory = { grpc_channel* grpc_insecure_channel_create(const char* target, const grpc_channel_args* args, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); @@ -93,11 +91,11 @@ grpc_channel* grpc_insecure_channel_create(const char* target, grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); // Create channel. grpc_channel* channel = client_channel_factory_create_channel( - &exec_ctx, &client_channel_factory, target, - GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); + &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, + new_args); // Clean up. - grpc_channel_args_destroy(&exec_ctx, new_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(new_args); + return channel != nullptr ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index c6b149d0b1..0cdea5a94e 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -37,7 +37,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, (target, fd, args)); @@ -50,17 +50,17 @@ grpc_channel* grpc_insecure_channel_create_from_fd( GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); grpc_endpoint* client = grpc_tcp_client_create_from_fd( - &exec_ctx, grpc_fd_create(fd, "client"), args, "fd-client"); + grpc_fd_create(fd, "client"), args, "fd-client"); grpc_transport* transport = - grpc_create_chttp2_transport(&exec_ctx, final_args, client, true); + grpc_create_chttp2_transport(final_args, client, true); GPR_ASSERT(transport); grpc_channel* channel = grpc_channel_create( - &exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_channel_args_destroy(&exec_ctx, final_args); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_channel_args_destroy(final_args); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); return channel != nullptr ? channel : grpc_lame_client_channel_create( @@ -73,7 +73,7 @@ grpc_channel* grpc_insecure_channel_create_from_fd( grpc_channel* grpc_insecure_channel_create_from_fd( const char* target, int fd, const grpc_channel_args* args) { GPR_ASSERT(0); - return NULL; + return nullptr; } #endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index dd2bc427a7..27c5b96a4c 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -41,10 +41,10 @@ static void client_channel_factory_ref( grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} + grpc_client_channel_factory* cc_factory) {} static grpc_subchannel_args* get_secure_naming_subchannel_args( - grpc_exec_ctx* exec_ctx, const grpc_subchannel_args* args) { + const grpc_subchannel_args* args) { grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args->args); if (channel_credentials == nullptr) { @@ -68,7 +68,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* server_uri_str = server_uri_arg->value.string; GPR_ASSERT(server_uri_str != nullptr); grpc_uri* server_uri = - grpc_uri_parse(exec_ctx, server_uri_str, true /* supress errors */); + grpc_uri_parse(server_uri_str, true /* supress errors */); GPR_ASSERT(server_uri != nullptr); const char* server_uri_path; server_uri_path = @@ -81,7 +81,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* target_uri_str = grpc_get_subchannel_address_uri_arg(args->args); grpc_uri* target_uri = - grpc_uri_parse(exec_ctx, target_uri_str, false /* suppress errors */); + grpc_uri_parse(target_uri_str, false /* suppress errors */); GPR_ASSERT(target_uri != nullptr); if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( @@ -89,7 +89,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* value = (const char*)grpc_slice_hash_table_get(targets_info, key); if (value != nullptr) target_name_to_check = gpr_strdup(value); - grpc_slice_unref_internal(exec_ctx, key); + grpc_slice_unref_internal(key); } if (target_name_to_check == nullptr) { // If the target name to check hasn't already been set, fall back to using @@ -107,7 +107,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args* new_args_from_connector = nullptr; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( - exec_ctx, channel_credentials, target_name_to_check, args->args, + channel_credentials, target_name_to_check, args->args, &subchannel_security_connector, &new_args_from_connector); if (security_status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, @@ -123,10 +123,10 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args* new_args = grpc_channel_args_copy_and_add( new_args_from_connector != nullptr ? new_args_from_connector : args->args, &new_security_connector_arg, 1); - GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &subchannel_security_connector->base, + GRPC_SECURITY_CONNECTOR_UNREF(&subchannel_security_connector->base, "lb_channel_create"); if (new_args_from_connector != nullptr) { - grpc_channel_args_destroy(exec_ctx, new_args_from_connector); + grpc_channel_args_destroy(new_args_from_connector); } grpc_subchannel_args* final_sc_args = (grpc_subchannel_args*)gpr_malloc(sizeof(*final_sc_args)); @@ -136,10 +136,9 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( } static grpc_subchannel* client_channel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, - const grpc_subchannel_args* args) { + grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { grpc_subchannel_args* subchannel_args = - get_secure_naming_subchannel_args(exec_ctx, args); + get_secure_naming_subchannel_args(args); if (subchannel_args == nullptr) { gpr_log( GPR_ERROR, @@ -147,19 +146,16 @@ static grpc_subchannel* client_channel_factory_create_subchannel( return nullptr; } grpc_connector* connector = grpc_chttp2_connector_create(); - grpc_subchannel* s = - grpc_subchannel_create(exec_ctx, connector, subchannel_args); - grpc_connector_unref(exec_ctx, connector); - grpc_channel_args_destroy(exec_ctx, - (grpc_channel_args*)subchannel_args->args); + grpc_subchannel* s = grpc_subchannel_create(connector, subchannel_args); + grpc_connector_unref(connector); + grpc_channel_args_destroy((grpc_channel_args*)subchannel_args->args); gpr_free(subchannel_args); return s; } static grpc_channel* client_channel_factory_create_channel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, - const char* target, grpc_client_channel_type type, - const grpc_channel_args* args) { + grpc_client_channel_factory* cc_factory, const char* target, + grpc_client_channel_type type, const grpc_channel_args* args) { if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return nullptr; @@ -167,14 +163,14 @@ static grpc_channel* client_channel_factory_create_channel( // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); + grpc_resolver_factory_add_default_prefix_if_needed(target)); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); - grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, - GRPC_CLIENT_CHANNEL, nullptr); - grpc_channel_args_destroy(exec_ctx, new_args); + grpc_channel* channel = + grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); + grpc_channel_args_destroy(new_args); return channel; } @@ -194,7 +190,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, const char* target, const grpc_channel_args* args, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", @@ -211,11 +207,10 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, args, args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Create channel. channel = client_channel_factory_create_channel( - &exec_ctx, &client_channel_factory, target, - GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); + &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, + new_args); // Clean up. - grpc_channel_args_destroy(&exec_ctx, new_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(new_args); } return channel != nullptr ? channel : grpc_lame_client_channel_create( diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 49ee677464..5669fa4090 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -69,17 +69,17 @@ typedef struct { } server_connection_state; static void server_connection_state_unref( - grpc_exec_ctx* exec_ctx, server_connection_state* connection_state) { + server_connection_state* connection_state) { if (gpr_unref(&connection_state->refs)) { if (connection_state->transport != nullptr) { - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, connection_state->transport, + GRPC_CHTTP2_UNREF_TRANSPORT(connection_state->transport, "receive settings timeout"); } gpr_free(connection_state); } } -static void on_timeout(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_timeout(void* arg, grpc_error* error) { server_connection_state* connection_state = (server_connection_state*)arg; // Note that we may be called with GRPC_ERROR_NONE when the timer fires // or with an error indicating that the timer system is being shut down. @@ -87,22 +87,20 @@ static void on_timeout(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Did not receive HTTP/2 settings before handshake timeout"); - grpc_transport_perform_op(exec_ctx, &connection_state->transport->base, op); + grpc_transport_perform_op(&connection_state->transport->base, op); } - server_connection_state_unref(exec_ctx, connection_state); + server_connection_state_unref(connection_state); } -static void on_receive_settings(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_receive_settings(void* arg, grpc_error* error) { server_connection_state* connection_state = (server_connection_state*)arg; if (error == GRPC_ERROR_NONE) { - grpc_timer_cancel(exec_ctx, &connection_state->timer); + grpc_timer_cancel(&connection_state->timer); } - server_connection_state_unref(exec_ctx, connection_state); + server_connection_state_unref(connection_state); } -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; server_connection_state* connection_state = (server_connection_state*)args->user_data; @@ -117,10 +115,10 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(exec_ctx, args->endpoint, GRPC_ERROR_NONE); - grpc_endpoint_destroy(exec_ctx, args->endpoint); - grpc_channel_args_destroy(exec_ctx, args->args); - grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); + grpc_endpoint_shutdown(args->endpoint, GRPC_ERROR_NONE); + grpc_endpoint_destroy(args->endpoint); + grpc_channel_args_destroy(args->args); + grpc_slice_buffer_destroy_internal(args->read_buffer); gpr_free(args->read_buffer); } } else { @@ -128,10 +126,10 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, // handshaker may have handed off the connection to some external // code, so we can just clean up here without creating a transport. if (args->endpoint != nullptr) { - grpc_transport* transport = grpc_create_chttp2_transport( - exec_ctx, args->args, args->endpoint, false); + grpc_transport* transport = + grpc_create_chttp2_transport(args->args, args->endpoint, false); grpc_server_setup_transport( - exec_ctx, connection_state->svr_state->server, transport, + connection_state->svr_state->server, transport, connection_state->accepting_pollset, args->args); // Use notify_on_receive_settings callback to enforce the // handshake deadline. @@ -141,16 +139,14 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, on_receive_settings, connection_state, grpc_schedule_on_exec_ctx); grpc_chttp2_transport_start_reading( - exec_ctx, transport, args->read_buffer, - &connection_state->on_receive_settings); - grpc_channel_args_destroy(exec_ctx, args->args); + transport, args->read_buffer, &connection_state->on_receive_settings); + grpc_channel_args_destroy(args->args); gpr_ref(&connection_state->refs); GRPC_CHTTP2_REF_TRANSPORT((grpc_chttp2_transport*)transport, "receive settings timeout"); GRPC_CLOSURE_INIT(&connection_state->on_timeout, on_timeout, connection_state, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &connection_state->timer, - connection_state->deadline, + grpc_timer_init(&connection_state->timer, connection_state->deadline, &connection_state->on_timeout); } } @@ -158,21 +154,21 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, &connection_state->svr_state->pending_handshake_mgrs, connection_state->handshake_mgr); gpr_mu_unlock(&connection_state->svr_state->mu); - grpc_handshake_manager_destroy(exec_ctx, connection_state->handshake_mgr); + grpc_handshake_manager_destroy(connection_state->handshake_mgr); gpr_free(connection_state->acceptor); - grpc_tcp_server_unref(exec_ctx, connection_state->svr_state->tcp_server); - server_connection_state_unref(exec_ctx, connection_state); + grpc_tcp_server_unref(connection_state->svr_state->tcp_server); + server_connection_state_unref(connection_state); } -static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, +static void on_accept(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); if (state->shutdown) { gpr_mu_unlock(&state->mu); - grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_NONE); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_shutdown(tcp, GRPC_ERROR_NONE); + grpc_endpoint_destroy(tcp); gpr_free(acceptor); return; } @@ -188,59 +184,56 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, connection_state->accepting_pollset = accepting_pollset; connection_state->acceptor = acceptor; connection_state->handshake_mgr = handshake_mgr; - grpc_handshakers_add(exec_ctx, HANDSHAKER_SERVER, state->args, + grpc_handshakers_add(HANDSHAKER_SERVER, state->args, connection_state->handshake_mgr); const grpc_arg* timeout_arg = grpc_channel_args_find(state->args, GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS); connection_state->deadline = - grpc_exec_ctx_now(exec_ctx) + + grpc_core::ExecCtx::Get()->Now() + grpc_channel_arg_get_integer(timeout_arg, {120 * GPR_MS_PER_SEC, 1, INT_MAX}); - grpc_handshake_manager_do_handshake(exec_ctx, connection_state->handshake_mgr, - nullptr /* interested_parties */, tcp, - state->args, connection_state->deadline, - acceptor, on_handshake_done, - connection_state); + grpc_handshake_manager_do_handshake( + connection_state->handshake_mgr, nullptr /* interested_parties */, tcp, + state->args, connection_state->deadline, acceptor, on_handshake_done, + connection_state); } /* Server callback: start listening on our ports */ -static void server_start_listener(grpc_exec_ctx* exec_ctx, grpc_server* server, - void* arg, grpc_pollset** pollsets, +static void server_start_listener(grpc_server* server, void* arg, + grpc_pollset** pollsets, size_t pollset_count) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); state->shutdown = false; gpr_mu_unlock(&state->mu); - grpc_tcp_server_start(exec_ctx, state->tcp_server, pollsets, pollset_count, - on_accept, state); + grpc_tcp_server_start(state->tcp_server, pollsets, pollset_count, on_accept, + state); } -static void tcp_server_shutdown_complete(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { server_state* state = (server_state*)arg; /* ensure all threads have unlocked */ gpr_mu_lock(&state->mu); grpc_closure* destroy_done = state->server_destroy_listener_done; GPR_ASSERT(state->shutdown); grpc_handshake_manager_pending_list_shutdown_all( - exec_ctx, state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); + state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); gpr_mu_unlock(&state->mu); // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); if (destroy_done != nullptr) { - destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error)); - grpc_exec_ctx_flush(exec_ctx); + destroy_done->cb(destroy_done->cb_arg, GRPC_ERROR_REF(error)); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_channel_args_destroy(exec_ctx, state->args); + grpc_channel_args_destroy(state->args); gpr_mu_destroy(&state->mu); gpr_free(state); } /* Server callback: destroy the tcp listener (so we don't generate further callbacks) */ -static void server_destroy_listener(grpc_exec_ctx* exec_ctx, - grpc_server* server, void* arg, +static void server_destroy_listener(grpc_server* server, void* arg, grpc_closure* destroy_done) { server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); @@ -248,12 +241,11 @@ static void server_destroy_listener(grpc_exec_ctx* exec_ctx, state->server_destroy_listener_done = destroy_done; grpc_tcp_server* tcp_server = state->tcp_server; gpr_mu_unlock(&state->mu); - grpc_tcp_server_shutdown_listeners(exec_ctx, tcp_server); - grpc_tcp_server_unref(exec_ctx, tcp_server); + grpc_tcp_server_shutdown_listeners(tcp_server); + grpc_tcp_server_unref(tcp_server); } -grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, - grpc_server* server, const char* addr, +grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, grpc_channel_args* args, int* port_num) { grpc_resolved_addresses* resolved = nullptr; @@ -277,8 +269,8 @@ grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_INIT(&state->tcp_server_shutdown_complete, tcp_server_shutdown_complete, state, grpc_schedule_on_exec_ctx); - err = grpc_tcp_server_create(exec_ctx, &state->tcp_server_shutdown_complete, - args, &tcp_server); + err = grpc_tcp_server_create(&state->tcp_server_shutdown_complete, args, + &tcp_server); if (err != GRPC_ERROR_NONE) { goto error; } @@ -327,7 +319,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, grpc_resolved_addresses_destroy(resolved); /* Register with the server only upon success */ - grpc_server_add_listener(exec_ctx, server, state, server_start_listener, + grpc_server_add_listener(server, state, server_start_listener, server_destroy_listener); goto done; @@ -338,9 +330,9 @@ error: grpc_resolved_addresses_destroy(resolved); } if (tcp_server) { - grpc_tcp_server_unref(exec_ctx, tcp_server); + grpc_tcp_server_unref(tcp_server); } else { - grpc_channel_args_destroy(exec_ctx, args); + grpc_channel_args_destroy(args); gpr_free(state); } *port_num = 0; diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h index 68304fd4f7..7de859da42 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.h +++ b/src/core/ext/transport/chttp2/server/chttp2_server.h @@ -25,8 +25,7 @@ /// Adds a port to \a server. Sets \a port_num to the port number. /// Takes ownership of \a args. -grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, - grpc_server* server, const char* addr, +grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, grpc_channel_args* args, int* port_num); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_SERVER_CHTTP2_SERVER_H */ diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 8984896538..52c42d056c 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -26,12 +26,12 @@ #include "src/core/lib/surface/server.h" int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; int port_num = 0; GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2, (server, addr)); grpc_error* err = grpc_chttp2_server_add_port( - &exec_ctx, server, addr, + server, addr, grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num); if (err != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(err); @@ -39,6 +39,6 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { GRPC_ERROR_UNREF(err); } - grpc_exec_ctx_finish(&exec_ctx); + return port_num; } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index 3fe05ce4ef..dafd4af6ce 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -38,32 +38,29 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, void* reserved, int fd) { GPR_ASSERT(reserved == nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; char* name; gpr_asprintf(&name, "fd:%d", fd); - grpc_endpoint* server_endpoint = - grpc_tcp_create(&exec_ctx, grpc_fd_create(fd, name), - grpc_server_get_channel_args(server), name); + grpc_endpoint* server_endpoint = grpc_tcp_create( + grpc_fd_create(fd, name), grpc_server_get_channel_args(server), name); gpr_free(name); const grpc_channel_args* server_args = grpc_server_get_channel_args(server); grpc_transport* transport = grpc_create_chttp2_transport( - &exec_ctx, server_args, server_endpoint, false /* is_client */); + server_args, server_endpoint, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server, &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(&exec_ctx, server_endpoint, pollsets[i]); + grpc_endpoint_add_to_pollset(server_endpoint, pollsets[i]); } - grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, - server_args); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_server_setup_transport(server, transport, nullptr, server_args); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } #else // !GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index ac3ea40f47..723af97ff0 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -36,7 +36,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_server_credentials* creds) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_error* err = GRPC_ERROR_NONE; grpc_server_security_connector* sc = nullptr; int port_num = 0; @@ -52,8 +52,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, "No credentials specified for secure server port (creds==NULL)"); goto done; } - status = - grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); + status = grpc_server_credentials_create_security_connector(creds, &sc); if (status != GRPC_SECURITY_OK) { char* msg; gpr_asprintf(&msg, @@ -72,12 +71,12 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_channel_args_copy_and_add(grpc_server_get_channel_args(server), args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Add server port. - err = grpc_chttp2_server_add_port(&exec_ctx, server, addr, args, &port_num); + err = grpc_chttp2_server_add_port(server, addr, args, &port_num); done: if (sc != nullptr) { - GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "server"); + GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "server"); } - grpc_exec_ctx_finish(&exec_ctx); + if (err != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 3ccae7afc3..984cd4ca78 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -130,8 +130,7 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx) { return true; } -grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, - grpc_slice input) { +grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { size_t input_length = GRPC_SLICE_LENGTH(input); size_t output_length = input_length / 4 * 3; struct grpc_base64_decode_context ctx; @@ -167,7 +166,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); - grpc_slice_unref_internal(exec_ctx, output); + grpc_slice_unref_internal(output); return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); @@ -175,8 +174,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, return output; } -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, - grpc_slice input, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, size_t output_length) { size_t input_length = GRPC_SLICE_LENGTH(input); grpc_slice output = GRPC_SLICE_MALLOC(output_length); @@ -189,7 +187,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, "grpc_chttp2_base64_decode_with_length has a length of %d, which " "has a tail of 1 byte.\n", (int)input_length); - grpc_slice_unref_internal(exec_ctx, output); + grpc_slice_unref_internal(output); return grpc_empty_slice(); } @@ -199,7 +197,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, "than the max possible output length %d.\n", (int)output_length, (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); - grpc_slice_unref_internal(exec_ctx, output); + grpc_slice_unref_internal(output); return grpc_empty_slice(); } @@ -213,7 +211,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); - grpc_slice_unref_internal(exec_ctx, output); + grpc_slice_unref_internal(output); return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.h b/src/core/ext/transport/chttp2/transport/bin_decoder.h index a78c305766..9cb75ccd81 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.h @@ -40,13 +40,12 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx); /* base64 decode a slice with pad chars. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, grpc_slice input); +grpc_slice grpc_chttp2_base64_decode(grpc_slice input); /* base64 decode a slice without pad chars, data length is needed. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, - grpc_slice input, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, size_t output_length); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */ diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.h b/src/core/ext/transport/chttp2/transport/bin_encoder.h index a8f36a345a..93ad0dfdea 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.h @@ -32,7 +32,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input); /* equivalent to: grpc_slice x = grpc_chttp2_base64_encode(input); grpc_slice y = grpc_chttp2_huffman_compress(x); - grpc_slice_unref_internal(exec_ctx, x); + grpc_slice_unref_internal( x); return y; */ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 63ac65ac78..f537fb09c2 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -95,105 +95,77 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); /* forward declarations of various callbacks that we'll build closures around */ -static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* t, - grpc_error* error); -static void write_action(grpc_exec_ctx* exec_ctx, void* t, grpc_error* error); -static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* t, - grpc_error* error); +static void write_action_begin_locked(void* t, grpc_error* error); +static void write_action(void* t, grpc_error* error); +static void write_action_end_locked(void* t, grpc_error* error); -static void read_action_locked(grpc_exec_ctx* exec_ctx, void* t, - grpc_error* error); +static void read_action_locked(void* t, grpc_error* error); -static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, - grpc_error* error); +static void complete_fetch_locked(void* gs, grpc_error* error); /** Set a transport level setting, and push it to our peer */ -static void queue_setting_update(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void queue_setting_update(grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value); -static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_error* error); +static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_error* error); /** Start new streams that have been created if we can */ -static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); +static void maybe_start_some_streams(grpc_chttp2_transport* t); -static void connectivity_state_set(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void connectivity_state_set(grpc_chttp2_transport* t, grpc_connectivity_state state, grpc_error* error, const char* reason); -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, - void* byte_stream, +static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored); static void incoming_byte_stream_publish_error( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_error* error); -static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, - grpc_chttp2_incoming_byte_stream* bs); - -static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, - grpc_error* error); -static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, - grpc_error* error); - -static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); - -static void close_transport_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, grpc_error* error); -static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error); - -static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error); -static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error); -static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, - void* tp, grpc_error* error); - -static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error); -static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_incoming_byte_stream* bs, grpc_error* error); +static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs); + +static void benign_reclaimer_locked(void* t, grpc_error* error); +static void destructive_reclaimer_locked(void* t, grpc_error* error); + +static void post_benign_reclaimer(grpc_chttp2_transport* t); +static void post_destructive_reclaimer(grpc_chttp2_transport* t); + +static void close_transport_locked(grpc_chttp2_transport* t, grpc_error* error); +static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error); + +static void schedule_bdp_ping_locked(grpc_chttp2_transport* t); +static void start_bdp_ping_locked(void* tp, grpc_error* error); +static void finish_bdp_ping_locked(void* tp, grpc_error* error); +static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error); + +static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error); +static void send_ping_locked(grpc_chttp2_transport* t, grpc_closure* on_initiate, grpc_closure* on_complete); -static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error); +static void retry_initiate_ping_locked(void* tp, grpc_error* error); /** keepalive-relevant functions */ -static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); -static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); -static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); -static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); - -static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +static void init_keepalive_ping_locked(void* arg, grpc_error* error); +static void start_keepalive_ping_locked(void* arg, grpc_error* error); +static void finish_keepalive_ping_locked(void* arg, grpc_error* error); +static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error); + +static void reset_byte_stream(void* arg, grpc_error* error); /******************************************************************************* * CONSTRUCTION/DESTRUCTION/REFCOUNTING */ -static void destruct_transport(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void destruct_transport(grpc_chttp2_transport* t) { size_t i; - grpc_endpoint_destroy(exec_ctx, t->ep); + grpc_endpoint_destroy(t->ep); - grpc_slice_buffer_destroy_internal(exec_ctx, &t->qbuf); + grpc_slice_buffer_destroy_internal(&t->qbuf); - grpc_slice_buffer_destroy_internal(exec_ctx, &t->outbuf); - grpc_chttp2_hpack_compressor_destroy(exec_ctx, &t->hpack_compressor); + grpc_slice_buffer_destroy_internal(&t->outbuf); + grpc_chttp2_hpack_compressor_destroy(&t->hpack_compressor); - grpc_slice_buffer_destroy_internal(exec_ctx, &t->read_buffer); - grpc_chttp2_hpack_parser_destroy(exec_ctx, &t->hpack_parser); + grpc_slice_buffer_destroy_internal(&t->read_buffer); + grpc_chttp2_hpack_parser_destroy(&t->hpack_parser); grpc_chttp2_goaway_parser_destroy(&t->goaway_parser); for (i = 0; i < STREAM_LIST_COUNT; i++) { @@ -206,12 +178,11 @@ static void destruct_transport(grpc_exec_ctx* exec_ctx, GPR_ASSERT(grpc_chttp2_stream_map_size(&t->stream_map) == 0); grpc_chttp2_stream_map_destroy(&t->stream_map); - grpc_connectivity_state_destroy(exec_ctx, &t->channel_callback.state_tracker); + grpc_connectivity_state_destroy(&t->channel_callback.state_tracker); - GRPC_COMBINER_UNREF(exec_ctx, t->combiner, "chttp2_transport"); + GRPC_COMBINER_UNREF(t->combiner, "chttp2_transport"); - cancel_pings(exec_ctx, t, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); + cancel_pings(t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); while (t->write_cb_pool) { grpc_chttp2_write_cb* next = t->write_cb_pool->next; @@ -228,8 +199,7 @@ static void destruct_transport(grpc_exec_ctx* exec_ctx, } #ifndef NDEBUG -void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, const char* reason, +void grpc_chttp2_unref_transport(grpc_chttp2_transport* t, const char* reason, const char* file, int line) { if (grpc_trace_chttp2_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); @@ -237,7 +207,7 @@ void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, t, val, val - 1, reason, file, line); } if (!gpr_unref(&t->refs)) return; - destruct_transport(exec_ctx, t); + destruct_transport(t); } void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, @@ -250,10 +220,9 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, gpr_ref(&t->refs); } #else -void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +void grpc_chttp2_unref_transport(grpc_chttp2_transport* t) { if (!gpr_unref(&t->refs)) return; - destruct_transport(exec_ctx, t); + destruct_transport(t); } void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); } @@ -261,7 +230,7 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); } static const grpc_transport_vtable* get_vtable(void); -static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, +static void init_transport(grpc_chttp2_transport* t, const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { size_t i; @@ -320,7 +289,7 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, t->goaway_error = GRPC_ERROR_NONE; grpc_chttp2_goaway_parser_init(&t->goaway_parser); - grpc_chttp2_hpack_parser_init(exec_ctx, &t->hpack_parser); + grpc_chttp2_hpack_parser_init(&t->hpack_parser); grpc_slice_buffer_init(&t->read_buffer); @@ -351,14 +320,13 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, /* configure http2 the way we like it */ if (is_client) { - queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0); - queue_setting_update(exec_ctx, t, - GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0); + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0); + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0); } - queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, DEFAULT_MAX_HEADER_LIST_SIZE); - queue_setting_update(exec_ctx, t, - GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1); + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, + 1); t->ping_policy.max_pings_without_data = g_default_max_pings_without_data; t->ping_policy.min_sent_ping_interval_without_data = @@ -533,7 +501,7 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, int value = grpc_channel_arg_get_integer( &channel_args->args[i], settings_map[j].integer_options); if (value >= 0) { - queue_setting_update(exec_ctx, t, settings_map[j].setting_id, + queue_setting_update(t, settings_map[j].setting_id, (uint32_t)value); } } @@ -544,7 +512,7 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, } } - t->flow_control.Init(exec_ctx, t, enable_bdp); + t->flow_control.Init(t, enable_bdp); /* No pings allowed before receiving a header or data frame. */ t->ping_state.pings_before_data_required = 0; @@ -558,8 +526,8 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, if (t->keepalive_time != GRPC_MILLIS_INF_FUTURE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, - grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } else { /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no @@ -569,42 +537,37 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, if (enable_bdp) { GRPC_CHTTP2_REF_TRANSPORT(t, "bdp_ping"); - schedule_bdp_ping_locked(exec_ctx, t); + schedule_bdp_ping_locked(t); - grpc_chttp2_act_on_flowctl_action( - exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, nullptr); + grpc_chttp2_act_on_flowctl_action(t->flow_control->PeriodicUpdate(), t, + nullptr); } - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE); - post_benign_reclaimer(exec_ctx, t); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE); + post_benign_reclaimer(t); } -static void destroy_transport_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void destroy_transport_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->destroying = 1; close_transport_locked( - exec_ctx, t, - grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), - GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destroy"); + t, grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), + GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy"); } -static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { +static void destroy_transport(grpc_transport* gt) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_CREATE(destroy_transport_locked, t, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(destroy_transport_locked, t, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); } -static void close_transport_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void close_transport_locked(grpc_chttp2_transport* t, grpc_error* error) { - end_all_the_calls(exec_ctx, t, GRPC_ERROR_REF(error)); - cancel_pings(exec_ctx, t, GRPC_ERROR_REF(error)); + end_all_the_calls(t, GRPC_ERROR_REF(error)); + cancel_pings(t, GRPC_ERROR_REF(error)); if (t->closed_with_error == GRPC_ERROR_NONE) { if (!grpc_error_has_clear_grpc_status(error)) { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, @@ -622,21 +585,21 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, } GPR_ASSERT(error != GRPC_ERROR_NONE); t->closed_with_error = GRPC_ERROR_REF(error); - connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_REF(error), "close_transport"); + connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), + "close_transport"); if (t->ping_state.is_delayed_ping_timer_set) { - grpc_timer_cancel(exec_ctx, &t->ping_state.delayed_ping_timer); + grpc_timer_cancel(&t->ping_state.delayed_ping_timer); } if (t->have_next_bdp_ping_timer) { - grpc_timer_cancel(exec_ctx, &t->next_bdp_ping_timer); + grpc_timer_cancel(&t->next_bdp_ping_timer); } switch (t->keepalive_state) { case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: - grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); + grpc_timer_cancel(&t->keepalive_ping_timer); break; case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING: - grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); - grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer); + grpc_timer_cancel(&t->keepalive_ping_timer); + grpc_timer_cancel(&t->keepalive_watchdog_timer); break; case GRPC_CHTTP2_KEEPALIVE_STATE_DYING: case GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED: @@ -647,14 +610,13 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, /* flush writable stream list to avoid dangling references */ grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writable_stream(t, &s)) { - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:close"); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:close"); } GPR_ASSERT(t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE); - grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(t->ep, GRPC_ERROR_REF(error)); } if (t->notify_on_receive_settings != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, t->notify_on_receive_settings, - GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(t->notify_on_receive_settings, GRPC_ERROR_CANCELLED); t->notify_on_receive_settings = nullptr; } GRPC_ERROR_UNREF(error); @@ -664,22 +626,21 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, - const char* reason) { - grpc_stream_unref(exec_ctx, s->refcount, reason); +void grpc_chttp2_stream_unref(grpc_chttp2_stream* s, const char* reason) { + grpc_stream_unref(s->refcount, reason); } #else void grpc_chttp2_stream_ref(grpc_chttp2_stream* s) { grpc_stream_ref(s->refcount); } -void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s) { - grpc_stream_unref(exec_ctx, s->refcount); +void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) { + grpc_stream_unref(s->refcount); } #endif -static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_stream_refcount* refcount, - const void* server_data, gpr_arena* arena) { +static int init_stream(grpc_transport* gt, grpc_stream* gs, + grpc_stream_refcount* refcount, const void* server_data, + gpr_arena* arena) { GPR_TIMER_BEGIN("init_stream", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; @@ -713,7 +674,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->id = (uint32_t)(uintptr_t)server_data; *t->accepting_stream = s; grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); - post_destructive_reclaimer(exec_ctx, t); + post_destructive_reclaimer(t); } s->flow_control.Init(t->flow_control.get(), s); @@ -722,8 +683,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, return 0; } -static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, - grpc_error* error) { +static void destroy_stream_locked(void* sp, grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; grpc_chttp2_transport* t = s->t; @@ -734,11 +694,10 @@ static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == nullptr); } - grpc_slice_buffer_destroy_internal(exec_ctx, - &s->unprocessed_incoming_frames_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &s->frame_storage); - grpc_slice_buffer_destroy_internal(exec_ctx, &s->compressed_data_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &s->decompressed_data_buffer); + grpc_slice_buffer_destroy_internal(&s->unprocessed_incoming_frames_buffer); + grpc_slice_buffer_destroy_internal(&s->frame_storage); + grpc_slice_buffer_destroy_internal(&s->compressed_data_buffer); + grpc_slice_buffer_destroy_internal(&s->decompressed_data_buffer); grpc_chttp2_list_remove_stalled_by_transport(t, s); grpc_chttp2_list_remove_stalled_by_stream(t, s); @@ -757,27 +716,24 @@ static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); GPR_ASSERT(s->recv_message_ready == nullptr); GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); - grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser); - grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx, - &s->metadata_buffer[0]); - grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx, - &s->metadata_buffer[1]); - grpc_slice_buffer_destroy_internal(exec_ctx, &s->flow_controlled_buffer); + grpc_chttp2_data_parser_destroy(&s->data_parser); + grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[0]); + grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[1]); + grpc_slice_buffer_destroy_internal(&s->flow_controlled_buffer); GRPC_ERROR_UNREF(s->read_closed_error); GRPC_ERROR_UNREF(s->write_closed_error); GRPC_ERROR_UNREF(s->byte_stream_error); s->flow_control.Destroy(); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "stream"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "stream"); GPR_TIMER_END("destroy_stream", 0); - GRPC_CLOSURE_SCHED(exec_ctx, s->destroy_stream_arg, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->destroy_stream_arg, GRPC_ERROR_NONE); } -static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { GPR_TIMER_BEGIN("destroy_stream", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; @@ -794,7 +750,6 @@ static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->destroy_stream_arg = then_schedule_closure; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&s->destroy_stream, destroy_stream_locked, s, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -806,8 +761,7 @@ grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, return (grpc_chttp2_stream*)grpc_chttp2_stream_map_find(&t->stream_map, id); } -grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, uint32_t id) { if (t->channel_callback.accept_stream == nullptr) { return nullptr; @@ -815,8 +769,7 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* accepting; GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; - t->channel_callback.accept_stream(exec_ctx, - t->channel_callback.accept_stream_user_data, + t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, &t->base, (void*)(uintptr_t)id); t->accepting_stream = nullptr; return accepting; @@ -838,7 +791,7 @@ static const char* write_state_name(grpc_chttp2_write_state st) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -static void set_write_state(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, +static void set_write_state(grpc_chttp2_transport* t, grpc_chttp2_write_state st, const char* reason) { GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_DEBUG, "W:%p %s state %s -> %s [%s]", t, t->is_client ? "CLIENT" : "SERVER", @@ -846,108 +799,100 @@ static void set_write_state(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, write_state_name(st), reason)); t->write_state = st; if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &t->run_after_write); + GRPC_CLOSURE_LIST_SCHED(&t->run_after_write); if (t->close_transport_on_writes_finished != nullptr) { grpc_error* err = t->close_transport_on_writes_finished; t->close_transport_on_writes_finished = nullptr; - close_transport_locked(exec_ctx, t, err); + close_transport_locked(t, err); } } } static void inc_initiate_write_reason( - grpc_exec_ctx* exec_ctx, grpc_chttp2_initiate_write_reason reason) { + grpc_chttp2_initiate_write_reason reason) { switch (reason) { case GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(); break; case GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA(); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA(); break; case GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(); break; case GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(); break; case GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(); break; case GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(); break; case GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(); break; case GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL(); break; case GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL(); break; case GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(); break; case GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING(); break; case GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE(); break; case GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(); break; case GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(); break; case GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED( - exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED(); break; case GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(); break; case GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM: - GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(exec_ctx); + GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(); break; } } -void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason) { GPR_TIMER_BEGIN("grpc_chttp2_initiate_write", 0); switch (t->write_state) { case GRPC_CHTTP2_WRITE_STATE_IDLE: - inc_initiate_write_reason(exec_ctx, reason); - set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, + inc_initiate_write_reason(reason); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, grpc_chttp2_initiate_write_reason_string(reason)); t->is_first_write_in_batch = true; GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&t->write_action_begin_locked, write_action_begin_locked, t, grpc_combiner_finally_scheduler(t->combiner)), GRPC_ERROR_NONE); break; case GRPC_CHTTP2_WRITE_STATE_WRITING: - set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE, + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE, grpc_chttp2_initiate_write_reason_string(reason)); break; case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: @@ -956,8 +901,7 @@ void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, GPR_TIMER_END("grpc_chttp2_initiate_write", 0); } -void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (t->closed_with_error == GRPC_ERROR_NONE && grpc_chttp2_list_add_writable_stream(t, s)) { @@ -1007,8 +951,7 @@ static const char* begin_writing_desc(bool partial, bool inlined) { GPR_UNREACHABLE_CODE(return "bad state tuple"); } -static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* gt, - grpc_error* error_ignored) { +static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { GPR_TIMER_BEGIN("write_action_begin_locked", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); @@ -1016,62 +959,59 @@ static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* gt, if (t->closed_with_error != GRPC_ERROR_NONE) { r.writing = false; } else { - r = grpc_chttp2_begin_write(exec_ctx, t); + r = grpc_chttp2_begin_write(t); } if (r.writing) { if (r.partial) { - GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(exec_ctx); + GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(); } if (!t->is_first_write_in_batch) { - GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(exec_ctx); + GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(); } grpc_closure_scheduler* scheduler = write_scheduler(t, r.early_results_scheduled, r.partial); if (scheduler != grpc_schedule_on_exec_ctx) { - GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(exec_ctx); + GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(); } set_write_state( - exec_ctx, t, + t, r.partial ? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE : GRPC_CHTTP2_WRITE_STATE_WRITING, begin_writing_desc(r.partial, scheduler == grpc_schedule_on_exec_ctx)); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&t->write_action, write_action, t, scheduler), GRPC_ERROR_NONE); } else { - GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(exec_ctx); - set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE, - "begin writing nothing"); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing"); + GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "begin writing nothing"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); } GPR_TIMER_END("write_action_begin_locked", 0); } -static void write_action(grpc_exec_ctx* exec_ctx, void* gt, grpc_error* error) { +static void write_action(void* gt, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GPR_TIMER_BEGIN("write_action", 0); grpc_endpoint_write( - exec_ctx, t->ep, &t->outbuf, + t->ep, &t->outbuf, GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, grpc_combiner_scheduler(t->combiner))); GPR_TIMER_END("write_action", 0); } -static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void write_action_end_locked(void* tp, grpc_error* error) { GPR_TIMER_BEGIN("terminate_writing_with_lock", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (error != GRPC_ERROR_NONE) { - close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error)); + close_transport_locked(t, GRPC_ERROR_REF(error)); } if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT; if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { close_transport_locked( - exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); + t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); } } @@ -1080,17 +1020,14 @@ static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* tp, GPR_UNREACHABLE_CODE(break); case GRPC_CHTTP2_WRITE_STATE_WRITING: GPR_TIMER_MARK("state=writing", 0); - set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE, - "finish writing"); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing"); break; case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: GPR_TIMER_MARK("state=writing_stale_no_poller", 0); - set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, - "continue writing"); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, "continue writing"); t->is_first_write_in_batch = false; GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); GRPC_CLOSURE_RUN( - exec_ctx, GRPC_CLOSURE_INIT(&t->write_action_begin_locked, write_action_begin_locked, t, grpc_combiner_finally_scheduler(t->combiner)), @@ -1098,16 +1035,15 @@ static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* tp, break; } - grpc_chttp2_end_write(exec_ctx, t, GRPC_ERROR_REF(error)); + grpc_chttp2_end_write(t, GRPC_ERROR_REF(error)); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); GPR_TIMER_END("terminate_writing_with_lock", 0); } // Dirties an HTTP2 setting to be sent out next time a writing path occurs. // If the change needs to occur immediately, manually initiate a write. -static void queue_setting_update(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void queue_setting_update(grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value) { const grpc_chttp2_setting_parameters* sp = &grpc_chttp2_settings_parameters[id]; @@ -1122,8 +1058,7 @@ static void queue_setting_update(grpc_exec_ctx* exec_ctx, } } -void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text) { // GRPC_CHTTP2_IF_TRACING( @@ -1158,12 +1093,11 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, /* lie: use transient failure from the transport to indicate goaway has been * received */ - connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE, + connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(t->goaway_error), "got_goaway"); } -static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void maybe_start_some_streams(grpc_chttp2_transport* t) { grpc_chttp2_stream* s; /* start streams where we have free grpc_chttp2_stream ids and free * concurrency */ @@ -1183,22 +1117,21 @@ static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) { connectivity_state_set( - exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE, + t, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"), "no_more_stream_ids"); } grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); - post_destructive_reclaimer(exec_ctx, t); - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM); + post_destructive_reclaimer(t); + grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM); } /* cancel out streams that will never be started */ while (t->next_stream_id >= MAX_CLIENT_STREAM_ID && grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) { grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); @@ -1220,15 +1153,13 @@ static grpc_closure* add_closure_barrier(grpc_closure* closure) { return closure; } -static void null_then_run_closure(grpc_exec_ctx* exec_ctx, - grpc_closure** closure, grpc_error* error) { +static void null_then_run_closure(grpc_closure** closure, grpc_error* error) { grpc_closure* c = *closure; *closure = nullptr; - GRPC_CLOSURE_RUN(exec_ctx, c, error); + GRPC_CLOSURE_RUN(c, error); } -void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_closure** pclosure, grpc_error* error, const char* desc) { @@ -1268,7 +1199,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, } if ((t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE) || !(closure->next_data.scratch & CLOSURE_BARRIER_MAY_COVER_WRITE)) { - GRPC_CLOSURE_RUN(exec_ctx, closure, closure->error_data.error); + GRPC_CLOSURE_RUN(closure, closure->error_data.error); } else { grpc_closure_list_append(&t->run_after_write, closure, closure->error_data.error); @@ -1284,28 +1215,24 @@ static bool contains_non_ok_status(grpc_metadata_batch* batch) { return false; } -static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void maybe_become_writable_due_to_send_msg(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (s->id != 0 && (!s->write_buffering || s->flow_controlled_buffer.length > t->write_buffer_size)) { - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); + grpc_chttp2_mark_stream_writable(t, s); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_SEND_MESSAGE); } } -static void add_fetched_slice_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void add_fetched_slice_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { s->fetched_send_message_length += (uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); - maybe_become_writable_due_to_send_msg(exec_ctx, t, s); + maybe_become_writable_due_to_send_msg(t, s); } -static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void continue_fetching_send_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { for (;;) { if (s->fetching_send_message == nullptr) { @@ -1314,11 +1241,11 @@ static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, return; /* early out */ } if (s->fetched_send_message_length == s->fetching_send_message->length) { - grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); + grpc_byte_stream_destroy(s->fetching_send_message); int64_t notify_offset = s->next_message_end_offset; if (notify_offset <= s->flow_controlled_bytes_written) { grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE, + t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE, "fetching_send_message_finished"); } else { grpc_chttp2_write_cb* cb = t->write_cb_pool; @@ -1339,39 +1266,37 @@ static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, } s->fetching_send_message = nullptr; return; /* early out */ - } else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message, - UINT32_MAX, &s->complete_fetch_locked)) { - grpc_error* error = grpc_byte_stream_pull( - exec_ctx, s->fetching_send_message, &s->fetching_slice); + } else if (grpc_byte_stream_next(s->fetching_send_message, UINT32_MAX, + &s->complete_fetch_locked)) { + grpc_error* error = + grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); if (error != GRPC_ERROR_NONE) { - grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); - grpc_chttp2_cancel_stream(exec_ctx, t, s, error); + grpc_byte_stream_destroy(s->fetching_send_message); + grpc_chttp2_cancel_stream(t, s, error); } else { - add_fetched_slice_locked(exec_ctx, t, s); + add_fetched_slice_locked(t, s); } } } } -static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, - grpc_error* error) { +static void complete_fetch_locked(void* gs, grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; grpc_chttp2_transport* t = s->t; if (error == GRPC_ERROR_NONE) { - error = grpc_byte_stream_pull(exec_ctx, s->fetching_send_message, - &s->fetching_slice); + error = grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); if (error == GRPC_ERROR_NONE) { - add_fetched_slice_locked(exec_ctx, t, s); - continue_fetching_send_locked(exec_ctx, t, s); + add_fetched_slice_locked(t, s); + continue_fetching_send_locked(t, s); } } if (error != GRPC_ERROR_NONE) { - grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); - grpc_chttp2_cancel_stream(exec_ctx, t, s, error); + grpc_byte_stream_destroy(s->fetching_send_message); + grpc_chttp2_cancel_stream(t, s, error); } } -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, bool is_client, bool is_initial) { @@ -1386,7 +1311,7 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, } } -static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, +static void perform_stream_op_locked(void* stream_op, grpc_error* error_ignored) { GPR_TIMER_BEGIN("perform_stream_op_locked", 0); @@ -1396,7 +1321,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, grpc_transport_stream_op_batch_payload* op_payload = op->payload; grpc_chttp2_transport* t = s->t; - GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_BATCHES(); if (grpc_http_trace.enabled()) { char* str = grpc_transport_stream_op_batch_string(op); @@ -1431,13 +1356,12 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } if (op->cancel_stream) { - GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx); - grpc_chttp2_cancel_stream(exec_ctx, t, s, - op_payload->cancel_stream.cancel_error); + GRPC_STATS_INC_HTTP2_OP_CANCEL(); + grpc_chttp2_cancel_stream(t, s, op_payload->cancel_stream.cancel_error); } if (op->send_initial_metadata) { - GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(); GPR_ASSERT(s->send_initial_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; @@ -1465,7 +1389,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } if (metadata_size > metadata_peer_limit) { grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int( grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -1484,10 +1408,10 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (t->closed_with_error == GRPC_ERROR_NONE) { GPR_ASSERT(s->id == 0); grpc_chttp2_list_add_waiting_for_concurrency(t, s); - maybe_start_some_streams(exec_ctx, t); + maybe_start_some_streams(t); } else { grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int( GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Transport closed", &t->closed_with_error, 1), @@ -1495,18 +1419,18 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } } else { GPR_ASSERT(s->id != 0); - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_mark_stream_writable(t, s); if (!(op->send_message && (op->payload->send_message.send_message->flags & GRPC_WRITE_BUFFER_HINT))) { grpc_chttp2_initiate_write( - exec_ctx, t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); + t, GRPC_CHTTP2_INITIATE_WRITE_SEND_INITIAL_METADATA); } } } else { s->send_initial_metadata = nullptr; grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->send_initial_metadata_finished, + t, s, &s->send_initial_metadata_finished, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Attempt to send initial metadata after stream was closed", &s->write_closed_error, 1), @@ -1520,9 +1444,9 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } if (op->send_message) { - GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(); GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE( - exec_ctx, op->payload->send_message.send_message->length); + op->payload->send_message.send_message->length); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->fetching_send_message_finished = add_closure_barrier(op->on_complete); if (s->write_closed) { @@ -1532,7 +1456,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, // recv_message failure, breaking out of its loop, and then // starting recv_trailing_metadata. grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->fetching_send_message_finished, + t, s, &s->fetching_send_message_finished, t->is_client && s->received_trailing_metadata ? GRPC_ERROR_NONE : GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -1561,13 +1485,13 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } else { s->write_buffering = false; } - continue_fetching_send_locked(exec_ctx, t, s); - maybe_become_writable_due_to_send_msg(exec_ctx, t, s); + continue_fetching_send_locked(t, s); + maybe_become_writable_due_to_send_msg(t, s); } } if (op->send_trailing_metadata) { - GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(); GPR_ASSERT(s->send_trailing_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); @@ -1581,7 +1505,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE]; if (metadata_size > metadata_peer_limit) { grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int( grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -1598,7 +1522,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (s->write_closed) { s->send_trailing_metadata = nullptr; grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->send_trailing_metadata_finished, + t, s, &s->send_trailing_metadata_finished, grpc_metadata_batch_is_empty( op->payload->send_trailing_metadata.send_trailing_metadata) ? GRPC_ERROR_NONE @@ -1609,15 +1533,15 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } else if (s->id != 0) { /* TODO(ctiller): check if there's flow control for any outstanding bytes before going writable */ - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_mark_stream_writable(t, s); grpc_chttp2_initiate_write( - exec_ctx, t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); + t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); } } } if (op->recv_initial_metadata) { - GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(); GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); s->recv_initial_metadata_ready = op_payload->recv_initial_metadata.recv_initial_metadata_ready; @@ -1629,11 +1553,11 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, gpr_atm_rel_store(op_payload->recv_initial_metadata.peer_string, (gpr_atm)gpr_strdup(t->peer_string)); } - grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); } if (op->recv_message) { - GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(); size_t already_received; GPR_ASSERT(s->recv_message_ready == nullptr); GPR_ASSERT(!s->pending_byte_stream); @@ -1644,32 +1568,30 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, already_received = s->frame_storage.length; s->flow_control->IncomingByteStreamUpdate(GRPC_HEADER_SIZE_IN_BYTES, already_received); - grpc_chttp2_act_on_flowctl_action(exec_ctx, - s->flow_control->MakeAction(), t, s); + grpc_chttp2_act_on_flowctl_action(s->flow_control->MakeAction(), t, s); } } - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(t, s); } if (op->recv_trailing_metadata) { - GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx); + GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(); GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); s->recv_trailing_metadata_finished = add_closure_barrier(on_complete); s->recv_trailing_metadata = op_payload->recv_trailing_metadata.recv_trailing_metadata; s->final_metadata_requested = true; - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); } - grpc_chttp2_complete_closure_step(exec_ctx, t, s, &on_complete, - GRPC_ERROR_NONE, "op->on_complete"); + grpc_chttp2_complete_closure_step(t, s, &on_complete, GRPC_ERROR_NONE, + "op->on_complete"); GPR_TIMER_END("perform_stream_op_locked", 0); - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "perform_stream_op"); + GRPC_CHTTP2_STREAM_UNREF(s, "perform_stream_op"); } -static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { GPR_TIMER_BEGIN("perform_stream_op", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; @@ -1697,32 +1619,29 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, op->handler_private.extra_arg = gs; GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_stream_op_locked, op, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); GPR_TIMER_END("perform_stream_op", 0); } -static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error) { +static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { /* callback remaining pings: they're not allowed to call into the transpot, and maybe they hold resources that need to be freed */ grpc_chttp2_ping_queue* pq = &t->ping_queue; GPR_ASSERT(error != GRPC_ERROR_NONE); for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) { grpc_closure_list_fail_all(&pq->lists[j], GRPC_ERROR_REF(error)); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[j]); + GRPC_CLOSURE_LIST_SCHED(&pq->lists[j]); } GRPC_ERROR_UNREF(error); } -static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, +static void send_ping_locked(grpc_chttp2_transport* t, grpc_closure* on_initiate, grpc_closure* on_ack) { if (t->closed_with_error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(exec_ctx, on_initiate, - GRPC_ERROR_REF(t->closed_with_error)); - GRPC_CLOSURE_SCHED(exec_ctx, on_ack, GRPC_ERROR_REF(t->closed_with_error)); + GRPC_CLOSURE_SCHED(on_initiate, GRPC_ERROR_REF(t->closed_with_error)); + GRPC_CLOSURE_SCHED(on_ack, GRPC_ERROR_REF(t->closed_with_error)); return; } grpc_chttp2_ping_queue* pq = &t->ping_queue; @@ -1732,18 +1651,15 @@ static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, GRPC_ERROR_NONE); } -static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void retry_initiate_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->ping_state.is_delayed_ping_timer_set = false; if (error == GRPC_ERROR_NONE) { - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); } } -void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - uint64_t id) { +void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { grpc_chttp2_ping_queue* pq = &t->ping_queue; if (pq->inflight_id != id) { char* from = grpc_endpoint_get_peer(t->ep); @@ -1751,54 +1667,48 @@ void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, gpr_free(from); return; } - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); + GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS); } } -static void send_goaway(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error) { +static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; grpc_http2_error_code http_error; grpc_slice slice; - grpc_error_get_status(exec_ctx, error, GRPC_MILLIS_INF_FUTURE, nullptr, - &slice, &http_error, nullptr); + grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, + &http_error, nullptr); grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, grpc_slice_ref_internal(slice), &t->qbuf); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); GRPC_ERROR_UNREF(error); } -void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { t->ping_recv_state.ping_strikes++; if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes && t->ping_policy.max_ping_strikes != 0) { - send_goaway(exec_ctx, t, + send_goaway(t, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); /*The transport will be closed after the write is done */ close_transport_locked( - exec_ctx, t, - grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); + t, grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); } } -static void perform_transport_op_locked(grpc_exec_ctx* exec_ctx, - void* stream_op, +static void perform_transport_op_locked(void* stream_op, grpc_error* error_ignored) { grpc_transport_op* op = (grpc_transport_op*)stream_op; grpc_chttp2_transport* t = (grpc_chttp2_transport*)op->handler_private.extra_arg; if (op->goaway_error) { - send_goaway(exec_ctx, t, op->goaway_error); + send_goaway(t, op->goaway_error); } if (op->set_accept_stream) { @@ -1808,43 +1718,40 @@ static void perform_transport_op_locked(grpc_exec_ctx* exec_ctx, } if (op->bind_pollset) { - grpc_endpoint_add_to_pollset(exec_ctx, t->ep, op->bind_pollset); + grpc_endpoint_add_to_pollset(t->ep, op->bind_pollset); } if (op->bind_pollset_set) { - grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, op->bind_pollset_set); + grpc_endpoint_add_to_pollset_set(t->ep, op->bind_pollset_set); } if (op->send_ping) { - send_ping_locked(exec_ctx, t, nullptr, op->send_ping); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); + send_ping_locked(t, nullptr, op->send_ping); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); } if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( - exec_ctx, &t->channel_callback.state_tracker, op->connectivity_state, + &t->channel_callback.state_tracker, op->connectivity_state, op->on_connectivity_state_change); } if (op->disconnect_with_error != GRPC_ERROR_NONE) { - close_transport_locked(exec_ctx, t, op->disconnect_with_error); + close_transport_locked(t, op->disconnect_with_error); } - GRPC_CLOSURE_RUN(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(op->on_consumed, GRPC_ERROR_NONE); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "transport_op"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "transport_op"); } -static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_transport_op* op) { +static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; char* msg = grpc_transport_op_string(op); gpr_free(msg); op->handler_private.extra_arg = gt; GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op"); - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_INIT(&op->handler_private.closure, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_transport_op_locked, op, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -1854,36 +1761,33 @@ static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, * INPUT PROCESSING - GENERAL */ -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { if (s->recv_initial_metadata_ready != nullptr && s->published_metadata[0] != GRPC_METADATA_NOT_PUBLISHED) { if (s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); } } - grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &s->metadata_buffer[0], s->recv_initial_metadata); - null_then_run_closure(exec_ctx, &s->recv_initial_metadata_ready, - GRPC_ERROR_NONE); + grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[0], + s->recv_initial_metadata); + null_then_run_closure(&s->recv_initial_metadata_ready, GRPC_ERROR_NONE); } } -void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { grpc_error* error = GRPC_ERROR_NONE; if (s->recv_message_ready != nullptr) { *s->recv_message = nullptr; if (s->final_metadata_requested && s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); } } if (!s->pending_byte_stream) { @@ -1910,10 +1814,9 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, &s->decompressed_data_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES - s->decompressed_header_bytes, &end_of_context)) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Stream decompression error."); } else { @@ -1922,8 +1825,8 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, s->decompressed_header_bytes = 0; } error = grpc_deframe_unprocessed_incoming_frames( - exec_ctx, &s->data_parser, s, &s->decompressed_data_buffer, - nullptr, s->recv_message); + &s->data_parser, s, &s->decompressed_data_buffer, nullptr, + s->recv_message); if (end_of_context) { grpc_stream_compression_context_destroy( s->stream_decompression_ctx); @@ -1932,15 +1835,14 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, } } else { error = grpc_deframe_unprocessed_incoming_frames( - exec_ctx, &s->data_parser, s, - &s->unprocessed_incoming_frames_buffer, nullptr, s->recv_message); + &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, + nullptr, s->recv_message); } if (error != GRPC_ERROR_NONE) { s->seen_error = true; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); break; } else if (*s->recv_message != nullptr) { break; @@ -1948,26 +1850,25 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, } } if (error == GRPC_ERROR_NONE && *s->recv_message != nullptr) { - null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); + null_then_run_closure(&s->recv_message_ready, GRPC_ERROR_NONE); } else if (s->published_metadata[1] != GRPC_METADATA_NOT_PUBLISHED) { *s->recv_message = nullptr; - null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); + null_then_run_closure(&s->recv_message_ready, GRPC_ERROR_NONE); } GRPC_ERROR_UNREF(error); } } -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(t, s); if (s->recv_trailing_metadata_finished != nullptr && s->read_closed && s->write_closed) { if (s->seen_error) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); if (!s->pending_byte_stream) { grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); } } bool pending_data = s->pending_byte_stream || @@ -1985,9 +1886,9 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, s->stream_decompression_ctx, &s->frame_storage, &s->unprocessed_incoming_frames_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES, &end_of_context)) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( - exec_ctx, &s->unprocessed_incoming_frames_buffer); + &s->unprocessed_incoming_frames_buffer); s->seen_error = true; } else { if (s->unprocessed_incoming_frames_buffer.length > 0) { @@ -2002,23 +1903,23 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, } if (s->read_closed && s->frame_storage.length == 0 && !pending_data && s->recv_trailing_metadata_finished != nullptr) { - grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata); + grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[1], + s->recv_trailing_metadata); grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, + t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, "recv_trailing_metadata_finished"); } } } -static void remove_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - uint32_t id, grpc_error* error) { +static void remove_stream(grpc_chttp2_transport* t, uint32_t id, + grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)grpc_chttp2_stream_map_delete(&t->stream_map, id); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_parsing_become_skip_parser(t); } if (s->pending_byte_stream) { if (s->on_next != nullptr) { @@ -2026,8 +1927,8 @@ static void remove_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, if (error == GRPC_ERROR_NONE) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); } - incoming_byte_stream_publish_error(exec_ctx, bs, error); - incoming_byte_stream_unref(exec_ctx, bs); + incoming_byte_stream_publish_error(bs, error); + incoming_byte_stream_unref(bs); s->data_parser.parsing_frame = nullptr; } else { GRPC_ERROR_UNREF(s->byte_stream_error); @@ -2036,56 +1937,52 @@ static void remove_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, } if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { - post_benign_reclaimer(exec_ctx, t); + post_benign_reclaimer(t); if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SENT) { close_transport_locked( - exec_ctx, t, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Last stream closed after sending GOAWAY", &error, 1)); + t, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Last stream closed after sending GOAWAY", &error, 1)); } } if (grpc_chttp2_list_remove_writable_stream(t, s)) { - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:remove_stream"); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:remove_stream"); } GRPC_ERROR_UNREF(error); - maybe_start_some_streams(exec_ctx, t); + maybe_start_some_streams(t); } -void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, grpc_chttp2_stream* s, +void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* due_to_error) { if (!t->is_client && !s->sent_trailing_metadata && grpc_error_has_clear_grpc_status(due_to_error)) { - close_from_api(exec_ctx, t, s, due_to_error); + close_from_api(t, s, due_to_error); return; } if (!s->read_closed || !s->write_closed) { if (s->id != 0) { grpc_http2_error_code http_error; - grpc_error_get_status(exec_ctx, due_to_error, s->deadline, nullptr, - nullptr, &http_error, nullptr); + grpc_error_get_status(due_to_error, s->deadline, nullptr, nullptr, + &http_error, nullptr); grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, &s->stats.outgoing)); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); } } if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) { s->seen_error = true; } - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error); + grpc_chttp2_mark_stream_closed(t, s, 1, 1, due_to_error); } -void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_error* error) { +void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_error* error) { grpc_status_code status; grpc_slice slice; - grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, nullptr, - nullptr); + grpc_error_get_status(error, s->deadline, &status, &slice, nullptr, nullptr); if (status != GRPC_STATUS_OK) { s->seen_error = true; } @@ -2101,20 +1998,20 @@ void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, gpr_ltoa(status, status_string); GRPC_LOG_IF_ERROR("add_status", grpc_chttp2_incoming_metadata_buffer_replace_or_add( - exec_ctx, &s->metadata_buffer[1], + &s->metadata_buffer[1], grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_STATUS, + GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(status_string)))); if (!GRPC_SLICE_IS_EMPTY(slice)) { GRPC_LOG_IF_ERROR( "add_status_message", grpc_chttp2_incoming_metadata_buffer_replace_or_add( - exec_ctx, &s->metadata_buffer[1], - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + &s->metadata_buffer[1], + grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal(slice)))); } s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); } GRPC_ERROR_UNREF(error); @@ -2147,14 +2044,12 @@ static grpc_error* removal_error(grpc_error* extra_error, grpc_chttp2_stream* s, return error; } -static void flush_write_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_chttp2_write_cb** list, - grpc_error* error) { +static void flush_write_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_chttp2_write_cb** list, grpc_error* error) { while (*list) { grpc_chttp2_write_cb* cb = *list; *list = cb->next; - grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, - GRPC_ERROR_REF(error), + grpc_chttp2_complete_closure_step(t, s, &cb->closure, GRPC_ERROR_REF(error), "on_write_finished_cb"); cb->next = t->write_cb_pool; t->write_cb_pool = cb; @@ -2162,37 +2057,34 @@ static void flush_write_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, GRPC_ERROR_UNREF(error); } -void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_fail_pending_writes(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error) { error = removal_error(error, s, "Pending writes failed due to stream closure"); s->send_initial_metadata = nullptr; - grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_REF(error), - "send_initial_metadata_finished"); + grpc_chttp2_complete_closure_step(t, s, &s->send_initial_metadata_finished, + GRPC_ERROR_REF(error), + "send_initial_metadata_finished"); s->send_trailing_metadata = nullptr; - grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->send_trailing_metadata_finished, - GRPC_ERROR_REF(error), "send_trailing_metadata_finished"); + grpc_chttp2_complete_closure_step(t, s, &s->send_trailing_metadata_finished, + GRPC_ERROR_REF(error), + "send_trailing_metadata_finished"); s->fetching_send_message = nullptr; - grpc_chttp2_complete_closure_step( - exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_REF(error), - "fetching_send_message_finished"); - flush_write_list(exec_ctx, t, s, &s->on_write_finished_cbs, - GRPC_ERROR_REF(error)); - flush_write_list(exec_ctx, t, s, &s->on_flow_controlled_cbs, error); + grpc_chttp2_complete_closure_step(t, s, &s->fetching_send_message_finished, + GRPC_ERROR_REF(error), + "fetching_send_message_finished"); + flush_write_list(t, s, &s->on_write_finished_cbs, GRPC_ERROR_REF(error)); + flush_write_list(t, s, &s->on_flow_controlled_cbs, error); } -void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error) { if (s->read_closed && s->write_closed) { /* already closed */ - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); GRPC_ERROR_UNREF(error); return; } @@ -2206,20 +2098,20 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, if (close_writes && !s->write_closed) { s->write_closed_error = GRPC_ERROR_REF(error); s->write_closed = true; - grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error)); + grpc_chttp2_fail_pending_writes(t, s, GRPC_ERROR_REF(error)); } if (s->read_closed && s->write_closed) { became_closed = true; grpc_error* overall_error = removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { - remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error)); + remove_stream(t, s->id, GRPC_ERROR_REF(overall_error)); } else { /* Purge streams waiting on concurrency still waiting for id assignment */ grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } if (overall_error != GRPC_ERROR_NONE) { - grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); + grpc_chttp2_fake_status(t, s, overall_error); } } if (closed_read) { @@ -2228,18 +2120,18 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; } } - grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(t, s); + grpc_chttp2_maybe_complete_recv_message(t, s); } if (became_closed) { - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2"); + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2"); } GRPC_ERROR_UNREF(error); } -static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_error* error) { +static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_error* error) { grpc_slice hdr; grpc_slice status_hdr; grpc_slice http_status_hdr; @@ -2249,8 +2141,8 @@ static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, uint32_t len = 0; grpc_status_code grpc_status; grpc_slice slice; - grpc_error_get_status(exec_ctx, error, s->deadline, &grpc_status, &slice, - nullptr, nullptr); + grpc_error_get_status(error, s->deadline, &grpc_status, &slice, nullptr, + nullptr); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); @@ -2392,13 +2284,11 @@ static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API); + grpc_chttp2_mark_stream_closed(t, s, 1, 1, error); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_CLOSE_FROM_API); } typedef struct { - grpc_exec_ctx* exec_ctx; grpc_error* error; grpc_chttp2_transport* t; } cancel_stream_cb_args; @@ -2406,13 +2296,11 @@ typedef struct { static void cancel_stream_cb(void* user_data, uint32_t key, void* stream) { cancel_stream_cb_args* args = (cancel_stream_cb_args*)user_data; grpc_chttp2_stream* s = (grpc_chttp2_stream*)stream; - grpc_chttp2_cancel_stream(args->exec_ctx, args->t, s, - GRPC_ERROR_REF(args->error)); + grpc_chttp2_cancel_stream(args->t, s, GRPC_ERROR_REF(args->error)); } -static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error) { - cancel_stream_cb_args args = {exec_ctx, error, t}; +static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error) { + cancel_stream_cb_args args = {error, t}; grpc_chttp2_stream_map_for_each(&t->stream_map, cancel_stream_cb, &args); GRPC_ERROR_UNREF(error); } @@ -2422,14 +2310,14 @@ static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, */ template -static void WithUrgency(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, +static void WithUrgency(grpc_chttp2_transport* t, grpc_core::chttp2::FlowControlAction::Urgency urgency, grpc_chttp2_initiate_write_reason reason, F action) { switch (urgency) { case grpc_core::chttp2::FlowControlAction::Urgency::NO_ACTION_NEEDED: break; case grpc_core::chttp2::FlowControlAction::Urgency::UPDATE_IMMEDIATELY: - grpc_chttp2_initiate_write(exec_ctx, t, reason); + grpc_chttp2_initiate_write(t, reason); // fallthrough case grpc_core::chttp2::FlowControlAction::Urgency::QUEUE_UPDATE: action(); @@ -2438,31 +2326,27 @@ static void WithUrgency(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, } void grpc_chttp2_act_on_flowctl_action( - grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, + const grpc_core::chttp2::FlowControlAction& action, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - WithUrgency( - exec_ctx, t, action.send_stream_update(), - GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL, - [exec_ctx, t, s]() { grpc_chttp2_mark_stream_writable(exec_ctx, t, s); }); - WithUrgency(exec_ctx, t, action.send_transport_update(), + WithUrgency(t, action.send_stream_update(), + GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL, + [t, s]() { grpc_chttp2_mark_stream_writable(t, s); }); + WithUrgency(t, action.send_transport_update(), GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL, []() {}); - WithUrgency(exec_ctx, t, action.send_initial_window_update(), - GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, - [exec_ctx, t, &action]() { - queue_setting_update(exec_ctx, t, + WithUrgency(t, action.send_initial_window_update(), + GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [t, &action]() { + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, action.initial_window_size()); }); - WithUrgency( - exec_ctx, t, action.send_max_frame_size_update(), - GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [exec_ctx, t, &action]() { - queue_setting_update(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, - action.max_frame_size()); - }); + WithUrgency(t, action.send_max_frame_size_update(), + GRPC_CHTTP2_INITIATE_WRITE_SEND_SETTINGS, [t, &action]() { + queue_setting_update(t, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, + action.max_frame_size()); + }); } -static grpc_error* try_http_parsing(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { grpc_http_parser parser; size_t i = 0; grpc_error* error = GRPC_ERROR_NONE; @@ -2491,8 +2375,7 @@ static grpc_error* try_http_parsing(grpc_exec_ctx* exec_ctx, return error; } -static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void read_action_locked(void* tp, grpc_error* error) { GPR_TIMER_BEGIN("reading_action_locked", 0); grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; @@ -2516,11 +2399,10 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, for (; i < t->read_buffer.count && errors[1] == GRPC_ERROR_NONE; i++) { t->flow_control->bdp_estimator()->AddIncomingBytes( (int64_t)GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); - errors[1] = - grpc_chttp2_perform_read(exec_ctx, t, t->read_buffer.slices[i]); + errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]); } if (errors[1] != GRPC_ERROR_NONE) { - errors[2] = try_http_parsing(exec_ctx, t); + errors[2] = try_http_parsing(t); GRPC_ERROR_UNREF(error); error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed parsing HTTP/2", errors, GPR_ARRAY_SIZE(errors)); @@ -2535,10 +2417,9 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, if (t->initial_window_update > 0) { grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_stalled_by_stream(t, &s)) { - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_mark_stream_writable(t, s); grpc_chttp2_initiate_write( - exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING); + t, GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING); } } t->initial_window_update = 0; @@ -2559,22 +2440,21 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, error = grpc_error_add_child(error, GRPC_ERROR_REF(t->goaway_error)); } - close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error)); + close_transport_locked(t, GRPC_ERROR_REF(error)); t->endpoint_reading = 0; } else if (t->closed_with_error == GRPC_ERROR_NONE) { keep_reading = true; GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading"); } - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(&t->read_buffer); if (keep_reading) { - grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer, - &t->read_action_locked); - grpc_chttp2_act_on_flowctl_action(exec_ctx, t->flow_control->MakeAction(), - t, nullptr); - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keep_reading"); + grpc_endpoint_read(t->ep, &t->read_buffer, &t->read_action_locked); + grpc_chttp2_act_on_flowctl_action(t->flow_control->MakeAction(), t, + nullptr); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "keep_reading"); } else { - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "reading_action"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action"); } GPR_TIMER_END("post_reading_action_locked", 0); @@ -2586,15 +2466,12 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, // t is reffed prior to calling the first time, and once the callback chain // that kicks off finishes, it's unreffed -static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) { t->flow_control->bdp_estimator()->SchedulePing(); - send_ping_locked(exec_ctx, t, &t->start_bdp_ping_locked, - &t->finish_bdp_ping_locked); + send_ping_locked(t, &t->start_bdp_ping_locked, &t->finish_bdp_ping_locked); } -static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void start_bdp_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, @@ -2602,42 +2479,39 @@ static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, } /* Reset the keepalive ping timer */ if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) { - grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); + grpc_timer_cancel(&t->keepalive_ping_timer); } t->flow_control->bdp_estimator()->StartPing(); } -static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, - grpc_error* error) { +static void finish_bdp_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); } if (error != GRPC_ERROR_NONE) { - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); return; } - grpc_millis next_ping = - t->flow_control->bdp_estimator()->CompletePing(exec_ctx); - grpc_chttp2_act_on_flowctl_action( - exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, nullptr); + grpc_millis next_ping = t->flow_control->bdp_estimator()->CompletePing(); + grpc_chttp2_act_on_flowctl_action(t->flow_control->PeriodicUpdate(), t, + nullptr); GPR_ASSERT(!t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = true; - grpc_timer_init(exec_ctx, &t->next_bdp_ping_timer, next_ping, + grpc_timer_init(&t->next_bdp_ping_timer, next_ping, &t->next_bdp_ping_timer_expired_locked); } -static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, - void* tp, grpc_error* error) { +static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); return; } - schedule_bdp_ping_locked(exec_ctx, t); + schedule_bdp_ping_locked(t); } void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, @@ -2698,8 +2572,7 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } } -static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void init_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { @@ -2709,59 +2582,55 @@ static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_chttp2_stream_map_size(&t->stream_map) > 0) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end"); - send_ping_locked(exec_ctx, t, &t->start_keepalive_ping_locked, + send_ping_locked(t, &t->start_keepalive_ping_locked, &t->finish_keepalive_ping_locked); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); } else { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, - grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } else if (error == GRPC_ERROR_CANCELLED) { /* The keepalive ping timer may be cancelled by bdp */ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, - grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "init keepalive ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping"); } -static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void start_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); - grpc_timer_init(exec_ctx, &t->keepalive_watchdog_timer, - grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, + grpc_timer_init(&t->keepalive_watchdog_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->keepalive_watchdog_fired_locked); } -static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; - grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer); + grpc_timer_cancel(&t->keepalive_watchdog_timer); GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(exec_ctx, &t->keepalive_ping_timer, - grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } } - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive ping end"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive ping end"); } -static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; close_transport_locked( - exec_ctx, t, + t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "keepalive watchdog timeout"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL)); @@ -2774,71 +2643,67 @@ static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); } } - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive watchdog"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog"); } /******************************************************************************* * CALLBACK LOOP */ -static void connectivity_state_set(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void connectivity_state_set(grpc_chttp2_transport* t, grpc_connectivity_state state, grpc_error* error, const char* reason) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_DEBUG, "set connectivity_state=%d", state)); - grpc_connectivity_state_set(exec_ctx, &t->channel_callback.state_tracker, - state, error, reason); + grpc_connectivity_state_set(&t->channel_callback.state_tracker, state, error, + reason); } /******************************************************************************* * POLLSET STUFF */ -static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_pollset* pollset) { +static void set_pollset(grpc_transport* gt, grpc_stream* gs, + grpc_pollset* pollset) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_endpoint_add_to_pollset(exec_ctx, t->ep, pollset); + grpc_endpoint_add_to_pollset(t->ep, pollset); } -static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_pollset_set* pollset_set) { +static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, + grpc_pollset_set* pollset_set) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, pollset_set); + grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); } /******************************************************************************* * BYTE STREAM */ -static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void reset_byte_stream(void* arg, grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)arg; s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { - grpc_chttp2_maybe_complete_recv_message(exec_ctx, s->t, s); - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, s->t, s); + grpc_chttp2_maybe_complete_recv_message(s->t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(s->t, s); } else { GPR_ASSERT(error != GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_REF(error)); s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_NONE; - grpc_chttp2_cancel_stream(exec_ctx, s->t, s, GRPC_ERROR_REF(error)); + grpc_chttp2_cancel_stream(s->t, s, GRPC_ERROR_REF(error)); s->byte_stream_error = GRPC_ERROR_REF(error); } } -static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, - grpc_chttp2_incoming_byte_stream* bs) { +static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs) { if (gpr_unref(&bs->refs)) { gpr_free(bs); } } -static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, - void* argp, +static void incoming_byte_stream_next_locked(void* argp, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)argp; @@ -2849,30 +2714,29 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, if (!s->read_closed) { s->flow_control->IncomingByteStreamUpdate(bs->next_action.max_size_hint, cur_length); - grpc_chttp2_act_on_flowctl_action(exec_ctx, s->flow_control->MakeAction(), - t, s); + grpc_chttp2_act_on_flowctl_action(s->flow_control->MakeAction(), t, s); } GPR_ASSERT(s->unprocessed_incoming_frames_buffer.length == 0); if (s->frame_storage.length > 0) { grpc_slice_buffer_swap(&s->frame_storage, &s->unprocessed_incoming_frames_buffer); s->unprocessed_incoming_frames_decompressed = false; - GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(bs->next_action.on_complete, GRPC_ERROR_NONE); } else if (s->byte_stream_error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, + GRPC_CLOSURE_SCHED(bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); if (s->data_parser.parsing_frame != nullptr) { - incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); + incoming_byte_stream_unref(s->data_parser.parsing_frame); s->data_parser.parsing_frame = nullptr; } } else if (s->read_closed) { if (bs->remaining_bytes != 0) { s->byte_stream_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); - GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, + GRPC_CLOSURE_SCHED(bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); if (s->data_parser.parsing_frame != nullptr) { - incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); + incoming_byte_stream_unref(s->data_parser.parsing_frame); s->data_parser.parsing_frame = nullptr; } } else { @@ -2882,11 +2746,10 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, } else { s->on_next = bs->next_action.on_complete; } - incoming_byte_stream_unref(exec_ctx, bs); + incoming_byte_stream_unref(bs); } -static bool incoming_byte_stream_next(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { GPR_TIMER_BEGIN("incoming_byte_stream_next", 0); @@ -2901,7 +2764,6 @@ static bool incoming_byte_stream_next(grpc_exec_ctx* exec_ctx, bs->next_action.max_size_hint = max_size_hint; bs->next_action.on_complete = on_complete; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&bs->next_action.closure, incoming_byte_stream_next_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), @@ -2911,8 +2773,7 @@ static bool incoming_byte_stream_next(grpc_exec_ctx* exec_ctx, } } -static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { GPR_TIMER_BEGIN("incoming_byte_stream_pull", 0); grpc_chttp2_incoming_byte_stream* bs = @@ -2948,31 +2809,28 @@ static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, } } error = grpc_deframe_unprocessed_incoming_frames( - exec_ctx, &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, - slice, nullptr); + &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, slice, + nullptr); if (error != GRPC_ERROR_NONE) { return error; } } else { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); - GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); return error; } GPR_TIMER_END("incoming_byte_stream_pull", 0); return GRPC_ERROR_NONE; } -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, - void* byte_stream, +static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored); -static void incoming_byte_stream_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream) { +static void incoming_byte_stream_destroy(grpc_byte_stream* byte_stream) { GPR_TIMER_BEGIN("incoming_byte_stream_destroy", 0); grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&bs->destroy_action, incoming_byte_stream_destroy_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), @@ -2981,30 +2839,28 @@ static void incoming_byte_stream_destroy(grpc_exec_ctx* exec_ctx, } static void incoming_byte_stream_publish_error( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_error* error) { + grpc_chttp2_incoming_byte_stream* bs, grpc_error* error) { grpc_chttp2_stream* s = bs->stream; GPR_ASSERT(error != GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_REF(error)); s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_REF(error); - grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream, - GRPC_ERROR_REF(error)); + grpc_chttp2_cancel_stream(bs->transport, bs->stream, GRPC_ERROR_REF(error)); } grpc_error* grpc_chttp2_incoming_byte_stream_push( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_slice slice, grpc_slice* slice_out) { + grpc_chttp2_incoming_byte_stream* bs, grpc_slice slice, + grpc_slice* slice_out) { grpc_chttp2_stream* s = bs->stream; if (bs->remaining_bytes < GRPC_SLICE_LENGTH(slice)) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many bytes in stream"); - GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); - grpc_slice_unref_internal(exec_ctx, slice); + GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); + grpc_slice_unref_internal(slice); return error; } else { bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice); @@ -3016,8 +2872,8 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( } grpc_error* grpc_chttp2_incoming_byte_stream_finished( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_error* error, bool reset_on_error) { + grpc_chttp2_incoming_byte_stream* bs, grpc_error* error, + bool reset_on_error) { grpc_chttp2_stream* s = bs->stream; if (error == GRPC_ERROR_NONE) { @@ -3026,27 +2882,25 @@ grpc_error* grpc_chttp2_incoming_byte_stream_finished( } } if (error != GRPC_ERROR_NONE && reset_on_error) { - GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); } - incoming_byte_stream_unref(exec_ctx, bs); + incoming_byte_stream_unref(bs); return error; } -static void incoming_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static void incoming_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - exec_ctx, bs, error, true /* reset_on_error */)); + bs, error, true /* reset_on_error */)); } static const grpc_byte_stream_vtable grpc_chttp2_incoming_byte_stream_vtable = { incoming_byte_stream_next, incoming_byte_stream_pull, incoming_byte_stream_shutdown, incoming_byte_stream_destroy}; -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, - void* byte_stream, +static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = (grpc_chttp2_incoming_byte_stream*)byte_stream; @@ -3054,15 +2908,15 @@ static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t = s->t; GPR_ASSERT(bs->base.vtable == &grpc_chttp2_incoming_byte_stream_vtable); - incoming_byte_stream_unref(exec_ctx, bs); + incoming_byte_stream_unref(bs); s->pending_byte_stream = false; - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); } grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( - grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, - uint32_t frame_size, uint32_t flags) { + grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, + uint32_t flags) { grpc_chttp2_incoming_byte_stream* incoming_byte_stream = (grpc_chttp2_incoming_byte_stream*)gpr_malloc( sizeof(*incoming_byte_stream)); @@ -3082,30 +2936,25 @@ grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( * RESOURCE QUOTAS */ -static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void post_benign_reclaimer(grpc_chttp2_transport* t) { if (!t->benign_reclaimer_registered) { t->benign_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer"); - grpc_resource_user_post_reclaimer(exec_ctx, - grpc_endpoint_get_resource_user(t->ep), + grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), false, &t->benign_reclaimer_locked); } } -static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void post_destructive_reclaimer(grpc_chttp2_transport* t) { if (!t->destructive_reclaimer_registered) { t->destructive_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer"); - grpc_resource_user_post_reclaimer(exec_ctx, - grpc_endpoint_get_resource_user(t->ep), + grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), true, &t->destructive_reclaimer_locked); } } -static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void benign_reclaimer_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; if (error == GRPC_ERROR_NONE && grpc_chttp2_stream_map_size(&t->stream_map) == 0) { @@ -3115,7 +2964,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory", t->peer_string); } - send_goaway(exec_ctx, t, + send_goaway(t, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); @@ -3128,13 +2977,12 @@ static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, t->benign_reclaimer_registered = false; if (error != GRPC_ERROR_CANCELLED) { grpc_resource_user_finish_reclamation( - exec_ctx, grpc_endpoint_get_resource_user(t->ep)); + grpc_endpoint_get_resource_user(t->ep)); } - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "benign_reclaimer"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "benign_reclaimer"); } -static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destructive_reclaimer_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; size_t n = grpc_chttp2_stream_map_size(&t->stream_map); t->destructive_reclaimer_registered = false; @@ -3146,7 +2994,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, s->id); } grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); @@ -3155,14 +3003,14 @@ static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, there are more streams left, we can immediately post a new reclaimer in case the resource quota needs to free more memory */ - post_destructive_reclaimer(exec_ctx, t); + post_destructive_reclaimer(t); } } if (error != GRPC_ERROR_CANCELLED) { grpc_resource_user_finish_reclamation( - exec_ctx, grpc_endpoint_get_resource_user(t->ep)); + grpc_endpoint_get_resource_user(t->ep)); } - GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destructive_reclaimer"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer"); } /******************************************************************************* @@ -3216,8 +3064,7 @@ const char* grpc_chttp2_initiate_write_reason_string( GPR_UNREACHABLE_CODE(return "unknown"); } -static grpc_endpoint* chttp2_get_endpoint(grpc_exec_ctx* exec_ctx, - grpc_transport* t) { +static grpc_endpoint* chttp2_get_endpoint(grpc_transport* t) { return ((grpc_chttp2_transport*)t)->ep; } @@ -3235,17 +3082,16 @@ static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), static const grpc_transport_vtable* get_vtable(void) { return &vtable; } grpc_transport* grpc_create_chttp2_transport( - grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, - grpc_endpoint* ep, bool is_client) { + const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)gpr_zalloc(sizeof(grpc_chttp2_transport)); - init_transport(exec_ctx, t, channel_args, ep, is_client); + init_transport(t, channel_args, ep, is_client); return &t->base; } void grpc_chttp2_transport_start_reading( - grpc_exec_ctx* exec_ctx, grpc_transport* transport, - grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings) { + grpc_transport* transport, grpc_slice_buffer* read_buffer, + grpc_closure* notify_on_receive_settings) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ @@ -3254,5 +3100,5 @@ void grpc_chttp2_transport_start_reading( gpr_free(read_buffer); } t->notify_on_receive_settings = notify_on_receive_settings; - GRPC_CLOSURE_SCHED(exec_ctx, &t->read_action_locked, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&t->read_action_locked, GRPC_ERROR_NONE); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index bd72e07bab..596ababb19 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -28,15 +28,14 @@ extern grpc_core::TraceFlag grpc_trace_http2_stream_state; extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount; grpc_transport* grpc_create_chttp2_transport( - grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, - grpc_endpoint* ep, bool is_client); + const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client); /// Takes ownership of \a read_buffer, which (if non-NULL) contains /// leftover bytes previously read from the endpoint (e.g., by handshakers). /// If non-null, \a notify_on_receive_settings will be scheduled when /// HTTP/2 settings are received from the peer. void grpc_chttp2_transport_start_reading( - grpc_exec_ctx* exec_ctx, grpc_transport* transport, - grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings); + grpc_transport* transport, grpc_slice_buffer* read_buffer, + grpc_closure* notify_on_receive_settings); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H */ diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 8a057bd9ff..ca48cc7e0a 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -149,8 +149,7 @@ void FlowControlAction::Trace(grpc_chttp2_transport* t) const { gpr_free(mf_str); } -TransportFlowControl::TransportFlowControl(grpc_exec_ctx* exec_ctx, - const grpc_chttp2_transport* t, +TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t, bool enable_bdp_probe) : t_(t), enable_bdp_probe_(enable_bdp_probe), @@ -163,7 +162,7 @@ TransportFlowControl::TransportFlowControl(grpc_exec_ctx* exec_ctx, .set_min_control_value(-1) .set_max_control_value(25) .set_integral_range(10)), - last_pid_update_(grpc_exec_ctx_now(exec_ctx)) {} + last_pid_update_(grpc_core::ExecCtx::Get()->Now()) {} uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) { FlowControlTrace trace("t updt sent", this, nullptr); @@ -308,9 +307,8 @@ double TransportFlowControl::TargetLogBdp() { 1 + log2(bdp_estimator_.EstimateBdp())); } -double TransportFlowControl::SmoothLogBdp(grpc_exec_ctx* exec_ctx, - double value) { - grpc_millis now = grpc_exec_ctx_now(exec_ctx); +double TransportFlowControl::SmoothLogBdp(double value) { + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); double bdp_error = value - pid_controller_.last_control_value(); const double dt = (double)(now - last_pid_update_) * 1e-3; last_pid_update_ = now; @@ -331,15 +329,14 @@ FlowControlAction::Urgency TransportFlowControl::DeltaUrgency( } } -FlowControlAction TransportFlowControl::PeriodicUpdate( - grpc_exec_ctx* exec_ctx) { +FlowControlAction TransportFlowControl::PeriodicUpdate() { FlowControlAction action; if (enable_bdp_probe_) { // get bdp estimate and update initial_window accordingly. // target might change based on how much memory pressure we are under // TODO(ncteisen): experiment with setting target to be huge under low // memory pressure. - const double target = pow(2, SmoothLogBdp(exec_ctx, TargetLogBdp())); + const double target = pow(2, SmoothLogBdp(TargetLogBdp())); // Though initial window 'could' drop to 0, we keep the floor at 128 target_initial_window_size_ = (int32_t)GPR_CLAMP(target, 128, INT32_MAX); diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 2515c94309..8306047dbc 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -134,8 +134,7 @@ class FlowControlTrace { class TransportFlowControl { public: - TransportFlowControl(grpc_exec_ctx* exec_ctx, const grpc_chttp2_transport* t, - bool enable_bdp_probe); + TransportFlowControl(const grpc_chttp2_transport* t, bool enable_bdp_probe); ~TransportFlowControl() {} bool bdp_probe() const { return enable_bdp_probe_; } @@ -153,7 +152,7 @@ class TransportFlowControl { // Call periodically (at a low-ish rate, 100ms - 10s makes sense) // to perform more complex flow control calculations and return an action // to let chttp2 change its parameters - FlowControlAction PeriodicUpdate(grpc_exec_ctx* exec_ctx); + FlowControlAction PeriodicUpdate(); void StreamSentData(int64_t size) { remote_window_ -= size; } @@ -212,7 +211,7 @@ class TransportFlowControl { private: friend class ::grpc::testing::TrickledCHTTP2; double TargetLogBdp(); - double SmoothLogBdp(grpc_exec_ctx* exec_ctx, double value); + double SmoothLogBdp(double value); FlowControlAction::Urgency DeltaUrgency(int32_t value, grpc_chttp2_setting_id setting_id); diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index f0c3b55792..9b3a6acc9e 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -36,11 +36,10 @@ grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser) { return GRPC_ERROR_NONE; } -void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_data_parser* parser) { +void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser* parser) { if (parser->parsing_frame != nullptr) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - exec_ctx, parser->parsing_frame, + parser->parsing_frame, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"), false)); } GRPC_ERROR_UNREF(parser->error); @@ -98,7 +97,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, } grpc_error* grpc_deframe_unprocessed_incoming_frames( - grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, grpc_slice_buffer* slices, grpc_slice* slice_out, grpc_byte_stream** stream_out) { grpc_error* error = GRPC_ERROR_NONE; @@ -118,14 +117,14 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( char* msg; if (cur == end) { - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } switch (p->state) { case GRPC_CHTTP2_DATA_ERROR: p->state = GRPC_CHTTP2_DATA_ERROR; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_REF(p->error); case GRPC_CHTTP2_DATA_FH_0: s->stats.incoming.framing_bytes++; @@ -150,12 +149,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg); p->state = GRPC_CHTTP2_DATA_ERROR; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_REF(p->error); } if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_1; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } /* fallthrough */ @@ -164,7 +163,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size = ((uint32_t)*cur) << 24; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_2; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } /* fallthrough */ @@ -173,7 +172,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size |= ((uint32_t)*cur) << 16; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_3; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } /* fallthrough */ @@ -182,7 +181,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->frame_size |= ((uint32_t)*cur) << 8; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_4; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } /* fallthrough */ @@ -198,11 +197,11 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( message_flags |= GRPC_WRITE_INTERNAL_COMPRESS; } p->parsing_frame = grpc_chttp2_incoming_byte_stream_create( - exec_ctx, t, s, p->frame_size, message_flags); + t, s, p->frame_size, message_flags); *stream_out = &p->parsing_frame->base; if (p->parsing_frame->remaining_bytes == 0) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( - exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true)); + p->parsing_frame, GRPC_ERROR_NONE, true)); p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; } @@ -213,64 +212,64 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( slices, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); } - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; case GRPC_CHTTP2_DATA_FRAME: { GPR_ASSERT(p->parsing_frame != nullptr); GPR_ASSERT(slice_out != nullptr); if (cur == end) { - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); continue; } uint32_t remaining = (uint32_t)(end - cur); if (remaining == p->frame_size) { s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - exec_ctx, p->parsing_frame, + p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)), slice_out))) { - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return error; } if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_finished( - exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) { - grpc_slice_unref_internal(exec_ctx, slice); + p->parsing_frame, GRPC_ERROR_NONE, true))) { + grpc_slice_unref_internal(slice); return error; } p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } else if (remaining < p->frame_size) { s->stats.incoming.data_bytes += remaining; if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - exec_ctx, p->parsing_frame, + p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)), slice_out))) { return error; } p->frame_size -= remaining; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } else { GPR_ASSERT(remaining > p->frame_size); s->stats.incoming.data_bytes += p->frame_size; if (GRPC_ERROR_NONE != (grpc_chttp2_incoming_byte_stream_push( - exec_ctx, p->parsing_frame, + p->parsing_frame, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(cur + p->frame_size - beg)), slice_out))) { - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return error; } if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_finished( - exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) { - grpc_slice_unref_internal(exec_ctx, slice); + p->parsing_frame, GRPC_ERROR_NONE, true))) { + grpc_slice_unref_internal(slice); return error; } p->parsing_frame = nullptr; @@ -279,7 +278,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_buffer_undo_take_first( slices, grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } } @@ -289,19 +288,19 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, +grpc_error* grpc_chttp2_data_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { if (!s->pending_byte_stream) { grpc_slice_ref_internal(slice); grpc_slice_buffer_add(&s->frame_storage, slice); - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(t, s); } else if (s->on_next) { GPR_ASSERT(s->frame_storage.length == 0); grpc_slice_ref_internal(slice); grpc_slice_buffer_add(&s->unprocessed_incoming_frames_buffer, slice); - GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->on_next, GRPC_ERROR_NONE); s->on_next = nullptr; s->unprocessed_incoming_frames_decompressed = false; } else { @@ -310,8 +309,7 @@ grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, } if (is_last && s->received_last_frame) { - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, - GRPC_ERROR_NONE); + grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE); } return GRPC_ERROR_NONE; diff --git a/src/core/ext/transport/chttp2/transport/frame_data.h b/src/core/ext/transport/chttp2/transport/frame_data.h index 4de553ea42..964cc59b1b 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.h +++ b/src/core/ext/transport/chttp2/transport/frame_data.h @@ -54,8 +54,7 @@ typedef struct { /* initialize per-stream state for data frame parsing */ grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser); -void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_data_parser* parser); +void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser* parser); /* start processing a new data frame */ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, @@ -65,7 +64,7 @@ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, /* handle a slice of a data frame - is_last indicates the last slice of a frame */ -grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, +grpc_error* grpc_chttp2_data_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); @@ -76,7 +75,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, grpc_slice_buffer* outbuf); grpc_error* grpc_deframe_unprocessed_incoming_frames( - grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, grpc_slice_buffer* slices, grpc_slice* slice_out, grpc_byte_stream** stream_out); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index a2ce709a2e..b60b4227fe 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -52,8 +52,7 @@ grpc_error* grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser* p, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, - void* parser, +grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -135,7 +134,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { grpc_chttp2_add_incoming_goaway( - exec_ctx, t, (uint32_t)p->error_code, + t, (uint32_t)p->error_code, grpc_slice_new(p->debug_data, p->debug_length, gpr_free)); p->debug_data = nullptr; } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.h b/src/core/ext/transport/chttp2/transport/frame_goaway.h index 743e763342..064d39ac59 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.h +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.h @@ -50,8 +50,7 @@ void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser* p); void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p); grpc_error* grpc_chttp2_goaway_parser_begin_frame( grpc_chttp2_goaway_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, - void* parser, +grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index d0feb51922..298a56721a 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -68,7 +68,7 @@ grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, +grpc_error* grpc_chttp2_ping_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -86,10 +86,10 @@ grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, if (p->byte == 8) { GPR_ASSERT(is_last); if (p->is_ack) { - grpc_chttp2_ack_ping(exec_ctx, t, p->opaque_8bytes); + grpc_chttp2_ack_ping(t, p->opaque_8bytes); } else { if (!t->is_client) { - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_recv_state.last_ping_recv_time + t->ping_policy.min_recv_ping_interval_without_data; @@ -104,7 +104,7 @@ grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, } if (next_allowed_ping > now) { - grpc_chttp2_add_ping_strike(exec_ctx, t); + grpc_chttp2_add_ping_strike(t); } t->ping_recv_state.last_ping_recv_time = now; @@ -116,8 +116,7 @@ grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks)); } t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes; - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); } } } diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.h b/src/core/ext/transport/chttp2/transport/frame_ping.h index 76ca397709..75bacfb1d4 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.h +++ b/src/core/ext/transport/chttp2/transport/frame_ping.h @@ -33,7 +33,7 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes); grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, +grpc_error* grpc_chttp2_ping_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index 05a7f056a4..fee576678d 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -69,8 +69,7 @@ grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, - void* parser, +grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -103,7 +102,7 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); gpr_free(message); } - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, error); + grpc_chttp2_mark_stream_closed(t, s, true, true, error); } return GRPC_ERROR_NONE; diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h index 7dfc5d4578..e76a3ca841 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h @@ -34,8 +34,7 @@ grpc_slice grpc_chttp2_rst_stream_create(uint32_t stream_id, uint32_t code, grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, - void* parser, +grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index de4340fea5..c6c2a6c301 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -108,8 +108,7 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame( } } -grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, void* p, - grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { grpc_chttp2_settings_parser* parser = (grpc_chttp2_settings_parser*)p; @@ -132,7 +131,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, void* p, GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); grpc_slice_buffer_add(&t->qbuf, grpc_chttp2_settings_ack_create()); if (t->notify_on_receive_settings != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, t->notify_on_receive_settings, + GRPC_CLOSURE_SCHED(t->notify_on_receive_settings, GRPC_ERROR_NONE); t->notify_on_receive_settings = nullptr; } diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.h b/src/core/ext/transport/chttp2/transport/frame_settings.h index 36e2ca83a0..ce65402815 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.h +++ b/src/core/ext/transport/chttp2/transport/frame_settings.h @@ -52,8 +52,7 @@ grpc_slice grpc_chttp2_settings_ack_create(void); grpc_error* grpc_chttp2_settings_parser_begin_frame( grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags, uint32_t* settings); -grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, - void* parser, +grpc_error* grpc_chttp2_settings_parser_parse(void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 08407a8e67..418ca144ce 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -64,9 +64,11 @@ grpc_error* grpc_chttp2_window_update_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_window_update_parser_parse( - grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_slice slice, int is_last) { +grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, + grpc_slice slice, + int is_last) { uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; @@ -98,10 +100,9 @@ grpc_error* grpc_chttp2_window_update_parser_parse( if (s != nullptr) { s->flow_control->RecvUpdate(received_update); if (grpc_chttp2_list_remove_stalled_by_stream(t, s)) { - grpc_chttp2_mark_stream_writable(exec_ctx, t, s); + grpc_chttp2_mark_stream_writable(t, s); grpc_chttp2_initiate_write( - exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE); + t, GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE); } } } else { @@ -110,8 +111,7 @@ grpc_error* grpc_chttp2_window_update_parser_parse( bool is_zero = t->flow_control->remote_window() <= 0; if (was_zero && !is_zero) { grpc_chttp2_initiate_write( - exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED); + t, GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED); } } } diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.h b/src/core/ext/transport/chttp2/transport/frame_window_update.h index e031b585fa..a32f1a9d11 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.h +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.h @@ -35,8 +35,10 @@ grpc_slice grpc_chttp2_window_update_create( grpc_error* grpc_chttp2_window_update_parser_begin_frame( grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags); -grpc_error* grpc_chttp2_window_update_parser_parse( - grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_slice slice, int is_last); +grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, + grpc_slice slice, + int is_last); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_WINDOW_UPDATE_H */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index e76d92e31d..3a5692a694 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -206,14 +206,12 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, } /* dummy function */ -static void add_nothing(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, +static void add_nothing(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, size_t elem_size) {} // Add a key to the dynamic table. Both key and value will be added to table at // the decoder. -static void add_key_with_index(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void add_key_with_index(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -240,14 +238,12 @@ static void add_key_with_index(grpc_exec_ctx* exec_ctx, c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { - grpc_slice_unref_internal(exec_ctx, - c->entries_keys[HASH_FRAGMENT_2(key_hash)]); + grpc_slice_unref_internal(c->entries_keys[HASH_FRAGMENT_2(key_hash)]); c->entries_keys[HASH_FRAGMENT_2(key_hash)] = grpc_slice_ref_internal(GRPC_MDKEY(elem)); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; } else { - grpc_slice_unref_internal(exec_ctx, - c->entries_keys[HASH_FRAGMENT_3(key_hash)]); + grpc_slice_unref_internal(c->entries_keys[HASH_FRAGMENT_3(key_hash)]); c->entries_keys[HASH_FRAGMENT_3(key_hash)] = grpc_slice_ref_internal(GRPC_MDKEY(elem)); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; @@ -255,8 +251,7 @@ static void add_key_with_index(grpc_exec_ctx* exec_ctx, } /* add an element to the decoder table */ -static void add_elem_with_index(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void add_elem_with_index(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -286,35 +281,34 @@ static void add_elem_with_index(grpc_exec_ctx* exec_ctx, } else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] < c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) { /* not there: replace oldest */ - GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_2(elem_hash)]); + GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_2(elem_hash)]); c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; } else { /* not there: replace oldest */ - GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_3(elem_hash)]); + GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_3(elem_hash)]); c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; } - add_key_with_index(exec_ctx, c, elem, new_index); + add_key_with_index(c, elem, new_index); } -static void add_elem(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, - grpc_mdelem elem, size_t elem_size) { +static void add_elem(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, + size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); - add_elem_with_index(exec_ctx, c, elem, new_index); + add_elem_with_index(c, elem, new_index); } -static void add_key(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, - grpc_mdelem elem, size_t elem_size) { +static void add_key(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, + size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); - add_key_with_index(exec_ctx, c, elem, new_index); + add_key_with_index(c, elem, new_index); } -static void emit_indexed(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, uint32_t elem_index, +static void emit_indexed(grpc_chttp2_hpack_compressor* c, uint32_t elem_index, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_INDEXED(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_INDEXED(); uint32_t len = GRPC_CHTTP2_VARINT_LENGTH(elem_index, 1); GRPC_CHTTP2_WRITE_VARINT(elem_index, 1, 0x80, add_tiny_header_data(st, len), len); @@ -326,18 +320,17 @@ typedef struct { bool insert_null_before_wire_value; } wire_value; -static wire_value get_wire_value(grpc_exec_ctx* exec_ctx, grpc_mdelem elem, - bool true_binary_enabled) { +static wire_value get_wire_value(grpc_mdelem elem, bool true_binary_enabled) { wire_value wire_val; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { if (true_binary_enabled) { - GRPC_STATS_INC_HPACK_SEND_BINARY(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_BINARY(); wire_val.huffman_prefix = 0x00; wire_val.insert_null_before_wire_value = true; wire_val.data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)); } else { - GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(); wire_val.huffman_prefix = 0x80; wire_val.insert_null_before_wire_value = false; wire_val.data = @@ -345,7 +338,7 @@ static wire_value get_wire_value(grpc_exec_ctx* exec_ctx, grpc_mdelem elem, } } else { /* TODO(ctiller): opportunistically compress non-binary headers */ - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); wire_val.huffman_prefix = 0x00; wire_val.insert_null_before_wire_value = false; wire_val.data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)); @@ -362,14 +355,12 @@ static void add_wire_value(framer_state* st, wire_value v) { add_header_data(st, v.data); } -static void emit_lithdr_incidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); - wire_value value = - get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); + wire_value value = get_wire_value(elem, st->use_true_binary_metadata); size_t len_val = wire_value_length(value); uint32_t len_val_len; GPR_ASSERT(len_val <= UINT32_MAX); @@ -381,14 +372,12 @@ static void emit_lithdr_incidx(grpc_exec_ctx* exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_noidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, framer_state* st) { - GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); - wire_value value = - get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); + wire_value value = get_wire_value(elem, st->use_true_binary_metadata); size_t len_val = wire_value_length(value); uint32_t len_val_len; GPR_ASSERT(len_val <= UINT32_MAX); @@ -400,16 +389,14 @@ static void emit_lithdr_noidx(grpc_exec_ctx* exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, framer_state* st) { GPR_ASSERT(unused_index == 0); - GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(exec_ctx); - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); - wire_value value = - get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); + wire_value value = get_wire_value(elem, st->use_true_binary_metadata); uint32_t len_val = (uint32_t)wire_value_length(value); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); @@ -424,16 +411,14 @@ static void emit_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_noidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, framer_state* st) { GPR_ASSERT(unused_index == 0); - GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(exec_ctx); - GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); + GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(); + GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); - wire_value value = - get_wire_value(exec_ctx, elem, st->use_true_binary_metadata); + wire_value value = get_wire_value(elem, st->use_true_binary_metadata); uint32_t len_val = (uint32_t)wire_value_length(value); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); @@ -462,8 +447,8 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor* c, uint32_t elem_index) { } /* encode an mdelem */ -static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, - grpc_mdelem elem, framer_state* st) { +static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, + framer_state* st) { GPR_ASSERT(GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)) > 0); if (GRPC_SLICE_START_PTR(GRPC_MDKEY(elem))[0] != ':') { /* regular header */ st->seen_regular_header = 1; @@ -496,7 +481,7 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, // Key is not interned, emit literals. if (!key_interned) { - emit_lithdr_noidx_v(exec_ctx, c, 0, elem, st); + emit_lithdr_noidx_v(c, 0, elem, st); return; } @@ -515,16 +500,16 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem) && c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (first cuckoo hash) */ - emit_indexed(exec_ctx, c, - dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), st); + emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), + st); return; } if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem) && c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (second cuckoo hash) */ - emit_indexed(exec_ctx, c, - dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), st); + emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), + st); return; } } @@ -538,10 +523,10 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, decoder_space_usage < MAX_DECODER_SPACE_USAGE && c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >= c->filter_elems_sum / ONE_ON_ADD_PROBABILITY; - void (*maybe_add)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, grpc_mdelem, - size_t) = should_add_elem ? add_elem : add_nothing; - void (*emit)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, uint32_t, - grpc_mdelem, framer_state*) = + void (*maybe_add)(grpc_chttp2_hpack_compressor*, grpc_mdelem, size_t) = + should_add_elem ? add_elem : add_nothing; + void (*emit)(grpc_chttp2_hpack_compressor*, uint32_t, grpc_mdelem, + framer_state*) = should_add_elem ? emit_lithdr_incidx : emit_lithdr_noidx; /* no hits for the elem... maybe there's a key? */ @@ -550,8 +535,8 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ - emit(exec_ctx, c, dynidx(c, indices_key), elem, st); - maybe_add(exec_ctx, c, elem, decoder_space_usage); + emit(c, dynidx(c, indices_key), elem, st); + maybe_add(c, elem, decoder_space_usage); return; } @@ -560,8 +545,8 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ - emit(exec_ctx, c, dynidx(c, indices_key), elem, st); - maybe_add(exec_ctx, c, elem, decoder_space_usage); + emit(c, dynidx(c, indices_key), elem, st); + maybe_add(c, elem, decoder_space_usage); return; } @@ -572,24 +557,23 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, : emit_lithdr_noidx_v; maybe_add = should_add_elem ? add_elem : (should_add_key ? add_key : add_nothing); - emit(exec_ctx, c, 0, elem, st); - maybe_add(exec_ctx, c, elem, decoder_space_usage); + emit(c, 0, elem, st); + maybe_add(c, elem, decoder_space_usage); } #define STRLEN_LIT(x) (sizeof(x) - 1) #define TIMEOUT_KEY "grpc-timeout" -static void deadline_enc(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, grpc_millis deadline, +static void deadline_enc(grpc_chttp2_hpack_compressor* c, grpc_millis deadline, framer_state* st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem mdelem; - grpc_http2_encode_timeout(deadline - grpc_exec_ctx_now(exec_ctx), + grpc_http2_encode_timeout(deadline - grpc_core::ExecCtx::Get()->Now(), timeout_str); - mdelem = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, + mdelem = grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_TIMEOUT, grpc_slice_from_copied_string(timeout_str)); - hpack_enc(exec_ctx, c, mdelem, st); - GRPC_MDELEM_UNREF(exec_ctx, mdelem); + hpack_enc(c, mdelem, st); + GRPC_MDELEM_UNREF(mdelem); } static uint32_t elems_for_bytes(uint32_t bytes) { return (bytes + 31) / 32; } @@ -609,14 +593,13 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { } } -void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c) { +void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor* c) { int i; for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { if (c->entries_keys[i].refcount != &terminal_slice_refcount) { - grpc_slice_unref_internal(exec_ctx, c->entries_keys[i]); + grpc_slice_unref_internal(c->entries_keys[i]); } - GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); + GRPC_MDELEM_UNREF(c->entries_elems[i]); } gpr_free(c->table_elem_size); } @@ -672,8 +655,7 @@ void grpc_chttp2_hpack_compressor_set_max_table_size( } } -void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, grpc_mdelem** extra_headers, size_t extra_headers_size, grpc_metadata_batch* metadata, @@ -699,15 +681,15 @@ void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, emit_advertise_table_size_change(c, &st); } for (size_t i = 0; i < extra_headers_size; ++i) { - hpack_enc(exec_ctx, c, *extra_headers[i], &st); + hpack_enc(c, *extra_headers[i], &st); } grpc_metadata_batch_assert_ok(metadata); for (grpc_linked_mdelem* l = metadata->list.head; l; l = l->next) { - hpack_enc(exec_ctx, c, l->md, &st); + hpack_enc(c, l->md, &st); } grpc_millis deadline = metadata->deadline; if (deadline != GRPC_MILLIS_INF_FUTURE) { - deadline_enc(exec_ctx, c, deadline, &st); + deadline_enc(c, deadline, &st); } finish_frame(&st, 1, options->is_eof); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 08921b19ec..a26514cab0 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -70,8 +70,7 @@ typedef struct { } grpc_chttp2_hpack_compressor; void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c); -void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c); +void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor* c); void grpc_chttp2_hpack_compressor_set_max_table_size( grpc_chttp2_hpack_compressor* c, uint32_t max_table_size); void grpc_chttp2_hpack_compressor_set_max_usable_size( @@ -85,8 +84,7 @@ typedef struct { grpc_transport_one_way_stats* stats; } grpc_encode_header_options; -void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_compressor* c, +void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c, grpc_mdelem** extra_headers, size_t extra_headers_size, grpc_metadata_batch* metadata, diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 18cb27f199..a395ab234c 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -61,96 +61,69 @@ typedef enum { a set of indirect jumps, and so not waste stack space. */ /* forward declarations for parsing states */ -static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, grpc_error* error); -static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); static grpc_error* parse_value_string_with_indexed_key( - grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, - const uint8_t* end); + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); static grpc_error* parse_value_string_with_literal_key( - grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, - const uint8_t* end); + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); -static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end); /* we translate the first byte of a hpack field into one of these decoding @@ -649,8 +622,8 @@ static const uint8_t inverse_base64[256] = { }; /* emission helpers */ -static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, - grpc_mdelem md, int add_to_table) { +static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md, + int add_to_table) { if (grpc_http_trace.enabled()) { char* k = grpc_slice_to_c_string(GRPC_MDKEY(md)); char* v = nullptr; @@ -671,26 +644,25 @@ static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, if (add_to_table) { GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); - grpc_error* err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); + grpc_error* err = grpc_chttp2_hptbl_add(&p->table, md); if (err != GRPC_ERROR_NONE) return err; } if (p->on_header == nullptr) { - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); return GRPC_ERROR_CREATE_FROM_STATIC_STRING("on_header callback not set"); } - p->on_header(exec_ctx, p->on_header_user_data, md); + p->on_header(p->on_header_user_data, md); return GRPC_ERROR_NONE; } -static grpc_slice take_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_slice take_string(grpc_chttp2_hpack_parser* p, grpc_chttp2_hpack_parser_string* str, bool intern) { grpc_slice s; if (!str->copied) { if (intern) { s = grpc_slice_intern(str->data.referenced); - grpc_slice_unref_internal(exec_ctx, str->data.referenced); + grpc_slice_unref_internal(str->data.referenced); } else { s = str->data.referenced; } @@ -708,85 +680,77 @@ static grpc_slice take_string(grpc_exec_ctx* exec_ctx, } /* jump to the next state */ -static grpc_error* parse_next(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_next(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { p->state = *p->next_state++; - return p->state(exec_ctx, p, cur, end); + return p->state(p, cur, end); } /* begin parsing a header: all functionality is encoded into lookup tables above */ -static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_begin; return GRPC_ERROR_NONE; } - return first_byte_action[first_byte_lut[*cur]](exec_ctx, p, cur, end); + return first_byte_action[first_byte_lut[*cur]](p, cur, end); } /* stream dependency and prioritization data: we just skip it */ -static grpc_error* parse_stream_weight(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_weight(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_weight; return GRPC_ERROR_NONE; } - return p->after_prioritization(exec_ctx, p, cur + 1, end); + return p->after_prioritization(p, cur + 1, end); } -static grpc_error* parse_stream_dep3(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep3; return GRPC_ERROR_NONE; } - return parse_stream_weight(exec_ctx, p, cur + 1, end); + return parse_stream_weight(p, cur + 1, end); } -static grpc_error* parse_stream_dep2(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep2; return GRPC_ERROR_NONE; } - return parse_stream_dep3(exec_ctx, p, cur + 1, end); + return parse_stream_dep3(p, cur + 1, end); } -static grpc_error* parse_stream_dep1(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep1; return GRPC_ERROR_NONE; } - return parse_stream_dep2(exec_ctx, p, cur + 1, end); + return parse_stream_dep2(p, cur + 1, end); } -static grpc_error* parse_stream_dep0(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_stream_dep0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep0; return GRPC_ERROR_NONE; } - return parse_stream_dep1(exec_ctx, p, cur + 1, end); + return parse_stream_dep1(p, cur + 1, end); } /* emit an indexed field; jumps to begin the next field on completion */ -static grpc_error* finish_indexed_field(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); @@ -798,24 +762,22 @@ static grpc_error* finish_indexed_field(grpc_exec_ctx* exec_ctx, GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); } GRPC_MDELEM_REF(md); - GRPC_STATS_INC_HPACK_RECV_INDEXED(exec_ctx); - grpc_error* err = on_hdr(exec_ctx, p, md, 0); + GRPC_STATS_INC_HPACK_RECV_INDEXED(); + grpc_error* err = on_hdr(p, md, 0); if (err != GRPC_ERROR_NONE) return err; - return parse_begin(exec_ctx, p, cur, end); + return parse_begin(p, cur, end); } /* parse an indexed field with index < 127 */ -static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { p->dynamic_table_update_allowed = 0; p->index = (*cur) & 0x7f; - return finish_indexed_field(exec_ctx, p, cur + 1, end); + return finish_indexed_field(p, cur + 1, end); } /* parse an indexed field with index >= 127 */ -static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -824,56 +786,52 @@ static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, p->next_state = and_then; p->index = 0x7f; p->parsing.value = &p->index; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } /* finish a literal header with incremental indexing */ -static grpc_error* finish_lithdr_incidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_incidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, true)), - 1); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(p, &p->value, true)), + 1); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* finish a literal header with incremental indexing with no index */ -static grpc_error* finish_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, true)), - 1); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(take_string(p, &p->key, true), + take_string(p, &p->value, true)), + 1); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* parse a literal header with incremental indexing; index < 63 */ -static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_incidx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0x3f; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* parse a literal header with incremental indexing; index >= 63 */ -static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -883,12 +841,11 @@ static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, p->next_state = and_then; p->index = 0x3f; p->parsing.value = &p->index; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } /* parse a literal header with incremental indexing; index = 0 */ -static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -896,56 +853,52 @@ static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, parse_value_string_with_literal_key, finish_lithdr_incidx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* finish a literal header without incremental indexing */ -static grpc_error* finish_lithdr_notidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_notidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* finish a literal header without incremental indexing with index = 0 */ -static grpc_error* finish_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(take_string(p, &p->key, true), + take_string(p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* parse a literal header without incremental indexing; index < 15 */ -static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_notidx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* parse a literal header without incremental indexing; index >= 15 */ -static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -955,12 +908,11 @@ static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } /* parse a literal header without incremental indexing; index == 0 */ -static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -968,56 +920,52 @@ static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, parse_value_string_with_literal_key, finish_lithdr_notidx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* finish a literal header that is never indexed */ -static grpc_error* finish_lithdr_nvridx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_nvridx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)), + take_string(p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* finish a literal header that is never indexed with an extra value */ -static grpc_error* finish_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(exec_ctx); - grpc_error* err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, false)), - 0); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(); + grpc_error* err = + on_hdr(p, + grpc_mdelem_from_slices(take_string(p, &p->key, true), + take_string(p, &p->value, false)), + 0); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* parse a literal header that is never indexed; index < 15 */ -static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_nvridx}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* parse a literal header that is never indexed; index >= 15 */ -static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -1027,12 +975,11 @@ static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } /* parse a literal header that is never indexed; index == 0 */ -static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { @@ -1040,47 +987,44 @@ static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, parse_value_string_with_literal_key, finish_lithdr_nvridx_v}; p->dynamic_table_update_allowed = 0; p->next_state = and_then; - return parse_string_prefix(exec_ctx, p, cur + 1, end); + return parse_string_prefix(p, cur + 1, end); } /* finish parsing a max table size change */ -static grpc_error* finish_max_tbl_size(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* finish_max_tbl_size(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (grpc_http_trace.enabled()) { gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); } grpc_error* err = - grpc_chttp2_hptbl_set_current_table_size(exec_ctx, &p->table, p->index); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_begin(exec_ctx, p, cur, end); + grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_begin(p, cur, end); } /* parse a max table size change, max size < 15 */ -static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (p->dynamic_table_update_allowed == 0) { return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "More than two max table size changes in a single frame")); } p->dynamic_table_update_allowed--; p->index = (*cur) & 0x1f; - return finish_max_tbl_size(exec_ctx, p, cur + 1, end); + return finish_max_tbl_size(p, cur + 1, end); } /* parse a max table size change, max size >= 15 */ -static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { finish_max_tbl_size}; if (p->dynamic_table_update_allowed == 0) { return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "More than two max table size changes in a single frame")); } @@ -1088,12 +1032,11 @@ static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, p->next_state = and_then; p->index = 0x1f; p->parsing.value = &p->index; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } /* a parse error: jam the parse state into parse_error, and return error */ -static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, grpc_error* err) { GPR_ASSERT(err != GRPC_ERROR_NONE); if (p->last_error == GRPC_ERROR_NONE) { @@ -1103,27 +1046,24 @@ static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, return err; } -static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { return GRPC_ERROR_REF(p->last_error); } -static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { GPR_ASSERT(cur != end); char* msg; gpr_asprintf(&msg, "Illegal hpack op code %d", *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(exec_ctx, p, cur, end, err); + return parse_error(p, cur, end, err); } /* parse the 1st byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value0; @@ -1133,16 +1073,15 @@ static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, *p->parsing.value += (*cur) & 0x7f; if ((*cur) & 0x80) { - return parse_value1(exec_ctx, p, cur + 1, end); + return parse_value1(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } } /* parse the 2nd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value1; @@ -1152,16 +1091,15 @@ static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 7; if ((*cur) & 0x80) { - return parse_value2(exec_ctx, p, cur + 1, end); + return parse_value2(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } } /* parse the 3rd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value2; @@ -1171,16 +1109,15 @@ static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 14; if ((*cur) & 0x80) { - return parse_value3(exec_ctx, p, cur + 1, end); + return parse_value3(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } } /* parse the 4th byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_value3; @@ -1190,16 +1127,15 @@ static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 21; if ((*cur) & 0x80) { - return parse_value4(exec_ctx, p, cur + 1, end); + return parse_value4(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } } /* parse the 5th byte of a varint into p->parsing.value depending on the byte, we may overflow, and care must be taken */ -static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { uint8_t c; uint32_t cur_value; @@ -1225,9 +1161,9 @@ static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, *p->parsing.value = cur_value + add_value; if ((*cur) & 0x80) { - return parse_value5up(exec_ctx, p, cur + 1, end); + return parse_value5up(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } error: @@ -1237,14 +1173,13 @@ error: *p->parsing.value, *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(exec_ctx, p, cur, end, err); + return parse_error(p, cur, end, err); } /* parse any trailing bytes in a varint: it's possible to append an arbitrary number of 0x80's and not affect the value - a zero will terminate - and anything else will overflow */ -static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { while (cur != end && *cur == 0x80) { ++cur; @@ -1256,7 +1191,7 @@ static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, } if (*cur == 0) { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } char* msg; @@ -1266,12 +1201,11 @@ static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, *p->parsing.value, *cur); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(exec_ctx, p, cur, end, err); + return parse_error(p, cur, end, err); } /* parse a string prefix */ -static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_string_prefix; @@ -1282,9 +1216,9 @@ static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, p->huff = (*cur) >> 7; if (p->strlen == 0x7f) { p->parsing.value = &p->strlen; - return parse_value0(exec_ctx, p, cur + 1, end); + return parse_value0(p, cur + 1, end); } else { - return parse_next(exec_ctx, p, cur + 1, end); + return parse_next(p, cur + 1, end); } } @@ -1303,8 +1237,7 @@ static void append_bytes(grpc_chttp2_hpack_parser_string* str, str->data.copied.length += (uint32_t)length; } -static grpc_error* append_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* append_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { grpc_chttp2_hpack_parser_string* str = p->parsing.str; uint32_t bits; @@ -1322,11 +1255,11 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, /* 'true-binary' case */ ++cur; p->binary = NOT_BINARY; - GRPC_STATS_INC_HPACK_RECV_BINARY(exec_ctx); + GRPC_STATS_INC_HPACK_RECV_BINARY(); append_bytes(str, cur, (size_t)(end - cur)); return GRPC_ERROR_NONE; } - GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(exec_ctx); + GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(); /* fallthrough */ b64_byte0: case B64_BYTE0: @@ -1338,7 +1271,7 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, ++cur; if (bits == 255) return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte0; @@ -1354,7 +1287,7 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, ++cur; if (bits == 255) return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte1; @@ -1370,7 +1303,7 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, ++cur; if (bits == 255) return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte2; @@ -1386,7 +1319,7 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, ++cur; if (bits == 255) return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character")); else if (bits == 64) goto b64_byte3; @@ -1399,12 +1332,11 @@ static grpc_error* append_string(grpc_exec_ctx* exec_ctx, goto b64_byte0; } GPR_UNREACHABLE_CODE(return parse_error( - exec_ctx, p, cur, end, + p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"))); } -static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { uint8_t decoded[2]; uint32_t bits; @@ -1417,7 +1349,7 @@ static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, case B64_BYTE0: break; case B64_BYTE1: - return parse_error(exec_ctx, p, cur, end, + return parse_error(p, cur, end, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "illegal base64 encoding")); /* illegal encoding */ case B64_BYTE2: @@ -1428,7 +1360,7 @@ static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, bits & 0xffff); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(exec_ctx, p, cur, end, err); + return parse_error(p, cur, end, err); } decoded[0] = (uint8_t)(bits >> 16); append_bytes(str, decoded, 1); @@ -1441,7 +1373,7 @@ static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, bits & 0xff); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - return parse_error(exec_ctx, p, cur, end, err); + return parse_error(p, cur, end, err); } decoded[0] = (uint8_t)(bits >> 16); decoded[1] = (uint8_t)(bits >> 8); @@ -1452,14 +1384,13 @@ static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, } /* decode a nibble from a huffman encoded stream */ -static grpc_error* huff_nibble(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, uint8_t nibble) { +static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) { int16_t emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble]; int16_t next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble]; if (emit != -1) { if (emit >= 0 && emit < 256) { uint8_t c = (uint8_t)emit; - grpc_error* err = append_string(exec_ctx, p, &c, (&c) + 1); + grpc_error* err = append_string(p, &c, (&c) + 1); if (err != GRPC_ERROR_NONE) return err; } else { assert(emit == 256); @@ -1470,45 +1401,42 @@ static grpc_error* huff_nibble(grpc_exec_ctx* exec_ctx, } /* decode full bytes from a huffman encoded stream */ -static grpc_error* add_huff_bytes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* add_huff_bytes(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { for (; cur != end; ++cur) { - grpc_error* err = huff_nibble(exec_ctx, p, *cur >> 4); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - err = huff_nibble(exec_ctx, p, *cur & 0xf); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + grpc_error* err = huff_nibble(p, *cur >> 4); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + err = huff_nibble(p, *cur & 0xf); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); } return GRPC_ERROR_NONE; } /* decode some string bytes based on the current decoding mode (huffman or not) */ -static grpc_error* add_str_bytes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* add_str_bytes(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { if (p->huff) { - return add_huff_bytes(exec_ctx, p, cur, end); + return add_huff_bytes(p, cur, end); } else { - return append_string(exec_ctx, p, cur, end); + return append_string(p, cur, end); } } /* parse a string - tries to do large chunks at a time */ -static grpc_error* parse_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, const uint8_t* cur, +static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { size_t remaining = p->strlen - p->strgot; size_t given = (size_t)(end - cur); if (remaining <= given) { - grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + remaining); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - err = finish_str(exec_ctx, p, cur + remaining, end); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_next(exec_ctx, p, cur + remaining, end); + grpc_error* err = add_str_bytes(p, cur, cur + remaining); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + err = finish_str(p, cur + remaining, end); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_next(p, cur + remaining, end); } else { - grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + given); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); + grpc_error* err = add_str_bytes(p, cur, cur + given); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); GPR_ASSERT(given <= UINT32_MAX - p->strgot); p->strgot += (uint32_t)given; p->state = parse_string; @@ -1517,20 +1445,19 @@ static grpc_error* parse_string(grpc_exec_ctx* exec_ctx, } /* begin parsing a string - performs setup, calls parse_string */ -static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && p->current_slice_refcount != nullptr) { - GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); + GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; str->data.referenced.data.refcounted.bytes = (uint8_t*)cur; str->data.referenced.data.refcounted.length = p->strlen; grpc_slice_ref_internal(str->data.referenced); - return parse_next(exec_ctx, p, cur + p->strlen, end); + return parse_next(p, cur + p->strlen, end); } p->strgot = 0; str->copied = true; @@ -1541,9 +1468,9 @@ static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, switch (p->binary) { case NOT_BINARY: if (p->huff) { - GRPC_STATS_INC_HPACK_RECV_HUFFMAN(exec_ctx); + GRPC_STATS_INC_HPACK_RECV_HUFFMAN(); } else { - GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); + GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); } break; case BINARY_BEGIN: @@ -1552,14 +1479,13 @@ static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, default: abort(); } - return parse_string(exec_ctx, p, cur, end); + return parse_string(p, cur, end); } /* parse the key string */ -static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { - return begin_parse_string(exec_ctx, p, cur, end, NOT_BINARY, &p->key); + return begin_parse_string(p, cur, end, NOT_BINARY, &p->key); } /* check if a key represents a binary header or not */ @@ -1586,33 +1512,29 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, } /* parse the value string */ -static grpc_error* parse_value_string(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +static grpc_error* parse_value_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, bool is_binary) { - return begin_parse_string(exec_ctx, p, cur, end, - is_binary ? BINARY_BEGIN : NOT_BINARY, &p->value); + return begin_parse_string(p, cur, end, is_binary ? BINARY_BEGIN : NOT_BINARY, + &p->value); } static grpc_error* parse_value_string_with_indexed_key( - grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, - const uint8_t* end) { + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { bool is_binary = false; grpc_error* err = is_binary_indexed_header(p, &is_binary); - if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); - return parse_value_string(exec_ctx, p, cur, end, is_binary); + if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); + return parse_value_string(p, cur, end, is_binary); } static grpc_error* parse_value_string_with_literal_key( - grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, - const uint8_t* end) { - return parse_value_string(exec_ctx, p, cur, end, is_binary_literal_header(p)); + grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { + return parse_value_string(p, cur, end, is_binary_literal_header(p)); } /* PUBLIC INTERFACE */ -void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p) { +void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p) { p->on_header = nullptr; p->on_header_user_data = nullptr; p->state = parse_begin; @@ -1626,7 +1548,7 @@ void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, p->value.data.copied.length = 0; p->dynamic_table_update_allowed = 2; p->last_error = GRPC_ERROR_NONE; - grpc_chttp2_hptbl_init(exec_ctx, &p->table); + grpc_chttp2_hptbl_init(&p->table); } void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) { @@ -1634,18 +1556,16 @@ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) { p->state = parse_stream_dep0; } -void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p) { - grpc_chttp2_hptbl_destroy(exec_ctx, &p->table); +void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser* p) { + grpc_chttp2_hptbl_destroy(&p->table); GRPC_ERROR_UNREF(p->last_error); - grpc_slice_unref_internal(exec_ctx, p->key.data.referenced); - grpc_slice_unref_internal(exec_ctx, p->value.data.referenced); + grpc_slice_unref_internal(p->key.data.referenced); + grpc_slice_unref_internal(p->value.data.referenced); gpr_free(p->key.data.copied.str); gpr_free(p->value.data.copied.str); } -grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p, grpc_slice slice) { /* max number of bytes to parse at a time... limits call stack depth on * compilers without TCO */ @@ -1656,37 +1576,33 @@ grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; while (start != end && error == GRPC_ERROR_NONE) { uint8_t* target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start); - error = p->state(exec_ctx, p, start, target); + error = p->state(p, start, target); start = target; } p->current_slice_refcount = nullptr; return error; } -typedef void (*maybe_complete_func_type)(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +typedef void (*maybe_complete_func_type)(grpc_chttp2_transport* t, grpc_chttp2_stream* s); static const maybe_complete_func_type maybe_complete_funcs[] = { grpc_chttp2_maybe_complete_recv_initial_metadata, grpc_chttp2_maybe_complete_recv_trailing_metadata}; -static void force_client_rst_stream(grpc_exec_ctx* exec_ctx, void* sp, - grpc_error* error) { +static void force_client_rst_stream(void* sp, grpc_error* error) { grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; grpc_chttp2_transport* t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); - grpc_chttp2_initiate_write(exec_ctx, t, - GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, GRPC_ERROR_NONE); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); + grpc_chttp2_mark_stream_closed(t, s, true, true, GRPC_ERROR_NONE); } - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "final_rst"); + GRPC_CHTTP2_STREAM_UNREF(s, "final_rst"); } -static void parse_stream_compression_md(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static void parse_stream_compression_md(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_metadata_batch* initial_metadata) { if (initial_metadata->idx.named.content_encoding == nullptr || @@ -1698,8 +1614,7 @@ static void parse_stream_compression_md(grpc_exec_ctx* exec_ctx, } } -grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, - void* hpack_parser, +grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { @@ -1708,7 +1623,7 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error* error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); + grpc_error* error = grpc_chttp2_hpack_parser_parse(parser, slice); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; @@ -1731,12 +1646,11 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, /* Process stream compression md element if it exists */ if (s->header_frames_received == 0) { /* Only acts on initial metadata */ - parse_stream_compression_md(exec_ctx, t, s, - &s->metadata_buffer[0].batch); + parse_stream_compression_md(t, s, &s->metadata_buffer[0].batch); } s->published_metadata[s->header_frames_received] = GRPC_METADATA_PUBLISHED_FROM_WIRE; - maybe_complete_funcs[s->header_frames_received](exec_ctx, t, s); + maybe_complete_funcs[s->header_frames_received](t, s); s->header_frames_received++; } if (parser->is_eof) { @@ -1747,13 +1661,11 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, and can avoid the extra write */ GRPC_CHTTP2_STREAM_REF(s, "final_rst"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(force_client_rst_stream, s, grpc_combiner_finally_scheduler(t->combiner)), GRPC_ERROR_NONE); } - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, - GRPC_ERROR_NONE); + grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE); } } parser->on_header = nullptr; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index b4a2b14bdb..060bc5ce9d 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -30,8 +30,7 @@ typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser; typedef grpc_error* (*grpc_chttp2_hpack_parser_state)( - grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* beg, - const uint8_t* end); + grpc_chttp2_hpack_parser* p, const uint8_t* beg, const uint8_t* end); typedef struct { bool copied; @@ -47,7 +46,7 @@ typedef struct { struct grpc_chttp2_hpack_parser { /* user specified callback for each header output */ - void (*on_header)(grpc_exec_ctx* exec_ctx, void* user_data, grpc_mdelem md); + void (*on_header)(void* user_data, grpc_mdelem md); void* on_header_user_data; grpc_error* last_error; @@ -92,21 +91,17 @@ struct grpc_chttp2_hpack_parser { grpc_chttp2_hptbl table; }; -void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p); -void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p); +void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p); +void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser* p); void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p); -grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hpack_parser* p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p, grpc_slice slice); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ -grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, - void* hpack_parser, +grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 75b83b80b6..c325465daa 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -165,7 +165,7 @@ static uint32_t entries_for_bytes(uint32_t bytes) { GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; } -void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { +void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { size_t i; memset(tbl, 0, sizeof(*tbl)); @@ -177,22 +177,19 @@ void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { tbl->static_ents[i - 1] = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(static_table[i].key)), grpc_slice_intern( grpc_slice_from_static_string(static_table[i].value))); } } -void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl) { +void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl* tbl) { size_t i; for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - GRPC_MDELEM_UNREF(exec_ctx, tbl->static_ents[i]); + GRPC_MDELEM_UNREF(tbl->static_ents[i]); } for (i = 0; i < tbl->num_ents; i++) { - GRPC_MDELEM_UNREF(exec_ctx, - tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]); + GRPC_MDELEM_UNREF(tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]); } gpr_free(tbl->ents); } @@ -215,7 +212,7 @@ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, } /* Evict one element from the table */ -static void evict1(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { +static void evict1(grpc_chttp2_hptbl* tbl) { grpc_mdelem first_ent = tbl->ents[tbl->first_ent]; size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(first_ent)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + @@ -224,7 +221,7 @@ static void evict1(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { tbl->mem_used -= (uint32_t)elem_bytes; tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries); tbl->num_ents--; - GRPC_MDELEM_UNREF(exec_ctx, first_ent); + GRPC_MDELEM_UNREF(first_ent); } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { @@ -240,8 +237,7 @@ static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { tbl->first_ent = 0; } -void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, +void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl* tbl, uint32_t max_bytes) { if (tbl->max_bytes == max_bytes) { return; @@ -250,13 +246,12 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes); } while (tbl->mem_used > max_bytes) { - evict1(exec_ctx, tbl); + evict1(tbl); } tbl->max_bytes = max_bytes; } -grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, uint32_t bytes) { if (tbl->current_table_bytes == bytes) { return GRPC_ERROR_NONE; @@ -274,7 +269,7 @@ grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes); } while (tbl->mem_used > bytes) { - evict1(exec_ctx, tbl); + evict1(tbl); } tbl->current_table_bytes = bytes; tbl->max_entries = entries_for_bytes(bytes); @@ -289,8 +284,7 @@ grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, grpc_mdelem md) { +grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { /* determine how many bytes of buffer this entry represents */ size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(md)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(md)) + @@ -320,14 +314,14 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, * empty table. */ while (tbl->num_ents) { - evict1(exec_ctx, tbl); + evict1(tbl); } return GRPC_ERROR_NONE; } /* evict entries to ensure no overflow */ while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) { - evict1(exec_ctx, tbl); + evict1(tbl); } /* copy the finalized entry in */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index aed7b13f0b..189ad1c697 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -69,21 +69,18 @@ typedef struct { } grpc_chttp2_hptbl; /* initialize a hpack table */ -void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); -void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); -void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, +void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl* tbl, uint32_t max_bytes); -grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl* tbl, uint32_t bytes); /* lookup a table entry based on its hpack index */ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, uint32_t index); /* add a table entry to the index */ -grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, - grpc_chttp2_hptbl* tbl, +grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) GRPC_MUST_USE_RESULT; /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index 4461f8c12c..ef0c9ed230 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -33,33 +33,31 @@ void grpc_chttp2_incoming_metadata_buffer_init( } void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer) { - grpc_metadata_batch_destroy(exec_ctx, &buffer->batch); + grpc_chttp2_incoming_metadata_buffer* buffer) { + grpc_metadata_batch_destroy(&buffer->batch); } grpc_error* grpc_chttp2_incoming_metadata_buffer_add( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, - grpc_mdelem elem) { + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( - exec_ctx, &buffer->batch, + &buffer->batch, (grpc_linked_mdelem*)gpr_arena_alloc(buffer->arena, sizeof(grpc_linked_mdelem)), elem); } grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, - grpc_mdelem elem) { + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { for (grpc_linked_mdelem* l = buffer->batch.list.head; l != nullptr; l = l->next) { if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) { - GRPC_MDELEM_UNREF(exec_ctx, l->md); + GRPC_MDELEM_UNREF(l->md); l->md = elem; return GRPC_ERROR_NONE; } } - return grpc_chttp2_incoming_metadata_buffer_add(exec_ctx, buffer, elem); + return grpc_chttp2_incoming_metadata_buffer_add(buffer, elem); } void grpc_chttp2_incoming_metadata_buffer_set_deadline( @@ -68,8 +66,7 @@ void grpc_chttp2_incoming_metadata_buffer_set_deadline( } void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, - grpc_metadata_batch* batch) { + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch) { *batch = buffer->batch; grpc_metadata_batch_init(&buffer->batch); } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index 6f2b81ef6c..b84cd484c4 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -31,16 +31,15 @@ typedef struct { void grpc_chttp2_incoming_metadata_buffer_init( grpc_chttp2_incoming_metadata_buffer* buffer, gpr_arena* arena); void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer); + grpc_chttp2_incoming_metadata_buffer* buffer); void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, - grpc_metadata_batch* batch); + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch); grpc_error* grpc_chttp2_incoming_metadata_buffer_add( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index f6fd6795d0..932f5ba83d 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -282,8 +282,8 @@ struct grpc_chttp2_transport { struct { /* accept stream callback */ - void (*accept_stream)(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_transport* transport, const void* server_data); + void (*accept_stream)(void* user_data, grpc_transport* transport, + const void* server_data); void* accept_stream_user_data; /** connectivity tracking */ @@ -371,9 +371,8 @@ struct grpc_chttp2_transport { /* active parser */ void* parser_data; grpc_chttp2_stream* incoming_stream; - grpc_error* (*parser)(grpc_exec_ctx* exec_ctx, void* parser_user_data, - grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_slice slice, int is_last); + grpc_error* (*parser)(void* parser_user_data, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); grpc_chttp2_write_cb* write_cb_pool; @@ -571,8 +570,7 @@ struct grpc_chttp2_stream { The actual call chain is documented in the implementation of this function. */ -void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason); typedef struct { @@ -585,14 +583,12 @@ typedef struct { } grpc_chttp2_begin_write_result; grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t); -void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error); + grpc_chttp2_transport* t); +void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error); /** Process one slice of incoming data; return 1 if the connection is still viable after reading, or 0 if the connection should be torn down */ -grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, grpc_slice slice); bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t, @@ -640,27 +636,23 @@ bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport* t, // Takes in a flow control action and performs all the needed operations. void grpc_chttp2_act_on_flowctl_action( - grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, + const grpc_core::chttp2::FlowControlAction& action, grpc_chttp2_transport* t, grpc_chttp2_stream* s); /********* End of Flow Control ***************/ grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id); -grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, uint32_t id); -void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text); -void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); +void grpc_chttp2_parsing_become_skip_parser(grpc_chttp2_transport* t); -void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_closure** pclosure, grpc_error* error, const char* desc); @@ -681,94 +673,80 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, else \ stmt -void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, +void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* stream, grpc_error* error); -void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error); -void grpc_chttp2_start_writing(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); +void grpc_chttp2_start_writing(grpc_chttp2_transport* t); #ifndef NDEBUG #define GRPC_CHTTP2_STREAM_REF(stream, reason) \ grpc_chttp2_stream_ref(stream, reason) -#define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ - grpc_chttp2_stream_unref(exec_ctx, stream, reason) +#define GRPC_CHTTP2_STREAM_UNREF(stream, reason) \ + grpc_chttp2_stream_unref(stream, reason) void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason); -void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, - const char* reason); +void grpc_chttp2_stream_unref(grpc_chttp2_stream* s, const char* reason); #else #define GRPC_CHTTP2_STREAM_REF(stream, reason) grpc_chttp2_stream_ref(stream) -#define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ - grpc_chttp2_stream_unref(exec_ctx, stream) +#define GRPC_CHTTP2_STREAM_UNREF(stream, reason) \ + grpc_chttp2_stream_unref(stream) void grpc_chttp2_stream_ref(grpc_chttp2_stream* s); -void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s); +void grpc_chttp2_stream_unref(grpc_chttp2_stream* s); #endif #ifndef NDEBUG #define GRPC_CHTTP2_REF_TRANSPORT(t, r) \ grpc_chttp2_ref_transport(t, r, __FILE__, __LINE__) -#define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) \ - grpc_chttp2_unref_transport(cl, t, r, __FILE__, __LINE__) -void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, const char* reason, +#define GRPC_CHTTP2_UNREF_TRANSPORT(t, r) \ + grpc_chttp2_unref_transport(t, r, __FILE__, __LINE__) +void grpc_chttp2_unref_transport(grpc_chttp2_transport* t, const char* reason, const char* file, int line); void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, const char* file, int line); #else #define GRPC_CHTTP2_REF_TRANSPORT(t, r) grpc_chttp2_ref_transport(t) -#define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) grpc_chttp2_unref_transport(cl, t) -void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); +#define GRPC_CHTTP2_UNREF_TRANSPORT(t, r) grpc_chttp2_unref_transport(t) +void grpc_chttp2_unref_transport(grpc_chttp2_transport* t); void grpc_chttp2_ref_transport(grpc_chttp2_transport* t); #endif grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( - grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, - uint32_t frame_size, uint32_t flags); + grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, + uint32_t flags); grpc_error* grpc_chttp2_incoming_byte_stream_push( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_slice slice, grpc_slice* slice_out); + grpc_chttp2_incoming_byte_stream* bs, grpc_slice slice, + grpc_slice* slice_out); grpc_error* grpc_chttp2_incoming_byte_stream_finished( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_error* error, bool reset_on_error); + grpc_chttp2_incoming_byte_stream* bs, grpc_error* error, + bool reset_on_error); void grpc_chttp2_incoming_byte_stream_notify( - grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, - grpc_error* error); + grpc_chttp2_incoming_byte_stream* bs, grpc_error* error); -void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - uint64_t id); +void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id); /** Add a new ping strike to ping_recv_state.ping_strikes. If ping_recv_state.ping_strikes > ping_policy.max_ping_strikes, it sends GOAWAY with error code ENHANCE_YOUR_CALM and additional debug data resembling "too_many_pings" followed by immediately closing the connection. */ -void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); +void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t); /** add a ref to the stream and add it to the writable list; ref will be dropped in writing.c */ -void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, grpc_chttp2_stream* s, +void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* due_to_error); -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, grpc_chttp2_stream* s); -void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +void grpc_chttp2_fail_pending_writes(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error); /** Set the default keepalive configurations, must only be called at diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 46ec3fbaa6..a56f89cc75 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -31,33 +31,22 @@ #include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" -static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static grpc_error* init_frame_parser(grpc_chttp2_transport* t); +static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, int is_continuation); -static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t); -static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static grpc_error* init_data_frame_parser(grpc_chttp2_transport* t); +static grpc_error* init_rst_stream_parser(grpc_chttp2_transport* t); +static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t); +static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t); +static grpc_error* init_ping_parser(grpc_chttp2_transport* t); +static grpc_error* init_goaway_parser(grpc_chttp2_transport* t); +static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, int is_header); -static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice, int is_last); -grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, grpc_slice slice) { uint8_t* beg = GRPC_SLICE_START_PTR(slice); uint8_t* end = GRPC_SLICE_END_PTR(slice); @@ -182,12 +171,12 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, GPR_ASSERT(cur < end); t->incoming_stream_id |= ((uint32_t)*cur); t->deframe_state = GRPC_DTS_FRAME; - err = init_frame_parser(exec_ctx, t); + err = init_frame_parser(t); if (err != GRPC_ERROR_NONE) { return err; } if (t->incoming_frame_size == 0) { - err = parse_frame_slice(exec_ctx, t, grpc_empty_slice(), 1); + err = parse_frame_slice(t, grpc_empty_slice(), 1); if (err != GRPC_ERROR_NONE) { return err; } @@ -217,7 +206,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, GPR_ASSERT(cur < end); if ((uint32_t)(end - cur) == t->incoming_frame_size) { err = - parse_frame_slice(exec_ctx, t, + parse_frame_slice(t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), (size_t)(end - beg)), 1); @@ -230,7 +219,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { size_t cur_offset = (size_t)(cur - beg); err = parse_frame_slice( - exec_ctx, t, + t, grpc_slice_sub_no_ref(slice, cur_offset, cur_offset + t->incoming_frame_size), 1); @@ -242,7 +231,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, goto dts_fh_0; /* loop */ } else { err = - parse_frame_slice(exec_ctx, t, + parse_frame_slice(t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), (size_t)(end - beg)), 0); @@ -258,8 +247,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, GPR_UNREACHABLE_CODE(return nullptr); } -static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_frame_parser(grpc_chttp2_transport* t) { if (t->is_first_frame && t->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) { char* msg; @@ -291,46 +279,43 @@ static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, gpr_free(msg); return err; } - return init_header_frame_parser(exec_ctx, t, 1); + return init_header_frame_parser(t, 1); } switch (t->incoming_frame_type) { case GRPC_CHTTP2_FRAME_DATA: - return init_data_frame_parser(exec_ctx, t); + return init_data_frame_parser(t); case GRPC_CHTTP2_FRAME_HEADER: - return init_header_frame_parser(exec_ctx, t, 0); + return init_header_frame_parser(t, 0); case GRPC_CHTTP2_FRAME_CONTINUATION: return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Unexpected CONTINUATION frame"); case GRPC_CHTTP2_FRAME_RST_STREAM: - return init_rst_stream_parser(exec_ctx, t); + return init_rst_stream_parser(t); case GRPC_CHTTP2_FRAME_SETTINGS: - return init_settings_frame_parser(exec_ctx, t); + return init_settings_frame_parser(t); case GRPC_CHTTP2_FRAME_WINDOW_UPDATE: - return init_window_update_frame_parser(exec_ctx, t); + return init_window_update_frame_parser(t); case GRPC_CHTTP2_FRAME_PING: - return init_ping_parser(exec_ctx, t); + return init_ping_parser(t); case GRPC_CHTTP2_FRAME_GOAWAY: - return init_goaway_parser(exec_ctx, t); + return init_goaway_parser(t); default: if (grpc_http_trace.enabled()) { gpr_log(GPR_ERROR, "Unknown frame type %02x", t->incoming_frame_type); } - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } } -static grpc_error* skip_parser(grpc_exec_ctx* exec_ctx, void* parser, - grpc_chttp2_transport* t, grpc_chttp2_stream* s, - grpc_slice slice, int is_last) { +static grpc_error* skip_parser(void* parser, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, + int is_last) { return GRPC_ERROR_NONE; } -static void skip_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); -} +static void skip_header(void* tp, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } -static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, int is_header) { if (is_header) { uint8_t is_eoh = t->expect_continuation_stream_id != 0; @@ -346,14 +331,11 @@ static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { - init_skip_frame_parser(exec_ctx, t, - t->parser == grpc_chttp2_header_parser_parse); +void grpc_chttp2_parsing_become_skip_parser(grpc_chttp2_transport* t) { + init_skip_frame_parser(t, t->parser == grpc_chttp2_header_parser_parse); } -static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_data_frame_parser(grpc_chttp2_transport* t) { grpc_chttp2_stream* s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); grpc_error* err = GRPC_ERROR_NONE; @@ -365,17 +347,17 @@ static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, err = s->flow_control->RecvData(t->incoming_frame_size); action = s->flow_control->MakeAction(); } - grpc_chttp2_act_on_flowctl_action(exec_ctx, action, t, s); + grpc_chttp2_act_on_flowctl_action(action, t, s); if (err != GRPC_ERROR_NONE) { goto error_handler; } if (s == nullptr) { - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } s->received_bytes += t->incoming_frame_size; s->stats.incoming.framing_bytes += 9; if (err == GRPC_ERROR_NONE && s->read_closed) { - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } if (err == GRPC_ERROR_NONE) { err = grpc_chttp2_data_parser_begin_frame( @@ -394,13 +376,13 @@ error_handler: } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { /* handle stream errors by closing the stream */ if (s != nullptr) { - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, err); + grpc_chttp2_mark_stream_closed(t, s, true, false, err); } grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, GRPC_HTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } else { return err; } @@ -408,8 +390,7 @@ error_handler: static void free_timeout(void* p) { gpr_free(p); } -static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, - grpc_mdelem md) { +static void on_initial_header(void* tp, grpc_mdelem md) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; grpc_chttp2_stream* s = t->incoming_stream; @@ -455,9 +436,9 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, } if (timeout != GRPC_MILLIS_INF_FUTURE) { grpc_chttp2_incoming_metadata_buffer_set_deadline( - &s->metadata_buffer[0], grpc_exec_ctx_now(exec_ctx) + timeout); + &s->metadata_buffer[0], grpc_core::ExecCtx::Get()->Now() + timeout); } - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } else { const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md); const size_t metadata_size_limit = @@ -469,22 +450,22 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, " vs. %" PRIuPTR ")", new_size, metadata_size_limit); grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "received initial metadata size exceeds limit"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_parsing_become_skip_parser(t); s->seen_error = true; - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } else { - grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( - exec_ctx, &s->metadata_buffer[0], md); + grpc_error* error = + grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[0], md); if (error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(exec_ctx, t, s, error); - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_cancel_stream(t, s, error); + grpc_chttp2_parsing_become_skip_parser(t); s->seen_error = true; - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } } } @@ -492,8 +473,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_TIMER_END("on_initial_header", 0); } -static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, - grpc_mdelem md) { +static void on_trailing_header(void* tp, grpc_mdelem md) { grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; grpc_chttp2_stream* s = t->incoming_stream; @@ -527,30 +507,29 @@ static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, " vs. %" PRIuPTR ")", new_size, metadata_size_limit); grpc_chttp2_cancel_stream( - exec_ctx, t, s, + t, s, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "received trailing metadata size exceeds limit"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_parsing_become_skip_parser(t); s->seen_error = true; - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } else { - grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( - exec_ctx, &s->metadata_buffer[1], md); + grpc_error* error = + grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[1], md); if (error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(exec_ctx, t, s, error); - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_cancel_stream(t, s, error); + grpc_chttp2_parsing_become_skip_parser(t); s->seen_error = true; - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } } GPR_TIMER_END("on_trailing_header", 0); } -static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, +static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, int is_continuation) { uint8_t is_eoh = (t->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; @@ -580,7 +559,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream disbanded before CONTINUATION received")); - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } if (t->is_client) { if ((t->incoming_stream_id & 1) && @@ -590,7 +569,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "ignoring new grpc_chttp2_stream creation on client")); } - grpc_error* err = init_skip_frame_parser(exec_ctx, t, 1); + grpc_error* err = init_skip_frame_parser(t, 1); if (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY) { grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser); } @@ -602,13 +581,13 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, "last grpc_chttp2_stream " "id=%d, new grpc_chttp2_stream id=%d", t->last_new_stream_id, t->incoming_stream_id)); - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } else if ((t->incoming_stream_id & 1) == 0) { GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "ignoring grpc_chttp2_stream with non-client generated index %d", t->incoming_stream_id)); - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } else if (grpc_chttp2_stream_map_size(&t->stream_map) >= t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]) { @@ -616,11 +595,11 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, } t->last_new_stream_id = t->incoming_stream_id; s = t->incoming_stream = - grpc_chttp2_parsing_accept_stream(exec_ctx, t, t->incoming_stream_id); + grpc_chttp2_parsing_accept_stream(t, t->incoming_stream_id); if (s == nullptr) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted")); - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } } else { t->incoming_stream = s; @@ -631,7 +610,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "skipping already closed grpc_chttp2_stream header")); t->incoming_stream = nullptr; - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } t->parser = grpc_chttp2_header_parser_parse; t->parser_data = &t->hpack_parser; @@ -656,7 +635,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, break; case 2: gpr_log(GPR_ERROR, "too many header frames received"); - return init_skip_frame_parser(exec_ctx, t, 1); + return init_skip_frame_parser(t, 1); } t->hpack_parser.on_header_user_data = t; t->hpack_parser.is_boundary = is_eoh; @@ -668,8 +647,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_window_update_frame_parser(grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_window_update_parser_begin_frame( &t->simple.window_update, t->incoming_frame_size, t->incoming_frame_flags); @@ -678,7 +656,7 @@ static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (s == nullptr) { - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } s->stats.incoming.framing_bytes += 9; } @@ -687,8 +665,7 @@ static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_ping_parser(grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_ping_parser_begin_frame( &t->simple.ping, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; @@ -697,15 +674,14 @@ static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_rst_stream_parser(grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_rst_stream_parser_begin_frame( &t->simple.rst_stream, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (!t->incoming_stream) { - return init_skip_frame_parser(exec_ctx, t, 0); + return init_skip_frame_parser(t, 0); } s->stats.incoming.framing_bytes += 9; t->parser = grpc_chttp2_rst_stream_parser_parse; @@ -713,8 +689,7 @@ static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_goaway_parser(grpc_chttp2_transport* t) { grpc_error* err = grpc_chttp2_goaway_parser_begin_frame( &t->goaway_parser, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; @@ -723,8 +698,7 @@ static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static grpc_error* init_settings_frame_parser(grpc_chttp2_transport* t) { if (t->incoming_stream_id != 0) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Settings frame received for grpc_chttp2_stream"); @@ -740,7 +714,7 @@ static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, memcpy(t->settings[GRPC_ACKED_SETTINGS], t->settings[GRPC_SENT_SETTINGS], GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); grpc_chttp2_hptbl_set_max_bytes( - exec_ctx, &t->hpack_parser.table, + &t->hpack_parser.table, t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]); t->sent_local_settings = 0; @@ -750,11 +724,10 @@ static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice, int is_last) { grpc_chttp2_stream* s = t->incoming_stream; - grpc_error* err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); + grpc_error* err = t->parser(t->parser_data, t, s, slice, is_last); if (err == GRPC_ERROR_NONE) { return err; } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { @@ -762,7 +735,7 @@ static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); } - grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); + grpc_chttp2_parsing_become_skip_parser(t); if (s) { s->forced_close_error = err; grpc_slice_buffer_add( diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 204b5a7708..3310f35f5f 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -33,17 +33,15 @@ static void add_to_write_list(grpc_chttp2_write_cb** list, *list = cb; } -static void finish_write_cb(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, grpc_chttp2_write_cb* cb, - grpc_error* error) { - grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, error, +static void finish_write_cb(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_chttp2_write_cb* cb, grpc_error* error) { + grpc_chttp2_complete_closure_step(t, s, &cb->closure, error, "finish_write_cb"); cb->next = t->write_cb_pool; t->write_cb_pool = cb; } -static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, - grpc_chttp2_transport* t) { +static void maybe_initiate_ping(grpc_chttp2_transport* t) { grpc_chttp2_ping_queue* pq = &t->ping_queue; if (grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { /* no ping needed: wait */ @@ -68,7 +66,7 @@ static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, } return; } - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); grpc_millis next_allowed_ping = t->ping_state.last_ping_sent_time + t->ping_policy.min_sent_ping_interval_without_data; @@ -89,20 +87,20 @@ static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, } if (!t->ping_state.is_delayed_ping_timer_set) { t->ping_state.is_delayed_ping_timer_set = true; - grpc_timer_init(exec_ctx, &t->ping_state.delayed_ping_timer, - next_allowed_ping, &t->retry_initiate_ping_locked); + grpc_timer_init(&t->ping_state.delayed_ping_timer, next_allowed_ping, + &t->retry_initiate_ping_locked); } return; } pq->inflight_id = t->ping_ctr; t->ping_ctr++; - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INITIATE]); + GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INITIATE]); grpc_closure_list_move(&pq->lists[GRPC_CHTTP2_PCL_NEXT], &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); grpc_slice_buffer_add(&t->outbuf, grpc_chttp2_ping_create(false, pq->inflight_id)); - GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx); + GRPC_STATS_INC_HTTP2_PINGS_SENT(); t->ping_state.last_ping_sent_time = now; if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping sent [%p]: %d/%d", @@ -114,10 +112,9 @@ static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, (t->ping_state.pings_before_data_required != 0); } -static bool update_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_chttp2_stream* s, int64_t send_bytes, - grpc_chttp2_write_cb** list, int64_t* ctr, - grpc_error* error) { +static bool update_list(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + int64_t send_bytes, grpc_chttp2_write_cb** list, + int64_t* ctr, grpc_error* error) { bool sched_any = false; grpc_chttp2_write_cb* cb = *list; *list = nullptr; @@ -126,7 +123,7 @@ static bool update_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_write_cb* next = cb->next; if (cb->call_at_byte <= *ctr) { sched_any = true; - finish_write_cb(exec_ctx, t, s, cb, GRPC_ERROR_REF(error)); + finish_write_cb(t, s, cb, GRPC_ERROR_REF(error)); } else { add_to_write_list(list, cb); } @@ -179,22 +176,22 @@ class StreamWriteContext; class WriteContext { public: - WriteContext(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) : t_(t) { - GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx); + WriteContext(grpc_chttp2_transport* t) : t_(t) { + GRPC_STATS_INC_HTTP2_WRITES_BEGUN(); GPR_TIMER_BEGIN("grpc_chttp2_begin_write", 0); } // TODO(ctiller): make this the destructor - void FlushStats(grpc_exec_ctx* exec_ctx) { + void FlushStats() { GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE( - exec_ctx, initial_metadata_writes_); - GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(exec_ctx, message_writes_); + initial_metadata_writes_); + GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(message_writes_); GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE( - exec_ctx, trailing_metadata_writes_); - GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(exec_ctx, flow_control_writes_); + trailing_metadata_writes_); + GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(flow_control_writes_); } - void FlushSettings(grpc_exec_ctx* exec_ctx) { + void FlushSettings() { if (t_->dirtied_local_settings && !t_->sent_local_settings) { grpc_slice_buffer_add( &t_->outbuf, grpc_chttp2_settings_create( @@ -204,17 +201,17 @@ class WriteContext { t_->force_send_settings = false; t_->dirtied_local_settings = false; t_->sent_local_settings = true; - GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(exec_ctx); + GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(); } } - void FlushQueuedBuffers(grpc_exec_ctx* exec_ctx) { + void FlushQueuedBuffers() { /* simple writes are queued to qbuf, and flushed here */ grpc_slice_buffer_move_into(&t_->qbuf, &t_->outbuf); GPR_ASSERT(t_->qbuf.count == 0); } - void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { + void FlushWindowUpdates() { uint32_t transport_announce = t_->flow_control->MaybeSendUpdate(t_->outbuf.count > 0); if (transport_announce) { @@ -234,7 +231,7 @@ class WriteContext { t_->ping_ack_count = 0; } - void EnactHpackSettings(grpc_exec_ctx* exec_ctx) { + void EnactHpackSettings() { grpc_chttp2_hpack_compressor_set_max_table_size( &t_->hpack_compressor, t_->settings[GRPC_PEER_SETTINGS] @@ -374,8 +371,8 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } - void CallCallbacks(grpc_exec_ctx* exec_ctx) { - if (update_list(exec_ctx, t_, s_, + void CallCallbacks() { + if (update_list(t_, s_, (int64_t)(s_->sending_bytes - sending_bytes_before_), &s_->on_flow_controlled_cbs, &s_->flow_controlled_bytes_flowed, GRPC_ERROR_NONE)) { @@ -403,7 +400,7 @@ class StreamWriteContext { s->flow_control->announced_window_delta()))); } - void FlushInitialMetadata(grpc_exec_ctx* exec_ctx) { + void FlushInitialMetadata() { /* send initial metadata if it's available */ if (s_->sent_initial_metadata) return; if (s_->send_initial_metadata == nullptr) return; @@ -430,7 +427,7 @@ class StreamWriteContext { [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], // max_frame_size &s_->stats.outgoing // stats }; - grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, nullptr, 0, + grpc_chttp2_encode_header(&t_->hpack_compressor, nullptr, 0, s_->send_initial_metadata, &hopt, &t_->outbuf); write_context_->ResetPingRecvClock(); write_context_->IncInitialMetadataWrites(); @@ -440,11 +437,11 @@ class StreamWriteContext { s_->sent_initial_metadata = true; write_context_->NoteScheduledResults(); grpc_chttp2_complete_closure_step( - exec_ctx, t_, s_, &s_->send_initial_metadata_finished, GRPC_ERROR_NONE, + t_, s_, &s_->send_initial_metadata_finished, GRPC_ERROR_NONE, "send_initial_metadata_finished"); } - void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { + void FlushWindowUpdates() { /* send any window updates */ const uint32_t stream_announce = s_->flow_control->MaybeSendUpdate(); if (stream_announce == 0) return; @@ -456,7 +453,7 @@ class StreamWriteContext { write_context_->IncWindowUpdateWrites(); } - void FlushData(grpc_exec_ctx* exec_ctx) { + void FlushData() { if (!s_->sent_initial_metadata) return; if (s_->flow_controlled_buffer.length == 0 && @@ -488,9 +485,9 @@ class StreamWriteContext { } write_context_->ResetPingRecvClock(); if (data_send_context.is_last_frame()) { - SentLastFrame(exec_ctx); + SentLastFrame(); } - data_send_context.CallCallbacks(exec_ctx); + data_send_context.CallCallbacks(); stream_became_writable_ = true; if (s_->flow_controlled_buffer.length > 0 || s_->compressed_data_buffer.length > 0) { @@ -500,7 +497,7 @@ class StreamWriteContext { write_context_->IncMessageWrites(); } - void FlushTrailingMetadata(grpc_exec_ctx* exec_ctx) { + void FlushTrailingMetadata() { if (!s_->sent_initial_metadata) return; if (s_->send_trailing_metadata == nullptr) return; @@ -521,18 +518,18 @@ class StreamWriteContext { t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], &s_->stats.outgoing}; - grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, + grpc_chttp2_encode_header(&t_->hpack_compressor, extra_headers_for_trailing_metadata_, num_extra_headers_for_trailing_metadata_, s_->send_trailing_metadata, &hopt, &t_->outbuf); } write_context_->IncTrailingMetadataWrites(); write_context_->ResetPingRecvClock(); - SentLastFrame(exec_ctx); + SentLastFrame(); write_context_->NoteScheduledResults(); grpc_chttp2_complete_closure_step( - exec_ctx, t_, s_, &s_->send_trailing_metadata_finished, GRPC_ERROR_NONE, + t_, s_, &s_->send_trailing_metadata_finished, GRPC_ERROR_NONE, "send_trailing_metadata_finished"); } @@ -556,7 +553,7 @@ class StreamWriteContext { } } - void SentLastFrame(grpc_exec_ctx* exec_ctx) { + void SentLastFrame() { s_->send_trailing_metadata = nullptr; s_->sent_trailing_metadata = true; @@ -565,7 +562,7 @@ class StreamWriteContext { &t_->outbuf, grpc_chttp2_rst_stream_create( s_->id, GRPC_HTTP2_NO_ERROR, &s_->stats.outgoing)); } - grpc_chttp2_mark_stream_closed(exec_ctx, t_, s_, !t_->is_client, true, + grpc_chttp2_mark_stream_closed(t_, s_, !t_->is_client, true, GRPC_ERROR_NONE); } @@ -579,12 +576,12 @@ class StreamWriteContext { } // namespace grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) { - WriteContext ctx(exec_ctx, t); - ctx.FlushSettings(exec_ctx); + grpc_chttp2_transport* t) { + WriteContext ctx(t); + ctx.FlushSettings(); ctx.FlushPingAcks(); - ctx.FlushQueuedBuffers(exec_ctx); - ctx.EnactHpackSettings(exec_ctx); + ctx.FlushQueuedBuffers(); + ctx.EnactHpackSettings(); if (t->flow_control->remote_window() > 0) { ctx.UpdateStreamsNoLongerStalled(); @@ -594,47 +591,45 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( (according to available window sizes) and add to the output buffer */ while (grpc_chttp2_stream* s = ctx.NextStream()) { StreamWriteContext stream_ctx(&ctx, s); - stream_ctx.FlushInitialMetadata(exec_ctx); - stream_ctx.FlushWindowUpdates(exec_ctx); - stream_ctx.FlushData(exec_ctx); - stream_ctx.FlushTrailingMetadata(exec_ctx); + stream_ctx.FlushInitialMetadata(); + stream_ctx.FlushWindowUpdates(); + stream_ctx.FlushData(); + stream_ctx.FlushTrailingMetadata(); if (stream_ctx.stream_became_writable()) { if (!grpc_chttp2_list_add_writing_stream(t, s)) { /* already in writing list: drop ref */ - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:already_writing"); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:already_writing"); } else { /* ref will be dropped at end of write */ } } else { - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:no_write"); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:no_write"); } } - ctx.FlushWindowUpdates(exec_ctx); + ctx.FlushWindowUpdates(); - maybe_initiate_ping(exec_ctx, t); + maybe_initiate_ping(t); GPR_TIMER_END("grpc_chttp2_begin_write", 0); return ctx.Result(); } -void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, - grpc_error* error) { +void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { GPR_TIMER_BEGIN("grpc_chttp2_end_write", 0); grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - update_list(exec_ctx, t, s, (int64_t)s->sending_bytes, - &s->on_write_finished_cbs, &s->flow_controlled_bytes_written, - GRPC_ERROR_REF(error)); + update_list(t, s, (int64_t)s->sending_bytes, &s->on_write_finished_cbs, + &s->flow_controlled_bytes_written, GRPC_ERROR_REF(error)); s->sending_bytes = 0; } - GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:end"); + GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:end"); } - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->outbuf); + grpc_slice_buffer_reset_and_unref_internal(&t->outbuf); GRPC_ERROR_UNREF(error); GPR_TIMER_END("grpc_chttp2_end_write", 0); } diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc index d590ba0371..40a30e4a31 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc @@ -49,7 +49,6 @@ GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( grpc_transport* ct = grpc_create_cronet_transport(engine, target, args, reserved); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - return grpc_channel_create(&exec_ctx, target, args, - GRPC_CLIENT_DIRECT_CHANNEL, ct); + grpc_core::ExecCtx exec_ctx; + return grpc_channel_create(target, args, GRPC_CLIENT_DIRECT_CHANNEL, ct); } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 4d24efe47b..c9fd94176b 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -197,27 +197,23 @@ typedef struct stream_obj stream_obj; #ifndef NDEBUG #define GRPC_CRONET_STREAM_REF(stream, reason) \ grpc_cronet_stream_ref((stream), (reason)) -#define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ - grpc_cronet_stream_unref((exec_ctx), (stream), (reason)) +#define GRPC_CRONET_STREAM_UNREF(stream, reason) \ + grpc_cronet_stream_unref((stream), (reason)) void grpc_cronet_stream_ref(stream_obj* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s, - const char* reason) { - grpc_stream_unref(exec_ctx, s->refcount, reason); +void grpc_cronet_stream_unref(stream_obj* s, const char* reason) { + grpc_stream_unref(s->refcount, reason); } #else #define GRPC_CRONET_STREAM_REF(stream, reason) grpc_cronet_stream_ref((stream)) -#define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ - grpc_cronet_stream_unref((exec_ctx), (stream)) +#define GRPC_CRONET_STREAM_UNREF(stream, reason) \ + grpc_cronet_stream_unref((stream)) void grpc_cronet_stream_ref(stream_obj* s) { grpc_stream_ref(s->refcount); } -void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s) { - grpc_stream_unref(exec_ctx, s->refcount); -} +void grpc_cronet_stream_unref(stream_obj* s) { grpc_stream_unref(s->refcount); } #endif -static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, - struct op_and_state* oas); +static enum e_op_result execute_stream_op(struct op_and_state* oas); /* Utility function to translate enum into string for printing @@ -373,12 +369,12 @@ static void remove_from_storage(struct stream_obj* s, This can get executed from the Cronet network thread via cronet callback or on the application supplied thread via the perform_stream_op function. */ -static void execute_from_storage(grpc_exec_ctx* exec_ctx, stream_obj* s) { +static void execute_from_storage(stream_obj* s) { gpr_mu_lock(&s->mu); for (struct op_and_state* curr = s->storage.head; curr != nullptr;) { CRONET_LOG(GPR_DEBUG, "calling op at %p. done = %d", curr, curr->done); GPR_ASSERT(curr->done == 0); - enum e_op_result result = execute_stream_op(exec_ctx, curr); + enum e_op_result result = execute_stream_op(curr); CRONET_LOG(GPR_DEBUG, "execute_stream_op[%p] returns %s", curr, op_result_string(result)); /* if this op is done, then remove it and free memory */ @@ -402,7 +398,7 @@ static void execute_from_storage(grpc_exec_ctx* exec_ctx, stream_obj* s) { */ static void on_failed(bidirectional_stream* stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -419,9 +415,8 @@ static void on_failed(bidirectional_stream* stream, int net_error) { } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); + GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); } /* @@ -429,7 +424,7 @@ static void on_failed(bidirectional_stream* stream, int net_error) { */ static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -446,9 +441,8 @@ static void on_canceled(bidirectional_stream* stream) { } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); + GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); } /* @@ -456,7 +450,7 @@ static void on_canceled(bidirectional_stream* stream) { */ static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); @@ -465,9 +459,8 @@ static void on_succeeded(bidirectional_stream* stream) { s->cbs = nullptr; null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - GRPC_CRONET_STREAM_UNREF(&exec_ctx, s, "cronet transport"); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); + GRPC_CRONET_STREAM_UNREF(s, "cronet transport"); } /* @@ -475,7 +468,7 @@ static void on_succeeded(bidirectional_stream* stream) { */ static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); @@ -495,8 +488,7 @@ static void on_stream_ready(bidirectional_stream* stream) { } } gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); } /* @@ -506,7 +498,7 @@ static void on_response_headers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* headers, const char* negotiated_protocol) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); stream_obj* s = (stream_obj*)stream->annotation; @@ -528,9 +520,8 @@ static void on_response_headers_received( for (size_t i = 0; i < headers->count; i++) { GRPC_LOG_IF_ERROR("on_response_headers_received", grpc_chttp2_incoming_metadata_buffer_add( - &exec_ctx, &s->state.rs.initial_metadata, + &s->state.rs.initial_metadata, grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( headers->headers[i].key)), grpc_slice_intern(grpc_slice_from_static_string( @@ -552,15 +543,14 @@ static void on_response_headers_received( s->state.pending_read_from_cronet = true; } gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); } /* Cronet callback */ static void on_write_completed(bidirectional_stream* stream, const char* data) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); @@ -570,8 +560,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { } s->state.state_callback_received[OP_SEND_MESSAGE] = true; gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + execute_from_storage(s); } /* @@ -579,7 +568,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { */ static void on_read_completed(bidirectional_stream* stream, char* data, int count) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); @@ -605,15 +594,14 @@ static void on_read_completed(bidirectional_stream* stream, char* data, gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); + execute_from_storage(s); } } else { null_and_maybe_free_read_buffer(s); s->state.rs.read_stream_closed = true; gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); + execute_from_storage(s); } - grpc_exec_ctx_finish(&exec_ctx); } /* @@ -622,7 +610,7 @@ static void on_read_completed(bidirectional_stream* stream, char* data, static void on_response_trailers_received( bidirectional_stream* stream, const bidirectional_stream_header_array* trailers) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); stream_obj* s = (stream_obj*)stream->annotation; @@ -638,9 +626,8 @@ static void on_response_trailers_received( trailers->headers[i].value); GRPC_LOG_IF_ERROR("on_response_trailers_received", grpc_chttp2_incoming_metadata_buffer_add( - &exec_ctx, &s->state.rs.trailing_metadata, + &s->state.rs.trailing_metadata, grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( trailers->headers[i].key)), grpc_slice_intern(grpc_slice_from_static_string( @@ -670,17 +657,15 @@ static void on_response_trailers_received( gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - execute_from_storage(&exec_ctx, s); + execute_from_storage(s); } - grpc_exec_ctx_finish(&exec_ctx); } /* Utility function that takes the data from s->write_slice_buffer and assembles into a contiguous byte stream with 5 byte gRPC header prepended. */ -static void create_grpc_frame(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* write_slice_buffer, +static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, char** pp_write_buffer, size_t* p_write_buffer_size, uint32_t flags) { grpc_slice slice = grpc_slice_buffer_take_first(write_slice_buffer); @@ -700,7 +685,7 @@ static void create_grpc_frame(grpc_exec_ctx* exec_ctx, *p++ = (uint8_t)(length); /* append actual data */ memcpy(p, GRPC_SLICE_START_PTR(slice), length); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); } /* @@ -981,8 +966,7 @@ static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op, /* TODO (makdharma): Break down this function in smaller chunks for readability. */ -static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, - struct op_and_state* oas) { +static enum e_op_result execute_stream_op(struct op_and_state* oas) { grpc_transport_stream_op_batch* stream_op = &oas->op; struct stream_obj* s = oas->s; grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; @@ -1040,15 +1024,14 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, grpc_slice slice; grpc_slice_buffer_init(&write_slice_buffer); if (1 != grpc_byte_stream_next( - exec_ctx, stream_op->payload->send_message.send_message, + stream_op->payload->send_message.send_message, stream_op->payload->send_message.send_message->length, nullptr)) { /* Should never reach here */ GPR_ASSERT(false); } if (GRPC_ERROR_NONE != - grpc_byte_stream_pull(exec_ctx, - stream_op->payload->send_message.send_message, + grpc_byte_stream_pull(stream_op->payload->send_message.send_message, &slice)) { /* Should never reach here */ GPR_ASSERT(false); @@ -1061,15 +1044,15 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, } if (write_slice_buffer.count > 0) { size_t write_buffer_size; - create_grpc_frame(exec_ctx, &write_slice_buffer, - &stream_state->ws.write_buffer, &write_buffer_size, + create_grpc_frame(&write_slice_buffer, &stream_state->ws.write_buffer, + &write_buffer_size, stream_op->payload->send_message.send_message->flags); CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", s->cbs, stream_state->ws.write_buffer); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, (int)write_buffer_size, false); - grpc_slice_buffer_destroy_internal(exec_ctx, &write_slice_buffer); + grpc_slice_buffer_destroy_internal(&write_slice_buffer); if (t->use_packet_coalescing) { if (!stream_op->send_trailing_metadata) { CRONET_LOG(GPR_DEBUG, "bidirectional_stream_flush (%p)", s->cbs); @@ -1112,25 +1095,21 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_INITIAL_METADATA", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else if (stream_state->state_callback_received[OP_FAILED]) { GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else if (stream_state->state_op_done[OP_RECV_TRAILING_METADATA]) { GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } else { grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &oas->s->state.rs.initial_metadata, + &oas->s->state.rs.initial_metadata, stream_op->payload->recv_initial_metadata.recv_initial_metadata); GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE); } @@ -1141,16 +1120,14 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_MESSAGE", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { CRONET_LOG(GPR_DEBUG, "Stream is cancelled."); - GRPC_CLOSURE_SCHED(exec_ctx, - stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->state_callback_received[OP_FAILED]) { CRONET_LOG(GPR_DEBUG, "Stream failed."); - GRPC_CLOSURE_SCHED(exec_ctx, - stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1158,16 +1135,14 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, } else if (stream_state->rs.read_stream_closed == true) { /* No more data will be received */ CRONET_LOG(GPR_DEBUG, "read stream closed"); - GRPC_CLOSURE_SCHED(exec_ctx, - stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->flush_read) { CRONET_LOG(GPR_DEBUG, "flush read"); - GRPC_CLOSURE_SCHED(exec_ctx, - stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1200,7 +1175,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, CRONET_LOG(GPR_DEBUG, "read operation complete. Empty response."); /* Clean up read_slice_buffer in case there is unread data. */ grpc_slice_buffer_destroy_internal( - exec_ctx, &stream_state->rs.read_slice_buffer); + &stream_state->rs.read_slice_buffer); grpc_slice_buffer_init(&stream_state->rs.read_slice_buffer); grpc_slice_buffer_stream_init(&stream_state->rs.sbs, &stream_state->rs.read_slice_buffer, 0); @@ -1210,7 +1185,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = (grpc_byte_buffer*)&stream_state->rs.sbs; GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->payload->recv_message.recv_message_ready, + stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1254,8 +1229,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, (size_t)stream_state->rs.length_field); null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ - grpc_slice_buffer_destroy_internal(exec_ctx, - &stream_state->rs.read_slice_buffer); + grpc_slice_buffer_destroy_internal(&stream_state->rs.read_slice_buffer); grpc_slice_buffer_init(&stream_state->rs.read_slice_buffer); grpc_slice_buffer_add(&stream_state->rs.read_slice_buffer, read_data_slice); @@ -1266,8 +1240,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, } *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = (grpc_byte_buffer*)&stream_state->rs.sbs; - GRPC_CLOSURE_SCHED(exec_ctx, - stream_op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; oas->state.state_op_done[OP_RECV_MESSAGE] = true; @@ -1290,7 +1263,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", oas); if (oas->s->state.rs.trailing_metadata_valid) { grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &oas->s->state.rs.trailing_metadata, + &oas->s->state.rs.trailing_metadata, stream_op->payload->recv_trailing_metadata.recv_trailing_metadata); stream_state->rs.trailing_metadata_valid = false; } @@ -1315,17 +1288,17 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, op_can_be_run(stream_op, s, &oas->state, OP_ON_COMPLETE)) { CRONET_LOG(GPR_DEBUG, "running: %p OP_ON_COMPLETE", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { - GRPC_CLOSURE_SCHED(exec_ctx, stream_op->on_complete, + GRPC_CLOSURE_SCHED(stream_op->on_complete, GRPC_ERROR_REF(stream_state->cancel_error)); } else if (stream_state->state_callback_received[OP_FAILED]) { GRPC_CLOSURE_SCHED( - exec_ctx, stream_op->on_complete, + stream_op->on_complete, make_error_with_desc(GRPC_STATUS_UNAVAILABLE, "Unavailable.")); } else { /* All actions in this stream_op are complete. Call the on_complete * callback */ - GRPC_CLOSURE_SCHED(exec_ctx, stream_op->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(stream_op->on_complete, GRPC_ERROR_NONE); } oas->state.state_op_done[OP_ON_COMPLETE] = true; oas->done = true; @@ -1350,9 +1323,9 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, Functions used by upper layers to access transport functionality. */ -static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_stream_refcount* refcount, - const void* server_data, gpr_arena* arena) { +static int init_stream(grpc_transport* gt, grpc_stream* gs, + grpc_stream_refcount* refcount, const void* server_data, + gpr_arena* arena) { stream_obj* s = (stream_obj*)gs; s->refcount = refcount; @@ -1383,15 +1356,13 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, return 0; } -static void set_pollset_do_nothing(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_pollset* pollset) {} +static void set_pollset_do_nothing(grpc_transport* gt, grpc_stream* gs, + grpc_pollset* pollset) {} -static void set_pollset_set_do_nothing(grpc_exec_ctx* exec_ctx, - grpc_transport* gt, grpc_stream* gs, +static void set_pollset_set_do_nothing(grpc_transport* gt, grpc_stream* gs, grpc_pollset_set* pollset_set) {} -static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { CRONET_LOG(GPR_DEBUG, "perform_stream_op"); if (op->send_initial_metadata && @@ -1401,42 +1372,36 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, this field is present in metadata */ if (op->recv_initial_metadata) { GRPC_CLOSURE_SCHED( - exec_ctx, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_CANCELLED); } if (op->recv_message) { - GRPC_CLOSURE_SCHED(exec_ctx, op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(op->payload->recv_message.recv_message_ready, GRPC_ERROR_CANCELLED); } - GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_CANCELLED); return; } stream_obj* s = (stream_obj*)gs; add_to_storage(s, op); - execute_from_storage(exec_ctx, s); + execute_from_storage(s); } -static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { stream_obj* s = (stream_obj*)gs; null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ - grpc_slice_buffer_destroy_internal(exec_ctx, &s->state.rs.read_slice_buffer); + grpc_slice_buffer_destroy_internal(&s->state.rs.read_slice_buffer); GRPC_ERROR_UNREF(s->state.cancel_error); - GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); } -static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) {} +static void destroy_transport(grpc_transport* gt) {} -static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, - grpc_transport* gt) { - return nullptr; -} +static grpc_endpoint* get_endpoint(grpc_transport* gt) { return nullptr; } -static void perform_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_transport_op* op) {} +static void perform_op(grpc_transport* gt, grpc_transport_op* op) {} static const grpc_transport_vtable grpc_cronet_vtable = { sizeof(stream_obj), diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index d8d753e459..8dd0b7dce2 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -54,8 +54,8 @@ typedef struct inproc_transport { gpr_refcount refs; bool is_client; grpc_connectivity_state_tracker connectivity; - void (*accept_stream_cb)(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_transport* transport, const void* server_data); + void (*accept_stream_cb)(void* user_data, grpc_transport* transport, + const void* server_data); void* accept_stream_data; bool is_closed; struct inproc_transport* other_side; @@ -118,39 +118,36 @@ typedef struct inproc_stream { } inproc_stream; static grpc_closure do_nothing_closure; -static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, - grpc_error* error); -static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +static bool cancel_stream_locked(inproc_stream* s, grpc_error* error); +static void op_state_machine(void* arg, grpc_error* error); static void ref_transport(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "ref_transport %p", t); gpr_ref(&t->refs); } -static void really_destroy_transport(grpc_exec_ctx* exec_ctx, - inproc_transport* t) { +static void really_destroy_transport(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "really_destroy_transport %p", t); - grpc_connectivity_state_destroy(exec_ctx, &t->connectivity); + grpc_connectivity_state_destroy(&t->connectivity); if (gpr_unref(&t->mu->refs)) { gpr_free(t->mu); } gpr_free(t); } -static void unref_transport(grpc_exec_ctx* exec_ctx, inproc_transport* t) { +static void unref_transport(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "unref_transport %p", t); if (gpr_unref(&t->refs)) { - really_destroy_transport(exec_ctx, t); + really_destroy_transport(t); } } #ifndef NDEBUG #define STREAM_REF(refs, reason) grpc_stream_ref(refs, reason) -#define STREAM_UNREF(e, refs, reason) grpc_stream_unref(e, refs, reason) +#define STREAM_UNREF(refs, reason) grpc_stream_unref(refs, reason) #else #define STREAM_REF(refs, reason) grpc_stream_ref(refs) -#define STREAM_UNREF(e, refs, reason) grpc_stream_unref(e, refs) +#define STREAM_UNREF(refs, reason) grpc_stream_unref(refs) #endif static void ref_stream(inproc_stream* s, const char* reason) { @@ -158,13 +155,12 @@ static void ref_stream(inproc_stream* s, const char* reason) { STREAM_REF(s->refs, reason); } -static void unref_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s, - const char* reason) { +static void unref_stream(inproc_stream* s, const char* reason) { INPROC_LOG(GPR_DEBUG, "unref_stream %p %s", s, reason); - STREAM_UNREF(exec_ctx, s->refs, reason); + STREAM_UNREF(s->refs, reason); } -static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { +static void really_destroy_stream(inproc_stream* s) { INPROC_LOG(GPR_DEBUG, "really_destroy_stream %p", s); GRPC_ERROR_UNREF(s->write_buffer_cancel_error); @@ -172,13 +168,13 @@ static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { GRPC_ERROR_UNREF(s->cancel_other_error); if (s->recv_inited) { - grpc_slice_buffer_destroy_internal(exec_ctx, &s->recv_message); + grpc_slice_buffer_destroy_internal(&s->recv_message); } - unref_transport(exec_ctx, s->t); + unref_transport(s->t); if (s->closure_at_destroy) { - GRPC_CLOSURE_SCHED(exec_ctx, s->closure_at_destroy, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->closure_at_destroy, GRPC_ERROR_NONE); } } @@ -195,7 +191,7 @@ static void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, } } -static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, +static grpc_error* fill_in_metadata(inproc_stream* s, const grpc_metadata_batch* metadata, uint32_t flags, grpc_metadata_batch* out_md, uint32_t* outflags, bool* markfilled) { @@ -214,18 +210,18 @@ static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { grpc_linked_mdelem* nelem = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); - nelem->md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(GRPC_MDKEY(elem->md)), - grpc_slice_intern(GRPC_MDVALUE(elem->md))); + nelem->md = + grpc_mdelem_from_slices(grpc_slice_intern(GRPC_MDKEY(elem->md)), + grpc_slice_intern(GRPC_MDVALUE(elem->md))); - error = grpc_metadata_batch_link_tail(exec_ctx, out_md, nelem); + error = grpc_metadata_batch_link_tail(out_md, nelem); } return error; } -static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_stream_refcount* refcount, - const void* server_data, gpr_arena* arena) { +static int init_stream(grpc_transport* gt, grpc_stream* gs, + grpc_stream_refcount* refcount, const void* server_data, + gpr_arena* arena) { INPROC_LOG(GPR_DEBUG, "init_stream %p %p %p", gt, gs, server_data); inproc_transport* t = (inproc_transport*)gt; inproc_stream* s = (inproc_stream*)gs; @@ -285,8 +281,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, // side to avoid destruction INPROC_LOG(GPR_DEBUG, "calling accept stream cb %p %p", st->accept_stream_cb, st->accept_stream_data); - (*st->accept_stream_cb)(exec_ctx, st->accept_stream_data, &st->base, - (void*)s); + (*st->accept_stream_cb)(st->accept_stream_data, &st->base, (void*)s); } else { // This is the server-side and is being called through accept_stream_cb inproc_stream* cs = (inproc_stream*)server_data; @@ -301,19 +296,19 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, // Now transfer from the other side's write_buffer if any to the to_read // buffer if (cs->write_buffer_initial_md_filled) { - fill_in_metadata(exec_ctx, s, &cs->write_buffer_initial_md, + fill_in_metadata(s, &cs->write_buffer_initial_md, cs->write_buffer_initial_md_flags, &s->to_read_initial_md, &s->to_read_initial_md_flags, &s->to_read_initial_md_filled); s->deadline = GPR_MIN(s->deadline, cs->write_buffer_deadline); - grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_initial_md); + grpc_metadata_batch_clear(&cs->write_buffer_initial_md); cs->write_buffer_initial_md_filled = false; } if (cs->write_buffer_trailing_md_filled) { - fill_in_metadata(exec_ctx, s, &cs->write_buffer_trailing_md, 0, + fill_in_metadata(s, &cs->write_buffer_trailing_md, 0, &s->to_read_trailing_md, nullptr, &s->to_read_trailing_md_filled); - grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_trailing_md); + grpc_metadata_batch_clear(&cs->write_buffer_trailing_md); cs->write_buffer_trailing_md_filled = false; } if (cs->write_buffer_cancel_error != GRPC_ERROR_NONE) { @@ -326,11 +321,11 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, return 0; // return value is not important } -static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { +static void close_stream_locked(inproc_stream* s) { if (!s->closed) { // Release the metadata that we would have written out - grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_initial_md); - grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_trailing_md); + grpc_metadata_batch_destroy(&s->write_buffer_initial_md); + grpc_metadata_batch_destroy(&s->write_buffer_trailing_md); if (s->listed) { inproc_stream* p = s->stream_list_prev; @@ -344,22 +339,21 @@ static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { n->stream_list_prev = p; } s->listed = false; - unref_stream(exec_ctx, s, "close_stream:list"); + unref_stream(s, "close_stream:list"); } s->closed = true; - unref_stream(exec_ctx, s, "close_stream:closing"); + unref_stream(s, "close_stream:closing"); } } // This function means that we are done talking/listening to the other side -static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, - const char* reason) { +static void close_other_side_locked(inproc_stream* s, const char* reason) { if (s->other_side != nullptr) { // First release the metadata that came from the other side's arena - grpc_metadata_batch_destroy(exec_ctx, &s->to_read_initial_md); - grpc_metadata_batch_destroy(exec_ctx, &s->to_read_trailing_md); + grpc_metadata_batch_destroy(&s->to_read_initial_md); + grpc_metadata_batch_destroy(&s->to_read_trailing_md); - unref_stream(exec_ctx, s->other_side, reason); + unref_stream(s->other_side, reason); s->other_side_closed = true; s->other_side = nullptr; } else if (!s->other_side_closed) { @@ -371,8 +365,7 @@ static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, // this stream_op_batch is only one of the pending operations for this // stream. This is called when one of the pending operations for the stream // is done and about to be NULLed out -static void complete_if_batch_end_locked(grpc_exec_ctx* exec_ctx, - inproc_stream* s, grpc_error* error, +static void complete_if_batch_end_locked(inproc_stream* s, grpc_error* error, grpc_transport_stream_op_batch* op, const char* msg) { int is_sm = (int)(op == s->send_message_op); @@ -383,22 +376,20 @@ static void complete_if_batch_end_locked(grpc_exec_ctx* exec_ctx, if ((is_sm + is_stm + is_rim + is_rm + is_rtm) == 1) { INPROC_LOG(GPR_DEBUG, "%s %p %p %p", msg, s, op, error); - GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_REF(error)); } } -static void maybe_schedule_op_closure_locked(grpc_exec_ctx* exec_ctx, - inproc_stream* s, +static void maybe_schedule_op_closure_locked(inproc_stream* s, grpc_error* error) { if (s && s->ops_needed && !s->op_closure_scheduled) { - GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(&s->op_closure, GRPC_ERROR_REF(error)); s->op_closure_scheduled = true; s->ops_needed = false; } } -static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, - grpc_error* error) { +static void fail_helper_locked(inproc_stream* s, grpc_error* error) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p fail_helper", s); // If we're failing this side, we need to make sure that // we also send or have already sent trailing metadata @@ -415,14 +406,14 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, nullptr, destfilled); - grpc_metadata_batch_destroy(exec_ctx, &fake_md); + fill_in_metadata(s, &fake_md, 0, dest, nullptr, destfilled); + grpc_metadata_batch_destroy(&fake_md); if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(error); } - maybe_schedule_op_closure_locked(exec_ctx, other, error); + maybe_schedule_op_closure_locked(other, error); } else if (s->write_buffer_cancel_error == GRPC_ERROR_NONE) { s->write_buffer_cancel_error = GRPC_ERROR_REF(error); } @@ -436,24 +427,22 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&fake_md); grpc_linked_mdelem* path_md = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*path_md)); - path_md->md = - grpc_mdelem_from_slices(exec_ctx, g_fake_path_key, g_fake_path_value); - GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, path_md) == + path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value); + GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, path_md) == GRPC_ERROR_NONE); grpc_linked_mdelem* auth_md = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*auth_md)); - auth_md->md = - grpc_mdelem_from_slices(exec_ctx, g_fake_auth_key, g_fake_auth_value); - GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, auth_md) == + auth_md->md = grpc_mdelem_from_slices(g_fake_auth_key, g_fake_auth_value); + GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, auth_md) == GRPC_ERROR_NONE); fill_in_metadata( - exec_ctx, s, &fake_md, 0, + s, &fake_md, 0, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, nullptr); - grpc_metadata_batch_destroy(exec_ctx, &fake_md); + grpc_metadata_batch_destroy(&fake_md); err = GRPC_ERROR_NONE; } else { err = GRPC_ERROR_REF(error); @@ -469,14 +458,13 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling initial-metadata-ready %p %p", s, error, err); - GRPC_CLOSURE_SCHED(exec_ctx, - s->recv_initial_md_op->payload->recv_initial_metadata + GRPC_CLOSURE_SCHED(s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata_ready, err); // Last use of err so no need to REF and then UNREF it complete_if_batch_end_locked( - exec_ctx, s, error, s->recv_initial_md_op, + s, error, s->recv_initial_md_op, "fail_helper scheduling recv-initial-metadata-on-complete"); s->recv_initial_md_op = nullptr; } @@ -484,22 +472,22 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling message-ready %p", s, error); GRPC_CLOSURE_SCHED( - exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, + s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_REF(error)); complete_if_batch_end_locked( - exec_ctx, s, error, s->recv_message_op, + s, error, s->recv_message_op, "fail_helper scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } if (s->send_message_op) { complete_if_batch_end_locked( - exec_ctx, s, error, s->send_message_op, + s, error, s->send_message_op, "fail_helper scheduling send-message-on-complete"); s->send_message_op = nullptr; } if (s->send_trailing_md_op) { complete_if_batch_end_locked( - exec_ctx, s, error, s->send_trailing_md_op, + s, error, s->send_trailing_md_op, "fail_helper scheduling send-trailng-md-on-complete"); s->send_trailing_md_op = nullptr; } @@ -508,23 +496,22 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, "fail_helper %p scheduling trailing-md-on-complete %p", s, error); complete_if_batch_end_locked( - exec_ctx, s, error, s->recv_trailing_md_op, + s, error, s->recv_trailing_md_op, "fail_helper scheduling recv-trailing-metadata-on-complete"); s->recv_trailing_md_op = nullptr; } - close_other_side_locked(exec_ctx, s, "fail_helper:other_side"); - close_stream_locked(exec_ctx, s); + close_other_side_locked(s, "fail_helper:other_side"); + close_stream_locked(s); GRPC_ERROR_UNREF(error); } -static void message_transfer_locked(grpc_exec_ctx* exec_ctx, - inproc_stream* sender, +static void message_transfer_locked(inproc_stream* sender, inproc_stream* receiver) { size_t remaining = sender->send_message_op->payload->send_message.send_message->length; if (receiver->recv_inited) { - grpc_slice_buffer_destroy_internal(exec_ctx, &receiver->recv_message); + grpc_slice_buffer_destroy_internal(&receiver->recv_message); } grpc_slice_buffer_init(&receiver->recv_message); receiver->recv_inited = true; @@ -532,13 +519,13 @@ static void message_transfer_locked(grpc_exec_ctx* exec_ctx, grpc_slice message_slice; grpc_closure unused; GPR_ASSERT(grpc_byte_stream_next( - exec_ctx, sender->send_message_op->payload->send_message.send_message, - SIZE_MAX, &unused)); + sender->send_message_op->payload->send_message.send_message, SIZE_MAX, + &unused)); grpc_error* error = grpc_byte_stream_pull( - exec_ctx, sender->send_message_op->payload->send_message.send_message, + sender->send_message_op->payload->send_message.send_message, &message_slice); if (error != GRPC_ERROR_NONE) { - cancel_stream_locked(exec_ctx, sender, GRPC_ERROR_REF(error)); + cancel_stream_locked(sender, GRPC_ERROR_REF(error)); break; } GPR_ASSERT(error == GRPC_ERROR_NONE); @@ -553,22 +540,20 @@ static void message_transfer_locked(grpc_exec_ctx* exec_ctx, INPROC_LOG(GPR_DEBUG, "message_transfer_locked %p scheduling message-ready", receiver); GRPC_CLOSURE_SCHED( - exec_ctx, receiver->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - exec_ctx, sender, GRPC_ERROR_NONE, sender->send_message_op, + sender, GRPC_ERROR_NONE, sender->send_message_op, "message_transfer scheduling sender on_complete"); complete_if_batch_end_locked( - exec_ctx, receiver, GRPC_ERROR_NONE, receiver->recv_message_op, + receiver, GRPC_ERROR_NONE, receiver->recv_message_op, "message_transfer scheduling receiver on_complete"); receiver->recv_message_op = nullptr; sender->send_message_op = nullptr; } -static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void op_state_machine(void* arg, grpc_error* error) { // This function gets called when we have contents in the unprocessed reads // Get what we want based on our ops wanted // Schedule our appropriate closures @@ -589,26 +574,26 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, inproc_stream* other = s->other_side; if (s->cancel_self_error != GRPC_ERROR_NONE) { - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(s->cancel_self_error)); + fail_helper_locked(s, GRPC_ERROR_REF(s->cancel_self_error)); goto done; } else if (s->cancel_other_error != GRPC_ERROR_NONE) { - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(s->cancel_other_error)); + fail_helper_locked(s, GRPC_ERROR_REF(s->cancel_other_error)); goto done; } else if (error != GRPC_ERROR_NONE) { - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(error)); + fail_helper_locked(s, GRPC_ERROR_REF(error)); goto done; } if (s->send_message_op && other) { if (other->recv_message_op) { - message_transfer_locked(exec_ctx, s, other); - maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); + message_transfer_locked(s, other); + maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); } else if (!s->t->is_client && (s->trailing_md_sent || other->recv_trailing_md_op)) { // A server send will never be matched if the client is waiting // for trailing metadata already complete_if_batch_end_locked( - exec_ctx, s, GRPC_ERROR_NONE, s->send_message_op, + s, GRPC_ERROR_NONE, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -630,11 +615,11 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // The buffer is already in use; that's an error! INPROC_LOG(GPR_DEBUG, "Extra trailing metadata %p", s); new_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Extra trailing metadata"); - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(s, GRPC_ERROR_REF(new_err)); goto done; } else { if (!other || !other->closed) { - fill_in_metadata(exec_ctx, s, + fill_in_metadata(s, s->send_trailing_md_op->payload->send_trailing_metadata .send_trailing_metadata, 0, dest, nullptr, destfilled); @@ -643,15 +628,15 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling trailing-md-on-complete", s); - GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, + GRPC_CLOSURE_SCHED(s->recv_trailing_md_op->on_complete, GRPC_ERROR_NONE); s->recv_trailing_md_op = nullptr; needs_close = true; } } - maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); + maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); complete_if_batch_end_locked( - exec_ctx, s, GRPC_ERROR_NONE, s->send_trailing_md_op, + s, GRPC_ERROR_NONE, s->send_trailing_md_op, "op_state_machine scheduling send-trailing-metadata-on-complete"); s->send_trailing_md_op = nullptr; } @@ -664,14 +649,14 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, "op_state_machine %p scheduling on_complete errors for already " "recvd initial md %p", s, new_err); - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(s, GRPC_ERROR_REF(new_err)); goto done; } if (s->to_read_initial_md_filled) { s->initial_md_recvd = true; new_err = fill_in_metadata( - exec_ctx, s, &s->to_read_initial_md, s->to_read_initial_md_flags, + s, &s->to_read_initial_md, s->to_read_initial_md_flags, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, @@ -684,17 +669,16 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, .trailing_metadata_available = (other != nullptr && other->send_trailing_md_op != nullptr); } - grpc_metadata_batch_clear(exec_ctx, &s->to_read_initial_md); + grpc_metadata_batch_clear(&s->to_read_initial_md); s->to_read_initial_md_filled = false; INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling initial-metadata-ready %p", s, new_err); - GRPC_CLOSURE_SCHED(exec_ctx, - s->recv_initial_md_op->payload->recv_initial_metadata + GRPC_CLOSURE_SCHED(s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata_ready, GRPC_ERROR_REF(new_err)); complete_if_batch_end_locked( - exec_ctx, s, new_err, s->recv_initial_md_op, + s, new_err, s->recv_initial_md_op, "op_state_machine scheduling recv-initial-metadata-on-complete"); s->recv_initial_md_op = nullptr; @@ -702,20 +686,20 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling on_complete errors2 %p", s, new_err); - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(s, GRPC_ERROR_REF(new_err)); goto done; } } } if (s->recv_message_op) { if (other && other->send_message_op) { - message_transfer_locked(exec_ctx, other, s); - maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); + message_transfer_locked(other, s); + maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); } } if (s->recv_trailing_md_op && s->t->is_client && other && other->send_message_op) { - maybe_schedule_op_closure_locked(exec_ctx, other, GRPC_ERROR_NONE); + maybe_schedule_op_closure_locked(other, GRPC_ERROR_NONE); } if (s->to_read_trailing_md_filled) { if (s->trailing_md_recvd) { @@ -726,7 +710,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, "op_state_machine %p scheduling on_complete errors for already " "recvd trailing md %p", s, new_err); - fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); + fail_helper_locked(s, GRPC_ERROR_REF(new_err)); goto done; } if (s->recv_message_op != nullptr) { @@ -734,11 +718,10 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // satisfied INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); GRPC_CLOSURE_SCHED( - exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - exec_ctx, s, new_err, s->recv_message_op, + s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } @@ -746,7 +729,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // Nothing further will try to receive from this stream, so finish off // any outstanding send_message op complete_if_batch_end_locked( - exec_ctx, s, new_err, s->send_message_op, + s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -754,11 +737,11 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // We wanted trailing metadata and we got it s->trailing_md_recvd = true; new_err = - fill_in_metadata(exec_ctx, s, &s->to_read_trailing_md, 0, + fill_in_metadata(s, &s->to_read_trailing_md, 0, s->recv_trailing_md_op->payload ->recv_trailing_metadata.recv_trailing_metadata, nullptr, nullptr); - grpc_metadata_batch_clear(exec_ctx, &s->to_read_trailing_md); + grpc_metadata_batch_clear(&s->to_read_trailing_md); s->to_read_trailing_md_filled = false; // We should schedule the recv_trailing_md_op completion if @@ -770,7 +753,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling trailing-md-on-complete %p", s, new_err); - GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, + GRPC_CLOSURE_SCHED(s->recv_trailing_md_op->on_complete, GRPC_ERROR_REF(new_err)); s->recv_trailing_md_op = nullptr; needs_close = true; @@ -791,10 +774,10 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // recv_message_op INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); GRPC_CLOSURE_SCHED( - exec_ctx, s->recv_message_op->payload->recv_message.recv_message_ready, + s->recv_message_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); complete_if_batch_end_locked( - exec_ctx, s, new_err, s->recv_message_op, + s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); s->recv_message_op = nullptr; } @@ -803,7 +786,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, // Nothing further will try to receive from this stream, so finish off // any outstanding send_message op complete_if_batch_end_locked( - exec_ctx, s, new_err, s->send_message_op, + s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); s->send_message_op = nullptr; } @@ -819,22 +802,21 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, } done: if (needs_close) { - close_other_side_locked(exec_ctx, s, "op_state_machine"); - close_stream_locked(exec_ctx, s); + close_other_side_locked(s, "op_state_machine"); + close_stream_locked(s); } gpr_mu_unlock(mu); GRPC_ERROR_UNREF(new_err); } -static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, - grpc_error* error) { +static bool cancel_stream_locked(inproc_stream* s, grpc_error* error) { bool ret = false; // was the cancel accepted INPROC_LOG(GPR_DEBUG, "cancel_stream %p with %s", s, grpc_error_string(error)); if (s->cancel_self_error == GRPC_ERROR_NONE) { ret = true; s->cancel_self_error = GRPC_ERROR_REF(error); - maybe_schedule_op_closure_locked(exec_ctx, s, s->cancel_self_error); + maybe_schedule_op_closure_locked(s, s->cancel_self_error); // Send trailing md to the other side indicating cancellation, even if we // already have s->trailing_md_sent = true; @@ -848,15 +830,14 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, nullptr, destfilled); - grpc_metadata_batch_destroy(exec_ctx, &cancel_md); + fill_in_metadata(s, &cancel_md, 0, dest, nullptr, destfilled); + grpc_metadata_batch_destroy(&cancel_md); if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(s->cancel_self_error); } - maybe_schedule_op_closure_locked(exec_ctx, other, - other->cancel_other_error); + maybe_schedule_op_closure_locked(other, other->cancel_other_error); } else if (s->write_buffer_cancel_error == GRPC_ERROR_NONE) { s->write_buffer_cancel_error = GRPC_ERROR_REF(s->cancel_self_error); } @@ -866,21 +847,20 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, // md, now's the chance if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { complete_if_batch_end_locked( - exec_ctx, s, s->cancel_self_error, s->recv_trailing_md_op, + s, s->cancel_self_error, s->recv_trailing_md_op, "cancel_stream scheduling trailing-md-on-complete"); s->recv_trailing_md_op = nullptr; } } - close_other_side_locked(exec_ctx, s, "cancel_stream:other_side"); - close_stream_locked(exec_ctx, s); + close_other_side_locked(s, "cancel_stream:other_side"); + close_stream_locked(s); GRPC_ERROR_UNREF(error); return ret; } -static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { INPROC_LOG(GPR_DEBUG, "perform_stream_op %p %p %p", gt, gs, op); inproc_stream* s = (inproc_stream*)gs; @@ -906,7 +886,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, if (op->cancel_stream) { // Call cancel_stream_locked without ref'ing the cancel_error because // this function is responsible to make sure that that field gets unref'ed - cancel_stream_locked(exec_ctx, s, op->payload->cancel_stream.cancel_error); + cancel_stream_locked(s, op->payload->cancel_stream.cancel_error); // this op can complete without an error } else if (s->cancel_self_error != GRPC_ERROR_NONE) { // already self-canceled so still give it an error @@ -946,8 +926,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } else { if (!other || !other->closed) { fill_in_metadata( - exec_ctx, s, - op->payload->send_initial_metadata.send_initial_metadata, + s, op->payload->send_initial_metadata.send_initial_metadata, op->payload->send_initial_metadata.send_initial_metadata_flags, dest, destflags, destfilled); } @@ -959,7 +938,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->initial_md_sent = true; } } - maybe_schedule_op_closure_locked(exec_ctx, other, error); + maybe_schedule_op_closure_locked(other, error); } } @@ -999,7 +978,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, (op->recv_message && other && (other->send_message_op != nullptr)) || (s->to_read_trailing_md_filled || s->trailing_md_recvd)) { if (!s->op_closure_scheduled) { - GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&s->op_closure, GRPC_ERROR_NONE); s->op_closure_scheduled = true; } } else { @@ -1023,7 +1002,6 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, "perform_stream_op error %p scheduling initial-metadata-ready %p", s, error); GRPC_CLOSURE_SCHED( - exec_ctx, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } @@ -1032,28 +1010,26 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, GPR_DEBUG, "perform_stream_op error %p scheduling recv message-ready %p", s, error); - GRPC_CLOSURE_SCHED(exec_ctx, - op->payload->recv_message.recv_message_ready, + GRPC_CLOSURE_SCHED(op->payload->recv_message.recv_message_ready, GRPC_ERROR_REF(error)); } } INPROC_LOG(GPR_DEBUG, "perform_stream_op %p scheduling on_complete %p", s, error); - GRPC_CLOSURE_SCHED(exec_ctx, on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_REF(error)); } if (needs_close) { - close_other_side_locked(exec_ctx, s, "perform_stream_op:other_side"); - close_stream_locked(exec_ctx, s); + close_other_side_locked(s, "perform_stream_op:other_side"); + close_stream_locked(s); } gpr_mu_unlock(mu); GRPC_ERROR_UNREF(error); } -static void close_transport_locked(grpc_exec_ctx* exec_ctx, - inproc_transport* t) { +static void close_transport_locked(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "close_transport %p %d", t, t->is_closed); grpc_connectivity_state_set( - exec_ctx, &t->connectivity, GRPC_CHANNEL_SHUTDOWN, + &t->connectivity, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Closing transport."), "close transport"); if (!t->is_closed) { @@ -1062,7 +1038,7 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, while (t->stream_list != nullptr) { // cancel_stream_locked also adjusts stream list cancel_stream_locked( - exec_ctx, t->stream_list, + t->stream_list, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); @@ -1070,14 +1046,13 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, } } -static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_transport_op* op) { +static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); if (op->on_connectivity_state_change) { grpc_connectivity_state_notify_on_state_change( - exec_ctx, &t->connectivity, op->connectivity_state, + &t->connectivity, op->connectivity_state, op->on_connectivity_state_change); } if (op->set_accept_stream) { @@ -1085,7 +1060,7 @@ static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, t->accept_stream_data = op->set_accept_stream_user_data; } if (op->on_consumed) { - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } bool do_close = false; @@ -1099,71 +1074,67 @@ static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } if (do_close) { - close_transport_locked(exec_ctx, t); + close_transport_locked(t); } gpr_mu_unlock(&t->mu->mu); } -static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, +static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { INPROC_LOG(GPR_DEBUG, "destroy_stream %p %p", gs, then_schedule_closure); inproc_stream* s = (inproc_stream*)gs; s->closure_at_destroy = then_schedule_closure; - really_destroy_stream(exec_ctx, s); + really_destroy_stream(s); } -static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { +static void destroy_transport(grpc_transport* gt) { inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "destroy_transport %p", t); gpr_mu_lock(&t->mu->mu); - close_transport_locked(exec_ctx, t); + close_transport_locked(t); gpr_mu_unlock(&t->mu->mu); - unref_transport(exec_ctx, t->other_side); - unref_transport(exec_ctx, t); + unref_transport(t->other_side); + unref_transport(t); } /******************************************************************************* * INTEGRATION GLUE */ -static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_pollset* pollset) { +static void set_pollset(grpc_transport* gt, grpc_stream* gs, + grpc_pollset* pollset) { // Nothing to do here } -static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, - grpc_stream* gs, grpc_pollset_set* pollset_set) { +static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, + grpc_pollset_set* pollset_set) { // Nothing to do here } -static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* t) { - return nullptr; -} +static grpc_endpoint* get_endpoint(grpc_transport* t) { return nullptr; } /******************************************************************************* * GLOBAL INIT AND DESTROY */ -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, nullptr, grpc_schedule_on_exec_ctx); g_empty_slice = grpc_slice_from_static_buffer(nullptr, 0); grpc_slice key_tmp = grpc_slice_from_static_string(":path"); g_fake_path_key = grpc_slice_intern(key_tmp); - grpc_slice_unref_internal(&exec_ctx, key_tmp); + grpc_slice_unref_internal(key_tmp); g_fake_path_value = grpc_slice_from_static_string("/"); grpc_slice auth_tmp = grpc_slice_from_static_string(":authority"); g_fake_auth_key = grpc_slice_intern(auth_tmp); - grpc_slice_unref_internal(&exec_ctx, auth_tmp); + grpc_slice_unref_internal(auth_tmp); g_fake_auth_value = grpc_slice_from_static_string("inproc-fail"); - grpc_exec_ctx_finish(&exec_ctx); } static const grpc_transport_vtable inproc_vtable = { @@ -1175,8 +1146,7 @@ static const grpc_transport_vtable inproc_vtable = { /******************************************************************************* * Main inproc transport functions */ -static void inproc_transports_create(grpc_exec_ctx* exec_ctx, - grpc_transport** server_transport, +static void inproc_transports_create(grpc_transport** server_transport, const grpc_channel_args* server_args, grpc_transport** client_transport, const grpc_channel_args* client_args) { @@ -1213,7 +1183,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, GRPC_API_TRACE("grpc_inproc_channel_create(server=%p, args=%p)", 2, (server, args)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const grpc_channel_args* server_args = grpc_server_get_channel_args(server); @@ -1228,30 +1198,26 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, grpc_transport* server_transport; grpc_transport* client_transport; - inproc_transports_create(&exec_ctx, &server_transport, server_args, - &client_transport, client_args); + inproc_transports_create(&server_transport, server_args, &client_transport, + client_args); - grpc_server_setup_transport(&exec_ctx, server, server_transport, nullptr, - server_args); - grpc_channel* channel = - grpc_channel_create(&exec_ctx, "inproc", client_args, - GRPC_CLIENT_DIRECT_CHANNEL, client_transport); + grpc_server_setup_transport(server, server_transport, nullptr, server_args); + grpc_channel* channel = grpc_channel_create( + "inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport); // Free up created channel args - grpc_channel_args_destroy(&exec_ctx, client_args); + grpc_channel_args_destroy(client_args); // Now finish scheduled operations - grpc_exec_ctx_finish(&exec_ctx); return channel; } void grpc_inproc_transport_shutdown(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_unref_internal(&exec_ctx, g_empty_slice); - grpc_slice_unref_internal(&exec_ctx, g_fake_path_key); - grpc_slice_unref_internal(&exec_ctx, g_fake_path_value); - grpc_slice_unref_internal(&exec_ctx, g_fake_auth_key); - grpc_slice_unref_internal(&exec_ctx, g_fake_auth_value); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_unref_internal(g_empty_slice); + grpc_slice_unref_internal(g_fake_path_key); + grpc_slice_unref_internal(g_fake_path_value); + grpc_slice_unref_internal(g_fake_auth_key); + grpc_slice_unref_internal(g_fake_auth_value); } diff --git a/src/core/lib/backoff/backoff.cc b/src/core/lib/backoff/backoff.cc index dc754ddd82..da3b9b1b2d 100644 --- a/src/core/lib/backoff/backoff.cc +++ b/src/core/lib/backoff/backoff.cc @@ -32,12 +32,11 @@ void grpc_backoff_init(grpc_backoff* backoff, grpc_millis initial_backoff, backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; } -grpc_backoff_result grpc_backoff_begin(grpc_exec_ctx* exec_ctx, - grpc_backoff* backoff) { +grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff) { backoff->current_backoff = backoff->initial_backoff; const grpc_millis initial_timeout = GPR_MAX(backoff->initial_backoff, backoff->min_connect_timeout); - const grpc_millis now = grpc_exec_ctx_now(exec_ctx); + const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + initial_timeout, now + backoff->current_backoff}; return result; @@ -57,8 +56,7 @@ static double generate_uniform_random_number_between(uint32_t* rng_state, return a + generate_uniform_random_number(rng_state) * range; } -grpc_backoff_result grpc_backoff_step(grpc_exec_ctx* exec_ctx, - grpc_backoff* backoff) { +grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff) { backoff->current_backoff = (grpc_millis)(GPR_MIN( backoff->current_backoff * backoff->multiplier, backoff->max_backoff)); const double jitter = generate_uniform_random_number_between( @@ -69,7 +67,7 @@ grpc_backoff_result grpc_backoff_step(grpc_exec_ctx* exec_ctx, backoff->min_connect_timeout); const grpc_millis next_timeout = GPR_MIN( (grpc_millis)(backoff->current_backoff + jitter), backoff->max_backoff); - const grpc_millis now = grpc_exec_ctx_now(exec_ctx); + const grpc_millis now = grpc_core::ExecCtx::Get()->Now(); const grpc_backoff_result result = {now + current_timeout, now + next_timeout}; return result; diff --git a/src/core/lib/backoff/backoff.h b/src/core/lib/backoff/backoff.h index 0da9082e70..f61d14ec95 100644 --- a/src/core/lib/backoff/backoff.h +++ b/src/core/lib/backoff/backoff.h @@ -60,13 +60,11 @@ void grpc_backoff_init(grpc_backoff* backoff, grpc_millis initial_backoff, /// Begin retry loop: returns the deadlines to be used for the current attempt /// and the subsequent retry, if any. -grpc_backoff_result grpc_backoff_begin(grpc_exec_ctx* exec_ctx, - grpc_backoff* backoff); +grpc_backoff_result grpc_backoff_begin(grpc_backoff* backoff); /// Step a retry loop: returns the deadlines to be used for the current attempt /// and the subsequent retry, if any. -grpc_backoff_result grpc_backoff_step(grpc_exec_ctx* exec_ctx, - grpc_backoff* backoff); +grpc_backoff_result grpc_backoff_step(grpc_backoff* backoff); /// Reset the backoff, so the next grpc_backoff_step will be a /// grpc_backoff_begin. diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 735fcbe405..578475b248 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -188,7 +188,7 @@ grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { return b; } -void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a) { +void grpc_channel_args_destroy(grpc_channel_args* a) { size_t i; if (!a) return; for (i = 0; i < a->num_args; i++) { @@ -199,8 +199,7 @@ void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a) { case GRPC_ARG_INTEGER: break; case GRPC_ARG_POINTER: - a->args[i].value.pointer.vtable->destroy(exec_ctx, - a->args[i].value.pointer.p); + a->args[i].value.pointer.vtable->destroy(a->args[i].value.pointer.p); break; } gpr_free(a->args[i].key); @@ -299,8 +298,7 @@ static int find_stream_compression_algorithm_states_bitset( } grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( - grpc_exec_ctx* exec_ctx, grpc_channel_args** a, - grpc_compression_algorithm algorithm, int state) { + grpc_channel_args** a, grpc_compression_algorithm algorithm, int state) { int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = @@ -333,15 +331,15 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); - grpc_channel_args_destroy(exec_ctx, *a); + grpc_channel_args_destroy(*a); *a = result; } return result; } grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_exec_ctx* exec_ctx, grpc_channel_args** a, - grpc_stream_compression_algorithm algorithm, int state) { + grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, + int state) { int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = @@ -375,7 +373,7 @@ grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); - grpc_channel_args_destroy(exec_ctx, *a); + grpc_channel_args_destroy(*a); *a = result; } return result; diff --git a/src/core/lib/channel/channel_args.h b/src/core/lib/channel/channel_args.h index f6cb7fa73d..9c7d06f34e 100644 --- a/src/core/lib/channel/channel_args.h +++ b/src/core/lib/channel/channel_args.h @@ -53,7 +53,7 @@ grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, const grpc_channel_args* b); /** Destroy arguments created by \a grpc_channel_args_copy */ -void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a); +void grpc_channel_args_destroy(grpc_channel_args* a); /** Returns the compression algorithm set in \a a. */ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( @@ -85,8 +85,7 @@ grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( * modified to point to the returned instance (which may be different from the * input value of \a a). */ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( - grpc_exec_ctx* exec_ctx, grpc_channel_args** a, - grpc_compression_algorithm algorithm, int enabled); + grpc_channel_args** a, grpc_compression_algorithm algorithm, int enabled); /** Sets the support for the given stream compression algorithm. By default, all * stream compression algorithms are enabled. It's an error to disable an @@ -96,8 +95,8 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( * modified to point to the returned instance (which may be different from the * input value of \a a). */ grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( - grpc_exec_ctx* exec_ctx, grpc_channel_args** a, - grpc_stream_compression_algorithm algorithm, int enabled); + grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, + int enabled); /** Returns the bitset representing the support state (true for enabled, false * for disabled) for compression algorithms. diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 7629d18789..195fe0b195 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -88,8 +88,8 @@ grpc_call_element* grpc_call_stack_element(grpc_call_stack* call_stack, } grpc_error* grpc_channel_stack_init( - grpc_exec_ctx* exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, - void* destroy_arg, const grpc_channel_filter** filters, size_t filter_count, + int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, + const grpc_channel_filter** filters, size_t filter_count, const grpc_channel_args* channel_args, grpc_transport* optional_transport, const char* name, grpc_channel_stack* stack) { size_t call_size = @@ -117,8 +117,7 @@ grpc_error* grpc_channel_stack_init( args.is_last = i == (filter_count - 1); elems[i].filter = filters[i]; elems[i].channel_data = user_data; - grpc_error* error = - elems[i].filter->init_channel_elem(exec_ctx, &elems[i], &args); + grpc_error* error = elems[i].filter->init_channel_elem(&elems[i], &args); if (error != GRPC_ERROR_NONE) { if (first_error == GRPC_ERROR_NONE) { first_error = error; @@ -138,20 +137,18 @@ grpc_error* grpc_channel_stack_init( return first_error; } -void grpc_channel_stack_destroy(grpc_exec_ctx* exec_ctx, - grpc_channel_stack* stack) { +void grpc_channel_stack_destroy(grpc_channel_stack* stack) { grpc_channel_element* channel_elems = CHANNEL_ELEMS_FROM_STACK(stack); size_t count = stack->count; size_t i; /* destroy per-filter data */ for (i = 0; i < count; i++) { - channel_elems[i].filter->destroy_channel_elem(exec_ctx, &channel_elems[i]); + channel_elems[i].filter->destroy_channel_elem(&channel_elems[i]); } } -grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, - grpc_channel_stack* channel_stack, +grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, const grpc_call_element_args* elem_args) { @@ -174,8 +171,8 @@ grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, call_elems[i].filter = channel_elems[i].filter; call_elems[i].channel_data = channel_elems[i].channel_data; call_elems[i].call_data = user_data; - grpc_error* error = call_elems[i].filter->init_call_elem( - exec_ctx, &call_elems[i], elem_args); + grpc_error* error = + call_elems[i].filter->init_call_elem(&call_elems[i], elem_args); if (error != GRPC_ERROR_NONE) { if (first_error == GRPC_ERROR_NONE) { first_error = error; @@ -189,8 +186,7 @@ grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, return first_error; } -void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_call_stack* call_stack, +void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, grpc_polling_entity* pollent) { size_t count = call_stack->count; grpc_call_element* call_elems; @@ -203,18 +199,16 @@ void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, /* init per-filter data */ for (i = 0; i < count; i++) { - call_elems[i].filter->set_pollset_or_pollset_set(exec_ctx, &call_elems[i], - pollent); + call_elems[i].filter->set_pollset_or_pollset_set(&call_elems[i], pollent); user_data += ROUND_UP_TO_ALIGNMENT_SIZE(call_elems[i].filter->sizeof_call_data); } } void grpc_call_stack_ignore_set_pollset_or_pollset_set( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_polling_entity* pollent) {} + grpc_call_element* elem, grpc_polling_entity* pollent) {} -void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, +void grpc_call_stack_destroy(grpc_call_stack* stack, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { grpc_call_element* elems = CALL_ELEMS_FROM_STACK(stack); @@ -224,29 +218,27 @@ void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, /* destroy per-filter data */ for (i = 0; i < count; i++) { elems[i].filter->destroy_call_elem( - exec_ctx, &elems[i], final_info, + &elems[i], final_info, i == count - 1 ? then_schedule_closure : nullptr); } } -void grpc_call_next_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_call_next_op(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { grpc_call_element* next_elem = elem + 1; GRPC_CALL_LOG_OP(GPR_INFO, next_elem, op); - next_elem->filter->start_transport_stream_op_batch(exec_ctx, next_elem, op); + next_elem->filter->start_transport_stream_op_batch(next_elem, op); } -void grpc_channel_next_get_info(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +void grpc_channel_next_get_info(grpc_channel_element* elem, const grpc_channel_info* channel_info) { grpc_channel_element* next_elem = elem + 1; - next_elem->filter->get_channel_info(exec_ctx, next_elem, channel_info); + next_elem->filter->get_channel_info(next_elem, channel_info); } -void grpc_channel_next_op(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op) { +void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op) { grpc_channel_element* next_elem = elem + 1; - next_elem->filter->start_transport_op(exec_ctx, next_elem, op); + next_elem->filter->start_transport_op(next_elem, op); } grpc_channel_stack* grpc_channel_stack_from_top_element( diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 1b6e5396a5..716866be26 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -96,14 +96,12 @@ typedef struct { typedef struct { /* Called to eg. send/receive data on a call. See grpc_call_next_op on how to call the next element in the stack */ - void (*start_transport_stream_op_batch)(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + void (*start_transport_stream_op_batch)(grpc_call_element* elem, grpc_transport_stream_op_batch* op); /* Called to handle channel level operations - e.g. new calls, or transport closure. See grpc_channel_next_op on how to call the next element in the stack */ - void (*start_transport_op)(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, grpc_transport_op* op); + void (*start_transport_op)(grpc_channel_element* elem, grpc_transport_op* op); /* sizeof(per call data) */ size_t sizeof_call_data; @@ -116,11 +114,9 @@ typedef struct { transport and is on the server. Most filters want to ignore this argument. Implementations may assume that elem->call_data is all zeros. */ - grpc_error* (*init_call_elem)(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + grpc_error* (*init_call_elem)(grpc_call_element* elem, const grpc_call_element_args* args); - void (*set_pollset_or_pollset_set)(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + void (*set_pollset_or_pollset_set)(grpc_call_element* elem, grpc_polling_entity* pollent); /* Destroy per call data. The filter does not need to do any chaining. @@ -128,7 +124,7 @@ typedef struct { \a then_schedule_closure that should be passed to GRPC_CLOSURE_SCHED when destruction is complete. \a final_info contains data about the completed call, mainly for reporting purposes. */ - void (*destroy_call_elem)(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + void (*destroy_call_elem)(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure); @@ -141,16 +137,14 @@ typedef struct { useful for asserting correct configuration by upper layer code. The filter does not need to do any chaining. Implementations may assume that elem->call_data is all zeros. */ - grpc_error* (*init_channel_elem)(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, + grpc_error* (*init_channel_elem)(grpc_channel_element* elem, grpc_channel_element_args* args); /* Destroy per channel data. The filter does not need to do any chaining */ - void (*destroy_channel_elem)(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem); + void (*destroy_channel_elem)(grpc_channel_element* elem); /* Implement grpc_channel_get_info() */ - void (*get_channel_info)(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + void (*get_channel_info)(grpc_channel_element* elem, const grpc_channel_info* channel_info); /* The name of this filter */ @@ -208,68 +202,62 @@ size_t grpc_channel_stack_size(const grpc_channel_filter** filters, size_t filter_count); /* Initialize a channel stack given some filters */ grpc_error* grpc_channel_stack_init( - grpc_exec_ctx* exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, - void* destroy_arg, const grpc_channel_filter** filters, size_t filter_count, + int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, + const grpc_channel_filter** filters, size_t filter_count, const grpc_channel_args* args, grpc_transport* optional_transport, const char* name, grpc_channel_stack* stack); /* Destroy a channel stack */ -void grpc_channel_stack_destroy(grpc_exec_ctx* exec_ctx, - grpc_channel_stack* stack); +void grpc_channel_stack_destroy(grpc_channel_stack* stack); /* Initialize a call stack given a channel stack. transport_server_data is expected to be NULL on a client, or an opaque transport owned pointer on the server. */ -grpc_error* grpc_call_stack_init(grpc_exec_ctx* exec_ctx, - grpc_channel_stack* channel_stack, +grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void* destroy_arg, const grpc_call_element_args* elem_args); /* Set a pollset or a pollset_set for a call stack: must occur before the first * op is started */ -void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_call_stack* call_stack, +void grpc_call_stack_set_pollset_or_pollset_set(grpc_call_stack* call_stack, grpc_polling_entity* pollent); #ifndef NDEBUG #define GRPC_CALL_STACK_REF(call_stack, reason) \ grpc_stream_ref(&(call_stack)->refcount, reason) -#define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ - grpc_stream_unref(exec_ctx, &(call_stack)->refcount, reason) +#define GRPC_CALL_STACK_UNREF(call_stack, reason) \ + grpc_stream_unref(&(call_stack)->refcount, reason) #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ grpc_stream_ref(&(channel_stack)->refcount, reason) -#define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ - grpc_stream_unref(exec_ctx, &(channel_stack)->refcount, reason) +#define GRPC_CHANNEL_STACK_UNREF(channel_stack, reason) \ + grpc_stream_unref(&(channel_stack)->refcount, reason) #else #define GRPC_CALL_STACK_REF(call_stack, reason) \ grpc_stream_ref(&(call_stack)->refcount) -#define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ - grpc_stream_unref(exec_ctx, &(call_stack)->refcount) +#define GRPC_CALL_STACK_UNREF(call_stack, reason) \ + grpc_stream_unref(&(call_stack)->refcount) #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ grpc_stream_ref(&(channel_stack)->refcount) -#define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ - grpc_stream_unref(exec_ctx, &(channel_stack)->refcount) +#define GRPC_CHANNEL_STACK_UNREF(channel_stack, reason) \ + grpc_stream_unref(&(channel_stack)->refcount) #endif /* Destroy a call stack */ -void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, +void grpc_call_stack_destroy(grpc_call_stack* stack, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure); /* Ignore set pollset{_set} - used by filters if they don't care about pollsets * at all. Does nothing. */ void grpc_call_stack_ignore_set_pollset_or_pollset_set( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_polling_entity* pollent); + grpc_call_element* elem, grpc_polling_entity* pollent); /* Call the next operation in a call stack */ -void grpc_call_next_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +void grpc_call_next_op(grpc_call_element* elem, grpc_transport_stream_op_batch* op); /* Call the next operation (depending on call directionality) in a channel stack */ -void grpc_channel_next_op(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op); +void grpc_channel_next_op(grpc_channel_element* elem, grpc_transport_op* op); /* Pass through a request to get_channel_info() to the next child element */ -void grpc_channel_next_get_info(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +void grpc_channel_next_get_info(grpc_channel_element* elem, const grpc_channel_info* channel_info); /* Given the top element of a channel stack, get the channel stack itself */ diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 77b7854f94..fcba826644 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -150,10 +150,9 @@ void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder* builder, } void grpc_channel_stack_builder_set_channel_arguments( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, - const grpc_channel_args* args) { + grpc_channel_stack_builder* builder, const grpc_channel_args* args) { if (builder->args != nullptr) { - grpc_channel_args_destroy(exec_ctx, builder->args); + grpc_channel_args_destroy(builder->args); } builder->args = grpc_channel_args_copy(args); } @@ -241,8 +240,7 @@ bool grpc_channel_stack_builder_add_filter_after( return true; } -void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder) { +void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder* builder) { filter_node* p = builder->begin.next; while (p != &builder->end) { filter_node* next = p->next; @@ -250,16 +248,15 @@ void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, p = next; } if (builder->args != nullptr) { - grpc_channel_args_destroy(exec_ctx, builder->args); + grpc_channel_args_destroy(builder->args); } gpr_free(builder->target); gpr_free(builder); } grpc_error* grpc_channel_stack_builder_finish( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, - size_t prefix_bytes, int initial_refs, grpc_iomgr_cb_func destroy, - void* destroy_arg, void** result) { + grpc_channel_stack_builder* builder, size_t prefix_bytes, int initial_refs, + grpc_iomgr_cb_func destroy, void* destroy_arg, void** result) { // count the number of filters size_t num_filters = 0; for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) { @@ -284,12 +281,12 @@ grpc_error* grpc_channel_stack_builder_finish( (grpc_channel_stack*)((char*)(*result) + prefix_bytes); // and initialize it grpc_error* error = grpc_channel_stack_init( - exec_ctx, initial_refs, destroy, - destroy_arg == nullptr ? *result : destroy_arg, filters, num_filters, - builder->args, builder->transport, builder->name, channel_stack); + initial_refs, destroy, destroy_arg == nullptr ? *result : destroy_arg, + filters, num_filters, builder->args, builder->transport, builder->name, + channel_stack); if (error != GRPC_ERROR_NONE) { - grpc_channel_stack_destroy(exec_ctx, channel_stack); + grpc_channel_stack_destroy(channel_stack); gpr_free(*result); *result = nullptr; } else { @@ -305,7 +302,7 @@ grpc_error* grpc_channel_stack_builder_finish( } } - grpc_channel_stack_builder_destroy(exec_ctx, builder); + grpc_channel_stack_builder_destroy(builder); gpr_free((grpc_channel_filter**)filters); return error; diff --git a/src/core/lib/channel/channel_stack_builder.h b/src/core/lib/channel/channel_stack_builder.h index 10019542b1..d00ddc698c 100644 --- a/src/core/lib/channel/channel_stack_builder.h +++ b/src/core/lib/channel/channel_stack_builder.h @@ -54,8 +54,7 @@ grpc_transport* grpc_channel_stack_builder_get_transport( /// Set channel arguments: copies args void grpc_channel_stack_builder_set_channel_arguments( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, - const grpc_channel_args* args); + grpc_channel_stack_builder* builder, const grpc_channel_args* args); /// Return a borrowed pointer to the channel arguments const grpc_channel_args* grpc_channel_stack_builder_get_channel_arguments( @@ -148,13 +147,11 @@ void grpc_channel_stack_builder_iterator_destroy( /// \a initial_refs, \a destroy, \a destroy_arg are as per /// grpc_channel_stack_init grpc_error* grpc_channel_stack_builder_finish( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, - size_t prefix_bytes, int initial_refs, grpc_iomgr_cb_func destroy, - void* destroy_arg, void** result); + grpc_channel_stack_builder* builder, size_t prefix_bytes, int initial_refs, + grpc_iomgr_cb_func destroy, void* destroy_arg, void** result); /// Destroy the builder without creating a channel stack -void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder); +void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder* builder); extern grpc_core::TraceFlag grpc_trace_channel_stack_builder; diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index af2f88ab2e..9d07cfff4e 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -51,17 +51,14 @@ typedef struct connected_channel_call_data { callback_state recv_message_ready; } call_data; -static void run_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void run_in_call_combiner(void* arg, grpc_error* error) { callback_state* state = (callback_state*)arg; - GRPC_CALL_COMBINER_START(exec_ctx, state->call_combiner, - state->original_closure, GRPC_ERROR_REF(error), - state->reason); + GRPC_CALL_COMBINER_START(state->call_combiner, state->original_closure, + GRPC_ERROR_REF(error), state->reason); } -static void run_cancel_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - run_in_call_combiner(exec_ctx, arg, error); +static void run_cancel_in_call_combiner(void* arg, grpc_error* error) { + run_in_call_combiner(arg, error); gpr_free(arg); } @@ -98,8 +95,7 @@ static callback_state* get_state_for_batch( /* Intercept a call operation and either push it directly up or translate it into transport stream operations */ static void con_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (batch->recv_initial_metadata) { @@ -126,58 +122,52 @@ static void con_start_transport_stream_op_batch( callback_state* state = get_state_for_batch(calld, batch); intercept_callback(calld, state, false, "on_complete", &batch->on_complete); } - grpc_transport_perform_stream_op(exec_ctx, chand->transport, - TRANSPORT_STREAM_FROM_CALL_DATA(calld), - batch); - GRPC_CALL_COMBINER_STOP(exec_ctx, calld->call_combiner, - "passed batch to transport"); + grpc_transport_perform_stream_op( + chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), batch); + GRPC_CALL_COMBINER_STOP(calld->call_combiner, "passed batch to transport"); } -static void con_start_transport_op(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void con_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_perform_op(exec_ctx, chand->transport, op); + grpc_transport_perform_op(chand->transport, op); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; calld->call_combiner = args->call_combiner; int r = grpc_transport_init_stream( - exec_ctx, chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), + chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), &args->call_stack->refcount, args->server_transport_data, args->arena); return r == 0 ? GRPC_ERROR_NONE : GRPC_ERROR_CREATE_FROM_STATIC_STRING( "transport stream initialization failed"); } -static void set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_set_pops(exec_ctx, chand->transport, + grpc_transport_set_pops(chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), pollent); } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - grpc_transport_destroy_stream(exec_ctx, chand->transport, + grpc_transport_destroy_stream(chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), then_schedule_closure); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* cd = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); @@ -186,17 +176,15 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for channel_data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { channel_data* cd = (channel_data*)elem->channel_data; if (cd->transport) { - grpc_transport_destroy(exec_ctx, cd->transport); + grpc_transport_destroy(cd->transport); } } /* No-op. */ -static void con_get_channel_info(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void con_get_channel_info(grpc_channel_element* elem, const grpc_channel_info* channel_info) {} const grpc_channel_filter grpc_connected_filter = { @@ -230,8 +218,7 @@ static void bind_transport(grpc_channel_stack* channel_stack, grpc_transport_stream_size((grpc_transport*)t); } -bool grpc_add_connected_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, void* arg_must_be_null) { GPR_ASSERT(arg_must_be_null == nullptr); grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); diff --git a/src/core/lib/channel/connected_channel.h b/src/core/lib/channel/connected_channel.h index cab8aad154..91de8022db 100644 --- a/src/core/lib/channel/connected_channel.h +++ b/src/core/lib/channel/connected_channel.h @@ -23,8 +23,7 @@ extern const grpc_channel_filter grpc_connected_filter; -bool grpc_add_connected_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +bool grpc_add_connected_filter(grpc_channel_stack_builder* builder, void* arg_must_be_null); /* Debug helper to dig the transport stream out of a call element */ diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc index 58c30b165b..dcb149c03e 100644 --- a/src/core/lib/channel/handshaker.cc +++ b/src/core/lib/channel/handshaker.cc @@ -34,23 +34,20 @@ void grpc_handshaker_init(const grpc_handshaker_vtable* vtable, handshaker->vtable = vtable; } -void grpc_handshaker_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker) { - handshaker->vtable->destroy(exec_ctx, handshaker); +void grpc_handshaker_destroy(grpc_handshaker* handshaker) { + handshaker->vtable->destroy(handshaker); } -void grpc_handshaker_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, grpc_error* why) { - handshaker->vtable->shutdown(exec_ctx, handshaker, why); +void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) { + handshaker->vtable->shutdown(handshaker, why); } -void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +void grpc_handshaker_do_handshake(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - handshaker->vtable->do_handshake(exec_ctx, handshaker, acceptor, - on_handshake_done, args); + handshaker->vtable->do_handshake(handshaker, acceptor, on_handshake_done, + args); } // @@ -116,9 +113,9 @@ void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, } void grpc_handshake_manager_pending_list_shutdown_all( - grpc_exec_ctx* exec_ctx, grpc_handshake_manager* head, grpc_error* why) { + grpc_handshake_manager* head, grpc_error* why) { while (head != nullptr) { - grpc_handshake_manager_shutdown(exec_ctx, head, GRPC_ERROR_REF(why)); + grpc_handshake_manager_shutdown(head, GRPC_ERROR_REF(why)); head = head->next; } GRPC_ERROR_UNREF(why); @@ -145,11 +142,10 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr, gpr_mu_unlock(&mgr->mu); } -static void grpc_handshake_manager_unref(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr) { +static void grpc_handshake_manager_unref(grpc_handshake_manager* mgr) { if (gpr_unref(&mgr->refs)) { for (size_t i = 0; i < mgr->count; ++i) { - grpc_handshaker_destroy(exec_ctx, mgr->handshakers[i]); + grpc_handshaker_destroy(mgr->handshakers[i]); } gpr_free(mgr->handshakers); gpr_mu_destroy(&mgr->mu); @@ -157,19 +153,17 @@ static void grpc_handshake_manager_unref(grpc_exec_ctx* exec_ctx, } } -void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr) { - grpc_handshake_manager_unref(exec_ctx, mgr); +void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr) { + grpc_handshake_manager_unref(mgr); } -void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr, +void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, grpc_error* why) { gpr_mu_lock(&mgr->mu); // Shutdown the handshaker that's currently in progress, if any. if (!mgr->shutdown && mgr->index > 0) { mgr->shutdown = true; - grpc_handshaker_shutdown(exec_ctx, mgr->handshakers[mgr->index - 1], + grpc_handshaker_shutdown(mgr->handshakers[mgr->index - 1], GRPC_ERROR_REF(why)); } gpr_mu_unlock(&mgr->mu); @@ -179,8 +173,7 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, // Helper function to call either the next handshaker or the // on_handshake_done callback. // Returns true if we've scheduled the on_handshake_done callback. -static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr, +static bool call_next_handshaker_locked(grpc_handshake_manager* mgr, grpc_error* error) { GPR_ASSERT(mgr->index <= mgr->count); // If we got an error or we've been shut down or we're exiting early or @@ -190,13 +183,12 @@ static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx, mgr->index == mgr->count) { // Cancel deadline timer, since we're invoking the on_handshake_done // callback now. - grpc_timer_cancel(exec_ctx, &mgr->deadline_timer); - GRPC_CLOSURE_SCHED(exec_ctx, &mgr->on_handshake_done, error); + grpc_timer_cancel(&mgr->deadline_timer); + GRPC_CLOSURE_SCHED(&mgr->on_handshake_done, error); mgr->shutdown = true; } else { - grpc_handshaker_do_handshake(exec_ctx, mgr->handshakers[mgr->index], - mgr->acceptor, &mgr->call_next_handshaker, - &mgr->args); + grpc_handshaker_do_handshake(mgr->handshakers[mgr->index], mgr->acceptor, + &mgr->call_next_handshaker, &mgr->args); } ++mgr->index; return mgr->shutdown; @@ -204,37 +196,34 @@ static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx, // A function used as the handshaker-done callback when chaining // handshakers together. -static void call_next_handshaker(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void call_next_handshaker(void* arg, grpc_error* error) { grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; gpr_mu_lock(&mgr->mu); - bool done = call_next_handshaker_locked(exec_ctx, mgr, GRPC_ERROR_REF(error)); + bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_REF(error)); gpr_mu_unlock(&mgr->mu); // If we're invoked the final callback, we won't be coming back // to this function, so we can release our reference to the // handshake manager. if (done) { - grpc_handshake_manager_unref(exec_ctx, mgr); + grpc_handshake_manager_unref(mgr); } } // Callback invoked when deadline is exceeded. -static void on_timeout(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_timeout(void* arg, grpc_error* error) { grpc_handshake_manager* mgr = (grpc_handshake_manager*)arg; if (error == GRPC_ERROR_NONE) { // Timer fired, rather than being cancelled. grpc_handshake_manager_shutdown( - exec_ctx, mgr, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); + mgr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out")); } - grpc_handshake_manager_unref(exec_ctx, mgr); + grpc_handshake_manager_unref(mgr); } void grpc_handshake_manager_do_handshake( - grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, - grpc_pollset_set* interested_parties, grpc_endpoint* endpoint, - const grpc_channel_args* channel_args, grpc_millis deadline, - grpc_tcp_server_acceptor* acceptor, grpc_iomgr_cb_func on_handshake_done, - void* user_data) { + grpc_handshake_manager* mgr, grpc_pollset_set* interested_parties, + grpc_endpoint* endpoint, const grpc_channel_args* channel_args, + grpc_millis deadline, grpc_tcp_server_acceptor* acceptor, + grpc_iomgr_cb_func on_handshake_done, void* user_data) { gpr_mu_lock(&mgr->mu); GPR_ASSERT(mgr->index == 0); GPR_ASSERT(!mgr->shutdown); @@ -257,12 +246,12 @@ void grpc_handshake_manager_do_handshake( gpr_ref(&mgr->refs); GRPC_CLOSURE_INIT(&mgr->on_timeout, on_timeout, mgr, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &mgr->deadline_timer, deadline, &mgr->on_timeout); + grpc_timer_init(&mgr->deadline_timer, deadline, &mgr->on_timeout); // Start first handshaker, which also owns a ref. gpr_ref(&mgr->refs); - bool done = call_next_handshaker_locked(exec_ctx, mgr, GRPC_ERROR_NONE); + bool done = call_next_handshaker_locked(mgr, GRPC_ERROR_NONE); gpr_mu_unlock(&mgr->mu); if (done) { - grpc_handshake_manager_unref(exec_ctx, mgr); + grpc_handshake_manager_unref(mgr); } } diff --git a/src/core/lib/channel/handshaker.h b/src/core/lib/channel/handshaker.h index 8e4114dc64..68e5463123 100644 --- a/src/core/lib/channel/handshaker.h +++ b/src/core/lib/channel/handshaker.h @@ -68,18 +68,17 @@ typedef struct { typedef struct { /// Destroys the handshaker. - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker); + void (*destroy)(grpc_handshaker* handshaker); /// Shuts down the handshaker (e.g., to clean up when the operation is /// aborted in the middle). - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker, - grpc_error* why); + void (*shutdown)(grpc_handshaker* handshaker, grpc_error* why); /// Performs handshaking, modifying \a args as needed (e.g., to /// replace \a endpoint with a wrapped endpoint). /// When finished, invokes \a on_handshake_done. /// \a acceptor will be NULL for client-side handshakers. - void (*do_handshake)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker, + void (*do_handshake)(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args); @@ -95,12 +94,9 @@ struct grpc_handshaker { void grpc_handshaker_init(const grpc_handshaker_vtable* vtable, grpc_handshaker* handshaker); -void grpc_handshaker_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker); -void grpc_handshaker_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, grpc_error* why); -void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +void grpc_handshaker_destroy(grpc_handshaker* handshaker); +void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why); +void grpc_handshaker_do_handshake(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args); @@ -120,15 +116,13 @@ void grpc_handshake_manager_add(grpc_handshake_manager* mgr, grpc_handshaker* handshaker); /// Destroys the handshake manager. -void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr); +void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr); /// Shuts down the handshake manager (e.g., to clean up when the operation is /// aborted in the middle). /// The caller must still call grpc_handshake_manager_destroy() after /// calling this function. -void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshake_manager* mgr, +void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr, grpc_error* why); /// Invokes handshakers in the order they were added. @@ -146,11 +140,10 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, /// the necessary clean-up. Otherwise, the callback takes ownership of /// the arguments. void grpc_handshake_manager_do_handshake( - grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, - grpc_pollset_set* interested_parties, grpc_endpoint* endpoint, - const grpc_channel_args* channel_args, grpc_millis deadline, - grpc_tcp_server_acceptor* acceptor, grpc_iomgr_cb_func on_handshake_done, - void* user_data); + grpc_handshake_manager* mgr, grpc_pollset_set* interested_parties, + grpc_endpoint* endpoint, const grpc_channel_args* channel_args, + grpc_millis deadline, grpc_tcp_server_acceptor* acceptor, + grpc_iomgr_cb_func on_handshake_done, void* user_data); /// Add \a mgr to the server side list of all pending handshake managers, the /// list starts with \a *head. @@ -166,6 +159,6 @@ void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, /// Shutdown all pending handshake managers on the server side. // Not thread-safe. Caller needs to synchronize. void grpc_handshake_manager_pending_list_shutdown_all( - grpc_exec_ctx* exec_ctx, grpc_handshake_manager* head, grpc_error* why); + grpc_handshake_manager* head, grpc_error* why); #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_H */ diff --git a/src/core/lib/channel/handshaker_factory.cc b/src/core/lib/channel/handshaker_factory.cc index 015006ade0..2380d98300 100644 --- a/src/core/lib/channel/handshaker_factory.cc +++ b/src/core/lib/channel/handshaker_factory.cc @@ -21,19 +21,19 @@ #include void grpc_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { if (handshaker_factory != nullptr) { GPR_ASSERT(handshaker_factory->vtable != nullptr); - handshaker_factory->vtable->add_handshakers(exec_ctx, handshaker_factory, - args, handshake_mgr); + handshaker_factory->vtable->add_handshakers(handshaker_factory, args, + handshake_mgr); } } void grpc_handshaker_factory_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) { + grpc_handshaker_factory* handshaker_factory) { if (handshaker_factory != nullptr) { GPR_ASSERT(handshaker_factory->vtable != nullptr); - handshaker_factory->vtable->destroy(exec_ctx, handshaker_factory); + handshaker_factory->vtable->destroy(handshaker_factory); } } diff --git a/src/core/lib/channel/handshaker_factory.h b/src/core/lib/channel/handshaker_factory.h index ca7c26b50a..8a7c0157e8 100644 --- a/src/core/lib/channel/handshaker_factory.h +++ b/src/core/lib/channel/handshaker_factory.h @@ -29,12 +29,10 @@ typedef struct grpc_handshaker_factory grpc_handshaker_factory; typedef struct { - void (*add_handshakers)(grpc_exec_ctx* exec_ctx, - grpc_handshaker_factory* handshaker_factory, + void (*add_handshakers)(grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); - void (*destroy)(grpc_exec_ctx* exec_ctx, - grpc_handshaker_factory* handshaker_factory); + void (*destroy)(grpc_handshaker_factory* handshaker_factory); } grpc_handshaker_factory_vtable; struct grpc_handshaker_factory { @@ -42,10 +40,10 @@ struct grpc_handshaker_factory { }; void grpc_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); + grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr); void grpc_handshaker_factory_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory); + grpc_handshaker_factory* handshaker_factory); #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H */ diff --git a/src/core/lib/channel/handshaker_registry.cc b/src/core/lib/channel/handshaker_registry.cc index c6bc87d704..098eabf084 100644 --- a/src/core/lib/channel/handshaker_registry.cc +++ b/src/core/lib/channel/handshaker_registry.cc @@ -47,18 +47,17 @@ static void grpc_handshaker_factory_list_register( } static void grpc_handshaker_factory_list_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshaker_factory_list* list, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { for (size_t i = 0; i < list->num_factories; ++i) { - grpc_handshaker_factory_add_handshakers(exec_ctx, list->list[i], args, - handshake_mgr); + grpc_handshaker_factory_add_handshakers(list->list[i], args, handshake_mgr); } } static void grpc_handshaker_factory_list_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list) { + grpc_handshaker_factory_list* list) { for (size_t i = 0; i < list->num_factories; ++i) { - grpc_handshaker_factory_destroy(exec_ctx, list->list[i]); + grpc_handshaker_factory_destroy(list->list[i]); } gpr_free(list->list); } @@ -74,10 +73,9 @@ void grpc_handshaker_factory_registry_init() { memset(g_handshaker_factory_lists, 0, sizeof(g_handshaker_factory_lists)); } -void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx) { +void grpc_handshaker_factory_registry_shutdown() { for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; ++i) { - grpc_handshaker_factory_list_destroy(exec_ctx, - &g_handshaker_factory_lists[i]); + grpc_handshaker_factory_list_destroy(&g_handshaker_factory_lists[i]); } } @@ -88,11 +86,9 @@ void grpc_handshaker_factory_register(bool at_start, &g_handshaker_factory_lists[handshaker_type], at_start, factory); } -void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, - grpc_handshaker_type handshaker_type, +void grpc_handshakers_add(grpc_handshaker_type handshaker_type, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { grpc_handshaker_factory_list_add_handshakers( - exec_ctx, &g_handshaker_factory_lists[handshaker_type], args, - handshake_mgr); + &g_handshaker_factory_lists[handshaker_type], args, handshake_mgr); } diff --git a/src/core/lib/channel/handshaker_registry.h b/src/core/lib/channel/handshaker_registry.h index a3b2ac1dc7..0b05531b7e 100644 --- a/src/core/lib/channel/handshaker_registry.h +++ b/src/core/lib/channel/handshaker_registry.h @@ -31,7 +31,7 @@ typedef enum { } grpc_handshaker_type; void grpc_handshaker_factory_registry_init(); -void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx); +void grpc_handshaker_factory_registry_shutdown(); /// Registers a new handshaker factory. Takes ownership. /// If \a at_start is true, the new handshaker will be at the beginning of @@ -40,8 +40,7 @@ void grpc_handshaker_factory_register(bool at_start, grpc_handshaker_type handshaker_type, grpc_handshaker_factory* factory); -void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, - grpc_handshaker_type handshaker_type, +void grpc_handshakers_add(grpc_handshaker_type handshaker_type, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr); diff --git a/src/core/lib/compression/message_compress.cc b/src/core/lib/compression/message_compress.cc index c051e28864..aa43a53f2b 100644 --- a/src/core/lib/compression/message_compress.cc +++ b/src/core/lib/compression/message_compress.cc @@ -29,8 +29,8 @@ #define OUTPUT_BLOCK_SIZE 1024 -static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs, - grpc_slice_buffer* input, grpc_slice_buffer* output, +static int zlib_body(z_stream* zs, grpc_slice_buffer* input, + grpc_slice_buffer* output, int (*flate)(z_stream* zs, int flush)) { int r; int flush; @@ -74,7 +74,7 @@ static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs, return 1; error: - grpc_slice_unref_internal(exec_ctx, outbuf); + grpc_slice_unref_internal(outbuf); return 0; } @@ -84,8 +84,8 @@ static void* zalloc_gpr(void* opaque, unsigned int items, unsigned int size) { static void zfree_gpr(void* opaque, void* address) { gpr_free(address); } -static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, - grpc_slice_buffer* output, int gzip) { +static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output, + int gzip) { z_stream zs; int r; size_t i; @@ -97,11 +97,10 @@ static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0), 8, Z_DEFAULT_STRATEGY); GPR_ASSERT(r == Z_OK); - r = zlib_body(exec_ctx, &zs, input, output, deflate) && - output->length < input->length; + r = zlib_body(&zs, input, output, deflate) && output->length < input->length; if (!r) { for (i = count_before; i < output->count; i++) { - grpc_slice_unref_internal(exec_ctx, output->slices[i]); + grpc_slice_unref_internal(output->slices[i]); } output->count = count_before; output->length = length_before; @@ -110,8 +109,8 @@ static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, return r; } -static int zlib_decompress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, - grpc_slice_buffer* output, int gzip) { +static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output, + int gzip) { z_stream zs; int r; size_t i; @@ -122,10 +121,10 @@ static int zlib_decompress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, zs.zfree = zfree_gpr; r = inflateInit2(&zs, 15 | (gzip ? 16 : 0)); GPR_ASSERT(r == Z_OK); - r = zlib_body(exec_ctx, &zs, input, output, inflate); + r = zlib_body(&zs, input, output, inflate); if (!r) { for (i = count_before; i < output->count; i++) { - grpc_slice_unref_internal(exec_ctx, output->slices[i]); + grpc_slice_unref_internal(output->slices[i]); } output->count = count_before; output->length = length_before; @@ -142,8 +141,7 @@ static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) { return 1; } -static int compress_inner(grpc_exec_ctx* exec_ctx, - grpc_compression_algorithm algorithm, +static int compress_inner(grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -151,9 +149,9 @@ static int compress_inner(grpc_exec_ctx* exec_ctx, rely on that here */ return 0; case GRPC_COMPRESS_DEFLATE: - return zlib_compress(exec_ctx, input, output, 0); + return zlib_compress(input, output, 0); case GRPC_COMPRESS_GZIP: - return zlib_compress(exec_ctx, input, output, 1); + return zlib_compress(input, output, 1); case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } @@ -161,26 +159,24 @@ static int compress_inner(grpc_exec_ctx* exec_ctx, return 0; } -int grpc_msg_compress(grpc_exec_ctx* exec_ctx, - grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { - if (!compress_inner(exec_ctx, algorithm, input, output)) { + if (!compress_inner(algorithm, input, output)) { copy(input, output); return 0; } return 1; } -int grpc_msg_decompress(grpc_exec_ctx* exec_ctx, - grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output) { switch (algorithm) { case GRPC_COMPRESS_NONE: return copy(input, output); case GRPC_COMPRESS_DEFLATE: - return zlib_decompress(exec_ctx, input, output, 0); + return zlib_decompress(input, output, 0); case GRPC_COMPRESS_GZIP: - return zlib_decompress(exec_ctx, input, output, 1); + return zlib_decompress(input, output, 1); case GRPC_COMPRESS_ALGORITHMS_COUNT: break; } diff --git a/src/core/lib/compression/message_compress.h b/src/core/lib/compression/message_compress.h index ca8ca37f8e..c963fccc73 100644 --- a/src/core/lib/compression/message_compress.h +++ b/src/core/lib/compression/message_compress.h @@ -25,15 +25,13 @@ /* compress 'input' to 'output' using 'algorithm'. On success, appends compressed slices to output and returns 1. On failure, appends uncompressed slices to output and returns 0. */ -int grpc_msg_compress(grpc_exec_ctx* exec_ctx, - grpc_compression_algorithm algorithm, +int grpc_msg_compress(grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); /* decompress 'input' to 'output' using 'algorithm'. On success, appends slices to output and returns 1. On failure, output is unchanged, and returns 0. */ -int grpc_msg_decompress(grpc_exec_ctx* exec_ctx, - grpc_compression_algorithm algorithm, +int grpc_msg_decompress(grpc_compression_algorithm algorithm, grpc_slice_buffer* input, grpc_slice_buffer* output); #endif /* GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H */ diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 0c3fdd1269..9d829b31db 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -40,7 +40,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, /* Full flush is not allowed when inflating. */ GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; int r; bool eoc = false; size_t original_max_output_size = max_output_size; @@ -57,8 +57,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, r = ctx->flate(&ctx->zs, Z_NO_FLUSH); if (r < 0 && r != Z_BUF_ERROR) { gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(slice_out); + return false; } else if (r == Z_STREAM_END && ctx->flate == inflate) { eoc = true; @@ -69,7 +69,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in, GRPC_SLICE_LENGTH(slice))); } - grpc_slice_unref_internal(&exec_ctx, slice); + grpc_slice_unref_internal(slice); } if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) { GPR_ASSERT(in->length == 0); @@ -88,8 +88,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, break; default: gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(slice_out); + return false; } } else if (flush == Z_FINISH) { @@ -104,8 +104,8 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, break; default: gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(slice_out); + return false; } } @@ -117,11 +117,11 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx, slice_out.data.refcounted.length -= ctx->zs.avail_out; grpc_slice_buffer_add(out, slice_out); } else { - grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_slice_unref_internal(slice_out); } max_output_size -= (slice_size - ctx->zs.avail_out); } - grpc_exec_ctx_finish(&exec_ctx); + if (end_of_context) { *end_of_context = eoc; } diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc index 7d2af71c47..0b39b2b1e7 100644 --- a/src/core/lib/debug/stats.cc +++ b/src/core/lib/debug/stats.cc @@ -62,9 +62,9 @@ void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a, } } -int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx* exec_ctx, int value, - const int* table, int table_size) { - GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx); +int grpc_stats_histo_find_bucket_slow(int value, const int* table, + int table_size) { + GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(); const int* const start = table; while (table_size > 0) { int step = table_size / 2; diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index 55db44e0c2..02eed5e844 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -30,17 +30,15 @@ typedef struct grpc_stats_data { extern grpc_stats_data* grpc_stats_per_cpu_storage; -#define GRPC_THREAD_STATS_DATA(exec_ctx) \ - (&grpc_stats_per_cpu_storage[(exec_ctx)->starting_cpu]) +#define GRPC_THREAD_STATS_DATA() \ + (&grpc_stats_per_cpu_storage[grpc_core::ExecCtx::Get()->starting_cpu()]) -#define GRPC_STATS_INC_COUNTER(exec_ctx, ctr) \ - (gpr_atm_no_barrier_fetch_add( \ - &GRPC_THREAD_STATS_DATA((exec_ctx))->counters[(ctr)], 1)) +#define GRPC_STATS_INC_COUNTER(ctr) \ + (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1)) -#define GRPC_STATS_INC_HISTOGRAM(exec_ctx, histogram, index) \ - (gpr_atm_no_barrier_fetch_add( \ - &GRPC_THREAD_STATS_DATA((exec_ctx)) \ - ->histograms[histogram##_FIRST_SLOT + (index)], \ +#define GRPC_STATS_INC_HISTOGRAM(histogram, index) \ + (gpr_atm_no_barrier_fetch_add( \ + &GRPC_THREAD_STATS_DATA()->histograms[histogram##_FIRST_SLOT + (index)], \ 1)) void grpc_stats_init(void); @@ -50,8 +48,8 @@ void grpc_stats_collect(grpc_stats_data* output); void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a, grpc_stats_data* c); char* grpc_stats_data_as_json(const grpc_stats_data* data); -int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx* exec_ctx, int value, - const int* table, int table_size); +int grpc_stats_histo_find_bucket_slow(int value, const int* table, + int table_size); double grpc_stats_histo_percentile(const grpc_stats_data* data, grpc_stats_histograms histogram, double percentile); diff --git a/src/core/lib/debug/stats_data.cc b/src/core/lib/debug/stats_data.cc index 17e15f4cfb..996ed3de9a 100644 --- a/src/core/lib/debug/stats_data.cc +++ b/src/core/lib/debug/stats_data.cc @@ -342,11 +342,10 @@ const uint8_t grpc_stats_table_7[102] = { 42, 42, 43, 44, 44, 45, 46, 46, 47, 48, 48, 49, 49, 50, 50, 51, 51}; const int grpc_stats_table_8[9] = {0, 1, 2, 4, 7, 13, 23, 39, 64}; const uint8_t grpc_stats_table_9[9] = {0, 0, 1, 2, 2, 3, 4, 4, 5}; -void grpc_stats_inc_call_initial_size(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_call_initial_size(int value) { value = GPR_CLAMP(value, 0, 262144); if (value < 6) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, - value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, value); return; } union { @@ -359,19 +358,17 @@ void grpc_stats_inc_call_initial_size(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_1[((_val.uint - 4618441417868443648ull) >> 49)] + 6; _bkt.dbl = grpc_stats_table_0[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, - bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_0, 64)); } -void grpc_stats_inc_poll_events_returned(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_poll_events_returned(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 29) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value); return; } union { @@ -384,20 +381,17 @@ void grpc_stats_inc_poll_events_returned(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_3[((_val.uint - 4628855992006737920ull) >> 47)] + 29; _bkt.dbl = grpc_stats_table_2[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_2, 128)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_2, 128)); } -void grpc_stats_inc_tcp_write_size(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_tcp_write_size(int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, - value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, value); return; } union { @@ -410,19 +404,17 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, - bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_tcp_write_iov_size(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); return; } union { @@ -435,19 +427,17 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_tcp_read_size(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_tcp_read_size(int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, value); return; } union { @@ -460,19 +450,17 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_tcp_read_offer(int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, - value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, value); return; } union { @@ -485,20 +473,18 @@ void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, - bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_tcp_read_offer_iov_size(grpc_exec_ctx* exec_ctx, - int value) { +void grpc_stats_inc_tcp_read_offer_iov_size(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, + value); return; } union { @@ -511,21 +497,19 @@ void grpc_stats_inc_tcp_read_offer_iov_size(grpc_exec_ctx* exec_ctx, grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx* exec_ctx, - int value) { +void grpc_stats_inc_http2_send_message_size(int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, + value); return; } union { @@ -538,22 +522,19 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx* exec_ctx, grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_4[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_4, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64)); } -void grpc_stats_inc_http2_send_initial_metadata_per_write( - grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_http2_send_initial_metadata_per_write(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, - value); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, value); return; } union { @@ -567,21 +548,18 @@ void grpc_stats_inc_http2_send_initial_metadata_per_write( _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, - bucket); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, bucket); return; } GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, - grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_6, - 64)); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_message_per_write(grpc_exec_ctx* exec_ctx, - int value) { +void grpc_stats_inc_http2_send_message_per_write(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, + value); return; } union { @@ -594,22 +572,19 @@ void grpc_stats_inc_http2_send_message_per_write(grpc_exec_ctx* exec_ctx, grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_trailing_metadata_per_write( - grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_http2_send_trailing_metadata_per_write(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, - value); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, value); return; } union { @@ -623,21 +598,18 @@ void grpc_stats_inc_http2_send_trailing_metadata_per_write( _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, - bucket); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, bucket); return; } GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, - grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_6, - 64)); + GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_http2_send_flowctl_per_write(grpc_exec_ctx* exec_ctx, - int value) { +void grpc_stats_inc_http2_send_flowctl_per_write(int value) { value = GPR_CLAMP(value, 0, 1024); if (value < 13) { - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, + value); return; } union { @@ -650,20 +622,18 @@ void grpc_stats_inc_http2_send_flowctl_per_write(grpc_exec_ctx* exec_ctx, grpc_stats_table_7[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_6[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, + bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_6, 64)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64)); } -void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx* exec_ctx, int value) { +void grpc_stats_inc_server_cqs_checked(int value) { value = GPR_CLAMP(value, 0, 64); if (value < 3) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value); return; } union { @@ -676,13 +646,12 @@ void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx* exec_ctx, int value) { grpc_stats_table_9[((_val.uint - 4613937818241073152ull) >> 51)] + 3; _bkt.dbl = grpc_stats_table_8[bucket]; bucket -= (_val.uint < _bkt.uint); - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, bucket); + GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, bucket); return; } - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, - grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_8, 8)); + GRPC_STATS_INC_HISTOGRAM( + GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, + grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_8, 8)); } const int grpc_stats_histo_buckets[13] = {64, 128, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 8}; @@ -694,7 +663,7 @@ const int* const grpc_stats_histo_bucket_boundaries[13] = { grpc_stats_table_6, grpc_stats_table_4, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_6, grpc_stats_table_8}; -void (*const grpc_stats_inc_histogram[13])(grpc_exec_ctx* exec_ctx, int x) = { +void (*const grpc_stats_inc_histogram[13])(int x) = { grpc_stats_inc_call_initial_size, grpc_stats_inc_poll_events_returned, grpc_stats_inc_tcp_write_size, diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 8a5bc97389..4504be33e7 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -172,330 +172,262 @@ typedef enum { GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED_BUCKETS = 8, GRPC_STATS_HISTOGRAM_BUCKETS = 840 } grpc_stats_histogram_constants; -#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) -#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) -#define GRPC_STATS_INC_CQS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CQS_CREATED) -#define GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CHANNELS_CREATED) -#define GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_CLIENT_SUBCHANNELS_CREATED) -#define GRPC_STATS_INC_SERVER_CHANNELS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CHANNELS_CREATED) -#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) -#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) -#define GRPC_STATS_INC_POLLSET_KICK(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK) -#define GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_POLLSET_KICKED_WITHOUT_POLLER) -#define GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICKED_AGAIN) -#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_FD) -#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_CV) -#define GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_POLLSET_KICK_OWN_THREAD) -#define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) -#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) -#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) -#define GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_TCP_BACKUP_POLLERS_CREATED) -#define GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_TCP_BACKUP_POLLER_POLLS) -#define GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_BATCHES) -#define GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_CANCEL) -#define GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE) -#define GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE) -#define GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_SETTINGS_WRITES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_SETTINGS_WRITES) -#define GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_PINGS_SENT) -#define GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN) -#define GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_OFFLOADED) -#define GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_CONTINUED) -#define GRPC_STATS_INC_HTTP2_PARTIAL_WRITES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_PARTIAL_WRITES) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_CLIENT_CALLS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) +#define GRPC_STATS_INC_SERVER_CALLS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) +#define GRPC_STATS_INC_CQS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQS_CREATED) +#define GRPC_STATS_INC_CLIENT_CHANNELS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_CHANNELS_CREATED) +#define GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CLIENT_SUBCHANNELS_CREATED) +#define GRPC_STATS_INC_SERVER_CHANNELS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_CHANNELS_CREATED) +#define GRPC_STATS_INC_SYSCALL_POLL() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_POLL) +#define GRPC_STATS_INC_SYSCALL_WAIT() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_WAIT) +#define GRPC_STATS_INC_POLLSET_KICK() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK) +#define GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICKED_WITHOUT_POLLER) +#define GRPC_STATS_INC_POLLSET_KICKED_AGAIN() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICKED_AGAIN) +#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_FD) +#define GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_WAKEUP_CV) +#define GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_POLLSET_KICK_OWN_THREAD) +#define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) +#define GRPC_STATS_INC_SYSCALL_WRITE() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_TCP_BACKUP_POLLERS_CREATED) +#define GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_TCP_BACKUP_POLLER_POLLS) +#define GRPC_STATS_INC_HTTP2_OP_BATCHES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_BATCHES) +#define GRPC_STATS_INC_HTTP2_OP_CANCEL() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_CANCEL) +#define GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_SETTINGS_WRITES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_SETTINGS_WRITES) +#define GRPC_STATS_INC_HTTP2_PINGS_SENT() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_PINGS_SENT) +#define GRPC_STATS_INC_HTTP2_WRITES_BEGUN() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN) +#define GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_OFFLOADED) +#define GRPC_STATS_INC_HTTP2_WRITES_CONTINUED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_WRITES_CONTINUED) +#define GRPC_STATS_INC_HTTP2_PARTIAL_WRITES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_PARTIAL_WRITES) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_START_NEW_STREAM) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA( \ - exec_ctx) \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE() \ + GRPC_STATS_INC_COUNTER( \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_MESSAGE) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA() \ GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_TRAILING_METADATA) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RETRY_SEND_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_CONTINUE_PINGS) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT() \ + GRPC_STATS_INC_COUNTER( \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_GOAWAY_SENT) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM() \ + GRPC_STATS_INC_COUNTER( \ + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_RST_STREAM) +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_CLOSE_FROM_API) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_STREAM_FLOW_CONTROL) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_SEND_SETTINGS) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_BDP_ESTIMATOR_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_SETTING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FLOW_CONTROL_UNSTALLED_BY_UPDATE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_APPLICATION_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_KEEPALIVE_PING) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED( \ - exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_TRANSPORT_FLOW_CONTROL_UNSTALLED) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE() \ + GRPC_STATS_INC_COUNTER( \ GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_PING_RESPONSE) -#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM) -#define GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HTTP2_SPURIOUS_WRITES_BEGUN) -#define GRPC_STATS_INC_HPACK_RECV_INDEXED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_INDEXED) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX) -#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX_V) -#define GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_UNCOMPRESSED) -#define GRPC_STATS_INC_HPACK_RECV_HUFFMAN(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_HUFFMAN) -#define GRPC_STATS_INC_HPACK_RECV_BINARY(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_RECV_BINARY) -#define GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_RECV_BINARY_BASE64) -#define GRPC_STATS_INC_HPACK_SEND_INDEXED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_INDEXED) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX) -#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX_V(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX_V) -#define GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_UNCOMPRESSED) -#define GRPC_STATS_INC_HPACK_SEND_HUFFMAN(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_HUFFMAN) -#define GRPC_STATS_INC_HPACK_SEND_BINARY(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HPACK_SEND_BINARY) -#define GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_HPACK_SEND_BINARY_BASE64) -#define GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED) -#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS) -#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx) \ +#define GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM() \ GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS) -#define GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED) -#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_INITIATED) -#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS) -#define GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_SET_NOTIFY_ON_CANCEL) -#define GRPC_STATS_INC_CALL_COMBINER_CANCELLED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CALL_COMBINER_CANCELLED) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_SHORT_ITEMS) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_LONG_ITEMS) -#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF) -#define GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) -#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) -#define GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_PUSH_RETRIES) -#define GRPC_STATS_INC_SERVER_REQUESTED_CALLS(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS) -#define GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_FAILURES) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), \ - GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_SUCCESSES) -#define GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(exec_ctx) \ - GRPC_STATS_INC_COUNTER( \ - (exec_ctx), GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES) -#define GRPC_STATS_INC_CALL_INITIAL_SIZE(exec_ctx, value) \ - grpc_stats_inc_call_initial_size((exec_ctx), (int)(value)) -void grpc_stats_inc_call_initial_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, value) \ - grpc_stats_inc_poll_events_returned((exec_ctx), (int)(value)) -void grpc_stats_inc_poll_events_returned(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ - grpc_stats_inc_tcp_write_size((exec_ctx), (int)(value)) -void grpc_stats_inc_tcp_write_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ - grpc_stats_inc_tcp_write_iov_size((exec_ctx), (int)(value)) -void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ - grpc_stats_inc_tcp_read_size((exec_ctx), (int)(value)) -void grpc_stats_inc_tcp_read_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, value) \ - grpc_stats_inc_tcp_read_offer((exec_ctx), (int)(value)) -void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(exec_ctx, value) \ - grpc_stats_inc_tcp_read_offer_iov_size((exec_ctx), (int)(value)) -void grpc_stats_inc_tcp_read_offer_iov_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \ - grpc_stats_inc_http2_send_message_size((exec_ctx), (int)(value)) -void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE(exec_ctx, value) \ - grpc_stats_inc_http2_send_initial_metadata_per_write((exec_ctx), (int)(value)) -void grpc_stats_inc_http2_send_initial_metadata_per_write( - grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(exec_ctx, value) \ - grpc_stats_inc_http2_send_message_per_write((exec_ctx), (int)(value)) -void grpc_stats_inc_http2_send_message_per_write(grpc_exec_ctx* exec_ctx, - int x); -#define GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE(exec_ctx, value) \ - grpc_stats_inc_http2_send_trailing_metadata_per_write((exec_ctx), \ - (int)(value)) -void grpc_stats_inc_http2_send_trailing_metadata_per_write( - grpc_exec_ctx* exec_ctx, int x); -#define GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(exec_ctx, value) \ - grpc_stats_inc_http2_send_flowctl_per_write((exec_ctx), (int)(value)) -void grpc_stats_inc_http2_send_flowctl_per_write(grpc_exec_ctx* exec_ctx, - int x); -#define GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, value) \ - grpc_stats_inc_server_cqs_checked((exec_ctx), (int)(value)) -void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx* exec_ctx, int x); + GRPC_STATS_COUNTER_HTTP2_INITIATE_WRITE_DUE_TO_FORCE_RST_STREAM) +#define GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_SPURIOUS_WRITES_BEGUN) +#define GRPC_STATS_INC_HPACK_RECV_INDEXED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_INDEXED) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_INCIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NOTIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX) +#define GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_LITHDR_NVRIDX_V) +#define GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_UNCOMPRESSED) +#define GRPC_STATS_INC_HPACK_RECV_HUFFMAN() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_HUFFMAN) +#define GRPC_STATS_INC_HPACK_RECV_BINARY() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_BINARY) +#define GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_RECV_BINARY_BASE64) +#define GRPC_STATS_INC_HPACK_SEND_INDEXED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_INDEXED) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_INCIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NOTIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX) +#define GRPC_STATS_INC_HPACK_SEND_LITHDR_NVRIDX_V() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_LITHDR_NVRIDX_V) +#define GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_UNCOMPRESSED) +#define GRPC_STATS_INC_HPACK_SEND_HUFFMAN() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_HUFFMAN) +#define GRPC_STATS_INC_HPACK_SEND_BINARY() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_BINARY) +#define GRPC_STATS_INC_HPACK_SEND_BINARY_BASE64() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HPACK_SEND_BINARY_BASE64) +#define GRPC_STATS_INC_COMBINER_LOCKS_INITIATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS() \ + GRPC_STATS_INC_COUNTER( \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED) +#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_INITIATED) +#define GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_SET_NOTIFY_ON_CANCEL) +#define GRPC_STATS_INC_CALL_COMBINER_CANCELLED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CALL_COMBINER_CANCELLED) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_SHORT_ITEMS) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_LONG_ITEMS) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF) +#define GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) +#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) +#define GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_EXECUTOR_PUSH_RETRIES) +#define GRPC_STATS_INC_SERVER_REQUESTED_CALLS() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS) +#define GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_FAILURES) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRYLOCK_SUCCESSES) +#define GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES) +#define GRPC_STATS_INC_CALL_INITIAL_SIZE(value) \ + grpc_stats_inc_call_initial_size((int)(value)) +void grpc_stats_inc_call_initial_size(int x); +#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(value) \ + grpc_stats_inc_poll_events_returned((int)(value)) +void grpc_stats_inc_poll_events_returned(int x); +#define GRPC_STATS_INC_TCP_WRITE_SIZE(value) \ + grpc_stats_inc_tcp_write_size((int)(value)) +void grpc_stats_inc_tcp_write_size(int x); +#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(value) \ + grpc_stats_inc_tcp_write_iov_size((int)(value)) +void grpc_stats_inc_tcp_write_iov_size(int x); +#define GRPC_STATS_INC_TCP_READ_SIZE(value) \ + grpc_stats_inc_tcp_read_size((int)(value)) +void grpc_stats_inc_tcp_read_size(int x); +#define GRPC_STATS_INC_TCP_READ_OFFER(value) \ + grpc_stats_inc_tcp_read_offer((int)(value)) +void grpc_stats_inc_tcp_read_offer(int x); +#define GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(value) \ + grpc_stats_inc_tcp_read_offer_iov_size((int)(value)) +void grpc_stats_inc_tcp_read_offer_iov_size(int x); +#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(value) \ + grpc_stats_inc_http2_send_message_size((int)(value)) +void grpc_stats_inc_http2_send_message_size(int x); +#define GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE(value) \ + grpc_stats_inc_http2_send_initial_metadata_per_write((int)(value)) +void grpc_stats_inc_http2_send_initial_metadata_per_write(int x); +#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(value) \ + grpc_stats_inc_http2_send_message_per_write((int)(value)) +void grpc_stats_inc_http2_send_message_per_write(int x); +#define GRPC_STATS_INC_HTTP2_SEND_TRAILING_METADATA_PER_WRITE(value) \ + grpc_stats_inc_http2_send_trailing_metadata_per_write((int)(value)) +void grpc_stats_inc_http2_send_trailing_metadata_per_write(int x); +#define GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(value) \ + grpc_stats_inc_http2_send_flowctl_per_write((int)(value)) +void grpc_stats_inc_http2_send_flowctl_per_write(int x); +#define GRPC_STATS_INC_SERVER_CQS_CHECKED(value) \ + grpc_stats_inc_server_cqs_checked((int)(value)) +void grpc_stats_inc_server_cqs_checked(int x); extern const int grpc_stats_histo_buckets[13]; extern const int grpc_stats_histo_start[13]; extern const int* const grpc_stats_histo_bucket_boundaries[13]; -extern void (*const grpc_stats_inc_histogram[13])(grpc_exec_ctx* exec_ctx, - int x); +extern void (*const grpc_stats_inc_histogram[13])(int x); #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc index 73b484b06d..ed874c4265 100644 --- a/src/core/lib/http/httpcli.cc +++ b/src/core/lib/http/httpcli.cc @@ -63,13 +63,11 @@ typedef struct { static grpc_httpcli_get_override g_get_override = nullptr; static grpc_httpcli_post_override g_post_override = nullptr; -static void plaintext_handshake(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint, const char* host, - grpc_millis deadline, - void (*on_done)(grpc_exec_ctx* exec_ctx, - void* arg, +static void plaintext_handshake(void* arg, grpc_endpoint* endpoint, + const char* host, grpc_millis deadline, + void (*on_done)(void* arg, grpc_endpoint* endpoint)) { - on_done(exec_ctx, arg, endpoint); + on_done(arg, endpoint); } const grpc_httpcli_handshaker grpc_httpcli_plaintext = {"http", @@ -79,34 +77,31 @@ void grpc_httpcli_context_init(grpc_httpcli_context* context) { context->pollset_set = grpc_pollset_set_create(); } -void grpc_httpcli_context_destroy(grpc_exec_ctx* exec_ctx, - grpc_httpcli_context* context) { - grpc_pollset_set_destroy(exec_ctx, context->pollset_set); +void grpc_httpcli_context_destroy(grpc_httpcli_context* context) { + grpc_pollset_set_destroy(context->pollset_set); } -static void next_address(grpc_exec_ctx* exec_ctx, internal_request* req, - grpc_error* due_to_error); +static void next_address(internal_request* req, grpc_error* due_to_error); -static void finish(grpc_exec_ctx* exec_ctx, internal_request* req, - grpc_error* error) { - grpc_polling_entity_del_from_pollset_set(exec_ctx, req->pollent, +static void finish(internal_request* req, grpc_error* error) { + grpc_polling_entity_del_from_pollset_set(req->pollent, req->context->pollset_set); - GRPC_CLOSURE_SCHED(exec_ctx, req->on_done, error); + GRPC_CLOSURE_SCHED(req->on_done, error); grpc_http_parser_destroy(&req->parser); if (req->addresses != nullptr) { grpc_resolved_addresses_destroy(req->addresses); } if (req->ep != nullptr) { - grpc_endpoint_destroy(exec_ctx, req->ep); + grpc_endpoint_destroy(req->ep); } - grpc_slice_unref_internal(exec_ctx, req->request_text); + grpc_slice_unref_internal(req->request_text); gpr_free(req->host); gpr_free(req->ssl_host_override); grpc_iomgr_unregister_object(&req->iomgr_obj); - grpc_slice_buffer_destroy_internal(exec_ctx, &req->incoming); - grpc_slice_buffer_destroy_internal(exec_ctx, &req->outgoing); + grpc_slice_buffer_destroy_internal(&req->incoming); + grpc_slice_buffer_destroy_internal(&req->outgoing); GRPC_ERROR_UNREF(req->overall_error); - grpc_resource_quota_unref_internal(exec_ctx, req->resource_quota); + grpc_resource_quota_unref_internal(req->resource_quota); gpr_free(req); } @@ -124,12 +119,11 @@ static void append_error(internal_request* req, grpc_error* error) { gpr_free(addr_text); } -static void do_read(grpc_exec_ctx* exec_ctx, internal_request* req) { - grpc_endpoint_read(exec_ctx, req->ep, &req->incoming, &req->on_read); +static void do_read(internal_request* req) { + grpc_endpoint_read(req->ep, &req->incoming, &req->on_read); } -static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void on_read(void* user_data, grpc_error* error) { internal_request* req = (internal_request*)user_data; size_t i; @@ -139,77 +133,70 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, grpc_error* err = grpc_http_parser_parse( &req->parser, req->incoming.slices[i], nullptr); if (err != GRPC_ERROR_NONE) { - finish(exec_ctx, req, err); + finish(req, err); return; } } } if (error == GRPC_ERROR_NONE) { - do_read(exec_ctx, req); + do_read(req); } else if (!req->have_read_byte) { - next_address(exec_ctx, req, GRPC_ERROR_REF(error)); + next_address(req, GRPC_ERROR_REF(error)); } else { - finish(exec_ctx, req, grpc_http_parser_eof(&req->parser)); + finish(req, grpc_http_parser_eof(&req->parser)); } } -static void on_written(grpc_exec_ctx* exec_ctx, internal_request* req) { - do_read(exec_ctx, req); -} +static void on_written(internal_request* req) { do_read(req); } -static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void done_write(void* arg, grpc_error* error) { internal_request* req = (internal_request*)arg; if (error == GRPC_ERROR_NONE) { - on_written(exec_ctx, req); + on_written(req); } else { - next_address(exec_ctx, req, GRPC_ERROR_REF(error)); + next_address(req, GRPC_ERROR_REF(error)); } } -static void start_write(grpc_exec_ctx* exec_ctx, internal_request* req) { +static void start_write(internal_request* req) { grpc_slice_ref_internal(req->request_text); grpc_slice_buffer_add(&req->outgoing, req->request_text); - grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write); + grpc_endpoint_write(req->ep, &req->outgoing, &req->done_write); } -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* ep) { +static void on_handshake_done(void* arg, grpc_endpoint* ep) { internal_request* req = (internal_request*)arg; if (!ep) { - next_address( - exec_ctx, req, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unexplained handshake failure")); + next_address(req, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Unexplained handshake failure")); return; } req->ep = ep; - start_write(exec_ctx, req); + start_write(req); } -static void on_connected(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_connected(void* arg, grpc_error* error) { internal_request* req = (internal_request*)arg; if (!req->ep) { - next_address(exec_ctx, req, GRPC_ERROR_REF(error)); + next_address(req, GRPC_ERROR_REF(error)); return; } req->handshaker->handshake( - exec_ctx, req, req->ep, - req->ssl_host_override ? req->ssl_host_override : req->host, + req, req->ep, req->ssl_host_override ? req->ssl_host_override : req->host, req->deadline, on_handshake_done); } -static void next_address(grpc_exec_ctx* exec_ctx, internal_request* req, - grpc_error* error) { +static void next_address(internal_request* req, grpc_error* error) { grpc_resolved_address* addr; if (error != GRPC_ERROR_NONE) { append_error(req, error); } if (req->next_address == req->addresses->naddrs) { - finish(exec_ctx, req, + finish(req, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed HTTP requests to all targets", &req->overall_error, 1)); return; @@ -221,23 +208,21 @@ static void next_address(grpc_exec_ctx* exec_ctx, internal_request* req, (char*)GRPC_ARG_RESOURCE_QUOTA, req->resource_quota, grpc_resource_quota_arg_vtable()); grpc_channel_args args = {1, &arg}; - grpc_tcp_client_connect(exec_ctx, &req->connected, &req->ep, - req->context->pollset_set, &args, addr, - req->deadline); + grpc_tcp_client_connect(&req->connected, &req->ep, req->context->pollset_set, + &args, addr, req->deadline); } -static void on_resolved(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_resolved(void* arg, grpc_error* error) { internal_request* req = (internal_request*)arg; if (error != GRPC_ERROR_NONE) { - finish(exec_ctx, req, GRPC_ERROR_REF(error)); + finish(req, GRPC_ERROR_REF(error)); return; } req->next_address = 0; - next_address(exec_ctx, req, GRPC_ERROR_NONE); + next_address(req, GRPC_ERROR_NONE); } -static void internal_request_begin(grpc_exec_ctx* exec_ctx, - grpc_httpcli_context* context, +static void internal_request_begin(grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -267,33 +252,31 @@ static void internal_request_begin(grpc_exec_ctx* exec_ctx, req->ssl_host_override = gpr_strdup(request->ssl_host_override); GPR_ASSERT(pollent); - grpc_polling_entity_add_to_pollset_set(exec_ctx, req->pollent, + grpc_polling_entity_add_to_pollset_set(req->pollent, req->context->pollset_set); grpc_resolve_address( - exec_ctx, request->host, req->handshaker->default_port, - req->context->pollset_set, + request->host, req->handshaker->default_port, req->context->pollset_set, GRPC_CLOSURE_CREATE(on_resolved, req, grpc_schedule_on_exec_ctx), &req->addresses); } -void grpc_httpcli_get(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, +void grpc_httpcli_get(grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { char* name; - if (g_get_override && - g_get_override(exec_ctx, request, deadline, on_done, response)) { + if (g_get_override && g_get_override(request, deadline, on_done, response)) { return; } gpr_asprintf(&name, "HTTP:GET:%s:%s", request->host, request->http.path); - internal_request_begin(exec_ctx, context, pollent, resource_quota, request, - deadline, on_done, response, name, + internal_request_begin(context, pollent, resource_quota, request, deadline, + on_done, response, name, grpc_httpcli_format_get_request(request)); gpr_free(name); } -void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, +void grpc_httpcli_post(grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -301,16 +284,14 @@ void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { char* name; - if (g_post_override && - g_post_override(exec_ctx, request, body_bytes, body_size, deadline, - on_done, response)) { + if (g_post_override && g_post_override(request, body_bytes, body_size, + deadline, on_done, response)) { return; } gpr_asprintf(&name, "HTTP:POST:%s:%s", request->host, request->http.path); internal_request_begin( - exec_ctx, context, pollent, resource_quota, request, deadline, on_done, - response, name, - grpc_httpcli_format_post_request(request, body_bytes, body_size)); + context, pollent, resource_quota, request, deadline, on_done, response, + name, grpc_httpcli_format_post_request(request, body_bytes, body_size)); gpr_free(name); } diff --git a/src/core/lib/http/httpcli.h b/src/core/lib/http/httpcli.h index 6f675568bd..72d20cc7a3 100644 --- a/src/core/lib/http/httpcli.h +++ b/src/core/lib/http/httpcli.h @@ -41,10 +41,9 @@ typedef struct grpc_httpcli_context { typedef struct { const char* default_port; - void (*handshake)(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint, - const char* host, grpc_millis deadline, - void (*on_done)(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint)); + void (*handshake)(void* arg, grpc_endpoint* endpoint, const char* host, + grpc_millis deadline, + void (*on_done)(void* arg, grpc_endpoint* endpoint)); } grpc_httpcli_handshaker; extern const grpc_httpcli_handshaker grpc_httpcli_plaintext; @@ -68,8 +67,7 @@ typedef struct grpc_httpcli_request { typedef struct grpc_http_response grpc_httpcli_response; void grpc_httpcli_context_init(grpc_httpcli_context* context); -void grpc_httpcli_context_destroy(grpc_exec_ctx* exec_ctx, - grpc_httpcli_context* context); +void grpc_httpcli_context_destroy(grpc_httpcli_context* context); /* Asynchronously perform a HTTP GET. 'context' specifies the http context under which to do the get @@ -80,7 +78,7 @@ void grpc_httpcli_context_destroy(grpc_exec_ctx* exec_ctx, destroyed once the call returns 'deadline' contains a deadline for the request (or gpr_inf_future) 'on_response' is a callback to report results to */ -void grpc_httpcli_get(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, +void grpc_httpcli_get(grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, grpc_millis deadline, @@ -101,7 +99,7 @@ void grpc_httpcli_get(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, lifetime of the request 'on_response' is a callback to report results to Does not support ?var1=val1&var2=val2 in the path. */ -void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, +void grpc_httpcli_post(grpc_httpcli_context* context, grpc_polling_entity* pollent, grpc_resource_quota* resource_quota, const grpc_httpcli_request* request, @@ -110,15 +108,16 @@ void grpc_httpcli_post(grpc_exec_ctx* exec_ctx, grpc_httpcli_context* context, grpc_httpcli_response* response); /* override functions return 1 if they handled the request, 0 otherwise */ -typedef int (*grpc_httpcli_get_override)(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_complete, grpc_httpcli_response* response); -typedef int (*grpc_httpcli_post_override)( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body_bytes, size_t body_size, grpc_millis deadline, - grpc_closure* on_complete, grpc_httpcli_response* response); +typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request* request, + const char* body_bytes, + size_t body_size, + grpc_millis deadline, + grpc_closure* on_complete, + grpc_httpcli_response* response); void grpc_httpcli_set_override(grpc_httpcli_get_override get, grpc_httpcli_post_override post); diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index dfcaee702b..bfb536a921 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -38,8 +38,7 @@ typedef struct { char* secure_peer_name; } grpc_httpcli_ssl_channel_security_connector; -static void httpcli_ssl_destroy(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { +static void httpcli_ssl_destroy(grpc_security_connector* sc) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; if (c->handshaker_factory != nullptr) { @@ -50,8 +49,7 @@ static void httpcli_ssl_destroy(grpc_exec_ctx* exec_ctx, gpr_free(sc); } -static void httpcli_ssl_add_handshakers(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, +static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; @@ -65,13 +63,11 @@ static void httpcli_ssl_add_handshakers(grpc_exec_ctx* exec_ctx, } } grpc_handshake_manager_add( - handshake_mgr, - grpc_security_handshaker_create( - exec_ctx, tsi_create_adapter_handshaker(handshaker), &sc->base)); + handshake_mgr, grpc_security_handshaker_create( + tsi_create_adapter_handshaker(handshaker), &sc->base)); } -static void httpcli_ssl_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_httpcli_ssl_channel_security_connector* c = @@ -87,7 +83,7 @@ static void httpcli_ssl_check_peer(grpc_exec_ctx* exec_ctx, error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); } - GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); + GRPC_CLOSURE_SCHED(on_peer_checked, error); tsi_peer_destruct(&peer); } @@ -104,8 +100,8 @@ static grpc_security_connector_vtable httpcli_ssl_vtable = { httpcli_ssl_destroy, httpcli_ssl_check_peer, httpcli_ssl_cmp}; static grpc_security_status httpcli_ssl_channel_security_connector_create( - grpc_exec_ctx* exec_ctx, const char* pem_root_certs, - const char* secure_peer_name, grpc_channel_security_connector** sc) { + const char* pem_root_certs, const char* secure_peer_name, + grpc_channel_security_connector** sc) { tsi_result result = TSI_OK; grpc_httpcli_ssl_channel_security_connector* c; @@ -128,12 +124,12 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); - httpcli_ssl_destroy(exec_ctx, &c->base.base); + httpcli_ssl_destroy(&c->base.base); *sc = nullptr; return GRPC_SECURITY_ERROR; } // We don't actually need a channel credentials object in this case, - // but we set it to a non-NULL address so that we don't trigger + // but we set it to a non-nullptr address so that we don't trigger // assertions in grpc_channel_security_connector_cmp(). c->base.channel_creds = (grpc_channel_credentials*)1; c->base.add_handshakers = httpcli_ssl_add_handshakers; @@ -144,40 +140,37 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( /* handshaker */ typedef struct { - void (*func)(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint); + void (*func)(void* arg, grpc_endpoint* endpoint); void* arg; grpc_handshake_manager* handshake_mgr; } on_done_closure; -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshaker_args* args = (grpc_handshaker_args*)arg; on_done_closure* c = (on_done_closure*)args->user_data; if (error != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - c->func(exec_ctx, c->arg, nullptr); + c->func(c->arg, nullptr); } else { - grpc_channel_args_destroy(exec_ctx, args->args); - grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); + grpc_channel_args_destroy(args->args); + grpc_slice_buffer_destroy_internal(args->read_buffer); gpr_free(args->read_buffer); - c->func(exec_ctx, c->arg, args->endpoint); + c->func(c->arg, args->endpoint); } - grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); + grpc_handshake_manager_destroy(c->handshake_mgr); gpr_free(c); } -static void ssl_handshake(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* tcp, const char* host, +static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host, grpc_millis deadline, - void (*on_done)(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint)) { + void (*on_done)(void* arg, grpc_endpoint* endpoint)) { on_done_closure* c = (on_done_closure*)gpr_malloc(sizeof(*c)); const char* pem_root_certs = grpc_get_default_ssl_roots(); if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); - on_done(exec_ctx, arg, nullptr); + on_done(arg, nullptr); gpr_free(c); return; } @@ -185,16 +178,16 @@ static void ssl_handshake(grpc_exec_ctx* exec_ctx, void* arg, c->arg = arg; grpc_channel_security_connector* sc = nullptr; GPR_ASSERT(httpcli_ssl_channel_security_connector_create( - exec_ctx, pem_root_certs, host, &sc) == GRPC_SECURITY_OK); + pem_root_certs, host, &sc) == GRPC_SECURITY_OK); grpc_arg channel_arg = grpc_security_connector_to_arg(&sc->base); grpc_channel_args args = {1, &channel_arg}; c->handshake_mgr = grpc_handshake_manager_create(); - grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, &args, c->handshake_mgr); + grpc_handshakers_add(HANDSHAKER_CLIENT, &args, c->handshake_mgr); grpc_handshake_manager_do_handshake( - exec_ctx, c->handshake_mgr, nullptr /* interested_parties */, tcp, + c->handshake_mgr, nullptr /* interested_parties */, tcp, nullptr /* channel_args */, deadline, nullptr /* acceptor */, on_handshake_done, c /* user_data */); - GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "httpcli"); + GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli"); } const grpc_httpcli_handshaker grpc_httpcli_ssl = {"https", ssl_handshake}; diff --git a/src/core/lib/iomgr/block_annotate.h b/src/core/lib/iomgr/block_annotate.h index 340ebcb1af..a57873aabb 100644 --- a/src/core/lib/iomgr/block_annotate.h +++ b/src/core/lib/iomgr/block_annotate.h @@ -31,26 +31,27 @@ void gpr_thd_end_blocking_region(); do { \ gpr_thd_start_blocking_region(); \ } while (0) +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + gpr_thd_end_blocking_region(); \ + grpc_core::ExecCtx::Get()->InvalidateNow(); \ + } while (0) #define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ do { \ gpr_thd_end_blocking_region(); \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(ec) \ - do { \ - gpr_thd_end_blocking_region(); \ - grpc_exec_ctx_invalidate_now((ec)); \ - } while (0) + #else #define GRPC_SCHEDULING_START_BLOCKING_REGION \ do { \ } while (0) +#define GRPC_SCHEDULING_END_BLOCKING_REGION \ + do { \ + grpc_core::ExecCtx::Get()->InvalidateNow(); \ + } while (0) #define GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX \ do { \ } while (0) -#define GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(ec) \ - do { \ - grpc_exec_ctx_invalidate_now((ec)); \ - } while (0) #endif #endif /* GRPC_CORE_LIB_IOMGR_BLOCK_ANNOTATE_H */ diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index b5910b42e4..a9f48fb3c2 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -56,8 +56,7 @@ void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner) { #define DEBUG_FMT_ARGS #endif -void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error DEBUG_ARGS, const char* reason) { @@ -75,15 +74,16 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, prev_size + 1); } - GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx); + GRPC_STATS_INC_CALL_COMBINER_LOCKS_SCHEDULED_ITEMS(); if (prev_size == 0) { - GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx); + GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(); + GPR_TIMER_MARK("call_combiner_initiate", 0); if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " EXECUTING IMMEDIATELY"); } // Queue was empty, so execute this closure immediately. - GRPC_CLOSURE_SCHED(exec_ctx, closure, error); + GRPC_CLOSURE_SCHED(closure, error); } else { if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_INFO, " QUEUING"); @@ -95,8 +95,7 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, GPR_TIMER_END("call_combiner_start", 0); } -void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner DEBUG_ARGS, +void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS, const char* reason) { GPR_TIMER_BEGIN("call_combiner_stop", 0); if (grpc_call_combiner_trace.enabled()) { @@ -131,7 +130,7 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, " EXECUTING FROM QUEUE: closure=%p error=%s", closure, grpc_error_string(closure->error_data.error)); } - GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error); + GRPC_CLOSURE_SCHED(closure, closure->error_data.error); break; } } else if (grpc_call_combiner_trace.enabled()) { @@ -140,10 +139,9 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, GPR_TIMER_END("call_combiner_stop", 0); } -void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, grpc_closure* closure) { - GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(exec_ctx); + GRPC_STATS_INC_CALL_COMBINER_SET_NOTIFY_ON_CANCEL(); while (true) { // Decode original state. gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state); @@ -157,7 +155,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, "for pre-existing cancellation", call_combiner, closure); } - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_REF(original_error)); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_REF(original_error)); break; } else { if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state, @@ -176,7 +174,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, "call_combiner=%p: scheduling old cancel callback=%p", call_combiner, closure); } - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } break; } @@ -185,10 +183,9 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, } } -void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner, grpc_error* error) { - GRPC_STATS_INC_CALL_COMBINER_CANCELLED(exec_ctx); + GRPC_STATS_INC_CALL_COMBINER_CANCELLED(); while (true) { gpr_atm original_state = gpr_atm_acq_load(&call_combiner->cancel_state); grpc_error* original_error = decode_cancel_state_error(original_state); @@ -205,7 +202,7 @@ void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, "call_combiner=%p: scheduling notify_on_cancel callback=%p", call_combiner, notify_on_cancel); } - GRPC_CLOSURE_SCHED(exec_ctx, notify_on_cancel, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(notify_on_cancel, GRPC_ERROR_REF(error)); } break; } diff --git a/src/core/lib/iomgr/call_combiner.h b/src/core/lib/iomgr/call_combiner.h index c07af51c91..9f7e6ce1c9 100644 --- a/src/core/lib/iomgr/call_combiner.h +++ b/src/core/lib/iomgr/call_combiner.h @@ -53,37 +53,29 @@ void grpc_call_combiner_init(grpc_call_combiner* call_combiner); void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner); #ifndef NDEBUG -#define GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, closure, error, \ - reason) \ - grpc_call_combiner_start((exec_ctx), (call_combiner), (closure), (error), \ - __FILE__, __LINE__, (reason)) -#define GRPC_CALL_COMBINER_STOP(exec_ctx, call_combiner, reason) \ - grpc_call_combiner_stop((exec_ctx), (call_combiner), __FILE__, __LINE__, \ - (reason)) +#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \ + grpc_call_combiner_start((call_combiner), (closure), (error), __FILE__, \ + __LINE__, (reason)) +#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \ + grpc_call_combiner_stop((call_combiner), __FILE__, __LINE__, (reason)) /// Starts processing \a closure on \a call_combiner. -void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error, const char* file, int line, const char* reason); /// Yields the call combiner to the next closure in the queue, if any. -void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_stop(grpc_call_combiner* call_combiner, const char* file, int line, const char* reason); #else -#define GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, closure, error, \ - reason) \ - grpc_call_combiner_start((exec_ctx), (call_combiner), (closure), (error), \ - (reason)) -#define GRPC_CALL_COMBINER_STOP(exec_ctx, call_combiner, reason) \ - grpc_call_combiner_stop((exec_ctx), (call_combiner), (reason)) +#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \ + grpc_call_combiner_start((call_combiner), (closure), (error), (reason)) +#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \ + grpc_call_combiner_stop((call_combiner), (reason)) /// Starts processing \a closure on \a call_combiner. -void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_start(grpc_call_combiner* call_combiner, grpc_closure* closure, grpc_error* error, const char* reason); /// Yields the call combiner to the next closure in the queue, if any. -void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_stop(grpc_call_combiner* call_combiner, const char* reason); #endif @@ -109,13 +101,11 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, /// cancellation; this effectively unregisters the previously set closure. /// However, most filters will not need to explicitly unregister their /// callbacks, as this is done automatically when the call is destroyed. -void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner, grpc_closure* closure); /// Indicates that the call has been cancelled. -void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, - grpc_call_combiner* call_combiner, +void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner, grpc_error* error); #endif /* GRPC_CORE_LIB_IOMGR_CALL_COMBINER_H */ diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 46793dd2c5..88af76006a 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -47,18 +47,15 @@ typedef struct grpc_closure_list { * describing what went wrong. * Error contract: it is not the cb's job to unref this error; * the closure scheduler will do that after the cb returns */ -typedef void (*grpc_iomgr_cb_func)(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +typedef void (*grpc_iomgr_cb_func)(void* arg, grpc_error* error); typedef struct grpc_closure_scheduler grpc_closure_scheduler; typedef struct grpc_closure_scheduler_vtable { /* NOTE: for all these functions, closure->scheduler == the scheduler that was used to find this vtable */ - void (*run)(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error); - void (*sched)(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error); + void (*run)(grpc_closure* closure, grpc_error* error); + void (*sched)(grpc_closure* closure, grpc_error* error); const char* name; } grpc_closure_scheduler_vtable; @@ -146,13 +143,12 @@ typedef struct { grpc_closure wrapper; } wrapped_closure; -inline void closure_wrapper(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +inline void closure_wrapper(void* arg, grpc_error* error) { wrapped_closure* wc = (wrapped_closure*)arg; grpc_iomgr_cb_func cb = wc->cb; void* cb_arg = wc->cb_arg; gpr_free(wc); - cb(exec_ctx, cb_arg, error); + cb(cb_arg, error); } } // namespace closure_impl @@ -247,12 +243,10 @@ inline bool grpc_closure_list_empty(grpc_closure_list closure_list) { } #ifndef NDEBUG -inline void grpc_closure_run(const char* file, int line, - grpc_exec_ctx* exec_ctx, grpc_closure* c, +inline void grpc_closure_run(const char* file, int line, grpc_closure* c, grpc_error* error) { #else -inline void grpc_closure_run(grpc_exec_ctx* exec_ctx, grpc_closure* c, - grpc_error* error) { +inline void grpc_closure_run(grpc_closure* c, grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_run", 0); if (c != nullptr) { @@ -262,7 +256,7 @@ inline void grpc_closure_run(grpc_exec_ctx* exec_ctx, grpc_closure* c, c->run = true; #endif assert(c->cb); - c->scheduler->vtable->run(exec_ctx, c, error); + c->scheduler->vtable->run(c, error); } else { GRPC_ERROR_UNREF(error); } @@ -273,20 +267,17 @@ inline void grpc_closure_run(grpc_exec_ctx* exec_ctx, grpc_closure* c, * Note that calling this at the end of a closure callback function itself is * by definition safe. */ #ifndef NDEBUG -#define GRPC_CLOSURE_RUN(exec_ctx, closure, error) \ - grpc_closure_run(__FILE__, __LINE__, exec_ctx, closure, error) +#define GRPC_CLOSURE_RUN(closure, error) \ + grpc_closure_run(__FILE__, __LINE__, closure, error) #else -#define GRPC_CLOSURE_RUN(exec_ctx, closure, error) \ - grpc_closure_run(exec_ctx, closure, error) +#define GRPC_CLOSURE_RUN(closure, error) grpc_closure_run(closure, error) #endif #ifndef NDEBUG -inline void grpc_closure_sched(const char* file, int line, - grpc_exec_ctx* exec_ctx, grpc_closure* c, +inline void grpc_closure_sched(const char* file, int line, grpc_closure* c, grpc_error* error) { #else -inline void grpc_closure_sched(grpc_exec_ctx* exec_ctx, grpc_closure* c, - grpc_error* error) { +inline void grpc_closure_sched(grpc_closure* c, grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_sched", 0); if (c != nullptr) { @@ -305,7 +296,7 @@ inline void grpc_closure_sched(grpc_exec_ctx* exec_ctx, grpc_closure* c, c->run = false; #endif assert(c->cb); - c->scheduler->vtable->sched(exec_ctx, c, error); + c->scheduler->vtable->sched(c, error); } else { GRPC_ERROR_UNREF(error); } @@ -314,20 +305,17 @@ inline void grpc_closure_sched(grpc_exec_ctx* exec_ctx, grpc_closure* c, /** Schedule a closure to be run. Does not need to be run from a safe point. */ #ifndef NDEBUG -#define GRPC_CLOSURE_SCHED(exec_ctx, closure, error) \ - grpc_closure_sched(__FILE__, __LINE__, exec_ctx, closure, error) +#define GRPC_CLOSURE_SCHED(closure, error) \ + grpc_closure_sched(__FILE__, __LINE__, closure, error) #else -#define GRPC_CLOSURE_SCHED(exec_ctx, closure, error) \ - grpc_closure_sched(exec_ctx, closure, error) +#define GRPC_CLOSURE_SCHED(closure, error) grpc_closure_sched(closure, error) #endif #ifndef NDEBUG inline void grpc_closure_list_sched(const char* file, int line, - grpc_exec_ctx* exec_ctx, grpc_closure_list* list) { #else -inline void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, - grpc_closure_list* list) { +inline void grpc_closure_list_sched(grpc_closure_list* list) { #endif grpc_closure* c = list->head; while (c != nullptr) { @@ -347,7 +335,7 @@ inline void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, c->run = false; #endif assert(c->cb); - c->scheduler->vtable->sched(exec_ctx, c, c->error_data.error); + c->scheduler->vtable->sched(c, c->error_data.error); c = next; } list->head = list->tail = nullptr; @@ -356,11 +344,11 @@ inline void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, /** Schedule all closures in a list to be run. Does not need to be run from a * safe point. */ #ifndef NDEBUG -#define GRPC_CLOSURE_LIST_SCHED(exec_ctx, closure_list) \ - grpc_closure_list_sched(__FILE__, __LINE__, exec_ctx, closure_list) +#define GRPC_CLOSURE_LIST_SCHED(closure_list) \ + grpc_closure_list_sched(__FILE__, __LINE__, closure_list) #else -#define GRPC_CLOSURE_LIST_SCHED(exec_ctx, closure_list) \ - grpc_closure_list_sched(exec_ctx, closure_list) +#define GRPC_CLOSURE_LIST_SCHED(closure_list) \ + grpc_closure_list_sched(closure_list) #endif #endif /* GRPC_CORE_LIB_IOMGR_CLOSURE_H */ diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 15c009dd77..e4d7a6abd8 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -61,17 +61,15 @@ struct grpc_combiner { gpr_refcount refs; }; -static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error); -static void combiner_finally_exec(grpc_exec_ctx* exec_ctx, - grpc_closure* closure, grpc_error* error); +static void combiner_exec(grpc_closure* closure, grpc_error* error); +static void combiner_finally_exec(grpc_closure* closure, grpc_error* error); static const grpc_closure_scheduler_vtable scheduler = { combiner_exec, combiner_exec, "combiner:immediately"}; static const grpc_closure_scheduler_vtable finally_scheduler = { combiner_finally_exec, combiner_finally_exec, "combiner:finally"}; -static void offload(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); +static void offload(void* arg, grpc_error* error); grpc_combiner* grpc_combiner_create(void) { grpc_combiner* lock = (grpc_combiner*)gpr_zalloc(sizeof(*lock)); @@ -87,19 +85,19 @@ grpc_combiner* grpc_combiner_create(void) { return lock; } -static void really_destroy(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { +static void really_destroy(grpc_combiner* lock) { GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p really_destroy", lock)); GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0); gpr_mpscq_destroy(&lock->queue); gpr_free(lock); } -static void start_destroy(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { +static void start_destroy(grpc_combiner* lock) { gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_UNORPHANED); GRPC_COMBINER_TRACE(gpr_log( GPR_DEBUG, "C:%p really_destroy old_state=%" PRIdPTR, lock, old_state)); if (old_state == 1) { - really_destroy(exec_ctx, lock); + really_destroy(lock); } } @@ -115,11 +113,10 @@ static void start_destroy(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { #define GRPC_COMBINER_DEBUG_SPAM(op, delta) #endif -void grpc_combiner_unref(grpc_exec_ctx* exec_ctx, - grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { +void grpc_combiner_unref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { GRPC_COMBINER_DEBUG_SPAM("UNREF", -1); if (gpr_unref(&lock->refs)) { - start_destroy(exec_ctx, lock); + start_destroy(lock); } } @@ -129,23 +126,25 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { return lock; } -static void push_last_on_exec_ctx(grpc_exec_ctx* exec_ctx, - grpc_combiner* lock) { +static void push_last_on_exec_ctx(grpc_combiner* lock) { lock->next_combiner_on_this_exec_ctx = nullptr; - if (exec_ctx->active_combiner == nullptr) { - exec_ctx->active_combiner = exec_ctx->last_combiner = lock; + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } else { - exec_ctx->last_combiner->next_combiner_on_this_exec_ctx = lock; - exec_ctx->last_combiner = lock; + grpc_core::ExecCtx::Get() + ->combiner_data() + ->last_combiner->next_combiner_on_this_exec_ctx = lock; + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } } -static void push_first_on_exec_ctx(grpc_exec_ctx* exec_ctx, - grpc_combiner* lock) { - lock->next_combiner_on_this_exec_ctx = exec_ctx->active_combiner; - exec_ctx->active_combiner = lock; +static void push_first_on_exec_ctx(grpc_combiner* lock) { + lock->next_combiner_on_this_exec_ctx = + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = lock; if (lock->next_combiner_on_this_exec_ctx == nullptr) { - exec_ctx->last_combiner = lock; + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock; } } @@ -153,9 +152,8 @@ static void push_first_on_exec_ctx(grpc_exec_ctx* exec_ctx, ((grpc_combiner*)(((char*)((closure)->scheduler)) - \ offsetof(grpc_combiner, scheduler_name))) -static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl, - grpc_error* error) { - GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx); +static void combiner_exec(grpc_closure* cl, grpc_error* error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(); GPR_TIMER_BEGIN("combiner.execute", 0); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(cl, scheduler); gpr_atm last = gpr_atm_full_fetch_add(&lock->state, STATE_ELEM_COUNT_LOW_BIT); @@ -163,19 +161,19 @@ static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl, "C:%p grpc_combiner_execute c=%p last=%" PRIdPTR, lock, cl, last)); if (last == 1) { - GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx); + GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(); GPR_TIMER_MARK("combiner.initiated", 0); gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, - (gpr_atm)exec_ctx); + (gpr_atm)grpc_core::ExecCtx::Get()); // first element on this list: add it to the list of combiner locks // executing within this exec_ctx - push_last_on_exec_ctx(exec_ctx, lock); + push_last_on_exec_ctx(lock); } else { // there may be a race with setting here: if that happens, we may delay // offload for one or two actions, and that's fine gpr_atm initiator = gpr_atm_no_barrier_load(&lock->initiating_exec_ctx_or_null); - if (initiator != 0 && initiator != (gpr_atm)exec_ctx) { + if (initiator != 0 && initiator != (gpr_atm)grpc_core::ExecCtx::Get()) { gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, 0); } } @@ -186,29 +184,32 @@ static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl, GPR_TIMER_END("combiner.execute", 0); } -static void move_next(grpc_exec_ctx* exec_ctx) { - exec_ctx->active_combiner = - exec_ctx->active_combiner->next_combiner_on_this_exec_ctx; - if (exec_ctx->active_combiner == nullptr) { - exec_ctx->last_combiner = nullptr; +static void move_next() { + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = + grpc_core::ExecCtx::Get() + ->combiner_data() + ->active_combiner->next_combiner_on_this_exec_ctx; + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) { + grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = nullptr; } } -static void offload(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void offload(void* arg, grpc_error* error) { grpc_combiner* lock = (grpc_combiner*)arg; - push_last_on_exec_ctx(exec_ctx, lock); + push_last_on_exec_ctx(lock); } -static void queue_offload(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { - GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx); - move_next(exec_ctx); +static void queue_offload(grpc_combiner* lock) { + GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(); + move_next(); GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p queue_offload", lock)); - GRPC_CLOSURE_SCHED(exec_ctx, &lock->offload, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&lock->offload, GRPC_ERROR_NONE); } -bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { +bool grpc_combiner_continue_exec_ctx() { GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0); - grpc_combiner* lock = exec_ctx->active_combiner; + grpc_combiner* lock = + grpc_core::ExecCtx::Get()->combiner_data()->active_combiner; if (lock == nullptr) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); return false; @@ -223,15 +224,15 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { "exec_ctx_ready_to_finish=%d " "time_to_execute_final_list=%d", lock, contended, - grpc_exec_ctx_ready_to_finish(exec_ctx), + grpc_core::ExecCtx::Get()->IsReadyToFinish(), lock->time_to_execute_final_list)); - if (contended && grpc_exec_ctx_ready_to_finish(exec_ctx) && + if (contended && grpc_core::ExecCtx::Get()->IsReadyToFinish() && grpc_executor_is_threaded()) { GPR_TIMER_MARK("offload_from_finished_exec_ctx", 0); // this execution context wants to move on: schedule remaining work to be // picked up on the executor - queue_offload(exec_ctx, lock); + queue_offload(lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } @@ -247,7 +248,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { // queue is in an inconsistent state: use this as a cue that we should // go off and do something else for a while (and come back later) GPR_TIMER_MARK("delay_busy", 0); - queue_offload(exec_ctx, lock); + queue_offload(lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } @@ -257,7 +258,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { #ifndef NDEBUG cl->scheduled = false; #endif - cl->cb(exec_ctx, cl->cb_arg, cl_err); + cl->cb(cl->cb_arg, cl_err); GRPC_ERROR_UNREF(cl_err); GPR_TIMER_END("combiner.exec1", 0); } else { @@ -274,7 +275,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { #ifndef NDEBUG c->scheduled = false; #endif - c->cb(exec_ctx, c->cb_arg, error); + c->cb(c->cb_arg, error); GRPC_ERROR_UNREF(error); c = next; GPR_TIMER_END("combiner.exec_1final", 0); @@ -282,7 +283,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { } GPR_TIMER_MARK("unref", 0); - move_next(exec_ctx); + move_next(); lock->time_to_execute_final_list = false; gpr_atm old_state = gpr_atm_full_fetch_add(&lock->state, -STATE_ELEM_COUNT_LOW_BIT); @@ -311,7 +312,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { return true; case OLD_STATE_WAS(true, 1): // and one count, one orphaned --> unlocked and orphaned - really_destroy(exec_ctx, lock); + really_destroy(lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; case OLD_STATE_WAS(false, 0): @@ -321,27 +322,24 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); GPR_UNREACHABLE_CODE(return true); } - push_first_on_exec_ctx(exec_ctx, lock); + push_first_on_exec_ctx(lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; } -static void enqueue_finally(grpc_exec_ctx* exec_ctx, void* closure, - grpc_error* error); +static void enqueue_finally(void* closure, grpc_error* error); -static void combiner_finally_exec(grpc_exec_ctx* exec_ctx, - grpc_closure* closure, grpc_error* error) { - GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx); +static void combiner_finally_exec(grpc_closure* closure, grpc_error* error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(); grpc_combiner* lock = COMBINER_FROM_CLOSURE_SCHEDULER(closure, finally_scheduler); - GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, - "C:%p grpc_combiner_execute_finally c=%p; ac=%p", - lock, closure, exec_ctx->active_combiner)); + GRPC_COMBINER_TRACE(gpr_log( + GPR_DEBUG, "C:%p grpc_combiner_execute_finally c=%p; ac=%p", lock, + closure, grpc_core::ExecCtx::Get()->combiner_data()->active_combiner)); GPR_TIMER_BEGIN("combiner.execute_finally", 0); - if (exec_ctx->active_combiner != lock) { + if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner != lock) { GPR_TIMER_MARK("slowpath", 0); - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_CREATE(enqueue_finally, closure, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(enqueue_finally, closure, grpc_combiner_scheduler(lock)), error); GPR_TIMER_END("combiner.execute_finally", 0); @@ -355,10 +353,8 @@ static void combiner_finally_exec(grpc_exec_ctx* exec_ctx, GPR_TIMER_END("combiner.execute_finally", 0); } -static void enqueue_finally(grpc_exec_ctx* exec_ctx, void* closure, - grpc_error* error) { - combiner_finally_exec(exec_ctx, (grpc_closure*)closure, - GRPC_ERROR_REF(error)); +static void enqueue_finally(void* closure, grpc_error* error) { + combiner_finally_exec((grpc_closure*)closure, GRPC_ERROR_REF(error)); } grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* combiner) { diff --git a/src/core/lib/iomgr/combiner.h b/src/core/lib/iomgr/combiner.h index 0c05511331..46b9ac58be 100644 --- a/src/core/lib/iomgr/combiner.h +++ b/src/core/lib/iomgr/combiner.h @@ -40,26 +40,24 @@ grpc_combiner* grpc_combiner_create(void); , const char *file, int line, const char *reason #define GRPC_COMBINER_REF(combiner, reason) \ grpc_combiner_ref((combiner), __FILE__, __LINE__, (reason)) -#define GRPC_COMBINER_UNREF(exec_ctx, combiner, reason) \ - grpc_combiner_unref((exec_ctx), (combiner), __FILE__, __LINE__, (reason)) +#define GRPC_COMBINER_UNREF(combiner, reason) \ + grpc_combiner_unref((combiner), __FILE__, __LINE__, (reason)) #else #define GRPC_COMBINER_DEBUG_ARGS #define GRPC_COMBINER_REF(combiner, reason) grpc_combiner_ref((combiner)) -#define GRPC_COMBINER_UNREF(exec_ctx, combiner, reason) \ - grpc_combiner_unref((exec_ctx), (combiner)) +#define GRPC_COMBINER_UNREF(combiner, reason) grpc_combiner_unref((combiner)) #endif // Ref/unref the lock, for when we're sharing the lock ownership // Prefer to use the macros above grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); -void grpc_combiner_unref(grpc_exec_ctx* exec_ctx, - grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); +void grpc_combiner_unref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS); // Fetch a scheduler to schedule closures against grpc_closure_scheduler* grpc_combiner_scheduler(grpc_combiner* lock); // Scheduler to execute \a action within the lock just prior to unlocking. grpc_closure_scheduler* grpc_combiner_finally_scheduler(grpc_combiner* lock); -bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx); +bool grpc_combiner_continue_exec_ctx(); extern grpc_core::TraceFlag grpc_combiner_trace; diff --git a/src/core/lib/iomgr/endpoint.cc b/src/core/lib/iomgr/endpoint.cc index 5eab1d3158..9d4b102822 100644 --- a/src/core/lib/iomgr/endpoint.cc +++ b/src/core/lib/iomgr/endpoint.cc @@ -18,41 +18,35 @@ #include "src/core/lib/iomgr/endpoint.h" -void grpc_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { - ep->vtable->read(exec_ctx, ep, slices, cb); +void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { + ep->vtable->read(ep, slices, cb); } -void grpc_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { - ep->vtable->write(exec_ctx, ep, slices, cb); +void grpc_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { + ep->vtable->write(ep, slices, cb); } -void grpc_endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) { - ep->vtable->add_to_pollset(exec_ctx, ep, pollset); +void grpc_endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { + ep->vtable->add_to_pollset(ep, pollset); } -void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +void grpc_endpoint_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - ep->vtable->add_to_pollset_set(exec_ctx, ep, pollset_set); + ep->vtable->add_to_pollset_set(ep, pollset_set); } -void grpc_endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +void grpc_endpoint_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - ep->vtable->delete_from_pollset_set(exec_ctx, ep, pollset_set); + ep->vtable->delete_from_pollset_set(ep, pollset_set); } -void grpc_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { - ep->vtable->shutdown(exec_ctx, ep, why); +void grpc_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { + ep->vtable->shutdown(ep, why); } -void grpc_endpoint_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { - ep->vtable->destroy(exec_ctx, ep); -} +void grpc_endpoint_destroy(grpc_endpoint* ep) { ep->vtable->destroy(ep); } char* grpc_endpoint_get_peer(grpc_endpoint* ep) { return ep->vtable->get_peer(ep); diff --git a/src/core/lib/iomgr/endpoint.h b/src/core/lib/iomgr/endpoint.h index 6ab0a6591c..cd53099334 100644 --- a/src/core/lib/iomgr/endpoint.h +++ b/src/core/lib/iomgr/endpoint.h @@ -33,18 +33,13 @@ typedef struct grpc_endpoint grpc_endpoint; typedef struct grpc_endpoint_vtable grpc_endpoint_vtable; struct grpc_endpoint_vtable { - void (*read)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb); - void (*write)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb); - void (*add_to_pollset)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset); - void (*add_to_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset_set* pollset); - void (*delete_from_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset_set* pollset); - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_error* why); - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep); + void (*read)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb); + void (*write)(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb); + void (*add_to_pollset)(grpc_endpoint* ep, grpc_pollset* pollset); + void (*add_to_pollset_set)(grpc_endpoint* ep, grpc_pollset_set* pollset); + void (*delete_from_pollset_set)(grpc_endpoint* ep, grpc_pollset_set* pollset); + void (*shutdown)(grpc_endpoint* ep, grpc_error* why); + void (*destroy)(grpc_endpoint* ep); grpc_resource_user* (*get_resource_user)(grpc_endpoint* ep); char* (*get_peer)(grpc_endpoint* ep); int (*get_fd)(grpc_endpoint* ep); @@ -55,8 +50,8 @@ struct grpc_endpoint_vtable { indicates the endpoint is closed. Valid slices may be placed into \a slices even when the callback is invoked with error != GRPC_ERROR_NONE. */ -void grpc_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb); +void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb); char* grpc_endpoint_get_peer(grpc_endpoint* ep); @@ -74,26 +69,22 @@ int grpc_endpoint_get_fd(grpc_endpoint* ep); No guarantee is made to the content of slices after a write EXCEPT that it is a valid slice buffer. */ -void grpc_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb); +void grpc_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb); /* Causes any pending and future read/write callbacks to run immediately with success==0 */ -void grpc_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why); -void grpc_endpoint_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep); +void grpc_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why); +void grpc_endpoint_destroy(grpc_endpoint* ep); /* Add an endpoint to a pollset or pollset_set, so that when the pollset is polled, events from this endpoint are considered */ -void grpc_endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset); -void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +void grpc_endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset); +void grpc_endpoint_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set); /* Delete an endpoint from a pollset_set */ -void grpc_endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +void grpc_endpoint_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set); grpc_resource_user* grpc_endpoint_get_resource_user(grpc_endpoint* endpoint); diff --git a/src/core/lib/iomgr/endpoint_pair_posix.cc b/src/core/lib/iomgr/endpoint_pair_posix.cc index f5f59f9917..0b4aefd1b7 100644 --- a/src/core/lib/iomgr/endpoint_pair_posix.cc +++ b/src/core/lib/iomgr/endpoint_pair_posix.cc @@ -54,18 +54,17 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name, char* final_name; create_sockets(sv); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_asprintf(&final_name, "%s:client", name); - p.client = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], final_name), args, + p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name), args, "socketpair-server"); gpr_free(final_name); gpr_asprintf(&final_name, "%s:server", name); - p.server = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[0], final_name), args, + p.server = grpc_tcp_create(grpc_fd_create(sv[0], final_name), args, "socketpair-client"); gpr_free(final_name); - grpc_exec_ctx_finish(&exec_ctx); return p; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index afa995a1c7..cc07ac0708 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -72,14 +72,12 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( SOCKET sv[2]; grpc_endpoint_pair p; create_sockets(sv); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - p.client = grpc_tcp_create(&exec_ctx, - grpc_winsocket_create(sv[1], "endpoint:client"), + grpc_core::ExecCtx exec_ctx; + p.client = grpc_tcp_create(grpc_winsocket_create(sv[1], "endpoint:client"), channel_args, "endpoint:server"); - p.server = grpc_tcp_create(&exec_ctx, - grpc_winsocket_create(sv[0], "endpoint:server"), + p.server = grpc_tcp_create(grpc_winsocket_create(sv[0], "endpoint:server"), channel_args, "endpoint:client"); - grpc_exec_ctx_finish(&exec_ctx); + return p; } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index e6d640c106..42cd7c455d 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -156,11 +156,7 @@ static void unref_errs(grpc_error* err) { } } -static void unref_slice(grpc_slice slice) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_unref_internal(&exec_ctx, slice); - grpc_exec_ctx_finish(&exec_ctx); -} +static void unref_slice(grpc_slice slice) { grpc_slice_unref_internal(slice); } static void unref_strs(grpc_error* err) { for (size_t which = 0; which < GRPC_ERROR_STR_MAX; ++which) { diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 0dda1d924c..d9e8a30f5e 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -299,31 +299,29 @@ static int fd_wrapped_fd(grpc_fd* fd) { return fd->fd; } /* if 'releasing_fd' is true, it means that we are going to detach the internal * fd from grpc_fd structure (i.e which means we should not be calling * shutdown() syscall on that fd) */ -static void fd_shutdown_internal(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_error* why, bool releasing_fd) { - if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { +static void fd_shutdown_internal(grpc_fd* fd, grpc_error* why, + bool releasing_fd) { + if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { if (!releasing_fd) { shutdown(fd->fd, SHUT_RDWR); } - fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } /* Might be called multiple times */ -static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { - fd_shutdown_internal(exec_ctx, fd, why, false); +static void fd_shutdown(grpc_fd* fd, grpc_error* why) { + fd_shutdown_internal(fd, why, false); } -static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; bool is_release_fd = (release_fd != nullptr); if (!fd->read_closure->IsShutdown()) { - fd_shutdown_internal(exec_ctx, fd, - GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason), + fd_shutdown_internal(fd, GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason), is_release_fd); } @@ -335,7 +333,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, close(fd->fd); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_REF(error)); grpc_iomgr_unregister_object(&fd->iomgr_object); fd->read_closure->DestroyEvent(); @@ -347,8 +345,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, gpr_mu_unlock(&fd_freelist_mu); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, - grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -357,26 +354,21 @@ static bool fd_is_shutdown(grpc_fd* fd) { return fd->read_closure->IsShutdown(); } -static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->read_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { + fd->read_closure->NotifyOn(closure); } -static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->write_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { + fd->write_closure->NotifyOn(closure); } -static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_pollset* notifier) { - fd->read_closure->SetReady(exec_ctx); +static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { + fd->read_closure->SetReady(); /* Use release store to match with acquire load in fd_get_read_notifier */ gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { - fd->write_closure->SetReady(exec_ctx); -} +static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } /******************************************************************************* * Pollset Definitions @@ -479,7 +471,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->next = pollset->prev = nullptr; } -static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { gpr_mu_lock(&pollset->mu); if (!pollset->seen_inactive) { pollset_neighborhood* neighborhood = pollset->neighborhood; @@ -507,27 +499,26 @@ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { gpr_mu_destroy(&pollset->mu); } -static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static grpc_error* pollset_kick_all(grpc_pollset* pollset) { GPR_TIMER_BEGIN("pollset_kick_all", 0); grpc_error* error = GRPC_ERROR_NONE; if (pollset->root_worker != nullptr) { grpc_pollset_worker* worker = pollset->root_worker; do { - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK(); switch (worker->state) { case KICKED: - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); break; case UNKICKED: SET_KICK_STATE(worker, KICKED); if (worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&worker->cv); } break; case DESIGNATED_POLLER: - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); SET_KICK_STATE(worker, KICKED); append_error(&error, grpc_wakeup_fd_wakeup(&global_wakeup_fd), "pollset_kick_all"); @@ -543,32 +534,29 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, return error; } -static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->begin_refs == 0) { GPR_TIMER_MARK("pollset_finish_shutdown", 0); - GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE); pollset->shutdown_closure = nullptr; } } -static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GPR_TIMER_BEGIN("pollset_shutdown", 0); GPR_ASSERT(pollset->shutdown_closure == nullptr); GPR_ASSERT(!pollset->shutting_down); pollset->shutdown_closure = closure; pollset->shutting_down = true; - GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); - pollset_maybe_finish_shutdown(exec_ctx, pollset); + GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset)); + pollset_maybe_finish_shutdown(pollset); GPR_TIMER_END("pollset_shutdown", 0); } -static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) { return INT_MAX; } else if (delta < 0) { @@ -586,8 +574,7 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, NOTE ON SYNCRHONIZATION: Similar to do_epoll_wait(), this function is only called by g_active_poller thread. So there is no need for synchronization when accessing fields in g_epoll_set */ -static grpc_error* process_epoll_events(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static grpc_error* process_epoll_events(grpc_pollset* pollset) { static const char* err_desc = "process_events"; grpc_error* error = GRPC_ERROR_NONE; @@ -611,11 +598,11 @@ static grpc_error* process_epoll_events(grpc_exec_ctx* exec_ctx, bool write_ev = (ev->events & EPOLLOUT) != 0; if (read_ev || cancel) { - fd_become_readable(exec_ctx, fd, pollset); + fd_become_readable(fd, pollset); } if (write_ev || cancel) { - fd_become_writable(exec_ctx, fd); + fd_become_writable(fd); } } } @@ -631,27 +618,26 @@ static grpc_error* process_epoll_events(grpc_exec_ctx* exec_ctx, NOTE ON SYNCHRONIZATION: At any point of time, only the g_active_poller (i.e the designated poller thread) will be calling this function. So there is no need for any synchronization when accesing fields in g_epoll_set */ -static grpc_error* do_epoll_wait(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, - grpc_millis deadline) { +static grpc_error* do_epoll_wait(grpc_pollset* ps, grpc_millis deadline) { GPR_TIMER_BEGIN("do_epoll_wait", 0); int r; - int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); + int timeout = poll_deadline_to_millis_timeout(deadline); if (timeout != 0) { GRPC_SCHEDULING_START_BLOCKING_REGION; } do { - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); r = epoll_wait(g_epoll_set.epfd, g_epoll_set.events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); + GRPC_SCHEDULING_END_BLOCKING_REGION; } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); - GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, r); + GRPC_STATS_INC_POLL_EVENTS_RETURNED(r); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "ps: %p poll got %d events", ps, r); @@ -664,8 +650,7 @@ static grpc_error* do_epoll_wait(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, return GRPC_ERROR_NONE; } -static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker* worker, +static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { GPR_TIMER_BEGIN("begin_worker", 0); @@ -760,7 +745,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, SET_KICK_STATE(worker, KICKED); } } - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); } if (grpc_polling_trace.enabled()) { @@ -791,7 +776,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } static bool check_neighborhood_for_available_poller( - grpc_exec_ctx* exec_ctx, pollset_neighborhood* neighborhood) { + pollset_neighborhood* neighborhood) { GPR_TIMER_BEGIN("check_neighborhood_for_available_poller", 0); bool found_worker = false; do { @@ -815,7 +800,7 @@ static bool check_neighborhood_for_available_poller( SET_KICK_STATE(inspect_worker, DESIGNATED_POLLER); if (inspect_worker->initialized_cv) { GPR_TIMER_MARK("signal worker", 0); - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&inspect_worker->cv); } } else { @@ -855,8 +840,7 @@ static bool check_neighborhood_for_available_poller( return found_worker; } -static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker* worker, +static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { GPR_TIMER_BEGIN("end_worker", 0); if (grpc_polling_trace.enabled()) { @@ -866,7 +850,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, /* Make sure we appear kicked */ SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, - &exec_ctx->closure_list); + grpc_core::ExecCtx::Get()->closure_list()); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { if (worker->next != worker && worker->next->state == UNKICKED) { if (grpc_polling_trace.enabled()) { @@ -875,11 +859,11 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, GPR_ASSERT(worker->next->initialized_cv); gpr_atm_no_barrier_store(&g_active_poller, (gpr_atm)worker->next); SET_KICK_STATE(worker->next, DESIGNATED_POLLER); - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&worker->next->cv); - if (grpc_exec_ctx_has_work(exec_ctx)) { + if (grpc_core::ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } else { @@ -894,8 +878,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, &g_neighborhoods[(poller_neighborhood_idx + i) % g_num_neighborhoods]; if (gpr_mu_trylock(&neighborhood->mu)) { - found_worker = - check_neighborhood_for_available_poller(exec_ctx, neighborhood); + found_worker = check_neighborhood_for_available_poller(neighborhood); gpr_mu_unlock(&neighborhood->mu); scan_state[i] = true; } else { @@ -908,16 +891,15 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, &g_neighborhoods[(poller_neighborhood_idx + i) % g_num_neighborhoods]; gpr_mu_lock(&neighborhood->mu); - found_worker = - check_neighborhood_for_available_poller(exec_ctx, neighborhood); + found_worker = check_neighborhood_for_available_poller(neighborhood); gpr_mu_unlock(&neighborhood->mu); } - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } - } else if (grpc_exec_ctx_has_work(exec_ctx)) { + } else if (grpc_core::ExecCtx::Get()->HasWork()) { gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } if (worker->initialized_cv) { @@ -927,7 +909,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, gpr_log(GPR_DEBUG, " .. remove worker"); } if (EMPTIED == worker_remove(pollset, worker)) { - pollset_maybe_finish_shutdown(exec_ctx, pollset); + pollset_maybe_finish_shutdown(pollset); } GPR_ASSERT(gpr_atm_no_barrier_load(&g_active_poller) != (gpr_atm)worker); GPR_TIMER_END("end_worker", 0); @@ -937,7 +919,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, +static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -950,7 +932,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, return GRPC_ERROR_NONE; } - if (begin_worker(exec_ctx, ps, &worker, worker_hdl, deadline)) { + if (begin_worker(ps, &worker, worker_hdl, deadline)) { gpr_tls_set(&g_current_thread_pollset, (intptr_t)ps); gpr_tls_set(&g_current_thread_worker, (intptr_t)&worker); GPR_ASSERT(!ps->shutting_down); @@ -968,14 +950,14 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, process_epoll_events() returns very quickly: It just queues the work on exec_ctx but does not execute it (the actual exectution or more - accurately grpc_exec_ctx_flush() happens in end_worker() AFTER selecting - a designated poller). So we are not waiting long periods without a - designated poller */ + accurately grpc_core::ExecCtx::Get()->Flush() happens in end_worker() + AFTER selecting a designated poller). So we are not waiting long periods + without a designated poller */ if (gpr_atm_acq_load(&g_epoll_set.cursor) == gpr_atm_acq_load(&g_epoll_set.num_events)) { - append_error(&error, do_epoll_wait(exec_ctx, ps, deadline), err_desc); + append_error(&error, do_epoll_wait(ps, deadline), err_desc); } - append_error(&error, process_epoll_events(exec_ctx, ps), err_desc); + append_error(&error, process_epoll_events(ps), err_desc); gpr_mu_lock(&ps->mu); /* lock */ @@ -983,17 +965,17 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, } else { gpr_tls_set(&g_current_thread_pollset, (intptr_t)ps); } - end_worker(exec_ctx, ps, &worker, worker_hdl); + end_worker(ps, &worker, worker_hdl); gpr_tls_set(&g_current_thread_pollset, 0); GPR_TIMER_END("pollset_work", 0); return error; } -static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +static grpc_error* pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { GPR_TIMER_BEGIN("pollset_kick", 0); - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK(); grpc_error* ret_err = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { gpr_strvec log; @@ -1026,7 +1008,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { grpc_pollset_worker* root_worker = pollset->root_worker; if (root_worker == nullptr) { - GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); pollset->kicked_without_poller = true; if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked_without_poller"); @@ -1035,14 +1017,14 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } grpc_pollset_worker* next_worker = root_worker->next; if (root_worker->state == KICKED) { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. already kicked %p", root_worker); } SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. already kicked %p", next_worker); } @@ -1053,7 +1035,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, // there is no next worker root_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load( &g_active_poller)) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked %p", root_worker); } @@ -1061,7 +1043,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (next_worker->state == UNKICKED) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked %p", next_worker); } @@ -1079,12 +1061,12 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } SET_KICK_STATE(root_worker, KICKED); if (root_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); gpr_cv_signal(&root_worker->cv); } goto done; } else { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker, root_worker); @@ -1094,13 +1076,13 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } } else { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); GPR_ASSERT(next_worker->state == KICKED); SET_KICK_STATE(next_worker, KICKED); goto done; } } else { - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked while waking up"); } @@ -1117,7 +1099,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker); } @@ -1125,7 +1107,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else if (specific_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick active poller"); } @@ -1133,7 +1115,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, ret_err = grpc_wakeup_fd_wakeup(&global_wakeup_fd); goto done; } else if (specific_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick waiting worker"); } @@ -1141,7 +1123,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, gpr_cv_signal(&specific_worker->cv); goto done; } else { - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kick non-waiting worker"); } @@ -1153,8 +1135,7 @@ done: return ret_err; } -static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_fd* fd) {} +static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {} /******************************************************************************* * Pollset-set Definitions @@ -1164,27 +1145,20 @@ static grpc_pollset_set* pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss) {} +static void pollset_set_destroy(grpc_pollset_set* pss) {} -static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) {} +static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {} -static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) {} +static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {} -static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) {} +static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {} -static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) {} +static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {} -static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} -static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} /******************************************************************************* @@ -1260,7 +1234,7 @@ const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { gpr_log(GPR_ERROR, "Skipping epoll1 becuase GRPC_LINUX_EPOLL is not defined."); - return NULL; + return nullptr; } #endif /* defined(GRPC_POSIX_SOCKET) */ #endif /* !defined(GRPC_LINUX_EPOLL) */ diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 62643df697..b2817156a8 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -257,8 +257,7 @@ static gpr_mu fd_freelist_mu; #ifndef NDEBUG #define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__) -#define UNREF_BY(ec, fd, n, reason) \ - unref_by(ec, fd, n, reason, __FILE__, __LINE__) +#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, int line) { if (grpc_trace_fd_refcount.enabled()) { @@ -269,13 +268,13 @@ static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file, } #else #define REF_BY(fd, n, reason) ref_by(fd, n) -#define UNREF_BY(ec, fd, n, reason) unref_by(ec, fd, n) +#define UNREF_BY(fd, n, reason) unref_by(fd, n) static void ref_by(grpc_fd* fd, int n) { #endif GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0); } -static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void fd_destroy(void* arg, grpc_error* error) { grpc_fd* fd = (grpc_fd*)arg; /* Add the fd to the freelist */ grpc_iomgr_unregister_object(&fd->iomgr_object); @@ -293,8 +292,8 @@ static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { } #ifndef NDEBUG -static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n, - const char* reason, const char* file, int line) { +static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file, + int line) { if (grpc_trace_fd_refcount.enabled()) { gpr_log(GPR_DEBUG, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", @@ -302,12 +301,11 @@ static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n, gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); } #else -static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n) { +static void unref_by(grpc_fd* fd, int n) { #endif gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n); if (old == n) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(fd_destroy, fd, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } else { @@ -373,8 +371,7 @@ static int fd_wrapped_fd(grpc_fd* fd) { return (gpr_atm_acq_load(&fd->refst) & 1) ? ret_fd : -1; } -static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { bool is_fd_closed = already_closed; @@ -399,15 +396,14 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, to be alive (and not added to freelist) until the end of this function */ REF_BY(fd, 1, reason); - GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_NONE); gpr_mu_unlock(&fd->orphan_mu); - UNREF_BY(exec_ctx, fd, 2, reason); /* Drop the reference */ + UNREF_BY(fd, 2, reason); /* Drop the reference */ } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, - grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -417,22 +413,20 @@ static bool fd_is_shutdown(grpc_fd* fd) { } /* Might be called multiple times */ -static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { - if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { +static void fd_shutdown(grpc_fd* fd, grpc_error* why) { + if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { shutdown(fd->fd, SHUT_RDWR); - fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } -static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->read_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { + fd->read_closure->NotifyOn(closure); } -static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->write_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { + fd->write_closure->NotifyOn(closure); } /******************************************************************************* @@ -556,8 +550,7 @@ static void pollset_global_shutdown(void) { } /* pollset->mu must be held while calling this function */ -static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) " @@ -567,7 +560,7 @@ static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, } if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->containing_pollset_set_count == 0) { - GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE); pollset->shutdown_closure = nullptr; } } @@ -575,8 +568,7 @@ static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, /* pollset->mu must be held before calling this function, * pollset->active_pollable->mu & specific_worker->pollable_obj->mu must not be * held */ -static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, - grpc_pollset_worker* specific_worker) { +static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) { pollable* p = specific_worker->pollable_obj; grpc_core::mu_guard lock(&p->mu); GPR_ASSERT(specific_worker != nullptr); @@ -584,19 +576,19 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p); } - GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_AGAIN(); return GRPC_ERROR_NONE; } if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p); } - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); specific_worker->kicked = true; return GRPC_ERROR_NONE; } if (specific_worker == p->root_worker) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p); } @@ -605,7 +597,7 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, return error; } if (specific_worker->initialized_cv) { - GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p); } @@ -618,9 +610,9 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +static grpc_error* pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK(); if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", @@ -634,7 +626,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset); } - GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); + GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(); pollset->kicked_without_poller = true; return GRPC_ERROR_NONE; } else { @@ -654,29 +646,28 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, // so we take our chances and choose the SECOND worker enqueued against // the pollset as a worker that's likely to be in cv_wait return kick_one_worker( - exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next); + pollset->root_worker->links[PWLINK_POLLSET].next); } } else { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset); } - GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(); return GRPC_ERROR_NONE; } } else { - return kick_one_worker(exec_ctx, specific_worker); + return kick_one_worker(specific_worker); } } -static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static grpc_error* pollset_kick_all(grpc_pollset* pollset) { grpc_error* error = GRPC_ERROR_NONE; const char* err_desc = "pollset_kick_all"; grpc_pollset_worker* w = pollset->root_worker; if (w != nullptr) { do { - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); - append_error(&error, kick_one_worker(exec_ctx, w), err_desc); + GRPC_STATS_INC_POLLSET_KICK(); + append_error(&error, kick_one_worker(w), err_desc); w = w->links[PWLINK_POLLSET].next; } while (w != pollset->root_worker); } @@ -689,10 +680,9 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &pollset->mu; } -static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -701,9 +691,8 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, return (int)delta; } -static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_pollset* notifier) { - fd->read_closure->SetReady(exec_ctx); +static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { + fd->read_closure->SetReady(); /* Note, it is possible that fd_become_readable might be called twice with different 'notifier's when an fd becomes readable and it is in two epoll @@ -714,9 +703,7 @@ static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { - fd->write_closure->SetReady(exec_ctx); -} +static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { gpr_mu_lock(&fd->pollable_mu); @@ -745,16 +732,14 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { } /* pollset->po.mu lock must be held by the caller before calling this */ -static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GPR_ASSERT(pollset->shutdown_closure == nullptr); pollset->shutdown_closure = closure; - GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); - pollset_maybe_finish_shutdown(exec_ctx, pollset); + GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset)); + pollset_maybe_finish_shutdown(pollset); } -static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, +static grpc_error* pollable_process_events(grpc_pollset* pollset, pollable* pollable_obj, bool drain) { static const char* err_desc = "pollset_process_events"; grpc_error* error = GRPC_ERROR_NONE; @@ -784,10 +769,10 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, pollset, fd, cancel, read_ev, write_ev); } if (read_ev || cancel) { - fd_become_readable(exec_ctx, fd, pollset); + fd_become_readable(fd, pollset); } if (write_ev || cancel) { - fd_become_writable(exec_ctx, fd); + fd_become_writable(fd); } } } @@ -796,14 +781,13 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, } /* pollset_shutdown is guaranteed to be called before pollset_destroy. */ -static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = nullptr; } -static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, - grpc_millis deadline) { - int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); +static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) { + int timeout = poll_deadline_to_millis_timeout(deadline); if (grpc_polling_trace.enabled()) { char* desc = pollable_desc(p); @@ -816,11 +800,11 @@ static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, } int r; do { - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); r = epoll_wait(p->epfd, p->events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); + GRPC_SCHEDULING_END_BLOCKING_REGION; } if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); @@ -875,8 +859,7 @@ static worker_remove_result worker_remove(grpc_pollset_worker** root_worker, } /* Return true if this thread should poll */ -static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker* worker, +static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { bool do_poll = (pollset->shutdown_closure == nullptr); @@ -897,7 +880,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset, worker->pollable_obj, worker, - poll_deadline_to_millis_timeout(exec_ctx, deadline)); + poll_deadline_to_millis_timeout(deadline)); } while (do_poll && worker->pollable_obj->root_worker != worker) { if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu, @@ -919,7 +902,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, worker->pollable_obj, worker); } } - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); } else { gpr_mu_unlock(&pollset->mu); } @@ -928,8 +911,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, return do_poll; } -static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker* worker, +static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { gpr_mu_lock(&pollset->mu); gpr_mu_lock(&worker->pollable_obj->mu); @@ -945,7 +927,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, case WRR_EMPTIED: if (pollset->active_pollable != worker->pollable_obj) { // pollable no longer being polled: flush events - pollable_process_events(exec_ctx, pollset, worker->pollable_obj, true); + pollable_process_events(pollset, worker->pollable_obj, true); } break; case WRR_REMOVED: @@ -955,7 +937,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, POLLABLE_UNREF(worker->pollable_obj, "pollset_worker"); if (worker_remove(&pollset->root_worker, worker, PWLINK_POLLSET) == WRR_EMPTIED) { - pollset_maybe_finish_shutdown(exec_ctx, pollset); + pollset_maybe_finish_shutdown(pollset); } if (worker->initialized_cv) { gpr_cv_destroy(&worker->cv); @@ -970,7 +952,7 @@ static long gettid(void) { return syscall(__NR_gettid); } The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { #ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP @@ -988,7 +970,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR " kwp=%d pollable=%p", - pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(exec_ctx), + pollset, worker_hdl, WORKER_PTR, grpc_core::ExecCtx::Get()->Now(), deadline, pollset->kicked_without_poller, pollset->active_pollable); } static const char* err_desc = "pollset_work"; @@ -996,25 +978,23 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (pollset->kicked_without_poller) { pollset->kicked_without_poller = false; } else { - if (begin_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl, deadline)) { + if (begin_worker(pollset, WORKER_PTR, worker_hdl, deadline)) { gpr_tls_set(&g_current_thread_pollset, (intptr_t)pollset); gpr_tls_set(&g_current_thread_worker, (intptr_t)WORKER_PTR); if (WORKER_PTR->pollable_obj->event_cursor == WORKER_PTR->pollable_obj->event_count) { - append_error( - &error, - pollable_epoll(exec_ctx, WORKER_PTR->pollable_obj, deadline), - err_desc); + append_error(&error, pollable_epoll(WORKER_PTR->pollable_obj, deadline), + err_desc); } - append_error(&error, - pollable_process_events(exec_ctx, pollset, - WORKER_PTR->pollable_obj, false), - err_desc); - grpc_exec_ctx_flush(exec_ctx); + append_error( + &error, + pollable_process_events(pollset, WORKER_PTR->pollable_obj, false), + err_desc); + grpc_core::ExecCtx::Get()->Flush(); gpr_tls_set(&g_current_thread_pollset, 0); gpr_tls_set(&g_current_thread_worker, 0); } - end_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl); + end_worker(pollset, WORKER_PTR, worker_hdl); } #ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP gpr_free(worker); @@ -1024,7 +1004,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( - grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* fd) { + grpc_pollset* pollset, grpc_fd* fd) { static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd"; grpc_error* error = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { @@ -1032,7 +1012,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( "PS:%p add fd %p (%d); transition pollable from empty to fd", pollset, fd, fd->fd); } - append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); + append_error(&error, pollset_kick_all(pollset), err_desc); POLLABLE_UNREF(pollset->active_pollable, "pollset"); append_error(&error, fd_get_or_become_pollable(fd, &pollset->active_pollable), err_desc); @@ -1040,7 +1020,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( } static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( - grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* and_add_fd) { + grpc_pollset* pollset, grpc_fd* and_add_fd) { static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi"; grpc_error* error = GRPC_ERROR_NONE; if (grpc_polling_trace.enabled()) { @@ -1050,7 +1030,7 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( pollset, and_add_fd, and_add_fd ? and_add_fd->fd : -1, pollset->active_pollable->owner_fd); } - append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); + append_error(&error, pollset_kick_all(pollset), err_desc); grpc_fd* initial_fd = pollset->active_pollable->owner_fd; POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = nullptr; @@ -1068,27 +1048,25 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( } /* expects pollsets locked, flag whether fd is locked or not */ -static grpc_error* pollset_add_fd_locked(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, grpc_fd* fd) { +static grpc_error* pollset_add_fd_locked(grpc_pollset* pollset, grpc_fd* fd) { grpc_error* error = GRPC_ERROR_NONE; pollable* po_at_start = POLLABLE_REF(pollset->active_pollable, "pollset_add_fd"); switch (pollset->active_pollable->type) { case PO_EMPTY: /* empty pollable --> single fd pollable */ - error = pollset_transition_pollable_from_empty_to_fd_locked(exec_ctx, - pollset, fd); + error = pollset_transition_pollable_from_empty_to_fd_locked(pollset, fd); break; case PO_FD: gpr_mu_lock(&po_at_start->owner_fd->orphan_mu); if ((gpr_atm_no_barrier_load(&pollset->active_pollable->owner_fd->refst) & 1) == 0) { - error = pollset_transition_pollable_from_empty_to_fd_locked( - exec_ctx, pollset, fd); + error = + pollset_transition_pollable_from_empty_to_fd_locked(pollset, fd); } else { /* fd --> multipoller */ - error = pollset_transition_pollable_from_fd_to_multi_locked( - exec_ctx, pollset, fd); + error = + pollset_transition_pollable_from_fd_to_multi_locked(pollset, fd); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1105,8 +1083,7 @@ static grpc_error* pollset_add_fd_locked(grpc_exec_ctx* exec_ctx, return error; } -static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, +static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset, pollable** pollable_obj) { grpc_error* error = GRPC_ERROR_NONE; pollable* po_at_start = @@ -1123,8 +1100,8 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, POLLABLE_UNREF(pollset->active_pollable, "pollset"); error = pollable_create(PO_MULTI, &pollset->active_pollable); } else { - error = pollset_transition_pollable_from_fd_to_multi_locked( - exec_ctx, pollset, nullptr); + error = pollset_transition_pollable_from_fd_to_multi_locked(pollset, + nullptr); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1142,10 +1119,9 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, return error; } -static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_fd* fd) { +static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { gpr_mu_lock(&pollset->mu); - grpc_error* error = pollset_add_fd_locked(exec_ctx, pollset, fd); + grpc_error* error = pollset_add_fd_locked(pollset, fd); gpr_mu_unlock(&pollset->mu); GRPC_LOG_IF_ERROR("pollset_add_fd", error); } @@ -1171,28 +1147,27 @@ static grpc_pollset_set* pollset_set_create(void) { return pss; } -static void pollset_set_unref(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) { +static void pollset_set_unref(grpc_pollset_set* pss) { if (pss == nullptr) return; if (!gpr_unref(&pss->refs)) return; - pollset_set_unref(exec_ctx, pss->parent); + pollset_set_unref(pss->parent); gpr_mu_destroy(&pss->mu); for (size_t i = 0; i < pss->pollset_count; i++) { gpr_mu_lock(&pss->pollsets[i]->mu); if (0 == --pss->pollsets[i]->containing_pollset_set_count) { - pollset_maybe_finish_shutdown(exec_ctx, pss->pollsets[i]); + pollset_maybe_finish_shutdown(pss->pollsets[i]); } gpr_mu_unlock(&pss->pollsets[i]->mu); } for (size_t i = 0; i < pss->fd_count; i++) { - UNREF_BY(exec_ctx, pss->fds[i], 2, "pollset_set"); + UNREF_BY(pss->fds[i], 2, "pollset_set"); } gpr_free(pss->pollsets); gpr_free(pss->fds); gpr_free(pss); } -static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) { +static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd); } @@ -1215,8 +1190,7 @@ static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, GRPC_LOG_IF_ERROR(err_desc, error); } -static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) { +static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: del fd %p", pss, fd); } @@ -1224,7 +1198,7 @@ static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, size_t i; for (i = 0; i < pss->fd_count; i++) { if (pss->fds[i] == fd) { - UNREF_BY(exec_ctx, fd, 2, "pollset_set"); + UNREF_BY(fd, 2, "pollset_set"); break; } } @@ -1236,8 +1210,7 @@ static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, gpr_mu_unlock(&pss->mu); } -static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: del pollset %p", pss, ps); } @@ -1256,15 +1229,15 @@ static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&pss->mu); gpr_mu_lock(&ps->mu); if (0 == --ps->containing_pollset_set_count) { - pollset_maybe_finish_shutdown(exec_ctx, ps); + pollset_maybe_finish_shutdown(ps); } gpr_mu_unlock(&ps->mu); } // add all fds to pollables, and output a new array of unorphaned out_fds // assumes pollsets are multipollable -static grpc_error* add_fds_to_pollsets(grpc_exec_ctx* exec_ctx, grpc_fd** fds, - size_t fd_count, grpc_pollset** pollsets, +static grpc_error* add_fds_to_pollsets(grpc_fd** fds, size_t fd_count, + grpc_pollset** pollsets, size_t pollset_count, const char* err_desc, grpc_fd** out_fds, size_t* out_fd_count) { @@ -1273,7 +1246,7 @@ static grpc_error* add_fds_to_pollsets(grpc_exec_ctx* exec_ctx, grpc_fd** fds, gpr_mu_lock(&fds[i]->orphan_mu); if ((gpr_atm_no_barrier_load(&fds[i]->refst) & 1) == 0) { gpr_mu_unlock(&fds[i]->orphan_mu); - UNREF_BY(exec_ctx, fds[i], 2, "pollset_set"); + UNREF_BY(fds[i], 2, "pollset_set"); } else { for (size_t j = 0; j < pollset_count; j++) { append_error(&error, @@ -1287,8 +1260,7 @@ static grpc_error* add_fds_to_pollsets(grpc_exec_ctx* exec_ctx, grpc_fd** fds, return error; } -static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS:%p: add pollset %p", pss, ps); } @@ -1296,8 +1268,8 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, static const char* err_desc = "pollset_set_add_pollset"; pollable* pollable_obj = nullptr; gpr_mu_lock(&ps->mu); - if (!GRPC_LOG_IF_ERROR(err_desc, pollset_as_multipollable_locked( - exec_ctx, ps, &pollable_obj))) { + if (!GRPC_LOG_IF_ERROR(err_desc, + pollset_as_multipollable_locked(ps, &pollable_obj))) { GPR_ASSERT(pollable_obj == nullptr); gpr_mu_unlock(&ps->mu); return; @@ -1308,8 +1280,8 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, size_t initial_fd_count = pss->fd_count; pss->fd_count = 0; append_error(&error, - add_fds_to_pollsets(exec_ctx, pss->fds, initial_fd_count, &ps, 1, - err_desc, pss->fds, &pss->fd_count), + add_fds_to_pollsets(pss->fds, initial_fd_count, &ps, 1, err_desc, + pss->fds, &pss->fd_count), err_desc); if (pss->pollset_count == pss->pollset_capacity) { pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8); @@ -1323,8 +1295,7 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, GRPC_LOG_IF_ERROR(err_desc, error); } -static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* a, +static void pollset_set_add_pollset_set(grpc_pollset_set* a, grpc_pollset_set* b) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PSS: merge (%p, %p)", a, b); @@ -1373,13 +1344,13 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, a->fd_count = 0; append_error( &error, - add_fds_to_pollsets(exec_ctx, a->fds, initial_a_fd_count, b->pollsets, + add_fds_to_pollsets(a->fds, initial_a_fd_count, b->pollsets, b->pollset_count, "merge_a2b", a->fds, &a->fd_count), err_desc); append_error( &error, - add_fds_to_pollsets(exec_ctx, b->fds, b->fd_count, a->pollsets, - a->pollset_count, "merge_b2a", a->fds, &a->fd_count), + add_fds_to_pollsets(b->fds, b->fd_count, a->pollsets, a->pollset_count, + "merge_b2a", a->fds, &a->fd_count), err_desc); if (a->pollset_capacity < a->pollset_count + b->pollset_count) { a->pollset_capacity = @@ -1401,8 +1372,7 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&b->mu); } -static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} /******************************************************************************* @@ -1481,7 +1451,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux( bool explicitly_requested) { gpr_log(GPR_ERROR, "Skipping epollex becuase GRPC_LINUX_EPOLL is not defined."); - return NULL; + return nullptr; } #endif /* defined(GRPC_POSIX_SOCKET) */ diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 12c8483b8e..7a8962f4a8 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -165,13 +165,12 @@ static void fd_global_shutdown(void); #ifndef NDEBUG #define PI_ADD_REF(p, r) pi_add_ref_dbg((p), (r), __FILE__, __LINE__) -#define PI_UNREF(exec_ctx, p, r) \ - pi_unref_dbg((exec_ctx), (p), (r), __FILE__, __LINE__) +#define PI_UNREF(p, r) pi_unref_dbg((p), (r), __FILE__, __LINE__) #else #define PI_ADD_REF(p, r) pi_add_ref((p)) -#define PI_UNREF(exec_ctx, p, r) pi_unref((exec_ctx), (p)) +#define PI_UNREF(p, r) pi_unref((p)) #endif @@ -270,7 +269,7 @@ static grpc_wakeup_fd polling_island_wakeup_fd; static __thread polling_island* g_current_thread_polling_island; /* Forward declaration */ -static void polling_island_delete(grpc_exec_ctx* exec_ctx, polling_island* pi); +static void polling_island_delete(polling_island* pi); #ifdef GRPC_TSAN /* Currently TSAN may incorrectly flag data races between epoll_ctl and @@ -284,7 +283,7 @@ gpr_atm g_epoll_sync; #endif /* defined(GRPC_TSAN) */ static void pi_add_ref(polling_island* pi); -static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi); +static void pi_unref(polling_island* pi); #ifndef NDEBUG static void pi_add_ref_dbg(polling_island* pi, const char* reason, @@ -299,8 +298,8 @@ static void pi_add_ref_dbg(polling_island* pi, const char* reason, pi_add_ref(pi); } -static void pi_unref_dbg(grpc_exec_ctx* exec_ctx, polling_island* pi, - const char* reason, const char* file, int line) { +static void pi_unref_dbg(polling_island* pi, const char* reason, + const char* file, int line) { if (grpc_polling_trace.enabled()) { gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count); gpr_log(GPR_DEBUG, @@ -308,7 +307,7 @@ static void pi_unref_dbg(grpc_exec_ctx* exec_ctx, polling_island* pi, " (%s) - (%s, %d)", pi, old_cnt, (old_cnt - 1), reason, file, line); } - pi_unref(exec_ctx, pi); + pi_unref(pi); } #endif @@ -316,7 +315,7 @@ static void pi_add_ref(polling_island* pi) { gpr_atm_no_barrier_fetch_add(&pi->ref_count, 1); } -static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi) { +static void pi_unref(polling_island* pi) { /* If ref count went to zero, delete the polling island. Note that this deletion not be done under a lock. Once the ref count goes to zero, we are guaranteed that no one else holds a reference to the @@ -327,9 +326,9 @@ static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi) { */ if (1 == gpr_atm_full_fetch_add(&pi->ref_count, -1)) { polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); - polling_island_delete(exec_ctx, pi); + polling_island_delete(pi); if (next != nullptr) { - PI_UNREF(exec_ctx, next, "pi_delete"); /* Recursive call */ + PI_UNREF(next, "pi_delete"); /* Recursive call */ } } } @@ -465,8 +464,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd, } /* Might return NULL in case of an error */ -static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, - grpc_fd* initial_fd, +static polling_island* polling_island_create(grpc_fd* initial_fd, grpc_error** error) { polling_island* pi = nullptr; const char* err_desc = "polling_island_create"; @@ -482,7 +480,7 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, gpr_atm_rel_store(&pi->ref_count, 0); gpr_atm_rel_store(&pi->poller_count, 0); - gpr_atm_rel_store(&pi->merged_to, (gpr_atm)NULL); + gpr_atm_rel_store(&pi->merged_to, (gpr_atm) nullptr); pi->epoll_fd = epoll_create1(EPOLL_CLOEXEC); @@ -497,13 +495,13 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, done: if (*error != GRPC_ERROR_NONE) { - polling_island_delete(exec_ctx, pi); + polling_island_delete(pi); pi = nullptr; } return pi; } -static void polling_island_delete(grpc_exec_ctx* exec_ctx, polling_island* pi) { +static void polling_island_delete(polling_island* pi) { GPR_ASSERT(pi->fd_cnt == 0); if (pi->epoll_fd >= 0) { @@ -862,8 +860,7 @@ static int fd_wrapped_fd(grpc_fd* fd) { return ret_fd; } -static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; polling_island* unref_pi = nullptr; @@ -902,7 +899,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, fd->orphaned = true; - GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_REF(error)); gpr_mu_unlock(&fd->po.mu); UNREF_BY(fd, 2, reason); /* Drop the reference */ @@ -911,7 +908,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, The polling island owns a workqueue which owns an fd, and unreffing inside the lock can cause an eventual lock loop that makes TSAN very unhappy. */ - PI_UNREF(exec_ctx, unref_pi, "fd_orphan"); + PI_UNREF(unref_pi, "fd_orphan"); } if (error != GRPC_ERROR_NONE) { const char* msg = grpc_error_string(error); @@ -920,8 +917,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, GRPC_ERROR_UNREF(error); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, - grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); return (grpc_pollset*)notifier; } @@ -931,22 +927,20 @@ static bool fd_is_shutdown(grpc_fd* fd) { } /* Might be called multiple times */ -static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { - if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) { +static void fd_shutdown(grpc_fd* fd, grpc_error* why) { + if (fd->read_closure->SetShutdown(GRPC_ERROR_REF(why))) { shutdown(fd->fd, SHUT_RDWR); - fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why)); + fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); } GRPC_ERROR_UNREF(why); } -static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->read_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { + fd->read_closure->NotifyOn(closure); } -static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - fd->write_closure->NotifyOn(exec_ctx, closure); +static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { + fd->write_closure->NotifyOn(closure); } /******************************************************************************* @@ -1028,11 +1022,11 @@ static void push_front_worker(grpc_pollset* p, grpc_pollset_worker* worker) { } /* p->mu must be held before calling this function */ -static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, +static grpc_error* pollset_kick(grpc_pollset* p, grpc_pollset_worker* specific_worker) { GPR_TIMER_BEGIN("pollset_kick", 0); grpc_error* error = GRPC_ERROR_NONE; - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK(); const char* err_desc = "Kick Failure"; grpc_pollset_worker* worker = specific_worker; if (worker != nullptr) { @@ -1096,10 +1090,9 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutdown_done = nullptr; } -static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis millis) { +static int poll_deadline_to_millis_timeout(grpc_millis millis) { if (millis == GRPC_MILLIS_INF_FUTURE) return -1; - grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx); + grpc_millis delta = millis - grpc_core::ExecCtx::Get()->Now(); if (delta > INT_MAX) return INT_MAX; else if (delta < 0) @@ -1108,9 +1101,8 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, return (int)delta; } -static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_pollset* notifier) { - fd->read_closure->SetReady(exec_ctx); +static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { + fd->read_closure->SetReady(); /* Note, it is possible that fd_become_readable might be called twice with different 'notifier's when an fd becomes readable and it is in two epoll @@ -1121,39 +1113,34 @@ static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd, gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); } -static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { - fd->write_closure->SetReady(exec_ctx); -} +static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } -static void pollset_release_polling_island(grpc_exec_ctx* exec_ctx, - grpc_pollset* ps, +static void pollset_release_polling_island(grpc_pollset* ps, const char* reason) { if (ps->po.pi != nullptr) { - PI_UNREF(exec_ctx, ps->po.pi, reason); + PI_UNREF(ps->po.pi, reason); } ps->po.pi = nullptr; } -static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static void finish_shutdown_locked(grpc_pollset* pollset) { /* The pollset cannot have any workers if we are at this stage */ GPR_ASSERT(!pollset_has_workers(pollset)); pollset->finish_shutdown_called = true; /* Release the ref and set pollset->po.pi to NULL */ - pollset_release_polling_island(exec_ctx, pollset, "ps_shutdown"); - GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_done, GRPC_ERROR_NONE); + pollset_release_polling_island(pollset, "ps_shutdown"); + GRPC_CLOSURE_SCHED(pollset->shutdown_done, GRPC_ERROR_NONE); } /* pollset->po.mu lock must be held by the caller before calling this */ -static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GPR_TIMER_BEGIN("pollset_shutdown", 0); GPR_ASSERT(!pollset->shutting_down); pollset->shutting_down = true; pollset->shutdown_done = closure; - pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); + pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); /* If the pollset has any workers, we cannot call finish_shutdown_locked() because it would release the underlying polling island. In such a case, we @@ -1161,7 +1148,7 @@ static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (!pollset_has_workers(pollset)) { GPR_ASSERT(!pollset->finish_shutdown_called); GPR_TIMER_MARK("pollset_shutdown.finish_shutdown_locked", 0); - finish_shutdown_locked(exec_ctx, pollset); + finish_shutdown_locked(pollset); } GPR_TIMER_END("pollset_shutdown", 0); } @@ -1169,15 +1156,14 @@ static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, /* pollset_shutdown is guaranteed to be called before pollset_destroy. So other * than destroying the mutexes, there is nothing special that needs to be done * here */ -static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { GPR_ASSERT(!pollset_has_workers(pollset)); gpr_mu_destroy(&pollset->po.mu); } #define GRPC_EPOLL_MAX_EVENTS 100 /* Note: sig_mask contains the signal mask to use *during* epoll_wait() */ -static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, +static void pollset_work_and_unlock(grpc_pollset* pollset, grpc_pollset_worker* worker, int timeout_ms, sigset_t* sig_mask, grpc_error** error) { struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS]; @@ -1199,7 +1185,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, this function (i.e pollset_work_and_unlock()) is called */ if (pollset->po.pi == nullptr) { - pollset->po.pi = polling_island_create(exec_ctx, nullptr, error); + pollset->po.pi = polling_island_create(nullptr, error); if (pollset->po.pi == nullptr) { GPR_TIMER_END("pollset_work_and_unlock", 0); return; /* Fatal error. We cannot continue */ @@ -1219,7 +1205,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, /* Always do PI_ADD_REF before PI_UNREF because PI_UNREF may cause the polling island to be deleted */ PI_ADD_REF(pi, "ps"); - PI_UNREF(exec_ctx, pollset->po.pi, "ps"); + PI_UNREF(pollset->po.pi, "ps"); pollset->po.pi = pi; } @@ -1233,10 +1219,10 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, g_current_thread_polling_island = pi; GRPC_SCHEDULING_START_BLOCKING_REGION; - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms, sig_mask); - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); + GRPC_SCHEDULING_END_BLOCKING_REGION; if (ep_rv < 0) { if (errno != EINTR) { gpr_asprintf(&err_msg, @@ -1274,10 +1260,10 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, int read_ev = ep_ev[i].events & (EPOLLIN | EPOLLPRI); int write_ev = ep_ev[i].events & EPOLLOUT; if (read_ev || cancel) { - fd_become_readable(exec_ctx, fd, pollset); + fd_become_readable(fd, pollset); } if (write_ev || cancel) { - fd_become_writable(exec_ctx, fd); + fd_become_writable(fd); } } } @@ -1292,7 +1278,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, that we got before releasing the polling island lock). This is because pollset->po.pi pointer might get udpated in other parts of the code when there is an island merge while we are doing epoll_wait() above */ - PI_UNREF(exec_ctx, pi, "ps_work"); + PI_UNREF(pi, "ps_work"); GPR_TIMER_END("pollset_work_and_unlock", 0); } @@ -1301,12 +1287,12 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, The function pollset_work() may temporarily release the lock (pollset->po.mu) during the course of its execution but it will always re-acquire the lock and ensure that it is held by the time the function returns */ -static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { GPR_TIMER_BEGIN("pollset_work", 0); grpc_error* error = GRPC_ERROR_NONE; - int timeout_ms = poll_deadline_to_millis_timeout(exec_ctx, deadline); + int timeout_ms = poll_deadline_to_millis_timeout(deadline); sigset_t new_mask; @@ -1364,9 +1350,9 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, push_front_worker(pollset, &worker); /* Add worker to pollset */ - pollset_work_and_unlock(exec_ctx, pollset, &worker, timeout_ms, - &g_orig_sigmask, &error); - grpc_exec_ctx_flush(exec_ctx); + pollset_work_and_unlock(pollset, &worker, timeout_ms, &g_orig_sigmask, + &error); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); @@ -1386,10 +1372,10 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (pollset->shutting_down && !pollset_has_workers(pollset) && !pollset->finish_shutdown_called) { GPR_TIMER_MARK("pollset_work.finish_shutdown_locked", 0); - finish_shutdown_locked(exec_ctx, pollset); + finish_shutdown_locked(pollset); gpr_mu_unlock(&pollset->po.mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->po.mu); } @@ -1404,9 +1390,8 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, return error; } -static void add_poll_object(grpc_exec_ctx* exec_ctx, poll_obj* bag, - poll_obj_type bag_type, poll_obj* item, - poll_obj_type item_type) { +static void add_poll_object(poll_obj* bag, poll_obj_type bag_type, + poll_obj* item, poll_obj_type item_type) { GPR_TIMER_BEGIN("add_poll_object", 0); #ifndef NDEBUG @@ -1456,7 +1441,7 @@ retry: keeping TSAN happy outweigh any performance advantage we might have by keeping the lock held. */ gpr_mu_unlock(&item->mu); - pi_new = polling_island_create(exec_ctx, FD_FROM_PO(item), &error); + pi_new = polling_island_create(FD_FROM_PO(item), &error); gpr_mu_lock(&item->mu); /* Need to reverify any assumptions made between the initial lock and @@ -1475,11 +1460,11 @@ retry: /* Ref and unref so that the polling island gets deleted during unref */ PI_ADD_REF(pi_new, "dance_of_destruction"); - PI_UNREF(exec_ctx, pi_new, "dance_of_destruction"); + PI_UNREF(pi_new, "dance_of_destruction"); goto retry; } } else { - pi_new = polling_island_create(exec_ctx, nullptr, &error); + pi_new = polling_island_create(nullptr, &error); } GRPC_POLLING_TRACE( @@ -1533,7 +1518,7 @@ retry: if (item->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(item_type)); if (item->pi != nullptr) { - PI_UNREF(exec_ctx, item->pi, poll_obj_string(item_type)); + PI_UNREF(item->pi, poll_obj_string(item_type)); } item->pi = pi_new; } @@ -1541,7 +1526,7 @@ retry: if (bag->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(bag_type)); if (bag->pi != nullptr) { - PI_UNREF(exec_ctx, bag->pi, poll_obj_string(bag_type)); + PI_UNREF(bag->pi, poll_obj_string(bag_type)); } bag->pi = pi_new; } @@ -1553,10 +1538,8 @@ retry: GPR_TIMER_END("add_poll_object", 0); } -static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_fd* fd) { - add_poll_object(exec_ctx, &pollset->po, POLL_OBJ_POLLSET, &fd->po, - POLL_OBJ_FD); +static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { + add_poll_object(&pollset->po, POLL_OBJ_POLLSET, &fd->po, POLL_OBJ_FD); } /******************************************************************************* @@ -1573,48 +1556,39 @@ static grpc_pollset_set* pollset_set_create(void) { return pss; } -static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss) { +static void pollset_set_destroy(grpc_pollset_set* pss) { gpr_mu_destroy(&pss->po.mu); if (pss->po.pi != nullptr) { - PI_UNREF(exec_ctx, pss->po.pi, "pss_destroy"); + PI_UNREF(pss->po.pi, "pss_destroy"); } gpr_free(pss); } -static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) { - add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &fd->po, - POLL_OBJ_FD); +static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) { + add_poll_object(&pss->po, POLL_OBJ_POLLSET_SET, &fd->po, POLL_OBJ_FD); } -static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss, - grpc_fd* fd) { +static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) { /* Nothing to do */ } -static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) { - add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &ps->po, - POLL_OBJ_POLLSET); +static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { + add_poll_object(&pss->po, POLL_OBJ_POLLSET_SET, &ps->po, POLL_OBJ_POLLSET); } -static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pss, grpc_pollset* ps) { +static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) { /* Nothing to do */ } -static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - add_poll_object(exec_ctx, &bag->po, POLL_OBJ_POLLSET_SET, &item->po, + add_poll_object(&bag->po, POLL_OBJ_POLLSET_SET, &item->po, POLL_OBJ_POLLSET_SET); } -static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { /* Nothing to do */ } @@ -1760,7 +1734,7 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux( bool explicit_request) { gpr_log(GPR_ERROR, "Skipping epollsig becuase GRPC_LINUX_EPOLL is not defined."); - return NULL; + return nullptr; } #endif /* defined(GRPC_POSIX_SOCKET) */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index e32e1ba42a..006e3ddd2f 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -128,8 +128,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, MUST NOT be called with a pollset lock taken if got_read or got_write are 1, also does the become_{readable,writable} as appropriate. */ -static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* rec, - int got_read, int got_write, +static void fd_end_poll(grpc_fd_watcher* rec, int got_read, int got_write, grpc_pollset* read_notifier_pollset); /* Return 1 if this fd is orphaned, 0 otherwise */ @@ -186,11 +185,9 @@ struct grpc_pollset { }; /* Add an fd to a pollset */ -static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - struct grpc_fd* fd); +static void pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd); -static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd); +static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); /* Convert a timespec to milliseconds: - very small or negative poll times are clamped to zero to do a @@ -199,8 +196,7 @@ static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, - longer than a millisecond polls are rounded up to the next nearest millisecond to avoid spinning - infinite timeouts are converted to -1 */ -static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis deadline); +static int poll_deadline_to_millis_timeout(grpc_millis deadline); /* Allow kick to wakeup the currently polling worker */ #define GRPC_POLLSET_CAN_KICK_SELF 1 @@ -208,7 +204,7 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, #define GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP 2 /* As per pollset_kick, with an extended set of flags (defined above) -- mostly for fd_posix's use. */ -static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, +static grpc_error* pollset_kick_ext(grpc_pollset* p, grpc_pollset_worker* specific_worker, uint32_t flags) GRPC_MUST_USE_RESULT; @@ -353,8 +349,7 @@ static bool fd_is_orphaned(grpc_fd* fd) { } /* Return the read-notifier pollset */ -static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, - grpc_fd* fd) { +static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { grpc_pollset* notifier = nullptr; gpr_mu_lock(&fd->mu); @@ -364,39 +359,36 @@ static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, return notifier; } -static grpc_error* pollset_kick_locked(grpc_exec_ctx* exec_ctx, - grpc_fd_watcher* watcher) { +static grpc_error* pollset_kick_locked(grpc_fd_watcher* watcher) { gpr_mu_lock(&watcher->pollset->mu); GPR_ASSERT(watcher->worker); - grpc_error* err = - pollset_kick_ext(exec_ctx, watcher->pollset, watcher->worker, - GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); + grpc_error* err = pollset_kick_ext(watcher->pollset, watcher->worker, + GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); gpr_mu_unlock(&watcher->pollset->mu); return err; } -static void maybe_wake_one_watcher_locked(grpc_exec_ctx* exec_ctx, - grpc_fd* fd) { +static void maybe_wake_one_watcher_locked(grpc_fd* fd) { if (fd->inactive_watcher_root.next != &fd->inactive_watcher_root) { - pollset_kick_locked(exec_ctx, fd->inactive_watcher_root.next); + pollset_kick_locked(fd->inactive_watcher_root.next); } else if (fd->read_watcher) { - pollset_kick_locked(exec_ctx, fd->read_watcher); + pollset_kick_locked(fd->read_watcher); } else if (fd->write_watcher) { - pollset_kick_locked(exec_ctx, fd->write_watcher); + pollset_kick_locked(fd->write_watcher); } } -static void wake_all_watchers_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { +static void wake_all_watchers_locked(grpc_fd* fd) { grpc_fd_watcher* watcher; for (watcher = fd->inactive_watcher_root.next; watcher != &fd->inactive_watcher_root; watcher = watcher->next) { - pollset_kick_locked(exec_ctx, watcher); + pollset_kick_locked(watcher); } if (fd->read_watcher) { - pollset_kick_locked(exec_ctx, fd->read_watcher); + pollset_kick_locked(fd->read_watcher); } if (fd->write_watcher && fd->write_watcher != fd->read_watcher) { - pollset_kick_locked(exec_ctx, fd->write_watcher); + pollset_kick_locked(fd->write_watcher); } } @@ -405,12 +397,12 @@ static int has_watchers(grpc_fd* fd) { fd->inactive_watcher_root.next != &fd->inactive_watcher_root; } -static void close_fd_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { +static void close_fd_locked(grpc_fd* fd) { fd->closed = 1; if (!fd->released) { close(fd->fd); } - GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(fd->on_done_closure, GRPC_ERROR_NONE); } static int fd_wrapped_fd(grpc_fd* fd) { @@ -421,8 +413,7 @@ static int fd_wrapped_fd(grpc_fd* fd) { } } -static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* on_done, int* release_fd, +static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { fd->on_done_closure = on_done; fd->released = release_fd != nullptr; @@ -435,9 +426,9 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, gpr_mu_lock(&fd->mu); REF_BY(fd, 1, reason); /* remove active status, but keep referenced */ if (!has_watchers(fd)) { - close_fd_locked(exec_ctx, fd); + close_fd_locked(fd); } else { - wake_all_watchers_locked(exec_ctx, fd); + wake_all_watchers_locked(fd); } gpr_mu_unlock(&fd->mu); UNREF_BY(fd, 2, reason); /* drop the reference */ @@ -469,10 +460,10 @@ static grpc_error* fd_shutdown_error(grpc_fd* fd) { } } -static void notify_on_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure** st, grpc_closure* closure) { +static void notify_on_locked(grpc_fd* fd, grpc_closure** st, + grpc_closure* closure) { if (fd->shutdown) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("FD shutdown")); } else if (*st == CLOSURE_NOT_READY) { /* not ready ==> switch to a waiting state by setting the closure */ @@ -480,8 +471,8 @@ static void notify_on_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, } else if (*st == CLOSURE_READY) { /* already ready ==> queue the closure to run immediately */ *st = CLOSURE_NOT_READY; - GRPC_CLOSURE_SCHED(exec_ctx, closure, fd_shutdown_error(fd)); - maybe_wake_one_watcher_locked(exec_ctx, fd); + GRPC_CLOSURE_SCHED(closure, fd_shutdown_error(fd)); + maybe_wake_one_watcher_locked(fd); } else { /* upcallptr was set to a different closure. This is an error! */ gpr_log(GPR_ERROR, @@ -492,8 +483,7 @@ static void notify_on_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, } /* returns 1 if state becomes not ready */ -static int set_ready_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure** st) { +static int set_ready_locked(grpc_fd* fd, grpc_closure** st) { if (*st == CLOSURE_READY) { /* duplicate ready ==> ignore */ return 0; @@ -503,18 +493,18 @@ static int set_ready_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd, return 0; } else { /* waiting ==> queue closure */ - GRPC_CLOSURE_SCHED(exec_ctx, *st, fd_shutdown_error(fd)); + GRPC_CLOSURE_SCHED(*st, fd_shutdown_error(fd)); *st = CLOSURE_NOT_READY; return 1; } } static void set_read_notifier_pollset_locked( - grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_pollset* read_notifier_pollset) { + grpc_fd* fd, grpc_pollset* read_notifier_pollset) { fd->read_notifier_pollset = read_notifier_pollset; } -static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { +static void fd_shutdown(grpc_fd* fd, grpc_error* why) { gpr_mu_lock(&fd->mu); /* only shutdown once */ if (!fd->shutdown) { @@ -522,8 +512,8 @@ static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { fd->shutdown_error = why; /* signal read/write closed to OS so that future operations fail */ shutdown(fd->fd, SHUT_RDWR); - set_ready_locked(exec_ctx, fd, &fd->read_closure); - set_ready_locked(exec_ctx, fd, &fd->write_closure); + set_ready_locked(fd, &fd->read_closure); + set_ready_locked(fd, &fd->write_closure); } else { GRPC_ERROR_UNREF(why); } @@ -537,17 +527,15 @@ static bool fd_is_shutdown(grpc_fd* fd) { return r; } -static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { +static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { gpr_mu_lock(&fd->mu); - notify_on_locked(exec_ctx, fd, &fd->read_closure, closure); + notify_on_locked(fd, &fd->read_closure, closure); gpr_mu_unlock(&fd->mu); } -static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { +static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { gpr_mu_lock(&fd->mu); - notify_on_locked(exec_ctx, fd, &fd->write_closure, closure); + notify_on_locked(fd, &fd->write_closure, closure); gpr_mu_unlock(&fd->mu); } @@ -602,8 +590,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, return mask; } -static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, - int got_read, int got_write, +static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write, grpc_pollset* read_notifier_pollset) { int was_polling = 0; int kick = 0; @@ -637,23 +624,23 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, watcher->prev->next = watcher->next; } if (got_read) { - if (set_ready_locked(exec_ctx, fd, &fd->read_closure)) { + if (set_ready_locked(fd, &fd->read_closure)) { kick = 1; } if (read_notifier_pollset != nullptr) { - set_read_notifier_pollset_locked(exec_ctx, fd, read_notifier_pollset); + set_read_notifier_pollset_locked(fd, read_notifier_pollset); } } if (got_write) { - if (set_ready_locked(exec_ctx, fd, &fd->write_closure)) { + if (set_ready_locked(fd, &fd->write_closure)) { kick = 1; } } if (kick) { - maybe_wake_one_watcher_locked(exec_ctx, fd); + maybe_wake_one_watcher_locked(fd); } if (fd_is_orphaned(fd) && !has_watchers(fd) && !fd->closed) { - close_fd_locked(exec_ctx, fd); + close_fd_locked(fd); } gpr_mu_unlock(&fd->mu); @@ -714,12 +701,12 @@ static void kick_append_error(grpc_error** composite, grpc_error* error) { *composite = grpc_error_add_child(*composite, error); } -static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, +static grpc_error* pollset_kick_ext(grpc_pollset* p, grpc_pollset_worker* specific_worker, uint32_t flags) { GPR_TIMER_BEGIN("pollset_kick_ext", 0); grpc_error* error = GRPC_ERROR_NONE; - GRPC_STATS_INC_POLLSET_KICK(exec_ctx); + GRPC_STATS_INC_POLLSET_KICK(); /* pollset->mu already held */ if (specific_worker != nullptr) { @@ -785,9 +772,9 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, return error; } -static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, +static grpc_error* pollset_kick(grpc_pollset* p, grpc_pollset_worker* specific_worker) { - return pollset_kick_ext(exec_ctx, p, specific_worker, 0); + return pollset_kick_ext(p, specific_worker, 0); } /* global state management */ @@ -821,7 +808,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->pollset_set_count = 0; } -static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { GPR_ASSERT(!pollset_has_workers(pollset)); GPR_ASSERT(pollset->idle_jobs.head == pollset->idle_jobs.tail); while (pollset->local_wakeup_cache) { @@ -834,8 +821,7 @@ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { gpr_mu_destroy(&pollset->mu); } -static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_fd* fd) { +static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) { gpr_mu_lock(&pollset->mu); size_t i; /* TODO(ctiller): this is O(num_fds^2); maybe switch to a hash set here */ @@ -850,19 +836,19 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } pollset->fds[pollset->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); - pollset_kick(exec_ctx, pollset, nullptr); + pollset_kick(pollset, nullptr); exit: gpr_mu_unlock(&pollset->mu); } -static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +static void finish_shutdown(grpc_pollset* pollset) { GPR_ASSERT(grpc_closure_list_empty(pollset->idle_jobs)); size_t i; for (i = 0; i < pollset->fd_count; i++) { GRPC_FD_UNREF(pollset->fds[i], "multipoller"); } pollset->fd_count = 0; - GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pollset->shutdown_done, GRPC_ERROR_NONE); } static void work_combine_error(grpc_error** composite, grpc_error* error) { @@ -873,7 +859,7 @@ static void work_combine_error(grpc_error** composite, grpc_error* error) { *composite = grpc_error_add_child(*composite, error); } -static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +static grpc_error* pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -912,7 +898,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (!pollset_has_workers(pollset) && !grpc_closure_list_empty(pollset->idle_jobs)) { GPR_TIMER_MARK("pollset_work.idle_jobs", 0); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); goto done; } /* If we're shutting down then we don't execute any extended work */ @@ -944,7 +930,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd_watcher* watchers; struct pollfd* pfds; - timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); + timeout = poll_deadline_to_millis_timeout(deadline); if (pollset->fd_count + 2 <= inline_elements) { pfds = pollfd_space; @@ -988,9 +974,9 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, /* TODO(vpai): Consider first doing a 0 timeout poll here to avoid even going into the blocking annotation if possible */ GRPC_SCHEDULING_START_BLOCKING_REGION; - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); r = grpc_poll_function(pfds, pfd_count, timeout); - GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); + GRPC_SCHEDULING_END_BLOCKING_REGION; if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); @@ -1003,16 +989,16 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0, nullptr); } else { // Wake up all the file descriptors, if we have an invalid one // we can identify it on the next pollset_work() - fd_end_poll(exec_ctx, &watchers[i], 1, 1, pollset); + fd_end_poll(&watchers[i], 1, 1, pollset); } } } else if (r == 0) { for (i = 1; i < pfd_count; i++) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0, nullptr); } } else { if (pfds[0].revents & POLLIN_CHECK) { @@ -1024,14 +1010,14 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0, nullptr); } else { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); } - fd_end_poll(exec_ctx, &watchers[i], pfds[i].revents & POLLIN_CHECK, + fd_end_poll(&watchers[i], pfds[i].revents & POLLIN_CHECK, pfds[i].revents & POLLOUT_CHECK, pollset); } } @@ -1054,7 +1040,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, worker list, which means nobody could ask us to re-evaluate polling). */ done: if (!locked) { - queued_work |= grpc_exec_ctx_flush(exec_ctx); + queued_work |= grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); locked = 1; } @@ -1083,21 +1069,21 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, /* check shutdown conditions */ if (pollset->shutting_down) { if (pollset_has_workers(pollset)) { - pollset_kick(exec_ctx, pollset, nullptr); + pollset_kick(pollset, nullptr); } else if (!pollset->called_shutdown && !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(exec_ctx, pollset); - grpc_exec_ctx_flush(exec_ctx); + finish_shutdown(pollset); + grpc_core::ExecCtx::Get()->Flush(); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * pollset_work. * TODO(dklempner): Can we refactor the shutdown logic to avoid this? */ gpr_mu_lock(&pollset->mu); } else if (!grpc_closure_list_empty(pollset->idle_jobs)) { - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); gpr_mu_unlock(&pollset->mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&pollset->mu); } } @@ -1107,26 +1093,24 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, return error; } -static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GPR_ASSERT(!pollset->shutting_down); pollset->shutting_down = 1; pollset->shutdown_done = closure; - pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); + pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset_has_workers(pollset)) { - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &pollset->idle_jobs); + GRPC_CLOSURE_LIST_SCHED(&pollset->idle_jobs); } if (!pollset->called_shutdown && !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; - finish_shutdown(exec_ctx, pollset); + finish_shutdown(pollset); } } -static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis deadline) { +static int poll_deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) return -1; if (deadline == 0) return 0; - grpc_millis n = deadline - grpc_exec_ctx_now(exec_ctx); + grpc_millis n = deadline - grpc_core::ExecCtx::Get()->Now(); if (n < 0) return 0; if (n > INT_MAX) return -1; return (int)n; @@ -1143,8 +1127,7 @@ static grpc_pollset_set* pollset_set_create(void) { return pollset_set; } -static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set) { +static void pollset_set_destroy(grpc_pollset_set* pollset_set) { size_t i; gpr_mu_destroy(&pollset_set->mu); for (i = 0; i < pollset_set->fd_count; i++) { @@ -1159,7 +1142,7 @@ static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(exec_ctx, pollset); + finish_shutdown(pollset); } else { gpr_mu_unlock(&pollset->mu); } @@ -1170,8 +1153,7 @@ static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, gpr_free(pollset_set); } -static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { size_t i, j; gpr_mu_lock(&pollset->mu); @@ -1190,7 +1172,7 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, if (fd_is_orphaned(pollset_set->fds[i])) { GRPC_FD_UNREF(pollset_set->fds[i], "pollset_set"); } else { - pollset_add_fd(exec_ctx, pollset, pollset_set->fds[i]); + pollset_add_fd(pollset, pollset_set->fds[i]); pollset_set->fds[j++] = pollset_set->fds[i]; } } @@ -1198,8 +1180,7 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&pollset_set->mu); } -static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { size_t i; gpr_mu_lock(&pollset_set->mu); @@ -1219,14 +1200,13 @@ static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); - finish_shutdown(exec_ctx, pollset); + finish_shutdown(pollset); } else { gpr_mu_unlock(&pollset->mu); } } -static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { size_t i, j; gpr_mu_lock(&bag->mu); @@ -1241,7 +1221,7 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, if (fd_is_orphaned(bag->fds[i])) { GRPC_FD_UNREF(bag->fds[i], "pollset_set"); } else { - pollset_set_add_fd(exec_ctx, item, bag->fds[i]); + pollset_set_add_fd(item, bag->fds[i]); bag->fds[j++] = bag->fds[i]; } } @@ -1249,8 +1229,7 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&bag->mu); } -static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { size_t i; gpr_mu_lock(&bag->mu); @@ -1265,8 +1244,7 @@ static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&bag->mu); } -static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd) { +static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { size_t i; gpr_mu_lock(&pollset_set->mu); if (pollset_set->fd_count == pollset_set->fd_capacity) { @@ -1277,16 +1255,15 @@ static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, GRPC_FD_REF(fd, "pollset_set"); pollset_set->fds[pollset_set->fd_count++] = fd; for (i = 0; i < pollset_set->pollset_count; i++) { - pollset_add_fd(exec_ctx, pollset_set->pollsets[i], fd); + pollset_add_fd(pollset_set->pollsets[i], fd); } for (i = 0; i < pollset_set->pollset_set_count; i++) { - pollset_set_add_fd(exec_ctx, pollset_set->pollset_sets[i], fd); + pollset_set_add_fd(pollset_set->pollset_sets[i], fd); } gpr_mu_unlock(&pollset_set->mu); } -static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd) { +static void pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { size_t i; gpr_mu_lock(&pollset_set->mu); for (i = 0; i < pollset_set->fd_count; i++) { @@ -1299,7 +1276,7 @@ static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, } } for (i = 0; i < pollset_set->pollset_set_count; i++) { - pollset_set_del_fd(exec_ctx, pollset_set->pollset_sets[i], fd); + pollset_set_del_fd(pollset_set->pollset_sets[i], fd); } gpr_mu_unlock(&pollset_set->mu); } diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 031c97564a..b516f93058 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -46,7 +46,7 @@ grpc_poll_function_type grpc_poll_function = poll; grpc_wakeup_fd grpc_global_wakeup_fd; -static const grpc_event_engine_vtable* g_event_engine; +static const grpc_event_engine_vtable* g_event_engine = nullptr; static const char* g_poll_strategy_name = nullptr; typedef const grpc_event_engine_vtable* (*event_engine_factory_fn)( @@ -184,28 +184,25 @@ int grpc_fd_wrapped_fd(grpc_fd* fd) { return g_event_engine->fd_wrapped_fd(fd); } -void grpc_fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, - int* release_fd, bool already_closed, const char* reason) { - g_event_engine->fd_orphan(exec_ctx, fd, on_done, release_fd, already_closed, - reason); +void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, + bool already_closed, const char* reason) { + g_event_engine->fd_orphan(fd, on_done, release_fd, already_closed, reason); } -void grpc_fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) { - g_event_engine->fd_shutdown(exec_ctx, fd, why); +void grpc_fd_shutdown(grpc_fd* fd, grpc_error* why) { + g_event_engine->fd_shutdown(fd, why); } bool grpc_fd_is_shutdown(grpc_fd* fd) { return g_event_engine->fd_is_shutdown(fd); } -void grpc_fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - g_event_engine->fd_notify_on_read(exec_ctx, fd, closure); +void grpc_fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { + g_event_engine->fd_notify_on_read(fd, closure); } -void grpc_fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure) { - g_event_engine->fd_notify_on_write(exec_ctx, fd, closure); +void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { + g_event_engine->fd_notify_on_write(fd, closure); } size_t grpc_pollset_size(void) { return g_event_engine->pollset_size; } @@ -214,72 +211,63 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { g_event_engine->pollset_init(pollset, mu); } -void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { - g_event_engine->pollset_shutdown(exec_ctx, pollset, closure); +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { + g_event_engine->pollset_shutdown(pollset, closure); } -void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { - g_event_engine->pollset_destroy(exec_ctx, pollset); +void grpc_pollset_destroy(grpc_pollset* pollset) { + g_event_engine->pollset_destroy(pollset); } -grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) { - return g_event_engine->pollset_work(exec_ctx, pollset, worker, deadline); + return g_event_engine->pollset_work(pollset, worker, deadline); } -grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - return g_event_engine->pollset_kick(exec_ctx, pollset, specific_worker); + return g_event_engine->pollset_kick(pollset, specific_worker); } -void grpc_pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - struct grpc_fd* fd) { - g_event_engine->pollset_add_fd(exec_ctx, pollset, fd); +void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { + g_event_engine->pollset_add_fd(pollset, fd); } grpc_pollset_set* grpc_pollset_set_create(void) { return g_event_engine->pollset_set_create(); } -void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set) { - g_event_engine->pollset_set_destroy(exec_ctx, pollset_set); +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { + g_event_engine->pollset_set_destroy(pollset_set); } -void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - g_event_engine->pollset_set_add_pollset(exec_ctx, pollset_set, pollset); + g_event_engine->pollset_set_add_pollset(pollset_set, pollset); } -void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - g_event_engine->pollset_set_del_pollset(exec_ctx, pollset_set, pollset); + g_event_engine->pollset_set_del_pollset(pollset_set, pollset); } -void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - g_event_engine->pollset_set_add_pollset_set(exec_ctx, bag, item); + g_event_engine->pollset_set_add_pollset_set(bag, item); } -void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - g_event_engine->pollset_set_del_pollset_set(exec_ctx, bag, item); + g_event_engine->pollset_set_del_pollset_set(bag, item); } -void grpc_pollset_set_add_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd) { - g_event_engine->pollset_set_add_fd(exec_ctx, pollset_set, fd); +void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { + g_event_engine->pollset_set_add_fd(pollset_set, fd); } -void grpc_pollset_set_del_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd) { - g_event_engine->pollset_set_del_fd(exec_ctx, pollset_set, fd); +void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { + g_event_engine->pollset_set_del_fd(pollset_set, fd); } #endif // GRPC_POSIX_SOCKET diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index 16fa10ca56..62f1162a23 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -36,48 +36,36 @@ typedef struct grpc_event_engine_vtable { grpc_fd* (*fd_create)(int fd, const char* name); int (*fd_wrapped_fd)(grpc_fd* fd); - void (*fd_orphan)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, - int* release_fd, bool already_closed, const char* reason); - void (*fd_shutdown)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why); - void (*fd_notify_on_read)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure); - void (*fd_notify_on_write)(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure); + void (*fd_orphan)(grpc_fd* fd, grpc_closure* on_done, int* release_fd, + bool already_closed, const char* reason); + void (*fd_shutdown)(grpc_fd* fd, grpc_error* why); + void (*fd_notify_on_read)(grpc_fd* fd, grpc_closure* closure); + void (*fd_notify_on_write)(grpc_fd* fd, grpc_closure* closure); bool (*fd_is_shutdown)(grpc_fd* fd); - grpc_pollset* (*fd_get_read_notifier_pollset)(grpc_exec_ctx* exec_ctx, - grpc_fd* fd); + grpc_pollset* (*fd_get_read_notifier_pollset)(grpc_fd* fd); void (*pollset_init)(grpc_pollset* pollset, gpr_mu** mu); - void (*pollset_shutdown)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure); - void (*pollset_destroy)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); - grpc_error* (*pollset_work)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + void (*pollset_shutdown)(grpc_pollset* pollset, grpc_closure* closure); + void (*pollset_destroy)(grpc_pollset* pollset); + grpc_error* (*pollset_work)(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline); - grpc_error* (*pollset_kick)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_error* (*pollset_kick)(grpc_pollset* pollset, grpc_pollset_worker* specific_worker); - void (*pollset_add_fd)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - struct grpc_fd* fd); + void (*pollset_add_fd)(grpc_pollset* pollset, struct grpc_fd* fd); grpc_pollset_set* (*pollset_set_create)(void); - void (*pollset_set_destroy)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set); - void (*pollset_set_add_pollset)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, + void (*pollset_set_destroy)(grpc_pollset_set* pollset_set); + void (*pollset_set_add_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); - void (*pollset_set_del_pollset)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, + void (*pollset_set_del_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); - void (*pollset_set_add_pollset_set)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, + void (*pollset_set_add_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); - void (*pollset_set_del_pollset_set)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, + void (*pollset_set_del_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); - void (*pollset_set_add_fd)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd); - void (*pollset_set_del_fd)(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd); + void (*pollset_set_add_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd); + void (*pollset_set_del_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd); void (*shutdown_engine)(void); } grpc_event_engine_vtable; @@ -103,14 +91,14 @@ int grpc_fd_wrapped_fd(grpc_fd* fd); Requires: *fd initialized; no outstanding notify_on_read or notify_on_write. MUST NOT be called with a pollset lock taken */ -void grpc_fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, - int* release_fd, bool already_closed, const char* reason); +void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, + bool already_closed, const char* reason); /* Has grpc_fd_shutdown been called on an fd? */ bool grpc_fd_is_shutdown(grpc_fd* fd); /* Cause any current and future callbacks to fail. */ -void grpc_fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why); +void grpc_fd_shutdown(grpc_fd* fd, grpc_error* why); /* Register read interest, causing read_cb to be called once when fd becomes readable, on deadline specified by deadline, or on shutdown triggered by @@ -125,29 +113,23 @@ void grpc_fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why); underlying platform. This means that users must drain fd in read_cb before calling notify_on_read again. Users are also expected to handle spurious events, i.e read_cb is called while nothing can be readable from fd */ -void grpc_fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure); +void grpc_fd_notify_on_read(grpc_fd* fd, grpc_closure* closure); /* Exactly the same semantics as above, except based on writable events. */ -void grpc_fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - grpc_closure* closure); +void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure); /* Return the read notifier pollset from the fd */ -grpc_pollset* grpc_fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, - grpc_fd* fd); +grpc_pollset* grpc_fd_get_read_notifier_pollset(grpc_fd* fd); /* pollset_posix functions */ /* Add an fd to a pollset */ -void grpc_pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - struct grpc_fd* fd); +void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd); /* pollset_set_posix functions */ -void grpc_pollset_set_add_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd); -void grpc_pollset_set_del_fd(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, grpc_fd* fd); +void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); +void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd); /* override to allow tests to hook poll() usage */ typedef int (*grpc_poll_function_type)(struct pollfd*, nfds_t, int); diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 1777456342..e005437e0a 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -25,39 +25,7 @@ #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/profiling/timers.h" -bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx* exec_ctx) { - if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { - if (exec_ctx->check_ready_to_finish(exec_ctx, - exec_ctx->check_ready_to_finish_arg)) { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - return true; - } - return false; - } else { - return true; - } -} - -bool grpc_never_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) { - return false; -} - -bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) { - return true; -} - -bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx) { - return exec_ctx->active_combiner != nullptr || - !grpc_closure_list_empty(exec_ctx->closure_list); -} - -void grpc_exec_ctx_finish(grpc_exec_ctx* exec_ctx) { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - grpc_exec_ctx_flush(exec_ctx); -} - -static void exec_ctx_run(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error) { +static void exec_ctx_run(grpc_closure* closure, grpc_error* error) { #ifndef NDEBUG closure->scheduled = false; if (grpc_trace_closure.enabled()) { @@ -67,7 +35,7 @@ static void exec_ctx_run(grpc_exec_ctx* exec_ctx, grpc_closure* closure, closure->line_initiated); } #endif - closure->cb(exec_ctx, closure->cb_arg, error); + closure->cb(closure->cb_arg, error); #ifndef NDEBUG if (grpc_trace_closure.enabled()) { gpr_log(GPR_DEBUG, "closure %p finished", closure); @@ -76,42 +44,13 @@ static void exec_ctx_run(grpc_exec_ctx* exec_ctx, grpc_closure* closure, GRPC_ERROR_UNREF(error); } -bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) { - bool did_something = 0; - GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); - for (;;) { - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { - grpc_closure* c = exec_ctx->closure_list.head; - exec_ctx->closure_list.head = exec_ctx->closure_list.tail = nullptr; - while (c != nullptr) { - grpc_closure* next = c->next_data.next; - grpc_error* error = c->error_data.error; - did_something = true; - exec_ctx_run(exec_ctx, c, error); - c = next; - } - } else if (!grpc_combiner_continue_exec_ctx(exec_ctx)) { - break; - } - } - GPR_ASSERT(exec_ctx->active_combiner == nullptr); - GPR_TIMER_END("grpc_exec_ctx_flush", 0); - return did_something; -} - -static void exec_ctx_sched(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error) { - grpc_closure_list_append(&exec_ctx->closure_list, closure, error); +static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) { + grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure, + error); } static gpr_timespec g_start_time; -void grpc_exec_ctx_global_init(void) { - g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); -} - -void grpc_exec_ctx_global_shutdown(void) {} - static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { ts = gpr_time_sub(ts, g_start_time); double x = @@ -131,18 +70,6 @@ static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { return (gpr_atm)x; } -grpc_millis grpc_exec_ctx_now(grpc_exec_ctx* exec_ctx) { - if (!exec_ctx->now_is_valid) { - exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); - exec_ctx->now_is_valid = true; - } - return exec_ctx->now; -} - -void grpc_exec_ctx_invalidate_now(grpc_exec_ctx* exec_ctx) { - exec_ctx->now_is_valid = false; -} - gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock_type) { // special-case infinities as grpc_millis can be 32bit on some platforms @@ -175,3 +102,44 @@ static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; grpc_closure_scheduler* grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; + +namespace grpc_core { +GPR_TLS_CLASS_DEF(ExecCtx::exec_ctx_); + +void ExecCtx::GlobalInit(void) { + g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); + gpr_tls_init(&exec_ctx_); +} + +bool ExecCtx::Flush() { + bool did_something = 0; + GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0); + for (;;) { + if (!grpc_closure_list_empty(closure_list_)) { + grpc_closure* c = closure_list_.head; + closure_list_.head = closure_list_.tail = nullptr; + while (c != nullptr) { + grpc_closure* next = c->next_data.next; + grpc_error* error = c->error_data.error; + did_something = true; + exec_ctx_run(c, error); + c = next; + } + } else if (!grpc_combiner_continue_exec_ctx()) { + break; + } + } + GPR_ASSERT(combiner_data_.active_combiner == nullptr); + GPR_TIMER_END("grpc_exec_ctx_flush", 0); + return did_something; +} + +grpc_millis ExecCtx::Now() { + if (!now_is_valid_) { + now_ = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); + now_is_valid_ = true; + } + return now_; +} + +} // namespace grpc_core diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index b415d2c255..b0c1740155 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -21,6 +21,8 @@ #include #include +#include +#include #include "src/core/lib/iomgr/closure.h" @@ -41,6 +43,13 @@ typedef struct grpc_combiner grpc_combiner; should be given to not delete said call/channel from this exec_ctx */ #define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 +extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; + +gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); + +namespace grpc_core { /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -61,63 +70,130 @@ typedef struct grpc_combiner grpc_combiner; * - Instances are always passed as the first argument to a function that * takes it, and always as a pointer (grpc_exec_ctx is never copied). */ -struct grpc_exec_ctx { - grpc_closure_list closure_list; - /** currently active combiner: updated only via combiner.c */ - grpc_combiner* active_combiner; - /** last active combiner in the active combiner list */ - grpc_combiner* last_combiner; - uintptr_t flags; - unsigned starting_cpu; - void* check_ready_to_finish_arg; - bool (*check_ready_to_finish)(grpc_exec_ctx* exec_ctx, void* arg); - - bool now_is_valid; - grpc_millis now; -}; +class ExecCtx { + public: + /** Default Constructor */ + + ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { Set(this); } -/* initializer for grpc_exec_ctx: - prefer to use GRPC_EXEC_CTX_INIT whenever possible */ -#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \ - { \ - GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, gpr_cpu_current_cpu(), \ - finish_check_arg, finish_check, false, 0 \ + /** Parameterised Constructor */ + ExecCtx(uintptr_t fl) : flags_(fl) { Set(this); } + + /** Destructor */ + ~ExecCtx() { + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + Flush(); + Set(last_exec_ctx_); } -/* initialize an execution context at the top level of an API call into grpc - (this is safe to use elsewhere, though possibly not as efficient) */ -#define GRPC_EXEC_CTX_INIT \ - GRPC_EXEC_CTX_INITIALIZER(GRPC_EXEC_CTX_FLAG_IS_FINISHED, NULL, NULL) + /** Disallow copy and assignment operators */ + ExecCtx(const ExecCtx&) = delete; + ExecCtx& operator=(const ExecCtx&) = delete; -extern grpc_closure_scheduler* grpc_schedule_on_exec_ctx; + /** Return starting_cpu */ + unsigned starting_cpu() const { return starting_cpu_; } -bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx); - -/** Flush any work that has been enqueued onto this grpc_exec_ctx. - * Caller must guarantee that no interfering locks are held. - * Returns true if work was performed, false otherwise. */ -bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx); -/** Finish any pending work for a grpc_exec_ctx. Must be called before - * the instance is destroyed, or work may be lost. */ -void grpc_exec_ctx_finish(grpc_exec_ctx* exec_ctx); -/** Returns true if we'd like to leave this execution context as soon as - possible: useful for deciding whether to do something more or not depending - on outside context */ -bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx* exec_ctx); -/** A finish check that is never ready to finish */ -bool grpc_never_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored); -/** A finish check that is always ready to finish */ -bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored); - -void grpc_exec_ctx_global_init(void); - -void grpc_exec_ctx_global_init(void); -void grpc_exec_ctx_global_shutdown(void); - -grpc_millis grpc_exec_ctx_now(grpc_exec_ctx* exec_ctx); -void grpc_exec_ctx_invalidate_now(grpc_exec_ctx* exec_ctx); -gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); -grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); -grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); + struct CombinerData { + /* currently active combiner: updated only via combiner.c */ + grpc_combiner* active_combiner; + /* last active combiner in the active combiner list */ + grpc_combiner* last_combiner; + }; + + /** Only to be used by grpc-combiner code */ + CombinerData* combiner_data() { return &combiner_data_; } + + /** Return pointer to grpc_closure_list */ + grpc_closure_list* closure_list() { return &closure_list_; } + + /** Return flags */ + uintptr_t flags() { return flags_; } + + /** Checks if there is work to be done */ + bool HasWork() { + return combiner_data_.active_combiner != NULL || + !grpc_closure_list_empty(closure_list_); + } + + /** Flush any work that has been enqueued onto this grpc_exec_ctx. + * Caller must guarantee that no interfering locks are held. + * Returns true if work was performed, false otherwise. */ + bool Flush(); + + /** Returns true if we'd like to leave this execution context as soon as +possible: useful for deciding whether to do something more or not depending +on outside context */ + bool IsReadyToFinish() { + if ((flags_ & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { + if (CheckReadyToFinish()) { + flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + return true; + } + return false; + } else { + return true; + } + } + + /** Returns the stored current time relative to start if valid, + * otherwise refreshes the stored time, sets it valid and returns the new + * value */ + grpc_millis Now(); + + /** Invalidates the stored time value. A new time value will be set on calling + * Now() */ + void InvalidateNow() { now_is_valid_ = false; } + + /** To be used only by shutdown code in iomgr */ + void SetNowIomgrShutdown() { + now_ = GRPC_MILLIS_INF_FUTURE; + now_is_valid_ = true; + } + + /** To be used only for testing. + * Sets the now value + */ + void TestOnlySetNow(grpc_millis new_val) { + now_ = new_val; + now_is_valid_ = true; + } + + /** Finish any pending work for a grpc_exec_ctx. Must be called before + * the instance is destroyed, or work may be lost. */ + void Finish(); + + /** Global initialization for ExecCtx. Called by iomgr */ + static void GlobalInit(void); + + /** Global shutdown for ExecCtx. Called by iomgr */ + static void GlobalShutdown(void) { gpr_tls_destroy(&exec_ctx_); } + + /** Gets pointer to current exec_ctx */ + static ExecCtx* Get() { + return reinterpret_cast(gpr_tls_get(&exec_ctx_)); + } + + protected: + /** Check if ready to finish */ + virtual bool CheckReadyToFinish() { return false; } + + private: + /** Set exec_ctx_ to exec_ctx */ + void Set(ExecCtx* exec_ctx) { + gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); + } + + grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; + CombinerData combiner_data_ = {nullptr, nullptr}; + uintptr_t flags_; + unsigned starting_cpu_ = gpr_cpu_current_cpu(); + + bool now_is_valid_ = false; + grpc_millis now_ = 0; + + GPR_TLS_CLASS_DECL(exec_ctx_); + ExecCtx* last_exec_ctx_ = Get(); +}; +} // namespace grpc_core #endif /* GRPC_CORE_LIB_IOMGR_EXEC_CTX_H */ diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index fabdbdf934..b45223ce16 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -55,7 +55,7 @@ grpc_core::TraceFlag executor_trace(false, "executor"); static void executor_thread(void* arg); -static size_t run_closures(grpc_exec_ctx* exec_ctx, grpc_closure_list list) { +static size_t run_closures(grpc_closure_list list) { size_t n = 0; grpc_closure* c = list.head; @@ -73,11 +73,11 @@ static size_t run_closures(grpc_exec_ctx* exec_ctx, grpc_closure_list list) { #ifndef NDEBUG c->scheduled = false; #endif - c->cb(exec_ctx, c->cb_arg, error); + c->cb(c->cb_arg, error); GRPC_ERROR_UNREF(error); c = next; n++; - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } return n; @@ -87,7 +87,7 @@ bool grpc_executor_is_threaded() { return gpr_atm_no_barrier_load(&g_cur_threads) > 0; } -void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool threading) { +void grpc_executor_set_threading(bool threading) { gpr_atm cur_threads = gpr_atm_no_barrier_load(&g_cur_threads); if (threading) { if (cur_threads > 0) return; @@ -125,28 +125,25 @@ void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool threading) { for (size_t i = 0; i < g_max_threads; i++) { gpr_mu_destroy(&g_thread_state[i].mu); gpr_cv_destroy(&g_thread_state[i].cv); - run_closures(exec_ctx, g_thread_state[i].elems); + run_closures(g_thread_state[i].elems); } gpr_free(g_thread_state); gpr_tls_destroy(&g_this_thread_state); } } -void grpc_executor_init(grpc_exec_ctx* exec_ctx) { +void grpc_executor_init() { gpr_atm_no_barrier_store(&g_cur_threads, 0); - grpc_executor_set_threading(exec_ctx, true); + grpc_executor_set_threading(true); } -void grpc_executor_shutdown(grpc_exec_ctx* exec_ctx) { - grpc_executor_set_threading(exec_ctx, false); -} +void grpc_executor_shutdown() { grpc_executor_set_threading(false); } static void executor_thread(void* arg) { thread_state* ts = (thread_state*)arg; gpr_tls_set(&g_this_thread_state, (intptr_t)ts); - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); + grpc_core::ExecCtx exec_ctx(0); size_t subtract_depth = 0; for (;;) { @@ -168,7 +165,7 @@ static void executor_thread(void* arg) { gpr_mu_unlock(&ts->mu); break; } - GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(&exec_ctx); + GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(); grpc_closure_list exec = ts->elems; ts->elems = GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); @@ -176,19 +173,18 @@ static void executor_thread(void* arg) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); } - grpc_exec_ctx_invalidate_now(&exec_ctx); - subtract_depth = run_closures(&exec_ctx, exec); + grpc_core::ExecCtx::Get()->InvalidateNow(); + subtract_depth = run_closures(exec); } - grpc_exec_ctx_finish(&exec_ctx); } -static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error, bool is_short) { +static void executor_push(grpc_closure* closure, grpc_error* error, + bool is_short) { bool retry_push; if (is_short) { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(exec_ctx); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(); } else { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(exec_ctx); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(); } do { retry_push = false; @@ -202,14 +198,16 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p inline", closure); #endif } - grpc_closure_list_append(&exec_ctx->closure_list, closure, error); + grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), + closure, error); return; } thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state); if (ts == nullptr) { - ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)]; + ts = &g_thread_state[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(), + cur_thread_count)]; } else { - GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(); } thread_state* orig_ts = ts; @@ -245,7 +243,7 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, continue; } if (grpc_closure_list_empty(ts->elems)) { - GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx); + GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(); gpr_cv_signal(&ts->cv); } grpc_closure_list_append(&ts->elems, closure, error); @@ -269,19 +267,17 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, gpr_spinlock_unlock(&g_adding_thread_lock); } if (retry_push) { - GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(exec_ctx); + GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(); } } while (retry_push); } -static void executor_push_short(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error) { - executor_push(exec_ctx, closure, error, true); +static void executor_push_short(grpc_closure* closure, grpc_error* error) { + executor_push(closure, error, true); } -static void executor_push_long(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_error* error) { - executor_push(exec_ctx, closure, error, false); +static void executor_push_long(grpc_closure* closure, grpc_error* error) { + executor_push(closure, error, false); } static const grpc_closure_scheduler_vtable executor_vtable_short = { diff --git a/src/core/lib/iomgr/executor.h b/src/core/lib/iomgr/executor.h index d349083eeb..e16f11aa21 100644 --- a/src/core/lib/iomgr/executor.h +++ b/src/core/lib/iomgr/executor.h @@ -31,18 +31,18 @@ typedef enum { * This mechanism is meant to outsource work (grpc_closure instances) to a * thread, for those cases where blocking isn't an option but there isn't a * non-blocking solution available. */ -void grpc_executor_init(grpc_exec_ctx* exec_ctx); +void grpc_executor_init(); grpc_closure_scheduler* grpc_executor_scheduler(grpc_executor_job_length); /** Shutdown the executor, running all pending work as part of the call */ -void grpc_executor_shutdown(grpc_exec_ctx* exec_ctx); +void grpc_executor_shutdown(); /** Is the executor multi-threaded? */ bool grpc_executor_is_threaded(); /* enable/disable threading - must be called after grpc_executor_init and before grpc_executor_shutdown */ -void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool enable); +void grpc_executor_set_threading(bool enable); #endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */ diff --git a/src/core/lib/iomgr/fork_posix.cc b/src/core/lib/iomgr/fork_posix.cc index f3cfd141b6..cc131408af 100644 --- a/src/core/lib/iomgr/fork_posix.cc +++ b/src/core/lib/iomgr/fork_posix.cc @@ -49,10 +49,10 @@ void grpc_prefork() { return; } if (grpc_is_initialized()) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_timer_manager_set_threading(false); - grpc_executor_set_threading(&exec_ctx, false); - grpc_exec_ctx_finish(&exec_ctx); + grpc_executor_set_threading(false); + grpc_core::ExecCtx::Get()->Flush(); if (!gpr_await_threads( gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(3, GPR_TIMESPAN)))) { @@ -64,18 +64,17 @@ void grpc_prefork() { void grpc_postfork_parent() { if (grpc_is_initialized()) { grpc_timer_manager_set_threading(true); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, true); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(true); } } void grpc_postfork_child() { if (grpc_is_initialized()) { grpc_timer_manager_set_threading(true); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, true); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(true); + grpc_core::ExecCtx::Get()->Flush(); } } diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 6bbe5669c7..0b6e6823b3 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -42,20 +42,18 @@ static gpr_atm g_custom_events = 0; static HANDLE g_iocp; -static DWORD deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, - grpc_millis deadline) { +static DWORD deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return INFINITE; } - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline < now) return 0; grpc_millis timeout = deadline - now; if (timeout > std::numeric_limits::max()) return INFINITE; return static_cast(deadline - now); } -grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, - grpc_millis deadline) { +grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { BOOL success; DWORD bytes = 0; DWORD flags = 0; @@ -63,11 +61,11 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, LPOVERLAPPED overlapped; grpc_winsocket* socket; grpc_winsocket_callback_info* info; - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key, &overlapped, - deadline_to_millis_timeout(exec_ctx, deadline)); - grpc_exec_ctx_invalidate_now(exec_ctx); + deadline_to_millis_timeout(deadline)); + grpc_core::ExecCtx::Get()->InvalidateNow(); if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } @@ -95,7 +93,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, info->bytes_transfered = bytes; info->wsa_error = success ? 0 : WSAGetLastError(); GPR_ASSERT(overlapped == &info->overlapped); - grpc_socket_become_ready(exec_ctx, socket, info); + grpc_socket_become_ready(socket, info); return GRPC_IOCP_WORK_WORK; } @@ -115,22 +113,22 @@ void grpc_iocp_kick(void) { } void grpc_iocp_flush(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_iocp_work_status work_status; do { - work_status = grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_PAST); + work_status = grpc_iocp_work(GRPC_MILLIS_INF_PAST); } while (work_status == GRPC_IOCP_WORK_KICK || - grpc_exec_ctx_flush(&exec_ctx)); + grpc_core::ExecCtx::Get()->Flush()); } void grpc_iocp_shutdown(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (gpr_atm_acq_load(&g_custom_events)) { - grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_FUTURE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(CloseHandle(g_iocp)); } diff --git a/src/core/lib/iomgr/iocp_windows.h b/src/core/lib/iomgr/iocp_windows.h index 0e9c3481f7..75b0ff4a92 100644 --- a/src/core/lib/iomgr/iocp_windows.h +++ b/src/core/lib/iomgr/iocp_windows.h @@ -33,8 +33,7 @@ typedef enum { GRPC_IOCP_WORK_KICK } grpc_iocp_work_status; -grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx* exec_ctx, - grpc_millis deadline); +grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline); void grpc_iocp_init(void); void grpc_iocp_kick(void); void grpc_iocp_flush(void); diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index e077b35014..dacf08ea9e 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -45,20 +45,20 @@ static gpr_cv g_rcv; static int g_shutdown; static grpc_iomgr_object g_root_object; -void grpc_iomgr_init(grpc_exec_ctx* exec_ctx) { +void grpc_iomgr_init() { + grpc_core::ExecCtx exec_ctx; g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); - grpc_exec_ctx_global_init(); - grpc_executor_init(exec_ctx); - grpc_timer_list_init(exec_ctx); + grpc_executor_init(); + grpc_timer_list_init(); g_root_object.next = g_root_object.prev = &g_root_object; g_root_object.name = (char*)"root"; grpc_network_status_init(); grpc_iomgr_platform_init(); } -void grpc_iomgr_start(grpc_exec_ctx* exec_ctx) { grpc_timer_manager_init(); } +void grpc_iomgr_start() { grpc_timer_manager_init(); } static size_t count_objects(void) { grpc_iomgr_object* obj; @@ -76,75 +76,76 @@ static void dump_objects(const char* kind) { } } -void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) { +void grpc_iomgr_shutdown() { gpr_timespec shutdown_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)); gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME); - grpc_timer_manager_shutdown(); - grpc_iomgr_platform_flush(); - grpc_executor_shutdown(exec_ctx); - - gpr_mu_lock(&g_mu); - g_shutdown = 1; - while (g_root_object.next != &g_root_object) { - if (gpr_time_cmp( - gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), - gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Waiting for %" PRIuPTR " iomgr objects to be destroyed", - count_objects()); + { + grpc_timer_manager_shutdown(); + grpc_iomgr_platform_flush(); + grpc_executor_shutdown(); + + gpr_mu_lock(&g_mu); + g_shutdown = 1; + while (g_root_object.next != &g_root_object) { + if (gpr_time_cmp( + gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), + gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Waiting for %" PRIuPTR " iomgr objects to be destroyed", + count_objects()); + } + last_warning_time = gpr_now(GPR_CLOCK_REALTIME); } - last_warning_time = gpr_now(GPR_CLOCK_REALTIME); - } - exec_ctx->now_is_valid = true; - exec_ctx->now = GRPC_MILLIS_INF_FUTURE; - if (grpc_timer_check(exec_ctx, nullptr) == GRPC_TIMERS_FIRED) { - gpr_mu_unlock(&g_mu); - grpc_exec_ctx_flush(exec_ctx); - grpc_iomgr_platform_flush(); - gpr_mu_lock(&g_mu); - continue; - } - if (g_root_object.next != &g_root_object) { - if (grpc_iomgr_abort_on_leaks()) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); - abort(); + grpc_core::ExecCtx::Get()->SetNowIomgrShutdown(); + if (grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED) { + gpr_mu_unlock(&g_mu); + grpc_core::ExecCtx::Get()->Flush(); + grpc_iomgr_platform_flush(); + gpr_mu_lock(&g_mu); + continue; } - gpr_timespec short_deadline = gpr_time_add( - gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); - if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { - if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) { - if (g_root_object.next != &g_root_object) { - gpr_log(GPR_DEBUG, - "Failed to free %" PRIuPTR - " iomgr objects before shutdown deadline: " - "memory leaks are likely", - count_objects()); - dump_objects("LEAKED"); + if (g_root_object.next != &g_root_object) { + if (grpc_iomgr_abort_on_leaks()) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); + abort(); + } + gpr_timespec short_deadline = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(100, GPR_TIMESPAN)); + if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) { + if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > + 0) { + if (g_root_object.next != &g_root_object) { + gpr_log(GPR_DEBUG, + "Failed to free %" PRIuPTR + " iomgr objects before shutdown deadline: " + "memory leaks are likely", + count_objects()); + dump_objects("LEAKED"); + } + break; } - break; } } } + gpr_mu_unlock(&g_mu); + grpc_timer_list_shutdown(); + grpc_core::ExecCtx::Get()->Flush(); } - gpr_mu_unlock(&g_mu); - - grpc_timer_list_shutdown(exec_ctx); - grpc_exec_ctx_flush(exec_ctx); /* ensure all threads have left g_mu */ gpr_mu_lock(&g_mu); gpr_mu_unlock(&g_mu); grpc_iomgr_platform_shutdown(); - grpc_exec_ctx_global_shutdown(); grpc_network_status_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr.h b/src/core/lib/iomgr/iomgr.h index 2f00c0343d..3f238c660a 100644 --- a/src/core/lib/iomgr/iomgr.h +++ b/src/core/lib/iomgr/iomgr.h @@ -23,13 +23,13 @@ #include "src/core/lib/iomgr/port.h" /** Initializes the iomgr. */ -void grpc_iomgr_init(grpc_exec_ctx* exec_ctx); +void grpc_iomgr_init(); /** Starts any background threads for iomgr. */ -void grpc_iomgr_start(grpc_exec_ctx* exec_ctx); +void grpc_iomgr_start(); /** Signals the intention to shutdown the iomgr. Expects to be able to flush * exec_ctx. */ -void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx); +void grpc_iomgr_shutdown(); #endif /* GRPC_CORE_LIB_IOMGR_IOMGR_H */ diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index b8a10f2ae8..9614c2e664 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -29,12 +29,11 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_global_init(); - grpc_executor_set_threading(&exec_ctx, false); + grpc_executor_set_threading(false); g_init_thread = gpr_thd_currentid(); - grpc_exec_ctx_finish(&exec_ctx); } void grpc_iomgr_platform_flush(void) {} void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index f0e798e8d8..7b194e3db5 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -85,7 +85,7 @@ void LockfreeEvent::DestroyEvent() { kShutdownBit /* shutdown, no error */)); } -void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { +void LockfreeEvent::NotifyOn(grpc_closure* closure) { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); if (grpc_polling_trace.enabled()) { @@ -118,7 +118,7 @@ void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { closure when transitioning out of CLOSURE_NO_READY state (i.e there is no other code that needs to 'happen-after' this) */ if (gpr_atm_no_barrier_cas(&state_, kClosureReady, kClosureNotReady)) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); return; /* Successful. Return */ } @@ -131,7 +131,7 @@ void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { schedule the closure with the shutdown error */ if ((curr & kShutdownBit) > 0) { grpc_error* shutdown_err = (grpc_error*)(curr & ~kShutdownBit); - GRPC_CLOSURE_SCHED(exec_ctx, closure, + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_err, 1)); return; @@ -149,8 +149,7 @@ void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { GPR_UNREACHABLE_CODE(return ); } -bool LockfreeEvent::SetShutdown(grpc_exec_ctx* exec_ctx, - grpc_error* shutdown_err) { +bool LockfreeEvent::SetShutdown(grpc_error* shutdown_err) { gpr_atm new_state = (gpr_atm)shutdown_err | kShutdownBit; while (true) { @@ -184,7 +183,7 @@ bool LockfreeEvent::SetShutdown(grpc_exec_ctx* exec_ctx, happens-after on that edge), and a release to pair with anything loading the shutdown state. */ if (gpr_atm_full_cas(&state_, curr, new_state)) { - GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr, + GRPC_CLOSURE_SCHED((grpc_closure*)curr, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "FD Shutdown", &shutdown_err, 1)); return true; @@ -200,7 +199,7 @@ bool LockfreeEvent::SetShutdown(grpc_exec_ctx* exec_ctx, GPR_UNREACHABLE_CODE(return false); } -void LockfreeEvent::SetReady(grpc_exec_ctx* exec_ctx) { +void LockfreeEvent::SetReady() { while (true) { gpr_atm curr = gpr_atm_no_barrier_load(&state_); @@ -234,7 +233,7 @@ void LockfreeEvent::SetReady(grpc_exec_ctx* exec_ctx) { spurious set_ready; release pairs with this or the acquire in notify_on (or set_shutdown) */ else if (gpr_atm_full_cas(&state_, curr, kClosureNotReady)) { - GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED((grpc_closure*)curr, GRPC_ERROR_NONE); return; } /* else the state changed again (only possible by either a racing diff --git a/src/core/lib/iomgr/lockfree_event.h b/src/core/lib/iomgr/lockfree_event.h index aec67a3399..3bd3fd72f1 100644 --- a/src/core/lib/iomgr/lockfree_event.h +++ b/src/core/lib/iomgr/lockfree_event.h @@ -44,9 +44,9 @@ class LockfreeEvent { return (gpr_atm_no_barrier_load(&state_) & kShutdownBit) != 0; } - void NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure); - bool SetShutdown(grpc_exec_ctx* exec_ctx, grpc_error* error); - void SetReady(grpc_exec_ctx* exec_ctx); + void NotifyOn(grpc_closure* closure); + bool SetShutdown(grpc_error* error); + void SetReady(); private: enum State { kClosureNotReady = 0, kClosureReady = 2, kShutdownBit = 1 }; diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc index 0ee4ea1255..126f6f45d6 100644 --- a/src/core/lib/iomgr/polling_entity.cc +++ b/src/core/lib/iomgr/polling_entity.cc @@ -56,32 +56,28 @@ bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) { return pollent->tag == GRPC_POLLS_NONE; } -void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_polling_entity* pollent, +void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { GPR_ASSERT(pollent->pollent.pollset != nullptr); - grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); + grpc_pollset_set_add_pollset(pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { GPR_ASSERT(pollent->pollent.pollset_set != nullptr); - grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst, - pollent->pollent.pollset_set); + grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set); } else { gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); abort(); } } -void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_polling_entity* pollent, +void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { GPR_ASSERT(pollent->pollent.pollset != nullptr); - grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); + grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { GPR_ASSERT(pollent->pollent.pollset_set != nullptr); - grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst, - pollent->pollent.pollset_set); + grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set); } else { gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); abort(); diff --git a/src/core/lib/iomgr/polling_entity.h b/src/core/lib/iomgr/polling_entity.h index dbe579e60d..0102d32c11 100644 --- a/src/core/lib/iomgr/polling_entity.h +++ b/src/core/lib/iomgr/polling_entity.h @@ -55,14 +55,12 @@ bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent); /** Add the pollset or pollset_set in \a pollent to the destination pollset_set * \a * pss_dst */ -void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_polling_entity* pollent, +void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set* pss_dst); /** Delete the pollset or pollset_set in \a pollent from the destination * pollset_set \a * pss_dst */ -void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_polling_entity* pollent, +void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, grpc_pollset_set* pss_dst); #endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */ diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index d5d78f3101..6bb3cd3e0c 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -42,9 +42,8 @@ size_t grpc_pollset_size(void); void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu); /* Begin shutting down the pollset, and call closure when done. * pollset's mutex must be held */ -void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure); -void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure); +void grpc_pollset_destroy(grpc_pollset* pollset); /* Do some work on a pollset. May involve invoking asynchronous callbacks, or actually polling file @@ -68,13 +67,13 @@ void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); May call grpc_closure_list_run on grpc_closure_list, without holding the pollset lock */ -grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) GRPC_MUST_USE_RESULT; /* Break one polling thread out of polling work for this pollset. If specific_worker is non-NULL, then kick that worker. */ -grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) GRPC_MUST_USE_RESULT; diff --git a/src/core/lib/iomgr/pollset_set.h b/src/core/lib/iomgr/pollset_set.h index 089c15cc94..a94d0afe75 100644 --- a/src/core/lib/iomgr/pollset_set.h +++ b/src/core/lib/iomgr/pollset_set.h @@ -29,19 +29,14 @@ typedef struct grpc_pollset_set grpc_pollset_set; grpc_pollset_set* grpc_pollset_set_create(void); -void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set); -void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set); +void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset); -void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset); -void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item); -void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item); #endif /* GRPC_CORE_LIB_IOMGR_POLLSET_SET_H */ diff --git a/src/core/lib/iomgr/pollset_set_uv.cc b/src/core/lib/iomgr/pollset_set_uv.cc index 90186edbb7..ac5dade8a5 100644 --- a/src/core/lib/iomgr/pollset_set_uv.cc +++ b/src/core/lib/iomgr/pollset_set_uv.cc @@ -26,23 +26,18 @@ grpc_pollset_set* grpc_pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set) {} +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/pollset_set_windows.cc b/src/core/lib/iomgr/pollset_set_windows.cc index 2105a47ad4..85edc9dee1 100644 --- a/src/core/lib/iomgr/pollset_set_windows.cc +++ b/src/core/lib/iomgr/pollset_set_windows.cc @@ -27,23 +27,18 @@ grpc_pollset_set* grpc_pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set) {} +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* pollset_set, +void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_pollset_set* bag, +void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) {} #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index 16132f3a80..d9e5ad81be 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -88,8 +88,7 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutting_down = 0; } -void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GPR_ASSERT(!pollset->shutting_down); GRPC_UV_ASSERT_SAME_THREAD(); pollset->shutting_down = 1; @@ -100,10 +99,10 @@ void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, // kick the loop once uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); } - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } -void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { +void grpc_pollset_destroy(grpc_pollset* pollset) { GRPC_UV_ASSERT_SAME_THREAD(); uv_close((uv_handle_t*)pollset->timer, timer_close_cb); // timer.data is a boolean indicating that the timer has finished closing @@ -115,14 +114,14 @@ void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { } } -grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { uint64_t timeout; GRPC_UV_ASSERT_SAME_THREAD(); gpr_mu_unlock(&grpc_polling_mu); if (grpc_pollset_work_run_loop) { - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline >= now) { timeout = deadline - now; } else { @@ -140,14 +139,14 @@ grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, uv_run(uv_default_loop(), UV_RUN_NOWAIT); } } - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { - grpc_exec_ctx_flush(exec_ctx); + if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { + grpc_core::ExecCtx::Get()->Flush(); } gpr_mu_lock(&grpc_polling_mu); return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { GRPC_UV_ASSERT_SAME_THREAD(); uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 95dd7d7ddd..6ef949aad7 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -92,20 +92,19 @@ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { &pollset->root_worker; } -void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure) { +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { pollset->shutting_down = 1; - grpc_pollset_kick(exec_ctx, pollset, GRPC_POLLSET_KICK_BROADCAST); + grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset->is_iocp_worker) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } else { pollset->on_shutdown = closure; } } -void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) {} +void grpc_pollset_destroy(grpc_pollset* pollset) {} -grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, +grpc_error* grpc_pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; @@ -126,8 +125,8 @@ grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, pollset->is_iocp_worker = 1; g_active_poller = &worker; gpr_mu_unlock(&grpc_polling_mu); - grpc_iocp_work(exec_ctx, deadline); - grpc_exec_ctx_flush(exec_ctx); + grpc_iocp_work(deadline); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); pollset->is_iocp_worker = 0; g_active_poller = NULL; @@ -145,7 +144,7 @@ grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } if (pollset->shutting_down && pollset->on_shutdown != NULL) { - GRPC_CLOSURE_SCHED(exec_ctx, pollset->on_shutdown, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(pollset->on_shutdown, GRPC_ERROR_NONE); pollset->on_shutdown = NULL; } goto done; @@ -158,18 +157,18 @@ grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, while (!worker.kicked) { if (gpr_cv_wait(&worker.cv, &grpc_polling_mu, grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); break; } - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); } } else { pollset->kicked_without_pollers = 0; } done: - if (!grpc_closure_list_empty(exec_ctx->closure_list)) { + if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { gpr_mu_unlock(&grpc_polling_mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&grpc_polling_mu); } if (added_worker) { @@ -181,7 +180,7 @@ done: return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, +grpc_error* grpc_pollset_kick(grpc_pollset* p, grpc_pollset_worker* specific_worker) { if (specific_worker != NULL) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { @@ -209,7 +208,7 @@ grpc_error* grpc_pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, specific_worker = pop_front_worker(&p->root_worker, GRPC_POLLSET_WORKER_LINK_POLLSET); if (specific_worker != NULL) { - grpc_pollset_kick(exec_ctx, p, specific_worker); + grpc_pollset_kick(p, specific_worker); } else if (p->is_iocp_worker) { grpc_iocp_kick(); } else { diff --git a/src/core/lib/iomgr/resolve_address.h b/src/core/lib/iomgr/resolve_address.h index 5105020404..12fc2ed088 100644 --- a/src/core/lib/iomgr/resolve_address.h +++ b/src/core/lib/iomgr/resolve_address.h @@ -38,8 +38,7 @@ typedef struct { /* Asynchronously resolve addr. Use default_port if a port isn't designated in addr, otherwise use the port in addr. */ /* TODO(ctiller): add a timeout here */ -extern void (*grpc_resolve_address)(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +extern void (*grpc_resolve_address)(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses); diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index fb5fa9d422..cc3d4fd7cf 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -42,6 +42,7 @@ static grpc_error* blocking_resolve_address_impl( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { + grpc_core::ExecCtx exec_ctx; struct addrinfo hints; struct addrinfo *result = nullptr, *resp; char* host; @@ -81,7 +82,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; if (s != 0) { /* Retry if well-known service name is recognized */ @@ -90,7 +91,7 @@ static grpc_error* blocking_resolve_address_impl( if (strcmp(port, svc[i][0]) == 0) { GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, svc[i][1], &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; break; } } @@ -152,12 +153,10 @@ typedef struct { /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ -static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, - grpc_error* error) { +static void do_request_thread(void* rp, grpc_error* error) { request* r = (request*)rp; - GRPC_CLOSURE_SCHED( - exec_ctx, r->on_done, - grpc_blocking_resolve_address(r->name, r->default_port, r->addrs_out)); + GRPC_CLOSURE_SCHED(r->on_done, grpc_blocking_resolve_address( + r->name, r->default_port, r->addrs_out)); gpr_free(r->name); gpr_free(r->default_port); gpr_free(r); @@ -170,8 +169,7 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, - const char* default_port, +static void resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -182,11 +180,11 @@ static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, r->default_port = gpr_strdup(default_port); r->on_done = on_done; r->addrs_out = addrs; - GRPC_CLOSURE_SCHED(exec_ctx, &r->request_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } void (*grpc_resolve_address)( - grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc index 6d09fd1d02..3eab04f3de 100644 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ b/src/core/lib/iomgr/resolve_address_uv.cc @@ -114,7 +114,7 @@ static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { request* r = (request*)req->data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_error* error; int retry_status; char* port = r->port; @@ -130,8 +130,8 @@ static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, /* Either no retry was attempted, or the retry failed. Either way, the original error probably has more interesting information */ error = handle_addrinfo_result(status, res, r->addresses); - GRPC_CLOSURE_SCHED(&exec_ctx, r->on_done, error); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CLOSURE_SCHED(r->on_done, error); + gpr_free(r->hints); gpr_free(r->host); gpr_free(r->port); @@ -224,8 +224,7 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, - const char* default_port, +static void resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -239,7 +238,7 @@ static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, GRPC_UV_ASSERT_SAME_THREAD(); err = try_split_host_port(name, default_port, &host, &port); if (err != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(exec_ctx, on_done, err); + GRPC_CLOSURE_SCHED(on_done, err); gpr_free(host); gpr_free(port); return; @@ -268,7 +267,7 @@ static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); err = grpc_error_set_str(err, GRPC_ERROR_STR_OS_ERROR, grpc_slice_from_static_string(uv_strerror(s))); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, err); + GRPC_CLOSURE_SCHED(on_done, err); gpr_free(r); gpr_free(req); gpr_free(hints); @@ -278,7 +277,7 @@ static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, } void (*grpc_resolve_address)( - grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index d9fc17a9f4..ccb1dae689 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -51,6 +51,7 @@ typedef struct { static grpc_error* blocking_resolve_address_impl( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { + grpc_core::ExecCtx exec_ctx; struct addrinfo hints; struct addrinfo *result = NULL, *resp; char* host; @@ -87,7 +88,7 @@ static grpc_error* blocking_resolve_address_impl( GRPC_SCHEDULING_START_BLOCKING_REGION; s = getaddrinfo(host, port, &hints, &result); - GRPC_SCHEDULING_END_BLOCKING_REGION_NO_EXEC_CTX; + GRPC_SCHEDULING_END_BLOCKING_REGION; if (s != 0) { error = GRPC_WSA_ERROR(WSAGetLastError(), "getaddrinfo"); goto done; @@ -132,8 +133,7 @@ grpc_error* (*grpc_blocking_resolve_address)( /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ -static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, - grpc_error* error) { +static void do_request_thread(void* rp, grpc_error* error) { request* r = (request*)rp; if (error == GRPC_ERROR_NONE) { error = @@ -141,7 +141,7 @@ static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, } else { GRPC_ERROR_REF(error); } - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, error); + GRPC_CLOSURE_SCHED(r->on_done, error); gpr_free(r->name); gpr_free(r->default_port); gpr_free(r); @@ -154,8 +154,7 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { gpr_free(addrs); } -static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, - const char* default_port, +static void resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) { @@ -166,11 +165,11 @@ static void resolve_address_impl(grpc_exec_ctx* exec_ctx, const char* name, r->default_port = gpr_strdup(default_port); r->on_done = on_done; r->addresses = addresses; - GRPC_CLOSURE_SCHED(exec_ctx, &r->request_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } void (*grpc_resolve_address)( - grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) = resolve_address_impl; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index ccd8d9f379..cabe28e4e6 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -154,8 +154,7 @@ struct grpc_resource_quota { char* name; }; -static void ru_unref_by(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, gpr_atm amount); +static void ru_unref_by(grpc_resource_user* resource_user, gpr_atm amount); /******************************************************************************* * list management @@ -239,35 +238,31 @@ static void rulist_remove(grpc_resource_user* resource_user, grpc_rulist list) { * resource quota state machine */ -static bool rq_alloc(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota); +static bool rq_alloc(grpc_resource_quota* resource_quota); static bool rq_reclaim_from_per_user_free_pool( - grpc_exec_ctx* exec_ctx, grpc_resource_quota* resource_quota); -static bool rq_reclaim(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota, bool destructive); + grpc_resource_quota* resource_quota); +static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive); -static void rq_step(grpc_exec_ctx* exec_ctx, void* rq, grpc_error* error) { +static void rq_step(void* rq, grpc_error* error) { grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; resource_quota->step_scheduled = false; do { - if (rq_alloc(exec_ctx, resource_quota)) goto done; - } while (rq_reclaim_from_per_user_free_pool(exec_ctx, resource_quota)); + if (rq_alloc(resource_quota)) goto done; + } while (rq_reclaim_from_per_user_free_pool(resource_quota)); - if (!rq_reclaim(exec_ctx, resource_quota, false)) { - rq_reclaim(exec_ctx, resource_quota, true); + if (!rq_reclaim(resource_quota, false)) { + rq_reclaim(resource_quota, true); } done: - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); } -static void rq_step_sched(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota) { +static void rq_step_sched(grpc_resource_quota* resource_quota) { if (resource_quota->step_scheduled) return; resource_quota->step_scheduled = true; grpc_resource_quota_ref_internal(resource_quota); - GRPC_CLOSURE_SCHED(exec_ctx, &resource_quota->rq_step_closure, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&resource_quota->rq_step_closure, GRPC_ERROR_NONE); } /* update the atomically available resource estimate - use no barriers since @@ -286,8 +281,7 @@ static void rq_update_estimate(grpc_resource_quota* resource_quota) { } /* returns true if all allocations are completed */ -static bool rq_alloc(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota) { +static bool rq_alloc(grpc_resource_quota* resource_quota) { grpc_resource_user* resource_user; while ((resource_user = rulist_pop_head(resource_quota, GRPC_RULIST_AWAITING_ALLOCATION))) { @@ -307,9 +301,9 @@ static bool rq_alloc(grpc_exec_ctx* exec_ctx, int64_t aborted_allocations = resource_user->outstanding_allocations; resource_user->outstanding_allocations = 0; resource_user->free_pool += aborted_allocations; - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &resource_user->on_allocated); + GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated); gpr_mu_unlock(&resource_user->mu); - ru_unref_by(exec_ctx, resource_user, (gpr_atm)aborted_allocations); + ru_unref_by(resource_user, (gpr_atm)aborted_allocations); continue; } if (resource_user->free_pool < 0 && @@ -333,7 +327,7 @@ static bool rq_alloc(grpc_exec_ctx* exec_ctx, if (resource_user->free_pool >= 0) { resource_user->allocating = false; resource_user->outstanding_allocations = 0; - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &resource_user->on_allocated); + GRPC_CLOSURE_LIST_SCHED(&resource_user->on_allocated); gpr_mu_unlock(&resource_user->mu); } else { rulist_add_head(resource_user, GRPC_RULIST_AWAITING_ALLOCATION); @@ -346,7 +340,7 @@ static bool rq_alloc(grpc_exec_ctx* exec_ctx, /* returns true if any memory could be reclaimed from buffers */ static bool rq_reclaim_from_per_user_free_pool( - grpc_exec_ctx* exec_ctx, grpc_resource_quota* resource_quota) { + grpc_resource_quota* resource_quota) { grpc_resource_user* resource_user; while ((resource_user = rulist_pop_head(resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL))) { @@ -373,8 +367,7 @@ static bool rq_reclaim_from_per_user_free_pool( } /* returns true if reclamation is proceeding */ -static bool rq_reclaim(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota, bool destructive) { +static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) { if (resource_quota->reclaiming) return true; grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE : GRPC_RULIST_RECLAIMER_BENIGN; @@ -392,7 +385,7 @@ static bool rq_reclaim(grpc_exec_ctx* exec_ctx, resource_quota->debug_only_last_reclaimer_resource_user = resource_user; resource_quota->debug_only_last_initiated_reclaimer = c; resource_user->reclaimers[destructive] = nullptr; - GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(c, GRPC_ERROR_NONE); return true; } @@ -412,10 +405,10 @@ static void ru_slice_ref(void* p) { gpr_ref(&rc->refs); } -static void ru_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void ru_slice_unref(void* p) { ru_slice_refcount* rc = (ru_slice_refcount*)p; if (gpr_unref(&rc->refs)) { - grpc_resource_user_free(exec_ctx, rc->resource_user, rc->size); + grpc_resource_user_free(rc->resource_user, rc->size); gpr_free(rc); } } @@ -445,61 +438,57 @@ static grpc_slice ru_slice_create(grpc_resource_user* resource_user, * the combiner */ -static void ru_allocate(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { +static void ru_allocate(void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; if (rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION)) { - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_AWAITING_ALLOCATION); } -static void ru_add_to_free_pool(grpc_exec_ctx* exec_ctx, void* ru, - grpc_error* error) { +static void ru_add_to_free_pool(void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL)) { - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_NON_EMPTY_FREE_POOL); } -static bool ru_post_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, +static bool ru_post_reclaimer(grpc_resource_user* resource_user, bool destructive) { grpc_closure* closure = resource_user->new_reclaimers[destructive]; GPR_ASSERT(closure != nullptr); resource_user->new_reclaimers[destructive] = nullptr; GPR_ASSERT(resource_user->reclaimers[destructive] == nullptr); if (gpr_atm_acq_load(&resource_user->shutdown) > 0) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CANCELLED); return false; } resource_user->reclaimers[destructive] = closure; return true; } -static void ru_post_benign_reclaimer(grpc_exec_ctx* exec_ctx, void* ru, - grpc_error* error) { +static void ru_post_benign_reclaimer(void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; - if (!ru_post_reclaimer(exec_ctx, resource_user, false)) return; + if (!ru_post_reclaimer(resource_user, false)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_NON_EMPTY_FREE_POOL) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_RECLAIMER_BENIGN)) { - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); } -static void ru_post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, void* ru, - grpc_error* error) { +static void ru_post_destructive_reclaimer(void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; - if (!ru_post_reclaimer(exec_ctx, resource_user, true)) return; + if (!ru_post_reclaimer(resource_user, true)) return; if (!rulist_empty(resource_user->resource_quota, GRPC_RULIST_AWAITING_ALLOCATION) && rulist_empty(resource_user->resource_quota, @@ -508,51 +497,46 @@ static void ru_post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, void* ru, GRPC_RULIST_RECLAIMER_BENIGN) && rulist_empty(resource_user->resource_quota, GRPC_RULIST_RECLAIMER_DESTRUCTIVE)) { - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } rulist_add_tail(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); } -static void ru_shutdown(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { +static void ru_shutdown(void* ru, grpc_error* error) { if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RU shutdown %p", ru); } grpc_resource_user* resource_user = (grpc_resource_user*)ru; - GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[0], - GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], - GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); resource_user->reclaimers[0] = nullptr; resource_user->reclaimers[1] = nullptr; rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); if (resource_user->allocating) { - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } } -static void ru_destroy(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { +static void ru_destroy(void* ru, grpc_error* error) { grpc_resource_user* resource_user = (grpc_resource_user*)ru; GPR_ASSERT(gpr_atm_no_barrier_load(&resource_user->refs) == 0); for (int i = 0; i < GRPC_RULIST_COUNT; i++) { rulist_remove(resource_user, (grpc_rulist)i); } - GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[0], - GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], - GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); if (resource_user->free_pool != 0) { resource_user->resource_quota->free_pool += resource_user->free_pool; - rq_step_sched(exec_ctx, resource_user->resource_quota); + rq_step_sched(resource_user->resource_quota); } - grpc_resource_quota_unref_internal(exec_ctx, resource_user->resource_quota); + grpc_resource_quota_unref_internal(resource_user->resource_quota); gpr_mu_destroy(&resource_user->mu); gpr_free(resource_user->name); gpr_free(resource_user); } -static void ru_allocated_slices(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void ru_allocated_slices(void* arg, grpc_error* error) { grpc_resource_user_slice_allocator* slice_allocator = (grpc_resource_user_slice_allocator*)arg; if (error == GRPC_ERROR_NONE) { @@ -562,7 +546,7 @@ static void ru_allocated_slices(grpc_exec_ctx* exec_ctx, void* arg, slice_allocator->length)); } } - GRPC_CLOSURE_RUN(exec_ctx, &slice_allocator->on_done, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(&slice_allocator->on_done, GRPC_ERROR_REF(error)); } /******************************************************************************* @@ -576,23 +560,22 @@ typedef struct { grpc_closure closure; } rq_resize_args; -static void rq_resize(grpc_exec_ctx* exec_ctx, void* args, grpc_error* error) { +static void rq_resize(void* args, grpc_error* error) { rq_resize_args* a = (rq_resize_args*)args; int64_t delta = a->size - a->resource_quota->size; a->resource_quota->size += delta; a->resource_quota->free_pool += delta; rq_update_estimate(a->resource_quota); - rq_step_sched(exec_ctx, a->resource_quota); - grpc_resource_quota_unref_internal(exec_ctx, a->resource_quota); + rq_step_sched(a->resource_quota); + grpc_resource_quota_unref_internal(a->resource_quota); gpr_free(a); } -static void rq_reclamation_done(grpc_exec_ctx* exec_ctx, void* rq, - grpc_error* error) { +static void rq_reclamation_done(void* rq, grpc_error* error) { grpc_resource_quota* resource_quota = (grpc_resource_quota*)rq; resource_quota->reclaiming = false; - rq_step_sched(exec_ctx, resource_quota); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + rq_step_sched(resource_quota); + grpc_resource_quota_unref_internal(resource_quota); } /******************************************************************************* @@ -628,10 +611,9 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { return resource_quota; } -void grpc_resource_quota_unref_internal(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota) { +void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) { if (gpr_unref(&resource_quota->refs)) { - GRPC_COMBINER_UNREF(exec_ctx, resource_quota->combiner, "resource_quota"); + GRPC_COMBINER_UNREF(resource_quota->combiner, "resource_quota"); gpr_free(resource_quota->name); gpr_free(resource_quota); } @@ -639,9 +621,8 @@ void grpc_resource_quota_unref_internal(grpc_exec_ctx* exec_ctx, /* Public API */ void grpc_resource_quota_unref(grpc_resource_quota* resource_quota) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_quota_unref_internal(resource_quota); } grpc_resource_quota* grpc_resource_quota_ref_internal( @@ -665,15 +646,14 @@ double grpc_resource_quota_get_memory_pressure( /* Public API */ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t size) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; rq_resize_args* a = (rq_resize_args*)gpr_malloc(sizeof(*a)); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota); a->size = (int64_t)size; gpr_atm_no_barrier_store(&resource_quota->last_size, (gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size)); GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&exec_ctx, &a->closure, GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CLOSURE_SCHED(&a->closure, GRPC_ERROR_NONE); } size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) { @@ -704,8 +684,8 @@ static void* rq_copy(void* rq) { return rq; } -static void rq_destroy(grpc_exec_ctx* exec_ctx, void* rq) { - grpc_resource_quota_unref_internal(exec_ctx, (grpc_resource_quota*)rq); +static void rq_destroy(void* rq) { + grpc_resource_quota_unref_internal((grpc_resource_quota*)rq); } static int rq_cmp(void* a, void* b) { return GPR_ICMP(a, b); } @@ -773,14 +753,12 @@ static void ru_ref_by(grpc_resource_user* resource_user, gpr_atm amount) { GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&resource_user->refs, amount) != 0); } -static void ru_unref_by(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, gpr_atm amount) { +static void ru_unref_by(grpc_resource_user* resource_user, gpr_atm amount) { GPR_ASSERT(amount > 0); gpr_atm old = gpr_atm_full_fetch_add(&resource_user->refs, -amount); GPR_ASSERT(old >= amount); if (old == amount) { - GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->destroy_closure, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&resource_user->destroy_closure, GRPC_ERROR_NONE); } } @@ -788,16 +766,13 @@ void grpc_resource_user_ref(grpc_resource_user* resource_user) { ru_ref_by(resource_user, 1); } -void grpc_resource_user_unref(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user) { - ru_unref_by(exec_ctx, resource_user, 1); +void grpc_resource_user_unref(grpc_resource_user* resource_user) { + ru_unref_by(resource_user, 1); } -void grpc_resource_user_shutdown(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user) { +void grpc_resource_user_shutdown(grpc_resource_user* resource_user) { if (gpr_atm_full_fetch_add(&resource_user->shutdown, 1) == 0) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE( ru_shutdown, resource_user, grpc_combiner_scheduler(resource_user->resource_quota->combiner)), @@ -805,8 +780,7 @@ void grpc_resource_user_shutdown(grpc_exec_ctx* exec_ctx, } } -void grpc_resource_user_alloc(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, size_t size, +void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, grpc_closure* optional_on_done) { gpr_mu_lock(&resource_user->mu); ru_ref_by(resource_user, (gpr_atm)size); @@ -822,18 +796,16 @@ void grpc_resource_user_alloc(grpc_exec_ctx* exec_ctx, GRPC_ERROR_NONE); if (!resource_user->allocating) { resource_user->allocating = true; - GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->allocate_closure, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&resource_user->allocate_closure, GRPC_ERROR_NONE); } } else { resource_user->outstanding_allocations -= (int64_t)size; - GRPC_CLOSURE_SCHED(exec_ctx, optional_on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(optional_on_done, GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); } -void grpc_resource_user_free(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, size_t size) { +void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) { gpr_mu_lock(&resource_user->mu); bool was_zero_or_negative = resource_user->free_pool <= 0; resource_user->free_pool += (int64_t)size; @@ -846,32 +818,29 @@ void grpc_resource_user_free(grpc_exec_ctx* exec_ctx, if (is_bigger_than_zero && was_zero_or_negative && !resource_user->added_to_free_pool) { resource_user->added_to_free_pool = true; - GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->add_to_free_pool_closure, + GRPC_CLOSURE_SCHED(&resource_user->add_to_free_pool_closure, GRPC_ERROR_NONE); } gpr_mu_unlock(&resource_user->mu); - ru_unref_by(exec_ctx, resource_user, (gpr_atm)size); + ru_unref_by(resource_user, (gpr_atm)size); } -void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, +void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user, bool destructive, grpc_closure* closure) { GPR_ASSERT(resource_user->new_reclaimers[destructive] == nullptr); resource_user->new_reclaimers[destructive] = closure; - GRPC_CLOSURE_SCHED(exec_ctx, - &resource_user->post_reclaimer_closure[destructive], + GRPC_CLOSURE_SCHED(&resource_user->post_reclaimer_closure[destructive], GRPC_ERROR_NONE); } -void grpc_resource_user_finish_reclamation(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user) { +void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user) { if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RQ %s %s: reclamation complete", resource_user->resource_quota->name, resource_user->name); } GRPC_CLOSURE_SCHED( - exec_ctx, &resource_user->resource_quota->rq_reclamation_done_closure, + &resource_user->resource_quota->rq_reclamation_done_closure, GRPC_ERROR_NONE); } @@ -886,12 +855,11 @@ void grpc_resource_user_slice_allocator_init( } void grpc_resource_user_alloc_slices( - grpc_exec_ctx* exec_ctx, grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest) { slice_allocator->length = length; slice_allocator->count = count; slice_allocator->dest = dest; - grpc_resource_user_alloc(exec_ctx, slice_allocator->resource_user, - count * length, &slice_allocator->on_allocated); + grpc_resource_user_alloc(slice_allocator->resource_user, count * length, + &slice_allocator->on_allocated); } diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 787370307a..39e3aabf18 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -65,8 +65,7 @@ extern grpc_core::TraceFlag grpc_resource_quota_trace; grpc_resource_quota* grpc_resource_quota_ref_internal( grpc_resource_quota* resource_quota); -void grpc_resource_quota_unref_internal(grpc_exec_ctx* exec_ctx, - grpc_resource_quota* resource_quota); +void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota); grpc_resource_quota* grpc_resource_quota_from_channel_args( const grpc_channel_args* channel_args); @@ -89,32 +88,26 @@ grpc_resource_quota* grpc_resource_user_quota( grpc_resource_user* resource_user); void grpc_resource_user_ref(grpc_resource_user* resource_user); -void grpc_resource_user_unref(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user); -void grpc_resource_user_shutdown(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user); +void grpc_resource_user_unref(grpc_resource_user* resource_user); +void grpc_resource_user_shutdown(grpc_resource_user* resource_user); /* Allocate from the resource user (and its quota). If optional_on_done is NULL, then allocate immediately. This may push the quota over-limit, at which point reclamation will kick in. If optional_on_done is non-NULL, it will be scheduled when the allocation has been granted by the quota. */ -void grpc_resource_user_alloc(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, size_t size, +void grpc_resource_user_alloc(grpc_resource_user* resource_user, size_t size, grpc_closure* optional_on_done); /* Release memory back to the quota */ -void grpc_resource_user_free(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, size_t size); +void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size); /* Post a memory reclaimer to the resource user. Only one benign and one destructive reclaimer can be posted at once. When executed, the reclaimer MUST call grpc_resource_user_finish_reclamation before it completes, to return control to the resource quota. */ -void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, +void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user, bool destructive, grpc_closure* closure); /* Finish a reclamation step */ -void grpc_resource_user_finish_reclamation(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user); +void grpc_resource_user_finish_reclamation(grpc_resource_user* resource_user); /* Helper to allocate slices from a resource user */ typedef struct grpc_resource_user_slice_allocator { @@ -141,13 +134,11 @@ void grpc_resource_user_slice_allocator_init( /* Allocate \a count slices of length \a length into \a dest. Only one request can be outstanding at a time. */ void grpc_resource_user_alloc_slices( - grpc_exec_ctx* exec_ctx, grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest); /* Allocate one slice of length \a size synchronously. */ -grpc_slice grpc_resource_user_slice_malloc(grpc_exec_ctx* exec_ctx, - grpc_resource_user* resource_user, +grpc_slice grpc_resource_user_slice_malloc(grpc_resource_user* resource_user, size_t size); #endif /* GRPC_CORE_LIB_IOMGR_RESOURCE_QUOTA_H */ diff --git a/src/core/lib/iomgr/socket_factory_posix.cc b/src/core/lib/iomgr/socket_factory_posix.cc index 40bfecd4c2..bc7d0b12f3 100644 --- a/src/core/lib/iomgr/socket_factory_posix.cc +++ b/src/core/lib/iomgr/socket_factory_posix.cc @@ -72,7 +72,7 @@ static void* socket_factory_arg_copy(void* p) { return grpc_socket_factory_ref((grpc_socket_factory*)p); } -static void socket_factory_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { +static void socket_factory_arg_destroy(void* p) { grpc_socket_factory_unref((grpc_socket_factory*)p); } diff --git a/src/core/lib/iomgr/socket_mutator.cc b/src/core/lib/iomgr/socket_mutator.cc index ff6c0c70d8..9d30e46b6b 100644 --- a/src/core/lib/iomgr/socket_mutator.cc +++ b/src/core/lib/iomgr/socket_mutator.cc @@ -63,7 +63,7 @@ static void* socket_mutator_arg_copy(void* p) { return grpc_socket_mutator_ref((grpc_socket_mutator*)p); } -static void socket_mutator_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { +static void socket_mutator_arg_destroy(void* p) { grpc_socket_mutator_unref((grpc_socket_mutator*)p); } diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index aee80f4b4c..9bb6a75dd8 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -109,37 +109,34 @@ void grpc_winsocket_destroy(grpc_winsocket* winsocket) { -) The IOCP already completed in the background, and we need to call the callback now. -) The IOCP hasn't completed yet, and we're queuing it for later. */ -static void socket_notify_on_iocp(grpc_exec_ctx* exec_ctx, - grpc_winsocket* socket, grpc_closure* closure, +static void socket_notify_on_iocp(grpc_winsocket* socket, grpc_closure* closure, grpc_winsocket_callback_info* info) { GPR_ASSERT(info->closure == NULL); gpr_mu_lock(&socket->state_mu); if (info->has_pending_iocp) { info->has_pending_iocp = 0; - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } else { info->closure = closure; } gpr_mu_unlock(&socket->state_mu); } -void grpc_socket_notify_on_write(grpc_exec_ctx* exec_ctx, - grpc_winsocket* socket, +void grpc_socket_notify_on_write(grpc_winsocket* socket, grpc_closure* closure) { - socket_notify_on_iocp(exec_ctx, socket, closure, &socket->write_info); + socket_notify_on_iocp(socket, closure, &socket->write_info); } -void grpc_socket_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, - grpc_closure* closure) { - socket_notify_on_iocp(exec_ctx, socket, closure, &socket->read_info); +void grpc_socket_notify_on_read(grpc_winsocket* socket, grpc_closure* closure) { + socket_notify_on_iocp(socket, closure, &socket->read_info); } -void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, +void grpc_socket_become_ready(grpc_winsocket* socket, grpc_winsocket_callback_info* info) { GPR_ASSERT(!info->has_pending_iocp); gpr_mu_lock(&socket->state_mu); if (info->closure) { - GRPC_CLOSURE_SCHED(exec_ctx, info->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(info->closure, GRPC_ERROR_NONE); info->closure = NULL; } else { info->has_pending_iocp = 1; diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 04e0a89d70..cb28f2b8df 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -98,16 +98,13 @@ void grpc_winsocket_shutdown(grpc_winsocket* socket); /* Destroy a socket. Should only be called if there's no pending operation. */ void grpc_winsocket_destroy(grpc_winsocket* socket); -void grpc_socket_notify_on_write(grpc_exec_ctx* exec_ctx, - grpc_winsocket* winsocket, +void grpc_socket_notify_on_write(grpc_winsocket* winsocket, grpc_closure* closure); -void grpc_socket_notify_on_read(grpc_exec_ctx* exec_ctx, - grpc_winsocket* winsocket, +void grpc_socket_notify_on_read(grpc_winsocket* winsocket, grpc_closure* closure); -void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx, - grpc_winsocket* winsocket, +void grpc_socket_become_ready(grpc_winsocket* winsocket, grpc_winsocket_callback_info* ci); #endif diff --git a/src/core/lib/iomgr/tcp_client.h b/src/core/lib/iomgr/tcp_client.h index 75e2fe0f36..5f55d30955 100644 --- a/src/core/lib/iomgr/tcp_client.h +++ b/src/core/lib/iomgr/tcp_client.h @@ -30,8 +30,7 @@ NULL on failure). interested_parties points to a set of pollsets that would be interested in this connection being established (in order to continue their work) */ -void grpc_tcp_client_connect(grpc_exec_ctx* exec_ctx, grpc_closure* on_connect, - grpc_endpoint** endpoint, +void grpc_tcp_client_connect(grpc_closure* on_connect, grpc_endpoint** endpoint, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* addr, diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 4cb2ac49d5..15062a52cd 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_tcp_trace.enabled()) { @@ -107,26 +107,24 @@ static void tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { gpr_mu_lock(&ac->mu); if (ac->fd != nullptr) { grpc_fd_shutdown( - exec_ctx, ac->fd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out")); + 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; @@ -150,7 +148,7 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { ac->fd = nullptr; 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) { @@ -172,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 = nullptr; break; case ENOBUFS: @@ -194,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(). */ @@ -209,8 +206,8 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { finish: if (fd != nullptr) { - grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); - grpc_fd_orphan(exec_ctx, fd, nullptr, nullptr, false /* already_closed */, + grpc_pollset_set_del_fd(ac->interested_parties, fd); + grpc_fd_orphan(fd, nullptr, nullptr, false /* already_closed */, "tcp_client_orphan"); fd = nullptr; } @@ -233,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, @@ -265,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) { @@ -274,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 +285,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, nullptr, nullptr, - false /* already_closed */, "tcp_client_connect_error"); - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_OS_ERROR(errno, "connect")); + grpc_fd_orphan(fdobj, nullptr, nullptr, false /* already_closed */, + "tcp_client_connect_error"); + 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 +319,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: @@ -335,19 +330,18 @@ done: // overridden by api_fuzzer.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 diff --git a/src/core/lib/iomgr/tcp_client_posix.h b/src/core/lib/iomgr/tcp_client_posix.h index 2b1fe79e90..7d0f133a6b 100644 --- a/src/core/lib/iomgr/tcp_client_posix.h +++ b/src/core/lib/iomgr/tcp_client_posix.h @@ -24,7 +24,6 @@ #include "src/core/lib/iomgr/tcp_client.h" 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); + grpc_fd* fd, const grpc_channel_args* channel_args, const char* addr_str); #endif /* GRPC_CORE_LIB_IOMGR_TCP_CLIENT_POSIX_H */ diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 5cca0c9936..4e9c7cc11d 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -46,17 +46,15 @@ typedef struct grpc_uv_tcp_connect { grpc_resource_quota* resource_quota; } grpc_uv_tcp_connect; -static void uv_tcp_connect_cleanup(grpc_exec_ctx* exec_ctx, - grpc_uv_tcp_connect* connect) { - grpc_resource_quota_unref_internal(exec_ctx, connect->resource_quota); +static void uv_tcp_connect_cleanup(grpc_uv_tcp_connect* connect) { + grpc_resource_quota_unref_internal(connect->resource_quota); gpr_free(connect->addr_name); gpr_free(connect); } static void tcp_close_callback(uv_handle_t* handle) { gpr_free(handle); } -static void uv_tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, - grpc_error* error) { +static void uv_tc_on_alarm(void* acp, grpc_error* error) { int done; grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)acp; if (grpc_tcp_trace.enabled()) { @@ -72,17 +70,17 @@ static void uv_tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, } done = (--connect->refs == 0); if (done) { - uv_tcp_connect_cleanup(exec_ctx, connect); + uv_tcp_connect_cleanup(connect); } } static void uv_tc_on_connect(uv_connect_t* req, int status) { grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_error* error = GRPC_ERROR_NONE; int done; grpc_closure* closure = connect->closure; - grpc_timer_cancel(&exec_ctx, &connect->alarm); + grpc_timer_cancel(&connect->alarm); if (status == 0) { *connect->endpoint = grpc_tcp_create( connect->tcp_handle, connect->resource_quota, connect->addr_name); @@ -107,15 +105,13 @@ static void uv_tc_on_connect(uv_connect_t* req, int status) { } done = (--connect->refs == 0); if (done) { - grpc_exec_ctx_flush(&exec_ctx); - uv_tcp_connect_cleanup(&exec_ctx, connect); + grpc_core::ExecCtx::Get()->Flush(); + uv_tcp_connect_cleanup(connect); } - GRPC_CLOSURE_SCHED(&exec_ctx, closure, error); - grpc_exec_ctx_finish(&exec_ctx); + 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* resolved_addr, @@ -130,7 +126,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, if (channel_args != NULL) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -157,24 +153,23 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, (const struct sockaddr*)resolved_addr->addr, uv_tc_on_connect); GRPC_CLOSURE_INIT(&connect->on_alarm, uv_tc_on_alarm, connect, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &connect->alarm, deadline, &connect->on_alarm); + grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); } // overridden by api_fuzzer.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 /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 5e30725e90..5521a0a9ae 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -52,13 +52,12 @@ typedef struct { grpc_channel_args* channel_args; } async_connect; -static void async_connect_unlock_and_cleanup(grpc_exec_ctx* exec_ctx, - async_connect* ac, +static void async_connect_unlock_and_cleanup(async_connect* ac, grpc_winsocket* socket) { int done = (--ac->refs == 0); gpr_mu_unlock(&ac->mu); if (done) { - grpc_channel_args_destroy(exec_ctx, ac->channel_args); + grpc_channel_args_destroy(ac->channel_args); gpr_mu_destroy(&ac->mu); gpr_free(ac->addr_name); gpr_free(ac); @@ -66,7 +65,7 @@ static void async_connect_unlock_and_cleanup(grpc_exec_ctx* exec_ctx, if (socket != NULL) grpc_winsocket_destroy(socket); } -static void on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { +static void on_alarm(void* acp, grpc_error* error) { async_connect* ac = (async_connect*)acp; gpr_mu_lock(&ac->mu); grpc_winsocket* socket = ac->socket; @@ -74,10 +73,10 @@ static void on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { if (socket != NULL) { grpc_winsocket_shutdown(socket); } - async_connect_unlock_and_cleanup(exec_ctx, ac, socket); + async_connect_unlock_and_cleanup(ac, socket); } -static void on_connect(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { +static void on_connect(void* acp, grpc_error* error) { async_connect* ac = (async_connect*)acp; grpc_endpoint** ep = ac->endpoint; GPR_ASSERT(*ep == NULL); @@ -90,7 +89,7 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { ac->socket = NULL; gpr_mu_unlock(&ac->mu); - grpc_timer_cancel(exec_ctx, &ac->alarm); + grpc_timer_cancel(&ac->alarm); gpr_mu_lock(&ac->mu); @@ -105,8 +104,7 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { if (!wsa_success) { error = GRPC_WSA_ERROR(WSAGetLastError(), "ConnectEx"); } else { - *ep = - grpc_tcp_create(exec_ctx, socket, ac->channel_args, ac->addr_name); + *ep = grpc_tcp_create(socket, ac->channel_args, ac->addr_name); socket = NULL; } } else { @@ -114,18 +112,20 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { } } - async_connect_unlock_and_cleanup(exec_ctx, ac, socket); + async_connect_unlock_and_cleanup(ac, socket); /* If the connection was aborted, the callback was already called when the deadline was met. */ - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); } /* Tries to issue one async connection, then schedules both an IOCP notification request for the connection, and one timeout alert. */ -static void tcp_client_connect_impl( - grpc_exec_ctx* exec_ctx, grpc_closure* on_done, grpc_endpoint** endpoint, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, grpc_millis deadline) { +static void tcp_client_connect_impl(grpc_closure* on_done, + grpc_endpoint** endpoint, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { SOCKET sock = INVALID_SOCKET; BOOL success; int status; @@ -205,8 +205,8 @@ static void tcp_client_connect_impl( GRPC_CLOSURE_INIT(&ac->on_connect, on_connect, ac, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&ac->on_alarm, on_alarm, ac, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &ac->alarm, deadline, &ac->on_alarm); - grpc_socket_notify_on_write(exec_ctx, socket, &ac->on_connect); + grpc_timer_init(&ac->alarm, deadline, &ac->on_alarm); + grpc_socket_notify_on_write(socket, &ac->on_connect); return; failure: @@ -222,24 +222,23 @@ failure: } else if (sock != INVALID_SOCKET) { closesocket(sock); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, final_error); + GRPC_CLOSURE_SCHED(on_done, final_error); } // overridden by api_fuzzer.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 /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index d09cfca9af..155329d2e8 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -108,36 +108,31 @@ typedef struct backup_poller { static gpr_atm g_uncovered_notifications_pending; static gpr_atm g_backup_poller; /* backup_poller* */ -static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error); -static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error); -static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx* exec_ctx, - void* arg /* grpc_tcp */, +static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error); +static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error); +static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */, grpc_error* error); -static void done_poller(grpc_exec_ctx* exec_ctx, void* bp, - grpc_error* error_ignored) { +static void done_poller(void* bp, grpc_error* error_ignored) { backup_poller* p = (backup_poller*)bp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); } - grpc_pollset_destroy(exec_ctx, BACKUP_POLLER_POLLSET(p)); + grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p)); gpr_free(p); } -static void run_poller(grpc_exec_ctx* exec_ctx, void* bp, - grpc_error* error_ignored) { +static void run_poller(void* bp, grpc_error* error_ignored) { backup_poller* p = (backup_poller*)bp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); } gpr_mu_lock(p->pollset_mu); - grpc_millis deadline = grpc_exec_ctx_now(exec_ctx) + 13 * GPR_MS_PER_SEC; - GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx); + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 13 * GPR_MS_PER_SEC; + GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", - grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), nullptr, deadline)); + grpc_pollset_work(BACKUP_POLLER_POLLSET(p), nullptr, deadline)); gpr_mu_unlock(p->pollset_mu); /* last "uncovered" notification is the ref that keeps us polling, if we get * there try a cas to release it */ @@ -152,18 +147,18 @@ static void run_poller(grpc_exec_ctx* exec_ctx, void* bp, if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p); } - grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p), + grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p), GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, grpc_schedule_on_exec_ctx)); } else { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); } - GRPC_CLOSURE_SCHED(exec_ctx, &p->run_poller, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&p->run_poller, GRPC_ERROR_NONE); } } -static void drop_uncovered(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void drop_uncovered(grpc_tcp* tcp) { backup_poller* p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller); gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); @@ -174,7 +169,7 @@ static void drop_uncovered(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { GPR_ASSERT(old_count != 1); } -static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void cover_self(grpc_tcp* tcp) { backup_poller* p; gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); @@ -183,7 +178,7 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { 2 + (int)old_count); } if (old_count == 0) { - GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx); + GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(); p = (backup_poller*)gpr_zalloc(sizeof(*p) + grpc_pollset_size()); if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); @@ -191,7 +186,6 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); gpr_atm_rel_store(&g_backup_poller, (gpr_atm)p); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)), GRPC_ERROR_NONE); @@ -204,39 +198,38 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); } - grpc_pollset_add_fd(exec_ctx, BACKUP_POLLER_POLLSET(p), tcp->em_fd); + grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd); if (old_count != 0) { - drop_uncovered(exec_ctx, tcp); + drop_uncovered(tcp); } } -static void notify_on_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void notify_on_read(grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp); } GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_done_closure); + grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure); } -static void notify_on_write(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void notify_on_write(grpc_tcp* tcp) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp); } - cover_self(exec_ctx, tcp); + cover_self(tcp); GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_drop_uncovered_then_handle_write, tcp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_write(exec_ctx, tcp->em_fd, &tcp->write_done_closure); + grpc_fd_notify_on_write(tcp->em_fd, &tcp->write_done_closure); } -static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error* error) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); } - drop_uncovered(exec_ctx, (grpc_tcp*)arg); - tcp_handle_write(exec_ctx, arg, error); + drop_uncovered((grpc_tcp*)arg); + tcp_handle_write(arg, error); } static void add_to_estimate(grpc_tcp* tcp, size_t bytes) { @@ -282,33 +275,29 @@ static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) { grpc_slice_from_copied_string(tcp->peer_string)); } -static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error); -static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error); +static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error); +static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error); -static void tcp_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void tcp_shutdown(grpc_endpoint* ep, grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_fd_shutdown(exec_ctx, tcp->em_fd, why); - grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); + grpc_fd_shutdown(tcp->em_fd, why); + grpc_resource_user_shutdown(tcp->resource_user); } -static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { - grpc_fd_orphan(exec_ctx, tcp->em_fd, tcp->release_fd_cb, tcp->release_fd, +static void tcp_free(grpc_tcp* tcp) { + grpc_fd_orphan(tcp->em_fd, tcp->release_fd_cb, tcp->release_fd, false /* already_closed */, "tcp_unref_orphan"); - grpc_slice_buffer_destroy_internal(exec_ctx, &tcp->last_read_buffer); - grpc_resource_user_unref(exec_ctx, tcp->resource_user); + grpc_slice_buffer_destroy_internal(&tcp->last_read_buffer); + grpc_resource_user_unref(tcp->resource_user); gpr_free(tcp->peer_string); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(cl, tcp, reason) \ - tcp_unref((cl), (tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - const char* reason, const char* file, int line) { +static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, + int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -316,7 +305,7 @@ static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } @@ -331,26 +320,25 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(cl, tcp, reason) tcp_unref((cl), (tcp)) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_unref(grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif -static void tcp_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void tcp_destroy(grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer); - TCP_UNREF(exec_ctx, tcp, "destroy"); + grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); + TCP_UNREF(tcp, "destroy"); } -static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - grpc_error* error) { +static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { grpc_closure* cb = tcp->read_cb; if (grpc_tcp_trace.enabled()) { @@ -369,11 +357,11 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, tcp->read_cb = nullptr; tcp->incoming_buffer = nullptr; - GRPC_CLOSURE_RUN(exec_ctx, cb, error); + GRPC_CLOSURE_RUN(cb, error); } #define MAX_READ_IOVEC 4 -static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_do_read(grpc_tcp* tcp) { struct msghdr msg; struct iovec iov[MAX_READ_IOVEC]; ssize_t read_bytes; @@ -396,12 +384,12 @@ static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { msg.msg_controllen = 0; msg.msg_flags = 0; - GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, tcp->incoming_buffer->length); - GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(exec_ctx, tcp->incoming_buffer->count); + GRPC_STATS_INC_TCP_READ_OFFER(tcp->incoming_buffer->length); + GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(tcp->incoming_buffer->count); GPR_TIMER_BEGIN("recvmsg", 0); do { - GRPC_STATS_INC_SYSCALL_READ(exec_ctx); + GRPC_STATS_INC_SYSCALL_READ(); read_bytes = recvmsg(tcp->fd, &msg, 0); } while (read_bytes < 0 && errno == EINTR); GPR_TIMER_END("recvmsg", read_bytes >= 0); @@ -412,24 +400,22 @@ static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { if (errno == EAGAIN) { finish_estimate(tcp); /* We've consumed the edge, request a new one */ - notify_on_read(exec_ctx, tcp); + notify_on_read(tcp); } else { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - tcp->incoming_buffer); - call_read_cb(exec_ctx, tcp, + grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); + call_read_cb(tcp, tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp)); - TCP_UNREF(exec_ctx, tcp, "read"); + TCP_UNREF(tcp, "read"); } } else if (read_bytes == 0) { /* 0 read size ==> end of stream */ - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); call_read_cb( - exec_ctx, tcp, - tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp)); - TCP_UNREF(exec_ctx, tcp, "read"); + tcp, tcp_annotate_error( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp)); + TCP_UNREF(tcp, "read"); } else { - GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, read_bytes); + GRPC_STATS_INC_TCP_READ_SIZE(read_bytes); add_to_estimate(tcp, (size_t)read_bytes); GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length); if ((size_t)read_bytes < tcp->incoming_buffer->length) { @@ -439,50 +425,47 @@ static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { &tcp->last_read_buffer); } GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length); - call_read_cb(exec_ctx, tcp, GRPC_ERROR_NONE); - TCP_UNREF(exec_ctx, tcp, "read"); + call_read_cb(tcp, GRPC_ERROR_NONE); + TCP_UNREF(tcp, "read"); } GPR_TIMER_END("tcp_continue_read", 0); } -static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, - grpc_error* error) { +static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, grpc_error_string(error)); } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - &tcp->last_read_buffer); - call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(exec_ctx, tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); + call_read_cb(tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(tcp, "read"); } else { - tcp_do_read(exec_ctx, tcp); + tcp_do_read(tcp); } } -static void tcp_continue_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_continue_read(grpc_tcp* tcp) { size_t target_read_size = get_target_read_size(tcp); if (tcp->incoming_buffer->length < target_read_size && tcp->incoming_buffer->count < MAX_READ_IOVEC) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp); } - grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, - target_read_size, 1, tcp->incoming_buffer); + grpc_resource_user_alloc_slices(&tcp->slice_allocator, target_read_size, 1, + tcp->incoming_buffer); } else { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp); } - tcp_do_read(exec_ctx, tcp); + tcp_do_read(tcp); } } -static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error) { +static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)arg; GPR_ASSERT(!tcp->finished_edge); if (grpc_tcp_trace.enabled()) { @@ -490,37 +473,35 @@ static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - &tcp->last_read_buffer); - call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(exec_ctx, tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); + call_read_cb(tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(tcp, "read"); } else { - tcp_continue_read(exec_ctx, tcp); + tcp_continue_read(tcp); } } -static void tcp_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* incoming_buffer, grpc_closure* cb) { +static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, + grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; tcp->incoming_buffer = incoming_buffer; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, incoming_buffer); + grpc_slice_buffer_reset_and_unref_internal(incoming_buffer); grpc_slice_buffer_swap(incoming_buffer, &tcp->last_read_buffer); TCP_REF(tcp, "read"); if (tcp->finished_edge) { tcp->finished_edge = false; - notify_on_read(exec_ctx, tcp); + notify_on_read(tcp); } else { - GRPC_CLOSURE_SCHED(exec_ctx, &tcp->read_done_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&tcp->read_done_closure, GRPC_ERROR_NONE); } } /* returns true if done, false if pending; if returning true, *error is set */ #define MAX_WRITE_IOVEC 1000 -static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - grpc_error** error) { +static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; msg_iovlen_type iov_size; @@ -562,13 +543,13 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, msg.msg_controllen = 0; msg.msg_flags = 0; - GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, sending_length); - GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, iov_size); + GRPC_STATS_INC_TCP_WRITE_SIZE(sending_length); + GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(iov_size); GPR_TIMER_BEGIN("sendmsg", 1); do { /* TODO(klempner): Cork if this is a partial write */ - GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx); + GRPC_STATS_INC_SYSCALL_WRITE(); sent_length = sendmsg(tcp->fd, &msg, SENDMSG_FLAGS); } while (sent_length < 0 && errno == EINTR); GPR_TIMER_END("sendmsg", 0); @@ -580,20 +561,18 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, // point for (size_t idx = 0; idx < unwind_slice_idx; ++idx) { grpc_slice_unref_internal( - exec_ctx, grpc_slice_buffer_take_first(tcp->outgoing_buffer)); + grpc_slice_buffer_take_first(tcp->outgoing_buffer)); } return false; } else if (errno == EPIPE) { *error = grpc_error_set_int(GRPC_OS_ERROR(errno, "sendmsg"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); return true; } else { *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "sendmsg"), tcp); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); return true; } } @@ -616,31 +595,29 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, if (outgoing_slice_idx == tcp->outgoing_buffer->count) { *error = GRPC_ERROR_NONE; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, - tcp->outgoing_buffer); + grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer); return true; } } } -static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, - grpc_error* error) { +static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)arg; grpc_closure* cb; if (error != GRPC_ERROR_NONE) { cb = tcp->write_cb; tcp->write_cb = nullptr; - cb->cb(exec_ctx, cb->cb_arg, error); - TCP_UNREF(exec_ctx, tcp, "write"); + cb->cb(cb->cb_arg, error); + TCP_UNREF(tcp, "write"); return; } - if (!tcp_flush(exec_ctx, tcp, &error)) { + if (!tcp_flush(tcp, &error)) { if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } - notify_on_write(exec_ctx, tcp); + notify_on_write(tcp); } else { cb = tcp->write_cb; tcp->write_cb = nullptr; @@ -649,13 +626,13 @@ static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, gpr_log(GPR_DEBUG, "write: %s", str); } - GRPC_CLOSURE_RUN(exec_ctx, cb, error); - TCP_UNREF(exec_ctx, tcp, "write"); + GRPC_CLOSURE_RUN(cb, error); + TCP_UNREF(tcp, "write"); } } -static void tcp_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* buf, grpc_closure* cb) { +static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf, + grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_error* error = GRPC_ERROR_NONE; @@ -676,51 +653,48 @@ static void tcp_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, if (buf->length == 0) { GPR_TIMER_END("tcp_write", 0); GRPC_CLOSURE_SCHED( - exec_ctx, cb, - grpc_fd_is_shutdown(tcp->em_fd) - ? tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), - tcp) - : GRPC_ERROR_NONE); + cb, grpc_fd_is_shutdown(tcp->em_fd) + ? tcp_annotate_error( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp) + : GRPC_ERROR_NONE); return; } tcp->outgoing_buffer = buf; tcp->outgoing_byte_idx = 0; - if (!tcp_flush(exec_ctx, tcp, &error)) { + if (!tcp_flush(tcp, &error)) { TCP_REF(tcp, "write"); tcp->write_cb = cb; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } - notify_on_write(exec_ctx, tcp); + notify_on_write(tcp); } else { if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); } - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + GRPC_CLOSURE_SCHED(cb, error); } GPR_TIMER_END("tcp_write", 0); } -static void tcp_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) { +static void tcp_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_add_fd(exec_ctx, pollset, tcp->em_fd); + grpc_pollset_add_fd(pollset, tcp->em_fd); } -static void tcp_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void tcp_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_set_add_fd(exec_ctx, pollset_set, tcp->em_fd); + grpc_pollset_set_add_fd(pollset_set, tcp->em_fd); } -static void tcp_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void tcp_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { grpc_tcp* tcp = (grpc_tcp*)ep; - grpc_pollset_set_del_fd(exec_ctx, pollset_set, tcp->em_fd); + grpc_pollset_set_del_fd(pollset_set, tcp->em_fd); } static char* tcp_get_peer(grpc_endpoint* ep) { @@ -751,7 +725,7 @@ static const grpc_endpoint_vtable vtable = {tcp_read, #define MAX_CHUNK_SIZE 32 * 1024 * 1024 -grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, +grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd, const grpc_channel_args* channel_args, const char* peer_string) { int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE; @@ -780,7 +754,7 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, grpc_channel_arg_get_integer(&channel_args->args[i], options); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -817,7 +791,7 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); /* Tell network status tracker about new endpoint */ grpc_network_status_register_endpoint(&tcp->base); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); return &tcp->base; } @@ -828,15 +802,15 @@ int grpc_tcp_fd(grpc_endpoint* ep) { return grpc_fd_wrapped_fd(tcp->em_fd); } -void grpc_tcp_destroy_and_release_fd(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - int* fd, grpc_closure* done) { +void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, + grpc_closure* done) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; GPR_ASSERT(ep->vtable == &vtable); tcp->release_fd = fd; tcp->release_fd_cb = done; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer); - TCP_UNREF(exec_ctx, tcp, "destroy"); + grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer); + TCP_UNREF(tcp, "destroy"); } #endif diff --git a/src/core/lib/iomgr/tcp_posix.h b/src/core/lib/iomgr/tcp_posix.h index 09051b7ed6..4529c02beb 100644 --- a/src/core/lib/iomgr/tcp_posix.h +++ b/src/core/lib/iomgr/tcp_posix.h @@ -37,8 +37,7 @@ extern grpc_core::TraceFlag grpc_tcp_trace; /* Create a tcp endpoint given a file desciptor and a read slice size. Takes ownership of fd. */ -grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - const grpc_channel_args* args, +grpc_endpoint* grpc_tcp_create(grpc_fd* fd, const grpc_channel_args* args, const char* peer_string); /* Return the tcp endpoint's fd, or -1 if this is not available. Does not @@ -50,7 +49,7 @@ int grpc_tcp_fd(grpc_endpoint* ep); /* Destroy the tcp endpoint without closing its fd. *fd will be set and done * will be called when the endpoint is destroyed. * Requires: ep must be a tcp endpoint and fd must not be NULL. */ -void grpc_tcp_destroy_and_release_fd(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - int* fd, grpc_closure* done); +void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd, + grpc_closure* done); #endif /* GRPC_CORE_LIB_IOMGR_TCP_POSIX_H */ diff --git a/src/core/lib/iomgr/tcp_server.h b/src/core/lib/iomgr/tcp_server.h index a1757a2b3e..038c765c6c 100644 --- a/src/core/lib/iomgr/tcp_server.h +++ b/src/core/lib/iomgr/tcp_server.h @@ -39,22 +39,20 @@ typedef struct grpc_tcp_server_acceptor { /* Called for newly connected TCP connections. Takes ownership of acceptor. */ -typedef void (*grpc_tcp_server_cb)(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* ep, +typedef void (*grpc_tcp_server_cb)(void* arg, grpc_endpoint* ep, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor); /* Create a server, initially not bound to any ports. The caller owns one ref. If shutdown_complete is not NULL, it will be used by grpc_tcp_server_unref() when the ref count reaches zero. */ -grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, - grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server); /* Start listening to bound ports */ -void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* server, - grpc_pollset** pollsets, size_t pollset_count, +void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* cb_arg); /* Add a port to the server, returning the newly allocated port on success, or @@ -92,10 +90,9 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, /* If the refcount drops to zero, enqueue calls on exec_ctx to shutdown_listeners and delete s. */ -void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s); +void grpc_tcp_server_unref(grpc_tcp_server* s); /* Shutdown the fds of listeners. */ -void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, - grpc_tcp_server* s); +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s); #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_H */ diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 6fed13c6c7..99e1c6cd06 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -68,8 +68,7 @@ static void init(void) { #endif } -grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, - grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { gpr_once_init(&check_init, init); @@ -116,12 +115,12 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void finish_shutdown(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); GPR_ASSERT(s->shutdown); gpr_mu_unlock(&s->mu); if (s->shutdown_complete != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); } gpr_mu_destroy(&s->mu); @@ -131,19 +130,18 @@ static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { s->head = sp->next; gpr_free(sp); } - grpc_channel_args_destroy(exec_ctx, s->channel_args); + grpc_channel_args_destroy(s->channel_args); gpr_free(s); } -static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, - grpc_error* error) { +static void destroyed_port(void* server, grpc_error* error) { grpc_tcp_server* s = (grpc_tcp_server*)server; gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { gpr_mu_unlock(&s->mu); - finish_shutdown(exec_ctx, s); + finish_shutdown(s); } else { GPR_ASSERT(s->destroyed_ports < s->nports); gpr_mu_unlock(&s->mu); @@ -153,7 +151,7 @@ static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, /* called when all listening endpoints have been shutdown, so no further events will be received on them - at this point it's safe to destroy things */ -static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void deactivated_all_ports(grpc_tcp_server* s) { /* delete ALL the things */ gpr_mu_lock(&s->mu); @@ -165,17 +163,17 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { grpc_unlink_if_unix_domain_socket(&sp->addr); GRPC_CLOSURE_INIT(&sp->destroyed_closure, destroyed_port, s, grpc_schedule_on_exec_ctx); - grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, + grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "tcp_listener_shutdown"); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - finish_shutdown(exec_ctx, s); + finish_shutdown(s); } } -static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); GPR_ASSERT(!s->shutdown); @@ -186,18 +184,17 @@ static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { grpc_tcp_listener* sp; for (sp = s->head; sp; sp = sp->next) { grpc_fd_shutdown( - exec_ctx, sp->emfd, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server destroyed")); + sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server destroyed")); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - deactivated_all_ports(exec_ctx, s); + deactivated_all_ports(s); } } /* event manager callback when reads are ready */ -static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* err) { +static void on_read(void* arg, grpc_error* err) { grpc_tcp_listener* sp = (grpc_tcp_listener*)arg; grpc_pollset* read_notifier_pollset; if (err != GRPC_ERROR_NONE) { @@ -223,7 +220,7 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* err) { case EINTR: continue; case EAGAIN: - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); return; default: gpr_mu_lock(&sp->server->mu); @@ -249,7 +246,7 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* err) { grpc_fd* fdobj = grpc_fd_create(fd, name); - grpc_pollset_add_fd(exec_ctx, read_notifier_pollset, fdobj); + grpc_pollset_add_fd(read_notifier_pollset, fdobj); // Create acceptor. grpc_tcp_server_acceptor* acceptor = @@ -259,8 +256,8 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* err) { acceptor->fd_index = sp->fd_index; sp->server->on_accept_cb( - exec_ctx, sp->server->on_accept_cb_arg, - grpc_tcp_create(exec_ctx, fdobj, sp->server->channel_args, addr_str), + sp->server->on_accept_cb_arg, + grpc_tcp_create(fdobj, sp->server->channel_args, addr_str), read_notifier_pollset, acceptor); gpr_free(name); @@ -273,7 +270,7 @@ error: gpr_mu_lock(&sp->server->mu); if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(exec_ctx, sp->server); + deactivated_all_ports(sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -483,8 +480,8 @@ int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, return -1; } -void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, - grpc_pollset** pollsets, size_t pollset_count, +void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* on_accept_cb_arg) { size_t i; @@ -504,20 +501,20 @@ void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, GPR_ASSERT(GRPC_LOG_IF_ERROR( "clone_port", clone_port(sp, (unsigned)(pollset_count - 1)))); for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); + grpc_pollset_add_fd(pollsets[i], sp->emfd); GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); s->active_ports++; sp = sp->next; } } else { for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); + grpc_pollset_add_fd(pollsets[i], sp->emfd); } GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); s->active_ports++; sp = sp->next; } @@ -538,25 +535,24 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { - grpc_tcp_server_shutdown_listeners(exec_ctx, s); + grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &s->shutdown_starting); + GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); gpr_mu_unlock(&s->mu); - tcp_server_destroy(exec_ctx, s); + tcp_server_destroy(s); } } -void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, - grpc_tcp_server* s) { +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); s->shutdown_listeners = true; /* shutdown all fd's */ if (s->active_ports) { grpc_tcp_listener* sp; for (sp = s->head; sp; sp = sp->next) { - grpc_fd_shutdown(exec_ctx, sp->emfd, + grpc_fd_shutdown(sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown")); } } diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index ffadf0b1ab..1ac49190fb 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -73,8 +73,7 @@ struct grpc_tcp_server { grpc_resource_quota* resource_quota; }; -grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, - grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); @@ -82,11 +81,11 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { if (args->args[i].type == GRPC_ARG_POINTER) { - grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); + grpc_resource_quota_unref_internal(s->resource_quota); s->resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)args->args[i].value.pointer.p); } else { - grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); + grpc_resource_quota_unref_internal(s->resource_quota); gpr_free(s); return GRPC_ERROR_CREATE_FROM_STATIC_STRING( GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); @@ -119,10 +118,10 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, GRPC_ERROR_NONE); } -static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void finish_shutdown(grpc_tcp_server* s) { GPR_ASSERT(s->shutdown); if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); } while (s->head) { @@ -132,18 +131,17 @@ static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { gpr_free(sp->handle); gpr_free(sp); } - grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota); + grpc_resource_quota_unref_internal(s->resource_quota); gpr_free(s); } static void handle_close_callback(uv_handle_t* handle) { grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; sp->server->open_ports--; if (sp->server->open_ports == 0 && sp->server->shutdown) { - finish_shutdown(&exec_ctx, sp->server); + finish_shutdown(sp->server); } - grpc_exec_ctx_finish(&exec_ctx); } static void close_listener(grpc_tcp_listener* sp) { @@ -153,7 +151,7 @@ static void close_listener(grpc_tcp_listener* sp) { } } -static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_tcp_server* s) { int immediately_done = 0; grpc_tcp_listener* sp; @@ -168,28 +166,22 @@ static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { } if (immediately_done) { - finish_shutdown(exec_ctx, s); + finish_shutdown(s); } } -void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); if (gpr_unref(&s->refs)) { /* Complete shutdown_starting work before destroying. */ - grpc_exec_ctx local_exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_LIST_SCHED(&local_exec_ctx, &s->shutdown_starting); - if (exec_ctx == NULL) { - grpc_exec_ctx_flush(&local_exec_ctx); - tcp_server_destroy(&local_exec_ctx, s); - grpc_exec_ctx_finish(&local_exec_ctx); - } else { - grpc_exec_ctx_finish(&local_exec_ctx); - tcp_server_destroy(exec_ctx, s); - } + grpc_core::ExecCtx exec_ctx; + GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); + grpc_core::ExecCtx::Get()->Flush(); + tcp_server_destroy(s); } } -static void finish_accept(grpc_exec_ctx* exec_ctx, grpc_tcp_listener* sp) { +static void finish_accept(grpc_tcp_listener* sp) { grpc_tcp_server_acceptor* acceptor = (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); uv_tcp_t* client = NULL; @@ -225,14 +217,13 @@ static void finish_accept(grpc_exec_ctx* exec_ctx, grpc_tcp_listener* sp) { acceptor->from_server = sp->server; acceptor->port_index = sp->port_index; acceptor->fd_index = 0; - sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep, NULL, - acceptor); + sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); gpr_free(peer_name_string); } static void on_connect(uv_stream_t* server, int status) { grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; if (status < 0) { switch (status) { @@ -253,11 +244,10 @@ static void on_connect(uv_stream_t* server, int status) { // Create acceptor. if (sp->server->on_accept_cb) { - finish_accept(&exec_ctx, sp); + finish_accept(sp); } else { sp->has_pending_connection = true; } - grpc_exec_ctx_finish(&exec_ctx); } static grpc_error* add_addr_to_server(grpc_tcp_server* s, @@ -454,8 +444,8 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, return error; } -void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* server, - grpc_pollset** pollsets, size_t pollset_count, +void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* cb_arg) { grpc_tcp_listener* sp; (void)pollsets; @@ -470,13 +460,12 @@ void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* server, server->on_accept_cb_arg = cb_arg; for (sp = server->head; sp; sp = sp->next) { if (sp->has_pending_connection) { - finish_accept(exec_ctx, sp); + finish_accept(sp); sp->has_pending_connection = false; } } } -void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, - grpc_tcp_server* s) {} +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index f538194895..8a30dfde43 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -94,8 +94,7 @@ struct grpc_tcp_server { /* Public function. Allocates the proper data structures to hold a grpc_tcp_server. */ -grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, - grpc_closure* shutdown_complete, +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, const grpc_channel_args* args, grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); @@ -114,8 +113,7 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void destroy_server(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_server(void* arg, grpc_error* error) { grpc_tcp_server* s = (grpc_tcp_server*)arg; /* Now that the accepts have been aborted, we can destroy the sockets. @@ -128,18 +126,16 @@ static void destroy_server(grpc_exec_ctx* exec_ctx, void* arg, grpc_winsocket_destroy(sp->socket); gpr_free(sp); } - grpc_channel_args_destroy(exec_ctx, s->channel_args); + grpc_channel_args_destroy(s->channel_args); gpr_free(s); } -static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx, - grpc_tcp_server* s) { +static void finish_shutdown_locked(grpc_tcp_server* s) { if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); } GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(destroy_server, s, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } @@ -157,14 +153,14 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, gpr_mu_unlock(&s->mu); } -static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +static void tcp_server_destroy(grpc_tcp_server* s) { grpc_tcp_listener* sp; gpr_mu_lock(&s->mu); /* First, shutdown all fd's. This will queue abortion calls for all of the pending accepts due to the normal operation mechanism. */ if (s->active_ports == 0) { - finish_shutdown_locked(exec_ctx, s); + finish_shutdown_locked(s); } else { for (sp = s->head; sp; sp = sp->next) { sp->shutting_down = 1; @@ -174,13 +170,13 @@ static void tcp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { +void grpc_tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { - grpc_tcp_server_shutdown_listeners(exec_ctx, s); + grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); - GRPC_CLOSURE_LIST_SCHED(exec_ctx, &s->shutdown_starting); + GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); gpr_mu_unlock(&s->mu); - tcp_server_destroy(exec_ctx, s); + tcp_server_destroy(s); } } @@ -234,19 +230,17 @@ failure: return error; } -static void decrement_active_ports_and_notify_locked(grpc_exec_ctx* exec_ctx, - grpc_tcp_listener* sp) { +static void decrement_active_ports_and_notify_locked(grpc_tcp_listener* sp) { sp->shutting_down = 0; GPR_ASSERT(sp->server->active_ports > 0); if (0 == --sp->server->active_ports) { - finish_shutdown_locked(exec_ctx, sp->server); + finish_shutdown_locked(sp->server); } } /* In order to do an async accept, we need to create a socket first which will be the one assigned to the new incoming connection. */ -static grpc_error* start_accept_locked(grpc_exec_ctx* exec_ctx, - grpc_tcp_listener* port) { +static grpc_error* start_accept_locked(grpc_tcp_listener* port) { SOCKET sock = INVALID_SOCKET; BOOL success; DWORD addrlen = sizeof(struct sockaddr_in6) + 16; @@ -285,7 +279,7 @@ static grpc_error* start_accept_locked(grpc_exec_ctx* exec_ctx, /* We're ready to do the accept. Calling grpc_socket_notify_on_read may immediately process an accept that happened in the meantime. */ port->new_socket = sock; - grpc_socket_notify_on_read(exec_ctx, port->socket, &port->on_accept); + grpc_socket_notify_on_read(port->socket, &port->on_accept); port->outstanding_calls++; return error; @@ -296,7 +290,7 @@ failure: } /* Event manager callback when reads are ready. */ -static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_accept(void* arg, grpc_error* error) { grpc_tcp_listener* sp = (grpc_tcp_listener*)arg; SOCKET sock = sp->new_socket; grpc_winsocket_callback_info* info = &sp->socket->read_info; @@ -357,7 +351,7 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { gpr_free(utf8_message); } gpr_asprintf(&fd_name, "tcp_server:%s", peer_name_string); - ep = grpc_tcp_create(exec_ctx, grpc_winsocket_create(sock, fd_name), + ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name), sp->server->channel_args, peer_name_string); gpr_free(fd_name); gpr_free(peer_name_string); @@ -375,17 +369,15 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { acceptor->from_server = sp->server; acceptor->port_index = sp->port_index; acceptor->fd_index = 0; - sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep, NULL, - acceptor); + sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); } /* As we were notified from the IOCP of one and exactly one accept, the former socked we created has now either been destroy or assigned to the new connection. We need to create a new one for the next connection. */ - GPR_ASSERT( - GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(exec_ctx, sp))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); if (0 == --sp->outstanding_calls) { - decrement_active_ports_and_notify_locked(exec_ctx, sp); + decrement_active_ports_and_notify_locked(sp); } gpr_mu_unlock(&sp->server->mu); } @@ -522,8 +514,8 @@ done: return error; } -void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, - grpc_pollset** pollset, size_t pollset_count, +void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, void* on_accept_cb_arg) { grpc_tcp_listener* sp; @@ -534,14 +526,12 @@ void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, s->on_accept_cb = on_accept_cb; s->on_accept_cb_arg = on_accept_cb_arg; for (sp = s->head; sp; sp = sp->next) { - GPR_ASSERT( - GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(exec_ctx, sp))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept_locked(sp))); s->active_ports++; } gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx* exec_ctx, - grpc_tcp_server* s) {} +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 40f4006203..2c26b60511 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -65,19 +65,18 @@ typedef struct { grpc_pollset* pollset; } grpc_tcp; -static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { - grpc_resource_user_unref(exec_ctx, tcp->resource_user); +static void tcp_free(grpc_tcp* tcp) { + grpc_resource_user_unref(tcp->resource_user); gpr_free(tcp->handle); gpr_free(tcp->peer_string); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(exec_ctx, tcp, reason) \ - tcp_unref((exec_ctx), (tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - const char* reason, const char* file, int line) { +static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, + int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -85,7 +84,7 @@ static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } @@ -100,11 +99,11 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(exec_ctx, tcp, reason) tcp_unref((exec_ctx), (tcp)) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_unref(grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } @@ -112,15 +111,14 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif static void uv_close_callback(uv_handle_t* handle) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; - TCP_UNREF(&exec_ctx, tcp, "destroy"); - grpc_exec_ctx_finish(&exec_ctx); + TCP_UNREF(tcp, "destroy"); } static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)handle->data; (void)suggested_size; /* Before calling uv_read_start, we allocate a buffer with exactly one slice @@ -128,11 +126,9 @@ static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, * allocation was successful. So slices[0] should always exist here */ buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); buf->len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); - grpc_exec_ctx_finish(&exec_ctx); } -static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - grpc_error* error) { +static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { grpc_closure* cb = tcp->read_cb; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); @@ -149,25 +145,25 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, } tcp->read_slices = NULL; tcp->read_cb = NULL; - GRPC_CLOSURE_RUN(exec_ctx, cb, error); + GRPC_CLOSURE_RUN(cb, error); } static void read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { grpc_error* error; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp* tcp = (grpc_tcp*)stream->data; grpc_slice_buffer garbage; if (nread == 0) { // Nothing happened. Wait for the next callback return; } - TCP_UNREF(&exec_ctx, tcp, "read"); + TCP_UNREF(tcp, "read"); // TODO(murgatroid99): figure out what the return value here means uv_read_stop(stream); if (nread == UV_EOF) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); } else if (nread > 0) { // Successful read error = GRPC_ERROR_NONE; @@ -177,19 +173,17 @@ static void read_callback(uv_stream_t* stream, ssize_t nread, grpc_slice_buffer_init(&garbage); grpc_slice_buffer_trim_end( tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &garbage); + grpc_slice_buffer_reset_and_unref_internal(&garbage); } } else { // nread < 0: Error error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); } - call_read_cb(&exec_ctx, tcp, error); - grpc_exec_ctx_finish(&exec_ctx); + call_read_cb(tcp, error); } -static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, - grpc_error* error) { +static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { int status; grpc_tcp* tcp = (grpc_tcp*)tcpp; if (grpc_tcp_trace.enabled()) { @@ -207,9 +201,9 @@ static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, } } if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->read_slices); - call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(exec_ctx, tcp, "read"); + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + call_read_cb(tcp, GRPC_ERROR_REF(error)); + TCP_UNREF(tcp, "read"); } if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); @@ -217,16 +211,16 @@ static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp, } } -static void uv_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* read_slices, grpc_closure* cb) { +static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, + grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(tcp->read_cb == NULL); tcp->read_cb = cb; tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices); + grpc_slice_buffer_reset_and_unref_internal(read_slices); TCP_REF(tcp, "read"); - grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, + grpc_resource_user_alloc_slices(&tcp->slice_allocator, GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, tcp->read_slices); } @@ -234,10 +228,10 @@ static void uv_endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, static void write_callback(uv_write_t* req, int status) { grpc_tcp* tcp = (grpc_tcp*)req->data; grpc_error* error; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure* cb = tcp->write_cb; tcp->write_cb = NULL; - TCP_UNREF(&exec_ctx, tcp, "write"); + TCP_UNREF(tcp, "write"); if (status == 0) { error = GRPC_ERROR_NONE; } else { @@ -248,11 +242,10 @@ static void write_callback(uv_write_t* req, int status) { gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str); } gpr_free(tcp->write_buffers); - GRPC_CLOSURE_SCHED(&exec_ctx, cb, error); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CLOSURE_SCHED(cb, error); } -static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void uv_endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* write_slices, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; @@ -275,9 +268,8 @@ static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } if (tcp->shutting_down) { - GRPC_CLOSURE_SCHED( - exec_ctx, cb, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP socket is shutting down")); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "TCP socket is shutting down")); return; } @@ -287,7 +279,7 @@ static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, if (tcp->write_slices->count == 0) { // No slices means we don't have to do anything, // and libuv doesn't like empty writes - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); return; } @@ -308,37 +300,31 @@ static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, write_callback); } -static void uv_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) { +static void uv_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { // No-op. We're ignoring pollsets currently - (void)exec_ctx; (void)ep; (void)pollset; grpc_tcp* tcp = (grpc_tcp*)ep; tcp->pollset = pollset; } -static void uv_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void uv_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) { // No-op. We're ignoring pollsets currently - (void)exec_ctx; (void)ep; (void)pollset; } -static void uv_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void uv_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) { // No-op. We're ignoring pollsets currently - (void)exec_ctx; (void)ep; (void)pollset; } static void shutdown_callback(uv_shutdown_t* req, int status) {} -static void uv_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void uv_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; if (!tcp->shutting_down) { if (grpc_tcp_trace.enabled()) { @@ -348,12 +334,12 @@ static void uv_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, tcp->shutting_down = true; uv_shutdown_t* req = &tcp->shutdown_req; uv_shutdown(req, (uv_stream_t*)tcp->handle, shutdown_callback); - grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); + grpc_resource_user_shutdown(tcp->resource_user); } GRPC_ERROR_UNREF(why); } -static void uv_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void uv_destroy(grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; uv_close((uv_handle_t*)tcp->handle, uv_close_callback); @@ -386,7 +372,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, grpc_resource_quota* resource_quota, char* peer_string) { grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); @@ -413,7 +399,6 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, uv_unref((uv_handle_t*)handle); #endif - grpc_exec_ctx_finish(&exec_ctx); return &tcp->base; } diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 33868cdc7a..6d091b77bb 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -109,21 +109,20 @@ typedef struct grpc_tcp { char* peer_string; } grpc_tcp; -static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_free(grpc_tcp* tcp) { grpc_winsocket_destroy(tcp->socket); gpr_mu_destroy(&tcp->mu); gpr_free(tcp->peer_string); - grpc_resource_user_unref(exec_ctx, tcp->resource_user); + grpc_resource_user_unref(tcp->resource_user); if (tcp->shutting_down) GRPC_ERROR_UNREF(tcp->shutdown_error); gpr_free(tcp); } #ifndef NDEBUG -#define TCP_UNREF(exec_ctx, tcp, reason) \ - tcp_unref((exec_ctx), (tcp), (reason), __FILE__, __LINE__) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, - const char* reason, const char* file, int line) { +static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, + int line) { if (grpc_tcp_trace.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -131,7 +130,7 @@ static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, val - 1); } if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } @@ -146,11 +145,11 @@ static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, gpr_ref(&tcp->refcount); } #else -#define TCP_UNREF(exec_ctx, tcp, reason) tcp_unref((exec_ctx), (tcp)) +#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { +static void tcp_unref(grpc_tcp* tcp) { if (gpr_unref(&tcp->refcount)) { - tcp_free(exec_ctx, tcp); + tcp_free(tcp); } } @@ -158,7 +157,7 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } #endif /* Asynchronous callback from the IOCP, or the background thread. */ -static void on_read(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { +static void on_read(void* tcpp, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; grpc_closure* cb = tcp->read_cb; grpc_winsocket* socket = tcp->socket; @@ -172,13 +171,13 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { char* utf8_message = gpr_format_message(info->wsa_error); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(utf8_message); gpr_free(utf8_message); - grpc_slice_unref_internal(exec_ctx, tcp->read_slice); + grpc_slice_unref_internal(tcp->read_slice); } else { if (info->bytes_transfered != 0 && !tcp->shutting_down) { sub = grpc_slice_sub_no_ref(tcp->read_slice, 0, info->bytes_transfered); grpc_slice_buffer_add(tcp->read_slices, sub); } else { - grpc_slice_unref_internal(exec_ctx, tcp->read_slice); + grpc_slice_unref_internal(tcp->read_slice); error = tcp->shutting_down ? GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "TCP stream shutting down", &tcp->shutdown_error, 1) @@ -188,12 +187,12 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { } tcp->read_cb = NULL; - TCP_UNREF(exec_ctx, tcp, "read"); - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + TCP_UNREF(tcp, "read"); + GRPC_CLOSURE_SCHED(cb, error); } -static void win_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* read_slices, grpc_closure* cb) { +static void win_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, + grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_winsocket* handle = tcp->socket; grpc_winsocket_callback_info* info = &handle->read_info; @@ -204,15 +203,14 @@ static void win_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, if (tcp->shutting_down) { GRPC_CLOSURE_SCHED( - exec_ctx, cb, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "TCP socket is shutting down", &tcp->shutdown_error, 1)); + cb, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "TCP socket is shutting down", &tcp->shutdown_error, 1)); return; } tcp->read_cb = cb; tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices); + grpc_slice_buffer_reset_and_unref_internal(read_slices); tcp->read_slice = GRPC_SLICE_MALLOC(8192); @@ -230,7 +228,7 @@ static void win_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, /* Did we get data immediately ? Yay. */ if (info->wsa_error != WSAEWOULDBLOCK) { info->bytes_transfered = bytes_read; - GRPC_CLOSURE_SCHED(exec_ctx, &tcp->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&tcp->on_read, GRPC_ERROR_NONE); return; } @@ -243,17 +241,17 @@ static void win_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, int wsa_error = WSAGetLastError(); if (wsa_error != WSA_IO_PENDING) { info->wsa_error = wsa_error; - GRPC_CLOSURE_SCHED(exec_ctx, &tcp->on_read, + GRPC_CLOSURE_SCHED(&tcp->on_read, GRPC_WSA_ERROR(info->wsa_error, "WSARecv")); return; } } - grpc_socket_notify_on_read(exec_ctx, tcp->socket, &tcp->on_read); + grpc_socket_notify_on_read(tcp->socket, &tcp->on_read); } /* Asynchronous callback from the IOCP, or the background thread. */ -static void on_write(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { +static void on_write(void* tcpp, grpc_error* error) { grpc_tcp* tcp = (grpc_tcp*)tcpp; grpc_winsocket* handle = tcp->socket; grpc_winsocket_callback_info* info = &handle->write_info; @@ -274,13 +272,13 @@ static void on_write(grpc_exec_ctx* exec_ctx, void* tcpp, grpc_error* error) { } } - TCP_UNREF(exec_ctx, tcp, "write"); - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + TCP_UNREF(tcp, "write"); + GRPC_CLOSURE_SCHED(cb, error); } /* Initiates a write. */ -static void win_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; grpc_winsocket* socket = tcp->socket; grpc_winsocket_callback_info* info = &socket->write_info; @@ -294,9 +292,8 @@ static void win_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, if (tcp->shutting_down) { GRPC_CLOSURE_SCHED( - exec_ctx, cb, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "TCP socket is shutting down", &tcp->shutdown_error, 1)); + cb, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "TCP socket is shutting down", &tcp->shutdown_error, 1)); return; } @@ -327,7 +324,7 @@ static void win_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_error* error = status == 0 ? GRPC_ERROR_NONE : GRPC_WSA_ERROR(info->wsa_error, "WSASend"); - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + GRPC_CLOSURE_SCHED(cb, error); if (allocated) gpr_free(allocated); return; } @@ -344,35 +341,32 @@ static void win_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, if (status != 0) { int wsa_error = WSAGetLastError(); if (wsa_error != WSA_IO_PENDING) { - TCP_UNREF(exec_ctx, tcp, "write"); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_WSA_ERROR(wsa_error, "WSASend")); + TCP_UNREF(tcp, "write"); + GRPC_CLOSURE_SCHED(cb, GRPC_WSA_ERROR(wsa_error, "WSASend")); return; } } /* As all is now setup, we can now ask for the IOCP notification. It may trigger the callback immediately however, but no matter. */ - grpc_socket_notify_on_write(exec_ctx, socket, &tcp->on_write); + grpc_socket_notify_on_write(socket, &tcp->on_write); } -static void win_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* ps) { +static void win_add_to_pollset(grpc_endpoint* ep, grpc_pollset* ps) { grpc_tcp* tcp; (void)ps; tcp = (grpc_tcp*)ep; grpc_iocp_add_socket(tcp->socket); } -static void win_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset_set* pss) { +static void win_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pss) { grpc_tcp* tcp; (void)pss; tcp = (grpc_tcp*)ep; grpc_iocp_add_socket(tcp->socket); } -static void win_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void win_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pss) {} /* Initiates a shutdown of the TCP endpoint. This will queue abort callbacks @@ -381,8 +375,7 @@ static void win_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, we're not going to protect against these. However the IO Completion Port callback will happen from another thread, so we need to protect against concurrent access of the data structure in that regard. */ -static void win_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void win_shutdown(grpc_endpoint* ep, grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; gpr_mu_lock(&tcp->mu); /* At that point, what may happen is that we're already inside the IOCP @@ -395,13 +388,13 @@ static void win_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } grpc_winsocket_shutdown(tcp->socket); gpr_mu_unlock(&tcp->mu); - grpc_resource_user_shutdown(exec_ctx, tcp->resource_user); + grpc_resource_user_shutdown(tcp->resource_user); } -static void win_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void win_destroy(grpc_endpoint* ep) { grpc_network_status_unregister_endpoint(ep); grpc_tcp* tcp = (grpc_tcp*)ep; - TCP_UNREF(exec_ctx, tcp, "destroy"); + TCP_UNREF(tcp, "destroy"); } static char* win_get_peer(grpc_endpoint* ep) { @@ -427,14 +420,14 @@ static grpc_endpoint_vtable vtable = {win_read, win_get_peer, win_get_fd}; -grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, +grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket, grpc_channel_args* channel_args, const char* peer_string) { grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); if (channel_args != NULL) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); resource_quota = grpc_resource_quota_ref_internal( (grpc_resource_quota*)channel_args->args[i].value.pointer.p); } @@ -452,7 +445,7 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); /* Tell network status tracking code about the new endpoint */ grpc_network_status_register_endpoint(&tcp->base); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); return &tcp->base; } diff --git a/src/core/lib/iomgr/tcp_windows.h b/src/core/lib/iomgr/tcp_windows.h index 28287e2795..8578a358ea 100644 --- a/src/core/lib/iomgr/tcp_windows.h +++ b/src/core/lib/iomgr/tcp_windows.h @@ -38,7 +38,7 @@ /* Create a tcp endpoint given a winsock handle. * Takes ownership of the handle. */ -grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_winsocket* socket, +grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket, grpc_channel_args* channel_args, const char* peer_string); diff --git a/src/core/lib/iomgr/timer.h b/src/core/lib/iomgr/timer.h index b9acce229e..82049859c5 100644 --- a/src/core/lib/iomgr/timer.h +++ b/src/core/lib/iomgr/timer.h @@ -40,8 +40,8 @@ typedef struct grpc_timer grpc_timer; application code should check the error to determine how it was invoked. The application callback is also responsible for maintaining information about when to free up any user-level state. */ -void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, - grpc_millis deadline, grpc_closure* closure); +void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure); /* Initialize *timer without setting it. This can later be passed through the regular init or cancel */ @@ -73,7 +73,7 @@ void grpc_timer_init_unset(grpc_timer* timer); matches this aim. Requires: cancel() must happen after init() on a given timer */ -void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer); +void grpc_timer_cancel(grpc_timer* timer); /* iomgr internal api for dealing with timers */ @@ -90,10 +90,9 @@ typedef enum { *next is never guaranteed to be updated on any given execution; however, with high probability at least one thread in the system will see an update at any time slice. */ -grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, - grpc_millis* next); -void grpc_timer_list_init(grpc_exec_ctx* exec_ctx); -void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx); +grpc_timer_check_result grpc_timer_check(grpc_millis* next); +void grpc_timer_list_init(); +void grpc_timer_list_shutdown(); /* Consume a kick issued by grpc_kick_poller */ void grpc_timer_consume_kick(void); diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index fa95c43dbe..103144eb3b 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -225,8 +225,7 @@ static gpr_atm saturating_add(gpr_atm a, gpr_atm b) { return a + b; } -static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, - gpr_atm now, +static grpc_timer_check_result run_some_expired_timers(gpr_atm now, gpr_atm* next, grpc_error* error); @@ -236,7 +235,7 @@ static gpr_atm compute_min_deadline(timer_shard* shard) { : grpc_timer_heap_top(&shard->heap)->deadline; } -void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { +void grpc_timer_list_init() { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); @@ -247,7 +246,7 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; gpr_mu_init(&g_shared_mutables.mu); - g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); + g_shared_mutables.min_timer = grpc_core::ExecCtx::Get()->Now(); gpr_tls_init(&g_last_seen_min_timer); gpr_tls_set(&g_last_seen_min_timer, 0); @@ -267,10 +266,10 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { INIT_TIMER_HASH_TABLE(); } -void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) { +void grpc_timer_list_shutdown() { size_t i; run_some_expired_timers( - exec_ctx, GPR_ATM_MAX, nullptr, + GPR_ATM_MAX, nullptr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown")); for (i = 0; i < g_num_shards; i++) { timer_shard* shard = &g_shards[i]; @@ -323,8 +322,8 @@ static void note_deadline_change(timer_shard* shard) { void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; } -void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, - grpc_millis deadline, grpc_closure* closure) { +void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { int is_first_timer = 0; timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer->closure = closure; @@ -337,12 +336,12 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, if (grpc_timer_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, - deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); + deadline, grpc_core::ExecCtx::Get()->Now(), closure, closure->cb); } if (!g_shared_mutables.initialized) { timer->pending = false; - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Attempt to create timer before initialization")); return; @@ -350,10 +349,10 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, gpr_mu_lock(&shard->mu); timer->pending = true; - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); if (deadline <= now) { timer->pending = false; - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); gpr_mu_unlock(&shard->mu); /* early out */ return; @@ -414,7 +413,7 @@ void grpc_timer_consume_kick(void) { gpr_tls_set(&g_last_seen_min_timer, 0); } -void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { +void grpc_timer_cancel(grpc_timer* timer) { if (!g_shared_mutables.initialized) { /* must have already been cancelled, also the shard mutex is invalid */ return; @@ -430,7 +429,7 @@ void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { if (timer->pending) { REMOVE_FROM_HASH_TABLE(timer); - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); timer->pending = false; if (timer->heap_index == INVALID_HEAP_INDEX) { list_remove(timer); @@ -516,15 +515,14 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { } /* REQUIRES: shard->mu unlocked */ -static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard, - gpr_atm now, gpr_atm* new_min_deadline, - grpc_error* error) { +static size_t pop_timers(timer_shard* shard, gpr_atm now, + gpr_atm* new_min_deadline, grpc_error* error) { size_t n = 0; grpc_timer* timer; gpr_mu_lock(&shard->mu); while ((timer = pop_one(shard, now))) { REMOVE_FROM_HASH_TABLE(timer); - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_REF(error)); n++; } *new_min_deadline = compute_min_deadline(shard); @@ -536,8 +534,7 @@ static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard, return n; } -static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, - gpr_atm now, +static grpc_timer_check_result run_some_expired_timers(gpr_atm now, gpr_atm* next, grpc_error* error) { grpc_timer_check_result result = GRPC_TIMERS_NOT_CHECKED; @@ -566,8 +563,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, /* For efficiency, we pop as many available timers as we can from the shard. This may violate perfect timer deadline ordering, but that shouldn't be a big deal because we don't make ordering guarantees. */ - if (pop_timers(exec_ctx, g_shard_queue[0], now, &new_min_deadline, - error) > 0) { + if (pop_timers(g_shard_queue[0], now, &new_min_deadline, error) > 0) { result = GRPC_TIMERS_FIRED; } @@ -604,10 +600,9 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, return result; } -grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, - grpc_millis* next) { +grpc_timer_check_result grpc_timer_check(grpc_millis* next) { // prelude - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); /* fetch from a thread-local first: this avoids contention on a globally mutable cacheline in the common case */ @@ -646,7 +641,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, } // actual code grpc_timer_check_result r = - run_some_expired_timers(exec_ctx, now, next, shutdown_error); + run_some_expired_timers(now, next, shutdown_error); // tracing if (grpc_timer_check_trace.enabled()) { char* next_str; diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 87ed0e05dc..8ca6a3c23e 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -98,13 +98,12 @@ static void start_timer_thread_and_unlock(void) { } void grpc_timer_manager_tick() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_timer_check(&exec_ctx, &next); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_check(&next); } -static void run_some_timers(grpc_exec_ctx* exec_ctx) { +static void run_some_timers() { // if there's something to execute... gpr_mu_lock(&g_mu); // remove a waiter from the pool, and start another thread if necessary @@ -126,7 +125,7 @@ static void run_some_timers(grpc_exec_ctx* exec_ctx) { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "flush exec_ctx"); } - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&g_mu); // garbage collect any threads hanging out that are dead gc_completed_threads(); @@ -138,7 +137,7 @@ static void run_some_timers(grpc_exec_ctx* exec_ctx) { // wait until 'next' (or forever if there is already a timed waiter in the pool) // returns true if the thread should continue executing (false if it should // shutdown) -static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { +static bool wait_until(grpc_millis next) { gpr_mu_lock(&g_mu); // if we're not threaded anymore, leave if (!g_threaded) { @@ -179,7 +178,7 @@ static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { g_timed_waiter_deadline = next; if (grpc_timer_check_trace.enabled()) { - grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx); + grpc_millis wait_time = next - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", wait_time); } @@ -220,15 +219,15 @@ static bool wait_until(grpc_exec_ctx* exec_ctx, grpc_millis next) { return true; } -static void timer_main_loop(grpc_exec_ctx* exec_ctx) { +static void timer_main_loop() { for (;;) { grpc_millis next = GRPC_MILLIS_INF_FUTURE; - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); // check timer state, updates next to the next time to run a check - switch (grpc_timer_check(exec_ctx, &next)) { + switch (grpc_timer_check(&next)) { case GRPC_TIMERS_FIRED: - run_some_timers(exec_ctx); + run_some_timers(); break; case GRPC_TIMERS_NOT_CHECKED: /* This case only happens under contention, meaning more than one timer @@ -246,7 +245,7 @@ static void timer_main_loop(grpc_exec_ctx* exec_ctx) { next = GRPC_MILLIS_INF_FUTURE; /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: - if (!wait_until(exec_ctx, next)) { + if (!wait_until(next)) { return; } break; @@ -274,10 +273,9 @@ static void timer_thread_cleanup(completed_thread* ct) { static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); - timer_main_loop(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx(0); + timer_main_loop(); + timer_thread_cleanup((completed_thread*)completed_thread_ptr); } diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index fac2026fa9..5d238da089 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -42,28 +42,27 @@ static void stop_uv_timer(uv_timer_t* handle) { void run_expired_timer(uv_timer_t* handle) { grpc_timer* timer = (grpc_timer*)handle->data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_UV_ASSERT_SAME_THREAD(); GPR_ASSERT(timer->pending); timer->pending = 0; - GRPC_CLOSURE_SCHED(&exec_ctx, timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); stop_uv_timer(handle); - grpc_exec_ctx_finish(&exec_ctx); } -void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, - grpc_millis deadline, grpc_closure* closure) { +void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { uint64_t timeout; uv_timer_t* uv_timer; GRPC_UV_ASSERT_SAME_THREAD(); timer->closure = closure; - if (deadline <= grpc_exec_ctx_now(exec_ctx)) { + if (deadline <= grpc_core::ExecCtx::Get()->Now()) { timer->pending = 0; - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); return; } timer->pending = 1; - timeout = (uint64_t)(deadline - grpc_exec_ctx_now(exec_ctx)); + timeout = (uint64_t)(deadline - grpc_core::ExecCtx::Get()->Now()); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); uv_timer->data = timer; @@ -77,22 +76,21 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = 0; } -void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { +void grpc_timer_cancel(grpc_timer* timer) { GRPC_UV_ASSERT_SAME_THREAD(); if (timer->pending) { timer->pending = 0; - GRPC_CLOSURE_SCHED(exec_ctx, timer->closure, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); stop_uv_timer((uv_timer_t*)timer->uv_timer); } } -grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, - grpc_millis* next) { +grpc_timer_check_result grpc_timer_check(grpc_millis* next) { return GRPC_TIMERS_NOT_CHECKED; } -void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) {} -void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) {} +void grpc_timer_list_init() {} +void grpc_timer_list_shutdown() {} void grpc_timer_consume_kick(void) {} diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 7b7d6946b1..55e0b165ec 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -150,31 +150,30 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { return s; } -static void shutdown_fd(grpc_exec_ctx* exec_ctx, void* args, - grpc_error* error) { +static void shutdown_fd(void* args, grpc_error* error) { struct shutdown_fd_args* shutdown_args = (struct shutdown_fd_args*)args; grpc_udp_listener* sp = shutdown_args->sp; gpr_log(GPR_DEBUG, "shutdown fd %d", sp->fd); gpr_mu_lock(shutdown_args->server_mu); - grpc_fd_shutdown(exec_ctx, sp->emfd, GRPC_ERROR_REF(error)); + grpc_fd_shutdown(sp->emfd, GRPC_ERROR_REF(error)); sp->already_shutdown = true; if (!sp->notify_on_write_armed) { // Re-arm write notification to notify listener with error. This is // necessary to decrement active_ports. sp->notify_on_write_armed = true; - grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); } gpr_mu_unlock(shutdown_args->server_mu); gpr_free(shutdown_args); } -static void dummy_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void dummy_cb(void* arg, grpc_error* error) { // No-op. } -static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { +static void finish_shutdown(grpc_udp_server* s) { if (s->shutdown_complete != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); } gpr_mu_destroy(&s->mu); @@ -193,14 +192,13 @@ static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { gpr_free(s); } -static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, - grpc_error* error) { +static void destroyed_port(void* server, grpc_error* error) { grpc_udp_server* s = (grpc_udp_server*)server; gpr_mu_lock(&s->mu); s->destroyed_ports++; if (s->destroyed_ports == s->nports) { gpr_mu_unlock(&s->mu); - finish_shutdown(exec_ctx, s); + finish_shutdown(s); } else { gpr_mu_unlock(&s->mu); } @@ -209,7 +207,7 @@ static void destroyed_port(grpc_exec_ctx* exec_ctx, void* server, /* called when all listening endpoints have been shutdown, so no further events will be received on them - at this point it's safe to destroy things */ -static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { +static void deactivated_all_ports(grpc_udp_server* s) { /* delete ALL the things */ gpr_mu_lock(&s->mu); @@ -230,21 +228,19 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { grpc_schedule_on_exec_ctx); GPR_ASSERT(sp->orphan_cb); gpr_log(GPR_DEBUG, "Orphan fd %d", sp->fd); - sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, - sp->server->user_data); + sp->orphan_cb(sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); } - grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, + grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "udp_listener_shutdown"); } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - finish_shutdown(exec_ctx, s); + finish_shutdown(s); } } -void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, - grpc_closure* on_done) { +void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) { grpc_udp_listener* sp; gpr_mu_lock(&s->mu); @@ -264,14 +260,13 @@ void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, args->server_mu = &s->mu; GRPC_CLOSURE_INIT(&sp->orphan_fd_closure, shutdown_fd, args, grpc_schedule_on_exec_ctx); - sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, - sp->server->user_data); + sp->orphan_cb(sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); sp->orphan_notified = true; } gpr_mu_unlock(&s->mu); } else { gpr_mu_unlock(&s->mu); - deactivated_all_ports(exec_ctx, s); + deactivated_all_ports(s); } } @@ -350,7 +345,7 @@ error: return -1; } -static void do_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void do_read(void* arg, grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); GPR_ASSERT(sp->read_cb && error == GRPC_ERROR_NONE); /* TODO: the reason we hold server->mu here is merely to prevent fd @@ -358,29 +353,28 @@ static void do_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { * read lock if available. */ gpr_mu_lock(&sp->server->mu); /* Tell the registered callback that data is available to read. */ - if (!sp->already_shutdown && - sp->read_cb(exec_ctx, sp->emfd, sp->server->user_data)) { + if (!sp->already_shutdown && sp->read_cb(sp->emfd, sp->server->user_data)) { /* There maybe more packets to read. Schedule read_more_cb_ closure to run * after finishing this event loop. */ - GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_read_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&sp->do_read_closure, GRPC_ERROR_NONE); } else { /* Finish reading all the packets, re-arm the notification event so we can * get another chance to read. Or fd already shutdown, re-arm to get a * notification with shutdown error. */ - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); } gpr_mu_unlock(&sp->server->mu); } /* event manager callback when reads are ready */ -static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_read(void* arg, grpc_error* error) { grpc_udp_listener* sp = (grpc_udp_listener*)arg; gpr_mu_lock(&sp->server->mu); if (error != GRPC_ERROR_NONE) { if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(exec_ctx, sp->server); + deactivated_all_ports(sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -389,59 +383,57 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { /* Read once. If there is more data to read, off load the work to another * thread to finish. */ GPR_ASSERT(sp->read_cb); - if (sp->read_cb(exec_ctx, sp->emfd, sp->server->user_data)) { + if (sp->read_cb(sp->emfd, sp->server->user_data)) { /* There maybe more packets to read. Schedule read_more_cb_ closure to run * after finishing this event loop. */ GRPC_CLOSURE_INIT(&sp->do_read_closure, do_read, arg, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)); - GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_read_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&sp->do_read_closure, GRPC_ERROR_NONE); } else { /* Finish reading all the packets, re-arm the notification event so we can * get another chance to read. Or fd already shutdown, re-arm to get a * notification with shutdown error. */ - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); } gpr_mu_unlock(&sp->server->mu); } // Wrapper of grpc_fd_notify_on_write() with a grpc_closure callback interface. -void fd_notify_on_write_wrapper(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +void fd_notify_on_write_wrapper(void* arg, grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); gpr_mu_lock(&sp->server->mu); if (!sp->notify_on_write_armed) { - grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); sp->notify_on_write_armed = true; } gpr_mu_unlock(&sp->server->mu); } -static void do_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void do_write(void* arg, grpc_error* error) { grpc_udp_listener* sp = reinterpret_cast(arg); gpr_mu_lock(&(sp->server->mu)); if (sp->already_shutdown) { // If fd has been shutdown, don't write any more and re-arm notification. - grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); } else { sp->notify_on_write_armed = false; /* Tell the registered callback that the socket is writeable. */ GPR_ASSERT(sp->write_cb && error == GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&sp->notify_on_write_closure, fd_notify_on_write_wrapper, arg, grpc_schedule_on_exec_ctx); - sp->write_cb(exec_ctx, sp->emfd, sp->server->user_data, - &sp->notify_on_write_closure); + sp->write_cb(sp->emfd, sp->server->user_data, &sp->notify_on_write_closure); } gpr_mu_unlock(&sp->server->mu); } -static void on_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_write(void* arg, grpc_error* error) { grpc_udp_listener* sp = (grpc_udp_listener*)arg; gpr_mu_lock(&(sp->server->mu)); if (error != GRPC_ERROR_NONE) { if (0 == --sp->server->active_ports && sp->server->shutdown) { gpr_mu_unlock(&sp->server->mu); - deactivated_all_ports(exec_ctx, sp->server); + deactivated_all_ports(sp->server); } else { gpr_mu_unlock(&sp->server->mu); } @@ -452,7 +444,7 @@ static void on_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GRPC_CLOSURE_INIT(&sp->do_write_closure, do_write, arg, grpc_executor_scheduler(GRPC_EXECUTOR_LONG)); - GRPC_CLOSURE_SCHED(exec_ctx, &sp->do_write_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&sp->do_write_closure, GRPC_ERROR_NONE); gpr_mu_unlock(&sp->server->mu); } @@ -593,9 +585,8 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index) { return sp->fd; } -void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, - grpc_pollset** pollsets, size_t pollset_count, - void* user_data) { +void grpc_udp_server_start(grpc_udp_server* s, grpc_pollset** pollsets, + size_t pollset_count, void* user_data) { size_t i; gpr_mu_lock(&s->mu); grpc_udp_listener* sp; @@ -606,16 +597,16 @@ void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, sp = s->head; while (sp != nullptr) { for (i = 0; i < pollset_count; i++) { - grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); + grpc_pollset_add_fd(pollsets[i], sp->emfd); } GRPC_CLOSURE_INIT(&sp->read_closure, on_read, sp, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); + grpc_fd_notify_on_read(sp->emfd, &sp->read_closure); GRPC_CLOSURE_INIT(&sp->write_closure, on_write, sp, grpc_schedule_on_exec_ctx); sp->notify_on_write_armed = true; - grpc_fd_notify_on_write(exec_ctx, sp->emfd, &sp->write_closure); + grpc_fd_notify_on_write(sp->emfd, &sp->write_closure); /* Registered for both read and write callbacks: increment active_ports * twice to account for this, and delay free-ing of memory until both diff --git a/src/core/lib/iomgr/udp_server.h b/src/core/lib/iomgr/udp_server.h index 1bd6922de6..02e3acb7f5 100644 --- a/src/core/lib/iomgr/udp_server.h +++ b/src/core/lib/iomgr/udp_server.h @@ -32,18 +32,15 @@ typedef struct grpc_udp_server grpc_udp_server; /* Called when data is available to read from the socket. * Return true if there is more data to read from fd. */ -typedef bool (*grpc_udp_server_read_cb)(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, - void* user_data); +typedef bool (*grpc_udp_server_read_cb)(grpc_fd* emfd, void* user_data); /* Called when the socket is writeable. The given closure should be scheduled * when the socket becomes blocked next time. */ -typedef void (*grpc_udp_server_write_cb)(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, - void* user_data, +typedef void (*grpc_udp_server_write_cb)(grpc_fd* emfd, void* user_data, grpc_closure* notify_on_write_closure); /* Called when the grpc_fd is about to be orphaned (and the FD closed). */ -typedef void (*grpc_udp_server_orphan_cb)(grpc_exec_ctx* exec_ctx, - grpc_fd* emfd, +typedef void (*grpc_udp_server_orphan_cb)(grpc_fd* emfd, grpc_closure* shutdown_fd_callback, void* user_data); @@ -51,9 +48,8 @@ typedef void (*grpc_udp_server_orphan_cb)(grpc_exec_ctx* exec_ctx, grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args); /* Start listening to bound ports. user_data is passed to callbacks. */ -void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* udp_server, - grpc_pollset** pollsets, size_t pollset_count, - void* user_data); +void grpc_udp_server_start(grpc_udp_server* udp_server, grpc_pollset** pollsets, + size_t pollset_count, void* user_data); int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index); @@ -73,7 +69,6 @@ int grpc_udp_server_add_port(grpc_udp_server* s, grpc_udp_server_write_cb write_cb, grpc_udp_server_orphan_cb orphan_cb); -void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* server, - grpc_closure* on_done); +void grpc_udp_server_destroy(grpc_udp_server* server, grpc_closure* on_done); #endif /* GRPC_CORE_LIB_IOMGR_UDP_SERVER_H */ diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 19c6148e43..0371027994 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -36,7 +36,7 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount( grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_client_security_context* ctx = nullptr; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); @@ -52,10 +52,10 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx, grpc_client_security_context_destroy); } else { - grpc_call_credentials_unref(&exec_ctx, ctx->creds); + grpc_call_credentials_unref(ctx->creds); ctx->creds = grpc_call_credentials_ref(creds); } - grpc_exec_ctx_finish(&exec_ctx); + return GRPC_CALL_OK; } @@ -85,15 +85,14 @@ grpc_client_security_context* grpc_client_security_context_create(void) { } void grpc_client_security_context_destroy(void* ctx) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_client_security_context* c = (grpc_client_security_context*)ctx; - grpc_call_credentials_unref(&exec_ctx, c->creds); + grpc_call_credentials_unref(c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); - grpc_exec_ctx_finish(&exec_ctx); } /* --- grpc_server_security_context --- */ @@ -141,7 +140,7 @@ grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx, } #else grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) { - if (ctx == NULL) return NULL; + if (ctx == nullptr) return nullptr; #endif gpr_ref(&ctx->refcount); return ctx; @@ -159,7 +158,7 @@ void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line, } #else void grpc_auth_context_unref(grpc_auth_context* ctx) { - if (ctx == NULL) return; + if (ctx == nullptr) return; #endif if (gpr_unref(&ctx->refcount)) { size_t i; @@ -303,7 +302,7 @@ void grpc_auth_property_reset(grpc_auth_property* property) { memset(property, 0, sizeof(grpc_auth_property)); } -static void auth_context_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { +static void auth_context_pointer_arg_destroy(void* p) { GRPC_AUTH_CONTEXT_UNREF((grpc_auth_context*)p, "auth_context_pointer_arg"); } diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index 93dd721240..e4c1604795 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -39,17 +39,15 @@ typedef struct { grpc_closure internal_on_request_metadata; } grpc_composite_call_credentials_metadata_context; -static void composite_call_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void composite_call_destruct(grpc_call_credentials* creds) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; for (size_t i = 0; i < c->inner.num_creds; i++) { - grpc_call_credentials_unref(exec_ctx, c->inner.creds_array[i]); + grpc_call_credentials_unref(c->inner.creds_array[i]); } gpr_free(c->inner.creds_array); } -static void composite_call_metadata_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void composite_call_metadata_cb(void* arg, grpc_error* error) { grpc_composite_call_credentials_metadata_context* ctx = (grpc_composite_call_credentials_metadata_context*)arg; if (error == GRPC_ERROR_NONE) { @@ -58,23 +56,23 @@ static void composite_call_metadata_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_call_credentials* inner_creds = ctx->composite_creds->inner.creds_array[ctx->creds_index++]; if (grpc_call_credentials_get_request_metadata( - exec_ctx, inner_creds, ctx->pollent, ctx->auth_md_context, - ctx->md_array, &ctx->internal_on_request_metadata, &error)) { + inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array, + &ctx->internal_on_request_metadata, &error)) { // Synchronous response, so call ourselves recursively. - composite_call_metadata_cb(exec_ctx, arg, error); + composite_call_metadata_cb(arg, error); GRPC_ERROR_UNREF(error); } return; } // We're done! } - GRPC_CLOSURE_SCHED(exec_ctx, ctx->on_request_metadata, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(ctx->on_request_metadata, GRPC_ERROR_REF(error)); gpr_free(ctx); } static bool composite_call_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context auth_md_context, + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context auth_md_context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; @@ -93,8 +91,8 @@ static bool composite_call_get_request_metadata( grpc_call_credentials* inner_creds = ctx->composite_creds->inner.creds_array[ctx->creds_index++]; if (grpc_call_credentials_get_request_metadata( - exec_ctx, inner_creds, ctx->pollent, ctx->auth_md_context, - ctx->md_array, &ctx->internal_on_request_metadata, error)) { + inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array, + &ctx->internal_on_request_metadata, error)) { if (*error != GRPC_ERROR_NONE) break; } else { synchronous = false; // Async return. @@ -106,12 +104,12 @@ static bool composite_call_get_request_metadata( } static void composite_call_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { grpc_composite_call_credentials* c = (grpc_composite_call_credentials*)creds; for (size_t i = 0; i < c->inner.num_creds; ++i) { grpc_call_credentials_cancel_get_request_metadata( - exec_ctx, c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); + c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); } @@ -200,19 +198,17 @@ grpc_call_credentials* grpc_credentials_contains_type( /* -- Composite channel credentials. -- */ -static void composite_channel_destruct(grpc_exec_ctx* exec_ctx, - grpc_channel_credentials* creds) { +static void composite_channel_destruct(grpc_channel_credentials* creds) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)creds; - grpc_channel_credentials_unref(exec_ctx, c->inner_creds); - grpc_call_credentials_unref(exec_ctx, c->call_creds); + grpc_channel_credentials_unref(c->inner_creds); + grpc_call_credentials_unref(c->call_creds); } static grpc_security_status composite_channel_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* creds, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)creds; grpc_security_status status = GRPC_SECURITY_ERROR; @@ -227,12 +223,11 @@ static grpc_security_status composite_channel_create_security_connector( grpc_composite_call_credentials_create(c->call_creds, call_creds, nullptr); status = c->inner_creds->vtable->create_security_connector( - exec_ctx, c->inner_creds, composite_call_creds, target, args, sc, - new_args); - grpc_call_credentials_unref(exec_ctx, composite_call_creds); + c->inner_creds, composite_call_creds, target, args, sc, new_args); + grpc_call_credentials_unref(composite_call_creds); } else { status = c->inner_creds->vtable->create_security_connector( - exec_ctx, c->inner_creds, c->call_creds, target, args, sc, new_args); + c->inner_creds, c->call_creds, target, args, sc, new_args); } return status; } diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index 90576e69b9..48b459e1be 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -47,8 +47,8 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( } void grpc_credentials_metadata_request_destroy( - grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* r) { - grpc_call_credentials_unref(exec_ctx, r->creds); + grpc_credentials_metadata_request* r) { + grpc_call_credentials_unref(r->creds); grpc_http_response_destroy(&r->response); gpr_free(r); } @@ -60,12 +60,11 @@ grpc_channel_credentials* grpc_channel_credentials_ref( return creds; } -void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_channel_credentials* creds) { +void grpc_channel_credentials_unref(grpc_channel_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(exec_ctx, creds); + creds->vtable->destruct(creds); } gpr_free(creds); } @@ -73,9 +72,8 @@ void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, void grpc_channel_credentials_release(grpc_channel_credentials* creds) { GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_credentials_unref(creds); } grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { @@ -84,12 +82,11 @@ grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { return creds; } -void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +void grpc_call_credentials_unref(grpc_call_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(exec_ctx, creds); + creds->vtable->destruct(creds); } gpr_free(creds); } @@ -97,44 +94,42 @@ void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, void grpc_call_credentials_release(grpc_call_credentials* creds) { GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_call_credentials_unref(creds); } bool grpc_call_credentials_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context context, - grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error) { + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, + grpc_closure* on_request_metadata, grpc_error** error) { if (creds == nullptr || creds->vtable->get_request_metadata == nullptr) { return true; } - return creds->vtable->get_request_metadata( - exec_ctx, creds, pollent, context, md_array, on_request_metadata, error); + return creds->vtable->get_request_metadata(creds, pollent, context, md_array, + on_request_metadata, error); } void grpc_call_credentials_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { if (creds == nullptr || creds->vtable->cancel_get_request_metadata == nullptr) { return; } - creds->vtable->cancel_get_request_metadata(exec_ctx, creds, md_array, error); + creds->vtable->cancel_get_request_metadata(creds, md_array, error); } grpc_security_status grpc_channel_credentials_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_channel_credentials* channel_creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { *new_args = nullptr; if (channel_creds == nullptr) { return GRPC_SECURITY_ERROR; } GPR_ASSERT(channel_creds->vtable->create_security_connector != nullptr); return channel_creds->vtable->create_security_connector( - exec_ctx, channel_creds, nullptr, target, args, sc, new_args); + channel_creds, nullptr, target, args, sc, new_args); } grpc_channel_credentials* @@ -149,8 +144,8 @@ grpc_channel_credentials_duplicate_without_call_credentials( } } -static void credentials_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { - grpc_channel_credentials_unref(exec_ctx, (grpc_channel_credentials*)p); +static void credentials_pointer_arg_destroy(void* p) { + grpc_channel_credentials_unref((grpc_channel_credentials*)p); } static void* credentials_pointer_arg_copy(void* p) { @@ -200,12 +195,11 @@ grpc_server_credentials* grpc_server_credentials_ref( return creds; } -void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_server_credentials* creds) { +void grpc_server_credentials_unref(grpc_server_credentials* creds) { if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { if (creds->vtable->destruct != nullptr) { - creds->vtable->destruct(exec_ctx, creds); + creds->vtable->destruct(creds); } if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { @@ -217,19 +211,17 @@ void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, void grpc_server_credentials_release(grpc_server_credentials* creds) { GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_server_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_server_credentials_unref(creds); } grpc_security_status grpc_server_credentials_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, - grpc_server_security_connector** sc) { + grpc_server_credentials* creds, grpc_server_security_connector** sc) { if (creds == nullptr || creds->vtable->create_security_connector == nullptr) { gpr_log(GPR_ERROR, "Server credentials cannot create security context."); return GRPC_SECURITY_ERROR; } - return creds->vtable->create_security_connector(exec_ctx, creds, sc); + return creds->vtable->create_security_connector(creds, sc); } void grpc_server_credentials_set_auth_metadata_processor( @@ -247,9 +239,8 @@ void grpc_server_credentials_set_auth_metadata_processor( creds->processor = processor; } -static void server_credentials_pointer_arg_destroy(grpc_exec_ctx* exec_ctx, - void* p) { - grpc_server_credentials_unref(exec_ctx, (grpc_server_credentials*)p); +static void server_credentials_pointer_arg_destroy(void* p) { + grpc_server_credentials_unref((grpc_server_credentials*)p); } static void* server_credentials_pointer_arg_copy(void* p) { diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index bc1bd11c77..4825b65720 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -88,13 +88,12 @@ void grpc_override_well_known_credentials_path_getter( #define GRPC_ARG_CHANNEL_CREDENTIALS "grpc.channel_credentials" typedef struct { - void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c); + void (*destruct)(grpc_channel_credentials* c); grpc_security_status (*create_security_connector)( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args); + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args); grpc_channel_credentials* (*duplicate_without_call_credentials)( grpc_channel_credentials* c); @@ -108,17 +107,16 @@ struct grpc_channel_credentials { grpc_channel_credentials* grpc_channel_credentials_ref( grpc_channel_credentials* creds); -void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_channel_credentials* creds); +void grpc_channel_credentials_unref(grpc_channel_credentials* creds); /* Creates a security connector for the channel. May also create new channel args for the channel to be used in place of the passed in const args if returned non NULL. In that case the caller is responsible for destroying new_args after channel creation. */ grpc_security_status grpc_channel_credentials_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, - const char* target, const grpc_channel_args* args, - grpc_channel_security_connector** sc, grpc_channel_args** new_args); + grpc_channel_credentials* creds, const char* target, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args); /* Creates a version of the channel credentials without any attached call credentials. This can be used in order to open a channel to a non-trusted @@ -153,22 +151,19 @@ void grpc_credentials_mdelem_array_add(grpc_credentials_mdelem_array* list, void grpc_credentials_mdelem_array_append(grpc_credentials_mdelem_array* dst, grpc_credentials_mdelem_array* src); -void grpc_credentials_mdelem_array_destroy(grpc_exec_ctx* exec_ctx, - grpc_credentials_mdelem_array* list); +void grpc_credentials_mdelem_array_destroy(grpc_credentials_mdelem_array* list); /* --- grpc_call_credentials. --- */ typedef struct { - void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_call_credentials* c); - bool (*get_request_metadata)(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* c, + void (*destruct)(grpc_call_credentials* c); + bool (*get_request_metadata)(grpc_call_credentials* c, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error); - void (*cancel_get_request_metadata)(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* c, + void (*cancel_get_request_metadata)(grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, grpc_error* error); } grpc_call_credentials_vtable; @@ -180,39 +175,35 @@ struct grpc_call_credentials { }; grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds); -void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds); +void grpc_call_credentials_unref(grpc_call_credentials* creds); /// Returns true if completed synchronously, in which case \a error will /// be set to indicate the result. Otherwise, \a on_request_metadata will /// be invoked asynchronously when complete. \a md_array will be populated /// with the resulting metadata once complete. bool grpc_call_credentials_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context context, - grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error); + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, + grpc_closure* on_request_metadata, grpc_error** error); /// Cancels a pending asynchronous operation started by /// grpc_call_credentials_get_request_metadata() with the corresponding /// value of \a md_array. void grpc_call_credentials_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, - grpc_credentials_mdelem_array* md_array, grpc_error* error); + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, + grpc_error* error); /* Metadata-only credentials with the specified key and value where asynchronicity can be simulated for testing. */ grpc_call_credentials* grpc_md_only_test_credentials_create( - grpc_exec_ctx* exec_ctx, const char* md_key, const char* md_value, - bool is_async); + const char* md_key, const char* md_value, bool is_async); /* --- grpc_server_credentials. --- */ typedef struct { - void (*destruct)(grpc_exec_ctx* exec_ctx, grpc_server_credentials* c); + void (*destruct)(grpc_server_credentials* c); grpc_security_status (*create_security_connector)( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* c, - grpc_server_security_connector** sc); + grpc_server_credentials* c, grpc_server_security_connector** sc); } grpc_server_credentials_vtable; struct grpc_server_credentials { @@ -223,14 +214,12 @@ struct grpc_server_credentials { }; grpc_security_status grpc_server_credentials_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, - grpc_server_security_connector** sc); + grpc_server_credentials* creds, grpc_server_security_connector** sc); grpc_server_credentials* grpc_server_credentials_ref( grpc_server_credentials* creds); -void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, - grpc_server_credentials* creds); +void grpc_server_credentials_unref(grpc_server_credentials* creds); #define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials" @@ -250,6 +239,6 @@ grpc_credentials_metadata_request* grpc_credentials_metadata_request_create( grpc_call_credentials* creds); void grpc_credentials_metadata_request_destroy( - grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* r); + grpc_credentials_metadata_request* r); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/credentials_metadata.cc b/src/core/lib/security/credentials/credentials_metadata.cc index a3623fa1d6..9ceaf21139 100644 --- a/src/core/lib/security/credentials/credentials_metadata.cc +++ b/src/core/lib/security/credentials/credentials_metadata.cc @@ -52,9 +52,9 @@ void grpc_credentials_mdelem_array_append(grpc_credentials_mdelem_array* dst, } void grpc_credentials_mdelem_array_destroy( - grpc_exec_ctx* exec_ctx, grpc_credentials_mdelem_array* list) { + grpc_credentials_mdelem_array* list) { for (size_t i = 0; i < list->size; ++i) { - GRPC_MDELEM_UNREF(exec_ctx, list->md[i]); + GRPC_MDELEM_UNREF(list->md[i]); } gpr_free(list->md); } diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index a535a317ee..99b1214951 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -34,10 +34,9 @@ "grpc.fake_security.expected_targets" static grpc_security_status fake_transport_security_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { *sc = grpc_fake_channel_security_connector_create(c, call_creds, target, args); return GRPC_SECURITY_OK; @@ -45,8 +44,7 @@ static grpc_security_status fake_transport_security_create_security_connector( static grpc_security_status fake_transport_security_server_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* c, - grpc_server_security_connector** sc) { + grpc_server_credentials* c, grpc_server_security_connector** sc) { *sc = grpc_fake_server_security_connector_create(c); return GRPC_SECURITY_OK; } @@ -98,29 +96,27 @@ const char* grpc_fake_transport_get_expected_targets( /* -- Metadata-only test credentials. -- */ -static void md_only_test_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void md_only_test_destruct(grpc_call_credentials* creds) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; - GRPC_MDELEM_UNREF(exec_ctx, c->md); + GRPC_MDELEM_UNREF(c->md); } static bool md_only_test_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context context, - grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error) { + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, + grpc_closure* on_request_metadata, grpc_error** error) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)creds; grpc_credentials_mdelem_array_add(md_array, c->md); if (c->is_async) { - GRPC_CLOSURE_SCHED(exec_ctx, on_request_metadata, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_request_metadata, GRPC_ERROR_NONE); return false; } return true; } static void md_only_test_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -129,16 +125,14 @@ static grpc_call_credentials_vtable md_only_test_vtable = { md_only_test_cancel_get_request_metadata}; grpc_call_credentials* grpc_md_only_test_credentials_create( - grpc_exec_ctx* exec_ctx, const char* md_key, const char* md_value, - bool is_async) { + const char* md_key, const char* md_value, bool is_async) { grpc_md_only_test_credentials* c = (grpc_md_only_test_credentials*)gpr_zalloc( sizeof(grpc_md_only_test_credentials)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &md_only_test_vtable; gpr_ref_init(&c->base.refcount, 1); - c->md = - grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(md_key), - grpc_slice_from_copied_string(md_value)); + c->md = grpc_mdelem_from_slices(grpc_slice_from_copied_string(md_key), + grpc_slice_from_copied_string(md_value)); c->is_async = is_async; return &c->base; } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index f586c7b604..03d52850d9 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -58,8 +58,7 @@ typedef struct { grpc_http_response response; } compute_engine_detector; -static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_compute_engine_detection_http_response(void* user_data, grpc_error* error) { compute_engine_detector* detector = (compute_engine_detector*)user_data; if (error == GRPC_ERROR_NONE && detector->response.status == 200 && @@ -80,16 +79,16 @@ static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx, detector->is_done = 1; GRPC_LOG_IF_ERROR( "Pollset kick", - grpc_pollset_kick( - exec_ctx, grpc_polling_entity_pollset(&detector->pollent), nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&detector->pollent), + nullptr)); gpr_mu_unlock(g_polling_mu); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, grpc_error* e) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* e) { + grpc_pollset_destroy((grpc_pollset*)p); } -static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { +static int is_stack_running_on_compute_engine() { compute_engine_detector detector; grpc_httpcli_request request; grpc_httpcli_context context; @@ -115,14 +114,14 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { grpc_resource_quota* resource_quota = grpc_resource_quota_create("google_default_credentials"); grpc_httpcli_get( - exec_ctx, &context, &detector.pollent, resource_quota, &request, - grpc_exec_ctx_now(exec_ctx) + max_detection_delay, + &context, &detector.pollent, resource_quota, &request, + grpc_core::ExecCtx::Get()->Now() + max_detection_delay, GRPC_CLOSURE_CREATE(on_compute_engine_detection_http_response, &detector, grpc_schedule_on_exec_ctx), &detector.response); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ @@ -131,8 +130,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(exec_ctx, - grpc_polling_entity_pollset(&detector.pollent), + grpc_pollset_work(grpc_polling_entity_pollset(&detector.pollent), &worker, GRPC_MILLIS_INF_FUTURE))) { detector.is_done = 1; detector.success = 0; @@ -140,15 +138,14 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { } gpr_mu_unlock(g_polling_mu); - grpc_httpcli_context_destroy(exec_ctx, &context); + grpc_httpcli_context_destroy(&context); GRPC_CLOSURE_INIT(&destroy_closure, destroy_pollset, grpc_polling_entity_pollset(&detector.pollent), grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, - grpc_polling_entity_pollset(&detector.pollent), + grpc_pollset_shutdown(grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); g_polling_mu = nullptr; - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); grpc_http_response_destroy(&detector.response); @@ -158,7 +155,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { /* Takes ownership of creds_path if not NULL. */ static grpc_error* create_default_creds_from_path( - grpc_exec_ctx* exec_ctx, char* creds_path, grpc_call_credentials** creds) { + char* creds_path, grpc_call_credentials** creds) { grpc_json* json = nullptr; grpc_auth_json_key key; grpc_auth_refresh_token token; @@ -187,7 +184,7 @@ static grpc_error* create_default_creds_from_path( if (grpc_auth_json_key_is_valid(&key)) { result = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - exec_ctx, key, grpc_max_auth_token_lifetime()); + key, grpc_max_auth_token_lifetime()); if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_service_account_jwt_access_credentials_create_from_auth_json_" @@ -212,7 +209,7 @@ static grpc_error* create_default_creds_from_path( end: GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1); if (creds_path != nullptr) gpr_free(creds_path); - grpc_slice_unref_internal(exec_ctx, creds_data); + grpc_slice_unref_internal(creds_data); if (json != nullptr) grpc_json_destroy(json); *creds = result; return error; @@ -224,7 +221,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ()); @@ -239,22 +236,20 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { /* First, try the environment variable. */ err = create_default_creds_from_path( - &exec_ctx, gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds); + gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds); if (err == GRPC_ERROR_NONE) goto end; error = grpc_error_add_child(error, err); /* Then the well-known file. */ err = create_default_creds_from_path( - &exec_ctx, grpc_get_well_known_google_credentials_file_path(), - &call_creds); + grpc_get_well_known_google_credentials_file_path(), &call_creds); if (err == GRPC_ERROR_NONE) goto end; error = grpc_error_add_child(error, err); /* At last try to see if we're on compute engine (do the detection only once since it requires a network test). */ if (!compute_engine_detection_done) { - int need_compute_engine_creds = - is_stack_running_on_compute_engine(&exec_ctx); + int need_compute_engine_creds = is_stack_running_on_compute_engine(); compute_engine_detection_done = 1; if (need_compute_engine_creds) { call_creds = grpc_google_compute_engine_credentials_create(nullptr); @@ -278,8 +273,8 @@ end: grpc_composite_channel_credentials_create(ssl_creds, call_creds, nullptr)); GPR_ASSERT(default_credentials != nullptr); - grpc_channel_credentials_unref(&exec_ctx, ssl_creds); - grpc_call_credentials_unref(&exec_ctx, call_creds); + grpc_channel_credentials_unref(ssl_creds); + grpc_call_credentials_unref(call_creds); result = default_credentials; } else { gpr_log(GPR_ERROR, "Could not create google default credentials."); @@ -291,21 +286,20 @@ end: } else { GRPC_ERROR_UNREF(error); } - grpc_exec_ctx_finish(&exec_ctx); + return result; } void grpc_flush_cached_google_default_credentials(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); if (default_credentials != nullptr) { - grpc_channel_credentials_unref(&exec_ctx, default_credentials); + grpc_channel_credentials_unref(default_credentials); default_credentials = nullptr; } compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); - grpc_exec_ctx_finish(&exec_ctx); } /* -- Well known credentials path. -- */ diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 1741bf3068..75acb2a58e 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -27,14 +27,12 @@ #include #include -static void iam_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void iam_destruct(grpc_call_credentials* creds) { grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)creds; - grpc_credentials_mdelem_array_destroy(exec_ctx, &c->md_array); + grpc_credentials_mdelem_array_destroy(&c->md_array); } -static bool iam_get_request_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds, +static bool iam_get_request_metadata(grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -46,8 +44,8 @@ static bool iam_get_request_metadata(grpc_exec_ctx* exec_ctx, } static void iam_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -56,7 +54,7 @@ static grpc_call_credentials_vtable iam_vtable = { grpc_call_credentials* grpc_google_iam_credentials_create( const char* token, const char* authority_selector, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", @@ -70,17 +68,15 @@ grpc_call_credentials* grpc_google_iam_credentials_create( c->base.vtable = &iam_vtable; gpr_ref_init(&c->base.refcount, 1); grpc_mdelem md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY), grpc_slice_from_copied_string(token)); grpc_credentials_mdelem_array_add(&c->md_array, md); - GRPC_MDELEM_UNREF(&exec_ctx, md); + GRPC_MDELEM_UNREF(md); md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY), grpc_slice_from_copied_string(authority_selector)); grpc_credentials_mdelem_array_add(&c->md_array, md); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + return &c->base; } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 77163c0cc1..2404e860e4 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -30,9 +30,8 @@ #include #include -static void jwt_reset_cache(grpc_exec_ctx* exec_ctx, - grpc_service_account_jwt_access_credentials* c) { - GRPC_MDELEM_UNREF(exec_ctx, c->cached.jwt_md); +static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) { + GRPC_MDELEM_UNREF(c->cached.jwt_md); c->cached.jwt_md = GRPC_MDNULL; if (c->cached.service_url != nullptr) { gpr_free(c->cached.service_url); @@ -41,17 +40,15 @@ static void jwt_reset_cache(grpc_exec_ctx* exec_ctx, c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); } -static void jwt_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void jwt_destruct(grpc_call_credentials* creds) { grpc_service_account_jwt_access_credentials* c = (grpc_service_account_jwt_access_credentials*)creds; grpc_auth_json_key_destruct(&c->key); - jwt_reset_cache(exec_ctx, c); + jwt_reset_cache(c); gpr_mu_destroy(&c->cache_mu); } -static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds, +static bool jwt_get_request_metadata(grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -81,7 +78,7 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, char* jwt = nullptr; /* Generate a new jwt. */ gpr_mu_lock(&c->cache_mu); - jwt_reset_cache(exec_ctx, c); + jwt_reset_cache(c); jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url, c->jwt_lifetime, nullptr); if (jwt != nullptr) { @@ -92,7 +89,6 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c->jwt_lifetime); c->cached.service_url = gpr_strdup(context.service_url); c->cached.jwt_md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(md_value)); gpr_free(md_value); @@ -103,7 +99,7 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, if (!GRPC_MDISNULL(jwt_md)) { grpc_credentials_mdelem_array_add(md_array, jwt_md); - GRPC_MDELEM_UNREF(exec_ctx, jwt_md); + GRPC_MDELEM_UNREF(jwt_md); } else { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Could not generate JWT."); } @@ -111,8 +107,8 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, } static void jwt_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -121,8 +117,7 @@ static grpc_call_credentials_vtable jwt_vtable = { grpc_call_credentials* grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - grpc_exec_ctx* exec_ctx, grpc_auth_json_key key, - gpr_timespec token_lifetime) { + grpc_auth_json_key key, gpr_timespec token_lifetime) { grpc_service_account_jwt_access_credentials* c; if (!grpc_auth_json_key_is_valid(&key)) { gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); @@ -143,7 +138,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( } c->jwt_lifetime = token_lifetime; gpr_mu_init(&c->cache_mu); - jwt_reset_cache(exec_ctx, c); + jwt_reset_cache(c); return &c->base; } @@ -186,11 +181,10 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( gpr_free(clean_json); } GPR_ASSERT(reserved == nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - &exec_ctx, grpc_auth_json_key_create_from_string(json_key), - token_lifetime); - grpc_exec_ctx_finish(&exec_ctx); + grpc_auth_json_key_create_from_string(json_key), token_lifetime); + return creds; } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.h b/src/core/lib/security/credentials/jwt/jwt_credentials.h index 85f068aac8..f58a8b67ba 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.h +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.h @@ -42,7 +42,6 @@ typedef struct { // Takes ownership of the key. grpc_call_credentials* grpc_service_account_jwt_access_credentials_create_from_auth_json_key( - grpc_exec_ctx* exec_ctx, grpc_auth_json_key key, - gpr_timespec token_lifetime); + grpc_auth_json_key key, gpr_timespec token_lifetime); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 3709b83c4e..39339f07d7 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -74,12 +74,11 @@ static const EVP_MD* evp_md_from_alg(const char* alg) { } } -static grpc_json* parse_json_part_from_jwt(grpc_exec_ctx* exec_ctx, - const char* str, size_t len, +static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, grpc_slice* buffer) { grpc_json* json; - *buffer = grpc_base64_decode_with_len(exec_ctx, str, len, 1); + *buffer = grpc_base64_decode_with_len(str, len, 1); if (GRPC_SLICE_IS_EMPTY(*buffer)) { gpr_log(GPR_ERROR, "Invalid base64."); return nullptr; @@ -87,7 +86,7 @@ static grpc_json* parse_json_part_from_jwt(grpc_exec_ctx* exec_ctx, json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer), GRPC_SLICE_LENGTH(*buffer)); if (json == nullptr) { - grpc_slice_unref_internal(exec_ctx, *buffer); + grpc_slice_unref_internal(*buffer); gpr_log(GPR_ERROR, "JSON parsing error."); } return json; @@ -123,14 +122,13 @@ typedef struct { grpc_slice buffer; } jose_header; -static void jose_header_destroy(grpc_exec_ctx* exec_ctx, jose_header* h) { - grpc_slice_unref_internal(exec_ctx, h->buffer); +static void jose_header_destroy(jose_header* h) { + grpc_slice_unref_internal(h->buffer); gpr_free(h); } /* Takes ownership of json and buffer. */ -static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, - grpc_json* json, grpc_slice buffer) { +static jose_header* jose_header_from_json(grpc_json* json, grpc_slice buffer) { grpc_json* cur; jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header)); h->buffer = buffer; @@ -164,7 +162,7 @@ static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, error: grpc_json_destroy(json); - jose_header_destroy(exec_ctx, h); + jose_header_destroy(h); return nullptr; } @@ -184,9 +182,9 @@ struct grpc_jwt_claims { grpc_slice buffer; }; -void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims) { +void grpc_jwt_claims_destroy(grpc_jwt_claims* claims) { grpc_json_destroy(claims->json); - grpc_slice_unref_internal(exec_ctx, claims->buffer); + grpc_slice_unref_internal(claims->buffer); gpr_free(claims); } @@ -231,8 +229,7 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) { } /* Takes ownership of json and buffer even in case of failure. */ -grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, - grpc_json* json, grpc_slice buffer) { +grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer) { grpc_json* cur; grpc_jwt_claims* claims = (grpc_jwt_claims*)gpr_malloc(sizeof(grpc_jwt_claims)); @@ -274,7 +271,7 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, return claims; error: - grpc_jwt_claims_destroy(exec_ctx, claims); + grpc_jwt_claims_destroy(claims); return nullptr; } @@ -350,7 +347,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create( grpc_jwt_claims* claims, const char* audience, grpc_slice signature, const char* signed_jwt, size_t signed_jwt_len, void* user_data, grpc_jwt_verification_done_cb cb) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; verifier_cb_ctx* ctx = (verifier_cb_ctx*)gpr_zalloc(sizeof(verifier_cb_ctx)); ctx->verifier = verifier; ctx->pollent = grpc_polling_entity_create_from_pollset(pollset); @@ -361,16 +358,16 @@ static verifier_cb_ctx* verifier_cb_ctx_create( ctx->signed_data = grpc_slice_from_copied_buffer(signed_jwt, signed_jwt_len); ctx->user_data = user_data; ctx->user_cb = cb; - grpc_exec_ctx_finish(&exec_ctx); + return ctx; } -void verifier_cb_ctx_destroy(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { +void verifier_cb_ctx_destroy(verifier_cb_ctx* ctx) { if (ctx->audience != nullptr) gpr_free(ctx->audience); - if (ctx->claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); - grpc_slice_unref_internal(exec_ctx, ctx->signature); - grpc_slice_unref_internal(exec_ctx, ctx->signed_data); - jose_header_destroy(exec_ctx, ctx->header); + if (ctx->claims != nullptr) grpc_jwt_claims_destroy(ctx->claims); + grpc_slice_unref_internal(ctx->signature); + grpc_slice_unref_internal(ctx->signed_data); + jose_header_destroy(ctx->header); for (size_t i = 0; i < HTTP_RESPONSE_COUNT; i++) { grpc_http_response_destroy(&ctx->responses[i]); } @@ -450,19 +447,19 @@ end: return result; } -static BIGNUM* bignum_from_base64(grpc_exec_ctx* exec_ctx, const char* b64) { +static BIGNUM* bignum_from_base64(const char* b64) { BIGNUM* result = nullptr; grpc_slice bin; if (b64 == nullptr) return nullptr; - bin = grpc_base64_decode(exec_ctx, b64, 1); + bin = grpc_base64_decode(b64, 1); if (GRPC_SLICE_IS_EMPTY(bin)) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); return nullptr; } result = BN_bin2bn(GRPC_SLICE_START_PTR(bin), TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), nullptr); - grpc_slice_unref_internal(exec_ctx, bin); + grpc_slice_unref_internal(bin); return result; } @@ -495,8 +492,7 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { } #endif // OPENSSL_VERSION_NUMBER < 0x10100000L -static EVP_PKEY* pkey_from_jwk(grpc_exec_ctx* exec_ctx, const grpc_json* json, - const char* kty) { +static EVP_PKEY* pkey_from_jwk(const grpc_json* json, const char* kty) { const grpc_json* key_prop; RSA* rsa = nullptr; EVP_PKEY* result = nullptr; @@ -515,12 +511,10 @@ static EVP_PKEY* pkey_from_jwk(grpc_exec_ctx* exec_ctx, const grpc_json* json, } for (key_prop = json->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "n") == 0) { - tmp_n = - bignum_from_base64(exec_ctx, validate_string_field(key_prop, "n")); + tmp_n = bignum_from_base64(validate_string_field(key_prop, "n")); if (tmp_n == nullptr) goto end; } else if (strcmp(key_prop->key, "e") == 0) { - tmp_e = - bignum_from_base64(exec_ctx, validate_string_field(key_prop, "e")); + tmp_e = bignum_from_base64(validate_string_field(key_prop, "e")); if (tmp_e == nullptr) goto end; } } @@ -545,8 +539,7 @@ end: return result; } -static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, - const grpc_json* json, +static EVP_PKEY* find_verification_key(const grpc_json* json, const char* header_alg, const char* header_kid) { const grpc_json* jkey; @@ -591,7 +584,7 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, } if (alg != nullptr && kid != nullptr && kty != nullptr && strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) { - return pkey_from_jwk(exec_ctx, jkey, kty); + return pkey_from_jwk(jkey, kty); } } gpr_log(GPR_ERROR, @@ -632,8 +625,7 @@ end: return result; } -static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void on_keys_retrieved(void* user_data, grpc_error* error) { verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]); EVP_PKEY* verification_key = nullptr; @@ -645,7 +637,7 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, goto end; } verification_key = - find_verification_key(exec_ctx, json, ctx->header->alg, ctx->header->kid); + find_verification_key(json, ctx->header->alg, ctx->header->kid); if (verification_key == nullptr) { gpr_log(GPR_ERROR, "Could not find verification key with kid %s.", ctx->header->kid); @@ -669,12 +661,11 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, end: if (json != nullptr) grpc_json_destroy(json); EVP_PKEY_free(verification_key); - ctx->user_cb(exec_ctx, ctx->user_data, status, claims); - verifier_cb_ctx_destroy(exec_ctx, ctx); + ctx->user_cb(ctx->user_data, status, claims); + verifier_cb_ctx_destroy(ctx); } -static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void on_openid_config_retrieved(void* user_data, grpc_error* error) { const grpc_json* cur; verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; const grpc_http_response* response = &ctx->responses[HTTP_RESPONSE_OPENID]; @@ -711,20 +702,19 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); grpc_httpcli_get( - exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, - grpc_exec_ctx_now(exec_ctx) + grpc_jwt_verifier_max_delay, + &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, GRPC_CLOSURE_CREATE(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx), &ctx->responses[HTTP_RESPONSE_KEYS]); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); grpc_json_destroy(json); gpr_free(req.host); return; error: if (json != nullptr) grpc_json_destroy(json); - ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - nullptr); - verifier_cb_ctx_destroy(exec_ctx, ctx); + ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr); + verifier_cb_ctx_destroy(ctx); } static email_key_mapping* verifier_get_mapping(grpc_jwt_verifier* v, @@ -772,8 +762,7 @@ const char* grpc_jwt_issuer_email_domain(const char* issuer) { } /* Takes ownership of ctx. */ -static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, - verifier_cb_ctx* ctx) { +static void retrieve_key_and_verify(verifier_cb_ctx* ctx) { const char* email_domain; grpc_closure* http_cb; char* path_prefix = nullptr; @@ -840,23 +829,21 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, channel. This would allow us to cancel an authentication query when under extreme memory pressure. */ resource_quota = grpc_resource_quota_create("jwt_verifier"); - grpc_httpcli_get(exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, - resource_quota, &req, - grpc_exec_ctx_now(exec_ctx) + grpc_jwt_verifier_max_delay, - http_cb, &ctx->responses[rsp_idx]); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_httpcli_get( + &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + grpc_jwt_verifier_max_delay, http_cb, + &ctx->responses[rsp_idx]); + grpc_resource_quota_unref_internal(resource_quota); gpr_free(req.host); gpr_free(req.http.path); return; error: - ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - nullptr); - verifier_cb_ctx_destroy(exec_ctx, ctx); + ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr); + verifier_cb_ctx_destroy(ctx); } -void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, - grpc_jwt_verifier* verifier, +void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, grpc_pollset* pollset, const char* jwt, const char* audience, grpc_jwt_verification_done_cb cb, @@ -875,35 +862,32 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, cb != nullptr); dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), - &header_buffer); + json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer); if (json == nullptr) goto error; - header = jose_header_from_json(exec_ctx, json, header_buffer); + header = jose_header_from_json(json, header_buffer); if (header == nullptr) goto error; cur = dot + 1; dot = strchr(cur, '.'); if (dot == nullptr) goto error; - json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), - &claims_buffer); + json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer); if (json == nullptr) goto error; - claims = grpc_jwt_claims_from_json(exec_ctx, json, claims_buffer); + claims = grpc_jwt_claims_from_json(json, claims_buffer); if (claims == nullptr) goto error; signed_jwt_len = (size_t)(dot - jwt); cur = dot + 1; - signature = grpc_base64_decode(exec_ctx, cur, 1); + signature = grpc_base64_decode(cur, 1); if (GRPC_SLICE_IS_EMPTY(signature)) goto error; retrieve_key_and_verify( - exec_ctx, verifier_cb_ctx_create(verifier, pollset, header, claims, audience, signature, jwt, signed_jwt_len, user_data, cb)); return; error: - if (header != nullptr) jose_header_destroy(exec_ctx, header); - if (claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, claims); - cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); + if (header != nullptr) jose_header_destroy(header); + if (claims != nullptr) grpc_jwt_claims_destroy(claims); + cb(user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); } grpc_jwt_verifier* grpc_jwt_verifier_create( @@ -930,10 +914,10 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( return v; } -void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_verifier* v) { +void grpc_jwt_verifier_destroy(grpc_jwt_verifier* v) { size_t i; if (v == nullptr) return; - grpc_httpcli_context_destroy(exec_ctx, &v->http_ctx); + grpc_httpcli_context_destroy(&v->http_ctx); if (v->mappings != nullptr) { for (i = 0; i < v->num_mappings; i++) { gpr_free(v->mappings[i].email_domain); diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.h b/src/core/lib/security/credentials/jwt/jwt_verifier.h index 2aacd497c7..b3805e75cd 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.h +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.h @@ -51,7 +51,7 @@ const char* grpc_jwt_verifier_status_to_string(grpc_jwt_verifier_status status); typedef struct grpc_jwt_claims grpc_jwt_claims; -void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims); +void grpc_jwt_claims_destroy(grpc_jwt_claims* claims); /* Returns the whole JSON tree of the claims. */ const grpc_json* grpc_jwt_claims_json(const grpc_jwt_claims* claims); @@ -94,21 +94,18 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( size_t num_mappings); /*The verifier must not be destroyed if there are still outstanding callbacks.*/ -void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, - grpc_jwt_verifier* verifier); +void grpc_jwt_verifier_destroy(grpc_jwt_verifier* verifier); /* User provided callback that will be called when the verification of the JWT is done (maybe in another thread). It is the responsibility of the callee to call grpc_jwt_claims_destroy on the claims. */ -typedef void (*grpc_jwt_verification_done_cb)(grpc_exec_ctx* exec_ctx, - void* user_data, +typedef void (*grpc_jwt_verification_done_cb)(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims); /* Verifies for the JWT for the given expected audience. */ -void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, - grpc_jwt_verifier* verifier, +void grpc_jwt_verifier_verify(grpc_jwt_verifier* verifier, grpc_pollset* pollset, const char* jwt, const char* audience, grpc_jwt_verification_done_cb cb, @@ -116,8 +113,7 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, /* --- TESTING ONLY exposed functions. --- */ -grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, - grpc_json* json, grpc_slice buffer); +grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_json* json, grpc_slice buffer); grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, const char* audience); const char* grpc_jwt_issuer_email_domain(const char* issuer); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index ccefb4db9c..e243ea52c6 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -103,21 +103,19 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { // Oauth2 Token Fetcher credentials. // -static void oauth2_token_fetcher_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void oauth2_token_fetcher_destruct(grpc_call_credentials* creds) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; - GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md); + GRPC_MDELEM_UNREF(c->access_token_md); gpr_mu_destroy(&c->mu); - grpc_pollset_set_destroy(exec_ctx, - grpc_polling_entity_pollset_set(&c->pollent)); - grpc_httpcli_context_destroy(exec_ctx, &c->httpcli_context); + grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&c->pollent)); + grpc_httpcli_context_destroy(&c->httpcli_context); } grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - grpc_exec_ctx* exec_ctx, const grpc_http_response* response, - grpc_mdelem* token_md, grpc_millis* token_lifetime) { + const grpc_http_response* response, grpc_mdelem* token_md, + grpc_millis* token_lifetime) { char* null_terminated_body = nullptr; char* new_access_token = nullptr; grpc_credentials_status status = GRPC_CREDENTIALS_OK; @@ -184,9 +182,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( gpr_asprintf(&new_access_token, "%s %s", token_type->value, access_token->value); *token_lifetime = strtol(expires_in->value, nullptr, 10) * GPR_MS_PER_SEC; - if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(exec_ctx, *token_md); + if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(*token_md); *token_md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(new_access_token)); status = GRPC_CREDENTIALS_OK; @@ -194,7 +191,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( end: if (status != GRPC_CREDENTIALS_OK && !GRPC_MDISNULL(*token_md)) { - GRPC_MDELEM_UNREF(exec_ctx, *token_md); + GRPC_MDELEM_UNREF(*token_md); *token_md = GRPC_MDNULL; } if (null_terminated_body != nullptr) gpr_free(null_terminated_body); @@ -203,8 +200,7 @@ end: return status; } -static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_oauth2_token_fetcher_http_response(void* user_data, grpc_error* error) { GRPC_LOG_IF_ERROR("oauth_fetch", GRPC_ERROR_REF(error)); grpc_credentials_metadata_request* r = @@ -215,13 +211,13 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, grpc_millis token_lifetime; grpc_credentials_status status = grpc_oauth2_token_fetcher_credentials_parse_server_response( - exec_ctx, &r->response, &access_token_md, &token_lifetime); + &r->response, &access_token_md, &token_lifetime); // Update cache and grab list of pending requests. gpr_mu_lock(&c->mu); c->token_fetch_pending = false; c->access_token_md = GRPC_MDELEM_REF(access_token_md); c->token_expiration = status == GRPC_CREDENTIALS_OK - ? grpc_exec_ctx_now(exec_ctx) + token_lifetime + ? grpc_core::ExecCtx::Get()->Now() + token_lifetime : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; @@ -236,24 +232,22 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Error occured when fetching oauth2 token.", &error, 1); } - GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, error); + GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, error); grpc_polling_entity_del_from_pollset_set( - exec_ctx, pending_request->pollent, - grpc_polling_entity_pollset_set(&c->pollent)); + pending_request->pollent, grpc_polling_entity_pollset_set(&c->pollent)); grpc_oauth2_pending_get_request_metadata* prev = pending_request; pending_request = pending_request->next; gpr_free(prev); } - GRPC_MDELEM_UNREF(exec_ctx, access_token_md); - grpc_call_credentials_unref(exec_ctx, r->creds); - grpc_credentials_metadata_request_destroy(exec_ctx, r); + GRPC_MDELEM_UNREF(access_token_md); + grpc_call_credentials_unref(r->creds); + grpc_credentials_metadata_request_destroy(r); } static bool oauth2_token_fetcher_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context context, - grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error) { + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, + grpc_closure* on_request_metadata, grpc_error** error) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; // Check if we can use the cached token. @@ -262,13 +256,14 @@ static bool oauth2_token_fetcher_get_request_metadata( grpc_mdelem cached_access_token_md = GRPC_MDNULL; gpr_mu_lock(&c->mu); if (!GRPC_MDISNULL(c->access_token_md) && - (c->token_expiration - grpc_exec_ctx_now(exec_ctx) > refresh_threshold)) { + (c->token_expiration - grpc_core::ExecCtx::Get()->Now() > + refresh_threshold)) { cached_access_token_md = GRPC_MDELEM_REF(c->access_token_md); } if (!GRPC_MDISNULL(cached_access_token_md)) { gpr_mu_unlock(&c->mu); grpc_credentials_mdelem_array_add(md_array, cached_access_token_md); - GRPC_MDELEM_UNREF(exec_ctx, cached_access_token_md); + GRPC_MDELEM_UNREF(cached_access_token_md); return true; } // Couldn't get the token from the cache. @@ -280,7 +275,7 @@ static bool oauth2_token_fetcher_get_request_metadata( pending_request->on_request_metadata = on_request_metadata; pending_request->pollent = pollent; grpc_polling_entity_add_to_pollset_set( - exec_ctx, pollent, grpc_polling_entity_pollset_set(&c->pollent)); + pollent, grpc_polling_entity_pollset_set(&c->pollent)); pending_request->next = c->pending_requests; c->pending_requests = pending_request; bool start_fetch = false; @@ -291,17 +286,17 @@ static bool oauth2_token_fetcher_get_request_metadata( gpr_mu_unlock(&c->mu); if (start_fetch) { grpc_call_credentials_ref(creds); - c->fetch_func(exec_ctx, grpc_credentials_metadata_request_create(creds), + c->fetch_func(grpc_credentials_metadata_request_create(creds), &c->httpcli_context, &c->pollent, on_oauth2_token_fetcher_http_response, - grpc_exec_ctx_now(exec_ctx) + refresh_threshold); + grpc_core::ExecCtx::Get()->Now() + refresh_threshold); } return false; } static void oauth2_token_fetcher_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; gpr_mu_lock(&c->mu); @@ -317,7 +312,7 @@ static void oauth2_token_fetcher_cancel_get_request_metadata( c->pending_requests = pending_request->next; } // Invoke the callback immediately with an error. - GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, + GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, GRPC_ERROR_REF(error)); gpr_free(pending_request); break; @@ -351,7 +346,7 @@ static grpc_call_credentials_vtable compute_engine_vtable = { oauth2_token_fetcher_cancel_get_request_metadata}; static void compute_engine_fetch_oauth2( - grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req, + grpc_credentials_metadata_request* metadata_req, grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_http_header header = {(char*)"Metadata-Flavor", (char*)"Google"}; @@ -367,10 +362,10 @@ static void compute_engine_fetch_oauth2( grpc_resource_quota* resource_quota = grpc_resource_quota_create("oauth2_credentials"); grpc_httpcli_get( - exec_ctx, httpcli_context, pollent, resource_quota, &request, deadline, + httpcli_context, pollent, resource_quota, &request, deadline, GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx), &metadata_req->response); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); } grpc_call_credentials* grpc_google_compute_engine_credentials_create( @@ -390,12 +385,11 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( // Google Refresh Token credentials. // -static void refresh_token_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void refresh_token_destruct(grpc_call_credentials* creds) { grpc_google_refresh_token_credentials* c = (grpc_google_refresh_token_credentials*)creds; grpc_auth_refresh_token_destruct(&c->refresh_token); - oauth2_token_fetcher_destruct(exec_ctx, &c->base.base); + oauth2_token_fetcher_destruct(&c->base.base); } static grpc_call_credentials_vtable refresh_token_vtable = { @@ -403,7 +397,7 @@ static grpc_call_credentials_vtable refresh_token_vtable = { oauth2_token_fetcher_cancel_get_request_metadata}; static void refresh_token_fetch_oauth2( - grpc_exec_ctx* exec_ctx, grpc_credentials_metadata_request* metadata_req, + grpc_credentials_metadata_request* metadata_req, grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func response_cb, grpc_millis deadline) { grpc_google_refresh_token_credentials* c = @@ -427,11 +421,11 @@ static void refresh_token_fetch_oauth2( grpc_resource_quota* resource_quota = grpc_resource_quota_create("oauth2_credentials_refresh"); grpc_httpcli_post( - exec_ctx, httpcli_context, pollent, resource_quota, &request, body, - strlen(body), deadline, + httpcli_context, pollent, resource_quota, &request, body, strlen(body), + deadline, GRPC_CLOSURE_CREATE(response_cb, metadata_req, grpc_schedule_on_exec_ctx), &metadata_req->response); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_free(body); } @@ -483,25 +477,23 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( // Oauth2 Access Token credentials. // -static void access_token_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void access_token_destruct(grpc_call_credentials* creds) { grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; - GRPC_MDELEM_UNREF(exec_ctx, c->access_token_md); + GRPC_MDELEM_UNREF(c->access_token_md); } static bool access_token_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_polling_entity* pollent, grpc_auth_metadata_context context, - grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error) { + grpc_call_credentials* creds, grpc_polling_entity* pollent, + grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, + grpc_closure* on_request_metadata, grpc_error** error) { grpc_access_token_credentials* c = (grpc_access_token_credentials*)creds; grpc_credentials_mdelem_array_add(md_array, c->access_token_md); return true; } static void access_token_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* c, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -523,11 +515,11 @@ grpc_call_credentials* grpc_access_token_credentials_create( gpr_ref_init(&c->base.refcount, 1); char* token_md_value; gpr_asprintf(&token_md_value, "Bearer %s", access_token); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; c->access_token_md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), + grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY), grpc_slice_from_copied_string(token_md_value)); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(token_md_value); return &c->base; } diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index 627783d648..e5b8df8eb9 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -52,8 +52,7 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token); // This object is a base for credentials that need to acquire an oauth2 token // from an http service. -typedef void (*grpc_fetch_oauth2_func)(grpc_exec_ctx* exec_ctx, - grpc_credentials_metadata_request* req, +typedef void (*grpc_fetch_oauth2_func)(grpc_credentials_metadata_request* req, grpc_httpcli_context* http_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, @@ -99,7 +98,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( // Exposed for testing only. grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - grpc_exec_ctx* exec_ctx, const struct grpc_http_response* response, - grpc_mdelem* token_md, grpc_millis* token_lifetime); + const struct grpc_http_response* response, grpc_mdelem* token_md, + grpc_millis* token_lifetime); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_OAUTH2_OAUTH2_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 1f1efd078d..203ba58c67 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -33,8 +33,7 @@ grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials"); -static void plugin_destruct(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds) { +static void plugin_destruct(grpc_call_credentials* creds) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_destroy(&c->mu); if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { @@ -61,18 +60,17 @@ static void pending_request_remove_locked( // When this returns, r->cancelled indicates whether the request was // cancelled before completion. static void pending_request_complete( - grpc_exec_ctx* exec_ctx, grpc_plugin_credentials_pending_request* r) { + grpc_plugin_credentials_pending_request* r) { gpr_mu_lock(&r->creds->mu); if (!r->cancelled) pending_request_remove_locked(r->creds, r); gpr_mu_unlock(&r->creds->mu); // Ref to credentials not needed anymore. - grpc_call_credentials_unref(exec_ctx, &r->creds->base); + grpc_call_credentials_unref(&r->creds->base); } static grpc_error* process_plugin_result( - grpc_exec_ctx* exec_ctx, grpc_plugin_credentials_pending_request* r, - const grpc_metadata* md, size_t num_md, grpc_status_code status, - const char* error_details) { + grpc_plugin_credentials_pending_request* r, const grpc_metadata* md, + size_t num_md, grpc_status_code status, const char* error_details) { grpc_error* error = GRPC_ERROR_NONE; if (status != GRPC_STATUS_OK) { char* msg; @@ -100,11 +98,11 @@ static grpc_error* process_plugin_result( error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal metadata"); } else { for (size_t i = 0; i < num_md; ++i) { - grpc_mdelem mdelem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md[i].key), - grpc_slice_ref_internal(md[i].value)); + grpc_mdelem mdelem = + grpc_mdelem_from_slices(grpc_slice_ref_internal(md[i].key), + grpc_slice_ref_internal(md[i].value)); grpc_credentials_mdelem_array_add(r->md_array, mdelem); - GRPC_MDELEM_UNREF(exec_ctx, mdelem); + GRPC_MDELEM_UNREF(mdelem); } } } @@ -117,9 +115,8 @@ static void plugin_md_request_metadata_ready(void* request, grpc_status_code status, const char* error_details) { /* called from application code */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( - GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, - nullptr, nullptr); + grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED | + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (grpc_plugin_credentials_trace.enabled()) { @@ -129,12 +126,12 @@ static void plugin_md_request_metadata_ready(void* request, r->creds, r); } // Remove request from pending list if not previously cancelled. - pending_request_complete(&exec_ctx, r); + pending_request_complete(r); // If it has not been cancelled, process it. if (!r->cancelled) { grpc_error* error = - process_plugin_result(&exec_ctx, r, md, num_md, status, error_details); - GRPC_CLOSURE_SCHED(&exec_ctx, r->on_request_metadata, error); + process_plugin_result(r, md, num_md, status, error_details); + GRPC_CLOSURE_SCHED(r->on_request_metadata, error); } else if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin was previously " @@ -142,11 +139,9 @@ static void plugin_md_request_metadata_ready(void* request, r->creds, r); } gpr_free(r); - grpc_exec_ctx_finish(&exec_ctx); } -static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds, +static bool plugin_get_request_metadata(grpc_call_credentials* creds, grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, @@ -194,7 +189,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, } // Returned synchronously. // Remove request from pending list if not previously cancelled. - pending_request_complete(exec_ctx, pending_request); + pending_request_complete(pending_request); // If the request was cancelled, the error will have been returned // asynchronously by plugin_cancel_get_request_metadata(), so return // false. Otherwise, process the result. @@ -213,13 +208,13 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, "synchronously", c, pending_request); } - *error = process_plugin_result(exec_ctx, pending_request, creds_md, - num_creds_md, status, error_details); + *error = process_plugin_result(pending_request, creds_md, num_creds_md, + status, error_details); } // Clean up. for (size_t i = 0; i < num_creds_md; ++i) { - grpc_slice_unref_internal(exec_ctx, creds_md[i].key); - grpc_slice_unref_internal(exec_ctx, creds_md[i].value); + grpc_slice_unref_internal(creds_md[i].key); + grpc_slice_unref_internal(creds_md[i].value); } gpr_free((void*)error_details); gpr_free(pending_request); @@ -228,8 +223,8 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, } static void plugin_cancel_get_request_metadata( - grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, - grpc_credentials_mdelem_array* md_array, grpc_error* error) { + grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, + grpc_error* error) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = @@ -241,7 +236,7 @@ static void plugin_cancel_get_request_metadata( pending_request); } pending_request->cancelled = true; - GRPC_CLOSURE_SCHED(exec_ctx, pending_request->on_request_metadata, + GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, GRPC_ERROR_REF(error)); pending_request_remove_locked(c, pending_request); break; diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 39dd38cf88..d8546441c9 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -41,18 +41,16 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, gpr_free(kp); } -static void ssl_destruct(grpc_exec_ctx* exec_ctx, - grpc_channel_credentials* creds) { +static void ssl_destruct(grpc_channel_credentials* creds) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; gpr_free(c->config.pem_root_certs); grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1); } static grpc_security_status ssl_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* creds, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; grpc_security_status status = GRPC_SECURITY_OK; const char* overridden_target_name = nullptr; @@ -65,8 +63,7 @@ static grpc_security_status ssl_create_security_connector( } } status = grpc_ssl_channel_security_connector_create( - exec_ctx, creds, call_creds, &c->config, target, overridden_target_name, - sc); + creds, call_creds, &c->config, target, overridden_target_name, sc); if (status != GRPC_SECURITY_OK) { return status; } @@ -125,8 +122,7 @@ struct grpc_ssl_server_credentials_options { grpc_ssl_server_certificate_config_fetcher* certificate_config_fetcher; }; -static void ssl_server_destruct(grpc_exec_ctx* exec_ctx, - grpc_server_credentials* creds) { +static void ssl_server_destruct(grpc_server_credentials* creds) { grpc_ssl_server_credentials* c = (grpc_ssl_server_credentials*)creds; grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs, c->config.num_key_cert_pairs); @@ -134,9 +130,8 @@ static void ssl_server_destruct(grpc_exec_ctx* exec_ctx, } static grpc_security_status ssl_server_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, - grpc_server_security_connector** sc) { - return grpc_ssl_server_security_connector_create(exec_ctx, creds, sc); + grpc_server_credentials* creds, grpc_server_security_connector** sc) { + return grpc_ssl_server_security_connector_create(creds, sc); } static grpc_server_credentials_vtable ssl_server_vtable = { diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc index 326f4d7773..cd3c2e3f19 100644 --- a/src/core/lib/security/transport/client_auth_filter.cc +++ b/src/core/lib/security/transport/client_auth_filter.cc @@ -90,8 +90,7 @@ static void add_error(grpc_error** combined, grpc_error* error) { *combined = grpc_error_add_child(*combined, error); } -static void on_credentials_metadata(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* input_error) { +static void on_credentials_metadata(void* arg, grpc_error* input_error) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call_element* elem = (grpc_call_element*)batch->handler_private.extra_arg; @@ -105,16 +104,16 @@ static void on_credentials_metadata(grpc_exec_ctx* exec_ctx, void* arg, batch->payload->send_initial_metadata.send_initial_metadata; for (size_t i = 0; i < calld->md_array.size; ++i) { add_error(&error, grpc_metadata_batch_add_tail( - exec_ctx, mdb, &calld->md_links[i], + mdb, &calld->md_links[i], GRPC_MDELEM_REF(calld->md_array.md[i]))); } } if (error == GRPC_ERROR_NONE) { - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); } else { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED); - grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, batch, error, + grpc_transport_stream_op_batch_finish_with_failure(batch, error, calld->call_combiner); } } @@ -156,20 +155,17 @@ void grpc_auth_metadata_context_build( gpr_free(host_and_port); } -static void cancel_get_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void cancel_get_request_metadata(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { grpc_call_credentials_cancel_get_request_metadata( - exec_ctx, calld->creds, &calld->md_array, GRPC_ERROR_REF(error)); + calld->creds, &calld->md_array, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, - "cancel_get_request_metadata"); + GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_get_request_metadata"); } -static void send_security_metadata(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void send_security_metadata(grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -183,7 +179,7 @@ static void send_security_metadata(grpc_exec_ctx* exec_ctx, if (channel_call_creds == nullptr && !call_creds_has_md) { /* Skip sending metadata altogether. */ - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); return; } @@ -192,7 +188,7 @@ static void send_security_metadata(grpc_exec_ctx* exec_ctx, ctx->creds, nullptr); if (calld->creds == nullptr) { grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, batch, + batch, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Incompatible credentials set on channel and call."), @@ -215,30 +211,29 @@ static void send_security_metadata(grpc_exec_ctx* exec_ctx, batch, grpc_schedule_on_exec_ctx); grpc_error* error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - exec_ctx, calld->creds, calld->pollent, calld->auth_md_context, + calld->creds, calld->pollent, calld->auth_md_context, &calld->md_array, &calld->async_result_closure, &error)) { // Synchronous return; invoke on_credentials_metadata() directly. - on_credentials_metadata(exec_ctx, batch, error); + on_credentials_metadata(batch, error); GRPC_ERROR_UNREF(error); } else { // Async return; register cancellation closure with call combiner. GRPC_CALL_STACK_REF(calld->owning_call, "cancel_get_request_metadata"); grpc_call_combiner_set_notify_on_cancel( - exec_ctx, calld->call_combiner, + calld->call_combiner, GRPC_CLOSURE_INIT(&calld->get_request_metadata_cancel_closure, cancel_get_request_metadata, elem, grpc_schedule_on_exec_ctx)); } } -static void on_host_checked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_host_checked(void* arg, grpc_error* error) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call_element* elem = (grpc_call_element*)batch->handler_private.extra_arg; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - send_security_metadata(exec_ctx, elem, batch); + send_security_metadata(elem, batch); } else { char* error_msg; char* host = grpc_slice_to_c_string(calld->host); @@ -246,7 +241,7 @@ static void on_host_checked(grpc_exec_ctx* exec_ctx, void* arg, host); gpr_free(host); grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, batch, + batch, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED), @@ -255,22 +250,20 @@ static void on_host_checked(grpc_exec_ctx* exec_ctx, void* arg, } } -static void cancel_check_call_host(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void cancel_check_call_host(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; if (error != GRPC_ERROR_NONE) { grpc_channel_security_connector_cancel_check_call_host( - exec_ctx, chand->security_connector, &calld->async_result_closure, + chand->security_connector, &calld->async_result_closure, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_check_call_host"); + GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_check_call_host"); } static void auth_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { GPR_TIMER_BEGIN("auth_start_transport_stream_op_batch", 0); /* grab pointers to our data from the call element */ @@ -303,13 +296,13 @@ static void auth_start_transport_stream_op_batch( */ if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { if (calld->have_host) { - grpc_slice_unref_internal(exec_ctx, calld->host); + grpc_slice_unref_internal(calld->host); } calld->host = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_host = true; } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { if (calld->have_method) { - grpc_slice_unref_internal(exec_ctx, calld->method); + grpc_slice_unref_internal(calld->method); } calld->method = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_method = true; @@ -322,16 +315,16 @@ static void auth_start_transport_stream_op_batch( char* call_host = grpc_slice_to_c_string(calld->host); grpc_error* error = GRPC_ERROR_NONE; if (grpc_channel_security_connector_check_call_host( - exec_ctx, chand->security_connector, call_host, - chand->auth_context, &calld->async_result_closure, &error)) { + chand->security_connector, call_host, chand->auth_context, + &calld->async_result_closure, &error)) { // Synchronous return; invoke on_host_checked() directly. - on_host_checked(exec_ctx, batch, error); + on_host_checked(batch, error); GRPC_ERROR_UNREF(error); } else { // Async return; register cancellation closure with call combiner. GRPC_CALL_STACK_REF(calld->owning_call, "cancel_check_call_host"); grpc_call_combiner_set_notify_on_cancel( - exec_ctx, calld->call_combiner, + calld->call_combiner, GRPC_CLOSURE_INIT(&calld->check_call_host_cancel_closure, cancel_check_call_host, elem, grpc_schedule_on_exec_ctx)); @@ -343,13 +336,12 @@ static void auth_start_transport_stream_op_batch( } /* pass control down the stack */ - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); GPR_TIMER_END("auth_start_transport_stream_op_batch", 0); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; calld->owning_call = args->call_stack; @@ -357,32 +349,30 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void set_pollset_or_pollset_set(grpc_call_element* elem, grpc_polling_entity* pollent) { call_data* calld = (call_data*)elem->call_data; calld->pollent = pollent; } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { call_data* calld = (call_data*)elem->call_data; - grpc_credentials_mdelem_array_destroy(exec_ctx, &calld->md_array); - grpc_call_credentials_unref(exec_ctx, calld->creds); + grpc_credentials_mdelem_array_destroy(&calld->md_array); + grpc_call_credentials_unref(calld->creds); if (calld->have_host) { - grpc_slice_unref_internal(exec_ctx, calld->host); + grpc_slice_unref_internal(calld->host); } if (calld->have_method) { - grpc_slice_unref_internal(exec_ctx, calld->method); + grpc_slice_unref_internal(calld->method); } grpc_auth_metadata_context_reset(&calld->auth_md_context); } /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { grpc_security_connector* sc = grpc_security_connector_find_in_args(args->channel_args); @@ -415,13 +405,12 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { /* grab pointers to our data from the channel element */ channel_data* chand = (channel_data*)elem->channel_data; grpc_channel_security_connector* sc = chand->security_connector; if (sc != nullptr) { - GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "client_auth_filter"); + GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter"); } GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter"); } diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc index c07be35840..183b1ebf35 100644 --- a/src/core/lib/security/transport/lb_targets_info.cc +++ b/src/core/lib/security/transport/lb_targets_info.cc @@ -28,8 +28,8 @@ static void* targets_info_copy(void* p) { return grpc_slice_hash_table_ref((grpc_slice_hash_table*)p); } -static void targets_info_destroy(grpc_exec_ctx* exec_ctx, void* p) { - grpc_slice_hash_table_unref(exec_ctx, (grpc_slice_hash_table*)p); +static void targets_info_destroy(void* p) { + grpc_slice_hash_table_unref((grpc_slice_hash_table*)p); } static int targets_info_cmp(void* a, void* b) { return grpc_slice_hash_table_cmp((const grpc_slice_hash_table*)a, diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index 4cd317a06d..e5c089de9c 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -63,28 +63,27 @@ typedef struct { grpc_core::TraceFlag grpc_trace_secure_endpoint(false, "secure_endpoint"); -static void destroy(grpc_exec_ctx* exec_ctx, secure_endpoint* secure_ep) { +static void destroy(secure_endpoint* secure_ep) { secure_endpoint* ep = secure_ep; - grpc_endpoint_destroy(exec_ctx, ep->wrapped_ep); + grpc_endpoint_destroy(ep->wrapped_ep); tsi_frame_protector_destroy(ep->protector); - tsi_zero_copy_grpc_protector_destroy(exec_ctx, ep->zero_copy_protector); - grpc_slice_buffer_destroy_internal(exec_ctx, &ep->leftover_bytes); - grpc_slice_unref_internal(exec_ctx, ep->read_staging_buffer); - grpc_slice_unref_internal(exec_ctx, ep->write_staging_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &ep->output_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &ep->source_buffer); + tsi_zero_copy_grpc_protector_destroy(ep->zero_copy_protector); + grpc_slice_buffer_destroy_internal(&ep->leftover_bytes); + grpc_slice_unref_internal(ep->read_staging_buffer); + grpc_slice_unref_internal(ep->write_staging_buffer); + grpc_slice_buffer_destroy_internal(&ep->output_buffer); + grpc_slice_buffer_destroy_internal(&ep->source_buffer); gpr_mu_destroy(&ep->protector_mu); gpr_free(ep); } #ifndef NDEBUG -#define SECURE_ENDPOINT_UNREF(exec_ctx, ep, reason) \ - secure_endpoint_unref((exec_ctx), (ep), (reason), __FILE__, __LINE__) +#define SECURE_ENDPOINT_UNREF(ep, reason) \ + secure_endpoint_unref((ep), (reason), __FILE__, __LINE__) #define SECURE_ENDPOINT_REF(ep, reason) \ secure_endpoint_ref((ep), (reason), __FILE__, __LINE__) -static void secure_endpoint_unref(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, - const char* reason, const char* file, - int line) { +static void secure_endpoint_unref(secure_endpoint* ep, const char* reason, + const char* file, int line) { if (grpc_trace_secure_endpoint.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -92,7 +91,7 @@ static void secure_endpoint_unref(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, val - 1); } if (gpr_unref(&ep->ref)) { - destroy(exec_ctx, ep); + destroy(ep); } } @@ -107,13 +106,11 @@ static void secure_endpoint_ref(secure_endpoint* ep, const char* reason, gpr_ref(&ep->ref); } #else -#define SECURE_ENDPOINT_UNREF(exec_ctx, ep, reason) \ - secure_endpoint_unref((exec_ctx), (ep)) +#define SECURE_ENDPOINT_UNREF(ep, reason) secure_endpoint_unref((ep)) #define SECURE_ENDPOINT_REF(ep, reason) secure_endpoint_ref((ep)) -static void secure_endpoint_unref(grpc_exec_ctx* exec_ctx, - secure_endpoint* ep) { +static void secure_endpoint_unref(secure_endpoint* ep) { if (gpr_unref(&ep->ref)) { - destroy(exec_ctx, ep); + destroy(ep); } } @@ -128,8 +125,7 @@ static void flush_read_staging_buffer(secure_endpoint* ep, uint8_t** cur, *end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); } -static void call_read_cb(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, - grpc_error* error) { +static void call_read_cb(secure_endpoint* ep, grpc_error* error) { if (grpc_trace_secure_endpoint.enabled()) { size_t i; for (i = 0; i < ep->read_buffer->count; i++) { @@ -140,12 +136,11 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, } } ep->read_buffer = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, ep->read_cb, error); - SECURE_ENDPOINT_UNREF(exec_ctx, ep, "read"); + GRPC_CLOSURE_SCHED(ep->read_cb, error); + SECURE_ENDPOINT_UNREF(ep, "read"); } -static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void on_read(void* user_data, grpc_error* error) { unsigned i; uint8_t keep_looping = 0; tsi_result result = TSI_OK; @@ -154,17 +149,16 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, uint8_t* end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); - call_read_cb(exec_ctx, ep, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Secure read failed", &error, 1)); + grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); + call_read_cb(ep, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Secure read failed", &error, 1)); return; } if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to unprotect. result = tsi_zero_copy_grpc_protector_unprotect( - exec_ctx, ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer); + ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer); } else { // Use frame protector to unprotect. /* TODO(yangg) check error, maybe bail out early */ @@ -217,37 +211,35 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, /* TODO(yangg) experiment with moving this block after read_cb to see if it helps latency */ - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->source_buffer); + grpc_slice_buffer_reset_and_unref_internal(&ep->source_buffer); if (result != TSI_OK) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); call_read_cb( - exec_ctx, ep, - grpc_set_tsi_error_result( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unwrap failed"), result)); + ep, grpc_set_tsi_error_result( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unwrap failed"), result)); return; } - call_read_cb(exec_ctx, ep, GRPC_ERROR_NONE); + call_read_cb(ep, GRPC_ERROR_NONE); } -static void endpoint_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void endpoint_read(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, + grpc_closure* cb) { secure_endpoint* ep = (secure_endpoint*)secure_ep; ep->read_cb = cb; ep->read_buffer = slices; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, ep->read_buffer); + grpc_slice_buffer_reset_and_unref_internal(ep->read_buffer); SECURE_ENDPOINT_REF(ep, "read"); if (ep->leftover_bytes.count) { grpc_slice_buffer_swap(&ep->leftover_bytes, &ep->source_buffer); GPR_ASSERT(ep->leftover_bytes.count == 0); - on_read(exec_ctx, ep, GRPC_ERROR_NONE); + on_read(ep, GRPC_ERROR_NONE); return; } - grpc_endpoint_read(exec_ctx, ep->wrapped_ep, &ep->source_buffer, - &ep->on_read); + grpc_endpoint_read(ep->wrapped_ep, &ep->source_buffer, &ep->on_read); } static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur, @@ -258,8 +250,8 @@ static void flush_write_staging_buffer(secure_endpoint* ep, uint8_t** cur, *end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); } -static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices, + grpc_closure* cb) { GPR_TIMER_BEGIN("secure_endpoint.endpoint_write", 0); unsigned i; @@ -268,7 +260,7 @@ static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, uint8_t* cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer); uint8_t* end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer); + grpc_slice_buffer_reset_and_unref_internal(&ep->output_buffer); if (grpc_trace_secure_endpoint.enabled()) { for (i = 0; i < slices->count; i++) { @@ -281,8 +273,8 @@ static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to protect. - result = tsi_zero_copy_grpc_protector_protect( - exec_ctx, ep->zero_copy_protector, slices, &ep->output_buffer); + result = tsi_zero_copy_grpc_protector_protect(ep->zero_copy_protector, + slices, &ep->output_buffer); } else { // Use frame protector to protect. for (i = 0; i < slices->count; i++) { @@ -340,50 +332,44 @@ static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, if (result != TSI_OK) { /* TODO(yangg) do different things according to the error type? */ - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer); + grpc_slice_buffer_reset_and_unref_internal(&ep->output_buffer); GRPC_CLOSURE_SCHED( - exec_ctx, cb, - grpc_set_tsi_error_result( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result)); + cb, grpc_set_tsi_error_result( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Wrap failed"), result)); GPR_TIMER_END("secure_endpoint.endpoint_write", 0); return; } - grpc_endpoint_write(exec_ctx, ep->wrapped_ep, &ep->output_buffer, cb); + grpc_endpoint_write(ep->wrapped_ep, &ep->output_buffer, cb); GPR_TIMER_END("secure_endpoint.endpoint_write", 0); } -static void endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, - grpc_error* why) { +static void endpoint_shutdown(grpc_endpoint* secure_ep, grpc_error* why) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_shutdown(exec_ctx, ep->wrapped_ep, why); + grpc_endpoint_shutdown(ep->wrapped_ep, why); } -static void endpoint_destroy(grpc_exec_ctx* exec_ctx, - grpc_endpoint* secure_ep) { +static void endpoint_destroy(grpc_endpoint* secure_ep) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - SECURE_ENDPOINT_UNREF(exec_ctx, ep, "destroy"); + SECURE_ENDPOINT_UNREF(ep, "destroy"); } -static void endpoint_add_to_pollset(grpc_exec_ctx* exec_ctx, - grpc_endpoint* secure_ep, +static void endpoint_add_to_pollset(grpc_endpoint* secure_ep, grpc_pollset* pollset) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_add_to_pollset(exec_ctx, ep->wrapped_ep, pollset); + grpc_endpoint_add_to_pollset(ep->wrapped_ep, pollset); } -static void endpoint_add_to_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* secure_ep, +static void endpoint_add_to_pollset_set(grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_add_to_pollset_set(exec_ctx, ep->wrapped_ep, pollset_set); + grpc_endpoint_add_to_pollset_set(ep->wrapped_ep, pollset_set); } -static void endpoint_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* secure_ep, +static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep, grpc_pollset_set* pollset_set) { secure_endpoint* ep = (secure_endpoint*)secure_ep; - grpc_endpoint_delete_from_pollset_set(exec_ctx, ep->wrapped_ep, pollset_set); + grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set); } static char* endpoint_get_peer(grpc_endpoint* secure_ep) { diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index c56e459aeb..fd139714da 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -105,33 +105,32 @@ const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, } void grpc_channel_security_connector_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, + grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr) { if (connector != nullptr) { - connector->add_handshakers(exec_ctx, connector, handshake_mgr); + connector->add_handshakers(connector, handshake_mgr); } } void grpc_server_security_connector_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_server_security_connector* connector, + grpc_server_security_connector* connector, grpc_handshake_manager* handshake_mgr) { if (connector != nullptr) { - connector->add_handshakers(exec_ctx, connector, handshake_mgr); + connector->add_handshakers(connector, handshake_mgr); } } -void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, +void grpc_security_connector_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { if (sc == nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, + GRPC_CLOSURE_SCHED(on_peer_checked, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check peer -- no security connector")); tsi_peer_destruct(&peer); } else { - sc->vtable->check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); + sc->vtable->check_peer(sc, peer, auth_context, on_peer_checked); } } @@ -169,26 +168,26 @@ int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, } bool grpc_channel_security_connector_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - const char* host, grpc_auth_context* auth_context, - grpc_closure* on_call_host_checked, grpc_error** error) { + grpc_channel_security_connector* sc, const char* host, + grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, + grpc_error** error) { if (sc == nullptr || sc->check_call_host == nullptr) { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check call host -- no security connector"); return true; } - return sc->check_call_host(exec_ctx, sc, host, auth_context, - on_call_host_checked, error); + return sc->check_call_host(sc, host, auth_context, on_call_host_checked, + error); } void grpc_channel_security_connector_cancel_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - grpc_closure* on_call_host_checked, grpc_error* error) { + grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, + grpc_error* error) { if (sc == nullptr || sc->cancel_check_call_host == nullptr) { GRPC_ERROR_UNREF(error); return; } - sc->cancel_check_call_host(exec_ctx, sc, on_call_host_checked, error); + sc->cancel_check_call_host(sc, on_call_host_checked, error); } #ifndef NDEBUG @@ -205,15 +204,14 @@ grpc_security_connector* grpc_security_connector_ref( #else grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* sc) { - if (sc == NULL) return NULL; + if (sc == nullptr) return nullptr; #endif gpr_ref(&sc->refcount); return sc; } #ifndef NDEBUG -void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, +void grpc_security_connector_unref(grpc_security_connector* sc, const char* file, int line, const char* reason) { if (sc == nullptr) return; @@ -224,15 +222,14 @@ void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, val, val - 1, reason); } #else -void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { - if (sc == NULL) return; +void grpc_security_connector_unref(grpc_security_connector* sc) { + if (sc == nullptr) return; #endif - if (gpr_unref(&sc->refcount)) sc->vtable->destroy(exec_ctx, sc); + if (gpr_unref(&sc->refcount)) sc->vtable->destroy(sc); } -static void connector_arg_destroy(grpc_exec_ctx* exec_ctx, void* p) { - GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, (grpc_security_connector*)p, +static void connector_arg_destroy(void* p) { + GRPC_SECURITY_CONNECTOR_UNREF((grpc_security_connector*)p, "connector_arg_destroy"); } @@ -309,20 +306,16 @@ typedef struct { bool is_lb_channel; } grpc_fake_channel_security_connector; -static void fake_channel_destroy(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { +static void fake_channel_destroy(grpc_security_connector* sc) { grpc_fake_channel_security_connector* c = (grpc_fake_channel_security_connector*)sc; - grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); + grpc_call_credentials_unref(c->base.request_metadata_creds); gpr_free(c->target); gpr_free(c->expected_targets); gpr_free(c); } -static void fake_server_destroy(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { - gpr_free(sc); -} +static void fake_server_destroy(grpc_security_connector* sc) { gpr_free(sc); } static bool fake_check_target(const char* target_type, const char* target, const char* set_str) { @@ -386,8 +379,7 @@ done: if (!success) abort(); } -static void fake_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { const char* prop_name; @@ -419,25 +411,23 @@ static void fake_check_peer(grpc_exec_ctx* exec_ctx, *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_FAKE_TRANSPORT_SECURITY_TYPE); end: - GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); + GRPC_CLOSURE_SCHED(on_peer_checked, error); tsi_peer_destruct(&peer); } -static void fake_channel_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); + fake_check_peer(sc, peer, auth_context, on_peer_checked); grpc_fake_channel_security_connector* c = (grpc_fake_channel_security_connector*)sc; fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel); } -static void fake_server_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked); + fake_check_peer(sc, peer, auth_context, on_peer_checked); } static int fake_channel_cmp(grpc_security_connector* sc1, @@ -466,8 +456,7 @@ static int fake_server_cmp(grpc_security_connector* sc1, (grpc_server_security_connector*)sc2); } -static bool fake_channel_check_call_host(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, +static bool fake_channel_check_call_host(grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, @@ -476,29 +465,26 @@ static bool fake_channel_check_call_host(grpc_exec_ctx* exec_ctx, } static void fake_channel_cancel_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - grpc_closure* on_call_host_checked, grpc_error* error) { + grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, + grpc_error* error) { GRPC_ERROR_UNREF(error); } static void fake_channel_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, + grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add( handshake_mgr, grpc_security_handshaker_create( - exec_ctx, tsi_create_fake_handshaker(true /* is_client */), - &sc->base)); + tsi_create_fake_handshaker(true /* is_client */), &sc->base)); } -static void fake_server_add_handshakers(grpc_exec_ctx* exec_ctx, - grpc_server_security_connector* sc, +static void fake_server_add_handshakers(grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_handshake_manager_add( handshake_mgr, grpc_security_handshaker_create( - exec_ctx, tsi_create_fake_handshaker(false /* is_client */), - &sc->base)); + tsi_create_fake_handshaker(false /* is_client */), &sc->base)); } static grpc_security_connector_vtable fake_channel_vtable = { @@ -565,12 +551,11 @@ static bool server_connector_has_cert_config_fetcher( return server_creds->certificate_config_fetcher.cb != nullptr; } -static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { +static void ssl_channel_destroy(grpc_security_connector* sc) { grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; - grpc_channel_credentials_unref(exec_ctx, c->base.channel_creds); - grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); + grpc_channel_credentials_unref(c->base.channel_creds); + grpc_call_credentials_unref(c->base.request_metadata_creds); tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory); c->client_handshaker_factory = nullptr; if (c->target_name != nullptr) gpr_free(c->target_name); @@ -578,18 +563,16 @@ static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, gpr_free(sc); } -static void ssl_server_destroy(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc) { +static void ssl_server_destroy(grpc_security_connector* sc) { grpc_ssl_server_security_connector* c = (grpc_ssl_server_security_connector*)sc; - grpc_server_credentials_unref(exec_ctx, c->base.server_creds); + grpc_server_credentials_unref(c->base.server_creds); tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory); c->server_handshaker_factory = nullptr; gpr_free(sc); } -static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, +static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; @@ -607,9 +590,8 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, - grpc_security_handshaker_create( - exec_ctx, tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, grpc_security_handshaker_create( + tsi_create_adapter_handshaker(tsi_hs), &sc->base)); } static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { @@ -701,8 +683,7 @@ static bool try_fetch_ssl_server_credentials( return status; } -static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, - grpc_server_security_connector* sc, +static void ssl_server_add_handshakers(grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr) { grpc_ssl_server_security_connector* c = (grpc_ssl_server_security_connector*)sc; @@ -718,9 +699,8 @@ static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, - grpc_security_handshaker_create( - exec_ctx, tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, grpc_security_handshaker_create( + tsi_create_adapter_handshaker(tsi_hs), &sc->base)); } static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { @@ -804,8 +784,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, return GRPC_ERROR_NONE; } -static void ssl_channel_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_ssl_channel_security_connector* c = @@ -815,17 +794,16 @@ static void ssl_channel_check_peer(grpc_exec_ctx* exec_ctx, ? c->overridden_target_name : c->target_name, &peer, auth_context); - GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); + GRPC_CLOSURE_SCHED(on_peer_checked, error); tsi_peer_destruct(&peer); } -static void ssl_server_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, tsi_peer peer, +static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { grpc_error* error = ssl_check_peer(sc, nullptr, &peer, auth_context); tsi_peer_destruct(&peer); - GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); + GRPC_CLOSURE_SCHED(on_peer_checked, error); } static int ssl_channel_cmp(grpc_security_connector* sc1, @@ -895,8 +873,7 @@ void tsi_shallow_peer_destruct(tsi_peer* peer) { if (peer->properties != nullptr) gpr_free(peer->properties); } -static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, +static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, @@ -922,8 +899,8 @@ static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, } static void ssl_channel_cancel_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - grpc_closure* on_call_host_checked, grpc_error* error) { + grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, + grpc_error* error) { GRPC_ERROR_UNREF(error); } @@ -990,7 +967,7 @@ const char* grpc_get_default_ssl_roots(void) { } grpc_security_status grpc_ssl_channel_security_connector_create( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, + grpc_channel_credentials* channel_creds, grpc_call_credentials* request_metadata_creds, const grpc_ssl_config* config, const char* target_name, const char* overridden_target_name, grpc_channel_security_connector** sc) { @@ -1045,7 +1022,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); - ssl_channel_destroy(exec_ctx, &c->base.base); + ssl_channel_destroy(&c->base.base); *sc = nullptr; goto error; } @@ -1073,8 +1050,7 @@ grpc_ssl_server_security_connector_initialize( } grpc_security_status grpc_ssl_server_security_connector_create( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* gsc, - grpc_server_security_connector** sc) { + grpc_server_credentials* gsc, grpc_server_security_connector** sc) { tsi_result result = TSI_OK; grpc_ssl_server_credentials* server_credentials = (grpc_ssl_server_credentials*)gsc; @@ -1114,7 +1090,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( if (retval == GRPC_SECURITY_OK) { *sc = &c->base; } else { - if (c != nullptr) ssl_server_destroy(exec_ctx, &c->base.base); + if (c != nullptr) ssl_server_destroy(&c->base.base); if (sc != nullptr) *sc = nullptr; } return retval; diff --git a/src/core/lib/security/transport/security_connector.h b/src/core/lib/security/transport/security_connector.h index 03daba3a18..495821d247 100644 --- a/src/core/lib/security/transport/security_connector.h +++ b/src/core/lib/security/transport/security_connector.h @@ -50,9 +50,9 @@ typedef struct grpc_security_connector grpc_security_connector; #define GRPC_ARG_SECURITY_CONNECTOR "grpc.security_connector" typedef struct { - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc); - void (*check_peer)(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, - tsi_peer peer, grpc_auth_context** auth_context, + void (*destroy)(grpc_security_connector* sc); + void (*check_peer)(grpc_security_connector* sc, tsi_peer peer, + grpc_auth_context** auth_context, grpc_closure* on_peer_checked); int (*cmp)(grpc_security_connector* sc, grpc_security_connector* other); } grpc_security_connector_vtable; @@ -67,29 +67,25 @@ struct grpc_security_connector { #ifndef NDEBUG #define GRPC_SECURITY_CONNECTOR_REF(p, r) \ grpc_security_connector_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, p, r) \ - grpc_security_connector_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) +#define GRPC_SECURITY_CONNECTOR_UNREF(p, r) \ + grpc_security_connector_unref((p), __FILE__, __LINE__, (r)) grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* policy, const char* file, int line, const char* reason); -void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, - grpc_security_connector* policy, +void grpc_security_connector_unref(grpc_security_connector* policy, const char* file, int line, const char* reason); #else #define GRPC_SECURITY_CONNECTOR_REF(p, r) grpc_security_connector_ref((p)) -#define GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, p, r) \ - grpc_security_connector_unref((exec_ctx), (p)) +#define GRPC_SECURITY_CONNECTOR_UNREF(p, r) grpc_security_connector_unref((p)) grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* policy); -void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, - grpc_security_connector* policy); +void grpc_security_connector_unref(grpc_security_connector* policy); #endif /* Check the peer. Callee takes ownership of the peer object. When done, sets *auth_context and invokes on_peer_checked. */ -void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, - grpc_security_connector* sc, +void grpc_security_connector_check_peer(grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked); @@ -119,17 +115,14 @@ struct grpc_channel_security_connector { grpc_security_connector base; grpc_channel_credentials* channel_creds; grpc_call_credentials* request_metadata_creds; - bool (*check_call_host)(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, const char* host, + bool (*check_call_host)(grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, grpc_error** error); - void (*cancel_check_call_host)(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, + void (*cancel_check_call_host)(grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, grpc_error* error); - void (*add_handshakers)(grpc_exec_ctx* exec_ctx, - grpc_channel_security_connector* sc, + void (*add_handshakers)(grpc_channel_security_connector* sc, grpc_handshake_manager* handshake_mgr); }; @@ -142,20 +135,20 @@ int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, /// be set to indicate the result. Otherwise, \a on_call_host_checked /// will be invoked when complete. bool grpc_channel_security_connector_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - const char* host, grpc_auth_context* auth_context, - grpc_closure* on_call_host_checked, grpc_error** error); + grpc_channel_security_connector* sc, const char* host, + grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, + grpc_error** error); /// Cancels a pending asychronous call to /// grpc_channel_security_connector_check_call_host() with /// \a on_call_host_checked as its callback. void grpc_channel_security_connector_cancel_check_call_host( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, - grpc_closure* on_call_host_checked, grpc_error* error); + grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, + grpc_error* error); /* Registers handshakers with \a handshake_mgr. */ void grpc_channel_security_connector_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, + grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr); /* --- server_security_connector object. --- @@ -168,8 +161,7 @@ typedef struct grpc_server_security_connector grpc_server_security_connector; struct grpc_server_security_connector { grpc_security_connector base; grpc_server_credentials* server_creds; - void (*add_handshakers)(grpc_exec_ctx* exec_ctx, - grpc_server_security_connector* sc, + void (*add_handshakers)(grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr); }; @@ -178,8 +170,7 @@ int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, grpc_server_security_connector* sc2); void grpc_server_security_connector_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_server_security_connector* sc, - grpc_handshake_manager* handshake_mgr); + grpc_server_security_connector* sc, grpc_handshake_manager* handshake_mgr); /* --- Creation security connectors. --- */ @@ -216,7 +207,7 @@ typedef struct { specific error code otherwise. */ grpc_security_status grpc_ssl_channel_security_connector_create( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, + grpc_channel_credentials* channel_creds, grpc_call_credentials* request_metadata_creds, const grpc_ssl_config* config, const char* target_name, const char* overridden_target_name, grpc_channel_security_connector** sc); @@ -242,7 +233,7 @@ typedef struct { specific error code otherwise. */ grpc_security_status grpc_ssl_server_security_connector_create( - grpc_exec_ctx* exec_ctx, grpc_server_credentials* server_credentials, + grpc_server_credentials* server_credentials, grpc_server_security_connector** sc); /* Util. */ diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 7067b70cb6..7623fbfd5b 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -65,8 +65,7 @@ typedef struct { tsi_handshaker_result* handshaker_result; } security_handshaker; -static size_t move_read_buffer_into_handshake_buffer(grpc_exec_ctx* exec_ctx, - security_handshaker* h) { +static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) { size_t bytes_in_read_buffer = h->args->read_buffer->length; if (h->handshake_buffer_size < bytes_in_read_buffer) { h->handshake_buffer = @@ -79,48 +78,45 @@ static size_t move_read_buffer_into_handshake_buffer(grpc_exec_ctx* exec_ctx, memcpy(h->handshake_buffer + offset, GRPC_SLICE_START_PTR(next_slice), GRPC_SLICE_LENGTH(next_slice)); offset += GRPC_SLICE_LENGTH(next_slice); - grpc_slice_unref_internal(exec_ctx, next_slice); + grpc_slice_unref_internal(next_slice); } return bytes_in_read_buffer; } -static void security_handshaker_unref(grpc_exec_ctx* exec_ctx, - security_handshaker* h) { +static void security_handshaker_unref(security_handshaker* h) { if (gpr_unref(&h->refs)) { gpr_mu_destroy(&h->mu); tsi_handshaker_destroy(h->handshaker); tsi_handshaker_result_destroy(h->handshaker_result); if (h->endpoint_to_destroy != nullptr) { - grpc_endpoint_destroy(exec_ctx, h->endpoint_to_destroy); + grpc_endpoint_destroy(h->endpoint_to_destroy); } if (h->read_buffer_to_destroy != nullptr) { - grpc_slice_buffer_destroy_internal(exec_ctx, h->read_buffer_to_destroy); + grpc_slice_buffer_destroy_internal(h->read_buffer_to_destroy); gpr_free(h->read_buffer_to_destroy); } gpr_free(h->handshake_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &h->outgoing); + grpc_slice_buffer_destroy_internal(&h->outgoing); GRPC_AUTH_CONTEXT_UNREF(h->auth_context, "handshake"); - GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, h->connector, "handshake"); + GRPC_SECURITY_CONNECTOR_UNREF(h->connector, "handshake"); gpr_free(h); } } // Set args fields to NULL, saving the endpoint and read buffer for // later destruction. -static void cleanup_args_for_failure_locked(grpc_exec_ctx* exec_ctx, - security_handshaker* h) { +static void cleanup_args_for_failure_locked(security_handshaker* h) { h->endpoint_to_destroy = h->args->endpoint; h->args->endpoint = nullptr; h->read_buffer_to_destroy = h->args->read_buffer; h->args->read_buffer = nullptr; - grpc_channel_args_destroy(exec_ctx, h->args->args); + grpc_channel_args_destroy(h->args->args); h->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the // callback with the error. -static void security_handshake_failed_locked(grpc_exec_ctx* exec_ctx, - security_handshaker* h, +static void security_handshake_failed_locked(security_handshaker* h, grpc_error* error) { if (error == GRPC_ERROR_NONE) { // If we were shut down after the handshake succeeded but before an @@ -135,34 +131,33 @@ static void security_handshake_failed_locked(grpc_exec_ctx* exec_ctx, // before destroying them, even if we know that there are no // pending read/write callbacks. This should be fixed, at which // point this can be removed. - grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(h->args->endpoint, GRPC_ERROR_REF(error)); // Not shutting down, so the write failed. Clean up before // invoking the callback. - cleanup_args_for_failure_locked(exec_ctx, h); + cleanup_args_for_failure_locked(h); // Set shutdown to true so that subsequent calls to // security_handshaker_shutdown() do nothing. h->shutdown = true; } // Invoke callback. - GRPC_CLOSURE_SCHED(exec_ctx, h->on_handshake_done, error); + GRPC_CLOSURE_SCHED(h->on_handshake_done, error); } -static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, - security_handshaker* h, grpc_error* error) { +static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) { if (error != GRPC_ERROR_NONE || h->shutdown) { - security_handshake_failed_locked(exec_ctx, h, GRPC_ERROR_REF(error)); + security_handshake_failed_locked(h, GRPC_ERROR_REF(error)); return; } // Create zero-copy frame protector, if implemented. tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr; tsi_result result = tsi_handshaker_result_create_zero_copy_grpc_protector( - exec_ctx, h->handshaker_result, nullptr, &zero_copy_protector); + h->handshaker_result, nullptr, &zero_copy_protector); if (result != TSI_OK && result != TSI_UNIMPLEMENTED) { error = grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Zero-copy frame protector creation failed"), result); - security_handshake_failed_locked(exec_ctx, h, error); + security_handshake_failed_locked(h, error); return; } // Create frame protector if zero-copy frame protector is NULL. @@ -174,7 +169,7 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, error = grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Frame protector creation failed"), result); - security_handshake_failed_locked(exec_ctx, h, error); + security_handshake_failed_locked(h, error); return; } } @@ -189,7 +184,7 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, grpc_slice_from_copied_buffer((char*)unused_bytes, unused_bytes_size); h->args->endpoint = grpc_secure_endpoint_create( protector, zero_copy_protector, h->args->endpoint, &slice, 1); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); } else { h->args->endpoint = grpc_secure_endpoint_create( protector, zero_copy_protector, h->args->endpoint, nullptr, 0); @@ -201,25 +196,23 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, grpc_channel_args* tmp_args = h->args->args; h->args->args = grpc_channel_args_copy_and_add(tmp_args, &auth_context_arg, 1); - grpc_channel_args_destroy(exec_ctx, tmp_args); + grpc_channel_args_destroy(tmp_args); // Invoke callback. - GRPC_CLOSURE_SCHED(exec_ctx, h->on_handshake_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(h->on_handshake_done, GRPC_ERROR_NONE); // Set shutdown to true so that subsequent calls to // security_handshaker_shutdown() do nothing. h->shutdown = true; } -static void on_peer_checked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_peer_checked(void* arg, grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); - on_peer_checked_inner(exec_ctx, h, error); + on_peer_checked_inner(h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); } -static grpc_error* check_peer_locked(grpc_exec_ctx* exec_ctx, - security_handshaker* h) { +static grpc_error* check_peer_locked(security_handshaker* h) { tsi_peer peer; tsi_result result = tsi_handshaker_result_extract_peer(h->handshaker_result, &peer); @@ -227,20 +220,20 @@ static grpc_error* check_peer_locked(grpc_exec_ctx* exec_ctx, return grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Peer extraction failed"), result); } - grpc_security_connector_check_peer(exec_ctx, h->connector, peer, - &h->auth_context, &h->on_peer_checked); + grpc_security_connector_check_peer(h->connector, peer, &h->auth_context, + &h->on_peer_checked); return GRPC_ERROR_NONE; } static grpc_error* on_handshake_next_done_locked( - grpc_exec_ctx* exec_ctx, security_handshaker* h, tsi_result result, + security_handshaker* h, tsi_result result, const unsigned char* bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) { grpc_error* error = GRPC_ERROR_NONE; // Read more if we need to. if (result == TSI_INCOMPLETE_DATA) { GPR_ASSERT(bytes_to_send_size == 0); - grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); return error; } @@ -257,17 +250,17 @@ static grpc_error* on_handshake_next_done_locked( // Send data to peer, if needed. grpc_slice to_send = grpc_slice_from_copied_buffer( (const char*)bytes_to_send, bytes_to_send_size); - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &h->outgoing); + grpc_slice_buffer_reset_and_unref_internal(&h->outgoing); grpc_slice_buffer_add(&h->outgoing, to_send); - grpc_endpoint_write(exec_ctx, h->args->endpoint, &h->outgoing, + grpc_endpoint_write(h->args->endpoint, &h->outgoing, &h->on_handshake_data_sent_to_peer); } else if (handshaker_result == nullptr) { // There is nothing to send, but need to read from peer. - grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); } else { // Handshake has finished, check peer and so on. - error = check_peer_locked(exec_ctx, h); + error = check_peer_locked(h); } return error; } @@ -278,24 +271,22 @@ static void on_handshake_next_done_grpc_wrapper( security_handshaker* h = (security_handshaker*)user_data; // This callback will be invoked by TSI in a non-grpc thread, so it's // safe to create our own exec_ctx here. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(&h->mu); - grpc_error* error = - on_handshake_next_done_locked(&exec_ctx, h, result, bytes_to_send, - bytes_to_send_size, handshaker_result); + grpc_error* error = on_handshake_next_done_locked( + h, result, bytes_to_send, bytes_to_send_size, handshaker_result); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(&exec_ctx, h, error); + security_handshake_failed_locked(h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(&exec_ctx, h); + security_handshaker_unref(h); } else { gpr_mu_unlock(&h->mu); } - grpc_exec_ctx_finish(&exec_ctx); } static grpc_error* do_handshaker_next_locked( - grpc_exec_ctx* exec_ctx, security_handshaker* h, - const unsigned char* bytes_received, size_t bytes_received_size) { + security_handshaker* h, const unsigned char* bytes_received, + size_t bytes_received_size) { // Invoke TSI handshaker. const unsigned char* bytes_to_send = nullptr; size_t bytes_to_send_size = 0; @@ -311,62 +302,57 @@ static grpc_error* do_handshaker_next_locked( } // Handshaker returned synchronously. Invoke callback directly in // this thread with our existing exec_ctx. - return on_handshake_next_done_locked(exec_ctx, h, result, bytes_to_send, + return on_handshake_next_done_locked(h, result, bytes_to_send, bytes_to_send_size, handshaker_result); } -static void on_handshake_data_received_from_peer(grpc_exec_ctx* exec_ctx, - void* arg, grpc_error* error) { +static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( - exec_ctx, h, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Handshake read failed", &error, 1)); + h, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Handshake read failed", &error, 1)); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); return; } // Copy all slices received. - size_t bytes_received_size = - move_read_buffer_into_handshake_buffer(exec_ctx, h); + size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h); // Call TSI handshaker. - error = do_handshaker_next_locked(exec_ctx, h, h->handshake_buffer, - bytes_received_size); + error = + do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(exec_ctx, h, error); + security_handshake_failed_locked(h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); } else { gpr_mu_unlock(&h->mu); } } -static void on_handshake_data_sent_to_peer(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) { security_handshaker* h = (security_handshaker*)arg; gpr_mu_lock(&h->mu); if (error != GRPC_ERROR_NONE || h->shutdown) { security_handshake_failed_locked( - exec_ctx, h, - GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Handshake write failed", &error, 1)); + h, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Handshake write failed", &error, 1)); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); return; } // We may be done. if (h->handshaker_result == nullptr) { - grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, + grpc_endpoint_read(h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); } else { - error = check_peer_locked(exec_ctx, h); + error = check_peer_locked(h); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(exec_ctx, h, error); + security_handshake_failed_locked(h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); return; } } @@ -377,28 +363,25 @@ static void on_handshake_data_sent_to_peer(grpc_exec_ctx* exec_ctx, void* arg, // public handshaker API // -static void security_handshaker_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker) { +static void security_handshaker_destroy(grpc_handshaker* handshaker) { security_handshaker* h = (security_handshaker*)handshaker; - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); } -static void security_handshaker_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +static void security_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) { security_handshaker* h = (security_handshaker*)handshaker; gpr_mu_lock(&h->mu); if (!h->shutdown) { h->shutdown = true; - grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(why)); - cleanup_args_for_failure_locked(exec_ctx, h); + grpc_endpoint_shutdown(h->args->endpoint, GRPC_ERROR_REF(why)); + cleanup_args_for_failure_locked(h); } gpr_mu_unlock(&h->mu); GRPC_ERROR_UNREF(why); } -static void security_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +static void security_handshaker_do_handshake(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { @@ -407,14 +390,13 @@ static void security_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, h->args = args; h->on_handshake_done = on_handshake_done; gpr_ref(&h->refs); - size_t bytes_received_size = - move_read_buffer_into_handshake_buffer(exec_ctx, h); - grpc_error* error = do_handshaker_next_locked( - exec_ctx, h, h->handshake_buffer, bytes_received_size); + size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h); + grpc_error* error = + do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size); if (error != GRPC_ERROR_NONE) { - security_handshake_failed_locked(exec_ctx, h, error); + security_handshake_failed_locked(h, error); gpr_mu_unlock(&h->mu); - security_handshaker_unref(exec_ctx, h); + security_handshaker_unref(h); return; } gpr_mu_unlock(&h->mu); @@ -425,8 +407,7 @@ static const grpc_handshaker_vtable security_handshaker_vtable = { security_handshaker_do_handshake}; static grpc_handshaker* security_handshaker_create( - grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, - grpc_security_connector* connector) { + tsi_handshaker* handshaker, grpc_security_connector* connector) { security_handshaker* h = (security_handshaker*)gpr_zalloc(sizeof(security_handshaker)); grpc_handshaker_init(&security_handshaker_vtable, &h->base); @@ -452,23 +433,20 @@ static grpc_handshaker* security_handshaker_create( // fail_handshaker // -static void fail_handshaker_destroy(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker) { +static void fail_handshaker_destroy(grpc_handshaker* handshaker) { gpr_free(handshaker); } -static void fail_handshaker_shutdown(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +static void fail_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) { GRPC_ERROR_UNREF(why); } -static void fail_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, - grpc_handshaker* handshaker, +static void fail_handshaker_do_handshake(grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, grpc_handshaker_args* args) { - GRPC_CLOSURE_SCHED(exec_ctx, on_handshake_done, + GRPC_CLOSURE_SCHED(on_handshake_done, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create security handshaker")); } @@ -488,27 +466,27 @@ static grpc_handshaker* fail_handshaker_create() { // static void client_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { grpc_channel_security_connector* security_connector = (grpc_channel_security_connector*)grpc_security_connector_find_in_args( args); - grpc_channel_security_connector_add_handshakers(exec_ctx, security_connector, + grpc_channel_security_connector_add_handshakers(security_connector, handshake_mgr); } static void server_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* hf, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { + grpc_handshaker_factory* hf, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { grpc_server_security_connector* security_connector = (grpc_server_security_connector*)grpc_security_connector_find_in_args( args); - grpc_server_security_connector_add_handshakers(exec_ctx, security_connector, + grpc_server_security_connector_add_handshakers(security_connector, handshake_mgr); } static void handshaker_factory_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) {} + grpc_handshaker_factory* handshaker_factory) {} static const grpc_handshaker_factory_vtable client_handshaker_factory_vtable = { client_handshaker_factory_add_handshakers, handshaker_factory_destroy}; @@ -527,14 +505,13 @@ static grpc_handshaker_factory server_handshaker_factory = { // grpc_handshaker* grpc_security_handshaker_create( - grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, - grpc_security_connector* connector) { + tsi_handshaker* handshaker, grpc_security_connector* connector) { // If no TSI handshaker was created, return a handshaker that always fails. // Otherwise, return a real security handshaker. if (handshaker == nullptr) { return fail_handshaker_create(); } else { - return security_handshaker_create(exec_ctx, handshaker, connector); + return security_handshaker_create(handshaker, connector); } } diff --git a/src/core/lib/security/transport/security_handshaker.h b/src/core/lib/security/transport/security_handshaker.h index 6c3a0510ce..6cd6446b5a 100644 --- a/src/core/lib/security/transport/security_handshaker.h +++ b/src/core/lib/security/transport/security_handshaker.h @@ -25,8 +25,7 @@ /// Creates a security handshaker using \a handshaker. grpc_handshaker* grpc_security_handshaker_create( - grpc_exec_ctx* exec_ctx, tsi_handshaker* handshaker, - grpc_security_connector* connector); + tsi_handshaker* handshaker, grpc_security_connector* connector); /// Registers security handshaker factories. void grpc_security_register_handshaker_factories(); diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index 9cf368acd0..73653f2a66 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -73,8 +73,7 @@ static grpc_metadata_array metadata_batch_to_md_array( return result; } -static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx* exec_ctx, - void* user_data, +static grpc_filtered_mdelem remove_consumed_md(void* user_data, grpc_mdelem md) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; @@ -88,8 +87,7 @@ static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx* exec_ctx, return GRPC_FILTERED_MDELEM(md); } -static void on_md_processing_done_inner(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void on_md_processing_done_inner(grpc_call_element* elem, const grpc_metadata* consumed_md, size_t num_consumed_md, const grpc_metadata* response_md, @@ -107,11 +105,10 @@ static void on_md_processing_done_inner(grpc_exec_ctx* exec_ctx, calld->consumed_md = consumed_md; calld->num_consumed_md = num_consumed_md; error = grpc_metadata_batch_filter( - exec_ctx, batch->payload->recv_initial_metadata.recv_initial_metadata, + batch->payload->recv_initial_metadata.recv_initial_metadata, remove_consumed_md, elem, "Response metadata filtering error"); } - GRPC_CLOSURE_SCHED(exec_ctx, calld->original_recv_initial_metadata_ready, - error); + GRPC_CLOSURE_SCHED(calld->original_recv_initial_metadata_ready, error); } // Called from application code. @@ -121,7 +118,7 @@ static void on_md_processing_done( grpc_status_code status, const char* error_details) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // If the call was not cancelled while we were in flight, process the result. if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_DONE)) { @@ -134,34 +131,32 @@ static void on_md_processing_done( GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_details), GRPC_ERROR_INT_GRPC_STATUS, status); } - on_md_processing_done_inner(&exec_ctx, elem, consumed_md, num_consumed_md, - response_md, num_response_md, error); + on_md_processing_done_inner(elem, consumed_md, num_consumed_md, response_md, + num_response_md, error); } // Clean up. for (size_t i = 0; i < calld->md.count; i++) { - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); + grpc_slice_unref_internal(calld->md.metadata[i].key); + grpc_slice_unref_internal(calld->md.metadata[i].value); } grpc_metadata_array_destroy(&calld->md); - GRPC_CALL_STACK_UNREF(&exec_ctx, calld->owning_call, "server_auth_metadata"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CALL_STACK_UNREF(calld->owning_call, "server_auth_metadata"); } -static void cancel_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void cancel_call(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; // If the result was not already processed, invoke the callback now. if (error != GRPC_ERROR_NONE && gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_CANCELLED)) { - on_md_processing_done_inner(exec_ctx, elem, nullptr, 0, nullptr, 0, + on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0, GRPC_ERROR_REF(error)); } - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_call"); + GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_call"); } -static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void recv_initial_metadata_ready(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; @@ -173,7 +168,7 @@ static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, GRPC_CALL_STACK_REF(calld->owning_call, "cancel_call"); GRPC_CLOSURE_INIT(&calld->cancel_closure, cancel_call, elem, grpc_schedule_on_exec_ctx); - grpc_call_combiner_set_notify_on_cancel(exec_ctx, calld->call_combiner, + grpc_call_combiner_set_notify_on_cancel(calld->call_combiner, &calld->cancel_closure); GRPC_CALL_STACK_REF(calld->owning_call, "server_auth_metadata"); calld->md = metadata_batch_to_md_array( @@ -184,13 +179,12 @@ static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, return; } } - GRPC_CLOSURE_RUN(exec_ctx, calld->original_recv_initial_metadata_ready, + GRPC_CLOSURE_RUN(calld->original_recv_initial_metadata_ready, GRPC_ERROR_REF(error)); } static void auth_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* batch) { + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { call_data* calld = (call_data*)elem->call_data; if (batch->recv_initial_metadata) { // Inject our callback. @@ -200,12 +194,11 @@ static void auth_start_transport_stream_op_batch( batch->payload->recv_initial_metadata.recv_initial_metadata_ready = &calld->recv_initial_metadata_ready; } - grpc_call_next_op(exec_ctx, elem, batch); + grpc_call_next_op(elem, batch); } /* Constructor for call_data */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -231,13 +224,12 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} /* Constructor for channel_data */ -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); channel_data* chand = (channel_data*)elem->channel_data; @@ -253,11 +245,10 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "server_auth_filter"); - grpc_server_credentials_unref(exec_ctx, chand->creds); + grpc_server_credentials_unref(chand->creds); } const grpc_channel_filter grpc_server_auth_filter = { diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index fe7a86ef84..f36b13ef1b 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -122,9 +122,8 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, result[current - result] = '\0'; } -grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, - int url_safe) { - return grpc_base64_decode_with_len(exec_ctx, b64, strlen(b64), url_safe); +grpc_slice grpc_base64_decode(const char* b64, int url_safe) { + return grpc_base64_decode_with_len(b64, strlen(b64), url_safe); } static void decode_one_char(const unsigned char* codes, unsigned char* result, @@ -185,8 +184,8 @@ static int decode_group(const unsigned char* codes, size_t num_codes, return 1; } -grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, - size_t b64_len, int url_safe) { +grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, + int url_safe) { grpc_slice result = GRPC_SLICE_MALLOC(b64_len); unsigned char* current = GRPC_SLICE_START_PTR(result); size_t result_size = 0; @@ -231,6 +230,6 @@ grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, return result; fail: - grpc_slice_unref_internal(exec_ctx, result); + grpc_slice_unref_internal(result); return grpc_empty_slice(); } diff --git a/src/core/lib/slice/b64.h b/src/core/lib/slice/b64.h index f86c1d9901..17e7306303 100644 --- a/src/core/lib/slice/b64.h +++ b/src/core/lib/slice/b64.h @@ -40,11 +40,10 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, /* Decodes data according to the base64 specification. Returns an empty slice in case of failure. */ -grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, - int url_safe); +grpc_slice grpc_base64_decode(const char* b64, int url_safe); /* Same as above except that the length is provided by the caller. */ -grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, - size_t b64_len, int url_safe); +grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, + int url_safe); #endif /* GRPC_CORE_LIB_SLICE_B64_H */ diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index bbaf87ba23..1eb15290eb 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -54,9 +54,9 @@ grpc_slice grpc_slice_ref_internal(grpc_slice slice) { return slice; } -void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice) { +void grpc_slice_unref_internal(grpc_slice slice) { if (slice.refcount) { - slice.refcount->vtable->unref(exec_ctx, slice.refcount); + slice.refcount->vtable->unref(slice.refcount); } } @@ -67,15 +67,14 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { /* Public API */ void grpc_slice_unref(grpc_slice slice) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_unref_internal(&exec_ctx, slice); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_unref_internal(slice); } /* grpc_slice_from_static_string support structure - a refcount that does nothing */ static void noop_ref(void* unused) {} -static void noop_unref(grpc_exec_ctx* exec_ctx, void* unused) {} +static void noop_unref(void* unused) {} static const grpc_slice_refcount_vtable noop_refcount_vtable = { noop_ref, noop_unref, grpc_slice_default_eq_impl, @@ -109,7 +108,7 @@ static void new_slice_ref(void* p) { gpr_ref(&r->refs); } -static void new_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void new_slice_unref(void* p) { new_slice_refcount* r = (new_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data); @@ -159,7 +158,7 @@ static void new_with_len_ref(void* p) { gpr_ref(&r->refs); } -static void new_with_len_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void new_with_len_unref(void* p) { new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data, r->user_length); @@ -210,7 +209,7 @@ static void malloc_ref(void* p) { gpr_ref(&r->refs); } -static void malloc_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void malloc_unref(void* p) { malloc_refcount* r = (malloc_refcount*)p; if (gpr_unref(&r->refs)) { gpr_free(r); diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 5db54dad91..33ec2af683 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -65,18 +65,16 @@ void grpc_slice_buffer_init(grpc_slice_buffer* sb) { sb->base_slices = sb->slices = sb->inlined; } -void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* sb) { - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, sb); +void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { + grpc_slice_buffer_reset_and_unref_internal(sb); if (sb->base_slices != sb->inlined) { gpr_free(sb->base_slices); } } void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, sb); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(sb); } uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { @@ -163,11 +161,10 @@ void grpc_slice_buffer_pop(grpc_slice_buffer* sb) { } } -void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* sb) { +void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { size_t i; for (i = 0; i < sb->count; i++) { - grpc_slice_unref_internal(exec_ctx, sb->slices[i]); + grpc_slice_unref_internal(sb->slices[i]); } sb->count = 0; @@ -175,9 +172,8 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, } void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, sb); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_reset_and_unref_internal(sb); } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { @@ -289,8 +285,7 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, slice_buffer_move_first_maybe_ref(src, n, dst, false); } -void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* src, size_t n, +void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, void* dst) { char* dstp = (char*)dst; GPR_ASSERT(src->length >= n); @@ -305,13 +300,13 @@ void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, n = 0; } else if (slice_len == n) { memcpy(dstp, GRPC_SLICE_START_PTR(slice), n); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); n = 0; } else { memcpy(dstp, GRPC_SLICE_START_PTR(slice), slice_len); dstp += slice_len; n -= slice_len; - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(slice); } } } diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 8f8e5a6b34..89340eff84 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -27,7 +27,7 @@ struct grpc_slice_hash_table { gpr_refcount refs; - void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); + void (*destroy_value)(void* value); int (*value_cmp)(void* a, void* b); size_t size; size_t max_num_probes; @@ -58,8 +58,7 @@ static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), - int (*value_cmp)(void* a, void* b)) { + void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) { grpc_slice_hash_table* table = (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table)); gpr_ref_init(&table->refs, 1); @@ -81,14 +80,13 @@ grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { return table; } -void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_slice_hash_table* table) { +void grpc_slice_hash_table_unref(grpc_slice_hash_table* table) { if (table != nullptr && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; if (!is_empty(entry)) { - grpc_slice_unref_internal(exec_ctx, entry->key); - table->destroy_value(exec_ctx, entry->value); + grpc_slice_unref_internal(entry->key); + table->destroy_value(entry->value); } } gpr_free(table->entries); diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index 85102bd67d..db69da662a 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -46,12 +46,10 @@ typedef struct grpc_slice_hash_table_entry { will be used. */ grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), - int (*value_cmp)(void* a, void* b)); + void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)); grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table); -void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_slice_hash_table* table); +void grpc_slice_hash_table_unref(grpc_slice_hash_table* table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index e8949135c0..c578c6d9de 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -90,7 +90,7 @@ static void interned_slice_destroy(interned_slice_refcount* s) { gpr_mu_unlock(&shard->mu); } -static void interned_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void interned_slice_unref(void* p) { interned_slice_refcount* s = (interned_slice_refcount*)p; if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { interned_slice_destroy(s); @@ -101,9 +101,8 @@ static void interned_slice_sub_ref(void* p) { interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub)); } -static void interned_slice_sub_unref(grpc_exec_ctx* exec_ctx, void* p) { - interned_slice_unref(exec_ctx, - ((char*)p) - offsetof(interned_slice_refcount, sub)); +static void interned_slice_sub_unref(void* p) { + interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub)); } static uint32_t interned_slice_hash(grpc_slice slice) { diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index ed0070d375..4e9ab80261 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -25,14 +25,11 @@ #include "src/core/lib/iomgr/exec_ctx.h" grpc_slice grpc_slice_ref_internal(grpc_slice slice); -void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice); -void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* sb); -void grpc_slice_buffer_partial_unref_internal(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* sb, +void grpc_slice_unref_internal(grpc_slice slice); +void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb); +void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb, size_t idx); -void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, - grpc_slice_buffer* sb); +void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb); /* Check if a slice is interned */ bool grpc_slice_is_interned(grpc_slice slice); diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index b1c9f7b164..f6ea016c33 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -45,11 +45,11 @@ static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } static void alarm_unref(grpc_alarm* alarm) { if (gpr_unref(&alarm->refs)) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; if (alarm->cq != nullptr) { - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, alarm->cq, "alarm"); + GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); } - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(alarm); } } @@ -80,20 +80,19 @@ static void alarm_unref_dbg(grpc_alarm* alarm, const char* reason, } #endif -static void alarm_end_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* c) { +static void alarm_end_completion(void* arg, grpc_cq_completion* c) { grpc_alarm* alarm = (grpc_alarm*)arg; GRPC_ALARM_UNREF(alarm, "dequeue-end-op"); } -static void alarm_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void alarm_cb(void* arg, grpc_error* error) { grpc_alarm* alarm = (grpc_alarm*)arg; /* We are queuing an op on completion queue. This means, the alarm's structure cannot be destroyed until the op is dequeued. Adding an extra ref here and unref'ing when the op is dequeued will achieve this */ GRPC_ALARM_REF(alarm, "queue-end-op"); - grpc_cq_end_op(exec_ctx, alarm->cq, alarm->tag, error, alarm_end_completion, + grpc_cq_end_op(alarm->cq, alarm->tag, error, alarm_end_completion, (void*)alarm, &alarm->completion); } @@ -116,22 +115,20 @@ grpc_alarm* grpc_alarm_create(void* reserved) { void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, gpr_timespec deadline, void* tag, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CQ_INTERNAL_REF(cq, "alarm"); alarm->cq = cq; alarm->tag = tag; GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - grpc_timer_init(&exec_ctx, &alarm->alarm, - grpc_timespec_to_millis_round_up(deadline), &alarm->on_alarm); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_init(&alarm->alarm, grpc_timespec_to_millis_round_up(deadline), + &alarm->on_alarm); } void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_timer_cancel(&exec_ctx, &alarm->alarm); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_timer_cancel(&alarm->alarm); } void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved) { diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index 9e0636b4ce..e4c2a4a4c2 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -71,14 +71,13 @@ grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { if (!bb) return; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; switch (bb->type) { case GRPC_BB_RAW: - grpc_slice_buffer_destroy_internal(&exec_ctx, &bb->data.raw.slice_buffer); + grpc_slice_buffer_destroy_internal(&bb->data.raw.slice_buffer); break; } gpr_free(bb); - grpc_exec_ctx_finish(&exec_ctx); } size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) { diff --git a/src/core/lib/surface/byte_buffer_reader.cc b/src/core/lib/surface/byte_buffer_reader.cc index 001227a2aa..81a48e95fc 100644 --- a/src/core/lib/surface/byte_buffer_reader.cc +++ b/src/core/lib/surface/byte_buffer_reader.cc @@ -42,15 +42,14 @@ static int is_compressed(grpc_byte_buffer* buffer) { int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer decompressed_slices_buffer; reader->buffer_in = buffer; switch (reader->buffer_in->type) { case GRPC_BB_RAW: grpc_slice_buffer_init(&decompressed_slices_buffer); if (is_compressed(reader->buffer_in)) { - if (grpc_msg_decompress(&exec_ctx, - reader->buffer_in->data.raw.compression, + if (grpc_msg_decompress(reader->buffer_in->data.raw.compression, &reader->buffer_in->data.raw.slice_buffer, &decompressed_slices_buffer) == 0) { gpr_log(GPR_ERROR, @@ -64,15 +63,14 @@ int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_raw_byte_buffer_create(decompressed_slices_buffer.slices, decompressed_slices_buffer.count); } - grpc_slice_buffer_destroy_internal(&exec_ctx, - &decompressed_slices_buffer); + grpc_slice_buffer_destroy_internal(&decompressed_slices_buffer); } else { /* not compressed, use the input buffer as output */ reader->buffer_out = reader->buffer_in; } reader->current.index = 0; break; } - grpc_exec_ctx_finish(&exec_ctx); + return 1; } @@ -112,14 +110,14 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) { grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size); uint8_t* const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { const size_t slice_length = GRPC_SLICE_LENGTH(in_slice); memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length); bytes_read += slice_length; - grpc_slice_unref_internal(&exec_ctx, in_slice); + grpc_slice_unref_internal(in_slice); GPR_ASSERT(bytes_read <= input_size); } - grpc_exec_ctx_finish(&exec_ctx); + return out_slice; } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index a2eb02bd85..a457aaa7a2 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -270,30 +270,25 @@ grpc_core::TraceFlag grpc_compression_trace(false, "compression"); #define CALL_FROM_TOP_ELEM(top_elem) \ CALL_FROM_CALL_STACK(grpc_call_stack_from_top_element(top_elem)) -static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, - grpc_transport_stream_op_batch* op, +static void execute_batch(grpc_call* call, grpc_transport_stream_op_batch* op, grpc_closure* start_batch_closure); -static void cancel_with_status(grpc_exec_ctx* exec_ctx, grpc_call* c, - status_source source, grpc_status_code status, +static void cancel_with_status(grpc_call* c, status_source source, + grpc_status_code status, const char* description); -static void cancel_with_error(grpc_exec_ctx* exec_ctx, grpc_call* c, - status_source source, grpc_error* error); -static void destroy_call(grpc_exec_ctx* exec_ctx, void* call_stack, - grpc_error* error); -static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, - grpc_error* error); -static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, - void (*set_value)(grpc_status_code code, - void* user_data), - void* set_value_user_data, grpc_slice* details, - const char** error_string); +static void cancel_with_error(grpc_call* c, status_source source, + grpc_error* error); +static void destroy_call(void* call_stack, grpc_error* error); +static void receiving_slice_ready(void* bctlp, grpc_error* error); +static void get_final_status( + grpc_call* call, void (*set_value)(grpc_status_code code, void* user_data), + void* set_value_user_data, grpc_slice* details, const char** error_string); static void set_status_value_directly(grpc_status_code status, void* dest); -static void set_status_from_error(grpc_exec_ctx* exec_ctx, grpc_call* call, - status_source source, grpc_error* error); -static void process_data_after_md(grpc_exec_ctx* exec_ctx, batch_control* bctl); -static void post_batch_completion(grpc_exec_ctx* exec_ctx, batch_control* bctl); -static void add_batch_error(grpc_exec_ctx* exec_ctx, batch_control* bctl, - grpc_error* error, bool has_cancelled); +static void set_status_from_error(grpc_call* call, status_source source, + grpc_error* error); +static void process_data_after_md(batch_control* bctl); +static void post_batch_completion(batch_control* bctl); +static void add_batch_error(batch_control* bctl, grpc_error* error, + bool has_cancelled); static void add_init_error(grpc_error** composite, grpc_error* new_err) { if (new_err == GRPC_ERROR_NONE) return; @@ -311,7 +306,8 @@ static parent_call* get_or_create_parent_call(grpc_call* call) { if (p == nullptr) { p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p)); gpr_mu_init(&p->child_list_mu); - if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm)NULL, (gpr_atm)p)) { + if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm) nullptr, + (gpr_atm)p)) { gpr_mu_destroy(&p->child_list_mu); p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); } @@ -323,8 +319,7 @@ static parent_call* get_parent_call(grpc_call* call) { return (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); } -grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, - const grpc_call_create_args* args, +grpc_error* grpc_call_create(const grpc_call_create_args* args, grpc_call** out_call) { size_t i, j; grpc_error* error = GRPC_ERROR_NONE; @@ -333,7 +328,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, grpc_call* call; GPR_TIMER_BEGIN("grpc_call_create", 0); size_t initial_size = grpc_channel_get_call_size_estimate(args->channel); - GRPC_STATS_INC_CALL_INITIAL_SIZE(exec_ctx, initial_size); + GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size); gpr_arena* arena = gpr_arena_create(initial_size); call = (grpc_call*)gpr_arena_alloc( arena, sizeof(grpc_call) + channel_stack->call_stack_size); @@ -348,9 +343,9 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); call->is_client = args->server_transport_data == nullptr; if (call->is_client) { - GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx); + GRPC_STATS_INC_CLIENT_CALLS_CREATED(); } else { - GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx); + GRPC_STATS_INC_SERVER_CALLS_CREATED(); } call->stream_op_payload.context = call->context; grpc_slice path = grpc_empty_slice(); @@ -445,15 +440,13 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, send_deadline, call->arena, &call->call_combiner}; - add_init_error(&error, grpc_call_stack_init(exec_ctx, channel_stack, 1, - destroy_call, call, &call_args)); + add_init_error(&error, grpc_call_stack_init(channel_stack, 1, destroy_call, + call, &call_args)); if (error != GRPC_ERROR_NONE) { - cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_ERROR_REF(error)); + cancel_with_error(call, STATUS_FROM_SURFACE, GRPC_ERROR_REF(error)); } if (immediately_cancel) { - cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, - GRPC_ERROR_CANCELLED); + cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); } if (args->cq != nullptr) { GPR_ASSERT( @@ -468,17 +461,17 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, args->pollset_set_alternative); } if (!grpc_polling_entity_is_empty(&call->pollent)) { - grpc_call_stack_set_pollset_or_pollset_set( - exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); + grpc_call_stack_set_pollset_or_pollset_set(CALL_STACK_FROM_CALL(call), + &call->pollent); } - grpc_slice_unref_internal(exec_ctx, path); + grpc_slice_unref_internal(path); GPR_TIMER_END("grpc_call_create", 0); return error; } -void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, +void grpc_call_set_completion_queue(grpc_call* call, grpc_completion_queue* cq) { GPR_ASSERT(cq); @@ -489,8 +482,8 @@ void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, call->cq = cq; GRPC_CQ_INTERNAL_REF(cq, "bind"); call->pollent = grpc_polling_entity_create_from_pollset(grpc_cq_pollset(cq)); - grpc_call_stack_set_pollset_or_pollset_set( - exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); + grpc_call_stack_set_pollset_or_pollset_set(CALL_STACK_FROM_CALL(call), + &call->pollent); } #ifndef NDEBUG @@ -503,40 +496,38 @@ void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, void grpc_call_internal_ref(grpc_call* c REF_ARG) { GRPC_CALL_STACK_REF(CALL_STACK_FROM_CALL(c), REF_REASON); } -void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* c REF_ARG) { - GRPC_CALL_STACK_UNREF(exec_ctx, CALL_STACK_FROM_CALL(c), REF_REASON); +void grpc_call_internal_unref(grpc_call* c REF_ARG) { + GRPC_CALL_STACK_UNREF(CALL_STACK_FROM_CALL(c), REF_REASON); } -static void release_call(grpc_exec_ctx* exec_ctx, void* call, - grpc_error* error) { +static void release_call(void* call, grpc_error* error) { grpc_call* c = (grpc_call*)call; grpc_channel* channel = c->channel; grpc_call_combiner_destroy(&c->call_combiner); gpr_free((char*)c->peer_string); grpc_channel_update_call_size_estimate(channel, gpr_arena_destroy(c->arena)); - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "call"); + GRPC_CHANNEL_INTERNAL_UNREF(channel, "call"); } static void set_status_value_directly(grpc_status_code status, void* dest); -static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, - grpc_error* error) { +static void destroy_call(void* call, grpc_error* error) { size_t i; int ii; grpc_call* c = (grpc_call*)call; GPR_TIMER_BEGIN("destroy_call", 0); for (i = 0; i < 2; i++) { grpc_metadata_batch_destroy( - exec_ctx, &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); + &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); } if (c->receiving_stream != nullptr) { - grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); + grpc_byte_stream_destroy(c->receiving_stream); } parent_call* pc = get_parent_call(c); if (pc != nullptr) { gpr_mu_destroy(&pc->child_list_mu); } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { - GRPC_MDELEM_UNREF(exec_ctx, c->send_extra_metadata[ii].md); + GRPC_MDELEM_UNREF(c->send_extra_metadata[ii].md); } for (i = 0; i < GRPC_CONTEXT_COUNT; i++) { if (c->context[i].destroy) { @@ -544,12 +535,11 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, } } if (c->cq) { - GRPC_CQ_INTERNAL_UNREF(exec_ctx, c->cq, "bind"); + GRPC_CQ_INTERNAL_UNREF(c->cq, "bind"); } - get_final_status(exec_ctx, c, set_status_value_directly, - &c->final_info.final_status, nullptr, - c->final_info.error_string); + get_final_status(c, set_status_value_directly, &c->final_info.final_status, + nullptr, c->final_info.error_string); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); @@ -558,7 +548,7 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, unpack_received_status(gpr_atm_acq_load(&c->status[i])).error); } - grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), &c->final_info, + grpc_call_stack_destroy(CALL_STACK_FROM_CALL(c), &c->final_info, GRPC_CLOSURE_INIT(&c->release_call, release_call, c, grpc_schedule_on_exec_ctx)); GPR_TIMER_END("destroy_call", 0); @@ -570,7 +560,7 @@ void grpc_call_unref(grpc_call* c) { if (!gpr_unref(&c->ext_ref)) return; child_call* cc = c->child; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_TIMER_BEGIN("grpc_call_unref", 0); GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c)); @@ -587,7 +577,7 @@ void grpc_call_unref(grpc_call* c) { cc->sibling_prev->child->sibling_next = cc->sibling_next; cc->sibling_next->child->sibling_prev = cc->sibling_prev; gpr_mu_unlock(&pc->child_list_mu); - GRPC_CALL_INTERNAL_UNREF(&exec_ctx, cc->parent, "child"); + GRPC_CALL_INTERNAL_UNREF(cc->parent, "child"); } GPR_ASSERT(!c->destroy_called); @@ -595,53 +585,49 @@ void grpc_call_unref(grpc_call* c) { bool cancel = gpr_atm_acq_load(&c->any_ops_sent_atm) != 0 && gpr_atm_acq_load(&c->received_final_op_atm) == 0; if (cancel) { - cancel_with_error(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, - GRPC_ERROR_CANCELLED); + cancel_with_error(c, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); } else { // Unset the call combiner cancellation closure. This has the // effect of scheduling the previously set cancellation closure, if // any, so that it can release any internal references it may be // holding to the call stack. - grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, - nullptr); + grpc_call_combiner_set_notify_on_cancel(&c->call_combiner, nullptr); } - GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CALL_INTERNAL_UNREF(c, "destroy"); + GPR_TIMER_END("grpc_call_unref", 0); } grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); GPR_ASSERT(!reserved); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - cancel_with_error(&exec_ctx, call, STATUS_FROM_API_OVERRIDE, - GRPC_ERROR_CANCELLED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + cancel_with_error(call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); + return GRPC_CALL_OK; } // This is called via the call combiner to start sending a batch down // the filter stack. -static void execute_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* ignored) { +static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) { grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call* call = (grpc_call*)batch->handler_private.extra_arg; GPR_TIMER_BEGIN("execute_batch", 0); grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, batch); - elem->filter->start_transport_stream_op_batch(exec_ctx, elem, batch); + elem->filter->start_transport_stream_op_batch(elem, batch); GPR_TIMER_END("execute_batch", 0); } // start_batch_closure points to a caller-allocated closure to be used // for entering the call combiner. -static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, +static void execute_batch(grpc_call* call, grpc_transport_stream_op_batch* batch, grpc_closure* start_batch_closure) { batch->handler_private.extra_arg = call; GRPC_CLOSURE_INIT(start_batch_closure, execute_batch_in_call_combiner, batch, grpc_schedule_on_exec_ctx); - GRPC_CALL_COMBINER_START(exec_ctx, &call->call_combiner, start_batch_closure, + GRPC_CALL_COMBINER_START(&call->call_combiner, start_batch_closure, GRPC_ERROR_NONE, "executing batch"); } @@ -665,15 +651,14 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, grpc_status_code status, const char* description, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE( "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", 4, (c, (int)status, description, reserved)); GPR_ASSERT(reserved == nullptr); - cancel_with_status(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, status, - description); - grpc_exec_ctx_finish(&exec_ctx); + cancel_with_status(c, STATUS_FROM_API_OVERRIDE, status, description); + return GRPC_CALL_OK; } @@ -685,24 +670,23 @@ typedef struct { // The on_complete callback used when sending a cancel_stream batch down // the filter stack. Yields the call combiner when the batch is done. -static void done_termination(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void done_termination(void* arg, grpc_error* error) { cancel_state* state = (cancel_state*)arg; - GRPC_CALL_COMBINER_STOP(exec_ctx, &state->call->call_combiner, + GRPC_CALL_COMBINER_STOP(&state->call->call_combiner, "on_complete for cancel_stream op"); - GRPC_CALL_INTERNAL_UNREF(exec_ctx, state->call, "termination"); + GRPC_CALL_INTERNAL_UNREF(state->call, "termination"); gpr_free(state); } -static void cancel_with_error(grpc_exec_ctx* exec_ctx, grpc_call* c, - status_source source, grpc_error* error) { +static void cancel_with_error(grpc_call* c, status_source source, + grpc_error* error) { GRPC_CALL_INTERNAL_REF(c, "termination"); // Inform the call combiner of the cancellation, so that it can cancel // any in-flight asynchronous actions that may be holding the call // combiner. This ensures that the cancel_stream batch can be sent // down the filter stack in a timely manner. - grpc_call_combiner_cancel(exec_ctx, &c->call_combiner, GRPC_ERROR_REF(error)); - set_status_from_error(exec_ctx, c, source, GRPC_ERROR_REF(error)); + grpc_call_combiner_cancel(&c->call_combiner, GRPC_ERROR_REF(error)); + set_status_from_error(c, source, GRPC_ERROR_REF(error)); cancel_state* state = (cancel_state*)gpr_malloc(sizeof(*state)); state->call = c; GRPC_CLOSURE_INIT(&state->finish_batch, done_termination, state, @@ -711,7 +695,7 @@ static void cancel_with_error(grpc_exec_ctx* exec_ctx, grpc_call* c, grpc_make_transport_stream_op(&state->finish_batch); op->cancel_stream = true; op->payload->cancel_stream.cancel_error = error; - execute_batch(exec_ctx, c, op, &state->start_batch); + execute_batch(c, op, &state->start_batch); } static grpc_error* error_from_status(grpc_status_code status, @@ -725,11 +709,10 @@ static grpc_error* error_from_status(grpc_status_code status, GRPC_ERROR_INT_GRPC_STATUS, status); } -static void cancel_with_status(grpc_exec_ctx* exec_ctx, grpc_call* c, - status_source source, grpc_status_code status, +static void cancel_with_status(grpc_call* c, status_source source, + grpc_status_code status, const char* description) { - cancel_with_error(exec_ctx, c, source, - error_from_status(status, description)); + cancel_with_error(c, source, error_from_status(status, description)); } /******************************************************************************* @@ -737,14 +720,13 @@ static void cancel_with_status(grpc_exec_ctx* exec_ctx, grpc_call* c, */ static bool get_final_status_from( - grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_error* error, - bool allow_ok_status, + grpc_call* call, grpc_error* error, bool allow_ok_status, void (*set_value)(grpc_status_code code, void* user_data), void* set_value_user_data, grpc_slice* details, const char** error_string) { grpc_status_code code; grpc_slice slice = grpc_empty_slice(); - grpc_error_get_status(exec_ctx, error, call->send_deadline, &code, &slice, - nullptr, error_string); + grpc_error_get_status(error, call->send_deadline, &code, &slice, nullptr, + error_string); if (code == GRPC_STATUS_OK && !allow_ok_status) { return false; } @@ -756,11 +738,9 @@ static bool get_final_status_from( return true; } -static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, - void (*set_value)(grpc_status_code code, - void* user_data), - void* set_value_user_data, grpc_slice* details, - const char** error_string) { +static void get_final_status( + grpc_call* call, void (*set_value)(grpc_status_code code, void* user_data), + void* set_value_user_data, grpc_slice* details, const char** error_string) { int i; received_status status[STATUS_SOURCE_COUNT]; for (i = 0; i < STATUS_SOURCE_COUNT; i++) { @@ -782,9 +762,9 @@ static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (status[i].is_set && grpc_error_has_clear_grpc_status(status[i].error)) { - if (get_final_status_from(exec_ctx, call, status[i].error, - allow_ok_status != 0, set_value, - set_value_user_data, details, error_string)) { + if (get_final_status_from(call, status[i].error, allow_ok_status != 0, + set_value, set_value_user_data, details, + error_string)) { return; } } @@ -792,9 +772,9 @@ static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, /* If no clearly defined status exists, search for 'anything' */ for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (status[i].is_set) { - if (get_final_status_from(exec_ctx, call, status[i].error, - allow_ok_status != 0, set_value, - set_value_user_data, details, error_string)) { + if (get_final_status_from(call, status[i].error, allow_ok_status != 0, + set_value, set_value_user_data, details, + error_string)) { return; } } @@ -808,8 +788,8 @@ static void get_final_status(grpc_exec_ctx* exec_ctx, grpc_call* call, } } -static void set_status_from_error(grpc_exec_ctx* exec_ctx, grpc_call* call, - status_source source, grpc_error* error) { +static void set_status_from_error(grpc_call* call, status_source source, + grpc_error* error) { if (!gpr_atm_rel_cas(&call->status[source], pack_received_status({false, GRPC_ERROR_NONE}), pack_received_status({true, error}))) { @@ -861,8 +841,7 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call* call) { static void destroy_encodings_accepted_by_peer(void* p) { return; } -static void set_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, - grpc_call* call, grpc_mdelem mdel) { +static void set_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { size_t i; grpc_compression_algorithm algorithm; grpc_slice_buffer accept_encoding_parts; @@ -900,15 +879,14 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, } } - grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); + grpc_slice_buffer_destroy_internal(&accept_encoding_parts); grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, (void*)(((uintptr_t)call->encodings_accepted_by_peer) + 1)); } -static void set_stream_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, - grpc_call* call, +static void set_stream_encodings_accepted_by_peer(grpc_call* call, grpc_mdelem mdel) { size_t i; grpc_stream_compression_algorithm algorithm; @@ -946,7 +924,7 @@ static void set_stream_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, } } - grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); + grpc_slice_buffer_destroy_internal(&accept_encoding_parts); grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, @@ -984,10 +962,12 @@ static grpc_metadata* get_md_elem(grpc_metadata* metadata, return res; } -static int prepare_application_metadata( - grpc_exec_ctx* exec_ctx, grpc_call* call, int count, - grpc_metadata* metadata, int is_trailing, int prepend_extra_metadata, - grpc_metadata* additional_metadata, int additional_metadata_count) { +static int prepare_application_metadata(grpc_call* call, int count, + grpc_metadata* metadata, + int is_trailing, + int prepend_extra_metadata, + grpc_metadata* additional_metadata, + int additional_metadata_count) { int total_count = count + additional_metadata_count; int i; grpc_metadata_batch* batch = @@ -1006,14 +986,14 @@ static int prepare_application_metadata( grpc_validate_header_nonbin_value_is_legal(md->value))) { break; } - l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata*)md); + l->md = grpc_mdelem_from_grpc_metadata((grpc_metadata*)md); } if (i != total_count) { for (int j = 0; j < i; j++) { const grpc_metadata* md = get_md_elem(metadata, additional_metadata, j, count); grpc_linked_mdelem* l = linked_from_md(md); - GRPC_MDELEM_UNREF(exec_ctx, l->md); + GRPC_MDELEM_UNREF(l->md); } return 0; } @@ -1024,16 +1004,16 @@ static int prepare_application_metadata( for (i = 0; i < call->send_extra_metadata_count; i++) { GRPC_LOG_IF_ERROR("prepare_application_metadata", grpc_metadata_batch_link_tail( - exec_ctx, batch, &call->send_extra_metadata[i])); + batch, &call->send_extra_metadata[i])); } } } for (i = 0; i < total_count; i++) { grpc_metadata* md = get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem* l = linked_from_md(md); - grpc_error* error = grpc_metadata_batch_link_tail(exec_ctx, batch, l); + grpc_error* error = grpc_metadata_batch_link_tail(batch, l); if (error != GRPC_ERROR_NONE) { - GRPC_MDELEM_UNREF(exec_ctx, l->md); + GRPC_MDELEM_UNREF(l->md); } GRPC_LOG_IF_ERROR("prepare_application_metadata", error); } @@ -1120,46 +1100,43 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, GPR_TIMER_END("publish_app_metadata", 0); } -static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, - grpc_metadata_batch* b) { +static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) { if (b->idx.named.content_encoding != nullptr) { if (b->idx.named.grpc_encoding != nullptr) { gpr_log(GPR_ERROR, "Received both content-encoding and grpc-encoding header. " "Ignoring grpc-encoding."); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); + grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); } GPR_TIMER_BEGIN("incoming_stream_compression_algorithm", 0); set_incoming_stream_compression_algorithm( call, decode_stream_compression(b->idx.named.content_encoding->md)); GPR_TIMER_END("incoming_stream_compression_algorithm", 0); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_encoding); + grpc_metadata_batch_remove(b, b->idx.named.content_encoding); } else if (b->idx.named.grpc_encoding != nullptr) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm( call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); + grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); } if (b->idx.named.grpc_accept_encoding != nullptr) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(exec_ctx, call, - b->idx.named.grpc_accept_encoding->md); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); + set_encodings_accepted_by_peer(call, b->idx.named.grpc_accept_encoding->md); + grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } if (b->idx.named.accept_encoding != nullptr) { GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); - set_stream_encodings_accepted_by_peer(exec_ctx, call, + set_stream_encodings_accepted_by_peer(call, b->idx.named.accept_encoding->md); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.accept_encoding); + grpc_metadata_batch_remove(b, b->idx.named.accept_encoding); GPR_TIMER_END("stream_encodings_accepted_by_peer", 0); } publish_app_metadata(call, b, false); } -static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, - grpc_metadata_batch* b) { +static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { grpc_call* call = (grpc_call*)args; if (b->idx.named.grpc_status != nullptr) { uint32_t status_code = decode_status(b->idx.named.grpc_status->md); @@ -1174,13 +1151,13 @@ static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, error = grpc_error_set_str( error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); + grpc_metadata_batch_remove(b, b->idx.named.grpc_message); } else if (error != GRPC_ERROR_NONE) { error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_empty_slice()); } - set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); + set_status_from_error(call, STATUS_FROM_WIRE, error); + grpc_metadata_batch_remove(b, b->idx.named.grpc_status); } publish_app_metadata(call, b, true); } @@ -1257,12 +1234,12 @@ static batch_control* allocate_batch_control(grpc_call* call, return bctl; } -static void finish_batch_completion(grpc_exec_ctx* exec_ctx, void* user_data, +static void finish_batch_completion(void* user_data, grpc_cq_completion* storage) { batch_control* bctl = (batch_control*)user_data; grpc_call* call = bctl->call; bctl->call = nullptr; - GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); + GRPC_CALL_INTERNAL_UNREF(call, "completion"); } static grpc_error* consolidate_batch_errors(batch_control* bctl) { @@ -1286,15 +1263,13 @@ static grpc_error* consolidate_batch_errors(batch_control* bctl) { } } -static void post_batch_completion(grpc_exec_ctx* exec_ctx, - batch_control* bctl) { +static void post_batch_completion(batch_control* bctl) { grpc_call* next_child_call; grpc_call* call = bctl->call; grpc_error* error = consolidate_batch_errors(bctl); if (bctl->op.send_initial_metadata) { grpc_metadata_batch_destroy( - exec_ctx, &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); } if (bctl->op.send_message) { @@ -1302,13 +1277,12 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, } if (bctl->op.send_trailing_metadata) { grpc_metadata_batch_destroy( - exec_ctx, &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); } if (bctl->op.recv_trailing_metadata) { grpc_metadata_batch* md = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - recv_trailing_filter(exec_ctx, call, md); + recv_trailing_filter(call, md); /* propagate cancellation to any interested children */ gpr_atm_rel_store(&call->received_final_op_atm, 1); @@ -1322,9 +1296,9 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, next_child_call = child->child->sibling_next; if (child->cancellation_is_inherited) { GRPC_CALL_INTERNAL_REF(child, "propagate_cancel"); - cancel_with_error(exec_ctx, child, STATUS_FROM_API_OVERRIDE, + cancel_with_error(child, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); - GRPC_CALL_INTERNAL_UNREF(exec_ctx, child, "propagate_cancel"); + GRPC_CALL_INTERNAL_UNREF(child, "propagate_cancel"); } child = next_child_call; } while (child != pc->first_child); @@ -1333,12 +1307,12 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, } if (call->is_client) { - get_final_status(exec_ctx, call, set_status_value_directly, + get_final_status(call, set_status_value_directly, call->final_op.client.status, call->final_op.client.status_details, call->final_op.client.error_string); } else { - get_final_status(exec_ctx, call, set_cancelled_value, + get_final_status(call, set_cancelled_value, call->final_op.server.cancelled, nullptr, nullptr); } @@ -1354,25 +1328,24 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, if (bctl->completion_data.notify_tag.is_closure) { /* unrefs bctl->error */ bctl->call = nullptr; - GRPC_CLOSURE_RUN( - exec_ctx, (grpc_closure*)bctl->completion_data.notify_tag.tag, error); - GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); + GRPC_CLOSURE_RUN((grpc_closure*)bctl->completion_data.notify_tag.tag, + error); + GRPC_CALL_INTERNAL_UNREF(call, "completion"); } else { /* unrefs bctl->error */ - grpc_cq_end_op( - exec_ctx, bctl->call->cq, bctl->completion_data.notify_tag.tag, error, - finish_batch_completion, bctl, &bctl->completion_data.cq_completion); + grpc_cq_end_op(bctl->call->cq, bctl->completion_data.notify_tag.tag, error, + finish_batch_completion, bctl, + &bctl->completion_data.cq_completion); } } -static void finish_batch_step(grpc_exec_ctx* exec_ctx, batch_control* bctl) { +static void finish_batch_step(batch_control* bctl) { if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); + post_batch_completion(bctl); } } -static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, - batch_control* bctl) { +static void continue_receiving_slices(batch_control* bctl) { grpc_error* error; grpc_call* call = bctl->call; for (;;) { @@ -1380,25 +1353,25 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, (*call->receiving_buffer)->data.raw.slice_buffer.length; if (remaining == 0) { call->receiving_message = 0; - grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); + grpc_byte_stream_destroy(call->receiving_stream); call->receiving_stream = nullptr; - finish_batch_step(exec_ctx, bctl); + finish_batch_step(bctl); return; } - if (grpc_byte_stream_next(exec_ctx, call->receiving_stream, remaining, + if (grpc_byte_stream_next(call->receiving_stream, remaining, &call->receiving_slice_ready)) { - error = grpc_byte_stream_pull(exec_ctx, call->receiving_stream, - &call->receiving_slice); + error = + grpc_byte_stream_pull(call->receiving_stream, &call->receiving_slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer, call->receiving_slice); } else { - grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); + grpc_byte_stream_destroy(call->receiving_stream); call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(exec_ctx, bctl); + finish_batch_step(bctl); return; } } else { @@ -1407,8 +1380,7 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, } } -static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, - grpc_error* error) { +static void receiving_slice_ready(void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; grpc_byte_stream* bs = call->receiving_stream; @@ -1416,11 +1388,11 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, if (error == GRPC_ERROR_NONE) { grpc_slice slice; - error = grpc_byte_stream_pull(exec_ctx, bs, &slice); + error = grpc_byte_stream_pull(bs, &slice); if (error == GRPC_ERROR_NONE) { grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer, slice); - continue_receiving_slices(exec_ctx, bctl); + continue_receiving_slices(bctl); } else { /* Error returned by grpc_byte_stream_pull needs to be released manually */ @@ -1432,25 +1404,24 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, if (grpc_trace_operation_failures.enabled()) { GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error)); } - grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); + grpc_byte_stream_destroy(call->receiving_stream); call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(exec_ctx, bctl); + finish_batch_step(bctl); if (release_error) { GRPC_ERROR_UNREF(error); } } } -static void process_data_after_md(grpc_exec_ctx* exec_ctx, - batch_control* bctl) { +static void process_data_after_md(batch_control* bctl) { grpc_call* call = bctl->call; if (call->receiving_stream == nullptr) { *call->receiving_buffer = nullptr; call->receiving_message = 0; - finish_batch_step(exec_ctx, bctl); + finish_batch_step(bctl); } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && @@ -1462,46 +1433,42 @@ static void process_data_after_md(grpc_exec_ctx* exec_ctx, } GRPC_CLOSURE_INIT(&call->receiving_slice_ready, receiving_slice_ready, bctl, grpc_schedule_on_exec_ctx); - continue_receiving_slices(exec_ctx, bctl); + continue_receiving_slices(bctl); } } -static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, - grpc_error* error) { +static void receiving_stream_ready(void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; if (error != GRPC_ERROR_NONE) { if (call->receiving_stream != nullptr) { - grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); + grpc_byte_stream_destroy(call->receiving_stream); call->receiving_stream = nullptr; } - add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), true); - cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_ERROR_REF(error)); + add_batch_error(bctl, GRPC_ERROR_REF(error), true); + cancel_with_error(call, STATUS_FROM_SURFACE, GRPC_ERROR_REF(error)); } /* If recv_state is RECV_NONE, we will save the batch_control * object with rel_cas, and will not use it after the cas. Its corresponding * acq_load is in receiving_initial_metadata_ready() */ if (error != GRPC_ERROR_NONE || call->receiving_stream == nullptr || !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) { - process_data_after_md(exec_ctx, bctl); + process_data_after_md(bctl); } } // The recv_message_ready callback used when sending a batch containing // a recv_message op down the filter stack. Yields the call combiner // before processing the received message. -static void receiving_stream_ready_in_call_combiner(grpc_exec_ctx* exec_ctx, - void* bctlp, +static void receiving_stream_ready_in_call_combiner(void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, "recv_message_ready"); - receiving_stream_ready(exec_ctx, bctlp, error); + GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_message_ready"); + receiving_stream_ready(bctlp, error); } -static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, - batch_control* bctl) { +static void validate_filtered_metadata(batch_control* bctl) { grpc_call* call = bctl->call; /* validate compression algorithms */ if (call->incoming_stream_compression_algorithm != @@ -1515,8 +1482,8 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, gpr_asprintf(&error_msg, "Invalid stream compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, + error_msg); } else if (grpc_compression_options_is_stream_compression_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1525,8 +1492,8 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, gpr_asprintf(&error_msg, "Stream compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, + error_msg); } gpr_free(error_msg); @@ -1556,8 +1523,8 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, gpr_asprintf(&error_msg, "Invalid compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, + error_msg); } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1566,8 +1533,8 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, STATUS_FROM_SURFACE, - GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(call, STATUS_FROM_SURFACE, GRPC_STATUS_UNIMPLEMENTED, + error_msg); } else { call->incoming_compression_algorithm = algo; } @@ -1590,34 +1557,31 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } } -static void add_batch_error(grpc_exec_ctx* exec_ctx, batch_control* bctl, - grpc_error* error, bool has_cancelled) { +static void add_batch_error(batch_control* bctl, grpc_error* error, + bool has_cancelled) { if (error == GRPC_ERROR_NONE) return; int idx = (int)gpr_atm_full_fetch_add(&bctl->num_errors, 1); if (idx == 0 && !has_cancelled) { - cancel_with_error(exec_ctx, bctl->call, STATUS_FROM_CORE, - GRPC_ERROR_REF(error)); + cancel_with_error(bctl->call, STATUS_FROM_CORE, GRPC_ERROR_REF(error)); } bctl->errors[idx] = error; } -static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, - void* bctlp, grpc_error* error) { +static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, - "recv_initial_metadata_ready"); + GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_initial_metadata_ready"); - add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), false); + add_batch_error(bctl, GRPC_ERROR_REF(error), false); if (error == GRPC_ERROR_NONE) { grpc_metadata_batch* md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; - recv_initial_filter(exec_ctx, call, md); + recv_initial_filter(call, md); /* TODO(ctiller): this could be moved into recv_initial_filter now */ GPR_TIMER_BEGIN("validate_filtered_metadata", 0); - validate_filtered_metadata(exec_ctx, bctl); + validate_filtered_metadata(bctl); GPR_TIMER_END("validate_filtered_metadata", 0); if (md->deadline != GRPC_MILLIS_INF_FUTURE && !call->is_client) { @@ -1650,28 +1614,25 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, } } if (saved_rsr_closure != nullptr) { - GRPC_CLOSURE_RUN(exec_ctx, saved_rsr_closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(saved_rsr_closure, GRPC_ERROR_REF(error)); } - finish_batch_step(exec_ctx, bctl); + finish_batch_step(bctl); } -static void finish_batch(grpc_exec_ctx* exec_ctx, void* bctlp, - grpc_error* error) { +static void finish_batch(void* bctlp, grpc_error* error) { batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; - GRPC_CALL_COMBINER_STOP(exec_ctx, &call->call_combiner, "on_complete"); - add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), false); - finish_batch_step(exec_ctx, bctl); + GRPC_CALL_COMBINER_STOP(&call->call_combiner, "on_complete"); + add_batch_error(bctl, GRPC_ERROR_REF(error), false); + finish_batch_step(bctl); } -static void free_no_op_completion(grpc_exec_ctx* exec_ctx, void* p, - grpc_cq_completion* completion) { +static void free_no_op_completion(void* p, grpc_cq_completion* completion) { gpr_free(completion); } -static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, - grpc_call* call, const grpc_op* ops, +static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* notify_tag, int is_notify_tag_closure) { size_t i; @@ -1689,11 +1650,10 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, if (!is_notify_tag_closure) { GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); grpc_cq_end_op( - exec_ctx, call->cq, notify_tag, GRPC_ERROR_NONE, - free_no_op_completion, nullptr, + call->cq, notify_tag, GRPC_ERROR_NONE, free_no_op_completion, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); } else { - GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)notify_tag, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED((grpc_closure*)notify_tag, GRPC_ERROR_NONE); } error = GRPC_CALL_OK; goto done; @@ -1793,7 +1753,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, stream_op->send_initial_metadata = true; call->sent_initial_metadata = true; if (!prepare_application_metadata( - exec_ctx, call, (int)op->data.send_initial_metadata.count, + call, (int)op->data.send_initial_metadata.count, op->data.send_initial_metadata.metadata, 0, call->is_client, &call->compression_md, (int)additional_metadata_count)) { error = GRPC_CALL_ERROR_INVALID_METADATA; @@ -1887,7 +1847,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, GPR_ASSERT(call->send_extra_metadata_count == 0); call->send_extra_metadata_count = 1; call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( - exec_ctx, call->channel, op->data.send_status_from_server.status); + call->channel, op->data.send_status_from_server.status); { grpc_error* override_error = GRPC_ERROR_NONE; if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { @@ -1896,7 +1856,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, } if (op->data.send_status_from_server.status_details != nullptr) { call->send_extra_metadata[1].md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal( *op->data.send_status_from_server.status_details)); call->send_extra_metadata_count++; @@ -1907,16 +1867,15 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, grpc_slice_from_copied_string(msg)); gpr_free(msg); } - set_status_from_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, - override_error); + set_status_from_error(call, STATUS_FROM_API_OVERRIDE, override_error); } if (!prepare_application_metadata( - exec_ctx, call, + call, (int)op->data.send_status_from_server.trailing_metadata_count, op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { - GRPC_MDELEM_UNREF(exec_ctx, call->send_extra_metadata[n].md); + GRPC_MDELEM_UNREF(call->send_extra_metadata[n].md); } call->send_extra_metadata_count = 0; error = GRPC_CALL_ERROR_INVALID_METADATA; @@ -2045,7 +2004,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, stream_op->on_complete = &bctl->finish_batch; gpr_atm_rel_store(&call->any_ops_sent_atm, 1); - execute_batch(exec_ctx, call, stream_op, &bctl->start_batch); + execute_batch(call, stream_op, &bctl->start_batch); done: GPR_TIMER_END("grpc_call_start_batch", 0); @@ -2055,15 +2014,15 @@ done_with_error: /* reverse any mutations that occured */ if (stream_op->send_initial_metadata) { call->sent_initial_metadata = false; - grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][0]); + grpc_metadata_batch_clear(&call->metadata_batch[0][0]); } if (stream_op->send_message) { call->sending_message = false; - grpc_byte_stream_destroy(exec_ctx, &call->sending_stream.base); + grpc_byte_stream_destroy(&call->sending_stream.base); } if (stream_op->send_trailing_metadata) { call->sent_final_op = false; - grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][1]); + grpc_metadata_batch_clear(&call->metadata_batch[0][1]); } if (stream_op->recv_initial_metadata) { call->received_initial_metadata = false; @@ -2079,7 +2038,7 @@ done_with_error: grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* tag, void* reserved) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_call_error err; GRPC_API_TRACE( @@ -2090,19 +2049,17 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, if (reserved != nullptr) { err = GRPC_CALL_ERROR; } else { - err = call_start_batch(&exec_ctx, call, ops, nops, tag, 0); + err = call_start_batch(call, ops, nops, tag, 0); } - grpc_exec_ctx_finish(&exec_ctx); return err; } -grpc_call_error grpc_call_start_batch_and_execute(grpc_exec_ctx* exec_ctx, - grpc_call* call, +grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call, const grpc_op* ops, size_t nops, grpc_closure* closure) { - return call_start_batch(exec_ctx, call, ops, nops, closure, 1); + return call_start_batch(call, ops, nops, closure, 1); } void grpc_call_context_set(grpc_call* call, grpc_context_index elem, diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 1d2e266717..189329ccc4 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -26,8 +26,7 @@ #include #include -typedef void (*grpc_ioreq_completion_func)(grpc_exec_ctx* exec_ctx, - grpc_call* call, int success, +typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success, void* user_data); typedef struct grpc_call_create_args { @@ -51,33 +50,28 @@ typedef struct grpc_call_create_args { /* Create a new call based on \a args. Regardless of success or failure, always returns a valid new call into *call */ -grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, - const grpc_call_create_args* args, +grpc_error* grpc_call_create(const grpc_call_create_args* args, grpc_call** call); -void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, - grpc_completion_queue* cq); +void grpc_call_set_completion_queue(grpc_call* call, grpc_completion_queue* cq); #ifndef NDEBUG void grpc_call_internal_ref(grpc_call* call, const char* reason); -void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* call, - const char* reason); +void grpc_call_internal_unref(grpc_call* call, const char* reason); #define GRPC_CALL_INTERNAL_REF(call, reason) \ grpc_call_internal_ref(call, reason) -#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \ - grpc_call_internal_unref(exec_ctx, call, reason) +#define GRPC_CALL_INTERNAL_UNREF(call, reason) \ + grpc_call_internal_unref(call, reason) #else void grpc_call_internal_ref(grpc_call* call); -void grpc_call_internal_unref(grpc_exec_ctx* exec_ctx, grpc_call* call); +void grpc_call_internal_unref(grpc_call* call); #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call) -#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \ - grpc_call_internal_unref(exec_ctx, call) +#define GRPC_CALL_INTERNAL_UNREF(call, reason) grpc_call_internal_unref(call) #endif grpc_call_stack* grpc_call_get_call_stack(grpc_call* call); -grpc_call_error grpc_call_start_batch_and_execute(grpc_exec_ctx* exec_ctx, - grpc_call* call, +grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call, const grpc_op* ops, size_t nops, grpc_closure* closure); diff --git a/src/core/lib/surface/call_details.cc b/src/core/lib/surface/call_details.cc index ea9208c7e3..cd0b14586a 100644 --- a/src/core/lib/surface/call_details.cc +++ b/src/core/lib/surface/call_details.cc @@ -34,8 +34,7 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_unref_internal(&exec_ctx, cd->method); - grpc_slice_unref_internal(&exec_ctx, cd->host); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_unref_internal(cd->method); + grpc_slice_unref_internal(cd->host); } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 1be734cdb7..cf5e8c2150 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -69,23 +69,22 @@ struct grpc_channel { #define CHANNEL_FROM_TOP_ELEM(top_elem) \ CHANNEL_FROM_CHANNEL_STACK(grpc_channel_stack_from_top_element(top_elem)) -static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error); +static void destroy_channel(void* arg, grpc_error* error); grpc_channel* grpc_channel_create_with_builder( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + grpc_channel_stack_builder* builder, grpc_channel_stack_type channel_stack_type) { char* target = gpr_strdup(grpc_channel_stack_builder_get_target(builder)); grpc_channel_args* args = grpc_channel_args_copy( grpc_channel_stack_builder_get_channel_arguments(builder)); grpc_channel* channel; if (channel_stack_type == GRPC_SERVER_CHANNEL) { - GRPC_STATS_INC_SERVER_CHANNELS_CREATED(exec_ctx); + GRPC_STATS_INC_SERVER_CHANNELS_CREATED(); } else { - GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(exec_ctx); + GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(); } grpc_error* error = grpc_channel_stack_builder_finish( - exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, + builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, (void**)&channel); if (error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "channel stack builder failed: %s", @@ -114,10 +113,10 @@ grpc_channel* grpc_channel_create_with_builder( } else { if (!GRPC_MDISNULL(channel->default_authority)) { /* setting this takes precedence over anything else */ - GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); + GRPC_MDELEM_UNREF(channel->default_authority); } channel->default_authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, + GRPC_MDSTR_AUTHORITY, grpc_slice_intern( grpc_slice_from_static_string(args->args[i].value.string))); } @@ -134,7 +133,7 @@ grpc_channel* grpc_channel_create_with_builder( GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { channel->default_authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, + GRPC_MDSTR_AUTHORITY, grpc_slice_intern( grpc_slice_from_static_string(args->args[i].value.string))); } @@ -191,25 +190,23 @@ grpc_channel* grpc_channel_create_with_builder( } done: - grpc_channel_args_destroy(exec_ctx, args); + grpc_channel_args_destroy(args); return channel; } -grpc_channel* grpc_channel_create(grpc_exec_ctx* exec_ctx, const char* target, +grpc_channel* grpc_channel_create(const char* target, const grpc_channel_args* input_args, grpc_channel_stack_type channel_stack_type, grpc_transport* optional_transport) { grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, - input_args); + grpc_channel_stack_builder_set_channel_arguments(builder, input_args); grpc_channel_stack_builder_set_target(builder, target); grpc_channel_stack_builder_set_transport(builder, optional_transport); - if (!grpc_channel_init_create_stack(exec_ctx, builder, channel_stack_type)) { - grpc_channel_stack_builder_destroy(exec_ctx, builder); + if (!grpc_channel_init_create_stack(builder, channel_stack_type)) { + grpc_channel_stack_builder_destroy(builder); return nullptr; } - return grpc_channel_create_with_builder(exec_ctx, builder, - channel_stack_type); + return grpc_channel_create_with_builder(builder, channel_stack_type); } size_t grpc_channel_get_call_size_estimate(grpc_channel* channel) { @@ -251,18 +248,17 @@ char* grpc_channel_get_target(grpc_channel* channel) { void grpc_channel_get_info(grpc_channel* channel, const grpc_channel_info* channel_info) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); - elem->filter->get_channel_info(&exec_ctx, elem, channel_info); - grpc_exec_ctx_finish(&exec_ctx); + elem->filter->get_channel_info(elem, channel_info); } static grpc_call* grpc_channel_create_call_internal( - grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, - uint32_t propagation_mask, grpc_completion_queue* cq, - grpc_pollset_set* pollset_set_alternative, grpc_mdelem path_mdelem, - grpc_mdelem authority_mdelem, grpc_millis deadline) { + grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, + grpc_completion_queue* cq, grpc_pollset_set* pollset_set_alternative, + grpc_mdelem path_mdelem, grpc_mdelem authority_mdelem, + grpc_millis deadline) { grpc_mdelem send_metadata[2]; size_t num_metadata = 0; @@ -289,7 +285,7 @@ static grpc_call* grpc_channel_create_call_internal( args.send_deadline = deadline; grpc_call* call; - GRPC_LOG_IF_ERROR("call_create", grpc_call_create(exec_ctx, &args, &call)); + GRPC_LOG_IF_ERROR("call_create", grpc_call_create(&args, &call)); return call; } @@ -300,29 +296,27 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel, grpc_slice method, const grpc_slice* host, gpr_timespec deadline, void* reserved) { GPR_ASSERT(!reserved); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_call* call = grpc_channel_create_call_internal( - &exec_ctx, channel, parent_call, propagation_mask, cq, nullptr, - grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref_internal(method)), - host != nullptr ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, + channel, parent_call, propagation_mask, cq, nullptr, + grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), + host != nullptr ? grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, grpc_timespec_to_millis_round_up(deadline)); - grpc_exec_ctx_finish(&exec_ctx); + return call; } grpc_call* grpc_channel_create_pollset_set_call( - grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, - uint32_t propagation_mask, grpc_pollset_set* pollset_set, grpc_slice method, - const grpc_slice* host, grpc_millis deadline, void* reserved) { + grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, + grpc_pollset_set* pollset_set, grpc_slice method, const grpc_slice* host, + grpc_millis deadline, void* reserved) { GPR_ASSERT(!reserved); return grpc_channel_create_call_internal( - exec_ctx, channel, parent_call, propagation_mask, nullptr, pollset_set, - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref_internal(method)), - host != nullptr ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + channel, parent_call, propagation_mask, nullptr, pollset_set, + grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_ref_internal(method)), + host != nullptr ? grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, deadline); @@ -335,21 +329,21 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; rc->path = grpc_mdelem_from_slices( - &exec_ctx, GRPC_MDSTR_PATH, + GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string(method))); rc->authority = host ? grpc_mdelem_from_slices( - &exec_ctx, GRPC_MDSTR_AUTHORITY, + GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string(host))) : GRPC_MDNULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; gpr_mu_unlock(&channel->registered_call_mu); - grpc_exec_ctx_finish(&exec_ctx); + return rc; } @@ -370,12 +364,12 @@ grpc_call* grpc_channel_create_registered_call( registered_call_handle, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_call* call = grpc_channel_create_call_internal( - &exec_ctx, channel, parent_call, propagation_mask, completion_queue, - nullptr, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), + channel, parent_call, propagation_mask, completion_queue, nullptr, + GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), grpc_timespec_to_millis_round_up(deadline)); - grpc_exec_ctx_finish(&exec_ctx); + return call; } @@ -390,23 +384,21 @@ void grpc_channel_internal_ref(grpc_channel* c REF_ARG) { GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); } -void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, - grpc_channel* c REF_ARG) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); +void grpc_channel_internal_unref(grpc_channel* c REF_ARG) { + GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CHANNEL(c), REF_REASON); } -static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_channel(void* arg, grpc_error* error) { grpc_channel* channel = (grpc_channel*)arg; - grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CHANNEL(channel)); + grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel)); while (channel->registered_calls) { registered_call* rc = channel->registered_calls; channel->registered_calls = rc->next; - GRPC_MDELEM_UNREF(exec_ctx, rc->path); - GRPC_MDELEM_UNREF(exec_ctx, rc->authority); + GRPC_MDELEM_UNREF(rc->path); + GRPC_MDELEM_UNREF(rc->authority); gpr_free(rc); } - GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); + GRPC_MDELEM_UNREF(channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); @@ -415,16 +407,14 @@ static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, void grpc_channel_destroy(grpc_channel* channel) { grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel)); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Destroyed"); elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CHANNEL(channel), 0); - elem->filter->start_transport_op(&exec_ctx, elem, op); - - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "channel"); + elem->filter->start_transport_op(elem, op); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CHANNEL_INTERNAL_UNREF(channel, "channel"); } grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel) { @@ -436,8 +426,7 @@ grpc_compression_options grpc_channel_compression_options( return channel->compression_options; } -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx* exec_ctx, - grpc_channel* channel, int i) { +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: @@ -448,6 +437,6 @@ grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx* exec_ctx, return GRPC_MDELEM_GRPC_STATUS_2; } gpr_ltoa(i, tmp); - return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, + return grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); } diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index a2e53c777d..26d8fceb2f 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -23,13 +23,13 @@ #include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/surface/channel_stack_type.h" -grpc_channel* grpc_channel_create(grpc_exec_ctx* exec_ctx, const char* target, +grpc_channel* grpc_channel_create(const char* target, const grpc_channel_args* args, grpc_channel_stack_type channel_stack_type, grpc_transport* optional_transport); grpc_channel* grpc_channel_create_with_builder( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, + grpc_channel_stack_builder* builder, grpc_channel_stack_type channel_stack_type); /** Create a call given a grpc_channel, in order to call \a method. @@ -41,9 +41,9 @@ grpc_channel* grpc_channel_create_with_builder( properties from the server call to this new client call, depending on the value of \a propagation_mask (see propagation_bits.h for possible values) */ grpc_call* grpc_channel_create_pollset_set_call( - grpc_exec_ctx* exec_ctx, grpc_channel* channel, grpc_call* parent_call, - uint32_t propagation_mask, grpc_pollset_set* pollset_set, grpc_slice method, - const grpc_slice* host, grpc_millis deadline, void* reserved); + grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask, + grpc_pollset_set* pollset_set, grpc_slice method, const grpc_slice* host, + grpc_millis deadline, void* reserved); /** Get a (borrowed) pointer to this channels underlying channel stack */ grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel); @@ -52,8 +52,7 @@ grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel); status_code. The returned elem is owned by the caller. */ -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx* exec_ctx, - grpc_channel* channel, +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel, int status_code); size_t grpc_channel_get_call_size_estimate(grpc_channel* channel); @@ -61,20 +60,18 @@ void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size); #ifndef NDEBUG void grpc_channel_internal_ref(grpc_channel* channel, const char* reason); -void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, grpc_channel* channel, - const char* reason); +void grpc_channel_internal_unref(grpc_channel* channel, const char* reason); #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \ grpc_channel_internal_ref(channel, reason) -#define GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, reason) \ - grpc_channel_internal_unref(exec_ctx, channel, reason) +#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \ + grpc_channel_internal_unref(channel, reason) #else void grpc_channel_internal_ref(grpc_channel* channel); -void grpc_channel_internal_unref(grpc_exec_ctx* exec_ctx, - grpc_channel* channel); +void grpc_channel_internal_unref(grpc_channel* channel); #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \ grpc_channel_internal_ref(channel) -#define GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, reason) \ - grpc_channel_internal_unref(exec_ctx, channel) +#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \ + grpc_channel_internal_unref(channel) #endif /** Return the channel's compression options. */ diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index b563537f35..95cbbbd037 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -89,8 +89,7 @@ void grpc_channel_init_shutdown(void) { } } -bool grpc_channel_init_create_stack(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, grpc_channel_stack_type type) { GPR_ASSERT(g_finalized); @@ -99,7 +98,7 @@ bool grpc_channel_init_create_stack(grpc_exec_ctx* exec_ctx, for (size_t i = 0; i < g_slots[type].num_slots; i++) { const stage_slot* slot = &g_slots[type].slots[i]; - if (!slot->fn(exec_ctx, builder, slot->arg)) { + if (!slot->fn(builder, slot->arg)) { return false; } } diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index 556ecc4147..d702f0f325 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -32,8 +32,7 @@ /// One stage of mutation: call functions against \a builder to influence the /// finally constructed channel stack -typedef bool (*grpc_channel_init_stage)(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder* builder, void* arg); /// Global initialization of the system @@ -66,8 +65,7 @@ void grpc_channel_init_shutdown(void); /// \a optional_transport is either NULL or a constructed transport object /// Returns a pointer to the base of the memory allocated (the actual channel /// stack object will be prefix_bytes past that pointer) -bool grpc_channel_init_create_stack(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder, grpc_channel_stack_type type); #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */ diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index e8f47f01cf..616ba9e0ac 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -33,15 +33,14 @@ typedef struct { grpc_cq_completion completion_storage; } ping_result; -static void ping_destroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* storage) { +static void ping_destroy(void* arg, grpc_cq_completion* storage) { gpr_free(arg); } -static void ping_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void ping_done(void* arg, grpc_error* error) { ping_result* pr = (ping_result*)arg; - grpc_cq_end_op(exec_ctx, pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, - pr, &pr->completion_storage); + grpc_cq_end_op(pr->cq, pr->tag, GRPC_ERROR_REF(error), ping_destroy, pr, + &pr->completion_storage); } void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, @@ -52,7 +51,7 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(reserved == nullptr); pr->tag = tag; pr->cq = cq; @@ -60,6 +59,5 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, op->send_ping = &pr->closure; op->bind_pollset = grpc_cq_pollset(cq); GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - top_elem->filter->start_transport_op(&exec_ctx, top_elem, op); - grpc_exec_ctx_finish(&exec_ctx); + top_elem->filter->start_transport_op(top_elem, op); } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 98d7e35943..12385b7130 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -62,13 +62,12 @@ typedef struct { bool can_listen; size_t (*size)(void); void (*init)(grpc_pollset* pollset, gpr_mu** mu); - grpc_error* (*kick)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, + grpc_error* (*kick)(grpc_pollset* pollset, grpc_pollset_worker* specific_worker); - grpc_error* (*work)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker** worker, grpc_millis deadline); - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_closure* closure); - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset); + grpc_error* (*work)(grpc_pollset* pollset, grpc_pollset_worker** worker, + grpc_millis deadline); + void (*shutdown)(grpc_pollset* pollset, grpc_closure* closure); + void (*destroy)(grpc_pollset* pollset); } cq_poller_vtable; typedef struct non_polling_worker { @@ -94,14 +93,12 @@ static void non_polling_poller_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &npp->mu; } -static void non_polling_poller_destroy(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset) { +static void non_polling_poller_destroy(grpc_pollset* pollset) { non_polling_poller* npp = (non_polling_poller*)pollset; gpr_mu_destroy(&npp->mu); } -static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, +static grpc_error* non_polling_poller_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_millis deadline) { non_polling_poller* npp = (non_polling_poller*)pollset; @@ -122,12 +119,12 @@ static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline_ts)) ; - grpc_exec_ctx_invalidate_now(exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); if (&w == npp->root) { npp->root = w.next; if (&w == npp->root) { if (npp->shutdown) { - GRPC_CLOSURE_SCHED(exec_ctx, npp->shutdown, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(npp->shutdown, GRPC_ERROR_NONE); } npp->root = nullptr; } @@ -140,8 +137,7 @@ static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, } static grpc_error* non_polling_poller_kick( - grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) { + grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { non_polling_poller* p = (non_polling_poller*)pollset; if (specific_worker == nullptr) specific_worker = (grpc_pollset_worker*)p->root; @@ -155,14 +151,13 @@ static grpc_error* non_polling_poller_kick( return GRPC_ERROR_NONE; } -static void non_polling_poller_shutdown(grpc_exec_ctx* exec_ctx, - grpc_pollset* pollset, +static void non_polling_poller_shutdown(grpc_pollset* pollset, grpc_closure* closure) { non_polling_poller* p = (non_polling_poller*)pollset; GPR_ASSERT(closure != nullptr); p->shutdown = closure; if (p->root == nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } else { non_polling_worker* w = p->root; do { @@ -189,13 +184,11 @@ typedef struct cq_vtable { grpc_cq_completion_type cq_completion_type; size_t data_size; void (*init)(void* data); - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq); + void (*shutdown)(grpc_completion_queue* cq); void (*destroy)(void* data); bool (*begin_op)(grpc_completion_queue* cq, void* tag); - void (*end_op)(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, void* tag, - grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, - grpc_cq_completion* storage), + void (*end_op)(grpc_completion_queue* cq, void* tag, grpc_error* error, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); grpc_event (*next)(grpc_completion_queue* cq, gpr_timespec deadline, void* reserved); @@ -280,31 +273,23 @@ struct grpc_completion_queue { }; /* Forward declarations */ -static void cq_finish_shutdown_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq); -static void cq_finish_shutdown_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq); -static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq); -static void cq_shutdown_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq); +static void cq_finish_shutdown_next(grpc_completion_queue* cq); +static void cq_finish_shutdown_pluck(grpc_completion_queue* cq); +static void cq_shutdown_next(grpc_completion_queue* cq); +static void cq_shutdown_pluck(grpc_completion_queue* cq); static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag); static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag); -static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, - void* done_arg, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); -static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, - void* done_arg, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); @@ -346,8 +331,7 @@ grpc_core::TraceFlag grpc_cq_event_timeout_trace(true, "queue_timeout"); gpr_free(_ev); \ } -static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* cq, - grpc_error* error); +static void on_pollset_shutdown_done(void* cq, grpc_error* error); void grpc_cq_global_init() { gpr_tls_init(&g_cached_event); @@ -369,19 +353,18 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, if (storage != nullptr && (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; *ok = (storage->next & (uintptr_t)(1)) == 1; - storage->done(&exec_ctx, storage->done_arg, storage); + storage->done(storage->done_arg, storage); ret = 1; cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(&exec_ctx, cq); + cq_finish_shutdown_next(cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } - grpc_exec_ctx_finish(&exec_ctx); } gpr_tls_set(&g_cached_event, (intptr_t)0); gpr_tls_set(&g_cached_cq, (intptr_t)0); @@ -406,24 +389,22 @@ static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { grpc_cq_completion* c = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; if (gpr_spinlock_trylock(&q->queue_lock)) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(); bool is_empty = false; c = (grpc_cq_completion*)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); gpr_spinlock_unlock(&q->queue_lock); if (c == nullptr && !is_empty) { - GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(); } } else { - GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(&exec_ctx); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(); } - grpc_exec_ctx_finish(&exec_ctx); - if (c) { gpr_atm_no_barrier_fetch_add(&q->num_queue_items, -1); } @@ -453,9 +434,8 @@ grpc_completion_queue* grpc_completion_queue_create_internal( const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_CQS_CREATED(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_STATS_INC_CQS_CREATED(); cq = (grpc_completion_queue*)gpr_zalloc(sizeof(grpc_completion_queue) + vtable->data_size + @@ -537,15 +517,14 @@ void grpc_cq_internal_ref(grpc_completion_queue* cq) { gpr_ref(&cq->owning_refs); } -static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_pollset_shutdown_done(void* arg, grpc_error* error) { grpc_completion_queue* cq = (grpc_completion_queue*)arg; - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "pollset_destroy"); + GRPC_CQ_INTERNAL_UNREF(cq, "pollset_destroy"); } #ifndef NDEBUG -void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, - const char* reason, const char* file, int line) { +void grpc_cq_internal_unref(grpc_completion_queue* cq, const char* reason, + const char* file, int line) { if (grpc_trace_cq_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -553,12 +532,11 @@ void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, reason); } #else -void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq) { +void grpc_cq_internal_unref(grpc_completion_queue* cq) { #endif if (gpr_unref(&cq->owning_refs)) { cq->vtable->destroy(DATA_FROM_CQ(cq)); - cq->poller_vtable->destroy(exec_ctx, POLLSET_FROM_CQ(cq)); + cq->poller_vtable->destroy(POLLSET_FROM_CQ(cq)); #ifndef NDEBUG gpr_free(cq->outstanding_tags); #endif @@ -639,11 +617,9 @@ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) { /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_NEXT) */ -static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, - void* done_arg, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { GPR_TIMER_BEGIN("cq_end_op_for_next", 0); @@ -652,9 +628,9 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_next(cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 6, (cq, tag, errmsg, done, done_arg, storage)); if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -689,7 +665,7 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, if (is_first) { gpr_mu_lock(cq->mu); grpc_error* kick_error = - cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), nullptr); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); if (kick_error != GRPC_ERROR_NONE) { @@ -701,17 +677,17 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } } else { GRPC_CQ_INTERNAL_REF(cq, "shutting_down"); gpr_atm_rel_store(&cqd->pending_events, 0); gpr_mu_lock(cq->mu); - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } } @@ -723,11 +699,9 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, /* Queue a GRPC_OP_COMPLETED operation to a completion queue (with a * completion * type of GRPC_CQ_PLUCK) */ -static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq, void* tag, +static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, - void* done_arg, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); @@ -739,9 +713,9 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( - "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " + "cq_end_op_for_pluck(cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", - 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); + 6, (cq, tag, errmsg, done, done_arg, storage)); if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -762,7 +736,7 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, cqd->completed_tail = storage; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(exec_ctx, cq); + cq_finish_shutdown_pluck(cq); gpr_mu_unlock(cq->mu); } else { grpc_pollset_worker* pluck_worker = nullptr; @@ -774,7 +748,7 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, } grpc_error* kick_error = - cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), pluck_worker); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), pluck_worker); gpr_mu_unlock(cq->mu); @@ -791,12 +765,10 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, GRPC_ERROR_UNREF(error); } -void grpc_cq_end_op(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, - void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, - grpc_cq_completion* storage), +void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { - cq->vtable->end_op(exec_ctx, cq, tag, error, done, done_arg, storage); + cq->vtable->end_op(cq, tag, error, done, done_arg, storage); } typedef struct { @@ -808,31 +780,40 @@ typedef struct { bool first_loop; } cq_is_finished_arg; -static bool cq_is_next_finished(grpc_exec_ctx* exec_ctx, void* arg) { - cq_is_finished_arg* a = (cq_is_finished_arg*)arg; - grpc_completion_queue* cq = a->cq; - cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == nullptr); +class ExecCtxNext : public grpc_core::ExecCtx { + public: + ExecCtxNext(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} - gpr_atm current_last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); + bool CheckReadyToFinish() override { + cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + grpc_completion_queue* cq = a->cq; + cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); + GPR_ASSERT(a->stolen_completion == nullptr); - if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { - a->last_seen_things_queued_ever = + gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - /* Pop a cq_completion from the queue. Returns NULL if the queue is empty - * might return NULL in some cases even if the queue is not empty; but - * that - * is ok and doesn't affect correctness. Might effect the tail latencies a - * bit) */ - a->stolen_completion = cq_event_queue_pop(&cqd->queue); - if (a->stolen_completion != nullptr) { - return true; + if (current_last_seen_things_queued_ever != + a->last_seen_things_queued_ever) { + a->last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); + + /* Pop a cq_completion from the queue. Returns NULL if the queue is empty + * might return NULL in some cases even if the queue is not empty; but + * that + * is ok and doesn't affect correctness. Might effect the tail latencies a + * bit) */ + a->stolen_completion = cq_event_queue_pop(&cqd->queue); + if (a->stolen_completion != nullptr) { + return true; + } } + return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); -} + + private: + void* check_ready_to_finish_arg_; +}; #ifndef NDEBUG static void dump_pending_tags(grpc_completion_queue* cq) { @@ -887,8 +868,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, nullptr, nullptr, true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); + ExecCtxNext exec_ctx(&is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; @@ -898,7 +878,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } @@ -908,7 +888,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } else { /* If c == NULL it means either the queue is empty OR in an transient @@ -939,7 +919,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, } if (!is_finished_arg.first_loop && - grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { + grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; dump_pending_tags(cq); @@ -949,8 +929,8 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, /* The main polling work happens in grpc_pollset_work */ gpr_mu_lock(cq->mu); cq->num_polls++; - grpc_error* err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), - nullptr, iteration_deadline); + grpc_error* err = cq->poller_vtable->work(POLLSET_FROM_CQ(cq), nullptr, + iteration_deadline); gpr_mu_unlock(cq->mu); if (err != GRPC_ERROR_NONE) { @@ -969,13 +949,13 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, if (cq_event_queue_num_items(&cqd->queue) > 0 && gpr_atm_acq_load(&cqd->pending_events) > 0) { gpr_mu_lock(cq->mu); - cq->poller_vtable->kick(&exec_ctx, POLLSET_FROM_CQ(cq), nullptr); + cq->poller_vtable->kick(POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); } GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "next"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CQ_INTERNAL_UNREF(cq, "next"); + GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_next", 0); @@ -989,19 +969,16 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, - Must be called only once in completion queue's lifetime - grpc_completion_queue_shutdown() MUST have been called before calling this function */ -static void cq_finish_shutdown_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq) { +static void cq_finish_shutdown_next(grpc_completion_queue* cq) { cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(gpr_atm_no_barrier_load(&cqd->pending_events) == 0); - cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), - &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); } -static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq) { +static void cq_shutdown_next(grpc_completion_queue* cq) { cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -1014,7 +991,7 @@ static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); return; } cqd->shutdown_called = true; @@ -1022,10 +999,10 @@ static void cq_shutdown_next(grpc_exec_ctx* exec_ctx, * cq_begin_op_for_next and and cq_end_op_for_next functions which read/write * on this counter without necessarily holding a lock on cq */ if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_next(exec_ctx, cq); + cq_finish_shutdown_next(cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down"); } grpc_event grpc_completion_queue_next(grpc_completion_queue* cq, @@ -1058,37 +1035,46 @@ static void del_plucker(grpc_completion_queue* cq, void* tag, GPR_UNREACHABLE_CODE(return ); } -static bool cq_is_pluck_finished(grpc_exec_ctx* exec_ctx, void* arg) { - cq_is_finished_arg* a = (cq_is_finished_arg*)arg; - grpc_completion_queue* cq = a->cq; - cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); +class ExecCtxPluck : public grpc_core::ExecCtx { + public: + ExecCtxPluck(void* arg) : ExecCtx(0), check_ready_to_finish_arg_(arg) {} - GPR_ASSERT(a->stolen_completion == nullptr); - gpr_atm current_last_seen_things_queued_ever = - gpr_atm_no_barrier_load(&cqd->things_queued_ever); - if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { - gpr_mu_lock(cq->mu); - a->last_seen_things_queued_ever = + bool CheckReadyToFinish() override { + cq_is_finished_arg* a = (cq_is_finished_arg*)check_ready_to_finish_arg_; + grpc_completion_queue* cq = a->cq; + cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); + + GPR_ASSERT(a->stolen_completion == nullptr); + gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); - grpc_cq_completion* c; - grpc_cq_completion* prev = &cqd->completed_head; - while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != - &cqd->completed_head) { - if (c->tag == a->tag) { - prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); - if (c == cqd->completed_tail) { - cqd->completed_tail = prev; + if (current_last_seen_things_queued_ever != + a->last_seen_things_queued_ever) { + gpr_mu_lock(cq->mu); + a->last_seen_things_queued_ever = + gpr_atm_no_barrier_load(&cqd->things_queued_ever); + grpc_cq_completion* c; + grpc_cq_completion* prev = &cqd->completed_head; + while ((c = (grpc_cq_completion*)(prev->next & ~(uintptr_t)1)) != + &cqd->completed_head) { + if (c->tag == a->tag) { + prev->next = (prev->next & (uintptr_t)1) | (c->next & ~(uintptr_t)1); + if (c == cqd->completed_tail) { + cqd->completed_tail = prev; + } + gpr_mu_unlock(cq->mu); + a->stolen_completion = c; + return true; } - gpr_mu_unlock(cq->mu); - a->stolen_completion = c; - return true; + prev = c; } - prev = c; + gpr_mu_unlock(cq->mu); } - gpr_mu_unlock(cq->mu); + return !a->first_loop && a->deadline < grpc_core::ExecCtx::Get()->Now(); } - return !a->first_loop && a->deadline < grpc_exec_ctx_now(exec_ctx); -} + + private: + void* check_ready_to_finish_arg_; +}; static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved) { @@ -1125,8 +1111,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, nullptr, tag, true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); + ExecCtxPluck exec_ctx(&is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != nullptr) { gpr_mu_unlock(cq->mu); @@ -1135,7 +1120,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); break; } prev = &cqd->completed_head; @@ -1150,7 +1135,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; - c->done(&exec_ctx, c->done_arg, c); + c->done(c->done_arg, c); goto done; } prev = c; @@ -1174,7 +1159,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } if (!is_finished_arg.first_loop && - grpc_exec_ctx_now(&exec_ctx) >= deadline_millis) { + grpc_core::ExecCtx::Get()->Now() >= deadline_millis) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); memset(&ret, 0, sizeof(ret)); @@ -1183,8 +1168,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, break; } cq->num_polls++; - grpc_error* err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), - &worker, deadline_millis); + grpc_error* err = + cq->poller_vtable->work(POLLSET_FROM_CQ(cq), &worker, deadline_millis); if (err != GRPC_ERROR_NONE) { del_plucker(cq, tag, &worker); gpr_mu_unlock(cq->mu); @@ -1202,8 +1187,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, } done: GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "pluck"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_CQ_INTERNAL_UNREF(cq, "pluck"); + GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_pluck", 0); @@ -1216,22 +1201,19 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, return cq->vtable->pluck(cq, tag, deadline, reserved); } -static void cq_finish_shutdown_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq) { +static void cq_finish_shutdown_pluck(grpc_completion_queue* cq) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); GPR_ASSERT(cqd->shutdown_called); GPR_ASSERT(!gpr_atm_no_barrier_load(&cqd->shutdown)); gpr_atm_no_barrier_store(&cqd->shutdown, 1); - cq->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cq), - &cq->pollset_shutdown_done); + cq->poller_vtable->shutdown(POLLSET_FROM_CQ(cq), &cq->pollset_shutdown_done); } /* NOTE: This function is almost exactly identical to cq_shutdown_next() but * merging them is a bit tricky and probably not worth it */ -static void cq_shutdown_pluck(grpc_exec_ctx* exec_ctx, - grpc_completion_queue* cq) { +static void cq_shutdown_pluck(grpc_completion_queue* cq) { cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); /* Need an extra ref for cq here because: @@ -1244,25 +1226,25 @@ static void cq_shutdown_pluck(grpc_exec_ctx* exec_ctx, gpr_mu_lock(cq->mu); if (cqd->shutdown_called) { gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); return; } cqd->shutdown_called = true; if (gpr_atm_full_fetch_add(&cqd->pending_events, -1) == 1) { - cq_finish_shutdown_pluck(exec_ctx, cq); + cq_finish_shutdown_pluck(cq); } gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(exec_ctx, cq, "shutting_down (pluck cq)"); + GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (pluck cq)"); } /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); - cq->vtable->shutdown(&exec_ctx, cq); - grpc_exec_ctx_finish(&exec_ctx); + cq->vtable->shutdown(cq); + GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } @@ -1271,9 +1253,9 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "destroy"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); + GPR_TIMER_END("grpc_completion_queue_destroy", 0); } diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 13d3e5807d..aea47afaf5 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -40,8 +40,7 @@ typedef struct grpc_cq_completion { void* tag; /** done callback - called when this queue element is no longer needed by the completion queue */ - void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, - struct grpc_cq_completion* c); + void (*done)(void* done_arg, struct grpc_cq_completion* c); void* done_arg; /** next pointer; low bit is used to indicate success or not */ uintptr_t next; @@ -50,17 +49,17 @@ typedef struct grpc_cq_completion { #ifndef NDEBUG void grpc_cq_internal_ref(grpc_completion_queue* cc, const char* reason, const char* file, int line); -void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc, - const char* reason, const char* file, int line); +void grpc_cq_internal_unref(grpc_completion_queue* cc, const char* reason, + const char* file, int line); #define GRPC_CQ_INTERNAL_REF(cc, reason) \ grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__) -#define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) \ - grpc_cq_internal_unref(ec, cc, reason, __FILE__, __LINE__) +#define GRPC_CQ_INTERNAL_UNREF(cc, reason) \ + grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__) #else void grpc_cq_internal_ref(grpc_completion_queue* cc); -void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc); +void grpc_cq_internal_unref(grpc_completion_queue* cc); #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc) -#define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) grpc_cq_internal_unref(ec, cc) +#define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc) #endif /* Initializes global variables used by completion queues */ @@ -74,10 +73,8 @@ bool grpc_cq_begin_op(grpc_completion_queue* cc, void* tag); /* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to grpc_cq_begin_op */ -void grpc_cq_end_op(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cc, - void* tag, grpc_error* error, - void (*done)(grpc_exec_ctx* exec_ctx, void* done_arg, - grpc_cq_completion* storage), +void grpc_cq_end_op(grpc_completion_queue* cc, void* tag, grpc_error* error, + void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage); grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cc); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 8ee1383fb8..c6ce235da7 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -73,14 +73,12 @@ static void do_basic_init(void) { grpc_fork_handlers_auto_register(); } -static bool append_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } -static bool prepend_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } @@ -123,7 +121,6 @@ void grpc_init(void) { int i; gpr_once_init(&g_basic_init, do_basic_init); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); @@ -133,7 +130,8 @@ void grpc_init(void) { grpc_mdctx_global_init(); grpc_channel_init_init(); grpc_security_pre_init(); - grpc_iomgr_init(&exec_ctx); + grpc_core::ExecCtx::GlobalInit(); + grpc_iomgr_init(); gpr_timers_global_init(); grpc_handshaker_factory_registry_init(); grpc_security_init(); @@ -149,37 +147,44 @@ void grpc_init(void) { grpc_tracer_init("GRPC_TRACE"); /* no more changes to channel init pipelines */ grpc_channel_init_finalize(); - grpc_iomgr_start(&exec_ctx); + grpc_iomgr_start(); } gpr_mu_unlock(&g_init_mu); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_API_TRACE("grpc_init(void)", 0, ()); } void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); + if (grpc_core::ExecCtx::Get()) { + grpc_core::ExecCtx::Get()->Flush(); + } gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { - grpc_executor_shutdown(&exec_ctx); - grpc_timer_manager_set_threading(false); // shutdown timer_manager thread - for (i = g_number_of_plugins; i >= 0; i--) { - if (g_all_of_the_plugins[i].destroy != nullptr) { - g_all_of_the_plugins[i].destroy(); + { + grpc_core::ExecCtx exec_ctx(0); + { + grpc_executor_shutdown(); + grpc_timer_manager_set_threading( + false); // shutdown timer_manager thread + for (i = g_number_of_plugins; i >= 0; i--) { + if (g_all_of_the_plugins[i].destroy != nullptr) { + g_all_of_the_plugins[i].destroy(); + } + } } + grpc_iomgr_shutdown(); + gpr_timers_global_destroy(); + grpc_tracer_shutdown(); + grpc_mdctx_global_shutdown(); + grpc_handshaker_factory_registry_shutdown(); + grpc_slice_intern_shutdown(); + grpc_stats_shutdown(); } - grpc_iomgr_shutdown(&exec_ctx); - gpr_timers_global_destroy(); - grpc_tracer_shutdown(); - grpc_mdctx_global_shutdown(&exec_ctx); - grpc_handshaker_factory_registry_shutdown(&exec_ctx); - grpc_slice_intern_shutdown(); - grpc_stats_shutdown(); + grpc_core::ExecCtx::GlobalShutdown(); } gpr_mu_unlock(&g_init_mu); - grpc_exec_ctx_finish(&exec_ctx); } int grpc_is_initialized(void) { diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 3eee570fc2..75ed9faef0 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -37,7 +37,7 @@ void grpc_security_pre_init(void) {} static bool maybe_prepend_client_auth_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { @@ -52,7 +52,7 @@ static bool maybe_prepend_client_auth_filter( } static bool maybe_prepend_server_auth_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index c32c9af50e..29b4e3f0c7 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -49,8 +49,7 @@ struct ChannelData { const char* error_message; }; -static void fill_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_metadata_batch* mdb) { +static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { CallData* calld = reinterpret_cast(elem->call_data); bool expected = false; if (!calld->filled_metadata.compare_exchange_strong( @@ -62,9 +61,9 @@ static void fill_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); calld->status.md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); + GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); calld->details.md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_from_copied_string(chand->error_message)); calld->status.prev = calld->details.next = nullptr; calld->status.next = &calld->details; @@ -76,69 +75,61 @@ static void fill_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, } static void lame_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { CallData* calld = reinterpret_cast(elem->call_data); if (op->recv_initial_metadata) { - fill_metadata(exec_ctx, elem, + fill_metadata(elem, op->payload->recv_initial_metadata.recv_initial_metadata); } else if (op->recv_trailing_metadata) { - fill_metadata(exec_ctx, elem, + fill_metadata(elem, op->payload->recv_trailing_metadata.recv_trailing_metadata); } grpc_transport_stream_op_batch_finish_with_failure( - exec_ctx, op, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"), + op, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"), calld->call_combiner); } -static void lame_get_channel_info(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void lame_get_channel_info(grpc_channel_element* elem, const grpc_channel_info* channel_info) {} -static void lame_start_transport_op(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void lame_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { if (op->on_connectivity_state_change) { GPR_ASSERT(*op->connectivity_state != GRPC_CHANNEL_SHUTDOWN); *op->connectivity_state = GRPC_CHANNEL_SHUTDOWN; - GRPC_CLOSURE_SCHED(exec_ctx, op->on_connectivity_state_change, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_connectivity_state_change, GRPC_ERROR_NONE); } if (op->send_ping != nullptr) { - GRPC_CLOSURE_SCHED( - exec_ctx, op->send_ping, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel")); + GRPC_CLOSURE_SCHED(op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "lame client channel")); } GRPC_ERROR_UNREF(op->disconnect_with_error); if (op->on_consumed != nullptr) { - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } } -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { CallData* calld = reinterpret_cast(elem->call_data); calld->call_combiner = args->call_combiner; return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_schedule_closure) { - GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(then_schedule_closure, GRPC_ERROR_NONE); } -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} } // namespace @@ -163,10 +154,10 @@ const grpc_channel_filter grpc_lame_filter = { grpc_channel* grpc_lame_client_channel_create(const char* target, grpc_status_code error_code, const char* error_message) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem; - grpc_channel* channel = grpc_channel_create( - &exec_ctx, target, nullptr, GRPC_CLIENT_LAME_CHANNEL, nullptr); + grpc_channel* channel = + grpc_channel_create(target, nullptr, GRPC_CLIENT_LAME_CHANNEL, nullptr); elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); GRPC_API_TRACE( "grpc_lame_client_channel_create(target=%s, error_code=%d, " @@ -176,6 +167,6 @@ grpc_channel* grpc_lame_client_channel_create(const char* target, auto chand = reinterpret_cast(elem->channel_data); chand->error_code = error_code; chand->error_message = error_message; - grpc_exec_ctx_finish(&exec_ctx); + return channel; } diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 0f8a057f31..4f07183180 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -46,10 +46,9 @@ typedef struct listener { void* arg; - void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_pollset** pollsets, size_t pollset_count); - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_closure* closure); + void (*start)(grpc_server* server, void* arg, grpc_pollset** pollsets, + size_t pollset_count); + void (*destroy)(grpc_server* server, void* arg, grpc_closure* closure); struct listener* next; grpc_closure destroy_done; } listener; @@ -224,13 +223,12 @@ struct grpc_server { #define SERVER_FROM_CALL_ELEM(elem) \ (((channel_data*)(elem)->channel_data)->server) -static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* calld, - grpc_error* error); -static void fail_call(grpc_exec_ctx* exec_ctx, grpc_server* server, - size_t cq_idx, requested_call* rc, grpc_error* error); +static void publish_new_rpc(void* calld, grpc_error* error); +static void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc, + grpc_error* error); /* Before calling maybe_finish_shutdown, we must hold mu_global and not hold mu_call */ -static void maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_server* server); +static void maybe_finish_shutdown(grpc_server* server); /* * channel broadcaster @@ -258,15 +256,14 @@ struct shutdown_cleanup_args { grpc_slice slice; }; -static void shutdown_cleanup(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void shutdown_cleanup(void* arg, grpc_error* error) { struct shutdown_cleanup_args* a = (struct shutdown_cleanup_args*)arg; - grpc_slice_unref_internal(exec_ctx, a->slice); + grpc_slice_unref_internal(a->slice); gpr_free(a); } -static void send_shutdown(grpc_exec_ctx* exec_ctx, grpc_channel* channel, - bool send_goaway, grpc_error* send_disconnect) { +static void send_shutdown(grpc_channel* channel, bool send_goaway, + grpc_error* send_disconnect) { struct shutdown_cleanup_args* sc = (struct shutdown_cleanup_args*)gpr_malloc(sizeof(*sc)); GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc, @@ -284,19 +281,18 @@ static void send_shutdown(grpc_exec_ctx* exec_ctx, grpc_channel* channel, op->disconnect_with_error = send_disconnect; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - elem->filter->start_transport_op(exec_ctx, elem, op); + elem->filter->start_transport_op(elem, op); } -static void channel_broadcaster_shutdown(grpc_exec_ctx* exec_ctx, - channel_broadcaster* cb, +static void channel_broadcaster_shutdown(channel_broadcaster* cb, bool send_goaway, grpc_error* force_disconnect) { size_t i; for (i = 0; i < cb->num_channels; i++) { - send_shutdown(exec_ctx, cb->channels[i], send_goaway, + send_shutdown(cb->channels[i], send_goaway, GRPC_ERROR_REF(force_disconnect)); - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, cb->channels[i], "broadcast"); + GRPC_CHANNEL_INTERNAL_UNREF(cb->channels[i], "broadcast"); } gpr_free(cb->channels); GRPC_ERROR_UNREF(force_disconnect); @@ -324,13 +320,11 @@ static void request_matcher_destroy(request_matcher* rm) { gpr_free(rm->requests_per_cq); } -static void kill_zombie(grpc_exec_ctx* exec_ctx, void* elem, - grpc_error* error) { +static void kill_zombie(void* elem, grpc_error* error) { grpc_call_unref(grpc_call_from_top_element((grpc_call_element*)elem)); } -static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx* exec_ctx, - request_matcher* rm) { +static void request_matcher_zombify_all_pending_calls(request_matcher* rm) { while (rm->pending_head) { call_data* calld = rm->pending_head; rm->pending_head = calld->pending_next; @@ -339,19 +333,18 @@ static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx* exec_ctx, &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); } } -static void request_matcher_kill_requests(grpc_exec_ctx* exec_ctx, - grpc_server* server, +static void request_matcher_kill_requests(grpc_server* server, request_matcher* rm, grpc_error* error) { requested_call* rc; for (size_t i = 0; i < server->cq_count; i++) { while ((rc = (requested_call*)gpr_locked_mpscq_pop( &rm->requests_per_cq[i])) != nullptr) { - fail_call(exec_ctx, server, i, rc, GRPC_ERROR_REF(error)); + fail_call(server, i, rc, GRPC_ERROR_REF(error)); } } GRPC_ERROR_UNREF(error); @@ -365,10 +358,10 @@ static void server_ref(grpc_server* server) { gpr_ref(&server->internal_refcount); } -static void server_delete(grpc_exec_ctx* exec_ctx, grpc_server* server) { +static void server_delete(grpc_server* server) { registered_method* rm; size_t i; - grpc_channel_args_destroy(exec_ctx, server->channel_args); + grpc_channel_args_destroy(server->channel_args); gpr_mu_destroy(&server->mu_global); gpr_mu_destroy(&server->mu_call); gpr_cv_destroy(&server->starting_cv); @@ -385,7 +378,7 @@ static void server_delete(grpc_exec_ctx* exec_ctx, grpc_server* server) { request_matcher_destroy(&server->unregistered_request_matcher); } for (i = 0; i < server->cq_count; i++) { - GRPC_CQ_INTERNAL_UNREF(exec_ctx, server->cqs[i], "server"); + GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server"); } gpr_free(server->cqs); gpr_free(server->pollsets); @@ -393,9 +386,9 @@ static void server_delete(grpc_exec_ctx* exec_ctx, grpc_server* server) { gpr_free(server); } -static void server_unref(grpc_exec_ctx* exec_ctx, grpc_server* server) { +static void server_unref(grpc_server* server) { if (gpr_unref(&server->internal_refcount)) { - server_delete(exec_ctx, server); + server_delete(server); } } @@ -409,21 +402,19 @@ static void orphan_channel(channel_data* chand) { chand->next = chand->prev = chand; } -static void finish_destroy_channel(grpc_exec_ctx* exec_ctx, void* cd, - grpc_error* error) { +static void finish_destroy_channel(void* cd, grpc_error* error) { channel_data* chand = (channel_data*)cd; grpc_server* server = chand->server; - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, chand->channel, "server"); - server_unref(exec_ctx, server); + GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server"); + server_unref(server); } -static void destroy_channel(grpc_exec_ctx* exec_ctx, channel_data* chand, - grpc_error* error) { +static void destroy_channel(channel_data* chand, grpc_error* error) { if (is_channel_orphaned(chand)) return; GPR_ASSERT(chand->server != nullptr); orphan_channel(chand); server_ref(chand->server); - maybe_finish_shutdown(exec_ctx, chand->server); + maybe_finish_shutdown(chand->server); GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, finish_destroy_channel, chand, grpc_schedule_on_exec_ctx); @@ -436,20 +427,18 @@ static void destroy_channel(grpc_exec_ctx* exec_ctx, channel_data* chand, grpc_transport_op* op = grpc_make_transport_op(&chand->finish_destroy_channel_closure); op->set_accept_stream = true; - grpc_channel_next_op(exec_ctx, - grpc_channel_stack_element( + grpc_channel_next_op(grpc_channel_stack_element( grpc_channel_get_channel_stack(chand->channel), 0), op); } -static void done_request_event(grpc_exec_ctx* exec_ctx, void* req, - grpc_cq_completion* c) { +static void done_request_event(void* req, grpc_cq_completion* c) { gpr_free(req); } -static void publish_call(grpc_exec_ctx* exec_ctx, grpc_server* server, - call_data* calld, size_t cq_idx, requested_call* rc) { - grpc_call_set_completion_queue(exec_ctx, calld->call, rc->cq_bound_to_call); +static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx, + requested_call* rc) { + grpc_call_set_completion_queue(calld->call, rc->cq_bound_to_call); grpc_call* call = calld->call; *rc->call = call; calld->cq_new = server->cqs[cq_idx]; @@ -476,12 +465,11 @@ static void publish_call(grpc_exec_ctx* exec_ctx, grpc_server* server, GPR_UNREACHABLE_CODE(return ); } - grpc_cq_end_op(exec_ctx, calld->cq_new, rc->tag, GRPC_ERROR_NONE, - done_request_event, rc, &rc->completion); + grpc_cq_end_op(calld->cq_new, rc->tag, GRPC_ERROR_NONE, done_request_event, + rc, &rc->completion); } -static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void publish_new_rpc(void* arg, grpc_error* error) { grpc_call_element* call_elem = (grpc_call_element*)arg; call_data* calld = (call_data*)call_elem->call_data; channel_data* chand = (channel_data*)call_elem->channel_data; @@ -494,8 +482,7 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, - GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_REF(error)); return; } @@ -506,15 +493,15 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, if (rc == nullptr) { continue; } else { - GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i); + GRPC_STATS_INC_SERVER_CQS_CHECKED(i); gpr_atm_no_barrier_store(&calld->state, ACTIVATED); - publish_call(exec_ctx, server, calld, cq_idx, rc); + publish_call(server, calld, cq_idx, rc); return; /* early out */ } } /* no cq to take the request found: queue it on the slow list */ - GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx); + GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(); gpr_mu_lock(&server->mu_call); // We need to ensure that all the queues are empty. We do this under @@ -529,9 +516,9 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, continue; } else { gpr_mu_unlock(&server->mu_call); - GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i + server->cq_count); + GRPC_STATS_INC_SERVER_CQS_CHECKED(i + server->cq_count); gpr_atm_no_barrier_store(&calld->state, ACTIVATED); - publish_call(exec_ctx, server, calld, cq_idx, rc); + publish_call(server, calld, cq_idx, rc); return; /* early out */ } } @@ -548,8 +535,7 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, } static void finish_start_new_rpc( - grpc_exec_ctx* exec_ctx, grpc_server* server, grpc_call_element* elem, - request_matcher* rm, + grpc_server* server, grpc_call_element* elem, request_matcher* rm, grpc_server_register_method_payload_handling payload_handling) { call_data* calld = (call_data*)elem->call_data; @@ -557,7 +543,7 @@ static void finish_start_new_rpc( gpr_atm_no_barrier_store(&calld->state, ZOMBIED); GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); return; } @@ -565,7 +551,7 @@ static void finish_start_new_rpc( switch (payload_handling) { case GRPC_SRM_PAYLOAD_NONE: - publish_new_rpc(exec_ctx, elem, GRPC_ERROR_NONE); + publish_new_rpc(elem, GRPC_ERROR_NONE); break; case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: { grpc_op op; @@ -574,14 +560,13 @@ static void finish_start_new_rpc( op.data.recv_message.recv_message = &calld->payload; GRPC_CLOSURE_INIT(&calld->publish, publish_new_rpc, elem, grpc_schedule_on_exec_ctx); - grpc_call_start_batch_and_execute(exec_ctx, calld->call, &op, 1, - &calld->publish); + grpc_call_start_batch_and_execute(calld->call, &op, 1, &calld->publish); break; } } } -static void start_new_rpc(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { +static void start_new_rpc(grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; grpc_server* server = chand->server; @@ -606,8 +591,7 @@ static void start_new_rpc(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) { continue; } - finish_start_new_rpc(exec_ctx, server, elem, - &rm->server_registered_method->matcher, + finish_start_new_rpc(server, elem, &rm->server_registered_method->matcher, rm->server_registered_method->payload_handling); return; } @@ -624,14 +608,12 @@ static void start_new_rpc(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) { continue; } - finish_start_new_rpc(exec_ctx, server, elem, - &rm->server_registered_method->matcher, + finish_start_new_rpc(server, elem, &rm->server_registered_method->matcher, rm->server_registered_method->payload_handling); return; } } - finish_start_new_rpc(exec_ctx, server, elem, - &server->unregistered_request_matcher, + finish_start_new_rpc(server, elem, &server->unregistered_request_matcher, GRPC_SRM_PAYLOAD_NONE); } @@ -644,9 +626,8 @@ static int num_listeners(grpc_server* server) { return n; } -static void done_shutdown_event(grpc_exec_ctx* exec_ctx, void* server, - grpc_cq_completion* completion) { - server_unref(exec_ctx, (grpc_server*)server); +static void done_shutdown_event(void* server, grpc_cq_completion* completion) { + server_unref((grpc_server*)server); } static int num_channels(grpc_server* server) { @@ -659,34 +640,30 @@ static int num_channels(grpc_server* server) { return n; } -static void kill_pending_work_locked(grpc_exec_ctx* exec_ctx, - grpc_server* server, grpc_error* error) { +static void kill_pending_work_locked(grpc_server* server, grpc_error* error) { if (server->started) { - request_matcher_kill_requests(exec_ctx, server, - &server->unregistered_request_matcher, + request_matcher_kill_requests(server, &server->unregistered_request_matcher, GRPC_ERROR_REF(error)); request_matcher_zombify_all_pending_calls( - exec_ctx, &server->unregistered_request_matcher); + &server->unregistered_request_matcher); for (registered_method* rm = server->registered_methods; rm; rm = rm->next) { - request_matcher_kill_requests(exec_ctx, server, &rm->matcher, + request_matcher_kill_requests(server, &rm->matcher, GRPC_ERROR_REF(error)); - request_matcher_zombify_all_pending_calls(exec_ctx, &rm->matcher); + request_matcher_zombify_all_pending_calls(&rm->matcher); } } GRPC_ERROR_UNREF(error); } -static void maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, - grpc_server* server) { +static void maybe_finish_shutdown(grpc_server* server) { size_t i; if (!gpr_atm_acq_load(&server->shutdown_flag) || server->shutdown_published) { return; } kill_pending_work_locked( - exec_ctx, server, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); + server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); if (server->root_channel_data.next != &server->root_channel_data || server->listeners_destroyed < num_listeners(server)) { @@ -706,15 +683,13 @@ static void maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, server->shutdown_published = 1; for (i = 0; i < server->num_shutdown_tags; i++) { server_ref(server); - grpc_cq_end_op(exec_ctx, server->shutdown_tags[i].cq, - server->shutdown_tags[i].tag, GRPC_ERROR_NONE, - done_shutdown_event, server, + grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag, + GRPC_ERROR_NONE, done_shutdown_event, server, &server->shutdown_tags[i].completion); } } -static void server_on_recv_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, - grpc_error* error) { +static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)ptr; call_data* calld = (call_data*)elem->call_data; grpc_millis op_deadline; @@ -728,10 +703,10 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); calld->path_set = true; calld->host_set = true; - grpc_metadata_batch_remove(exec_ctx, calld->recv_initial_metadata, + grpc_metadata_batch_remove(calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.path); grpc_metadata_batch_remove( - exec_ctx, calld->recv_initial_metadata, + calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.authority); } else { GRPC_ERROR_REF(error); @@ -749,7 +724,7 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, GRPC_ERROR_UNREF(src_error); } - GRPC_CLOSURE_RUN(exec_ctx, calld->on_done_recv_initial_metadata, error); + GRPC_CLOSURE_RUN(calld->on_done_recv_initial_metadata, error); } static void server_mutate_op(grpc_call_element* elem, @@ -770,24 +745,21 @@ static void server_mutate_op(grpc_call_element* elem, } static void server_start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { server_mutate_op(elem, op); - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } -static void got_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, - grpc_error* error) { +static void got_initial_metadata(void* ptr, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)ptr; call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { - start_new_rpc(exec_ctx, elem); + start_new_rpc(elem); } else { if (gpr_atm_full_cas(&calld->state, NOT_STARTED, ZOMBIED)) { GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); } else if (gpr_atm_full_cas(&calld->state, PENDING, ZOMBIED)) { /* zombied call will be destroyed when it's removed from the pending queue... later */ @@ -795,8 +767,7 @@ static void got_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, } } -static void accept_stream(grpc_exec_ctx* exec_ctx, void* cd, - grpc_transport* transport, +static void accept_stream(void* cd, grpc_transport* transport, const void* transport_server_data) { channel_data* chand = (channel_data*)cd; /* create a call */ @@ -806,11 +777,11 @@ static void accept_stream(grpc_exec_ctx* exec_ctx, void* cd, args.server_transport_data = transport_server_data; args.send_deadline = GRPC_MILLIS_INF_FUTURE; grpc_call* call; - grpc_error* error = grpc_call_create(exec_ctx, &args, &call); + grpc_error* error = grpc_call_create(&args, &call); grpc_call_element* elem = grpc_call_stack_element(grpc_call_get_call_stack(call), 0); if (error != GRPC_ERROR_NONE) { - got_initial_metadata(exec_ctx, elem, error); + got_initial_metadata(elem, error); GRPC_ERROR_UNREF(error); return; } @@ -822,32 +793,28 @@ static void accept_stream(grpc_exec_ctx* exec_ctx, void* cd, &calld->initial_metadata; GRPC_CLOSURE_INIT(&calld->got_initial_metadata, got_initial_metadata, elem, grpc_schedule_on_exec_ctx); - grpc_call_start_batch_and_execute(exec_ctx, call, &op, 1, - &calld->got_initial_metadata); + grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata); } -static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* cd, - grpc_error* error) { +static void channel_connectivity_changed(void* cd, grpc_error* error) { channel_data* chand = (channel_data*)cd; grpc_server* server = chand->server; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed; op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(exec_ctx, - grpc_channel_stack_element( + grpc_channel_next_op(grpc_channel_stack_element( grpc_channel_get_channel_stack(chand->channel), 0), op); } else { gpr_mu_lock(&server->mu_global); - destroy_channel(exec_ctx, chand, GRPC_ERROR_REF(error)); + destroy_channel(chand, GRPC_ERROR_REF(error)); gpr_mu_unlock(&server->mu_global); - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, chand->channel, "connectivity"); + GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "connectivity"); } } -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; @@ -863,7 +830,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { channel_data* chand = (channel_data*)elem->channel_data; @@ -872,19 +839,18 @@ static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, GPR_ASSERT(calld->state != PENDING); if (calld->host_set) { - grpc_slice_unref_internal(exec_ctx, calld->host); + grpc_slice_unref_internal(calld->host); } if (calld->path_set) { - grpc_slice_unref_internal(exec_ctx, calld->path); + grpc_slice_unref_internal(calld->path); } grpc_metadata_array_destroy(&calld->initial_metadata); grpc_byte_buffer_destroy(calld->payload); - server_unref(exec_ctx, chand->server); + server_unref(chand->server); } -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_first); @@ -900,15 +866,14 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { +static void destroy_channel_elem(grpc_channel_element* elem) { size_t i; channel_data* chand = (channel_data*)elem->channel_data; if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { - grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].method); + grpc_slice_unref_internal(chand->registered_methods[i].method); if (chand->registered_methods[i].has_host) { - grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].host); + grpc_slice_unref_internal(chand->registered_methods[i].host); } } gpr_free(chand->registered_methods); @@ -918,9 +883,9 @@ static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, chand->next->prev = chand->prev; chand->prev->next = chand->next; chand->next = chand->prev = chand; - maybe_finish_shutdown(exec_ctx, chand->server); + maybe_finish_shutdown(chand->server); gpr_mu_unlock(&chand->server->mu_global); - server_unref(exec_ctx, chand->server); + server_unref(chand->server); } } @@ -1034,11 +999,10 @@ void* grpc_server_register_method( return m; } -static void start_listeners(grpc_exec_ctx* exec_ctx, void* s, - grpc_error* error) { +static void start_listeners(void* s, grpc_error* error) { grpc_server* server = (grpc_server*)s; for (listener* l = server->listeners; l; l = l->next) { - l->start(exec_ctx, server, l->arg, server->pollsets, server->pollset_count); + l->start(server, l->arg, server->pollsets, server->pollset_count); } gpr_mu_lock(&server->mu_global); @@ -1046,12 +1010,12 @@ static void start_listeners(grpc_exec_ctx* exec_ctx, void* s, gpr_cv_signal(&server->starting_cv); gpr_mu_unlock(&server->mu_global); - server_unref(exec_ctx, server); + server_unref(server); } void grpc_server_start(grpc_server* server) { size_t i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server)); @@ -1073,12 +1037,9 @@ void grpc_server_start(grpc_server* server) { server_ref(server); server->starting = true; GRPC_CLOSURE_SCHED( - &exec_ctx, GRPC_CLOSURE_CREATE(start_listeners, server, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)), GRPC_ERROR_NONE); - - grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, @@ -1087,8 +1048,7 @@ void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, *pollsets = server->pollsets; } -void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, - grpc_transport* transport, +void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args) { size_t num_registered_methods; @@ -1103,8 +1063,7 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, uint32_t max_probes = 0; grpc_transport_op* op = nullptr; - channel = grpc_channel_create(exec_ctx, nullptr, args, GRPC_SERVER_CHANNEL, - transport); + channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport); chand = (channel_data*)grpc_channel_stack_element( grpc_channel_get_channel_stack(channel), 0) ->channel_data; @@ -1181,21 +1140,19 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"); } - grpc_transport_perform_op(exec_ctx, transport, op); + grpc_transport_perform_op(transport, op); } -void done_published_shutdown(grpc_exec_ctx* exec_ctx, void* done_arg, - grpc_cq_completion* storage) { +void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) { (void)done_arg; gpr_free(storage); } -static void listener_destroy_done(grpc_exec_ctx* exec_ctx, void* s, - grpc_error* error) { +static void listener_destroy_done(void* s, grpc_error* error) { grpc_server* server = (grpc_server*)s; gpr_mu_lock(&server->mu_global); server->listeners_destroyed++; - maybe_finish_shutdown(exec_ctx, server); + maybe_finish_shutdown(server); gpr_mu_unlock(&server->mu_global); } @@ -1204,7 +1161,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, listener* l; shutdown_tag* sdt; channel_broadcaster broadcaster; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3, (server, cq, tag)); @@ -1219,11 +1176,10 @@ void grpc_server_shutdown_and_notify(grpc_server* server, /* stay locked, and gather up some stuff to do */ GPR_ASSERT(grpc_cq_begin_op(cq, tag)); if (server->shutdown_published) { - grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown, - nullptr, + grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); gpr_mu_unlock(&server->mu_global); - goto done; + return; } server->shutdown_tags = (shutdown_tag*)gpr_realloc( server->shutdown_tags, @@ -1233,7 +1189,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, sdt->cq = cq; if (gpr_atm_acq_load(&server->shutdown_flag)) { gpr_mu_unlock(&server->mu_global); - goto done; + return; } server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME); @@ -1245,30 +1201,26 @@ void grpc_server_shutdown_and_notify(grpc_server* server, /* collect all unregistered then registered calls */ gpr_mu_lock(&server->mu_call); kill_pending_work_locked( - &exec_ctx, server, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); + server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); gpr_mu_unlock(&server->mu_call); - maybe_finish_shutdown(&exec_ctx, server); + maybe_finish_shutdown(server); gpr_mu_unlock(&server->mu_global); /* Shutdown listeners */ for (l = server->listeners; l; l = l->next) { GRPC_CLOSURE_INIT(&l->destroy_done, listener_destroy_done, server, grpc_schedule_on_exec_ctx); - l->destroy(&exec_ctx, server, l->arg, &l->destroy_done); + l->destroy(server, l->arg, &l->destroy_done); } - channel_broadcaster_shutdown(&exec_ctx, &broadcaster, true /* send_goaway */, + channel_broadcaster_shutdown(&broadcaster, true /* send_goaway */, GRPC_ERROR_NONE); - -done: - grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_cancel_all_calls(grpc_server* server) { channel_broadcaster broadcaster; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server)); @@ -1277,14 +1229,13 @@ void grpc_server_cancel_all_calls(grpc_server* server) { gpr_mu_unlock(&server->mu_global); channel_broadcaster_shutdown( - &exec_ctx, &broadcaster, false /* send_goaway */, + &broadcaster, false /* send_goaway */, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls")); - grpc_exec_ctx_finish(&exec_ctx); } void grpc_server_destroy(grpc_server* server) { listener* l; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server)); @@ -1300,16 +1251,15 @@ void grpc_server_destroy(grpc_server* server) { gpr_mu_unlock(&server->mu_global); - server_unref(&exec_ctx, server); - grpc_exec_ctx_finish(&exec_ctx); + server_unref(server); } -void grpc_server_add_listener( - grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_pollset** pollsets, size_t pollset_count), - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_closure* on_done)) { +void grpc_server_add_listener(grpc_server* server, void* arg, + void (*start)(grpc_server* server, void* arg, + grpc_pollset** pollsets, + size_t pollset_count), + void (*destroy)(grpc_server* server, void* arg, + grpc_closure* on_done)) { listener* l = (listener*)gpr_malloc(sizeof(listener)); l->arg = arg; l->start = start; @@ -1318,13 +1268,12 @@ void grpc_server_add_listener( server->listeners = l; } -static grpc_call_error queue_call_request(grpc_exec_ctx* exec_ctx, - grpc_server* server, size_t cq_idx, +static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx, requested_call* rc) { call_data* calld = nullptr; request_matcher* rm = nullptr; if (gpr_atm_acq_load(&server->shutdown_flag)) { - fail_call(exec_ctx, server, cq_idx, rc, + fail_call(server, cq_idx, rc, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); return GRPC_CALL_OK; } @@ -1351,10 +1300,9 @@ static grpc_call_error queue_call_request(grpc_exec_ctx* exec_ctx, &calld->kill_zombie_closure, kill_zombie, grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0), grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(exec_ctx, &calld->kill_zombie_closure, - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&calld->kill_zombie_closure, GRPC_ERROR_NONE); } else { - publish_call(exec_ctx, server, calld, cq_idx, rc); + publish_call(server, calld, cq_idx, rc); } gpr_mu_lock(&server->mu_call); } @@ -1369,9 +1317,9 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); - GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); + GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( "grpc_server_request_call(" "server=%p, call=%p, details=%p, initial_metadata=%p, " @@ -1404,9 +1352,9 @@ grpc_call_error grpc_server_request_call( rc->call = call; rc->data.batch.details = details; rc->initial_metadata = initial_metadata; - error = queue_call_request(&exec_ctx, server, cq_idx, rc); + error = queue_call_request(server, cq_idx, rc); done: - grpc_exec_ctx_finish(&exec_ctx); + return error; } @@ -1416,10 +1364,10 @@ grpc_call_error grpc_server_request_registered_call( grpc_completion_queue* cq_bound_to_call, grpc_completion_queue* cq_for_notification, void* tag) { grpc_call_error error; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; requested_call* rc = (requested_call*)gpr_malloc(sizeof(*rc)); registered_method* rm = (registered_method*)rmp; - GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); + GRPC_STATS_INC_SERVER_REQUESTED_CALLS(); GRPC_API_TRACE( "grpc_server_request_registered_call(" "server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, " @@ -1461,20 +1409,20 @@ grpc_call_error grpc_server_request_registered_call( rc->data.registered.deadline = deadline; rc->initial_metadata = initial_metadata; rc->data.registered.optional_payload = optional_payload; - error = queue_call_request(&exec_ctx, server, cq_idx, rc); + error = queue_call_request(server, cq_idx, rc); done: - grpc_exec_ctx_finish(&exec_ctx); + return error; } -static void fail_call(grpc_exec_ctx* exec_ctx, grpc_server* server, - size_t cq_idx, requested_call* rc, grpc_error* error) { +static void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc, + grpc_error* error) { *rc->call = nullptr; rc->initial_metadata->count = 0; GPR_ASSERT(error != GRPC_ERROR_NONE); - grpc_cq_end_op(exec_ctx, server->cqs[cq_idx], rc->tag, error, - done_request_event, rc, &rc->completion); + grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc, + &rc->completion); } const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) { diff --git a/src/core/lib/surface/server.h b/src/core/lib/surface/server.h index d7ec025d95..63b6dff16b 100644 --- a/src/core/lib/surface/server.h +++ b/src/core/lib/surface/server.h @@ -31,17 +31,16 @@ extern grpc_core::TraceFlag grpc_server_channel_trace; /* Add a listener to the server: when the server starts, it will call start, and when it shuts down, it will call destroy */ -void grpc_server_add_listener( - grpc_exec_ctx* exec_ctx, grpc_server* server, void* listener, - void (*start)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_pollset** pollsets, size_t npollsets), - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_server* server, void* arg, - grpc_closure* on_done)); +void grpc_server_add_listener(grpc_server* server, void* listener, + void (*start)(grpc_server* server, void* arg, + grpc_pollset** pollsets, + size_t npollsets), + void (*destroy)(grpc_server* server, void* arg, + grpc_closure* on_done)); /* Setup a transport - creates a channel stack, binds the transport to the server */ -void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* server, - grpc_transport* transport, +void grpc_server_setup_transport(grpc_server* server, grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args); diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index bb0e583045..5fcc62ec43 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -37,7 +37,7 @@ BdpEstimator::BdpEstimator(const char* name) bw_est_(0), name_(name) {} -grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx* exec_ctx) { +grpc_millis BdpEstimator::CompletePing() { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_); double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec; @@ -78,7 +78,7 @@ grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx* exec_ctx) { } ping_state_ = PingState::UNSCHEDULED; accumulator_ = 0; - return grpc_exec_ctx_now(exec_ctx) + inter_ping_delay_; + return grpc_core::ExecCtx::Get()->Now() + inter_ping_delay_; } } // namespace grpc_core diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index df3a86c5f1..e703af121c 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -73,7 +73,7 @@ class BdpEstimator { } // Completes a previously started ping, returns when to schedule the next one - grpc_millis CompletePing(grpc_exec_ctx* exec_ctx); + grpc_millis CompletePing(); private: enum class PingState { UNSCHEDULED, SCHEDULED, STARTED }; diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc index b8720250e7..8dcb1e0bdb 100644 --- a/src/core/lib/transport/byte_stream.cc +++ b/src/core/lib/transport/byte_stream.cc @@ -25,34 +25,28 @@ #include "src/core/lib/slice/slice_internal.h" -bool grpc_byte_stream_next(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, size_t max_size_hint, +bool grpc_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - return byte_stream->vtable->next(exec_ctx, byte_stream, max_size_hint, - on_complete); + return byte_stream->vtable->next(byte_stream, max_size_hint, on_complete); } -grpc_error* grpc_byte_stream_pull(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +grpc_error* grpc_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - return byte_stream->vtable->pull(exec_ctx, byte_stream, slice); + return byte_stream->vtable->pull(byte_stream, slice); } -void grpc_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +void grpc_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { - byte_stream->vtable->shutdown(exec_ctx, byte_stream, error); + byte_stream->vtable->shutdown(byte_stream, error); } -void grpc_byte_stream_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream) { - byte_stream->vtable->destroy(exec_ctx, byte_stream); +void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream) { + byte_stream->vtable->destroy(byte_stream); } // grpc_slice_buffer_stream -static bool slice_buffer_stream_next(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static bool slice_buffer_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; @@ -60,8 +54,7 @@ static bool slice_buffer_stream_next(grpc_exec_ctx* exec_ctx, return true; } -static grpc_error* slice_buffer_stream_pull(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static grpc_error* slice_buffer_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) { @@ -74,18 +67,16 @@ static grpc_error* slice_buffer_stream_pull(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static void slice_buffer_stream_shutdown(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static void slice_buffer_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = error; } -static void slice_buffer_stream_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream) { +static void slice_buffer_stream_destroy(grpc_byte_stream* byte_stream) { grpc_slice_buffer_stream* stream = (grpc_slice_buffer_stream*)byte_stream; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, stream->backing_buffer); + grpc_slice_buffer_reset_and_unref_internal(stream->backing_buffer); GRPC_ERROR_UNREF(stream->shutdown_error); } @@ -113,25 +104,22 @@ void grpc_byte_stream_cache_init(grpc_byte_stream_cache* cache, grpc_slice_buffer_init(&cache->cache_buffer); } -void grpc_byte_stream_cache_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream_cache* cache) { - grpc_byte_stream_destroy(exec_ctx, cache->underlying_stream); - grpc_slice_buffer_destroy_internal(exec_ctx, &cache->cache_buffer); +void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache) { + grpc_byte_stream_destroy(cache->underlying_stream); + grpc_slice_buffer_destroy_internal(&cache->cache_buffer); } -static bool caching_byte_stream_next(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static bool caching_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) return true; if (stream->cursor < stream->cache->cache_buffer.count) return true; - return grpc_byte_stream_next(exec_ctx, stream->cache->underlying_stream, - max_size_hint, on_complete); + return grpc_byte_stream_next(stream->cache->underlying_stream, max_size_hint, + on_complete); } -static grpc_error* caching_byte_stream_pull(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static grpc_error* caching_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; if (stream->shutdown_error != GRPC_ERROR_NONE) { @@ -144,7 +132,7 @@ static grpc_error* caching_byte_stream_pull(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } grpc_error* error = - grpc_byte_stream_pull(exec_ctx, stream->cache->underlying_stream, slice); + grpc_byte_stream_pull(stream->cache->underlying_stream, slice); if (error == GRPC_ERROR_NONE) { ++stream->cursor; grpc_slice_buffer_add(&stream->cache->cache_buffer, @@ -153,17 +141,15 @@ static grpc_error* caching_byte_stream_pull(grpc_exec_ctx* exec_ctx, return error; } -static void caching_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +static void caching_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); stream->shutdown_error = GRPC_ERROR_REF(error); - grpc_byte_stream_shutdown(exec_ctx, stream->cache->underlying_stream, error); + grpc_byte_stream_shutdown(stream->cache->underlying_stream, error); } -static void caching_byte_stream_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream) { +static void caching_byte_stream_destroy(grpc_byte_stream* byte_stream) { grpc_caching_byte_stream* stream = (grpc_caching_byte_stream*)byte_stream; GRPC_ERROR_UNREF(stream->shutdown_error); } diff --git a/src/core/lib/transport/byte_stream.h b/src/core/lib/transport/byte_stream.h index 6bca154cb5..52c7a07f56 100644 --- a/src/core/lib/transport/byte_stream.h +++ b/src/core/lib/transport/byte_stream.h @@ -31,13 +31,11 @@ typedef struct grpc_byte_stream grpc_byte_stream; typedef struct { - bool (*next)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, - size_t max_size_hint, grpc_closure* on_complete); - grpc_error* (*pull)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, - grpc_slice* slice); - void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream, - grpc_error* error); - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_byte_stream* byte_stream); + bool (*next)(grpc_byte_stream* byte_stream, size_t max_size_hint, + grpc_closure* on_complete); + grpc_error* (*pull)(grpc_byte_stream* byte_stream, grpc_slice* slice); + void (*shutdown)(grpc_byte_stream* byte_stream, grpc_error* error); + void (*destroy)(grpc_byte_stream* byte_stream); } grpc_byte_stream_vtable; struct grpc_byte_stream { @@ -52,8 +50,7 @@ struct grpc_byte_stream { // // max_size_hint can be set as a hint as to the maximum number // of bytes that would be acceptable to read. -bool grpc_byte_stream_next(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, size_t max_size_hint, +bool grpc_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete); // Returns the next slice in the byte stream when it is ready (indicated by @@ -61,8 +58,7 @@ bool grpc_byte_stream_next(grpc_exec_ctx* exec_ctx, // grpc_byte_stream_next is called). // // Once a slice is returned into *slice, it is owned by the caller. -grpc_error* grpc_byte_stream_pull(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +grpc_error* grpc_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice); // Shuts down the byte stream. @@ -72,12 +68,10 @@ grpc_error* grpc_byte_stream_pull(grpc_exec_ctx* exec_ctx, // // The next call to grpc_byte_stream_pull() (if any) will return the error // passed to grpc_byte_stream_shutdown(). -void grpc_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream, +void grpc_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error); -void grpc_byte_stream_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream* byte_stream); +void grpc_byte_stream_destroy(grpc_byte_stream* byte_stream); // grpc_slice_buffer_stream // @@ -119,8 +113,7 @@ void grpc_byte_stream_cache_init(grpc_byte_stream_cache* cache, grpc_byte_stream* underlying_stream); // Must not be called while still in use by a grpc_caching_byte_stream. -void grpc_byte_stream_cache_destroy(grpc_exec_ctx* exec_ctx, - grpc_byte_stream_cache* cache); +void grpc_byte_stream_cache_destroy(grpc_byte_stream_cache* cache); typedef struct { grpc_byte_stream base; diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index e7e5dbd1f1..c42cc9c8d0 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -51,8 +51,7 @@ void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, tracker->name = gpr_strdup(name); } -void grpc_connectivity_state_destroy(grpc_exec_ctx* exec_ctx, - grpc_connectivity_state_tracker* tracker) { +void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { grpc_error* error; grpc_connectivity_state_watcher* w; while ((w = tracker->watchers)) { @@ -65,7 +64,7 @@ void grpc_connectivity_state_destroy(grpc_exec_ctx* exec_ctx, error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutdown connectivity owner"); } - GRPC_CLOSURE_SCHED(exec_ctx, w->notify, error); + GRPC_CLOSURE_SCHED(w->notify, error); gpr_free(w); } GRPC_ERROR_UNREF(tracker->current_error); @@ -105,8 +104,8 @@ bool grpc_connectivity_state_has_watchers( } bool grpc_connectivity_state_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state* current, grpc_closure* notify) { + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, + grpc_closure* notify) { grpc_connectivity_state cur = (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); @@ -123,7 +122,7 @@ bool grpc_connectivity_state_notify_on_state_change( if (current == nullptr) { grpc_connectivity_state_watcher* w = tracker->watchers; if (w != nullptr && w->notify == notify) { - GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); tracker->watchers = w->next; gpr_free(w); return false; @@ -131,7 +130,7 @@ bool grpc_connectivity_state_notify_on_state_change( while (w != nullptr) { grpc_connectivity_state_watcher* rm_candidate = w->next; if (rm_candidate != nullptr && rm_candidate->notify == notify) { - GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); w->next = w->next->next; gpr_free(rm_candidate); return false; @@ -142,8 +141,7 @@ bool grpc_connectivity_state_notify_on_state_change( } else { if (cur != *current) { *current = cur; - GRPC_CLOSURE_SCHED(exec_ctx, notify, - GRPC_ERROR_REF(tracker->current_error)); + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_REF(tracker->current_error)); } else { grpc_connectivity_state_watcher* w = (grpc_connectivity_state_watcher*)gpr_malloc(sizeof(*w)); @@ -156,8 +154,7 @@ bool grpc_connectivity_state_notify_on_state_change( } } -void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, - grpc_connectivity_state_tracker* tracker, +void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* error, const char* reason) { grpc_connectivity_state cur = @@ -195,8 +192,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "NOTIFY: %p %s: %p", tracker, tracker->name, w->notify); } - GRPC_CLOSURE_SCHED(exec_ctx, w->notify, - GRPC_ERROR_REF(tracker->current_error)); + GRPC_CLOSURE_SCHED(w->notify, GRPC_ERROR_REF(tracker->current_error)); gpr_free(w); } } diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 653637ebea..c3a50f3211 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -51,13 +51,11 @@ const char* grpc_connectivity_state_name(grpc_connectivity_state state); void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state init_state, const char* name); -void grpc_connectivity_state_destroy(grpc_exec_ctx* exec_ctx, - grpc_connectivity_state_tracker* tracker); +void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker); /** Set connectivity state; not thread safe; access must be serialized with an * external lock */ -void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, - grpc_connectivity_state_tracker* tracker, +void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, grpc_connectivity_state state, grpc_error* associated_error, const char* reason); @@ -81,7 +79,7 @@ grpc_connectivity_state grpc_connectivity_state_get( case). Access must be serialized with an external lock. */ bool grpc_connectivity_state_notify_on_state_change( - grpc_exec_ctx* exec_ctx, grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state* current, grpc_closure* notify); + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, + grpc_closure* notify); #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */ diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index 69c8ae6de3..ffaf327081 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -40,9 +40,9 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, return nullptr; } -void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, - grpc_millis deadline, grpc_status_code* code, - grpc_slice* slice, grpc_http2_error_code* http_error, +void grpc_error_get_status(grpc_error* error, grpc_millis deadline, + grpc_status_code* code, grpc_slice* slice, + grpc_http2_error_code* http_error, const char** error_string) { // Start with the parent error and recurse through the tree of children // until we find the first one that has a status code. @@ -65,8 +65,8 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, status = (grpc_status_code)integer; } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - status = grpc_http2_error_to_grpc_status( - exec_ctx, (grpc_http2_error_code)integer, deadline); + status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer, + deadline); } if (code != nullptr) *code = status; diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h index 8b006ae992..4100f65d6d 100644 --- a/src/core/lib/transport/error_utils.h +++ b/src/core/lib/transport/error_utils.h @@ -30,9 +30,8 @@ /// be populated with the entire error string. If any of the attributes (code, /// msg, http_status, error_string) are unneeded, they can be passed as /// NULL. -void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, - grpc_millis deadline, grpc_status_code* code, - grpc_slice* slice, +void grpc_error_get_status(grpc_error* error, grpc_millis deadline, + grpc_status_code* code, grpc_slice* slice, grpc_http2_error_code* http_status, const char** error_string); diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 0f30c7533d..5f0673e014 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -108,7 +108,7 @@ typedef struct mdtab_shard { static mdtab_shard g_shards[SHARD_COUNT]; -static void gc_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard); +static void gc_mdtab(mdtab_shard* shard); void grpc_mdctx_global_init(void) { /* initialize shards */ @@ -123,11 +123,11 @@ void grpc_mdctx_global_init(void) { } } -void grpc_mdctx_global_shutdown(grpc_exec_ctx* exec_ctx) { +void grpc_mdctx_global_shutdown() { for (size_t i = 0; i < SHARD_COUNT; i++) { mdtab_shard* shard = &g_shards[i]; gpr_mu_destroy(&shard->mu); - gc_mdtab(exec_ctx, shard); + gc_mdtab(shard); /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ if (shard->count != 0) { gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata elements were leaked", @@ -165,7 +165,7 @@ static void ref_md_locked(mdtab_shard* shard, } } -static void gc_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard) { +static void gc_mdtab(mdtab_shard* shard) { size_t i; interned_metadata** prev_next; interned_metadata *md, *next; @@ -178,8 +178,8 @@ static void gc_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard) { void* user_data = (void*)gpr_atm_no_barrier_load(&md->user_data); next = md->bucket_next; if (gpr_atm_acq_load(&md->refcnt) == 0) { - grpc_slice_unref_internal(exec_ctx, md->key); - grpc_slice_unref_internal(exec_ctx, md->value); + grpc_slice_unref_internal(md->key); + grpc_slice_unref_internal(md->value); if (md->user_data) { ((destroy_user_data_func)gpr_atm_no_barrier_load( &md->destroy_user_data))(user_data); @@ -228,17 +228,17 @@ static void grow_mdtab(mdtab_shard* shard) { GPR_TIMER_END("grow_mdtab", 0); } -static void rehash_mdtab(grpc_exec_ctx* exec_ctx, mdtab_shard* shard) { +static void rehash_mdtab(mdtab_shard* shard) { if (gpr_atm_no_barrier_load(&shard->free_estimate) > (gpr_atm)(shard->capacity / 4)) { - gc_mdtab(exec_ctx, shard); + gc_mdtab(shard); } else { grow_mdtab(shard); } } grpc_mdelem grpc_mdelem_create( - grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value, + grpc_slice key, grpc_slice value, grpc_mdelem_data* compatible_external_backing_store) { if (!grpc_slice_is_interned(key) || !grpc_slice_is_interned(value)) { if (compatible_external_backing_store != nullptr) { @@ -318,7 +318,7 @@ grpc_mdelem grpc_mdelem_create( shard->count++; if (shard->count > shard->capacity * 2) { - rehash_mdtab(exec_ctx, shard); + rehash_mdtab(shard); } gpr_mu_unlock(&shard->mu); @@ -328,22 +328,20 @@ grpc_mdelem grpc_mdelem_create( return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); } -grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx* exec_ctx, grpc_slice key, - grpc_slice value) { - grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, nullptr); - grpc_slice_unref_internal(exec_ctx, key); - grpc_slice_unref_internal(exec_ctx, value); +grpc_mdelem grpc_mdelem_from_slices(grpc_slice key, grpc_slice value) { + grpc_mdelem out = grpc_mdelem_create(key, value, nullptr); + grpc_slice_unref_internal(key); + grpc_slice_unref_internal(value); return out; } -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx* exec_ctx, - grpc_metadata* metadata) { +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata) { bool changed = false; grpc_slice key_slice = grpc_slice_maybe_static_intern(metadata->key, &changed); grpc_slice value_slice = grpc_slice_maybe_static_intern(metadata->value, &changed); - return grpc_mdelem_create(exec_ctx, key_slice, value_slice, + return grpc_mdelem_create(key_slice, value_slice, changed ? nullptr : (grpc_mdelem_data*)metadata); } @@ -417,7 +415,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { return gmd; } -void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { +void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) { switch (GRPC_MDELEM_STORAGE(gmd)) { case GRPC_MDELEM_STORAGE_EXTERNAL: case GRPC_MDELEM_STORAGE_STATIC: @@ -465,8 +463,8 @@ void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); GPR_ASSERT(prev_refcount >= 1); if (1 == prev_refcount) { - grpc_slice_unref_internal(exec_ctx, md->key); - grpc_slice_unref_internal(exec_ctx, md->value); + grpc_slice_unref_internal(md->key); + grpc_slice_unref_internal(md->value); gpr_free(md); } break; diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 8d4868d031..78e6beff9b 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -107,20 +107,18 @@ struct grpc_mdelem { (uintptr_t)GRPC_MDELEM_STORAGE_INTERNED_BIT)) /* Unrefs the slices. */ -grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx* exec_ctx, grpc_slice key, - grpc_slice value); +grpc_mdelem grpc_mdelem_from_slices(grpc_slice key, grpc_slice value); /* Cheaply convert a grpc_metadata to a grpc_mdelem; may use the grpc_metadata object as backing storage (so lifetimes should align) */ -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx* exec_ctx, - grpc_metadata* metadata); +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_metadata* metadata); /* Does not unref the slices; if a new non-interned mdelem is needed, allocates one if compatible_external_backing_store is NULL, or uses compatible_external_backing_store if it is non-NULL (in which case it's the users responsibility to ensure that it outlives usage) */ grpc_mdelem grpc_mdelem_create( - grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value, + grpc_slice key, grpc_slice value, grpc_mdelem_data* compatible_external_backing_store); bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b); @@ -136,16 +134,14 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), #ifndef NDEBUG #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) -#define GRPC_MDELEM_UNREF(exec_ctx, s) \ - grpc_mdelem_unref((exec_ctx), (s), __FILE__, __LINE__) +#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s), __FILE__, __LINE__) grpc_mdelem grpc_mdelem_ref(grpc_mdelem md, const char* file, int line); -void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem md, - const char* file, int line); +void grpc_mdelem_unref(grpc_mdelem md, const char* file, int line); #else #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s)) -#define GRPC_MDELEM_UNREF(exec_ctx, s) grpc_mdelem_unref((exec_ctx), (s)) +#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s)) grpc_mdelem grpc_mdelem_ref(grpc_mdelem md); -void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem md); +void grpc_mdelem_unref(grpc_mdelem md); #endif #define GRPC_MDKEY(md) (GRPC_MDELEM_DATA(md)->key) @@ -162,6 +158,6 @@ void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem md); #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) void grpc_mdctx_global_init(void); -void grpc_mdctx_global_shutdown(grpc_exec_ctx* exec_ctx); +void grpc_mdctx_global_shutdown(); #endif /* GRPC_CORE_LIB_TRANSPORT_METADATA_H */ diff --git a/src/core/lib/transport/metadata_batch.cc b/src/core/lib/transport/metadata_batch.cc index 5817765aa3..9c95339ba0 100644 --- a/src/core/lib/transport/metadata_batch.cc +++ b/src/core/lib/transport/metadata_batch.cc @@ -51,8 +51,7 @@ static void assert_valid_list(grpc_mdelem_list* list) { #endif /* NDEBUG */ } -static void assert_valid_callouts(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch) { +static void assert_valid_callouts(grpc_metadata_batch* batch) { #ifndef NDEBUG for (grpc_linked_mdelem* l = batch->list.head; l != nullptr; l = l->next) { grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); @@ -61,7 +60,7 @@ static void assert_valid_callouts(grpc_exec_ctx* exec_ctx, if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { GPR_ASSERT(batch->idx.array[callout_idx] == l); } - grpc_slice_unref_internal(exec_ctx, key_interned); + grpc_slice_unref_internal(key_interned); } #endif } @@ -77,11 +76,10 @@ void grpc_metadata_batch_init(grpc_metadata_batch* batch) { batch->deadline = GRPC_MILLIS_INF_FUTURE; } -void grpc_metadata_batch_destroy(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch) { +void grpc_metadata_batch_destroy(grpc_metadata_batch* batch) { grpc_linked_mdelem* l; for (l = batch->list.head; l; l = l->next) { - GRPC_MDELEM_UNREF(exec_ctx, l->md); + GRPC_MDELEM_UNREF(l->md); } } @@ -126,13 +124,12 @@ static void maybe_unlink_callout(grpc_metadata_batch* batch, batch->idx.array[idx] = nullptr; } -grpc_error* grpc_metadata_batch_add_head(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_add_head(grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_head(exec_ctx, batch, storage); + return grpc_metadata_batch_link_head(batch, storage); } static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { @@ -150,27 +147,25 @@ static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); } -grpc_error* grpc_metadata_batch_link_head(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_link_head(grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); grpc_error* err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); return err; } link_head(&batch->list, storage); - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); return GRPC_ERROR_NONE; } -grpc_error* grpc_metadata_batch_add_tail(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_add_tail(grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_tail(exec_ctx, batch, storage); + return grpc_metadata_batch_link_tail(batch, storage); } static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { @@ -189,17 +184,16 @@ static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); } -grpc_error* grpc_metadata_batch_link_tail(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); grpc_error* err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); return err; } link_tail(&batch->list, storage); - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); return GRPC_ERROR_NONE; } @@ -220,31 +214,28 @@ static void unlink_storage(grpc_mdelem_list* list, assert_valid_list(list); } -void grpc_metadata_batch_remove(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +void grpc_metadata_batch_remove(grpc_metadata_batch* batch, grpc_linked_mdelem* storage) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); maybe_unlink_callout(batch, storage); unlink_storage(&batch->list, storage); - GRPC_MDELEM_UNREF(exec_ctx, storage->md); - assert_valid_callouts(exec_ctx, batch); + GRPC_MDELEM_UNREF(storage->md); + assert_valid_callouts(batch); } -void grpc_metadata_batch_set_value(grpc_exec_ctx* exec_ctx, - grpc_linked_mdelem* storage, +void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage, grpc_slice value) { grpc_mdelem old_mdelem = storage->md; grpc_mdelem new_mdelem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(old_mdelem)), value); + grpc_slice_ref_internal(GRPC_MDKEY(old_mdelem)), value); storage->md = new_mdelem; - GRPC_MDELEM_UNREF(exec_ctx, old_mdelem); + GRPC_MDELEM_UNREF(old_mdelem); } -grpc_error* grpc_metadata_batch_substitute(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem new_mdelem) { - assert_valid_callouts(exec_ctx, batch); + assert_valid_callouts(batch); grpc_error* error = GRPC_ERROR_NONE; grpc_mdelem old_mdelem = storage->md; if (!grpc_slice_eq(GRPC_MDKEY(new_mdelem), GRPC_MDKEY(old_mdelem))) { @@ -253,19 +244,18 @@ grpc_error* grpc_metadata_batch_substitute(grpc_exec_ctx* exec_ctx, error = maybe_link_callout(batch, storage); if (error != GRPC_ERROR_NONE) { unlink_storage(&batch->list, storage); - GRPC_MDELEM_UNREF(exec_ctx, storage->md); + GRPC_MDELEM_UNREF(storage->md); } } else { storage->md = new_mdelem; } - GRPC_MDELEM_UNREF(exec_ctx, old_mdelem); - assert_valid_callouts(exec_ctx, batch); + GRPC_MDELEM_UNREF(old_mdelem); + assert_valid_callouts(batch); return error; } -void grpc_metadata_batch_clear(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch) { - grpc_metadata_batch_destroy(exec_ctx, batch); +void grpc_metadata_batch_clear(grpc_metadata_batch* batch) { + grpc_metadata_batch_destroy(batch); grpc_metadata_batch_init(batch); } @@ -292,8 +282,7 @@ static void add_error(grpc_error** composite, grpc_error* error, *composite = grpc_error_add_child(*composite, error); } -grpc_error* grpc_metadata_batch_filter(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_filter(grpc_metadata_batch* batch, grpc_metadata_batch_filter_func func, void* user_data, const char* composite_error_string) { @@ -301,12 +290,12 @@ grpc_error* grpc_metadata_batch_filter(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; while (l) { grpc_linked_mdelem* next = l->next; - grpc_filtered_mdelem new_mdelem = func(exec_ctx, user_data, l->md); + grpc_filtered_mdelem new_mdelem = func(user_data, l->md); add_error(&error, new_mdelem.error, composite_error_string); if (GRPC_MDISNULL(new_mdelem.md)) { - grpc_metadata_batch_remove(exec_ctx, batch, l); + grpc_metadata_batch_remove(batch, l); } else if (new_mdelem.md.payload != l->md.payload) { - grpc_metadata_batch_substitute(exec_ctx, batch, l, new_mdelem.md); + grpc_metadata_batch_substitute(batch, l, new_mdelem.md); } l = next; } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index adfb2d8069..8353a426f8 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -53,28 +53,23 @@ typedef struct grpc_metadata_batch { } grpc_metadata_batch; void grpc_metadata_batch_init(grpc_metadata_batch* batch); -void grpc_metadata_batch_destroy(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch); -void grpc_metadata_batch_clear(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch); +void grpc_metadata_batch_destroy(grpc_metadata_batch* batch); +void grpc_metadata_batch_clear(grpc_metadata_batch* batch); bool grpc_metadata_batch_is_empty(grpc_metadata_batch* batch); /* Returns the transport size of the batch. */ size_t grpc_metadata_batch_size(grpc_metadata_batch* batch); /** Remove \a storage from the batch, unreffing the mdelem contained */ -void grpc_metadata_batch_remove(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +void grpc_metadata_batch_remove(grpc_metadata_batch* batch, grpc_linked_mdelem* storage); /** Substitute a new mdelem for an old value */ -grpc_error* grpc_metadata_batch_substitute(grpc_exec_ctx* exec_ctx, - grpc_metadata_batch* batch, +grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch, grpc_linked_mdelem* storage, grpc_mdelem new_value); -void grpc_metadata_batch_set_value(grpc_exec_ctx* exec_ctx, - grpc_linked_mdelem* storage, +void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage, grpc_slice value); /** Add \a storage to the beginning of \a batch. storage->md is @@ -82,17 +77,17 @@ void grpc_metadata_batch_set_value(grpc_exec_ctx* exec_ctx, \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error* grpc_metadata_batch_link_head( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, - grpc_linked_mdelem* storage) GRPC_MUST_USE_RESULT; +grpc_error* grpc_metadata_batch_link_head(grpc_metadata_batch* batch, + grpc_linked_mdelem* storage) + GRPC_MUST_USE_RESULT; /** Add \a storage to the end of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error* grpc_metadata_batch_link_tail( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, - grpc_linked_mdelem* storage) GRPC_MUST_USE_RESULT; +grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch, + grpc_linked_mdelem* storage) + GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the first element in \a batch, using \a storage as backing storage for the linked list element. @@ -101,8 +96,8 @@ grpc_error* grpc_metadata_batch_link_tail( for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error* grpc_metadata_batch_add_head( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, - grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, + grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the @@ -110,8 +105,8 @@ grpc_error* grpc_metadata_batch_add_head( for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error* grpc_metadata_batch_add_tail( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, - grpc_linked_mdelem* storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_metadata_batch* batch, grpc_linked_mdelem* storage, + grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; grpc_error* grpc_attach_md_to_error(grpc_error* src, grpc_mdelem md); @@ -128,11 +123,10 @@ typedef struct { { GRPC_ERROR_NONE, GRPC_MDNULL } typedef grpc_filtered_mdelem (*grpc_metadata_batch_filter_func)( - grpc_exec_ctx* exec_ctx, void* user_data, grpc_mdelem elem); + void* user_data, grpc_mdelem elem); grpc_error* grpc_metadata_batch_filter( - grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, - grpc_metadata_batch_filter_func func, void* user_data, - const char* composite_error_string) GRPC_MUST_USE_RESULT; + grpc_metadata_batch* batch, grpc_metadata_batch_filter_func func, + void* user_data, const char* composite_error_string) GRPC_MUST_USE_RESULT; #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch* comd); diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc index adcec8c444..cbafc33840 100644 --- a/src/core/lib/transport/service_config.cc +++ b/src/core/lib/transport/service_config.cc @@ -152,10 +152,8 @@ static char* parse_json_method_name(grpc_json* json) { // each name found, incrementing \a idx for each entry added. // Returns false on error. static bool parse_json_method_config( - grpc_exec_ctx* exec_ctx, grpc_json* json, - void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), - void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value), + grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), + void* (*ref_value)(void* value), void (*unref_value)(void* value), grpc_slice_hash_table_entry* entries, size_t* idx) { // Construct value. void* method_config = create_value(json); @@ -184,16 +182,15 @@ static bool parse_json_method_config( } success = true; done: - unref_value(exec_ctx, method_config); + unref_value(method_config); gpr_strvec_destroy(&paths); return success; } grpc_slice_hash_table* grpc_service_config_create_method_config_table( - grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, + const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), - void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value)) { + void* (*ref_value)(void* value), void (*unref_value)(void* value)) { const grpc_json* json = service_config->json_tree; // Traverse parsed JSON tree. if (json->type != GRPC_JSON_OBJECT || json->key != nullptr) return nullptr; @@ -217,11 +214,11 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( size_t idx = 0; for (grpc_json* method = field->child; method != nullptr; method = method->next) { - if (!parse_json_method_config(exec_ctx, method, create_value, ref_value, + if (!parse_json_method_config(method, create_value, ref_value, unref_value, entries, &idx)) { for (size_t i = 0; i < idx; ++i) { - grpc_slice_unref_internal(exec_ctx, entries[i].key); - unref_value(exec_ctx, entries[i].value); + grpc_slice_unref_internal(entries[i].key); + unref_value(entries[i].value); } gpr_free(entries); return nullptr; @@ -240,8 +237,7 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( return method_config_table; } -void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_slice_hash_table* table, +void* grpc_method_config_table_get(const grpc_slice_hash_table* table, grpc_slice path) { void* value = grpc_slice_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard @@ -257,7 +253,7 @@ void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, grpc_slice wildcard_path = grpc_slice_from_copied_string(buf); gpr_free(buf); value = grpc_slice_hash_table_get(table, wildcard_path); - grpc_slice_unref_internal(exec_ctx, wildcard_path); + grpc_slice_unref_internal(wildcard_path); gpr_free(path_str); } return value; diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h index 75a290bfd8..98554b9f0f 100644 --- a/src/core/lib/transport/service_config.h +++ b/src/core/lib/transport/service_config.h @@ -45,10 +45,9 @@ const char* grpc_service_config_get_lb_policy_name( /// \a ref_value() and \a unref_value() are used to ref and unref values. /// Returns NULL on error. grpc_slice_hash_table* grpc_service_config_create_method_config_table( - grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, + const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - void* (*ref_value)(void* value), - void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value)); + void* (*ref_value)(void* value), void (*unref_value)(void* value)); /// A helper function for looking up values in the table returned by /// \a grpc_service_config_create_method_config_table(). @@ -56,8 +55,7 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( /// the form "/service/method". /// Returns NULL if the method has no config. /// Caller does NOT own a reference to the result. -void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_slice_hash_table* table, +void* grpc_method_config_table_get(const grpc_slice_hash_table* table, grpc_slice path); #endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index 844724cbeb..2213b30f56 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -104,7 +104,7 @@ static uint8_t g_bytes[] = { 101, 44, 103, 122, 105, 112}; static void static_ref(void* unused) {} -static void static_unref(grpc_exec_ctx* exec_ctx, void* unused) {} +static void static_unref(void* unused) {} static const grpc_slice_refcount_vtable static_sub_vtable = { static_ref, static_unref, grpc_slice_default_eq_impl, grpc_slice_default_hash_impl}; diff --git a/src/core/lib/transport/status_conversion.cc b/src/core/lib/transport/status_conversion.cc index a0a5f1ba4b..46cba4292b 100644 --- a/src/core/lib/transport/status_conversion.cc +++ b/src/core/lib/transport/status_conversion.cc @@ -37,8 +37,7 @@ grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status) { } } -grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx* exec_ctx, - grpc_http2_error_code error, +grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, grpc_millis deadline) { switch (error) { case GRPC_HTTP2_NO_ERROR: @@ -47,7 +46,7 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx* exec_ctx, case GRPC_HTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ - return grpc_exec_ctx_now(exec_ctx) > deadline + return grpc_core::ExecCtx::Get()->Now() > deadline ? GRPC_STATUS_DEADLINE_EXCEEDED : GRPC_STATUS_CANCELLED; case GRPC_HTTP2_ENHANCE_YOUR_CALM: diff --git a/src/core/lib/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h index 3637b82801..107eb92a53 100644 --- a/src/core/lib/transport/status_conversion.h +++ b/src/core/lib/transport/status_conversion.h @@ -25,8 +25,7 @@ /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status); -grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx* exec_ctx, - grpc_http2_error_code error, +grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, grpc_millis deadline); /* Conversion of HTTP status codes (:status) to grpc status codes */ diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 5bda1541a6..08aee04ac9 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -49,8 +49,7 @@ void grpc_stream_ref(grpc_stream_refcount* refcount) { } #ifndef NDEBUG -void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, - const char* reason) { +void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason) { if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p UNREF %" PRIdPTR "->%" PRIdPTR " %s", @@ -58,11 +57,11 @@ void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, val - 1, reason); } #else -void grpc_stream_unref(grpc_exec_ctx* exec_ctx, - grpc_stream_refcount* refcount) { +void grpc_stream_unref(grpc_stream_refcount* refcount) { #endif if (gpr_unref(&refcount->refs)) { - if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { + if (grpc_core::ExecCtx::Get()->flags() & + GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { /* Ick. The thread we're running on MAY be owned (indirectly) by a call-stack. If that's the case, destroying the call-stack MAY try to destroy the @@ -73,7 +72,7 @@ void grpc_stream_unref(grpc_exec_ctx* exec_ctx, refcount->destroy.scheduler = grpc_executor_scheduler(GRPC_EXECUTOR_SHORT); } - GRPC_CLOSURE_SCHED(exec_ctx, &refcount->destroy, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&refcount->destroy, GRPC_ERROR_NONE); } } @@ -89,11 +88,11 @@ static void slice_stream_ref(void* p) { #endif } -static void slice_stream_unref(grpc_exec_ctx* exec_ctx, void* p) { +static void slice_stream_unref(void* p) { #ifndef NDEBUG - grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p), "slice"); + grpc_stream_unref(STREAM_REF_FROM_SLICE_REF(p), "slice"); #else - grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p)); + grpc_stream_unref(STREAM_REF_FROM_SLICE_REF(p)); #endif } @@ -151,59 +150,50 @@ size_t grpc_transport_stream_size(grpc_transport* transport) { return transport->vtable->sizeof_stream; } -void grpc_transport_destroy(grpc_exec_ctx* exec_ctx, - grpc_transport* transport) { - transport->vtable->destroy(exec_ctx, transport); +void grpc_transport_destroy(grpc_transport* transport) { + transport->vtable->destroy(transport); } -int grpc_transport_init_stream(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, grpc_stream* stream, +int grpc_transport_init_stream(grpc_transport* transport, grpc_stream* stream, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { - return transport->vtable->init_stream(exec_ctx, transport, stream, refcount, + return transport->vtable->init_stream(transport, stream, refcount, server_data, arena); } -void grpc_transport_perform_stream_op(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_perform_stream_op(grpc_transport* transport, grpc_stream* stream, grpc_transport_stream_op_batch* op) { - transport->vtable->perform_stream_op(exec_ctx, transport, stream, op); + transport->vtable->perform_stream_op(transport, stream, op); } -void grpc_transport_perform_op(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_perform_op(grpc_transport* transport, grpc_transport_op* op) { - transport->vtable->perform_op(exec_ctx, transport, op); + transport->vtable->perform_op(transport, op); } -void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, - grpc_stream* stream, +void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, grpc_polling_entity* pollent) { grpc_pollset* pollset; grpc_pollset_set* pollset_set; if ((pollset = grpc_polling_entity_pollset(pollent)) != nullptr) { - transport->vtable->set_pollset(exec_ctx, transport, stream, pollset); + transport->vtable->set_pollset(transport, stream, pollset); } else if ((pollset_set = grpc_polling_entity_pollset_set(pollent)) != nullptr) { - transport->vtable->set_pollset_set(exec_ctx, transport, stream, - pollset_set); + transport->vtable->set_pollset_set(transport, stream, pollset_set); } else { abort(); } } -void grpc_transport_destroy_stream(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_destroy_stream(grpc_transport* transport, grpc_stream* stream, grpc_closure* then_schedule_closure) { - transport->vtable->destroy_stream(exec_ctx, transport, stream, - then_schedule_closure); + transport->vtable->destroy_stream(transport, stream, then_schedule_closure); } -grpc_endpoint* grpc_transport_get_endpoint(grpc_exec_ctx* exec_ctx, - grpc_transport* transport) { - return transport->vtable->get_endpoint(exec_ctx, transport); +grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport) { + return transport->vtable->get_endpoint(transport); } // This comment should be sung to the tune of @@ -214,25 +204,23 @@ grpc_endpoint* grpc_transport_get_endpoint(grpc_exec_ctx* exec_ctx, // though it lives in lib, it handles transport stream ops sure // it's grpc_transport_stream_op_batch_finish_with_failure void grpc_transport_stream_op_batch_finish_with_failure( - grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* batch, - grpc_error* error, grpc_call_combiner* call_combiner) { + grpc_transport_stream_op_batch* batch, grpc_error* error, + grpc_call_combiner* call_combiner) { if (batch->send_message) { - grpc_byte_stream_destroy(exec_ctx, - batch->payload->send_message.send_message); + grpc_byte_stream_destroy(batch->payload->send_message.send_message); } if (batch->recv_message) { - GRPC_CALL_COMBINER_START(exec_ctx, call_combiner, - batch->payload->recv_message.recv_message_ready, - GRPC_ERROR_REF(error), - "failing recv_message_ready"); + GRPC_CALL_COMBINER_START( + call_combiner, batch->payload->recv_message.recv_message_ready, + GRPC_ERROR_REF(error), "failing recv_message_ready"); } if (batch->recv_initial_metadata) { GRPC_CALL_COMBINER_START( - exec_ctx, call_combiner, + call_combiner, batch->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_REF(error), "failing recv_initial_metadata_ready"); } - GRPC_CLOSURE_SCHED(exec_ctx, batch->on_complete, error); + GRPC_CLOSURE_SCHED(batch->on_complete, error); if (batch->cancel_stream) { GRPC_ERROR_UNREF(batch->payload->cancel_stream.cancel_error); } @@ -244,10 +232,9 @@ typedef struct { grpc_transport_op op; } made_transport_op; -static void destroy_made_transport_op(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_made_transport_op(void* arg, grpc_error* error) { made_transport_op* op = (made_transport_op*)arg; - GRPC_CLOSURE_SCHED(exec_ctx, op->inner_on_complete, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(op->inner_on_complete, GRPC_ERROR_REF(error)); gpr_free(op); } @@ -268,12 +255,11 @@ typedef struct { grpc_transport_stream_op_batch_payload payload; } made_transport_stream_op; -static void destroy_made_transport_stream_op(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_made_transport_stream_op(void* arg, grpc_error* error) { made_transport_stream_op* op = (made_transport_stream_op*)arg; grpc_closure* c = op->inner_on_complete; gpr_free(op); - GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_RUN(c, GRPC_ERROR_REF(error)); } grpc_transport_stream_op_batch* grpc_make_transport_stream_op( diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index b3cf04c22d..b03c0218dc 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -55,15 +55,14 @@ void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, grpc_iomgr_cb_func cb, void* cb_arg, const char* object_type); void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason); -void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, - const char* reason); +void grpc_stream_unref(grpc_stream_refcount* refcount, const char* reason); #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ grpc_stream_ref_init(rc, ir, cb, cb_arg, objtype) #else void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, grpc_iomgr_cb_func cb, void* cb_arg); void grpc_stream_ref(grpc_stream_refcount* refcount); -void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount); +void grpc_stream_unref(grpc_stream_refcount* refcount); #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ grpc_stream_ref_init(rc, ir, cb, cb_arg) #endif @@ -237,8 +236,7 @@ typedef struct grpc_transport_op { If true, the callback is set to set_accept_stream_fn, with its user_data argument set to set_accept_stream_user_data */ bool set_accept_stream; - void (*set_accept_stream_fn)(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_transport* transport, + void (*set_accept_stream_fn)(void* user_data, grpc_transport* transport, const void* server_data); void* set_accept_stream_user_data; /** add this transport to a pollset */ @@ -269,13 +267,12 @@ size_t grpc_transport_stream_size(grpc_transport* transport); stream - a pointer to uninitialized memory to initialize server_data - either NULL for a client initiated stream, or a pointer supplied from the accept_stream callback function */ -int grpc_transport_init_stream(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, grpc_stream* stream, +int grpc_transport_init_stream(grpc_transport* transport, grpc_stream* stream, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena); -void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, - grpc_stream* stream, grpc_polling_entity* pollent); +void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, + grpc_polling_entity* pollent); /* Destroy transport data for a stream. @@ -287,14 +284,13 @@ void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, transport - the transport on which to create this stream stream - the grpc_stream to destroy (memory is still owned by the caller, but any child memory must be cleaned up) */ -void grpc_transport_destroy_stream(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_destroy_stream(grpc_transport* transport, grpc_stream* stream, grpc_closure* then_schedule_closure); void grpc_transport_stream_op_batch_finish_with_failure( - grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* op, - grpc_error* error, grpc_call_combiner* call_combiner); + grpc_transport_stream_op_batch* op, grpc_error* error, + grpc_call_combiner* call_combiner); char* grpc_transport_stream_op_batch_string(grpc_transport_stream_op_batch* op); char* grpc_transport_op_string(grpc_transport_op* op); @@ -309,13 +305,11 @@ char* grpc_transport_op_string(grpc_transport_op* op); non-NULL and previously initialized by the same transport. op - a grpc_transport_stream_op_batch specifying the op to perform */ -void grpc_transport_perform_stream_op(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_perform_stream_op(grpc_transport* transport, grpc_stream* stream, grpc_transport_stream_op_batch* op); -void grpc_transport_perform_op(grpc_exec_ctx* exec_ctx, - grpc_transport* transport, +void grpc_transport_perform_op(grpc_transport* transport, grpc_transport_op* op); /* Send a ping on a transport @@ -328,11 +322,10 @@ void grpc_transport_goaway(grpc_transport* transport, grpc_status_code status, grpc_slice debug_data); /* Destroy the transport */ -void grpc_transport_destroy(grpc_exec_ctx* exec_ctx, grpc_transport* transport); +void grpc_transport_destroy(grpc_transport* transport); /* Get the endpoint used by \a transport */ -grpc_endpoint* grpc_transport_get_endpoint(grpc_exec_ctx* exec_ctx, - grpc_transport* transport); +grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport); /* Allocate a grpc_transport_op, and preconfigure the on_consumed closure to \a on_consumed and then delete the returned transport op */ diff --git a/src/core/lib/transport/transport_impl.h b/src/core/lib/transport/transport_impl.h index 46be61427e..50b8a5f9b7 100644 --- a/src/core/lib/transport/transport_impl.h +++ b/src/core/lib/transport/transport_impl.h @@ -30,37 +30,34 @@ typedef struct grpc_transport_vtable { const char* name; /* implementation of grpc_transport_init_stream */ - int (*init_stream)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_stream_refcount* refcount, - const void* server_data, gpr_arena* arena); + int (*init_stream)(grpc_transport* self, grpc_stream* stream, + grpc_stream_refcount* refcount, const void* server_data, + gpr_arena* arena); /* implementation of grpc_transport_set_pollset */ - void (*set_pollset)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_pollset* pollset); + void (*set_pollset)(grpc_transport* self, grpc_stream* stream, + grpc_pollset* pollset); /* implementation of grpc_transport_set_pollset */ - void (*set_pollset_set)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_pollset_set* pollset_set); + void (*set_pollset_set)(grpc_transport* self, grpc_stream* stream, + grpc_pollset_set* pollset_set); /* implementation of grpc_transport_perform_stream_op */ - void (*perform_stream_op)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, + void (*perform_stream_op)(grpc_transport* self, grpc_stream* stream, grpc_transport_stream_op_batch* op); /* implementation of grpc_transport_perform_op */ - void (*perform_op)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_transport_op* op); + void (*perform_op)(grpc_transport* self, grpc_transport_op* op); /* implementation of grpc_transport_destroy_stream */ - void (*destroy_stream)(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, + void (*destroy_stream)(grpc_transport* self, grpc_stream* stream, grpc_closure* then_schedule_closure); /* implementation of grpc_transport_destroy */ - void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_transport* self); + void (*destroy)(grpc_transport* self); /* implementation of grpc_transport_get_endpoint */ - grpc_endpoint* (*get_endpoint)(grpc_exec_ctx* exec_ctx, grpc_transport* self); + grpc_endpoint* (*get_endpoint)(grpc_transport* self); } grpc_transport_vtable; /* an instance of a grpc transport */ diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index f2f365fc0f..b907636f9d 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -399,8 +399,7 @@ static const tsi_frame_protector_vtable frame_protector_vtable = { /* --- tsi_zero_copy_grpc_protector methods implementation. ---*/ static tsi_result fake_zero_copy_grpc_protector_protect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* unprotected_slices, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { @@ -424,8 +423,7 @@ static tsi_result fake_zero_copy_grpc_protector_protect( } static tsi_result fake_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* protected_slices, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { @@ -454,18 +452,18 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( impl->parsed_frame_size - TSI_FAKE_FRAME_HEADER_SIZE, unprotected_slices); impl->parsed_frame_size = 0; - grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &impl->header_sb); + grpc_slice_buffer_reset_and_unref_internal(&impl->header_sb); } return TSI_OK; } static void fake_zero_copy_grpc_protector_destroy( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self) { + tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; tsi_fake_zero_copy_grpc_protector* impl = (tsi_fake_zero_copy_grpc_protector*)self; - grpc_slice_buffer_destroy_internal(exec_ctx, &impl->header_sb); - grpc_slice_buffer_destroy_internal(exec_ctx, &impl->protected_sb); + grpc_slice_buffer_destroy_internal(&impl->header_sb); + grpc_slice_buffer_destroy_internal(&impl->protected_sb); gpr_free(impl); } @@ -497,8 +495,7 @@ static tsi_result fake_handshaker_result_extract_peer( } static tsi_result fake_handshaker_result_create_zero_copy_grpc_protector( - void* exec_ctx, const tsi_handshaker_result* self, - size_t* max_output_protected_frame_size, + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { *protector = tsi_create_fake_zero_copy_grpc_protector(max_output_protected_frame_size); diff --git a/src/core/tsi/transport_security.h b/src/core/tsi/transport_security.h index bf3a776b11..ed662d48af 100644 --- a/src/core/tsi/transport_security.h +++ b/src/core/tsi/transport_security.h @@ -90,7 +90,7 @@ struct tsi_handshaker { typedef struct { tsi_result (*extract_peer)(const tsi_handshaker_result* self, tsi_peer* peer); tsi_result (*create_zero_copy_grpc_protector)( - void* exec_ctx, const tsi_handshaker_result* self, + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector); tsi_result (*create_frame_protector)(const tsi_handshaker_result* self, diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index 875d367218..76f7ae782f 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -20,18 +20,16 @@ /* This method creates a tsi_zero_copy_grpc_protector object. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, - size_t* max_output_protected_frame_size, + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { - if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || - protector == nullptr) { + if (self == nullptr || self->vtable == nullptr || protector == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->create_zero_copy_grpc_protector == nullptr) { return TSI_UNIMPLEMENTED; } return self->vtable->create_zero_copy_grpc_protector( - exec_ctx, self, max_output_protected_frame_size, protector); + self, max_output_protected_frame_size, protector); } /* --- tsi_zero_copy_grpc_protector common implementation. --- @@ -39,33 +37,28 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( Calls specific implementation after state/input validation. */ tsi_result tsi_zero_copy_grpc_protector_protect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* unprotected_slices, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { - if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + if (self == nullptr || self->vtable == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->protect == nullptr) return TSI_UNIMPLEMENTED; - return self->vtable->protect(exec_ctx, self, unprotected_slices, - protected_slices); + return self->vtable->protect(self, unprotected_slices, protected_slices); } tsi_result tsi_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* protected_slices, + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { - if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + if (self == nullptr || self->vtable == nullptr || protected_slices == nullptr || unprotected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->vtable->unprotect == nullptr) return TSI_UNIMPLEMENTED; - return self->vtable->unprotect(exec_ctx, self, protected_slices, - unprotected_slices); + return self->vtable->unprotect(self, protected_slices, unprotected_slices); } -void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, - tsi_zero_copy_grpc_protector* self) { +void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; - self->vtable->destroy(exec_ctx, self); + self->vtable->destroy(self); } diff --git a/src/core/tsi/transport_security_grpc.h b/src/core/tsi/transport_security_grpc.h index 9fccfd79dd..0156ff1c68 100644 --- a/src/core/tsi/transport_security_grpc.h +++ b/src/core/tsi/transport_security_grpc.h @@ -26,8 +26,7 @@ assuming there is no fatal error. The caller is responsible for destroying the protector. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, - size_t* max_output_protected_frame_size, + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector); /* -- tsi_zero_copy_grpc_protector object -- */ @@ -39,8 +38,8 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - This method returns TSI_OK in case of success or a specific error code in case of failure. */ tsi_result tsi_zero_copy_grpc_protector_protect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices); + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices); /* Outputs unprotected bytes. - protected_slices is the bytes of protected frames. @@ -49,24 +48,21 @@ tsi_result tsi_zero_copy_grpc_protector_protect( there is not enough data to output in which case unprotected_slices has 0 bytes. */ tsi_result tsi_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, - grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices); + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices); /* Destroys the tsi_zero_copy_grpc_protector object. */ -void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, - tsi_zero_copy_grpc_protector* self); +void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self); /* Base for tsi_zero_copy_grpc_protector implementations. */ typedef struct { - tsi_result (*protect)(grpc_exec_ctx* exec_ctx, - tsi_zero_copy_grpc_protector* self, + tsi_result (*protect)(tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices); - tsi_result (*unprotect)(grpc_exec_ctx* exec_ctx, - tsi_zero_copy_grpc_protector* self, + tsi_result (*unprotect)(tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices); - void (*destroy)(grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self); + void (*destroy)(tsi_zero_copy_grpc_protector* self); } tsi_zero_copy_grpc_protector_vtable; struct tsi_zero_copy_grpc_protector { diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index cae9ef953a..b696774243 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -66,13 +66,12 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } ChannelArguments::~ChannelArguments() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == GRPC_ARG_POINTER) { - it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); + it->value.pointer.vtable->destroy(it->value.pointer.p); } } - grpc_exec_ctx_finish(&exec_ctx); } void ChannelArguments::Swap(ChannelArguments& other) { @@ -95,17 +94,17 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { } grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator); bool replaced = false; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { GPR_ASSERT(!replaced); - it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); + it->value.pointer.vtable->destroy(it->value.pointer.p); it->value.pointer = mutator_arg.value.pointer; replaced = true; } } - grpc_exec_ctx_finish(&exec_ctx); + if (!replaced) { args_.push_back(mutator_arg); } diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 274079f8dd..cbe2a209f5 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -27,43 +27,39 @@ namespace grpc { // MetadataBatch -grpc_linked_mdelem* MetadataBatch::AddMetadata(grpc_exec_ctx* exec_ctx, - const string& key, +grpc_linked_mdelem* MetadataBatch::AddMetadata(const string& key, const string& value) { grpc_linked_mdelem* storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); - storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), + storage->md = grpc_mdelem_from_slices(SliceFromCopiedString(key), SliceFromCopiedString(value)); GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(exec_ctx, batch_, storage)); + grpc_metadata_batch_link_head(batch_, storage)); return storage; } // ChannelData -void ChannelData::StartTransportOp(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +void ChannelData::StartTransportOp(grpc_channel_element* elem, TransportOp* op) { - grpc_channel_next_op(exec_ctx, elem, op->op()); + grpc_channel_next_op(elem, op->op()); } -void ChannelData::GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, +void ChannelData::GetInfo(grpc_channel_element* elem, const grpc_channel_info* channel_info) { - grpc_channel_next_get_info(exec_ctx, elem, channel_info); + grpc_channel_next_get_info(elem, channel_info); } // CallData -void CallData::StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +void CallData::StartTransportStreamOpBatch(grpc_call_element* elem, TransportStreamOpBatch* op) { - grpc_call_next_op(exec_ctx, elem, op->op()); + grpc_call_next_op(elem, op->op()); } -void CallData::SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_polling_entity* pollent) { - grpc_call_stack_ignore_set_pollset_or_pollset_set(exec_ctx, elem, pollent); + grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent); } // internal code used by RegisterChannelFilter() @@ -75,8 +71,7 @@ std::vector* channel_filters; namespace { -bool MaybeAddFilter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) { const FilterRecord& filter = *(FilterRecord*)arg; if (filter.include_filter) { const grpc_channel_args* args = diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 9fe9cf0aea..a1f42c0b32 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -54,8 +54,7 @@ class MetadataBatch { /// Adds metadata and returns the newly allocated storage. /// The caller takes ownership of the result, which must exist for the /// lifetime of the gRPC call. - grpc_linked_mdelem* AddMetadata(grpc_exec_ctx* exec_ctx, const string& key, - const string& value); + grpc_linked_mdelem* AddMetadata(const string& key, const string& value); class const_iterator : public std::iterator { @@ -222,18 +221,17 @@ class ChannelData { // TODO(roth): Come up with a more C++-like API for the channel element. /// Initializes the channel data. - virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + virtual grpc_error* Init(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} + virtual void Destroy(grpc_channel_element* elem) {} - virtual void StartTransportOp(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, TransportOp* op); + virtual void StartTransportOp(grpc_channel_element* elem, TransportOp* op); - virtual void GetInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + virtual void GetInfo(grpc_channel_element* elem, const grpc_channel_info* channel_info); }; @@ -246,24 +244,22 @@ class CallData { // TODO(roth): Come up with a more C++-like API for the call element. /// Initializes the call data. - virtual grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + virtual grpc_error* Init(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + virtual void Destroy(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_call_closure) {} /// Starts a new stream operation. - virtual void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + virtual void StartTransportStreamOpBatch(grpc_call_element* elem, TransportStreamOpBatch* op); /// Sets a pollset or pollset set. - virtual void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + virtual void SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_polling_entity* pollent); }; @@ -277,71 +273,63 @@ class ChannelFilter final { public: static const size_t channel_data_size = sizeof(ChannelDataType); - static grpc_error* InitChannelElement(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, + static grpc_error* InitChannelElement(grpc_channel_element* elem, grpc_channel_element_args* args) { // Construct the object in the already-allocated memory. ChannelDataType* channel_data = new (elem->channel_data) ChannelDataType(); - return channel_data->Init(exec_ctx, elem, args); + return channel_data->Init(elem, args); } - static void DestroyChannelElement(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) { + static void DestroyChannelElement(grpc_channel_element* elem) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); - channel_data->Destroy(exec_ctx, elem); + channel_data->Destroy(elem); channel_data->~ChannelDataType(); } - static void StartTransportOp(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, + static void StartTransportOp(grpc_channel_element* elem, grpc_transport_op* op) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); TransportOp op_wrapper(op); - channel_data->StartTransportOp(exec_ctx, elem, &op_wrapper); + channel_data->StartTransportOp(elem, &op_wrapper); } - static void GetChannelInfo(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, + static void GetChannelInfo(grpc_channel_element* elem, const grpc_channel_info* channel_info) { ChannelDataType* channel_data = reinterpret_cast(elem->channel_data); - channel_data->GetInfo(exec_ctx, elem, channel_info); + channel_data->GetInfo(elem, channel_info); } static const size_t call_data_size = sizeof(CallDataType); - static grpc_error* InitCallElement(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + static grpc_error* InitCallElement(grpc_call_element* elem, const grpc_call_element_args* args) { // Construct the object in the already-allocated memory. CallDataType* call_data = new (elem->call_data) CallDataType(); - return call_data->Init(exec_ctx, elem, args); + return call_data->Init(elem, args); } - static void DestroyCallElement(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + static void DestroyCallElement(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_call_closure) { CallDataType* call_data = reinterpret_cast(elem->call_data); - call_data->Destroy(exec_ctx, elem, final_info, then_call_closure); + call_data->Destroy(elem, final_info, then_call_closure); call_data->~CallDataType(); } - static void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + static void StartTransportStreamOpBatch(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { CallDataType* call_data = reinterpret_cast(elem->call_data); TransportStreamOpBatch op_wrapper(op); - call_data->StartTransportStreamOpBatch(exec_ctx, elem, &op_wrapper); + call_data->StartTransportStreamOpBatch(elem, &op_wrapper); } - static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + static void SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_polling_entity* pollent) { CallDataType* call_data = reinterpret_cast(elem->call_data); - call_data->SetPollsetOrPollsetSet(exec_ctx, elem, pollent); + call_data->SetPollsetOrPollsetSet(elem, pollent); } }; diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm index d5e668a858..d130971364 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm @@ -110,13 +110,12 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void cronet_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_exec_ctx ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; stream_engine *cronetEngine = [Cronet getGlobalEngine]; grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args); cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine); - grpc_channel_args_destroy(&ctx, new_client_args); - grpc_exec_ctx_finish(&ctx); + grpc_channel_args_destroy(new_client_args); } static int fail_server_auth_check(grpc_channel_args *server_args) { diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index fae77843f0..6377008a3b 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -558,7 +558,7 @@ extern grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import; typedef void(*grpc_slice_buffer_move_first_no_ref_type)(grpc_slice_buffer* src, size_t n, grpc_slice_buffer* dst); extern grpc_slice_buffer_move_first_no_ref_type grpc_slice_buffer_move_first_no_ref_import; #define grpc_slice_buffer_move_first_no_ref grpc_slice_buffer_move_first_no_ref_import -typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* src, size_t n, void* dst); +typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_slice_buffer* src, size_t n, void* dst); extern grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import; #define grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer_import typedef grpc_slice(*grpc_slice_buffer_take_first_type)(grpc_slice_buffer* src); diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index ef2de8d638..d3115fe1dd 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/backoff/backoff.h" +#include #include #include @@ -32,23 +33,24 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + next_deadlines = grpc_backoff_step(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - exec_ctx.now = next_deadlines.current_deadline; + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(&exec_ctx); } static void test_min_connect(void) { @@ -60,17 +62,16 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next = grpc_backoff_begin(&exec_ctx, &backoff); + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_exec_ctx_now(&exec_ctx) == + GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == initial_backoff); - grpc_exec_ctx_finish(&exec_ctx); } static void test_no_jitter_backoff(void) { @@ -84,49 +85,47 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - exec_ctx.now = 0; - exec_ctx.now_is_valid = true; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + grpc_core::ExecCtx exec_ctx; + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); - grpc_exec_ctx_finish(&exec_ctx); } static void test_jitter_backoff(void) { @@ -142,12 +141,13 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); grpc_millis expected_next_lower_bound = @@ -156,11 +156,11 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 + jitter)); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + next_deadlines = grpc_backoff_step(&backoff); // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx); + next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -169,13 +169,13 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - exec_ctx.now = next_deadlines.current_deadline; + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); gpr_time_init(); test_constant_backoff(); @@ -183,5 +183,6 @@ int main(int argc, char** argv) { test_no_jitter_backoff(); test_jitter_backoff(); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index d8bb092e14..4c1642aa5d 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -50,20 +50,19 @@ static void thd_func(void* arg) { gpr_event_set(&a->done_thd, (void*)1); } -static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void done_write(void* arg, grpc_error* error) { thd_args* a = (thd_args*)arg; gpr_event_set(&a->done_write, (void*)1); } static void server_setup_transport(void* ts, grpc_transport* transport) { thd_args* a = (thd_args*)ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_server_setup_transport(&exec_ctx, a->server, transport, nullptr, + grpc_core::ExecCtx exec_ctx; + grpc_server_setup_transport(a->server, transport, nullptr, grpc_server_get_channel_args(a->server)); - grpc_exec_ctx_finish(&exec_ctx); } -static void read_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void read_done(void* arg, grpc_error* error) { gpr_event* read_done = (gpr_event*)arg; gpr_event_set(read_done, (void*)1); } @@ -81,7 +80,7 @@ void grpc_run_bad_client_test( grpc_slice_from_copied_buffer(client_payload, client_payload_length); grpc_slice_buffer outgoing; grpc_closure done_write_closure; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_completion_queue* shutdown_cq; if (client_payload_length < 4 * 1024) { @@ -115,15 +114,13 @@ void grpc_run_bad_client_test( GRPC_BAD_CLIENT_REGISTERED_HOST, GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); grpc_server_start(a.server); - transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, sfd.server, false); + transport = grpc_create_chttp2_transport(nullptr, sfd.server, false); server_setup_transport(&a, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); /* Bind everything into the same pollset */ - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.client, grpc_cq_pollset(a.cq)); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.server, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq)); /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); @@ -137,8 +134,8 @@ void grpc_run_bad_client_test( grpc_schedule_on_exec_ctx); /* Write data */ - grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure); + grpc_core::ExecCtx::Get()->Flush(); /* Await completion, unless the request is large and write may not finish * before the peer shuts down. */ @@ -149,10 +146,9 @@ void grpc_run_bad_client_test( if (flags & GRPC_BAD_CLIENT_DISCONNECT) { grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); + sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); + grpc_endpoint_destroy(sfd.client); + grpc_core::ExecCtx::Get()->Flush(); sfd.client = nullptr; } @@ -171,9 +167,8 @@ void grpc_run_bad_client_test( grpc_closure read_done_closure; GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, sfd.client, &incoming, - &read_done_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_read(sfd.client, &incoming, &read_done_closure); + grpc_core::ExecCtx::Get()->Flush(); do { GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); GPR_ASSERT( @@ -186,14 +181,13 @@ void grpc_run_bad_client_test( "client validator failed; trying additional read " "in case we didn't get all the data"); } - grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); + grpc_slice_buffer_destroy_internal(&incoming); } // Shutdown. grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); + sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + grpc_endpoint_destroy(sfd.client); + grpc_core::ExecCtx::Get()->Flush(); } GPR_ASSERT( @@ -207,8 +201,7 @@ void grpc_run_bad_client_test( grpc_completion_queue_destroy(shutdown_cq); grpc_server_destroy(a.server); grpc_completion_queue_destroy(a.cq); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); + grpc_slice_buffer_destroy_internal(&outgoing); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } diff --git a/test/core/bad_client/tests/badreq.cc b/test/core/bad_client/tests/badreq.cc index c30244e0cd..eeaf4c9974 100644 --- a/test/core/bad_client/tests/badreq.cc +++ b/test/core/bad_client/tests/badreq.cc @@ -20,6 +20,8 @@ #include +#include + #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -38,6 +40,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* invalid content type */ GRPC_RUN_BAD_CLIENT_TEST( @@ -126,5 +129,6 @@ int main(int argc, char** argv) { "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/connection_prefix.cc b/test/core/bad_client/tests/connection_prefix.cc index 47252f9f10..4aab234d3e 100644 --- a/test/core/bad_client/tests/connection_prefix.cc +++ b/test/core/bad_client/tests/connection_prefix.cc @@ -30,6 +30,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "X", 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PX", 0); @@ -57,5 +58,7 @@ int main(int argc, char** argv) { 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", 0); + + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc index bbc5611991..f56c4d71dd 100644 --- a/test/core/bad_client/tests/head_of_line_blocking.cc +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -20,6 +20,7 @@ #include +#include #include #include "src/core/lib/surface/server.h" @@ -109,6 +110,7 @@ static void addbuf(const void* data, size_t len) { int main(int argc, char** argv) { int i; grpc_test_init(argc, argv); + grpc_init(); #define NUM_FRAMES 10 #define FRAME_SIZE 1000 @@ -131,6 +133,7 @@ int main(int argc, char** argv) { } grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, 0); gpr_free(g_buffer); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/headers.cc b/test/core/bad_client/tests/headers.cc index 50bb72c493..2aa1b280ce 100644 --- a/test/core/bad_client/tests/headers.cc +++ b/test/core/bad_client/tests/headers.cc @@ -34,6 +34,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* partial http2 header prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -335,5 +336,6 @@ int main(int argc, char** argv) { "15 seconds", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/initial_settings_frame.cc b/test/core/bad_client/tests/initial_settings_frame.cc index edc52f503e..0220000ece 100644 --- a/test/core/bad_client/tests/initial_settings_frame.cc +++ b/test/core/bad_client/tests/initial_settings_frame.cc @@ -33,6 +33,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* various partial prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -106,5 +107,6 @@ int main(int argc, char** argv) { PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc index 6613c94b41..c2dc9c66af 100644 --- a/test/core/bad_client/tests/server_registered_method.cc +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -77,6 +77,7 @@ static void verifier_fails(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* body generated with * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ @@ -123,5 +124,6 @@ int main(int argc, char** argv) { "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", 0); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc index 9f4a03e69b..c80fc5cb4a 100644 --- a/test/core/bad_client/tests/simple_request.cc +++ b/test/core/bad_client/tests/simple_request.cc @@ -20,6 +20,8 @@ #include +#include + #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -122,6 +124,7 @@ static void failure_verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* basic request: check that things are working */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR, 0); @@ -164,5 +167,6 @@ int main(int argc, char** argv) { GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, nullptr, PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/unknown_frame.cc b/test/core/bad_client/tests/unknown_frame.cc index d962a4244d..b1b618a43f 100644 --- a/test/core/bad_client/tests/unknown_frame.cc +++ b/test/core/bad_client/tests/unknown_frame.cc @@ -33,6 +33,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, } int main(int argc, char** argv) { + grpc_init(); grpc_test_init(argc, argv); /* test adding prioritization data */ @@ -40,5 +41,6 @@ int main(int argc, char** argv) { PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc index f4bd81828b..ed8279c951 100644 --- a/test/core/bad_client/tests/window_overflow.cc +++ b/test/core/bad_client/tests/window_overflow.cc @@ -20,6 +20,7 @@ #include +#include #include #include "src/core/lib/surface/server.h" @@ -72,6 +73,7 @@ int main(int argc, char** argv) { #define SEND_SIZE (6 * 1024 * 1024) #define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) grpc_test_init(argc, argv); + grpc_init(); addbuf(PFX_STR, sizeof(PFX_STR) - 1); for (i = 0; i < NUM_FRAMES; i++) { @@ -93,6 +95,7 @@ int main(int argc, char** argv) { grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, GRPC_BAD_CLIENT_LARGE_REQUEST); gpr_free(g_buffer); + grpc_shutdown(); return 0; } diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index e8b3334185..4a8195e984 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -26,7 +26,7 @@ #include "test/core/util/test_config.h" static void test_create(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_arg arg_int; grpc_arg arg_string; @@ -55,12 +55,11 @@ static void test_create(void) { GPR_ASSERT(strcmp(ch_args->args[1].value.string, arg_string.value.string) == 0); - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_set_compression_algorithm(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* ch_args; ch_args = @@ -70,12 +69,11 @@ static void test_set_compression_algorithm(void) { GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER); - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_compression_algorithm_states(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; unsigned states_bitset; size_t i; @@ -91,10 +89,10 @@ static void test_compression_algorithm_states(void) { /* disable gzip and deflate */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args, GRPC_COMPRESS_GZIP, 0); + &ch_args, GRPC_COMPRESS_GZIP, 0); GPR_ASSERT(ch_args == ch_args_wo_gzip); ch_args_wo_gzip_deflate = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); + &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -109,7 +107,7 @@ static void test_compression_algorithm_states(void) { /* re-enabled gzip only */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); + &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -122,8 +120,7 @@ static void test_compression_algorithm_states(void) { } } - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_set_socket_mutator(void) { @@ -137,9 +134,8 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ch_args); } } diff --git a/test/core/channel/channel_stack_builder_test.cc b/test/core/channel/channel_stack_builder_test.cc index a67f0efafe..ef6db81b0b 100644 --- a/test/core/channel/channel_stack_builder_test.cc +++ b/test/core/channel/channel_stack_builder_test.cc @@ -29,34 +29,30 @@ #include "src/core/lib/surface/channel_init.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* call_init_func(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_destroy_func(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_func(grpc_call_element* elem, grpc_transport_stream_op_batch* op) {} -static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op) { +static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } bool g_replacement_fn_called = false; @@ -106,8 +102,7 @@ const grpc_channel_filter original_filter = { grpc_channel_next_get_info, "filter_name"}; -static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool add_replacement_filter(grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_filter* filter = static_cast(arg); @@ -118,8 +113,7 @@ static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, builder, filter, set_arg_once_fn, &g_replacement_fn_called); } -static bool add_original_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool add_original_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter*)arg, set_arg_once_fn, diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index 988ea9bac9..ef43facd6e 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -27,8 +27,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->channel_args->num_args == 1); GPR_ASSERT(args->channel_args->args[0].type == GRPC_ARG_INTEGER); @@ -40,42 +39,37 @@ static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* call_init_func(grpc_call_element* elem, const grpc_call_element_args* args) { ++*(int*)(elem->channel_data); *(int*)(elem->call_data) = 0; return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_destroy_func(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { ++*(int*)(elem->channel_data); } -static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_func(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { ++*(int*)(elem->call_data); } -static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op) { +static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { ++*(int*)(elem->channel_data); } -static void free_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - grpc_channel_stack_destroy(exec_ctx, static_cast(arg)); +static void free_channel(void* arg, grpc_error* error) { + grpc_channel_stack_destroy(static_cast(arg)); gpr_free(arg); } -static void free_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - grpc_call_stack_destroy(exec_ctx, static_cast(arg), nullptr, - nullptr); +static void free_call(void* arg, grpc_error* error) { + grpc_call_stack_destroy(static_cast(arg), nullptr, nullptr); gpr_free(arg); } @@ -101,7 +95,7 @@ static void test_create_channel_stack(void) { grpc_channel_args chan_args; int* channel_data; int* call_data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; @@ -113,8 +107,8 @@ static void test_create_channel_stack(void) { channel_stack = static_cast( gpr_malloc(grpc_channel_stack_size(&filters, 1))); - grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, - 1, &chan_args, nullptr, "test", channel_stack); + grpc_channel_stack_init(1, free_channel, channel_stack, &filters, 1, + &chan_args, nullptr, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_data = (int*)channel_elem->channel_data; @@ -132,8 +126,8 @@ static void test_create_channel_stack(void) { nullptr, /* arena */ nullptr /* call_combiner */ }; - grpc_error* error = grpc_call_stack_init(&exec_ctx, channel_stack, 1, - free_call, call_stack, &args); + grpc_error* error = + grpc_call_stack_init(channel_stack, 1, free_call, call_stack, &args); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); @@ -143,14 +137,13 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); - GRPC_CALL_STACK_UNREF(&exec_ctx, call_stack, "done"); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CALL_STACK_UNREF(call_stack, "done"); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(*channel_data == 2); - GRPC_CHANNEL_STACK_UNREF(&exec_ctx, channel_stack, "done"); + GRPC_CHANNEL_STACK_UNREF(channel_stack, "done"); - grpc_slice_unref_internal(&exec_ctx, path); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(path); } int main(int argc, char** argv) { diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index e0cffa39a8..3495f603e4 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -125,12 +125,10 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_transport(builder, &fake_transport); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_stack_builder_set_channel_arguments(&exec_ctx, builder, - channel_args); + grpc_core::ExecCtx exec_ctx; + grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); GPR_ASSERT(grpc_channel_init_create_stack( - &exec_ctx, builder, (grpc_channel_stack_type)channel_stack_type)); - grpc_exec_ctx_finish(&exec_ctx); + builder, (grpc_channel_stack_type)channel_stack_type)); } // build up our expectation list @@ -212,10 +210,9 @@ static int check_stack(const char* file, int line, const char* transport_name, gpr_free(expect); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_stack_builder_destroy(&exec_ctx, builder); - grpc_channel_args_destroy(&exec_ctx, channel_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_stack_builder_destroy(builder); + grpc_channel_args_destroy(channel_args); } return result; diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 5f8d3b84cc..847ea0066b 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,9 +651,8 @@ static void test_get_channel_info() { grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); @@ -959,7 +958,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; @@ -969,9 +968,9 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_tracer_set_enabled("round_robin", 1); - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist", - nullptr) == nullptr); - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, nullptr, nullptr) == nullptr); + GPR_ASSERT(grpc_lb_policy_create("this-lb-policy-does-not-exist", nullptr) == + nullptr); + GPR_ASSERT(grpc_lb_policy_create(nullptr, nullptr) == nullptr); spec = test_spec_create(NUM_ITERS, NUM_SERVERS); /* everything is fine, all servers stay up the whole time and life's peachy @@ -1025,7 +1024,6 @@ int main(int argc, char** argv) { test_ping(); test_get_channel_info(); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 94f76da920..6d56961d84 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -24,6 +24,7 @@ #include #endif +#include #include #include "src/core/lib/iomgr/exec_ctx.h" @@ -33,8 +34,8 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); @@ -43,7 +44,6 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } #else /* GRPC_HAVE_UNIX_SOCKET */ @@ -54,8 +54,8 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) {} static void test_grpc_parse_ipv4(const char* uri_text, const char* host, unsigned short port) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -68,13 +68,12 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, GPR_ASSERT(ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } static void test_grpc_parse_ipv6(const char* uri_text, const char* host, unsigned short port, uint32_t scope_id) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; @@ -88,14 +87,16 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_grpc_parse_unix("unix:/path/name", "/path/name"); test_grpc_parse_ipv4("ipv4:192.0.2.1:12345", "192.0.2.1", 12345); test_grpc_parse_ipv6("ipv6:[2001:db8::1]:12345", "2001:db8::1", 12345, 0); test_grpc_parse_ipv6("ipv6:[2001:db8::1%252]:12345", "2001:db8::1", 12345, 2); + + grpc_shutdown(); } diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index dcf315eba5..18a795fbcb 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,8 +35,7 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -55,13 +54,13 @@ static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", addr)); @@ -76,27 +75,26 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); return nullptr; } -static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, - const char* name) { +static grpc_resolver* create_resolver(const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(exec_ctx, name, 0); + grpc_uri* uri = grpc_uri_parse(name, 0); GPR_ASSERT(uri); grpc_resolver_args args; memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); + grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { +static void on_done(void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -107,9 +105,8 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_timer_check(&exec_ctx, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_timer_check(nullptr); } return false; } @@ -120,16 +117,14 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, - void* arg, +static void call_resolver_next_now_lock_taken(void* arg, grpc_error* error_unused) { next_args* a = static_cast(arg); - grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast(gpr_malloc(sizeof(*a))); @@ -137,7 +132,6 @@ static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, a->result = result; a->on_complete = on_complete; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a, grpc_combiner_scheduler(resolver->combiner)), GRPC_ERROR_NONE); @@ -153,30 +147,31 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resolver* resolver = create_resolver(&exec_ctx, "dns:test"); - gpr_event ev1; - gpr_event_init(&ev1); - call_resolver_next_after_locking( - &exec_ctx, resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(5, &ev1)); - GPR_ASSERT(result == nullptr); - - gpr_event ev2; - gpr_event_init(&ev2); - call_resolver_next_after_locking( - &exec_ctx, resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(30, &ev2)); - GPR_ASSERT(result != nullptr); - - grpc_channel_args_destroy(&exec_ctx, result); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_resolver* resolver = create_resolver("dns:test"); + gpr_event ev1; + gpr_event_init(&ev1); + call_resolver_next_after_locking( + resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(wait_loop(5, &ev1)); + GPR_ASSERT(result == nullptr); + + gpr_event ev2; + gpr_event_init(&ev2); + call_resolver_next_after_locking( + resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(wait_loop(30, &ev2)); + GPR_ASSERT(result != nullptr); + + grpc_channel_args_destroy(result); + GRPC_RESOLVER_UNREF(resolver, "test"); + GRPC_COMBINER_UNREF(g_combiner, "test"); + } grpc_shutdown(); gpr_mu_destroy(&g_mu); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 4c040caeb9..80667908ef 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,8 +28,8 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -38,16 +38,15 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver != nullptr); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -56,10 +55,9 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -82,9 +80,8 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index d5538e9621..d85cbb1d03 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -33,7 +33,7 @@ #include "test/core/util/test_config.h" static grpc_resolver* build_fake_resolver( - grpc_exec_ctx* exec_ctx, grpc_combiner* combiner, + grpc_combiner* combiner, grpc_fake_resolver_response_generator* response_generator) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("fake"); grpc_arg generator_arg = @@ -44,7 +44,7 @@ static grpc_resolver* build_fake_resolver( args.args = &channel_args; args.combiner = combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); + grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_unref(factory); return resolver; } @@ -55,7 +55,7 @@ typedef struct on_resolution_arg { gpr_event ev; } on_resolution_arg; -void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +void on_resolution_cb(void* arg, grpc_error* error) { on_resolution_arg* res = static_cast(arg); // We only check the addresses channel arg because that's the only one // explicitly set by the test via @@ -66,24 +66,23 @@ void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_lb_addresses_find_channel_arg(res->expected_resolver_result); GPR_ASSERT( grpc_lb_addresses_cmp(actual_lb_addresses, expected_lb_addresses) == 0); - grpc_channel_args_destroy(exec_ctx, res->resolver_result); - grpc_channel_args_destroy(exec_ctx, res->expected_resolver_result); + grpc_channel_args_destroy(res->resolver_result); + grpc_channel_args_destroy(res->expected_resolver_result); gpr_event_set(&res->ev, (void*)1); } static void test_fake_resolver() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = grpc_fake_resolver_response_generator_create(); - grpc_resolver* resolver = - build_fake_resolver(&exec_ctx, combiner, response_generator); + grpc_resolver* resolver = build_fake_resolver(combiner, response_generator); GPR_ASSERT(resolver != nullptr); // Setup expectations. - grpc_uri* uris[] = {grpc_uri_parse(&exec_ctx, "ipv4:10.2.1.1:1234", true), - grpc_uri_parse(&exec_ctx, "ipv4:127.0.0.1:4321", true)}; + grpc_uri* uris[] = {grpc_uri_parse("ipv4:10.2.1.1:1234", true), + grpc_uri_parse("ipv4:127.0.0.1:4321", true)}; const char* balancer_names[] = {"name1", "name2"}; const bool is_balancer[] = {true, false}; grpc_lb_addresses* addresses = grpc_lb_addresses_create(3, nullptr); @@ -96,7 +95,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* results = grpc_channel_args_copy_and_add(nullptr, &addresses_arg, 1); - grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); on_resolution_arg on_res_arg; memset(&on_res_arg, 0, sizeof(on_res_arg)); on_res_arg.expected_resolver_result = results; @@ -106,17 +105,16 @@ static void test_fake_resolver() { // Set resolver results and trigger first resolution. on_resolution_cb // performs the checks. - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator, results); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_fake_resolver_response_generator_set_response(response_generator, + results); + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Setup update. - grpc_uri* uris_update[] = { - grpc_uri_parse(&exec_ctx, "ipv4:192.168.1.0:31416", true)}; + grpc_uri* uris_update[] = {grpc_uri_parse("ipv4:192.168.1.0:31416", true)}; const char* balancer_names_update[] = {"name3"}; const bool is_balancer_update[] = {false}; grpc_lb_addresses* addresses_update = grpc_lb_addresses_create(1, nullptr); @@ -131,7 +129,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses_update); grpc_channel_args* results_update = grpc_channel_args_copy_and_add(nullptr, &addresses_update_arg, 1); - grpc_lb_addresses_destroy(&exec_ctx, addresses_update); + grpc_lb_addresses_destroy(addresses_update); // Setup expectations for the update. on_resolution_arg on_res_arg_update; @@ -142,27 +140,27 @@ static void test_fake_resolver() { grpc_combiner_scheduler(combiner)); // Set updated resolver results and trigger a second resolution. - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator, results_update); - grpc_resolver_next_locked(&exec_ctx, resolver, - &on_res_arg_update.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_fake_resolver_response_generator_set_response(response_generator, + results_update); + grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, + on_resolution); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Requesting a new resolution without re-senting the response shouldn't // trigger the resolution callback. memset(&on_res_arg, 0, sizeof(on_res_arg)); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "test_fake_resolver"); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_fake_resolver"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); + GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); + grpc_fake_resolver_response_generator_unref(response_generator); } diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index dfa2d12b5e..4d16a77924 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -35,14 +35,14 @@ typedef struct on_resolution_arg { grpc_channel_args* resolver_result; } on_resolution_arg; -void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +void on_resolution_cb(void* arg, grpc_error* error) { on_resolution_arg* res = static_cast(arg); - grpc_channel_args_destroy(exec_ctx, res->resolver_result); + grpc_channel_args_destroy(res->resolver_result); } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -51,7 +51,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver != nullptr); on_resolution_arg on_res_arg; @@ -60,16 +60,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_closure* on_resolution = GRPC_CLOSURE_CREATE( on_resolution_cb, &on_res_arg, grpc_schedule_on_exec_ctx); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); + grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -78,10 +78,9 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -112,9 +111,8 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index ba31793ff3..ee38453166 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include "src/core/ext/filters/client_channel/uri_parser.h" @@ -33,12 +34,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { memcpy(s, data, size); s[size] = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* x; - if ((x = grpc_uri_parse(&exec_ctx, s, 1))) { - grpc_uri_destroy(x); + grpc_init(); + + { + grpc_core::ExecCtx exec_ctx; + grpc_uri* x; + if ((x = grpc_uri_parse(s, 1))) { + grpc_uri_destroy(x); + } + + gpr_free(s); } - grpc_exec_ctx_finish(&exec_ctx); - gpr_free(s); + + grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 30183f9f57..254bfddfb3 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -20,6 +20,7 @@ #include +#include #include #include "src/core/lib/iomgr/exec_ctx.h" @@ -28,29 +29,28 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); GPR_ASSERT(0 == strcmp(authority, uri->authority)); GPR_ASSERT(0 == strcmp(path, uri->path)); GPR_ASSERT(0 == strcmp(query, uri->query)); GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } static void test_fails(const char* uri_text) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(nullptr == grpc_uri_parse(&exec_ctx, uri_text, 0)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(nullptr == grpc_uri_parse(uri_text, 0)); } static void test_query_parts() { { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -77,14 +77,14 @@ static void test_query_parts() { GPR_ASSERT(nullptr == grpc_uri_get_query_arg(uri, "")); GPR_ASSERT(0 == strcmp("frag", uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } { /* test the current behavior of multiple query part values */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -96,14 +96,13 @@ static void test_query_parts() { GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); - grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } { /* empty query */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path"; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -114,13 +113,14 @@ static void test_query_parts() { GPR_ASSERT(nullptr == uri->query_parts); GPR_ASSERT(nullptr == uri->query_parts_values); GPR_ASSERT(0 == strcmp("", uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", @@ -148,5 +148,6 @@ int main(int argc, char** argv) { test_fails("http://foo?bar#lol#"); test_query_parts(); + grpc_shutdown(); return 0; } diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index 2f1d8bc8eb..9e811e9af1 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -39,7 +39,7 @@ static void test_algorithm_mesh(void) { grpc_compression_algorithm parsed; grpc_slice mdstr; grpc_mdelem mdelem; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); GPR_ASSERT(grpc_compression_algorithm_parse( @@ -51,9 +51,8 @@ static void test_algorithm_mesh(void) { mdelem = grpc_compression_encoding_mdelem(parsed); GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); - grpc_slice_unref_internal(&exec_ctx, mdstr); - GRPC_MDELEM_UNREF(&exec_ctx, mdelem); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(mdstr); + GRPC_MDELEM_UNREF(mdelem); } /* test failure */ @@ -62,7 +61,7 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); @@ -83,8 +82,7 @@ static void test_algorithm_failure(void) { grpc_compression_algorithm_slice(static_cast( static_cast(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)), grpc_empty_slice())); - grpc_slice_unref_internal(&exec_ctx, mdstr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(mdstr); } int main(int argc, char** argv) { diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 676415ba9d..6ca07b70c4 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -70,10 +70,8 @@ static void assert_passthrough(grpc_slice value, grpc_split_slices_to_buffer(uncompressed_split_mode, &value, 1, &input); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_compressed = - grpc_msg_compress(&exec_ctx, algorithm, &input, &compressed_raw); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); } GPR_ASSERT(input.count > 0); @@ -92,11 +90,9 @@ static void assert_passthrough(grpc_slice value, grpc_split_slice_buffer(compressed_split_mode, &compressed_raw, &compressed); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_msg_decompress( - &exec_ctx, was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); } final = grpc_slice_merge(output.slices, output.count); @@ -156,11 +152,11 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_compress( - &exec_ctx, static_cast(i), - &input, &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == + grpc_msg_compress(static_cast(i), + &input, &output)); + GPR_ASSERT(1 == output.count); } @@ -180,9 +176,9 @@ static void test_bad_decompression_data_crc(void) { grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* compress it */ - grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_GZIP, &input, &corrupted); + grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ GPR_ASSERT(corrupted.count > 1); GPR_ASSERT(GRPC_SLICE_LENGTH(corrupted.slices[1]) > 8); @@ -190,9 +186,7 @@ static void test_bad_decompression_data_crc(void) { memcpy(GRPC_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4); /* try (and fail) to decompress the corrupted compresed buffer */ - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_GZIP, &corrupted, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&corrupted); @@ -211,10 +205,8 @@ static void test_bad_decompression_data_trailing_garbage(void) { "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -230,10 +222,8 @@ static void test_bad_decompression_data_stream(void) { grpc_slice_from_copied_buffer("\x78\xda\xff\xff", 4)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -249,17 +239,15 @@ static void test_bad_compression_algorithm(void) { grpc_slice_buffer_add( &input, grpc_slice_from_copied_string("Never gonna give you up")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_compressed = grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, - &input, &output); + grpc_core::ExecCtx exec_ctx; + was_compressed = + grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_compressed); - was_compressed = grpc_msg_compress(&exec_ctx, - static_cast( + was_compressed = grpc_msg_compress(static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_compressed); - grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -275,18 +263,16 @@ static void test_bad_decompression_algorithm(void) { grpc_slice_buffer_add(&input, grpc_slice_from_copied_string( "I'm not really compressed but it doesn't matter")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_decompressed = grpc_msg_decompress( - &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); + grpc_core::ExecCtx exec_ctx; + was_decompressed = + grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); was_decompressed = - grpc_msg_decompress(&exec_ctx, - static_cast( + grpc_msg_decompress(static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_decompressed); - grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 5fae61f8f6..e60e54b2fd 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -49,9 +49,8 @@ TEST(StatsTest, IncCounters) { for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_COUNTER(&exec_ctx, (grpc_stats_counters)i); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); EXPECT_EQ(snapshot.delta().counters[i], 1); } @@ -60,9 +59,8 @@ TEST(StatsTest, IncCounters) { TEST(StatsTest, IncSpecificCounter) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_SYSCALL_POLL(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_STATS_INC_SYSCALL_POLL(); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); } @@ -94,9 +92,8 @@ TEST_P(HistogramTest, IncHistogram) { for (auto j : test_values) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_stats_inc_histogram[kHistogram](j); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 0fdb637ead..93809ac37a 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -91,22 +91,22 @@ static grpc_closure on_write; static void* tag(intptr_t t) { return (void*)t; } -static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void done_write(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); gpr_atm_rel_store(&state.done_atm, 1); } -static void handle_write(grpc_exec_ctx* exec_ctx) { +static void handle_write() { grpc_slice slice = grpc_slice_from_copied_buffer( state.response_payload, state.response_payload_length); grpc_slice_buffer_reset_and_unref(&state.outgoing_buffer); grpc_slice_buffer_add(&state.outgoing_buffer, slice); - grpc_endpoint_write(exec_ctx, state.tcp, &state.outgoing_buffer, &on_write); + grpc_endpoint_write(state.tcp, &state.outgoing_buffer, &on_write); } -static void handle_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void handle_read(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); state.incoming_data_length += state.temp_incoming_buffer.length; @@ -123,14 +123,13 @@ static void handle_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD); if (state.incoming_data_length >= SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD) { - handle_write(exec_ctx); + handle_write(); } else { - grpc_endpoint_read(exec_ctx, state.tcp, &state.temp_incoming_buffer, - &on_read); + grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read); } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -141,8 +140,8 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, grpc_slice_buffer_init(&state.outgoing_buffer); state.tcp = tcp; state.incoming_data_length = 0; - grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); - grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); + grpc_endpoint_add_to_pollset(tcp, server->pollset); + grpc_endpoint_read(tcp, &state.temp_incoming_buffer, &on_read); } static gpr_timespec n_sec_deadline(int seconds) { @@ -217,10 +216,10 @@ static void start_rpc(int target_port, grpc_status_code expected_status, cq_verifier_destroy(cqv); } -static void cleanup_rpc(grpc_exec_ctx* exec_ctx) { +static void cleanup_rpc() { grpc_event ev; - grpc_slice_buffer_destroy_internal(exec_ctx, &state.temp_incoming_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &state.outgoing_buffer); + grpc_slice_buffer_destroy_internal(&state.temp_incoming_buffer); + grpc_slice_buffer_destroy_internal(&state.outgoing_buffer); grpc_call_unref(state.call); grpc_completion_queue_shutdown(state.cq); do { @@ -270,7 +269,7 @@ static void run_test(const char* response_payload, grpc_status_code expected_status, const char* expected_detail) { test_tcp_server test_server; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_event ev; grpc_init(); @@ -287,11 +286,11 @@ static void run_test(const char* response_payload, gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); /* clean up */ - grpc_endpoint_shutdown(&exec_ctx, state.tcp, + grpc_endpoint_shutdown(state.tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(&exec_ctx, state.tcp); - cleanup_rpc(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_destroy(state.tcp); + cleanup_rpc(); + grpc_core::ExecCtx::Get()->Flush(); test_tcp_server_destroy(&test_server); grpc_shutdown(); @@ -299,6 +298,7 @@ static void run_test(const char* response_payload, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* status defined in hpack static table */ run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_CANCELLED, @@ -337,5 +337,6 @@ int main(int argc, char** argv) { run_test(HTTP1_RESP, sizeof(HTTP1_RESP) - 1, GRPC_STATUS_UNAVAILABLE, HTTP1_DETAIL_MSG); + grpc_shutdown(); return 0; } diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index f3f2dda91d..ca6d17e7c8 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -133,9 +133,8 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_metadata_array_destroy(&trailing_metadata_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (args != nullptr) grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (args != nullptr) grpc_channel_args_destroy(args); } grpc_shutdown(); diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index fed8ead5c8..75c80aa1ff 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -75,9 +75,8 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); } } @@ -92,9 +91,8 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index ea8990fd0a..5b9181586c 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -66,9 +66,8 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->client_args_compression != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->client_args_compression); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( client_args, GRPC_COMPRESS_GZIP); @@ -81,9 +80,8 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); if (ffd->server_args_compression != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( server_args, GRPC_COMPRESS_GZIP); @@ -97,14 +95,13 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, } void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; fullstack_compression_fixture_data* ffd = static_cast(f->fixture_data); - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); + grpc_channel_args_destroy(ffd->client_args_compression); + grpc_channel_args_destroy(ffd->server_args_compression); gpr_free(ffd->localaddr); gpr_free(ffd); - grpc_exec_ctx_finish(&exec_ctx); } /* All test configurations */ diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 97f4b71bf0..9157ab04d0 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -68,20 +68,18 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->client); f->client = grpc_insecure_channel_create_from_fd( "fixture_client", sfd->fd_pair[0], client_args); GPR_ASSERT(f->client); - - grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast(f->fixture_data); GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); @@ -90,8 +88,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_server_start(f->server); grpc_server_add_insecure_channel_from_fd(f->server, nullptr, sfd->fd_pair[1]); - - grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index 71a497d796..237841d185 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -72,7 +72,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; fullstack_fixture_data* ffd = static_cast(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; @@ -90,8 +90,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); - grpc_channel_args_destroy(&exec_ctx, server_args_new); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(server_args_new); } void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 7486b6af78..fda5f4b052 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -78,9 +78,8 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 1642cb0db9..5fed4434de 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -143,11 +143,11 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr); grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - &exec_ctx, "authorization", oauth2_md, true /* is_async */); + "authorization", oauth2_md, true /* is_async */); grpc_channel_credentials* ssl_oauth2_creds = grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, nullptr); @@ -158,10 +158,9 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds); - grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_channel_args_destroy(new_client_args); grpc_channel_credentials_release(ssl_creds); grpc_call_credentials_release(oauth2_creds); - grpc_exec_ctx_finish(&exec_ctx); } static int fail_server_auth_check(grpc_channel_args* server_args) { diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 9319c401dc..9807e929af 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -50,12 +50,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -63,13 +62,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -90,34 +87,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { @@ -133,7 +126,6 @@ static grpc_end2end_test_config configs[] = { int main(int argc, char** argv) { size_t i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* force tracing on, with a value to force many code paths in trace.c to be taken */ @@ -147,7 +139,6 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); grpc_init(); - grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 03566aada2..b68279fd71 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -44,12 +44,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -57,13 +56,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -84,34 +81,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 9adba00204..350be138ca 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -44,12 +44,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -57,13 +56,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -95,34 +92,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index 3d7e2e327e..9a0680c40e 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -110,9 +110,8 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index f8d5a699e4..5ddbdefc8c 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -66,9 +66,8 @@ static grpc_channel* create_proxy_client(const char* target, grpc_secure_channel_create(ssl_creds, target, new_client_args, nullptr); grpc_channel_credentials_release(ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } return channel; } @@ -148,9 +147,8 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 3904887026..137f7c9fa3 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -116,24 +116,21 @@ static void proxy_connection_ref(proxy_connection* conn, const char* reason) { } // Helper function to destroy the proxy connection. -static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, const char* reason) { +static void proxy_connection_unref(proxy_connection* conn, const char* reason) { if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); - grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); + grpc_endpoint_destroy(conn->client_endpoint); if (conn->server_endpoint != nullptr) { - grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); + grpc_endpoint_destroy(conn->server_endpoint); } - grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->client_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->server_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); + grpc_pollset_set_destroy(conn->pollset_set); + grpc_slice_buffer_destroy_internal(&conn->client_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); gpr_unref(&conn->proxy->users); @@ -150,8 +147,7 @@ enum failure_type { }; // Helper function to shut down the proxy connection. -static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, +static void proxy_connection_failed(proxy_connection* conn, failure_type failure, const char* prefix, grpc_error* error) { gpr_log(GPR_INFO, "%s: %s", prefix, grpc_error_string(error)); @@ -175,28 +171,25 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, } // If we decided to shut down either one and have not yet done so, do so. if (shutdown_client && !conn->client_shutdown) { - grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint, - GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(conn->client_endpoint, GRPC_ERROR_REF(error)); conn->client_shutdown = true; } if (shutdown_server && !conn->server_shutdown && (conn->server_endpoint != nullptr)) { - grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, - GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(conn->server_endpoint, GRPC_ERROR_REF(error)); conn->server_shutdown = true; } // Unref the connection. - proxy_connection_unref(exec_ctx, conn, "conn_failed"); + proxy_connection_unref(conn, "conn_failed"); GRPC_ERROR_UNREF(error); } // Callback for writing proxy data to the client. -static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, CLIENT_WRITE_FAILED, + proxy_connection_failed(conn, CLIENT_WRITE_FAILED, "HTTP proxy client write", GRPC_ERROR_REF(error)); return; } @@ -208,22 +201,20 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer, &conn->client_write_buffer); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "write_done"); + proxy_connection_unref(conn, "write_done"); } } // Callback for writing proxy data to the backend server. -static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->server_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SERVER_WRITE_FAILED, + proxy_connection_failed(conn, SERVER_WRITE_FAILED, "HTTP proxy server write", GRPC_ERROR_REF(error)); return; } @@ -235,23 +226,21 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer, &conn->server_write_buffer); conn->server_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "server_write"); + proxy_connection_unref(conn, "server_write"); } } // Callback for reading data from the client, which will be proxied to // the backend server. -static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, CLIENT_READ_FAILED, - "HTTP proxy client read", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, CLIENT_READ_FAILED, "HTTP proxy client read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., server_write_buffer is @@ -268,23 +257,21 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->server_write_buffer); proxy_connection_ref(conn, "client_read"); conn->server_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); } // Callback for reading data from the backend server, which will be // proxied to the client. -static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SERVER_READ_FAILED, - "HTTP proxy server read", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SERVER_READ_FAILED, "HTTP proxy server read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., client_write_buffer is @@ -301,23 +288,21 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->client_write_buffer); proxy_connection_ref(conn, "server_read"); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to write the HTTP response for the CONNECT request. -static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_write_response_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy write response", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy write response", + GRPC_ERROR_REF(error)); return; } // Clear write buffer. @@ -327,17 +312,16 @@ static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, // for the other one. proxy_connection_ref(conn, "client_read"); proxy_connection_ref(conn, "server_read"); - proxy_connection_unref(exec_ctx, conn, "write_response"); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + proxy_connection_unref(conn, "write_response"); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to connect to the backend server specified by the HTTP // CONNECT request. -static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_connect_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { // TODO(roth): Technically, in this case, we should handle the error @@ -345,8 +329,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, // connection failed. However, for the purposes of this test code, // it's fine to pretend this is a client-side error, which will // cause the client connection to be dropped. - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy server connect", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy server connect", + GRPC_ERROR_REF(error)); return; } // We've established a connection, so send back a 200 response code to @@ -356,8 +340,7 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n"); grpc_slice_buffer_add(&conn->client_write_buffer, slice); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_write_response_done); } @@ -366,8 +349,7 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, * Basic * Returns true if it matches, false otherwise */ -static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, - char* proxy_auth_header_val, +static bool proxy_auth_header_matches(char* proxy_auth_header_val, char* expected_cred) { GPR_ASSERT(proxy_auth_header_val != nullptr); GPR_ASSERT(expected_cred != nullptr); @@ -375,11 +357,10 @@ static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, return false; } proxy_auth_header_val += 6; - grpc_slice decoded_slice = - grpc_base64_decode(exec_ctx, proxy_auth_header_val, 0); + grpc_slice decoded_slice = grpc_base64_decode(proxy_auth_header_val, 0); const bool header_matches = grpc_slice_str_cmp(decoded_slice, expected_cred) == 0; - grpc_slice_unref_internal(exec_ctx, decoded_slice); + grpc_slice_unref_internal(decoded_slice); return header_matches; } @@ -389,14 +370,13 @@ static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, // the client indicating that the request failed. However, for the purposes // of this test code, it's fine to pretend this is a client-side error, // which will cause the client connection to be dropped. -static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_read_request_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); return; } // Read request and feed it to the parser. @@ -405,8 +385,7 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, error = grpc_http_parser_parse( &conn->http_parser, conn->client_read_buffer.slices[i], nullptr); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy request parse", + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy request parse", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; @@ -416,8 +395,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_reset_and_unref(&conn->client_read_buffer); // If we're not done reading the request, read more data. if (conn->http_parser.state != GRPC_HTTP_BODY) { - grpc_endpoint_read(exec_ctx, conn->client_endpoint, - &conn->client_read_buffer, &conn->on_read_request_done); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + &conn->on_read_request_done); return; } // Make sure we got a CONNECT request. @@ -427,8 +406,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, conn->http_request.method); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -440,16 +419,15 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, for (size_t i = 0; i < conn->http_request.hdr_count; i++) { if (strcmp(conn->http_request.hdrs[i].key, "Proxy-Authorization") == 0) { client_authenticated = proxy_auth_header_matches( - exec_ctx, conn->http_request.hdrs[i].value, - proxy_auth_arg->value.string); + conn->http_request.hdrs[i].value, proxy_auth_arg->value.string); break; } } if (!client_authenticated) { const char* msg = "HTTP Connect could not verify authentication"; error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(msg); - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -459,8 +437,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, error = grpc_blocking_resolve_address(conn->http_request.path, "80", &resolved_addresses); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy DNS lookup", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy DNS lookup", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -468,15 +446,15 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, // Connect to requested address. // The connection callback inherits our reference to conn. const grpc_millis deadline = - grpc_exec_ctx_now(exec_ctx) + 10 * GPR_MS_PER_SEC; - grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done, - &conn->server_endpoint, conn->pollset_set, nullptr, + grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; + grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, + conn->pollset_set, nullptr, &resolved_addresses->addrs[0], deadline); grpc_resolved_addresses_destroy(resolved_addresses); } -static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint, grpc_pollset* accepting_pollset, +static void on_accept(void* arg, grpc_endpoint* endpoint, + grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; @@ -487,8 +465,8 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); - grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); + grpc_pollset_set_add_pollset(conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(endpoint, conn->pollset_set); GRPC_CLOSURE_INIT(&conn->on_read_request_done, on_read_request_done, conn, grpc_combiner_scheduler(conn->proxy->combiner)); GRPC_CLOSURE_INIT(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -513,7 +491,7 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_init(&conn->server_write_buffer); grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST, &conn->http_request); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_read_request_done); } @@ -523,24 +501,23 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; do { gpr_ref(&proxy->users); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(proxy->mu); GRPC_LOG_IF_ERROR( "grpc_pollset_work", - grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC)); + grpc_pollset_work(proxy->pollset, &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } while (!gpr_unref(&proxy->users)); - grpc_exec_ctx_finish(&exec_ctx); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -552,8 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name); // Create TCP server. proxy->channel_args = grpc_channel_args_copy(args); - grpc_error* error = grpc_tcp_server_create( - &exec_ctx, nullptr, proxy->channel_args, &proxy->server); + grpc_error* error = + grpc_tcp_server_create(nullptr, proxy->channel_args, &proxy->server); GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; @@ -568,9 +545,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start server. proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(proxy->pollset, &proxy->mu); - grpc_tcp_server_start(&exec_ctx, proxy->server, &proxy->pollset, 1, on_accept, - proxy); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); + // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); @@ -579,27 +555,25 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( return proxy; } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_pollset(void* arg, grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_thd_join(proxy->thd); - grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); - grpc_tcp_server_unref(&exec_ctx, proxy->server); + grpc_tcp_server_shutdown_listeners(proxy->server); + grpc_tcp_server_unref(proxy->server); gpr_free(proxy->proxy_name); - grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); - grpc_pollset_shutdown(&exec_ctx, proxy->pollset, + grpc_channel_args_destroy(proxy->channel_args); + grpc_pollset_shutdown(proxy->pollset, GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset, grpc_schedule_on_exec_ctx)); - GRPC_COMBINER_UNREF(&exec_ctx, proxy->combiner, "test"); + GRPC_COMBINER_UNREF(proxy->combiner, "test"); gpr_free(proxy); - grpc_exec_ctx_finish(&exec_ctx); } const char* grpc_end2end_http_proxy_get_proxy_name( diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 75117218e4..967a6d560f 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -376,8 +376,7 @@ typedef struct addr_req { grpc_lb_addresses** lb_addrs; } addr_req; -static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void finish_resolve(void* arg, grpc_error* error) { addr_req* r = static_cast(arg); if (error == GRPC_ERROR_NONE && 0 == strcmp(r->addr, "server")) { @@ -395,9 +394,9 @@ static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, nullptr); *r->lb_addrs = lb_addrs; } - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_NONE); } else { - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, + GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Resolution failed", &error, 1)); } @@ -406,8 +405,7 @@ static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, gpr_free(r); } -void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) { @@ -417,22 +415,24 @@ void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, r->addrs = addresses; r->lb_addrs = nullptr; grpc_timer_init( - exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } -grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, - char** service_config_json) { +grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, + const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, + bool check_grpclb, + char** service_config_json) { addr_req* r = static_cast(gpr_malloc(sizeof(*r))); r->addr = gpr_strdup(addr); r->on_done = on_done; r->addrs = nullptr; r->lb_addrs = lb_addrs; grpc_timer_init( - exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); return nullptr; } @@ -442,12 +442,12 @@ grpc_ares_request* my_dns_lookup_ares( // defined in tcp_client_posix.c extern 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); -static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_endpoint** ep, gpr_timespec deadline); +static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, + gpr_timespec deadline); typedef struct { grpc_timer timer; @@ -456,11 +456,11 @@ typedef struct { gpr_timespec deadline; } future_connect; -static void do_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void do_connect(void* arg, grpc_error* error) { future_connect* fc = static_cast(arg); if (error != GRPC_ERROR_NONE) { *fc->ep = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_REF(error)); } else if (g_server != nullptr) { grpc_endpoint* client; grpc_endpoint* server; @@ -468,25 +468,23 @@ static void do_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { *fc->ep = client; grpc_transport* transport = - grpc_create_chttp2_transport(exec_ctx, nullptr, server, false); - grpc_server_setup_transport(exec_ctx, g_server, transport, nullptr, - nullptr); - grpc_chttp2_transport_start_reading(exec_ctx, transport, nullptr, nullptr); + grpc_create_chttp2_transport(nullptr, server, false); + grpc_server_setup_transport(g_server, transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_NONE); } else { - sched_connect(exec_ctx, fc->closure, fc->ep, fc->deadline); + sched_connect(fc->closure, fc->ep, fc->deadline); } gpr_free(fc); } -static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_endpoint** ep, gpr_timespec deadline) { +static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, + gpr_timespec deadline) { if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) { *ep = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, closure, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connect deadline exceeded")); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Connect deadline exceeded")); return; } @@ -495,17 +493,16 @@ static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, fc->ep = ep; fc->deadline = deadline; grpc_timer_init( - exec_ctx, &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &fc->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx)); } -static void my_tcp_client_connect(grpc_exec_ctx* exec_ctx, - grpc_closure* closure, grpc_endpoint** ep, +static void my_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) { - sched_connect(exec_ctx, closure, ep, + sched_connect(closure, ep, grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); } @@ -751,9 +748,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_timer_manager_set_threading(false); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); } grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; @@ -846,9 +842,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_insecure_channel_create(target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } gpr_free(target_uri); gpr_free(target); @@ -874,9 +869,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_server = grpc_server_create(args, nullptr); GPR_ASSERT(g_server != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } grpc_server_register_completion_queue(g_server, cq, nullptr); grpc_server_start(g_server); @@ -1205,9 +1199,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_secure_channel_create(creds, target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } gpr_free(target_uri); gpr_free(target); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index 5871f0f43e..c17d581d8b 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -43,112 +43,114 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("client_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_transport* transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, true); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - - grpc_channel* channel = grpc_channel_create( - &exec_ctx, "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_slice host = grpc_slice_from_static_string("localhost"); - grpc_call* call = grpc_channel_create_call( - channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - - grpc_metadata_array initial_metadata_recv; - grpc_metadata_array_init(&initial_metadata_recv); - grpc_byte_buffer* response_payload_recv = nullptr; - grpc_metadata_array trailing_metadata_recv; - grpc_metadata_array_init(&trailing_metadata_recv); - grpc_status_code status; - grpc_slice details = grpc_empty_slice(); - - grpc_op ops[6]; - memset(ops, 0, sizeof(ops)); - grpc_op* op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &response_payload_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; - op->data.recv_status_on_client.status = &status; - op->data.recv_status_on_client.status_details = &details; - op->flags = 0; - op->reserved = nullptr; - op++; - grpc_call_error error = - grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); - int requested_calls = 1; - GPR_ASSERT(GRPC_CALL_OK == error); - - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); - - grpc_event ev; - while (1) { - grpc_exec_ctx_flush(&exec_ctx); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - requested_calls--; - break; + { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("client_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_transport* transport = + grpc_create_chttp2_transport(nullptr, mock_endpoint, true); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + + grpc_channel* channel = grpc_channel_create( + "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_slice host = grpc_slice_from_static_string("localhost"); + grpc_call* call = grpc_channel_create_call( + channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); + + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array_init(&initial_metadata_recv); + grpc_byte_buffer* response_payload_recv = nullptr; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_status_code status; + grpc_slice details = grpc_empty_slice(); + + grpc_op ops[6]; + memset(ops, 0, sizeof(ops)); + grpc_op* op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->flags = 0; + op->reserved = nullptr; + op++; + grpc_call_error error = + grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); + int requested_calls = 1; + GPR_ASSERT(GRPC_CALL_OK == error); + + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); + + grpc_event ev; + while (1) { + grpc_core::ExecCtx::Get()->Flush(); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + requested_calls--; + break; + } } - } -done: - if (requested_calls) { - grpc_call_cancel(call, nullptr); - } - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); - } - grpc_call_unref(call); - grpc_completion_queue_destroy(cq); - grpc_metadata_array_destroy(&initial_metadata_recv); - grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); - grpc_channel_destroy(channel); - if (response_payload_recv != nullptr) { - grpc_byte_buffer_destroy(response_payload_recv); + done: + if (requested_calls) { + grpc_call_cancel(call, nullptr); + } + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + } + grpc_call_unref(call); + grpc_completion_queue_destroy(cq); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_slice_unref(details); + grpc_channel_destroy(channel); + if (response_payload_recv != nullptr) { + grpc_byte_buffer_destroy(response_payload_recv); + } } grpc_shutdown(); if (leak_check) { diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 67caf4e720..61c55e0afd 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -41,81 +41,82 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); + { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); - grpc_server* server = grpc_server_create(nullptr, nullptr); - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_server_register_completion_queue(server, cq, nullptr); - // TODO(ctiller): add registered methods (one for POST, one for PUT) - // void *registered_method = - // grpc_server_register_method(server, "/reg", NULL, 0); - grpc_server_start(server); - grpc_transport* transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, false); - grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, nullptr); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_server* server = grpc_server_create(nullptr, nullptr); + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_server_register_completion_queue(server, cq, nullptr); + // TODO(ctiller): add registered methods (one for POST, one for PUT) + // void *registered_method = + // grpc_server_register_method(server, "/reg", NULL, 0); + grpc_server_start(server); + grpc_transport* transport = + grpc_create_chttp2_transport(nullptr, mock_endpoint, false); + grpc_server_setup_transport(server, transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - grpc_call* call1 = nullptr; - grpc_call_details call_details1; - grpc_metadata_array request_metadata1; - grpc_call_details_init(&call_details1); - grpc_metadata_array_init(&request_metadata1); - int requested_calls = 0; + grpc_call* call1 = nullptr; + grpc_call_details call_details1; + grpc_metadata_array request_metadata1; + grpc_call_details_init(&call_details1); + grpc_metadata_array_init(&request_metadata1); + int requested_calls = 0; - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(server, &call1, &call_details1, - &request_metadata1, cq, cq, tag(1))); - requested_calls++; + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(server, &call1, &call_details1, + &request_metadata1, cq, cq, tag(1))); + requested_calls++; - grpc_event ev; - while (1) { - grpc_exec_ctx_flush(&exec_ctx); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - switch (detag(ev.tag)) { - case 1: - requested_calls--; - // TODO(ctiller): keep reading that call! - break; - } + grpc_event ev; + while (1) { + grpc_core::ExecCtx::Get()->Flush(); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + switch (detag(ev.tag)) { + case 1: + requested_calls--; + // TODO(ctiller): keep reading that call! + break; + } + } } - } -done: - if (call1 != nullptr) grpc_call_unref(call1); - grpc_call_details_destroy(&call_details1); - grpc_metadata_array_destroy(&request_metadata1); - grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); - grpc_server_cancel_all_calls(server); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + done: + if (call1 != nullptr) grpc_call_unref(call1); + grpc_call_details_destroy(&call_details1); + grpc_metadata_array_destroy(&request_metadata1); + grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); + grpc_server_cancel_all_calls(server); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + } + grpc_server_destroy(server); + grpc_completion_queue_destroy(cq); } - grpc_server_destroy(server); - grpc_completion_queue_destroy(cq); grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 2d0db967c3..94cfbdda7e 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -39,16 +39,15 @@ static void* tag(intptr_t i) { return (void*)i; } static gpr_mu g_mu; static int g_resolve_port = -1; -static void (*iomgr_resolve_address)(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void (*iomgr_resolve_address)(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses); static grpc_ares_request* (*iomgr_dns_lookup_ares)( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addresses, bool check_grpclb, char** service_config_json); static void set_resolve_port(int port) { @@ -57,14 +56,13 @@ static void set_resolve_port(int port) { gpr_mu_unlock(&g_mu); } -static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { if (0 != strcmp(addr, "test")) { - iomgr_resolve_address(exec_ctx, addr, default_port, interested_parties, - on_done, addrs); + iomgr_resolve_address(addr, default_port, interested_parties, on_done, + addrs); return; } @@ -86,16 +84,16 @@ static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { if (0 != strcmp(addr, "test")) { - return iomgr_dns_lookup_ares(exec_ctx, dns_server, addr, default_port, + return iomgr_dns_lookup_ares(dns_server, addr, default_port, interested_parties, on_done, lb_addrs, check_grpclb, service_config_json); } @@ -117,7 +115,7 @@ static grpc_ares_request* my_dns_lookup_ares( gpr_free(sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); return nullptr; } diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index 9a98c07158..d50d1f4d81 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -181,9 +181,8 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ { \ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; \ - grpc_channel_args_destroy(&exec_ctx, new_client_args); \ - grpc_exec_ctx_finish(&exec_ctx); \ + grpc_core::ExecCtx exec_ctx; \ + grpc_channel_args_destroy(new_client_args); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 83439d71d2..f59caf7e35 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -245,9 +245,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index ddcec67de5..b10b93978d 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -278,9 +278,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index a8ea0ff2e0..944edc7a70 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -129,10 +129,9 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(&exec_ctx); + &server_args, algorithm_to_disable, false); } f = begin_test(config, test_name, client_args, server_args); @@ -257,10 +256,9 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); @@ -539,10 +537,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/end2end/tests/filter_call_init_fails.cc b/test/core/end2end/tests/filter_call_init_fails.cc index 6eed68a2f9..8f46f0bb91 100644 --- a/test/core/end2end/tests/filter_call_init_fails.cc +++ b/test/core/end2end/tests/filter_call_init_fails.cc @@ -399,26 +399,23 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { * Test filter - always fails to initialize a call */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("access denied"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED); } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { grpc_call_next_op, @@ -437,8 +434,7 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_server_channel_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_server_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -457,8 +453,7 @@ static bool maybe_add_server_channel_filter(grpc_exec_ctx* exec_ctx, } } -static bool maybe_add_client_channel_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -478,7 +473,7 @@ static bool maybe_add_client_channel_filter(grpc_exec_ctx* exec_ctx, } static bool maybe_add_client_subchannel_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_subchannel_filter) { // Want to add the filter as close to the end as possible, to make // sure that all of the filters work well together. However, we diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index 793f590686..ec8f9dbe00 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -197,12 +197,11 @@ typedef struct { uint8_t unused; } channel_data; -static void recv_im_ready(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void recv_im_ready(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; GRPC_CLOSURE_RUN( - exec_ctx, calld->recv_im_ready, + calld->recv_im_ready, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failure that's not preventable.", &error, 1), GRPC_ERROR_INT_GRPC_STATUS, @@ -210,8 +209,7 @@ static void recv_im_ready(grpc_exec_ctx* exec_ctx, void* arg, } static void start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; if (op->recv_initial_metadata) { calld->recv_im_ready = @@ -219,27 +217,24 @@ static void start_transport_stream_op_batch( op->payload->recv_initial_metadata.recv_initial_metadata_ready = GRPC_CLOSURE_CREATE(recv_im_ready, elem, grpc_schedule_on_exec_ctx); } - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { start_transport_stream_op_batch, @@ -258,8 +253,7 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_filter) { return grpc_channel_stack_builder_prepend_filter(builder, &test_filter, nullptr, nullptr); diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index c4d96ebfe2..845cbc01cf 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -247,14 +247,12 @@ static void test_request(grpc_end2end_test_config config) { * Test latency filter */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void client_destroy_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void client_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -262,8 +260,7 @@ static void client_destroy_call_elem(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&g_mu); } -static void server_destroy_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void server_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -271,14 +268,12 @@ static void server_destroy_call_elem(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&g_mu); } -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_client_filter = { grpc_call_next_op, @@ -310,8 +305,7 @@ static const grpc_channel_filter test_server_filter = { * Registration */ -static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { grpc_channel_filter* filter = (grpc_channel_filter*)arg; if (g_enable_filter) { // Want to add the filter as close to the end as possible, to make diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index faabec34cb..e056bd547b 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -300,9 +300,8 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { &trailing_lr_metadata); end_test(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, lr_server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(lr_server_args); } config.tear_down_data(&f); } diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index f1ac27fa7c..e581f1fc20 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -173,12 +173,9 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, f = begin_test(config, "test_max_request_message_length", client_args, server_args); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (client_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, client_args); - if (server_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (client_args != nullptr) grpc_channel_args_destroy(client_args); + if (server_args != nullptr) grpc_channel_args_destroy(server_args); } cqv = cq_verifier_create(f.cq); @@ -366,12 +363,9 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, f = begin_test(config, "test_max_response_message_length", client_args, server_args); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (client_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, client_args); - if (server_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (client_args != nullptr) grpc_channel_args_destroy(client_args); + if (server_args != nullptr) grpc_channel_args_destroy(server_args); } cqv = cq_verifier_create(f.cq); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index d73346468a..ec3050ad45 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -129,10 +129,9 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_stream_compression_algorithm( nullptr, GRPC_STREAM_COMPRESS_NONE); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_stream_compression_algorithm_set_state( - &exec_ctx, &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(&exec_ctx); + &server_args, algorithm_to_disable, false); } f = begin_test(config, test_name, client_args, server_args); @@ -258,10 +257,9 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); @@ -547,10 +545,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 924961ea55..b95e6528cd 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -277,10 +277,9 @@ static void test_invoke_request_response_with_payload( end_test(&f); config.tear_down_data(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index d3b526f04e..2a8799ee67 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -275,10 +275,9 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, end_test(&f); config.tear_down_data(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index bc4d5079d8..d4decce0aa 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -142,15 +142,14 @@ static void request_with_payload_template( nullptr, default_server_channel_compression_algorithm); if (user_agent_override) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* client_args_old = client_args; grpc_arg arg; arg.key = const_cast(GRPC_ARG_PRIMARY_USER_AGENT_STRING); arg.type = GRPC_ARG_STRING; arg.value.string = user_agent_override; client_args = grpc_channel_args_copy_and_add(client_args_old, &arg, 1); - grpc_channel_args_destroy(&exec_ctx, client_args_old); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(client_args_old); } f = begin_test(config, test_name, client_args, server_args); @@ -351,10 +350,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 2810082837..599e0e16e2 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -49,41 +49,37 @@ * to the security_handshaker). This test is meant to protect code relying on * this functionality that lives outside of this repo. */ -static void readahead_handshaker_destroy(grpc_exec_ctx* ctx, - grpc_handshaker* handshaker) { +static void readahead_handshaker_destroy(grpc_handshaker* handshaker) { gpr_free(handshaker); } -static void readahead_handshaker_shutdown(grpc_exec_ctx* ctx, - grpc_handshaker* handshaker, +static void readahead_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* error) {} static void readahead_handshaker_do_handshake( - grpc_exec_ctx* ctx, grpc_handshaker* handshaker, - grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, - grpc_handshaker_args* args) { - grpc_endpoint_read(ctx, args->endpoint, args->read_buffer, on_handshake_done); + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, + grpc_closure* on_handshake_done, grpc_handshaker_args* args) { + grpc_endpoint_read(args->endpoint, args->read_buffer, on_handshake_done); } const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_destroy, readahead_handshaker_shutdown, readahead_handshaker_do_handshake}; -static grpc_handshaker* readahead_handshaker_create(grpc_exec_ctx* ctx) { +static grpc_handshaker* readahead_handshaker_create() { grpc_handshaker* h = (grpc_handshaker*)gpr_zalloc(sizeof(grpc_handshaker)); grpc_handshaker_init(&readahead_handshaker_vtable, h); return h; } static void readahead_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* hf, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { - grpc_handshake_manager_add(handshake_mgr, - readahead_handshaker_create(exec_ctx)); + grpc_handshaker_factory* hf, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { + grpc_handshake_manager_add(handshake_mgr, readahead_handshaker_create()); } static void readahead_handshaker_factory_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) {} + grpc_handshaker_factory* handshaker_factory) {} static const grpc_handshaker_factory_vtable readahead_handshaker_factory_vtable = { diff --git a/test/core/http/format_request_test.cc b/test/core/http/format_request_test.cc index 684738a997..353e138b2a 100644 --- a/test/core/http/format_request_test.cc +++ b/test/core/http/format_request_test.cc @@ -139,11 +139,13 @@ static void test_format_post_request_content_type_override(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_format_get_request(); test_format_post_request(); test_format_post_request_no_body(); test_format_post_request_content_type_override(); + grpc_shutdown(); return 0; } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 81e9374819..259e3aa463 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_finish(void* arg, grpc_error* error) { const char* expect = "Hello world!" "

This is a test

"; @@ -53,15 +53,14 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), - nullptr))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -78,19 +77,18 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -101,7 +99,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -118,20 +116,18 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, - n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -139,69 +135,69 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { - grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( - static_cast(p))); +static void destroy_pops(void* p, grpc_error* error) { + grpc_pollset_destroy( + grpc_polling_entity_pollset(static_cast(p))); } int main(int argc, char** argv) { - grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; - char* me = argv[0]; - char* lslash = strrchr(me, '/'); - char* args[4]; - int port = grpc_pick_unused_port_or_die(); - int arg_shift = 0; - /* figure out where we are */ - char* root; - if (lslash) { - root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); - memcpy(root, me, (size_t)(lslash - me)); - root[lslash - me] = 0; - } else { - root = gpr_strdup("."); - } - - GPR_ASSERT(argc <= 2); - if (argc == 2) { - args[0] = gpr_strdup(argv[1]); - } else { - arg_shift = 1; - gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); - gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); - } - - /* start the server */ - args[1 + arg_shift] = const_cast("--port"); - gpr_asprintf(&args[2 + arg_shift], "%d", port); - server = gpr_subprocess_create(3 + arg_shift, (const char**)args); - GPR_ASSERT(server); - gpr_free(args[0]); - if (arg_shift) gpr_free(args[1]); - gpr_free(args[2 + arg_shift]); - gpr_free(root); - - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(5, GPR_TIMESPAN))); - grpc_test_init(argc, argv); grpc_init(); - grpc_httpcli_context_init(&g_context); - grpc_pollset* pollset = - static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollset, &g_mu); - g_pops = grpc_polling_entity_create_from_pollset(pollset); - - test_get(port); - test_post(port); - - grpc_httpcli_context_destroy(&exec_ctx, &g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_closure destroyed; + grpc_core::ExecCtx exec_ctx; + char* me = argv[0]; + char* lslash = strrchr(me, '/'); + char* args[4]; + int port = grpc_pick_unused_port_or_die(); + int arg_shift = 0; + /* figure out where we are */ + char* root; + if (lslash) { + root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); + memcpy(root, me, (size_t)(lslash - me)); + root[lslash - me] = 0; + } else { + root = gpr_strdup("."); + } + + GPR_ASSERT(argc <= 2); + if (argc == 2) { + args[0] = gpr_strdup(argv[1]); + } else { + arg_shift = 1; + gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); + gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); + } + + /* start the server */ + args[1 + arg_shift] = const_cast("--port"); + gpr_asprintf(&args[2 + arg_shift], "%d", port); + server = gpr_subprocess_create(3 + arg_shift, (const char**)args); + GPR_ASSERT(server); + gpr_free(args[0]); + if (arg_shift) gpr_free(args[1]); + gpr_free(args[2 + arg_shift]); + gpr_free(root); + + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); + + grpc_httpcli_context_init(&g_context); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(pollset, &g_mu); + g_pops = grpc_polling_entity_create_from_pollset(pollset); + + test_get(port); + test_post(port); + + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index da8405c049..adf69f1b16 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_finish(void* arg, grpc_error* error) { const char* expect = "Hello world!" "

This is a test

"; @@ -53,15 +53,14 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), - nullptr))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -79,19 +78,18 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -102,7 +100,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -120,20 +118,18 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, - n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -141,14 +137,13 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { - grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( - static_cast(p))); +static void destroy_pops(void* p, grpc_error* error) { + grpc_pollset_destroy( + grpc_polling_entity_pollset(static_cast(p))); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; char* me = argv[0]; char* lslash = strrchr(me, '/'); @@ -199,12 +194,13 @@ int main(int argc, char** argv) { test_get(port); test_post(port); - grpc_httpcli_context_destroy(&exec_ctx, &g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/parser_test.cc b/test/core/http/parser_test.cc index 0b60e369b7..18f19856bd 100644 --- a/test/core/http/parser_test.cc +++ b/test/core/http/parser_test.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -217,6 +218,7 @@ int main(int argc, char** argv) { char *tmp1, *tmp2; grpc_test_init(argc, argv); + grpc_init(); for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) { test_succeeds(split_modes[i], @@ -300,5 +302,6 @@ int main(int argc, char** argv) { gpr_free(tmp2); } + grpc_shutdown(); return 0; } diff --git a/test/core/http/request_fuzzer.cc b/test/core/http/request_fuzzer.cc index 368ac1b49d..9798cfb33c 100644 --- a/test/core/http/request_fuzzer.cc +++ b/test/core/http/request_fuzzer.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include "src/core/lib/http/parser.h" @@ -30,6 +31,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_request request; + grpc_init(); memset(&request, 0, sizeof(request)); grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -38,5 +40,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_request_destroy(&request); + grpc_shutdown(); return 0; } diff --git a/test/core/http/response_fuzzer.cc b/test/core/http/response_fuzzer.cc index 2a793fddd4..fc0904b1db 100644 --- a/test/core/http/response_fuzzer.cc +++ b/test/core/http/response_fuzzer.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "src/core/lib/http/parser.h" @@ -29,6 +30,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_response response; + grpc_init(); memset(&response, 0, sizeof(response)); grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -37,5 +39,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_response_destroy(&response); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 33d892fa06..891008c774 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -28,13 +28,11 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, grpc_combiner_create(), "test_no_op"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); } -static void set_event_to_true(grpc_exec_ctx* exec_ctx, void* value, - grpc_error* error) { +static void set_event_to_true(void* value, grpc_error* error) { gpr_event_set(static_cast(value), (void*)1); } @@ -44,16 +42,14 @@ static void test_execute_one(void) { grpc_combiner* lock = grpc_combiner_create(); gpr_event done; gpr_event_init(&done); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE(set_event_to_true, &done, + grpc_core::ExecCtx exec_ctx; + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_one"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(lock, "test_execute_one"); } typedef struct { @@ -67,7 +63,7 @@ typedef struct { size_t value; } ex_args; -static void check_one(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void check_one(void* a, grpc_error* error) { ex_args* args = static_cast(a); GPR_ASSERT(*args->ctr == args->value - 1); *args->ctr = args->value; @@ -76,28 +72,25 @@ static void check_one(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { static void execute_many_loop(void* a) { thd_args* args = static_cast(a); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; size_t n = 1; for (size_t i = 0; i < 10; i++) { for (size_t j = 0; j < 10000; j++) { ex_args* c = static_cast(gpr_malloc(sizeof(*c))); c->ctr = &args->ctr; c->value = n++; - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE( + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE( check_one, c, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } // sleep for a little bit, to test a combiner draining and another thread // picking it up gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); } - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); } static void test_execute_many(void) { @@ -120,20 +113,18 @@ static void test_execute_many(void) { gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr); gpr_thd_join(thds[i]); } - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_many"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(lock, "test_execute_many"); } static gpr_event got_in_finally; -static void in_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void in_finally(void* arg, grpc_error* error) { gpr_event_set(&got_in_finally, (void*)1); } -static void add_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_CREATE(in_finally, arg, +static void add_finally(void* arg, grpc_error* error) { + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(in_finally, arg, grpc_combiner_finally_scheduler( static_cast(arg))), GRPC_ERROR_NONE); @@ -143,17 +134,15 @@ static void test_execute_finally(void) { gpr_log(GPR_DEBUG, "test_execute_finally"); grpc_combiner* lock = grpc_combiner_create(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_event_init(&got_in_finally); GRPC_CLOSURE_SCHED( - &exec_ctx, GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&got_in_finally, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_finally"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(lock, "test_execute_finally"); } int main(int argc, char** argv) { diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 30a0cb5924..90dd40d9c4 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -32,7 +32,7 @@ static void clean_up(void) {} static grpc_endpoint_test_fixture create_fixture_endpoint_pair( size_t slice_size) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_test_fixture f; grpc_arg a[1]; a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); @@ -43,9 +43,8 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( f.client_ep = p.client; f.server_ep = p.server; - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); return f; } @@ -54,23 +53,23 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 026e34105d..8ccae52067 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -115,8 +115,7 @@ struct read_and_write_test_state { grpc_closure done_write; }; -static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx, - void* data, grpc_error* error) { +static void read_and_write_test_read_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; @@ -126,17 +125,14 @@ static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx, gpr_log(GPR_INFO, "Read handler done"); gpr_mu_lock(g_mu); state->read_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); gpr_mu_unlock(g_mu); } else if (error == GRPC_ERROR_NONE) { - grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, - &state->done_read); + grpc_endpoint_read(state->read_ep, &state->incoming, &state->done_read); } } -static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, - void* data, grpc_error* error) { +static void read_and_write_test_write_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; grpc_slice* slices = nullptr; @@ -153,7 +149,7 @@ static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, &state->current_write_data); grpc_slice_buffer_reset_and_unref(&state->outgoing); grpc_slice_buffer_addn(&state->outgoing, slices, nslices); - grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing, + grpc_endpoint_write(state->write_ep, &state->outgoing, &state->done_write); gpr_free(slices); return; @@ -163,8 +159,7 @@ static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, gpr_log(GPR_INFO, "Write handler done"); gpr_mu_lock(g_mu); state->write_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); gpr_mu_unlock(g_mu); } @@ -178,7 +173,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, struct read_and_write_test_state state; grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, @@ -217,66 +212,57 @@ static void read_and_write_test(grpc_endpoint_test_config config, for the first iteration as for later iterations. It does the right thing even when bytes_written is unsigned. */ state.bytes_written -= state.current_write_size; - read_and_write_test_write_handler(&exec_ctx, &state, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + read_and_write_test_write_handler(&state, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); - grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming, - &state.done_read); + grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read); if (shutdown) { gpr_log(GPR_DEBUG, "shutdown read"); grpc_endpoint_shutdown( - &exec_ctx, state.read_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + state.read_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); gpr_log(GPR_DEBUG, "shutdown write"); grpc_endpoint_shutdown( - &exec_ctx, state.write_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = nullptr; - GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline); + GPR_ASSERT(grpc_core::ExecCtx::Get()->Now() < deadline); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); end_test(config); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.outgoing); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, state.read_ep); - grpc_endpoint_destroy(&exec_ctx, state.write_ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.outgoing); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(state.read_ep); + grpc_endpoint_destroy(state.write_ep); } -static void inc_on_failure(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void inc_on_failure(void* arg, grpc_error* error) { gpr_mu_lock(g_mu); *(int*)arg += (error != GRPC_ERROR_NONE); - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void wait_for_fail_count(grpc_exec_ctx* exec_ctx, int* fail_count, - int want_fail_count) { - grpc_exec_ctx_flush(exec_ctx); +static void wait_for_fail_count(int* fail_count, int want_fail_count) { + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); - while (grpc_exec_ctx_now(exec_ctx) < deadline && + while (grpc_core::ExecCtx::Get()->Now() < deadline && *fail_count < want_fail_count) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(*fail_count == want_fail_count); @@ -291,33 +277,32 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_slice_buffer slice_buffer; grpc_slice_buffer_init(&slice_buffer); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 0); - grpc_endpoint_shutdown(&exec_ctx, f.client_ep, + wait_for_fail_count(&fail_count, 0); + grpc_endpoint_shutdown(f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&exec_ctx, &fail_count, 1); - grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, + wait_for_fail_count(&fail_count, 1); + grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 2); + wait_for_fail_count(&fail_count, 2); grpc_slice_buffer_add(&slice_buffer, grpc_slice_from_copied_string("a")); - grpc_endpoint_write(&exec_ctx, f.client_ep, &slice_buffer, + grpc_endpoint_write(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 3); - grpc_endpoint_shutdown(&exec_ctx, f.client_ep, + wait_for_fail_count(&fail_count, 3); + grpc_endpoint_shutdown(f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&exec_ctx, &fail_count, 3); + wait_for_fail_count(&fail_count, 3); - grpc_slice_buffer_destroy_internal(&exec_ctx, &slice_buffer); + grpc_slice_buffer_destroy_internal(&slice_buffer); - grpc_endpoint_destroy(&exec_ctx, f.client_ep); - grpc_endpoint_destroy(&exec_ctx, f.server_ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_destroy(f.client_ep); + grpc_endpoint_destroy(f.server_ep); } void grpc_endpoint_tests(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 94f387164a..e767e01f21 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -70,19 +70,18 @@ static void test_fd_init(test_fd* tfds, int* fds, int num_fds) { } } -static void test_fd_cleanup(grpc_exec_ctx* exec_ctx, test_fd* tfds, - int num_fds) { +static void test_fd_cleanup(test_fd* tfds, int num_fds) { int release_fd; int i; for (i = 0; i < num_fds; i++) { - grpc_fd_shutdown(exec_ctx, tfds[i].fd, + grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, - false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(exec_ctx); + grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, + "test_fd_cleanup"); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(release_fd == tfds[i].inner_fd); close(tfds[i].inner_fd); @@ -98,22 +97,20 @@ static void test_pollset_init(test_pollset* pollsets, int num_pollsets) { } } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } -static void test_pollset_cleanup(grpc_exec_ctx* exec_ctx, - test_pollset* pollsets, int num_pollsets) { +static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { grpc_closure destroyed; int i; for (i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, pollsets[i].pollset, &destroyed); + grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].pollset); } } @@ -133,7 +130,7 @@ static void test_pollset_cleanup(grpc_exec_ctx* exec_ctx, #define NUM_POLLSETS 4 static void test_add_fd_to_pollset() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; test_fd tfds[NUM_FDS]; int fds[NUM_FDS]; test_pollset pollsets[NUM_POLLSETS]; @@ -170,33 +167,33 @@ static void test_add_fd_to_pollset() { /* == Step 1 == */ for (i = 0; i <= 2; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 3; i <= 4; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 5; i <= 7; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 2 == */ for (i = 0; i <= 1; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[3].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 3 == */ - grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[0].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); + grpc_core::ExecCtx::Get()->Flush(); /* == Step 4 == */ - grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[3].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); + grpc_core::ExecCtx::Get()->Flush(); /* All polling islands are merged at this point */ @@ -213,9 +210,8 @@ static void test_add_fd_to_pollset() { expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); } - test_fd_cleanup(&exec_ctx, tfds, NUM_FDS); - test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS); - grpc_exec_ctx_finish(&exec_ctx); + test_fd_cleanup(tfds, NUM_FDS); + test_pollset_cleanup(pollsets, NUM_POLLSETS); } #undef NUM_FDS @@ -235,26 +231,24 @@ static __thread int thread_wakeups = 0; static void test_threading_loop(void* arg) { threading_shared* shared = static_cast(arg); while (thread_wakeups < 1000000) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; gpr_mu_lock(shared->mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, shared->pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(shared->pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(shared->mu); - grpc_exec_ctx_finish(&exec_ctx); } } -static void test_threading_wakeup(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void test_threading_wakeup(void* arg, grpc_error* error) { threading_shared* shared = static_cast(arg); ++shared->wakeups; ++thread_wakeups; if (error == GRPC_ERROR_NONE) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "consume_wakeup", grpc_wakeup_fd_consume_wakeup(shared->wakeup_fd))); - grpc_fd_notify_on_read(exec_ctx, shared->wakeup_desc, &shared->on_wakeup); + grpc_fd_notify_on_read(shared->wakeup_desc, &shared->on_wakeup); GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_next", grpc_wakeup_fd_wakeup(shared->wakeup_fd))); } @@ -277,13 +271,12 @@ static void test_threading(void) { shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup"); shared.wakeups = 0; { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_add_fd(&exec_ctx, shared.pollset, shared.wakeup_desc); + grpc_core::ExecCtx exec_ctx; + grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); grpc_fd_notify_on_read( - &exec_ctx, shared.wakeup_desc, + shared.wakeup_desc, GRPC_CLOSURE_INIT(&shared.on_wakeup, test_threading_wakeup, &shared, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", grpc_wakeup_fd_wakeup(shared.wakeup_fd))); @@ -293,14 +286,13 @@ static void test_threading(void) { fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_fd_shutdown(&exec_ctx, shared.wakeup_desc, GRPC_ERROR_CANCELLED); - grpc_fd_orphan(&exec_ctx, shared.wakeup_desc, nullptr, nullptr, + grpc_core::ExecCtx exec_ctx; + grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); + grpc_fd_orphan(shared.wakeup_desc, nullptr, nullptr, false /* already_closed */, "done"); - grpc_pollset_shutdown(&exec_ctx, shared.pollset, + grpc_pollset_shutdown(shared.pollset, GRPC_CLOSURE_CREATE(destroy_pollset, shared.pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } gpr_free(shared.pollset); } @@ -309,20 +301,21 @@ int main(int argc, char** argv) { const char* poll_strategy = nullptr; grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - poll_strategy = grpc_get_poll_strategy_name(); - if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { - test_add_fd_to_pollset(); - test_threading(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epollsig' " - "strategy. and the current strategy is: '%s'", - poll_strategy); + { + grpc_core::ExecCtx exec_ctx; + + poll_strategy = grpc_get_poll_strategy_name(); + if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { + test_add_fd_to_pollset(); + test_threading(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epollsig' " + "strategy. and the current strategy is: '%s'", + poll_strategy); + } } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index f46430c611..aaa14010f8 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -31,26 +31,27 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - /* set max # of file descriptors to a low value, and - verify we can create and destroy many more than this number - of descriptors */ - rlim.rlim_cur = rlim.rlim_max = 10; - GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("fd_conservation_posix_test"); - - for (i = 0; i < 100; i++) { - p = grpc_iomgr_create_endpoint_pair("test", nullptr); - grpc_endpoint_destroy(&exec_ctx, p.client); - grpc_endpoint_destroy(&exec_ctx, p.server); - grpc_exec_ctx_flush(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + + /* set max # of file descriptors to a low value, and + verify we can create and destroy many more than this number + of descriptors */ + rlim.rlim_cur = rlim.rlim_max = 10; + GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("fd_conservation_posix_test"); + + for (i = 0; i < 100; i++) { + p = grpc_iomgr_create_endpoint_pair("test", NULL); + grpc_endpoint_destroy(p.client); + grpc_endpoint_destroy(p.server); + grpc_core::ExecCtx::Get()->Flush(); + } + + grpc_resource_quota_unref(resource_quota); } - grpc_resource_quota_unref(resource_quota); - - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index a03d841ecd..cf75517538 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -111,20 +111,19 @@ typedef struct { /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ -static void session_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ +static void session_shutdown_cb(void* arg, /*session */ bool success) { session* se = static_cast(arg); server* sv = se->sv; - grpc_fd_orphan(exec_ctx, se->em_fd, nullptr, nullptr, - false /* already_closed */, "a"); + grpc_fd_orphan(se->em_fd, nullptr, nullptr, false /* already_closed */, "a"); gpr_free(se); /* Start to shutdown listen fd. */ - grpc_fd_shutdown(exec_ctx, sv->em_fd, + grpc_fd_shutdown(sv->em_fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("session_shutdown_cb")); } /* Called when data become readable in a session. */ -static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ +static void session_read_cb(void* arg, /*session */ grpc_error* error) { session* se = static_cast(arg); int fd = grpc_fd_wrapped_fd(se->em_fd); @@ -133,7 +132,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ ssize_t read_total = 0; if (error != GRPC_ERROR_NONE) { - session_shutdown_cb(exec_ctx, arg, 1); + session_shutdown_cb(arg, 1); return; } @@ -148,7 +147,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ It is possible to read nothing due to spurious edge event or data has been drained, In such a case, read() returns -1 and set errno to EAGAIN. */ if (read_once == 0) { - session_shutdown_cb(exec_ctx, arg, 1); + session_shutdown_cb(arg, 1); } else if (read_once == -1) { if (errno == EAGAIN) { /* An edge triggered event is cached in the kernel until next poll. @@ -159,7 +158,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ TODO(chenw): in multi-threaded version, callback and polling can be run in different threads. polling may catch a persist read edge event before notify_on_read is called. */ - grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); } else { gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); abort(); @@ -169,22 +168,20 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ /* Called when the listen FD can be safely shutdown. Close listen FD and signal that server can be shutdown. */ -static void listen_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg /*server */, - int success) { +static void listen_shutdown_cb(void* arg /*server */, int success) { server* sv = static_cast(arg); - grpc_fd_orphan(exec_ctx, sv->em_fd, nullptr, nullptr, - false /* already_closed */, "b"); + grpc_fd_orphan(sv->em_fd, nullptr, nullptr, false /* already_closed */, "b"); gpr_mu_lock(g_mu); sv->done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } /* Called when a new TCP connection request arrives in the listening port. */ -static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ +static void listen_cb(void* arg, /*=sv_arg*/ grpc_error* error) { server* sv = static_cast(arg); int fd; @@ -195,7 +192,7 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ grpc_fd* listen_em_fd = sv->em_fd; if (error != GRPC_ERROR_NONE) { - listen_shutdown_cb(exec_ctx, arg, 1); + listen_shutdown_cb(arg, 1); return; } @@ -207,12 +204,12 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ se = static_cast(gpr_malloc(sizeof(*se))); se->sv = sv; se->em_fd = grpc_fd_create(fd, "listener"); - grpc_pollset_add_fd(exec_ctx, g_pollset, se->em_fd); + grpc_pollset_add_fd(g_pollset, se->em_fd); GRPC_CLOSURE_INIT(&se->session_read_closure, session_read_cb, se, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); - grpc_fd_notify_on_read(exec_ctx, listen_em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(listen_em_fd, &sv->listen_closure); } /* Max number of connections pending to be accepted by listen(). */ @@ -222,7 +219,7 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ listen_cb() is registered to be interested in reading from listen_fd. When connection request arrives, listen_cb() is called to accept the connection request. */ -static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { +static int server_start(server* sv) { int port = 0; int fd; struct sockaddr_in sin; @@ -236,11 +233,11 @@ static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); sv->em_fd = grpc_fd_create(fd, "server"); - grpc_pollset_add_fd(exec_ctx, g_pollset, sv->em_fd); + grpc_pollset_add_fd(g_pollset, sv->em_fd); /* Register to be interested in reading from listen_fd. */ GRPC_CLOSURE_INIT(&sv->listen_closure, listen_cb, sv, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, sv->em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(sv->em_fd, &sv->listen_closure); return port; } @@ -249,13 +246,13 @@ static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -289,18 +286,16 @@ static void client_init(client* cl) { } /* Called when a client upload session is ready to shutdown. */ -static void client_session_shutdown_cb(grpc_exec_ctx* exec_ctx, - void* arg /*client */, int success) { +static void client_session_shutdown_cb(void* arg /*client */, int success) { client* cl = static_cast(arg); - grpc_fd_orphan(exec_ctx, cl->em_fd, nullptr, nullptr, - false /* already_closed */, "c"); + grpc_fd_orphan(cl->em_fd, nullptr, nullptr, false /* already_closed */, "c"); cl->done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); } /* Write as much as possible, then register notify_on_write. */ -static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ +static void client_session_write(void* arg, /*client */ grpc_error* error) { client* cl = static_cast(arg); int fd = grpc_fd_wrapped_fd(cl->em_fd); @@ -308,7 +303,7 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ if (error != GRPC_ERROR_NONE) { gpr_mu_lock(g_mu); - client_session_shutdown_cb(exec_ctx, arg, 1); + client_session_shutdown_cb(arg, 1); gpr_mu_unlock(g_mu); return; } @@ -323,10 +318,10 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { GRPC_CLOSURE_INIT(&cl->write_closure, client_session_write, cl, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_write(exec_ctx, cl->em_fd, &cl->write_closure); + grpc_fd_notify_on_write(cl->em_fd, &cl->write_closure); cl->client_write_cnt++; } else { - client_session_shutdown_cb(exec_ctx, arg, 1); + client_session_shutdown_cb(arg, 1); } gpr_mu_unlock(g_mu); } else { @@ -336,7 +331,7 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ } /* Start a client to send a stream of bytes. */ -static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { +static void client_start(client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); @@ -357,9 +352,9 @@ static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { } cl->em_fd = grpc_fd_create(fd, "client"); - grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd); + grpc_pollset_add_fd(g_pollset, cl->em_fd); - client_session_write(exec_ctx, cl, GRPC_ERROR_NONE); + client_session_write(cl, GRPC_ERROR_NONE); } /* Wait for the signal to shutdown a client. */ @@ -367,12 +362,12 @@ static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker* worker = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -385,13 +380,13 @@ static void test_grpc_fd(void) { server sv; client cl; int port; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_init(&sv); - port = server_start(&exec_ctx, &sv); + port = server_start(&sv); client_init(&cl); - client_start(&exec_ctx, &cl, port); - grpc_exec_ctx_finish(&exec_ctx); + client_start(&cl, port); + client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); @@ -406,27 +401,25 @@ void init_change_data(fd_change_data* fdc) { fdc->cb_that_ran = nullptr; } void destroy_change_data(fd_change_data* fdc) {} -static void first_read_callback(grpc_exec_ctx* exec_ctx, - void* arg /* fd_change_data */, +static void first_read_callback(void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void second_read_callback(grpc_exec_ctx* exec_ctx, - void* arg /* fd_change_data */, +static void second_read_callback(void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -443,7 +436,7 @@ static void test_grpc_fd_change(void) { ssize_t result; grpc_closure first_closure; grpc_closure second_closure; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&first_closure, first_read_callback, &a, grpc_schedule_on_exec_ctx); @@ -460,10 +453,10 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change"); - grpc_pollset_add_fd(&exec_ctx, g_pollset, em_fd); + grpc_pollset_add_fd(g_pollset, em_fd); /* Register the first callback, then make its FD readable */ - grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure); + grpc_fd_notify_on_read(em_fd, &first_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -473,10 +466,10 @@ static void test_grpc_fd_change(void) { while (a.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); @@ -488,7 +481,7 @@ static void test_grpc_fd_change(void) { /* Now register a second callback with distinct change data, and do the same thing again. */ - grpc_fd_notify_on_read(&exec_ctx, em_fd, &second_closure); + grpc_fd_notify_on_read(em_fd, &second_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -497,44 +490,43 @@ static void test_grpc_fd_change(void) { while (b.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); gpr_mu_unlock(g_mu); - grpc_fd_orphan(&exec_ctx, em_fd, nullptr, nullptr, false /* already_closed */, - "d"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_fd_orphan(em_fd, nullptr, nullptr, false /* already_closed */, "d"); + destroy_change_data(&a); destroy_change_data(&b); close(sv[1]); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - test_grpc_fd(); - test_grpc_fd_change(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_flush(&exec_ctx); - gpr_free(g_pollset); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + test_grpc_fd(); + test_grpc_fd_change(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(g_pollset); + } grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/load_file_test.cc b/test/core/iomgr/load_file_test.cc index 9f360badcc..797d0ef1a4 100644 --- a/test/core/iomgr/load_file_test.cc +++ b/test/core/iomgr/load_file_test.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -152,9 +153,11 @@ static void test_load_big_file(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_load_empty_file(); test_load_failure(); test_load_small_file(); test_load_big_file(); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index 719eab91fe..f27079134b 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -47,11 +47,10 @@ void init_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { } } -void cleanup_test_pollset_sets(grpc_exec_ctx* exec_ctx, - test_pollset_set* pollset_sets, +void cleanup_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { for (int i = 0; i < num_pss; i++) { - grpc_pollset_set_destroy(exec_ctx, pollset_sets[i].pss); + grpc_pollset_set_destroy(pollset_sets[i].pss); pollset_sets[i].pss = nullptr; } } @@ -73,21 +72,19 @@ static void init_test_pollsets(test_pollset* pollsets, const int num_pollsets) { } } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } -static void cleanup_test_pollsets(grpc_exec_ctx* exec_ctx, - test_pollset* pollsets, +static void cleanup_test_pollsets(test_pollset* pollsets, const int num_pollsets) { grpc_closure destroyed; for (int i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); + grpc_pollset_shutdown(pollsets[i].ps, &destroyed); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].ps); pollsets[i].ps = nullptr; } @@ -105,45 +102,43 @@ typedef struct test_fd { grpc_closure on_readable; /* Closure to call when this fd is readable */ } test_fd; -void on_readable(grpc_exec_ctx* exec_ctx, void* tfd, grpc_error* error) { +void on_readable(void* tfd, grpc_error* error) { ((test_fd*)tfd)->is_on_readable_called = true; } -static void reset_test_fd(grpc_exec_ctx* exec_ctx, test_fd* tfd) { +static void reset_test_fd(test_fd* tfd) { tfd->is_on_readable_called = false; GRPC_CLOSURE_INIT(&tfd->on_readable, on_readable, tfd, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); + grpc_fd_notify_on_read(tfd->fd, &tfd->on_readable); } -static void init_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void init_test_fds(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), "test_fd"); - reset_test_fd(exec_ctx, &tfds[i]); + reset_test_fd(&tfds[i]); } } -static void cleanup_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void cleanup_test_fds(test_fd* tfds, const int num_fds) { int release_fd; for (int i = 0; i < num_fds; i++) { - grpc_fd_shutdown(exec_ctx, tfds[i].fd, + grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also * calls close() on the underlying fd. In our case, we are using * grpc_wakeup_fd and we would like to destroy it ourselves (by calling * grpc_wakeup_fd_destroy). To prevent grpc_fd from calling close() on the * underlying fd, call it with a non-NULL 'release_fd' parameter */ - grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, - false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(exec_ctx); + grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, + "test_fd_cleanup"); + grpc_core::ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); } @@ -155,8 +150,7 @@ static void make_test_fds_readable(test_fd* tfds, const int num_fds) { } } -static void verify_readable_and_reset(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void verify_readable_and_reset(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { /* Verify that the on_readable callback was called */ GPR_ASSERT(tfds[i].is_on_readable_called); @@ -164,7 +158,7 @@ static void verify_readable_and_reset(grpc_exec_ctx* exec_ctx, test_fd* tfds, /* Reset the tfd[i] structure */ GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_consume_wakeup(&tfds[i].wakeup_fd)); - reset_test_fd(exec_ctx, &tfds[i]); + reset_test_fd(&tfds[i]); } } @@ -205,7 +199,7 @@ static void pollset_set_test_basic() { * | * +---> FD9 (Added after PS2 is added to PSS0) */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -216,34 +210,33 @@ static void pollset_set_test_basic() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the pollset_set/pollset/fd tree (see diagram above) */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[2].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[3].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[4].fd); + grpc_pollset_add_fd(pollsets[0].ps, tfds[2].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[3].fd); + grpc_pollset_add_fd(pollsets[2].ps, tfds[4].fd); - grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); + grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); + grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[2].ps); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[6].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[7].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[8].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[9].fd); + grpc_pollset_add_fd(pollsets[0].ps, tfds[7].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); + grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); /* Test that if any FD in the above structure is readable, it is observable by * doing grpc_pollset_work on any pollset @@ -263,34 +256,32 @@ static void pollset_set_test_basic() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, deadline)); + grpc_pollset_work(pollsets[i].ps, &worker, deadline)); gpr_mu_unlock(pollsets[i].mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); } /* Test tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); - grpc_exec_ctx_flush(&exec_ctx); - - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); - - grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); - cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); + grpc_core::ExecCtx::Get()->Flush(); + + grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); + + grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(pollsets, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); } /* Same FD added multiple times to the pollset_set tree */ @@ -310,7 +301,7 @@ void pollset_set_test_dup_fds() { * | +--> FD2 * +---> FD1 */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -321,21 +312,20 @@ void pollset_set_test_dup_fds() { const int num_ps = 1; const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(&pollset, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[2].fd); + grpc_pollset_add_fd(pollset.ps, tfds[1].fd); + grpc_pollset_add_fd(pollset.ps, tfds[2].fd); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); + grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); /* Test. Make all FDs readable and make sure that can be observed by doing a * grpc_pollset_work on the pollset 'PS' */ @@ -345,27 +335,25 @@ void pollset_set_test_dup_fds() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollset.ps, &worker, deadline)); + grpc_pollset_work(pollset.ps, &worker, deadline)); gpr_mu_unlock(pollset.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, &pollset, num_ps); - cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(&pollset, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); } /* Pollset_set with an empty pollset */ @@ -383,7 +371,7 @@ void pollset_set_test_empty_pollset() { * | * +---> FD2 */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -394,17 +382,17 @@ void pollset_set_test_empty_pollset() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = 1; - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(&pollset_set, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[2].fd); + grpc_pollset_set_add_fd(pollset_set.pss, tfds[0].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[1].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[2].fd); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[1].ps); /* Test. Make all FDs readable and make sure that can be observed by doing * grpc_pollset_work on the empty pollset 'PS0' */ @@ -414,45 +402,44 @@ void pollset_set_test_empty_pollset() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, deadline)); + grpc_pollset_work(pollsets[0].ps, &worker, deadline)); gpr_mu_unlock(pollsets[0].mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); - cleanup_test_pollset_sets(&exec_ctx, &pollset_set, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); + grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(pollsets, num_ps); + cleanup_test_pollset_sets(&pollset_set, num_pss); } int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - const char* poll_strategy = grpc_get_poll_strategy_name(); - - if (poll_strategy != nullptr && - (strcmp(poll_strategy, "epollsig") == 0 || - strcmp(poll_strategy, "epoll-threadpool") == 0)) { - pollset_set_test_basic(); - pollset_set_test_dup_fds(); - pollset_set_test_empty_pollset(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epoll' " - "strategy. and the current strategy is: '%s'", - poll_strategy); + { + grpc_core::ExecCtx exec_ctx; + const char* poll_strategy = grpc_get_poll_strategy_name(); + + if (poll_strategy != nullptr && + (strcmp(poll_strategy, "epollsig") == 0 || + strcmp(poll_strategy, "epoll-threadpool") == 0)) { + pollset_set_test_basic(); + pollset_set_test_dup_fds(); + pollset_set_test_empty_pollset(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epoll' " + "strategy. and the current strategy is: '%s'", + poll_strategy); + } } - - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 836de423bd..e36315333c 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -46,29 +46,29 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} -void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_init(args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); args->addrs = nullptr; } -void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_finish(args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); - grpc_pollset_set_destroy(exec_ctx, args->pollset_set); + grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_destroy(args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(args->pollset, &do_nothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(exec_ctx); - grpc_pollset_destroy(exec_ctx, args->pollset); + grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -79,26 +79,24 @@ static grpc_millis n_sec_deadline(int seconds) { static void actually_poll(void* argsp) { args_struct* args = static_cast(argsp); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = n_sec_deadline(10); while (true) { + grpc_core::ExecCtx exec_ctx; bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(&exec_ctx); } static void poll_pollset_until_request_done(args_struct* args) { @@ -107,8 +105,7 @@ static void poll_pollset_until_request_done(args_struct* args) { gpr_thd_new(&id, "grpc_poll_pollset", actually_poll, args, nullptr); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, - grpc_error* err) { +static void must_succeed(void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); @@ -116,29 +113,28 @@ static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, gpr_atm_rel_store(&args->done_atm, 1); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { +static void must_fail(void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); } static void test_unix_socket(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); poll_pollset_until_request_done(&args); grpc_resolve_address( - &exec_ctx, "unix:/path/name", nullptr, args.pollset_set, + "unix:/path/name", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_unix_socket_path_name_too_long(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); const char prefix[] = "unix:/path/name"; size_t path_name_length = GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) + 6; @@ -150,22 +146,23 @@ static void test_unix_socket_path_name_too_long(void) { poll_pollset_until_request_done(&args); grpc_resolve_address( - &exec_ctx, path_name, nullptr, args.pollset_set, + path_name, nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); gpr_free(path_name); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_unix_socket(); - test_unix_socket_path_name_too_long(); - grpc_executor_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + test_unix_socket(); + test_unix_socket_path_name_too_long(); + } + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index 1c5aa38a95..a0dc484f3e 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -39,32 +39,32 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} -void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_init(args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); args->addrs = nullptr; gpr_atm_rel_store(&args->done_atm, 0); } -void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_finish(args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); - grpc_pollset_set_destroy(exec_ctx, args->pollset_set); + grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_destroy(args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); gpr_mu_lock(args->mu); - grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(args->pollset, &do_nothing_cb); gpr_mu_unlock(args->mu); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(exec_ctx); - grpc_pollset_destroy(exec_ctx, args->pollset); + grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -74,119 +74,109 @@ static grpc_millis n_sec_deadline(int seconds) { } static void poll_pollset_until_request_done(args_struct* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(&exec_ctx); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, - grpc_error* err) { +static void must_succeed(void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); GPR_ASSERT(args->addrs->naddrs > 0); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { +static void must_fail(void* argsp, grpc_error* err) { args_struct* args = static_cast(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } static void test_localhost(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost:1", nullptr, args.pollset_set, + "localhost:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", "1", args.pollset_set, + "localhost", "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_non_numeric_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", "https", args.pollset_set, + "localhost", "https", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_missing_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", nullptr, args.pollset_set, + "localhost", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_ipv6_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "[2001:db8::1]:1", nullptr, args.pollset_set, + "[2001:db8::1]:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_ipv6_without_port(void) { @@ -197,17 +187,16 @@ static void test_ipv6_without_port(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], "80", args.pollset_set, + kCases[i], "80", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } @@ -218,17 +207,16 @@ static void test_invalid_ip_addresses(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], nullptr, args.pollset_set, + kCases[i], nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } @@ -238,34 +226,35 @@ static void test_unparseable_hostports(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], "1", args.pollset_set, + kCases[i], "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_localhost(); - test_default_port(); - test_non_numeric_default_port(); - test_missing_default_port(); - test_ipv6_with_port(); - test_ipv6_without_port(); - test_invalid_ip_addresses(); - test_unparseable_hostports(); - grpc_executor_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + test_localhost(); + test_default_port(); + test_non_numeric_default_port(); + test_missing_default_port(); + test_ipv6_with_port(); + test_ipv6_without_port(); + test_invalid_ip_addresses(); + test_unparseable_hostports(); + grpc_executor_shutdown(); + } + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index 6851702e67..ae26f72701 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -27,7 +27,7 @@ gpr_mu g_mu; gpr_cv g_cv; -static void inc_int_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void inc_int_cb(void* a, grpc_error* error) { gpr_mu_lock(&g_mu); ++*(int*)a; gpr_cv_signal(&g_cv); @@ -43,7 +43,7 @@ static void assert_counter_becomes(int* ctr, int value) { gpr_mu_unlock(&g_mu); } -static void set_event_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void set_event_cb(void* a, grpc_error* error) { gpr_event_set((gpr_event*)a, (void*)1); } grpc_closure* set_event(gpr_event* ev) { @@ -56,13 +56,12 @@ typedef struct { grpc_closure* then; } reclaimer_args; -static void reclaimer_cb(grpc_exec_ctx* exec_ctx, void* args, - grpc_error* error) { +static void reclaimer_cb(void* args, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); reclaimer_args* a = static_cast(args); - grpc_resource_user_free(exec_ctx, a->resource_user, a->size); - grpc_resource_user_finish_reclamation(exec_ctx, a->resource_user); - GRPC_CLOSURE_RUN(exec_ctx, a->then, GRPC_ERROR_NONE); + grpc_resource_user_free(a->resource_user, a->size); + grpc_resource_user_finish_reclamation(a->resource_user); + GRPC_CLOSURE_RUN(a->then, GRPC_ERROR_NONE); gpr_free(a); } @@ -75,10 +74,9 @@ grpc_closure* make_reclaimer(grpc_resource_user* resource_user, size_t size, return GRPC_CLOSURE_CREATE(reclaimer_cb, a, grpc_schedule_on_exec_ctx); } -static void unused_reclaimer_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void unused_reclaimer_cb(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_RUN(exec_ctx, static_cast(arg), GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(static_cast(arg), GRPC_ERROR_NONE); } grpc_closure* make_unused_reclaimer(grpc_closure* then) { return GRPC_CLOSURE_CREATE(unused_reclaimer_cb, then, @@ -86,9 +84,8 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { } static void destroy_user(grpc_resource_user* usr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } static void test_no_op(void) { @@ -120,14 +117,12 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -140,10 +135,9 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -158,16 +152,15 @@ static void test_simple_async_alloc(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -182,9 +175,9 @@ static void test_async_alloc_blocked_by_size(void) { gpr_event ev; gpr_event_init(&ev); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } @@ -193,9 +186,8 @@ static void test_async_alloc_blocked_by_size(void) { nullptr); ; { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -210,32 +202,30 @@ static void test_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr1, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr1, 1024); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -251,33 +241,32 @@ static void test_scavenge_blocked(void) { gpr_event ev; { gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr1, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr1, 1024); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -293,9 +282,9 @@ static void test_blocked_until_scheduled_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -303,18 +292,16 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -322,9 +309,8 @@ static void test_blocked_until_scheduled_reclaim(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -340,9 +326,9 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -350,18 +336,16 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr1, false, - make_reclaimer(usr1, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -369,9 +353,8 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -387,9 +370,9 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -397,18 +380,16 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -416,9 +397,8 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -435,13 +415,12 @@ static void test_unused_reclaim_is_cancelled(void) { gpr_event destructive_done; gpr_event_init(&destructive_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, make_unused_reclaimer(set_event(&benign_done))); + usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_unused_reclaimer(set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -470,22 +449,20 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&benign_done))); + usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_unused_reclaimer(set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -496,9 +473,9 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -508,9 +485,8 @@ static void test_benign_reclaim_is_preferred(void) { nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -533,22 +509,20 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 512, set_event(&benign_done))); + usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_reclaimer(usr, 512, set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_reclaimer(usr, 512, set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -559,9 +533,9 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -571,9 +545,8 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -591,20 +564,17 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_quota_unref(q); - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_resource_user_unref(usr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } } @@ -624,11 +594,10 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event reclaimer_cancelled; gpr_event_init(&reclaimer_cancelled); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_unused_reclaimer(set_event(&reclaimer_cancelled))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -636,27 +605,27 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( - 5)) != nullptr); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(gpr_event_wait(&allocated, + grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_seconds_to_deadline(5)) != nullptr); @@ -674,9 +643,9 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != nullptr); } @@ -684,11 +653,10 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event reclaimer_done; gpr_event_init(&reclaimer_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&reclaimer_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -696,20 +664,19 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( - 5)) != nullptr); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(gpr_event_wait(&allocated, + grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); } } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -732,16 +699,15 @@ static void test_one_slice(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -765,23 +731,21 @@ static void test_one_slice_deleted_late(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } } @@ -809,9 +773,9 @@ static void test_negative_rq_free_pool(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } @@ -822,16 +786,14 @@ static void test_negative_rq_free_pool(void) { GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 9fb1a2d770..40a050ed9f 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -53,26 +53,24 @@ static grpc_millis test_deadline(void) { static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(&exec_ctx, g_pollset, nullptr))); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + gpr_mu_unlock(g_mu); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting != nullptr); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown( - exec_ctx, g_connecting, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); - grpc_endpoint_destroy(exec_ctx, g_connecting); + grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "must_succeed called")); + grpc_endpoint_destroy(g_connecting); g_connecting = nullptr; finish_connection(); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == nullptr); GPR_ASSERT(error != GRPC_ERROR_NONE); finish_connection(); @@ -85,7 +83,7 @@ void test_succeeds(void) { int r; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -108,8 +106,8 @@ void test_succeeds(void) { GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, - nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); /* await the connection */ do { @@ -125,17 +123,15 @@ void test_succeeds(void) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -143,7 +139,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -157,8 +153,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, - nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -166,7 +162,7 @@ void test_fails(void) { while (g_connections_complete == connections_complete_before) { grpc_pollset_worker* worker = nullptr; grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { + switch (grpc_timer_check(&polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -174,42 +170,43 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - polling_deadline))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset_set = grpc_pollset_set_create(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset); - grpc_exec_ctx_finish(&exec_ctx); - test_succeeds(); - gpr_log(GPR_ERROR, "End of first test"); - test_fails(); - grpc_pollset_set_destroy(&exec_ctx, g_pollset_set); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + g_pollset_set = grpc_pollset_set_create(); + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_pollset_set_add_pollset(g_pollset_set, g_pollset); + + test_succeeds(); + gpr_log(GPR_ERROR, "End of first test"); + test_fails(); + grpc_pollset_set_destroy(g_pollset_set); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index 101d7bf6b5..0c6250ed7f 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -46,30 +46,28 @@ static grpc_millis test_deadline(void) { return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); } -static void finish_connection(grpc_exec_ctx* exec_ctx) { +static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, NULL))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); gpr_mu_unlock(g_mu); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting != NULL); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown( - exec_ctx, g_connecting, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); - grpc_endpoint_destroy(exec_ctx, g_connecting); + grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "must_succeed called")); + grpc_endpoint_destroy(g_connecting); g_connecting = NULL; - finish_connection(exec_ctx); + finish_connection(); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == NULL); GPR_ASSERT(error != GRPC_ERROR_NONE); - finish_connection(exec_ctx); + finish_connection(); } static void close_cb(uv_handle_t* handle) { gpr_free(handle); } @@ -89,7 +87,7 @@ void test_succeeds(void) { uv_tcp_t* svr_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -110,8 +108,8 @@ void test_succeeds(void) { GPR_ASSERT(uv_tcp_getsockname(svr_handle, (struct sockaddr*)addr, (int*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, + GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -119,11 +117,11 @@ void test_succeeds(void) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -131,8 +129,6 @@ void test_succeeds(void) { uv_close((uv_handle_t*)svr_handle, close_cb); gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -140,7 +136,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -154,8 +150,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, + GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -164,7 +160,7 @@ void test_fails(void) { grpc_pollset_worker* worker = NULL; gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { + switch (grpc_timer_check(&polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -172,39 +168,37 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - polling_deadline))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); - grpc_exec_ctx_finish(&exec_ctx); + test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index 7986dc2b19..f4acba8302 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -131,8 +131,7 @@ static size_t count_slices(grpc_slice* slices, size_t nslices, return num_bytes; } -static void read_cb(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void read_cb(void* user_data, grpc_error* error) { struct read_socket_state* state = (struct read_socket_state*)user_data; size_t read_bytes; int current_data; @@ -147,11 +146,11 @@ static void read_cb(grpc_exec_ctx* exec_ctx, void* user_data, gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } else { - grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); + grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb); gpr_mu_unlock(g_mu); } } @@ -164,7 +163,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, num_bytes, slice_size); @@ -175,9 +174,8 @@ static void read_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, - "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -188,24 +186,22 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(ep); } /* Write to a socket until it fills up, then read from it using the grpc_tcp @@ -217,7 +213,7 @@ static void large_read_test(size_t slice_size) { ssize_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -228,9 +224,8 @@ static void large_read_test(size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "large_read_test"), - &args, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -241,24 +236,22 @@ static void large_read_test(size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(ep); } struct write_socket_state { @@ -289,16 +282,15 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, return slices; } -static void write_done(grpc_exec_ctx* exec_ctx, - void* user_data /* write_socket_state */, +static void write_done(void* user_data /* write_socket_state */, grpc_error* error) { struct write_socket_state* state = (struct write_socket_state*)user_data; gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); state->write_done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -309,7 +301,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { int flags; int current = 0; int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -319,11 +311,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { gpr_mu_lock(g_mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(10))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + do { bytes_read = read(fd, buf, bytes_left > read_size ? read_size : bytes_left); @@ -356,7 +348,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_closure write_done_closure; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, @@ -368,9 +360,8 @@ static void write_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "write_test"), &args, - "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); state.ep = ep; state.write_done = 0; @@ -382,7 +373,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { GRPC_CLOSURE_INIT(&write_done_closure, write_done, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); + grpc_endpoint_write(ep, &outgoing, &write_done_closure); drain_socket_blocking(sv[0], num_bytes, num_bytes); gpr_mu_lock(g_mu); for (;;) { @@ -391,25 +382,23 @@ static void write_test(size_t num_bytes, size_t slice_size) { break; } GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); - grpc_endpoint_destroy(&exec_ctx, ep); + grpc_slice_buffer_destroy_internal(&outgoing); + grpc_endpoint_destroy(ep); gpr_free(slices); - grpc_exec_ctx_finish(&exec_ctx); } -void on_fd_released(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* errors) { +void on_fd_released(void* arg, grpc_error* errors) { int* done = (int*)arg; *done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); } /* Do a read_test, then release fd and try to read/write again. Verify that @@ -422,7 +411,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure fd_released_cb; int fd_released_done = 0; GRPC_CLOSURE_INIT(&fd_released_cb, &on_fd_released, &fd_released_done, @@ -439,10 +428,9 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, - "test"); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -453,38 +441,35 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR, state.read_bytes, state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb); - grpc_exec_ctx_flush(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_tcp_destroy_and_release_fd(ep, &fd, &fd_released_cb); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done); } gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); - grpc_exec_ctx_finish(&exec_ctx); written_bytes = fill_socket_partial(sv[0], num_bytes); drain_socket_blocking(fd, written_bytes, written_bytes); @@ -522,7 +507,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( size_t slice_size) { int sv[2]; grpc_endpoint_test_fixture f; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; create_sockets(sv); grpc_resource_quota* resource_quota = @@ -532,15 +517,13 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - f.client_ep = grpc_tcp_create( - &exec_ctx, grpc_fd_create(sv[0], "fixture:client"), &args, "test"); - f.server_ep = grpc_tcp_create( - &exec_ctx, grpc_fd_create(sv[1], "fixture:server"), &args, "test"); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); - - grpc_exec_ctx_finish(&exec_ctx); + f.client_ep = + grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), &args, "test"); + f.server_ep = + grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), &args, "test"); + grpc_resource_quota_unref_internal(resource_quota); + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); return f; } @@ -549,24 +532,26 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - run_tests(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + run_tests(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + + grpc_core::ExecCtx::Get()->Flush(); + } grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 48d8d425a5..3c9ca2109e 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -110,8 +110,7 @@ static void on_connect_result_set(on_connect_result* result, result->server, acceptor->port_index, acceptor->fd_index); } -static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void server_weak_ref_shutdown(void* arg, grpc_error* error) { server_weak_ref* weak_ref = static_cast(arg); weak_ref->server = nullptr; } @@ -145,12 +144,11 @@ static void test_addr_init_str(test_addr* addr) { } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, - grpc_pollset* pollset, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -159,38 +157,33 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); + grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_unref(s); } static void test_no_op_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -201,17 +194,15 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void test_no_op_with_port_and_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port = -1; @@ -222,13 +213,12 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } -static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, +static grpc_error* tcp_connect(const test_addr* remote, on_connect_result* result) { grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); @@ -254,17 +244,17 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, } gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && - deadline > grpc_exec_ctx_now(exec_ctx)) { + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = nullptr; grpc_error* err; - if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)) != + if ((err = grpc_pollset_work(g_pollset, &worker, deadline)) != GRPC_ERROR_NONE) { gpr_mu_unlock(g_mu); close(clifd); return err; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(exec_ctx); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -279,7 +269,7 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, gpr_mu_unlock(g_mu); gpr_log(GPR_INFO, "Result (%d, %d) fd %d", result->port_index, result->fd_index, result->server_fd); - grpc_tcp_server_unref(exec_ctx, result->server); + grpc_tcp_server_unref(result->server); return GRPC_ERROR_NONE; } @@ -292,7 +282,7 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, static void test_connect(size_t num_connects, const grpc_channel_args* channel_args, test_addrs* dst_addrs, bool test_dst_addrs) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = @@ -307,7 +297,7 @@ static void test_connect(size_t num_connects, grpc_tcp_server* s; const unsigned num_ports = 2; GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, channel_args, &s)); + grpc_tcp_server_create(nullptr, channel_args, &s)); unsigned port_num; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -352,7 +342,7 @@ static void test_connect(size_t num_connects, svr1_fd_count = grpc_tcp_server_port_fd_count(s, 1); GPR_ASSERT(svr1_fd_count >= 1); - grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, nullptr); + grpc_tcp_server_start(s, &g_pollset, 1, on_connect, nullptr); if (dst_addrs != nullptr) { int ports[] = {svr_port, svr1_port}; @@ -372,7 +362,7 @@ static void test_connect(size_t num_connects, test_addr_init_str(&dst); ++num_tested; on_connect_result_init(&result); - if ((err = tcp_connect(&exec_ctx, &dst, &result)) == GRPC_ERROR_NONE && + if ((err = tcp_connect(&dst, &result)) == GRPC_ERROR_NONE && result.server_fd >= 0 && result.server == s) { continue; } @@ -403,8 +393,8 @@ static void test_connect(size_t num_connects, for (connect_num = 0; connect_num < num_connects; ++connect_num) { on_connect_result result; on_connect_result_init(&result); - GPR_ASSERT(GRPC_LOG_IF_ERROR("tcp_connect", - tcp_connect(&exec_ctx, &dst, &result))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("tcp_connect", tcp_connect(&dst, &result))); GPR_ASSERT(result.server_fd == fd); GPR_ASSERT(result.port_index == port_num); GPR_ASSERT(result.fd_index == fd_num); @@ -420,21 +410,19 @@ static void test_connect(size_t num_connects, GPR_ASSERT(weak_ref.server != nullptr); GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 0) >= 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == nullptr); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_arg chan_args[1]; chan_args[0].type = GRPC_ARG_INTEGER; chan_args[0].key = const_cast(GRPC_ARG_EXPAND_WILDCARD_ADDRS); @@ -447,58 +435,61 @@ int main(int argc, char** argv) { static_cast(gpr_zalloc(sizeof(*dst_addrs))); grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_start(); + + if (getifaddrs(&ifa) != 0 || ifa == nullptr) { + gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); + return EXIT_FAILURE; + } + dst_addrs->naddrs = 0; + for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; + ifa_it = ifa_it->ifa_next) { + if (ifa_it->ifa_addr == nullptr) { + continue; + } else if (ifa_it->ifa_addr->sa_family == AF_INET) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = + sizeof(struct sockaddr_in); + } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = + sizeof(struct sockaddr_in6); + } else { + continue; + } + memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, + dst_addrs->addrs[dst_addrs->naddrs].addr.len); + GPR_ASSERT( + grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); + test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); + ++dst_addrs->naddrs; + } + freeifaddrs(ifa); + ifa = nullptr; - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_start(); + /* Connect to same addresses as listeners. */ + test_connect(1, nullptr, nullptr, false); + test_connect(10, nullptr, nullptr, false); - if (getifaddrs(&ifa) != 0 || ifa == nullptr) { - gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); - return EXIT_FAILURE; - } - dst_addrs->naddrs = 0; - for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; - ifa_it = ifa_it->ifa_next) { - if (ifa_it->ifa_addr == nullptr) { - continue; - } else if (ifa_it->ifa_addr->sa_family == AF_INET) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = sizeof(struct sockaddr_in); - } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = - sizeof(struct sockaddr_in6); - } else { - continue; - } - memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, - dst_addrs->addrs[dst_addrs->naddrs].addr.len); - GPR_ASSERT( - grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); - test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); - ++dst_addrs->naddrs; + /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a + "::" listener. */ + test_connect(1, nullptr, dst_addrs, true); + + /* Test connect(2) with dst_addrs. */ + test_connect(1, &channel_args, dst_addrs, false); + /* Test connect(2) with dst_addrs. */ + test_connect(10, &channel_args, dst_addrs, false); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); } - freeifaddrs(ifa); - ifa = nullptr; - - /* Connect to same addresses as listeners. */ - test_connect(1, nullptr, nullptr, false); - test_connect(10, nullptr, nullptr, false); - - /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a - "::" listener. */ - test_connect(1, nullptr, dst_addrs, true); - - /* Test connect(2) with dst_addrs. */ - test_connect(1, &channel_args, dst_addrs, false); - /* Test connect(2) with dst_addrs. */ - test_connect(10, &channel_args, dst_addrs, false); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(dst_addrs); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index dd047a0498..35d62b51b7 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -74,8 +74,7 @@ static void on_connect_result_set(on_connect_result* result, result->fd_index = acceptor->fd_index; } -static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void server_weak_ref_shutdown(void* arg, grpc_error* error) { server_weak_ref* weak_ref = static_cast(arg); weak_ref->server = NULL; } @@ -97,12 +96,11 @@ static void server_weak_ref_set(server_weak_ref* weak_ref, weak_ref->server = server; } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, - grpc_pollset* pollset, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -111,38 +109,33 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, NULL))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); + grpc_tcp_server_unref(s); } static void test_no_op_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -153,17 +146,15 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void test_no_op_with_port_and_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port; @@ -174,10 +165,9 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); + grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void connect_cb(uv_connect_t* req, int status) { @@ -187,8 +177,8 @@ static void connect_cb(uv_connect_t* req, int status) { static void close_cb(uv_handle_t* handle) { gpr_free(handle); } -static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, - socklen_t remote_len, on_connect_result* result) { +static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, + on_connect_result* result) { gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10); uv_tcp_t* client_handle = static_cast(gpr_malloc(sizeof(uv_tcp_t))); @@ -208,10 +198,10 @@ static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up(deadline)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(exec_ctx); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -224,7 +214,7 @@ static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, /* Tests a tcp server with multiple ports. */ static void test_connect(unsigned n) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -233,8 +223,7 @@ static void test_connect(unsigned n) { int svr_port; int svr1_port; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); unsigned i; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -257,48 +246,45 @@ static void test_connect(unsigned n) { GRPC_ERROR_NONE && svr_port == svr1_port); - grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, NULL); + grpc_tcp_server_start(s, &g_pollset, 1, on_connect, NULL); GPR_ASSERT(uv_ip6_addr("::", svr_port, (struct sockaddr_in6*)addr1) == 0); for (i = 0; i < n; i++) { on_connect_result result; on_connect_result_init(&result); - tcp_connect(&exec_ctx, (struct sockaddr*)addr, (socklen_t)resolved_addr.len, - &result); + tcp_connect((struct sockaddr*)addr, (socklen_t)resolved_addr.len, &result); GPR_ASSERT(result.port_index == 0); GPR_ASSERT(result.server == s); if (weak_ref.server == NULL) { server_weak_ref_set(&weak_ref, result.server); } - grpc_tcp_server_unref(&exec_ctx, result.server); + grpc_tcp_server_unref(result.server); on_connect_result_init(&result); - tcp_connect(&exec_ctx, (struct sockaddr*)addr1, - (socklen_t)resolved_addr1.len, &result); + tcp_connect((struct sockaddr*)addr1, (socklen_t)resolved_addr1.len, + &result); GPR_ASSERT(result.port_index == 1); GPR_ASSERT(result.server == s); - grpc_tcp_server_unref(&exec_ctx, result.server); + grpc_tcp_server_unref(result.server); } /* Weak ref to server valid until final unref. */ GPR_ASSERT(weak_ref.server != NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); @@ -313,8 +299,8 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index d74ea4fc96..deb8c4d87e 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -25,6 +25,7 @@ #include +#include #include #include "src/core/lib/debug/trace.h" #include "test/core/util/test_config.h" @@ -37,127 +38,125 @@ extern grpc_core::TraceFlag grpc_timer_check_trace; static int cb_called[MAX_CB][2]; -static void cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void cb(void* arg, grpc_error* error) { cb_called[(intptr_t)arg][error == GRPC_ERROR_NONE]++; } static void add_test(void) { int i; grpc_timer timers[20]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "add_test"); - grpc_timer_list_init(&exec_ctx); + grpc_timer_list_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); - grpc_millis start = grpc_exec_ctx_now(&exec_ctx); + grpc_millis start = grpc_core::ExecCtx::Get()->Now(); /* 10 ms timers. will expire in the current epoch */ for (i = 0; i < 10; i++) { grpc_timer_init( - &exec_ctx, &timers[i], start + 10, + &timers[i], start + 10, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* 1010 ms timers. will expire in the next epoch */ for (i = 10; i < 20; i++) { grpc_timer_init( - &exec_ctx, &timers[i], start + 1010, + &timers[i], start + 1010, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* collect timers. Only the first batch should be ready. */ - exec_ctx.now = start + 500; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 500); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx.now = start + 600; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == - GRPC_TIMERS_CHECKED_AND_EMPTY); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 600); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the timers */ - exec_ctx.now = start + 1500; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1500); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx.now = start + 1600; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == - GRPC_TIMERS_CHECKED_AND_EMPTY); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1600); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - grpc_timer_list_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_list_shutdown(); } /* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "destruction_test"); - exec_ctx.now_is_valid = true; - exec_ctx.now = 0; - grpc_timer_list_init(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); + grpc_timer_list_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( - &exec_ctx, &timers[0], 100, + &timers[0], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)0, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[1], 3, + &timers[1], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)1, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[2], 100, + &timers[2], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)2, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[3], 3, + &timers[3], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)3, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[4], 1, + &timers[4], 1, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)4, grpc_schedule_on_exec_ctx)); - exec_ctx.now = 2; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(2); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[4][1]); - grpc_timer_cancel(&exec_ctx, &timers[0]); - grpc_timer_cancel(&exec_ctx, &timers[3]); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_cancel(&timers[0]); + grpc_timer_cancel(&timers[3]); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); - grpc_timer_list_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_list_shutdown(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_core::ExecCtx::GlobalInit(); gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); add_test(); destruction_test(); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 6e17be9cd6..0deb534abd 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -50,7 +50,7 @@ static int g_number_of_writes = 0; static int g_number_of_bytes_read = 0; static int g_number_of_orphan_calls = 0; -static bool on_read(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data) { +static bool on_read(grpc_fd* emfd, void* user_data) { char read_buffer[512]; ssize_t byte_count; @@ -61,27 +61,27 @@ static bool on_read(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data) { g_number_of_reads++; g_number_of_bytes_read += (int)byte_count; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); return false; } -static void on_write(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data, +static void on_write(grpc_fd* emfd, void* user_data, grpc_closure* notify_on_write_closure) { gpr_mu_lock(g_mu); g_number_of_writes++; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void on_fd_orphaned(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, - grpc_closure* closure, void* user_data) { +static void on_fd_orphaned(grpc_fd* emfd, grpc_closure* closure, + void* user_data) { gpr_log(GPR_INFO, "gRPC FD about to be orphaned: %d", grpc_fd_wrapped_fd(emfd)); - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); g_number_of_orphan_calls++; } @@ -130,24 +130,22 @@ static test_socket_factory* test_socket_factory_create(void) { } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_start"); - grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_start(s, nullptr, 0, nullptr); + grpc_udp_server_destroy(s, nullptr); } static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -159,8 +157,7 @@ static void test_no_op_with_port(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); @@ -168,7 +165,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; @@ -178,7 +175,7 @@ static void test_no_op_with_port_and_socket_factory(void) { grpc_channel_args* channel_args = grpc_channel_args_copy_and_add(nullptr, &socket_factory_arg, 1); grpc_udp_server* s = grpc_udp_server_create(channel_args); - grpc_channel_args_destroy(&exec_ctx, channel_args); + grpc_channel_args_destroy(channel_args); LOG_TEST("test_no_op_with_port_and_socket_factory"); @@ -190,8 +187,8 @@ static void test_no_op_with_port_and_socket_factory(void) { GPR_ASSERT(socket_factory->number_of_socket_calls == 1); GPR_ASSERT(socket_factory->number_of_bind_calls == 1); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); + grpc_socket_factory_unref(&socket_factory->base); /* The server had a single FD, which should have been orphaned. */ @@ -200,7 +197,7 @@ static void test_no_op_with_port_and_socket_factory(void) { static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -212,10 +209,9 @@ static void test_no_op_with_port_and_start(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); + grpc_udp_server_start(s, nullptr, 0, nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ @@ -223,7 +219,7 @@ static void test_no_op_with_port_and_start(void) { } static void test_receive(int number_of_clients) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int clifd, svrfd; @@ -250,7 +246,7 @@ static void test_receive(int number_of_clients) { GPR_ASSERT(resolved_addr.len <= sizeof(struct sockaddr_storage)); pollsets[0] = g_pollset; - grpc_udp_server_start(&exec_ctx, s, pollsets, 1, nullptr); + grpc_udp_server_start(s, pollsets, 1, nullptr); gpr_mu_lock(g_mu); @@ -266,13 +262,12 @@ static void test_receive(int number_of_clients) { (socklen_t)resolved_addr.len) == 0); GPR_ASSERT(5 == write(clifd, "hello", 5)); while (g_number_of_bytes_read < (number_of_bytes_read_before + 5) && - deadline > grpc_exec_ctx_now(&exec_ctx)) { + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } close(clifd); @@ -281,40 +276,40 @@ static void test_receive(int number_of_clients) { gpr_mu_unlock(g_mu); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ GPR_ASSERT(g_number_of_orphan_calls == 1); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_socket_factory(); - test_no_op_with_port_and_start(); - test_receive(1); - test_receive(10); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); - gpr_free(g_pollset); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_socket_factory(); + test_no_op_with_port_and_start(); + test_receive(1); + test_receive(10); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(g_pollset); + } grpc_shutdown(); return 0; } diff --git a/test/core/nanopb/fuzzer_response.cc b/test/core/nanopb/fuzzer_response.cc index 7039c801cb..3a70dea5e9 100644 --- a/test/core/nanopb/fuzzer_response.cc +++ b/test/core/nanopb/fuzzer_response.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -29,6 +30,7 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_initial_response* response; @@ -36,5 +38,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_initial_response_destroy(response); } grpc_slice_unref(slice); + grpc_shutdown(); return 0; } diff --git a/test/core/nanopb/fuzzer_serverlist.cc b/test/core/nanopb/fuzzer_serverlist.cc index 0a6b1767a1..d0af117ef9 100644 --- a/test/core/nanopb/fuzzer_serverlist.cc +++ b/test/core/nanopb/fuzzer_serverlist.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -29,6 +30,7 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_serverlist* serverlist; @@ -36,5 +38,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_destroy_serverlist(serverlist); } grpc_slice_unref(slice); + grpc_shutdown(); return 0; } diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 64d383ad0a..ecc61928f5 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -148,41 +148,37 @@ static grpc_httpcli_response http_response(int status, const char* body) { /* -- Tests. -- */ static void test_empty_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); GPR_ASSERT(md_array.md == nullptr); GPR_ASSERT(md_array.size == 0); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_add_to_empty_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_credentials_mdelem_array_add(&md_array, md); GPR_ASSERT(md_array.size == 1); GPR_ASSERT(grpc_mdelem_eq(md, md_array.md[0])); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_add_abunch_to_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); size_t num_entries = 1000; for (size_t i = 0; i < num_entries; ++i) { grpc_credentials_mdelem_array_add(&md_array, md); @@ -190,57 +186,52 @@ static void test_add_abunch_to_md_array(void) { for (size_t i = 0; i < num_entries; ++i) { GPR_ASSERT(grpc_mdelem_eq(md_array.md[i], md)); } - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == - GRPC_CREDENTIALS_OK); + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_OK); GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md), "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); - GRPC_MDELEM_UNREF(&exec_ctx, token_md); + GRPC_MDELEM_UNREF(token_md); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(401, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, ""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -249,14 +240,13 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, @@ -264,14 +254,13 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -280,15 +269,14 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { " \"expires_in\":3599, " "}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -296,10 +284,9 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( "{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\"," " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -336,8 +323,7 @@ static void check_metadata(const expected_md* expected, } } -static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void check_request_metadata(void* arg, grpc_error* error) { request_metadata_state* state = (request_metadata_state*)arg; gpr_log(GPR_INFO, "expected_error: %s", grpc_error_string(state->expected_error)); @@ -358,9 +344,8 @@ static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, state->expected_size, state->md_array.size); GPR_ASSERT(state->md_array.size == state->expected_size); check_metadata(state->expected, &state->md_array); - grpc_credentials_mdelem_array_destroy(exec_ctx, &state->md_array); - grpc_pollset_set_destroy(exec_ctx, - grpc_polling_entity_pollset_set(&state->pollent)); + grpc_credentials_mdelem_array_destroy(&state->md_array); + grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&state->pollent)); gpr_free(state); } @@ -379,22 +364,21 @@ static request_metadata_state* make_request_metadata_state( return state; } -static void run_request_metadata_test(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds, +static void run_request_metadata_test(grpc_call_credentials* creds, grpc_auth_metadata_context auth_md_ctx, request_metadata_state* state) { grpc_error* error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - exec_ctx, creds, &state->pollent, auth_md_ctx, &state->md_array, + creds, &state->pollent, auth_md_ctx, &state->md_array, &state->on_request_metadata, &error)) { // Synchronous result. Invoke the callback directly. - check_request_metadata(exec_ctx, state, error); + check_request_metadata(state, error); GRPC_ERROR_UNREF(error); } } static void test_google_iam_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -406,13 +390,12 @@ static void test_google_iam_creds(void) { nullptr); grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); } static void test_access_token_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); @@ -421,16 +404,14 @@ static void test_access_token_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); } static grpc_security_status check_channel_oauth2_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); @@ -438,7 +419,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector( } static void test_channel_oauth2_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_create_security_connector, nullptr}; @@ -452,14 +433,13 @@ static void test_channel_oauth2_composite_creds(void) { grpc_channel_credentials_release(channel_creds); grpc_call_credentials_release(oauth2_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - &exec_ctx, channel_oauth2_creds, nullptr, nullptr, nullptr, - &new_args) == GRPC_SECURITY_OK); + channel_oauth2_creds, nullptr, nullptr, nullptr, &new_args) == + GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_creds); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_google_iam_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -471,15 +451,15 @@ static void test_oauth2_google_iam_composite_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - &exec_ctx, "authorization", test_oauth2_bearer_token, 0); + "authorization", test_oauth2_bearer_token, 0); grpc_call_credentials* google_iam_creds = grpc_google_iam_credentials_create( test_google_iam_authorization_token, test_google_iam_authority_selector, nullptr); grpc_call_credentials* composite_creds = grpc_composite_call_credentials_create(oauth2_creds, google_iam_creds, nullptr); - grpc_call_credentials_unref(&exec_ctx, oauth2_creds); - grpc_call_credentials_unref(&exec_ctx, google_iam_creds); + grpc_call_credentials_unref(oauth2_creds); + grpc_call_credentials_unref(google_iam_creds); GPR_ASSERT( strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); const grpc_call_credentials_array* creds_array = @@ -489,17 +469,15 @@ static void test_oauth2_google_iam_composite_creds(void) { GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); - run_request_metadata_test(&exec_ctx, composite_creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, composite_creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(composite_creds, auth_md_ctx, state); + grpc_call_credentials_unref(composite_creds); } static grpc_security_status check_channel_oauth2_google_iam_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { const grpc_call_credentials_array* creds_array; GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); @@ -514,7 +492,7 @@ check_channel_oauth2_google_iam_create_security_connector( } static void test_channel_oauth2_google_iam_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_google_iam_create_security_connector, @@ -538,11 +516,10 @@ static void test_channel_oauth2_google_iam_composite_creds(void) { grpc_call_credentials_release(google_iam_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - &exec_ctx, channel_oauth2_iam_creds, nullptr, nullptr, nullptr, + channel_oauth2_iam_creds, nullptr, nullptr, nullptr, &new_args) == GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_iam_creds); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_compute_engine_http_request( @@ -559,35 +536,32 @@ static void validate_compute_engine_http_request( } static int compute_engine_httpcli_get_success_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int compute_engine_httpcli_get_failure_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int httpcli_post_should_not_be_called( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body_bytes, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body_bytes, + size_t body_size, grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } -static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -596,7 +570,7 @@ static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, } static void test_compute_engine_creds_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_call_credentials* creds = @@ -609,24 +583,23 @@ static void test_compute_engine_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_compute_engine_creds_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -637,10 +610,9 @@ static void test_compute_engine_creds_failure(void) { grpc_google_compute_engine_credentials_create(nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_refresh_token_http_request( @@ -667,27 +639,27 @@ static void validate_refresh_token_http_request( } static int refresh_token_httpcli_post_success( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body, size_t body_size, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int refresh_token_httpcli_post_failure( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body, size_t body_size, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_refresh_token_creds_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, @@ -700,24 +672,23 @@ static void test_refresh_token_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_refresh_token_creds_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -728,10 +699,9 @@ static void test_refresh_token_creds_failure(void) { test_refresh_token_str, nullptr); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_failure); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_jwt_encode_and_sign_params( @@ -821,7 +791,7 @@ static void test_jwt_creds_lifetime(void) { static void test_jwt_creds_success(void) { char* json_key_string = test_json_key_str(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_md_value; @@ -835,16 +805,16 @@ static void test_jwt_creds_success(void) { request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ @@ -852,19 +822,18 @@ static void test_jwt_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); auth_md_ctx.service_url = other_test_service_url; grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); gpr_free(json_key_string); gpr_free(expected_md_value); grpc_jwt_encode_and_sign_set_override(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_jwt_creds_signing_failure(void) { char* json_key_string = test_json_key_str(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* state = make_request_metadata_state( @@ -875,12 +844,11 @@ static void test_jwt_creds_signing_failure(void) { json_key_string, grpc_max_auth_token_lifetime(), nullptr); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + run_request_metadata_test(creds, auth_md_ctx, state); gpr_free(json_key_string); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_jwt_encode_and_sign_set_override(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void set_google_default_creds_env_var_with_file_contents( @@ -897,7 +865,7 @@ static void set_google_default_creds_env_var_with_file_contents( } static void test_google_default_creds_auth_key(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_service_account_jwt_access_credentials* jwt; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); @@ -913,13 +881,12 @@ static void test_google_default_creds_auth_key(void) { strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(&exec_ctx); } static void test_google_default_creds_refresh_token(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_google_refresh_token_credentials* refresh; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); @@ -931,15 +898,13 @@ static void test_google_default_creds_refresh_token(void) { refresh = (grpc_google_refresh_token_credentials*)creds->call_creds; GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_success_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, ""); grpc_http_header* headers = static_cast(gpr_malloc(sizeof(*headers) * 1)); @@ -949,14 +914,14 @@ static int default_creds_gce_detection_httpcli_get_success_override( response->hdrs = headers; GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static char* null_well_known_creds_path_getter(void) { return nullptr; } static void test_google_default_creds_gce(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; request_metadata_state* state = @@ -981,8 +946,8 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(creds->call_creds != nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds->call_creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds->call_creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Check that we get a cached creds if we call grpc_google_default_credentials_create again. @@ -994,22 +959,20 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(cached_creds == &creds->base); /* Cleanup. */ - grpc_channel_credentials_unref(&exec_ctx, cached_creds); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(cached_creds); + grpc_channel_credentials_unref(&creds->base); grpc_httpcli_set_override(nullptr, nullptr); grpc_override_well_known_credentials_path_getter(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_failure_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { /* No magic header. */ GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); *response = http_response(200, ""); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } @@ -1093,7 +1056,7 @@ static void plugin_destroy(void* state) { static void test_metadata_plugin_success(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* md_state = make_request_metadata_state( @@ -1106,17 +1069,17 @@ static void test_metadata_plugin_success(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); + run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_call_credentials_unref(creds); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } static void test_metadata_plugin_failure(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_error; @@ -1134,10 +1097,10 @@ static void test_metadata_plugin_failure(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); + run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_call_credentials_unref(creds); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } @@ -1158,7 +1121,7 @@ static void test_get_well_known_google_credentials_file_path(void) { } static void test_channel_creds_duplicate_without_call_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* channel_creds = grpc_fake_transport_security_credentials_create(); @@ -1167,23 +1130,21 @@ static void test_channel_creds_duplicate_without_call_creds(void) { grpc_channel_credentials_duplicate_without_call_credentials( channel_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(&exec_ctx, dup); + grpc_channel_credentials_unref(dup); grpc_call_credentials* call_creds = grpc_access_token_credentials_create("blah", nullptr); grpc_channel_credentials* composite_creds = grpc_composite_channel_credentials_create(channel_creds, call_creds, nullptr); - grpc_call_credentials_unref(&exec_ctx, call_creds); + grpc_call_credentials_unref(call_creds); dup = grpc_channel_credentials_duplicate_without_call_credentials( composite_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(&exec_ctx, dup); - - grpc_channel_credentials_unref(&exec_ctx, channel_creds); - grpc_channel_credentials_unref(&exec_ctx, composite_creds); + grpc_channel_credentials_unref(dup); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_credentials_unref(channel_creds); + grpc_channel_credentials_unref(composite_creds); } typedef struct { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 0b6ccd5e37..aac9cc0029 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -207,7 +207,7 @@ static void test_parse_json_key_failure_no_private_key(void) { static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, char** scratchpad) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; char* b64; char* decoded; grpc_json* json; @@ -215,7 +215,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, b64 = static_cast(gpr_malloc(len + 1)); strncpy(b64, str, len); b64[len] = '\0'; - slice = grpc_base64_decode(&exec_ctx, b64, 1); + slice = grpc_base64_decode(b64, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice)); decoded = static_cast(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); strncpy(decoded, (const char*)GRPC_SLICE_START_PTR(slice), @@ -225,7 +225,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_free(b64); *scratchpad = decoded; grpc_slice_unref(slice); - grpc_exec_ctx_finish(&exec_ctx); + return json; } @@ -327,12 +327,12 @@ static void check_jwt_claim(grpc_json* claim, const char* expected_audience, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, const char* signed_data, size_t signed_data_size) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); EVP_PKEY* key = EVP_PKEY_new(); - grpc_slice sig = grpc_base64_decode(&exec_ctx, b64_signature, 1); + grpc_slice sig = grpc_base64_decode(b64_signature, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); GPR_ASSERT(GRPC_SLICE_LENGTH(sig) == 128); @@ -347,11 +347,9 @@ static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, GPR_ASSERT(EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(sig), GRPC_SLICE_LENGTH(sig)) == 1); - grpc_slice_unref_internal(&exec_ctx, sig); + grpc_slice_unref_internal(sig); if (key != nullptr) EVP_PKEY_free(key); if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); - - grpc_exec_ctx_finish(&exec_ctx); } static char* service_account_creds_jwt_encode_and_sign( @@ -485,6 +483,7 @@ static void test_parse_refresh_token_failure_no_refresh_token(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_parse_json_key_success(); test_parse_json_key_failure_bad_json(); test_parse_json_key_failure_no_type(); @@ -499,5 +498,6 @@ int main(int argc, char** argv) { test_parse_refresh_token_failure_no_client_id(); test_parse_refresh_token_failure_no_client_secret(); test_parse_refresh_token_failure_no_refresh_token(); + grpc_shutdown(); return 0; } diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index df0ebe5607..e219260b1d 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -209,8 +209,8 @@ static void test_claims_success(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -219,8 +219,7 @@ static void test_claims_success(void) { GPR_ASSERT(strcmp(grpc_jwt_claims_id(claims), "jwtuniqueid") == 0); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_OK); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_expired_claims_failure(void) { @@ -232,8 +231,8 @@ static void test_expired_claims_failure(void) { gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -246,17 +245,15 @@ static void test_expired_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_jwt_claims_from_json(&exec_ctx, json, s) == nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); } static void test_bad_audience_claims_failure(void) { @@ -265,13 +262,12 @@ static void test_bad_audience_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == GRPC_JWT_VERIFIER_BAD_AUDIENCE); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_bad_subject_claims_failure(void) { @@ -280,13 +276,12 @@ static void test_bad_subject_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_BAD_SUBJECT); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static char* json_key_str(const char* last_part) { @@ -323,17 +318,16 @@ static grpc_httpcli_response http_response(int status, char* body) { } static int httpcli_post_should_not_be_called( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body_bytes, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body_bytes, + size_t body_size, grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } static int httpcli_get_google_keys_for_email( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, good_google_email_keys()); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); @@ -341,22 +335,22 @@ static int httpcli_get_google_keys_for_email( "/robot/v1/metadata/x509/" "777-abaslkan11hlb6nmim3bpspl31ud@developer." "gserviceaccount.com") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } -static void on_verification_success(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_verification_success(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_OK); GPR_ASSERT(claims != nullptr); GPR_ASSERT(user_data == (void*)expected_user_data); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), expected_audience) == 0); - grpc_jwt_claims_destroy(exec_ctx, claims); + grpc_jwt_claims_destroy(claims); } static void test_jwt_verifier_google_email_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -369,28 +363,27 @@ static void test_jwt_verifier_google_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static int httpcli_get_custom_keys_for_email( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "keys.bar.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/jwk/foo@bar.com") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_custom_email_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -403,28 +396,26 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_jwk_set(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_jwk_set(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/oauth2/v3/certs") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } -static int httpcli_get_openid_config(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_openid_config(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -434,12 +425,12 @@ static int httpcli_get_openid_config(grpc_exec_ctx* exec_ctx, GPR_ASSERT(strcmp(request->http.path, GRPC_OPENID_CONFIG_URL_SUFFIX) == 0); grpc_httpcli_set_override(httpcli_get_jwk_set, httpcli_post_should_not_be_called); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -452,16 +443,15 @@ static void test_jwt_verifier_url_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static void on_verification_key_retrieval_error(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_verification_key_retrieval_error(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR); @@ -469,18 +459,17 @@ static void on_verification_key_retrieval_error(grpc_exec_ctx* exec_ctx, GPR_ASSERT(user_data == (void*)expected_user_data); } -static int httpcli_get_bad_json(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_bad_json(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}")); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_bad_config(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -493,17 +482,17 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static void test_jwt_verifier_bad_json_key(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -516,11 +505,11 @@ static void test_jwt_verifier_bad_json_key(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } @@ -532,9 +521,8 @@ static void corrupt_jwt_sig(char* jwt) { char* last_dot = strrchr(jwt, '.'); GPR_ASSERT(last_dot != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - sig = grpc_base64_decode(&exec_ctx, last_dot + 1, 1); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + sig = grpc_base64_decode(last_dot + 1, 1); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); sig_bytes = GRPC_SLICE_START_PTR(sig); @@ -546,8 +534,7 @@ static void corrupt_jwt_sig(char* jwt) { grpc_slice_unref(sig); } -static void on_verification_bad_signature(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_verification_bad_signature(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_SIGNATURE); @@ -556,7 +543,7 @@ static void on_verification_bad_signature(grpc_exec_ctx* exec_ctx, } static void test_jwt_verifier_bad_signature(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -570,17 +557,16 @@ static void test_jwt_verifier_bad_signature(void) { grpc_auth_json_key_destruct(&key); corrupt_jwt_sig(jwt); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_bad_signature, (void*)expected_user_data); gpr_free(jwt); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -588,7 +574,7 @@ static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, return 1; } -static void on_verification_bad_format(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_verification_bad_format(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_FORMAT); @@ -597,15 +583,15 @@ static void on_verification_bad_format(grpc_exec_ctx* exec_ctx, void* user_data, } static void test_jwt_verifier_bad_format(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, "bad jwt", - expected_audience, on_verification_bad_format, + grpc_jwt_verifier_verify(verifier, nullptr, "bad jwt", expected_audience, + on_verification_bad_format, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); grpc_httpcli_set_override(nullptr, nullptr); } diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 602041eecc..0d3a1279af 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -39,8 +39,7 @@ typedef struct { grpc_closure closure; } oauth2_request; -static void on_oauth2_response(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_oauth2_response(void* arg, grpc_error* error) { oauth2_request* request = (oauth2_request*)arg; char* token = nullptr; grpc_slice token_slice; @@ -54,25 +53,23 @@ static void on_oauth2_response(grpc_exec_ctx* exec_ctx, void* arg, GRPC_SLICE_LENGTH(token_slice)); token[GRPC_SLICE_LENGTH(token_slice)] = '\0'; } - grpc_credentials_mdelem_array_destroy(exec_ctx, &request->md_array); + grpc_credentials_mdelem_array_destroy(&request->md_array); gpr_mu_lock(request->mu); request->is_done = true; request->token = token; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&request->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&request->pops), nullptr)); gpr_mu_unlock(request->mu); } -static void do_nothing(grpc_exec_ctx* exec_ctx, void* unused, - grpc_error* error) {} +static void do_nothing(void* unused, grpc_error* error) {} char* grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials* creds) { oauth2_request request; memset(&request, 0, sizeof(request)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; @@ -88,31 +85,30 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_schedule_on_exec_ctx); grpc_error* error = GRPC_ERROR_NONE; - if (grpc_call_credentials_get_request_metadata( - &exec_ctx, creds, &request.pops, null_ctx, &request.md_array, - &request.closure, &error)) { + if (grpc_call_credentials_get_request_metadata(creds, &request.pops, null_ctx, + &request.md_array, + &request.closure, &error)) { // Synchronous result; invoke callback directly. - on_oauth2_response(&exec_ctx, &request, error); + on_oauth2_response(&request, error); GRPC_ERROR_UNREF(error); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(request.mu); while (!request.is_done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, - grpc_polling_entity_pollset(&request.pops), + grpc_pollset_work(grpc_polling_entity_pollset(&request.pops), &worker, GRPC_MILLIS_INF_FUTURE))) { request.is_done = true; } } gpr_mu_unlock(request.mu); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&request.pops), + grpc_pollset_shutdown(grpc_polling_entity_pollset(&request.pops), &do_nothing_closure); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(grpc_polling_entity_pollset(&request.pops)); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index f4acf023bd..b3742f58a8 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -41,8 +41,7 @@ typedef struct { grpc_closure on_request_metadata; } synchronizer; -static void on_metadata_response(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_metadata_response(void* arg, grpc_error* error) { synchronizer* sync = static_cast(arg); if (error != GRPC_ERROR_NONE) { fprintf(stderr, "Fetching token failed: %s\n", grpc_error_string(error)); @@ -57,14 +56,13 @@ static void on_metadata_response(grpc_exec_ctx* exec_ctx, void* arg, sync->is_done = true; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&sync->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&sync->pops), nullptr)); gpr_mu_unlock(sync->mu); } int main(int argc, char** argv) { int result = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; synchronizer sync; grpc_channel_credentials* creds = nullptr; const char* service_url = "https://test.foo.google.com/Foo"; @@ -97,11 +95,10 @@ int main(int argc, char** argv) { error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - &exec_ctx, ((grpc_composite_channel_credentials*)creds)->call_creds, - &sync.pops, context, &sync.md_array, &sync.on_request_metadata, - &error)) { + ((grpc_composite_channel_credentials*)creds)->call_creds, &sync.pops, + context, &sync.md_array, &sync.on_request_metadata, &error)) { // Synchronous response. Invoke callback directly. - on_metadata_response(&exec_ctx, &sync, error); + on_metadata_response(&sync, error); GRPC_ERROR_UNREF(error); } @@ -110,18 +107,15 @@ int main(int argc, char** argv) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, - grpc_polling_entity_pollset(&sync.pops), &worker, + grpc_pollset_work(grpc_polling_entity_pollset(&sync.pops), &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); - grpc_exec_ctx_finish(&exec_ctx); - grpc_channel_credentials_release(creds); gpr_free(grpc_polling_entity_pollset(&sync.pops)); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index a12af02479..38c78fed42 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -38,7 +38,7 @@ static grpc_pollset* g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, grpc_slice* leftover_slices, size_t leftover_nslices, bool use_zero_copy_protector) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; tsi_frame_protector* fake_read_protector = tsi_create_fake_frame_protector(nullptr); tsi_frame_protector* fake_write_protector = @@ -60,8 +60,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; tcp = grpc_iomgr_create_endpoint_pair("fixture", &args); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset); + grpc_endpoint_add_to_pollset(tcp.client, g_pollset); + grpc_endpoint_add_to_pollset(tcp.server, g_pollset); if (leftover_nslices == 0) { f.client_ep = grpc_secure_endpoint_create(fake_read_protector, @@ -117,7 +117,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( f.server_ep = grpc_secure_endpoint_create(fake_write_protector, fake_write_zero_copy_protector, tcp.server, nullptr, 0); - grpc_exec_ctx_finish(&exec_ctx); + return f; } @@ -165,65 +165,62 @@ static grpc_endpoint_test_config configs[] = { clean_up}, }; -static void inc_call_ctr(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - ++*(int*)arg; -} +static void inc_call_ctr(void* arg, grpc_error* error) { ++*(int*)arg; } static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_endpoint_test_fixture f = config.create_fixture(slice_size); grpc_slice_buffer incoming; grpc_slice s = grpc_slice_from_copied_string("hello world 12345678900987654321"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; int n = 0; grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); grpc_slice_buffer_init(&incoming); GRPC_CLOSURE_INIT(&done_closure, inc_call_ctr, &n, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, &done_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_read(f.client_ep, &incoming, &done_closure); + + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); grpc_endpoint_shutdown( - &exec_ctx, f.client_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); grpc_endpoint_shutdown( - &exec_ctx, f.server_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); - grpc_endpoint_destroy(&exec_ctx, f.client_ep); - grpc_endpoint_destroy(&exec_ctx, f.server_ep); - grpc_exec_ctx_finish(&exec_ctx); - grpc_slice_unref_internal(&exec_ctx, s); - grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); + f.server_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + grpc_endpoint_destroy(f.client_ep); + grpc_endpoint_destroy(f.server_ep); + + grpc_slice_unref_internal(s); + grpc_slice_buffer_destroy_internal(&incoming); clean_up(); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); - grpc_init(); - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - grpc_endpoint_tests(configs[1], g_pollset, g_mu); - test_leftover(configs[2], 1); - test_leftover(configs[3], 1); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + grpc_endpoint_tests(configs[1], g_pollset, g_mu); + test_leftover(configs[2], 1); + test_leftover(configs[3], 1); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } + grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index d83ebb18d2..6e30698562 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -40,8 +40,7 @@ struct handshake_state { bool done_callback_called; }; -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshaker_args* args = static_cast(arg); struct handshake_state* state = static_cast(args->user_data); @@ -56,67 +55,70 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("ssl_server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); - - // Load key pair and establish server SSL credentials. - grpc_ssl_pem_key_cert_pair pem_key_cert_pair; - grpc_slice ca_slice, cert_slice, key_slice; - ca_slice = grpc_slice_from_static_string(test_root_cert); - cert_slice = grpc_slice_from_static_string(test_server1_cert); - key_slice = grpc_slice_from_static_string(test_server1_key); - const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); - grpc_server_credentials* creds = grpc_ssl_server_credentials_create( - ca_cert, &pem_key_cert_pair, 1, 0, nullptr); - - // Create security connector - grpc_server_security_connector* sc = nullptr; - grpc_security_status status = - grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); - GPR_ASSERT(status == GRPC_SECURITY_OK); - grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(&exec_ctx); - - struct handshake_state state; - state.done_callback_called = false; - grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); - grpc_server_security_connector_add_handshakers(&exec_ctx, sc, handshake_mgr); - grpc_handshake_manager_do_handshake( - &exec_ctx, handshake_mgr, nullptr /* interested_parties */, mock_endpoint, - nullptr /* channel_args */, deadline, nullptr /* acceptor */, - on_handshake_done, &state); - grpc_exec_ctx_flush(&exec_ctx); - - // If the given string happens to be part of the correct client hello, the - // server will wait for more data. Explicitly fail the server by shutting down - // the endpoint. - if (!state.done_callback_called) { - grpc_endpoint_shutdown( - &exec_ctx, mock_endpoint, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); - grpc_exec_ctx_flush(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("ssl_server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); + + // Load key pair and establish server SSL credentials. + grpc_ssl_pem_key_cert_pair pem_key_cert_pair; + grpc_slice ca_slice, cert_slice, key_slice; + ca_slice = grpc_slice_from_static_string(test_root_cert); + cert_slice = grpc_slice_from_static_string(test_server1_cert); + key_slice = grpc_slice_from_static_string(test_server1_key); + const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = + (const char*)GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = + (const char*)GRPC_SLICE_START_PTR(cert_slice); + grpc_server_credentials* creds = grpc_ssl_server_credentials_create( + ca_cert, &pem_key_cert_pair, 1, 0, nullptr); + + // Create security connector + grpc_server_security_connector* sc = nullptr; + grpc_security_status status = + grpc_server_credentials_create_security_connector(creds, &sc); + GPR_ASSERT(status == GRPC_SECURITY_OK); + grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(); + + struct handshake_state state; + state.done_callback_called = false; + grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); + grpc_server_security_connector_add_handshakers(sc, handshake_mgr); + grpc_handshake_manager_do_handshake( + handshake_mgr, nullptr /* interested_parties */, mock_endpoint, + nullptr /* channel_args */, deadline, nullptr /* acceptor */, + on_handshake_done, &state); + grpc_core::ExecCtx::Get()->Flush(); + + // If the given string happens to be part of the correct client hello, the + // server will wait for more data. Explicitly fail the server by shutting + // down the endpoint. + if (!state.done_callback_called) { + grpc_endpoint_shutdown( + mock_endpoint, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); + grpc_core::ExecCtx::Get()->Flush(); + } + + GPR_ASSERT(state.done_callback_called); + + grpc_handshake_manager_destroy(handshake_mgr); + GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test"); + grpc_server_credentials_release(creds); + grpc_slice_unref(cert_slice); + grpc_slice_unref(key_slice); + grpc_slice_unref(ca_slice); + grpc_core::ExecCtx::Get()->Flush(); } - GPR_ASSERT(state.done_callback_called); - - grpc_handshake_manager_destroy(&exec_ctx, handshake_mgr); - GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "test"); - grpc_server_credentials_release(creds); - grpc_slice_unref(cert_slice); - grpc_slice_unref(key_slice); - grpc_slice_unref(ca_slice); - grpc_exec_ctx_flush(&exec_ctx); - grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index 787d58bc37..e039970c67 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -44,7 +44,7 @@ static void print_usage_and_exit(gpr_cmdline* cl, const char* argv0) { exit(1); } -static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_jwt_verification_done(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { synchronizer* sync = static_cast(user_data); @@ -57,7 +57,7 @@ static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, grpc_json_dump_to_string((grpc_json*)grpc_jwt_claims_json(claims), 2); printf("Claims: \n\n%s\n", claims_str); gpr_free(claims_str); - grpc_jwt_claims_destroy(exec_ctx, claims); + grpc_jwt_claims_destroy(claims); } else { GPR_ASSERT(claims == nullptr); fprintf(stderr, "Verification failed with error %s\n", @@ -66,8 +66,7 @@ static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, gpr_mu_lock(sync->mu); sync->is_done = 1; - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, sync->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(sync->pollset, nullptr)); gpr_mu_unlock(sync->mu); } @@ -77,7 +76,7 @@ int main(int argc, char** argv) { gpr_cmdline* cl; const char* jwt = nullptr; const char* aud = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_init(); cl = gpr_cmdline_create("JWT verifier tool"); @@ -96,26 +95,26 @@ int main(int argc, char** argv) { grpc_pollset_init(sync.pollset, &sync.mu); sync.is_done = 0; - grpc_jwt_verifier_verify(&exec_ctx, verifier, sync.pollset, jwt, aud, + grpc_jwt_verifier_verify(verifier, sync.pollset, jwt, aud, on_jwt_verification_done, &sync); gpr_mu_lock(sync.mu); while (!sync.is_done) { grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, sync.pollset, &worker, - GRPC_MILLIS_INF_FUTURE))) + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work(sync.pollset, &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); gpr_free(sync.pollset); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + gpr_cmdline_destroy(cl); grpc_shutdown(); return !sync.success; diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 479198f9f9..94785fd1e2 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -44,14 +45,14 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char* hello = "hello"; char* hello_b64 = grpc_base64_encode(hello, strlen(hello), url_safe, multiline); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice hello_slice = grpc_base64_decode(&exec_ctx, hello_b64, url_safe); + grpc_core::ExecCtx exec_ctx; + grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello)); GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello, GRPC_SLICE_LENGTH(hello_slice)) == 0); - grpc_slice_unref_internal(&exec_ctx, hello_slice); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(hello_slice); + gpr_free(hello_b64); } @@ -64,15 +65,14 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { /* Try all the different paddings. */ for (i = 0; i < 3; i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); + orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i)); GPR_ASSERT(buffers_are_equal(orig, GRPC_SLICE_START_PTR(orig_decoded), sizeof(orig) - i)); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); + grpc_slice_unref_internal(orig_decoded); gpr_free(b64); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -116,19 +116,18 @@ static void test_url_safe_unsafe_mismatch_failure(void) { int url_safe = 1; for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, !url_safe); + orig_decoded = grpc_base64_decode(b64, !url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); + grpc_slice_unref_internal(orig_decoded); b64 = grpc_base64_encode(orig, sizeof(orig), !url_safe, 0); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); + orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(orig_decoded); } static void test_rfc4648_test_vectors(void) { @@ -166,44 +165,44 @@ static void test_rfc4648_test_vectors(void) { static void test_unpadded_decode(void) { grpc_slice decoded; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmFy", 0); + grpc_core::ExecCtx exec_ctx; + decoded = grpc_base64_decode("Zm9vYmFy", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmE", 0); + decoded = grpc_base64_decode("Zm9vYmE", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fooba") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYg", 0); + decoded = grpc_base64_decode("Zm9vYg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foob") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9v", 0); + decoded = grpc_base64_decode("Zm9v", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm8", 0); + decoded = grpc_base64_decode("Zm8", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zg", 0); + decoded = grpc_base64_decode("Zg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "f") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "", 0); + decoded = grpc_base64_decode("", 0); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded)); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_simple_encode_decode_b64_no_multiline(); test_simple_encode_decode_b64_multiline(); test_simple_encode_decode_b64_urlsafe_no_multiline(); @@ -215,5 +214,6 @@ int main(int argc, char** argv) { test_url_safe_unsafe_mismatch_failure(); test_rfc4648_test_vectors(); test_unpadded_decode(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/percent_decode_fuzzer.cc b/test/core/slice/percent_decode_fuzzer.cc index 3603177c47..81eb031014 100644 --- a/test/core/slice/percent_decode_fuzzer.cc +++ b/test/core/slice/percent_decode_fuzzer.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,6 +32,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { struct grpc_memory_counters counters; + grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output; @@ -46,6 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(input); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); + grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); return 0; } diff --git a/test/core/slice/percent_encode_fuzzer.cc b/test/core/slice/percent_encode_fuzzer.cc index c8e3849fc8..201ae2790e 100644 --- a/test/core/slice/percent_encode_fuzzer.cc +++ b/test/core/slice/percent_encode_fuzzer.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,6 +32,7 @@ bool leak_check = true; static void test(const uint8_t* data, size_t size, const uint8_t* dict) { struct grpc_memory_counters counters; + grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output = grpc_percent_encode_slice(input, dict); @@ -48,6 +50,7 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) { grpc_slice_unref(permissive_decoded_output); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); + grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); } diff --git a/test/core/slice/percent_encoding_test.cc b/test/core/slice/percent_encoding_test.cc index 253240faad..11f3995f98 100644 --- a/test/core/slice/percent_encoding_test.cc +++ b/test/core/slice/percent_encoding_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/slice/percent_encoding.h" +#include #include #include @@ -118,6 +119,7 @@ static void test_nonconformant_vector(const char* encoded, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); TEST_VECTOR( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", @@ -140,5 +142,6 @@ int main(int argc, char** argv) { grpc_url_percent_encoding_unreserved_bytes); TEST_NONCONFORMANT_VECTOR("\0", "\0", grpc_url_percent_encoding_unreserved_bytes); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_buffer_test.cc b/test/core/slice/slice_buffer_test.cc index 338e8079dc..e59986730b 100644 --- a/test/core/slice/slice_buffer_test.cc +++ b/test/core/slice/slice_buffer_test.cc @@ -16,6 +16,7 @@ * */ +#include #include #include #include "test/core/util/test_config.h" @@ -106,9 +107,11 @@ void test_slice_buffer_move_first() { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_slice_buffer_add(); test_slice_buffer_move_first(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index 0ee4e8617d..9fad9a614e 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -59,9 +59,7 @@ static void check_non_existent_value(const char* key_string, grpc_slice_unref(key); } -static void destroy_string(grpc_exec_ctx* exec_ctx, void* value) { - gpr_free(value); -} +static void destroy_string(void* value) { gpr_free(value); } static grpc_slice_hash_table* create_table_from_entries( const test_entry* test_entries, size_t num_test_entries, @@ -121,9 +119,8 @@ static void test_slice_hash_table() { check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); // Clean up. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table); } static int value_cmp_fn(void* a, void* b) { @@ -149,10 +146,9 @@ static void test_slice_hash_table_eq() { create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table_a); - grpc_slice_hash_table_unref(&exec_ctx, table_b); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table_a); + grpc_slice_hash_table_unref(table_b); } static void test_slice_hash_table_not_eq() { @@ -221,23 +217,24 @@ static void test_slice_hash_table_not_eq() { create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table_a); - grpc_slice_hash_table_unref(&exec_ctx, table_b_larger); - grpc_slice_hash_table_unref(&exec_ctx, table_b_smaller); - grpc_slice_hash_table_unref(&exec_ctx, table_c); - grpc_slice_hash_table_unref(&exec_ctx, table_d); - grpc_slice_hash_table_unref(&exec_ctx, table_e); - grpc_slice_hash_table_unref(&exec_ctx, table_f); - grpc_slice_hash_table_unref(&exec_ctx, table_g); - grpc_slice_hash_table_unref(&exec_ctx, table_h); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table_a); + grpc_slice_hash_table_unref(table_b_larger); + grpc_slice_hash_table_unref(table_b_smaller); + grpc_slice_hash_table_unref(table_c); + grpc_slice_hash_table_unref(table_d); + grpc_slice_hash_table_unref(table_e); + grpc_slice_hash_table_unref(table_f); + grpc_slice_hash_table_unref(table_g); + grpc_slice_hash_table_unref(table_h); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_core::ExecCtx::GlobalInit(); test_slice_hash_table(); test_slice_hash_table_eq(); test_slice_hash_table_not_eq(); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/slice/slice_string_helpers_test.cc b/test/core/slice/slice_string_helpers_test.cc index 260f8c80d5..f1d470461a 100644 --- a/test/core/slice/slice_string_helpers_test.cc +++ b/test/core/slice/slice_string_helpers_test.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -130,7 +131,9 @@ static void test_strsplit(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_dump_slice(); test_strsplit(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index 02f6b1ea79..e40154dd0e 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -292,6 +292,7 @@ static void test_static_slice_copy_interning(void) { int main(int argc, char** argv) { unsigned length; grpc_test_init(argc, argv); + grpc_init(); test_slice_malloc_returns_something_sensible(); test_slice_new_returns_something_sensible(); test_slice_new_with_user_data(); @@ -305,5 +306,6 @@ int main(int argc, char** argv) { test_slice_interning(); test_static_slice_interning(); test_static_slice_copy_interning(); + grpc_shutdown(); return 0; } diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index e5d2d7c78d..94a8615b3c 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -132,10 +132,8 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, memset(GRPC_SLICE_START_PTR(input_slice), 'a', input_size); grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT( - grpc_msg_compress(&exec_ctx, algorithm, &sliceb_in, &sliceb_out)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); } buffer = grpc_raw_compressed_byte_buffer_create(sliceb_out.slices, @@ -267,6 +265,7 @@ static void test_byte_buffer_copy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_read_one_slice(); test_read_one_slice_malloc(); test_read_none_compressed_slice(); @@ -276,5 +275,6 @@ int main(int argc, char** argv) { test_byte_buffer_from_reader(); test_byte_buffer_copy(); test_readall(); + grpc_shutdown(); return 0; } diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index f358b0fc8d..37247f89d0 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -35,11 +35,10 @@ void test_unknown_scheme_target(void) { chan = grpc_insecure_channel_create("blah://blah", nullptr, nullptr); GPR_ASSERT(chan != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx_finish(&exec_ctx); grpc_channel_destroy(chan); } diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index c6e13d2386..fefbb3c185 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -121,8 +121,7 @@ static void test_wait_empty(void) { } } -static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* c) {} +static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} static void test_cq_end_op(void) { grpc_event ev; @@ -131,8 +130,6 @@ static void test_cq_end_op(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); LOG_TEST("test_cq_end_op"); @@ -140,14 +137,14 @@ static void test_cq_end_op(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completion); + grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, + &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -156,7 +153,6 @@ static void test_cq_end_op(void) { GPR_ASSERT(ev.success); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -167,8 +163,6 @@ static void test_cq_tls_cache_full(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); void* res_tag; int ok; @@ -178,15 +172,15 @@ static void test_cq_tls_cache_full(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); grpc_completion_queue_thread_local_cache_init(cc); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completion); + grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, + &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -202,7 +196,6 @@ static void test_cq_tls_cache_full(void) { GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -211,8 +204,6 @@ static void test_cq_tls_cache_empty(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* res_tag; int ok; @@ -221,7 +212,7 @@ static void test_cq_tls_cache_empty(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -232,7 +223,6 @@ static void test_cq_tls_cache_empty(void) { GPR_ASSERT( grpc_completion_queue_thread_local_cache_flush(cc, &res_tag, &ok) == 0); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -289,8 +279,6 @@ static void test_pluck(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; unsigned i, j; LOG_TEST("test_pluck"); @@ -305,15 +293,15 @@ static void test_pluck(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_PLUCK; for (size_t pidx = 0; pidx < GPR_ARRAY_SIZE(polling_types); pidx++) { - exec_ctx = init_exec_ctx; // reset exec_ctx + grpc_core::ExecCtx exec_ctx; // reset exec_ctx attr.cq_polling_type = polling_types[pidx]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -324,8 +312,8 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -336,7 +324,6 @@ static void test_pluck(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 126d363f83..4a9e818b45 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -59,8 +59,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { grpc_completion_queue_destroy(cc); } -static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* c) {} +static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} struct thread_state { grpc_completion_queue* cc; @@ -81,7 +80,7 @@ static void test_too_many_plucks(void) { gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; gpr_thd_options thread_options = gpr_thd_options_default(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); @@ -109,8 +108,8 @@ static void test_too_many_plucks(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -118,7 +117,6 @@ static void test_too_many_plucks(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } #define TEST_THREAD_EVENTS 10000 @@ -138,15 +136,13 @@ gpr_timespec ten_seconds_time(void) { return grpc_timeout_seconds_to_deadline(10); } -static void free_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* completion) { +static void free_completion(void* arg, grpc_cq_completion* completion) { gpr_free(completion); } static void producer_thread(void* arg) { test_thread_options* opt = static_cast(arg); int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "producer %d started", opt->id); gpr_event_set(&opt->on_started, (void*)(intptr_t)1); @@ -163,17 +159,16 @@ static void producer_thread(void* arg) { gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { - grpc_cq_end_op(&exec_ctx, opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, + grpc_core::ExecCtx exec_ctx; + grpc_cq_end_op(opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, free_completion, nullptr, static_cast( gpr_malloc(sizeof(grpc_cq_completion)))); opt->events_triggered++; - grpc_exec_ctx_finish(&exec_ctx); } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); gpr_event_set(&opt->on_finished, (void*)(intptr_t)1); - grpc_exec_ctx_finish(&exec_ctx); } static void consumer_thread(void* arg) { diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 2ff1ca3d79..235d136376 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -103,29 +103,28 @@ void server_thread(void* vargs) { GPR_ASSERT(detag(ev.tag) == 0xd1e); } -static void on_connect(grpc_exec_ctx* exec_ctx, void* vargs, grpc_endpoint* tcp, +static void on_connect(void* vargs, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } void bad_server_thread(void* vargs) { struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int port; grpc_tcp_server* s; - grpc_error* error = grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s); + grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); GPR_ASSERT(error == GRPC_ERROR_NONE); memset(&resolved_addr, 0, sizeof(resolved_addr)); addr->ss_family = AF_INET; @@ -134,35 +133,32 @@ void bad_server_thread(void* vargs) { GPR_ASSERT(port > 0); gpr_asprintf(&args->addr, "localhost:%d", port); - grpc_tcp_server_start(&exec_ctx, s, &args->pollset, 1, on_connect, args); + grpc_tcp_server_start(s, &args->pollset, 1, on_connect, args); gpr_event_set(&args->ready, (void*)1); gpr_mu_lock(args->mu); while (gpr_atm_acq_load(&args->stop) == 0) { - grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 100; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 100; grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, deadline))) { + grpc_pollset_work(args->pollset, &worker, deadline))) { gpr_atm_rel_store(&args->stop, 1); } gpr_mu_unlock(args->mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(args->mu); } gpr_mu_unlock(args->mu); - grpc_tcp_server_unref(&exec_ctx, s); - - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); gpr_free(args->addr); } -static void done_pollset_shutdown(grpc_exec_ctx* exec_ctx, void* pollset, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(pollset)); +static void done_pollset_shutdown(void* pollset, grpc_error* error) { + grpc_pollset_destroy(static_cast(pollset)); gpr_free(pollset); } @@ -234,11 +230,12 @@ int run_concurrent_connectivity_test() { gpr_atm_rel_store(&args.stop, 1); gpr_thd_join(server); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_shutdown(&exec_ctx, args.pollset, - GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, - grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_pollset_shutdown( + args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, + grpc_schedule_on_exec_ctx)); + } grpc_shutdown(); return 0; diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index f3df7f35a7..4bf40569e6 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -32,20 +32,19 @@ grpc_closure transport_op_cb; static void* tag(intptr_t x) { return (void*)x; } -void verify_connectivity(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +void verify_connectivity(void* arg, grpc_error* error) { grpc_connectivity_state* state = static_cast(arg); GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *state); GPR_ASSERT(error == GRPC_ERROR_NONE); } -void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +void do_nothing(void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { grpc_transport_op* op; grpc_channel_element* elem; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, grpc_schedule_on_exec_ctx); @@ -54,14 +53,12 @@ void test_transport_op(grpc_channel* channel) { op->on_connectivity_state_change = &transport_op_cb; op->connectivity_state = &state; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - elem->filter->start_transport_op(&exec_ctx, elem, op); - grpc_exec_ctx_finish(&exec_ctx); + elem->filter->start_transport_op(elem, op); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); op = grpc_make_transport_op(&transport_op_cb); - elem->filter->start_transport_op(&exec_ctx, elem, op); - grpc_exec_ctx_finish(&exec_ctx); + elem->filter->start_transport_op(elem, op); } int main(int argc, char** argv) { diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index f78d333673..9cdd299ae3 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -178,9 +178,8 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index c31c61430c..fa22cd6873 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -37,10 +37,9 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_channel_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); + grpc_channel_credentials_unref(creds); } void test_security_connector_already_in_arg(void) { @@ -56,9 +55,8 @@ void test_security_connector_already_in_arg(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } void test_null_creds(void) { @@ -67,9 +65,8 @@ void test_null_creds(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } int main(int argc, char** argv) { diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 11d0aa705d..ac49bd9823 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -156,9 +156,8 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index d1272607f2..445823b628 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -58,7 +58,7 @@ namespace { void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { estimator->AddIncomingBytes(1234567); inc_time(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; estimator->SchedulePing(); estimator->StartPing(); for (size_t i = 0; i < n; i++) { @@ -66,9 +66,8 @@ void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { } gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1, GPR_TIMESPAN))); - grpc_exec_ctx_invalidate_now(&exec_ctx); - estimator->CompletePing(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); + estimator->CompletePing(); } void AddSample(BdpEstimator* estimator, int64_t sample) { diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 0e34fd7651..2aab6e9262 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/transport/byte_stream.h" +#include #include #include #include @@ -30,14 +31,13 @@ // grpc_slice_buffer_stream tests // -static void not_called_closure(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void not_called_closure(void* arg, grpc_error* error) { GPR_ASSERT(false); } static void test_slice_buffer_stream_basic(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_basic"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -57,23 +57,21 @@ static void test_slice_buffer_stream_basic(void) { grpc_schedule_on_exec_ctx); // Read each slice. Note that next() always returns synchronously. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_slice_buffer_stream_shutdown(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_shutdown"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -92,29 +90,25 @@ static void test_slice_buffer_stream_shutdown(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read the first slice. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Now shutdown. grpc_error* shutdown_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown error"); - grpc_byte_stream_shutdown(&exec_ctx, &stream.base, - GRPC_ERROR_REF(shutdown_error)); + grpc_byte_stream_shutdown(&stream.base, GRPC_ERROR_REF(shutdown_error)); // After shutdown, the next pull() should return the error. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == shutdown_error); GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(shutdown_error); // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_slice_buffer_destroy_internal(&buffer); } // @@ -123,7 +117,7 @@ static void test_slice_buffer_stream_shutdown(void) { static void test_caching_byte_stream_basic(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_basic"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -147,24 +141,22 @@ static void test_caching_byte_stream_basic(void) { // Read each slice. Note that next() always returns synchronously, // because the underlying byte stream always does. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_caching_byte_stream_reset(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_reset"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -186,34 +178,31 @@ static void test_caching_byte_stream_reset(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Reset the caching stream. The reads should start over from the // first slice. grpc_caching_byte_stream_reset(&stream); for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_caching_byte_stream_shared_cache(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_shared_cache"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -237,43 +226,41 @@ static void test_caching_byte_stream_shared_cache(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice from stream1. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Read all slices from stream2. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream2.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream2.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream2.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream2.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Now read the second slice from stream1. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[1], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream1.base); - grpc_byte_stream_destroy(&exec_ctx, &stream2.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream1.base); + grpc_byte_stream_destroy(&stream2.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } int main(int argc, char** argv) { + grpc_init(); grpc_test_init(argc, argv); test_slice_buffer_stream_basic(); test_slice_buffer_stream_shutdown(); test_caching_byte_stream_basic(); test_caching_byte_stream_reset(); test_caching_byte_stream_shared_cache(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index a29ec8a13f..6d70a4261b 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -20,6 +20,7 @@ #include +#include #include #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" @@ -29,8 +30,8 @@ static int all_ok = 1; -static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected, - grpc_slice slice, const char* debug, int line) { +static void expect_slice_eq(grpc_slice expected, grpc_slice slice, + const char* debug, int line) { if (!grpc_slice_eq(slice, expected)) { char* hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char* he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -40,104 +41,97 @@ static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected, gpr_free(he); all_ok = 0; } - grpc_slice_unref_internal(exec_ctx, expected); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(expected); + grpc_slice_unref_internal(slice); } -static grpc_slice base64_encode(grpc_exec_ctx* exec_ctx, const char* s) { +static grpc_slice base64_encode(const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); grpc_slice out = grpc_chttp2_base64_encode(ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode(grpc_exec_ctx* exec_ctx, const char* s) { +static grpc_slice base64_decode(const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = grpc_chttp2_base64_decode(exec_ctx, ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode(ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode_with_length(grpc_exec_ctx* exec_ctx, - const char* s, +static grpc_slice base64_decode_with_length(const char* s, size_t output_length) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = - grpc_chttp2_base64_decode_with_length(exec_ctx, ss, output_length); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); + grpc_slice_unref_internal(ss); return out; } -#define EXPECT_SLICE_EQ(exec_ctx, expected, slice) \ - expect_slice_eq( \ - exec_ctx, grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), \ - slice, #slice, __LINE__); +#define EXPECT_SLICE_EQ(expected, slice) \ + expect_slice_eq( \ + grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \ + #slice, __LINE__); -#define ENCODE_AND_DECODE(exec_ctx, s) \ - EXPECT_SLICE_EQ(exec_ctx, s, \ - grpc_chttp2_base64_decode_with_length( \ - exec_ctx, base64_encode(exec_ctx, s), strlen(s))); +#define ENCODE_AND_DECODE(s) \ + EXPECT_SLICE_EQ( \ + s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which - takes encoded base64 strings without pad chars, but output length is - required. */ - /* Base64 test vectors from RFC 4648 */ - ENCODE_AND_DECODE(&exec_ctx, ""); - ENCODE_AND_DECODE(&exec_ctx, "f"); - ENCODE_AND_DECODE(&exec_ctx, "foo"); - ENCODE_AND_DECODE(&exec_ctx, "fo"); - ENCODE_AND_DECODE(&exec_ctx, "foob"); - ENCODE_AND_DECODE(&exec_ctx, "fooba"); - ENCODE_AND_DECODE(&exec_ctx, "foobar"); - - ENCODE_AND_DECODE(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5"); - - /* Base64 test vectors from RFC 4648, with pad chars */ - /* BASE64("") = "" */ - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "")); - /* BASE64("f") = "Zg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "f", base64_decode(&exec_ctx, "Zg==")); - /* BASE64("fo") = "Zm8=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fo", base64_decode(&exec_ctx, "Zm8=")); - /* BASE64("foo") = "Zm9v" */ - EXPECT_SLICE_EQ(&exec_ctx, "foo", base64_decode(&exec_ctx, "Zm9v")); - /* BASE64("foob") = "Zm9vYg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "foob", base64_decode(&exec_ctx, "Zm9vYg==")); - /* BASE64("fooba") = "Zm9vYmE=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fooba", base64_decode(&exec_ctx, "Zm9vYmE=")); - /* BASE64("foobar") = "Zm9vYmFy" */ - EXPECT_SLICE_EQ(&exec_ctx, "foobar", base64_decode(&exec_ctx, "Zm9vYmFy")); - - EXPECT_SLICE_EQ(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5", - base64_decode(&exec_ctx, "wMHCw8TF")); - - // Test illegal input length in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "a")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "ab")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "abc")); - - // Test illegal charactors in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm:v")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm=v")); - - // Test output_length longer than max possible output length in - // grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode_with_length(&exec_ctx, "Zg", 2)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm8", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm9v", 4)); - - // Test illegal charactors in grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm:v", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm=v", 3)); - - grpc_exec_ctx_finish(&exec_ctx); - + grpc_init(); + { + grpc_core::ExecCtx exec_ctx; + + /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which + takes encoded base64 strings without pad chars, but output length is + required. */ + /* Base64 test vectors from RFC 4648 */ + ENCODE_AND_DECODE(""); + ENCODE_AND_DECODE("f"); + ENCODE_AND_DECODE("foo"); + ENCODE_AND_DECODE("fo"); + ENCODE_AND_DECODE("foob"); + ENCODE_AND_DECODE("fooba"); + ENCODE_AND_DECODE("foobar"); + + ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); + + /* Base64 test vectors from RFC 4648, with pad chars */ + /* BASE64("") = "" */ + EXPECT_SLICE_EQ("", base64_decode("")); + /* BASE64("f") = "Zg==" */ + EXPECT_SLICE_EQ("f", base64_decode("Zg==")); + /* BASE64("fo") = "Zm8=" */ + EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); + /* BASE64("foo") = "Zm9v" */ + EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); + /* BASE64("foob") = "Zm9vYg==" */ + EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); + /* BASE64("fooba") = "Zm9vYmE=" */ + EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); + /* BASE64("foobar") = "Zm9vYmFy" */ + EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); + + EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); + + // Test illegal input length in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("a")); + EXPECT_SLICE_EQ("", base64_decode("ab")); + EXPECT_SLICE_EQ("", base64_decode("abc")); + + // Test illegal charactors in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("Zm:v")); + EXPECT_SLICE_EQ("", base64_decode("Zm=v")); + + // Test output_length longer than max possible output length in + // grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); + + // Test illegal charactors in grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); + } + grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 78b8808c41..44f5de8a50 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -99,6 +99,8 @@ static void expect_binary_header(const char* hdr, int binary) { } int main(int argc, char** argv) { + grpc_init(); + /* Base64 test vectors from RFC 4648, with padding removed */ /* BASE64("") = "" */ EXPECT_SLICE_EQ("", B64("")); @@ -169,5 +171,6 @@ int main(int argc, char** argv) { expect_binary_header("foo-bar", 0); expect_binary_header("-bin", 0); + grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index 2d18b72504..d2dbd4a798 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -51,8 +51,8 @@ typedef struct { /* verify that the output generated by encoding the stream matches the hexstring passed in */ -static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, - const char* expected, size_t nheaders, ...) { +static void verify(const verify_params params, const char* expected, + size_t nheaders, ...) { grpc_slice_buffer output; grpc_slice merged; grpc_slice expect = parse_hexstring(expected); @@ -77,8 +77,7 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, value_slice = grpc_slice_intern(value_slice); } e[i].md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - value_slice); + grpc_slice_intern(grpc_slice_from_static_string(key)), value_slice); } e[0].prev = nullptr; e[nheaders - 1].next = nullptr; @@ -106,11 +105,10 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, 16384, /* max_frame_size */ &stats /* stats */ }; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, - &output); + grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); merged = grpc_slice_merge(output.slices, output.count); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); if (!grpc_slice_eq(merged, expect)) { char* expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -123,11 +121,11 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, g_failure = 1; } - grpc_slice_unref_internal(exec_ctx, merged); - grpc_slice_unref_internal(exec_ctx, expect); + grpc_slice_unref_internal(merged); + grpc_slice_unref_internal(expect); } -static void test_basic_headers(grpc_exec_ctx* exec_ctx) { +static void test_basic_headers() { int i; verify_params params = { @@ -135,24 +133,22 @@ static void test_basic_headers(grpc_exec_ctx* exec_ctx) { false, false, }; - verify(exec_ctx, params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); - verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", - "b", "c"); - verify(exec_ctx, params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); - verify(exec_ctx, params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); + verify(params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); + verify(params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", "c"); + verify(params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); + verify(params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); /* flush out what's there to make a few values look very popular */ for (i = 0; i < 350; i++) { - verify(exec_ctx, params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", - "c", "a", "d"); + verify(params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", "c", "a", + "d"); } - verify(exec_ctx, params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", - "k", "v"); + verify(params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", "k", "v"); /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify(exec_ctx, params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); + verify(params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); } static void encode_int_to_str(int i, char* p) { @@ -163,7 +159,7 @@ static void encode_int_to_str(int i, char* p) { p[2] = 0; } -static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) { +static void test_decode_table_overflow() { int i; char key[3], value[3]; char* expect; @@ -192,26 +188,24 @@ static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) { } if (i > 0) { - verify(exec_ctx, params, expect, 2, "aa", "ba", key, value); + verify(params, expect, 2, "aa", "ba", key, value); } else { - verify(exec_ctx, params, expect, 1, key, value); + verify(params, expect, 1, key, value); } gpr_free(expect); } /* if the above passes, then we must have just knocked this pair out of the decoder stack, and so we'll be forced to re-encode it */ - verify(exec_ctx, params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", - "ba"); + verify(params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", "ba"); } -static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx, - const char* key, +static void verify_table_size_change_match_elem_size(const char* key, const char* value, bool use_true_binary) { grpc_slice_buffer output; grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(key)), grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, use_true_binary); size_t initial_table_size = g_compressor.table_size; @@ -235,41 +229,38 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx, use_true_binary, /* use_true_binary_metadata */ 16384, /* max_frame_size */ &stats /* stats */}; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, - &output); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); GPR_ASSERT(g_compressor.table_size == elem_size + initial_table_size); gpr_free(e); } -static void test_encode_header_size(grpc_exec_ctx* exec_ctx) { - verify_table_size_change_match_elem_size(exec_ctx, "hello", "world", false); - verify_table_size_change_match_elem_size(exec_ctx, "hello-bin", "world", - false); - verify_table_size_change_match_elem_size(exec_ctx, "true-binary-bin", +static void test_encode_header_size() { + verify_table_size_change_match_elem_size("hello", "world", false); + verify_table_size_change_match_elem_size("hello-bin", "world", false); + verify_table_size_change_match_elem_size("true-binary-bin", "I_am_true_binary_value", true); } -static void test_interned_key_indexed(grpc_exec_ctx* exec_ctx) { +static void test_interned_key_indexed() { int i; verify_params params = {false, false, true}; - verify(exec_ctx, params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, - "a", "b", "a", "c"); + verify(params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, "a", "b", + "a", "c"); for (i = 0; i < 10; i++) { - verify(exec_ctx, params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", - "b", "a", "c"); + verify(params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", "b", "a", + "c"); } } -static void run_test(void (*test)(grpc_exec_ctx* exec_ctx), const char* name) { +static void run_test(void (*test)(), const char* name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_compressor_init(&g_compressor); - test(&exec_ctx); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &g_compressor); - grpc_exec_ctx_finish(&exec_ctx); + test(); + grpc_chttp2_hpack_compressor_destroy(&g_compressor); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index 942f25e0b7..9a195daee0 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -29,9 +29,7 @@ bool squelch = true; bool leak_check = true; -static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); -} +static void onhdr(void* ud, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { @@ -39,13 +37,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - parser.on_header = onhdr; - GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_chttp2_hpack_parser_init(&parser); + parser.on_header = onhdr; + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &parser, grpc_slice_from_static_buffer(data, size))); + grpc_chttp2_hpack_parser_destroy(&parser); + } grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 82fb20aced..9d3456a873 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -32,7 +32,7 @@ typedef struct { va_list args; } test_checker; -static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { +static void onhdr(void* ud, grpc_mdelem md) { const char *ekey, *evalue; test_checker* chk = static_cast(ud); ekey = va_arg(chk->args, char*); @@ -41,7 +41,7 @@ static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { GPR_ASSERT(evalue); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } static void test_vector(grpc_chttp2_hpack_parser* parser, @@ -62,10 +62,9 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); } for (i = 0; i < nslices; i++) { @@ -80,9 +79,9 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ test_vector(&parser, mode, "400a 6375 7374 6f6d 2d6b 6579 0d63 7573" @@ -98,9 +97,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "password", "secret", NULL); /* D.2.4 */ test_vector(&parser, mode, "82", ":method", "GET", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.3.1 */ test_vector(&parser, mode, "8286 8441 0f77 7777 2e65 7861 6d70 6c65" @@ -118,9 +117,9 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.4.1 */ test_vector(&parser, mode, "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4" @@ -138,11 +137,11 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.5.1 */ test_vector(&parser, mode, "4803 3330 3258 0770 7269 7661 7465 611d" @@ -172,11 +171,11 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.6.1 */ test_vector(&parser, mode, "4882 6402 5885 aec3 771a 4b61 96d0 7abe" @@ -203,9 +202,7 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hpack_parser_destroy(&parser); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index ff7c2de538..3f3cb2ee9d 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -44,10 +44,10 @@ static void assert_index(const grpc_chttp2_hptbl* tbl, uint32_t idx, } static void test_static_lookup(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + grpc_chttp2_hptbl_init(&tbl); LOG_TEST("test_static_lookup"); assert_index(&tbl, 1, ":authority", ""); @@ -112,8 +112,7 @@ static void test_static_lookup(void) { assert_index(&tbl, 60, "via", ""); assert_index(&tbl, 61, "www-authenticate", ""); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } static void test_many_additions(void) { @@ -124,18 +123,17 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + grpc_core::ExecCtx exec_ctx; + grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 100000; i++) { grpc_mdelem elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); gpr_free(key); gpr_free(value); @@ -148,25 +146,23 @@ static void test_many_additions(void) { } } - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, const char* key, const char* value) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_core::ExecCtx exec_ctx; + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + return r; } static void test_find(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; @@ -175,21 +171,19 @@ static void test_find(void) { LOG_TEST("test_find"); - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("xyz")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("123")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), + grpc_chttp2_hptbl_init(&tbl); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("xyz")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("123")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("x"), grpc_slice_from_static_string("1")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); r = find_simple(&tbl, "abc", "123"); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); @@ -238,11 +232,10 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_slices(&exec_ctx, - grpc_slice_from_static_string("test"), + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("test"), grpc_slice_from_copied_string(buffer)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); } r = find_simple(&tbl, "abc", "123"); @@ -270,8 +263,7 @@ static void test_find(void) { GPR_ASSERT(r.index != 0); GPR_ASSERT(r.has_value == 0); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 670eae1f79..08473c72b6 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -97,7 +97,7 @@ class Client { : server_address_(server_address) {} void Connect() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_addresses* server_addresses = nullptr; grpc_error* error = grpc_blocking_resolve_address(server_address_, "80", &server_addresses); @@ -106,56 +106,53 @@ class Client { pollset_ = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(pollset_, &mu_); grpc_pollset_set* pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set, pollset_); + grpc_pollset_set_add_pollset(pollset_set, pollset_); EventState state; - grpc_tcp_client_connect(&exec_ctx, state.closure(), &endpoint_, pollset_set, + grpc_tcp_client_connect(state.closure(), &endpoint_, pollset_set, nullptr /* channel_args */, server_addresses->addrs, 1000); ASSERT_TRUE(PollUntilDone( - &exec_ctx, &state, + &state, grpc_timespec_to_millis_round_up(gpr_inf_future(GPR_CLOCK_MONOTONIC)))); ASSERT_EQ(GRPC_ERROR_NONE, state.error()); - grpc_pollset_set_destroy(&exec_ctx, pollset_set); - grpc_endpoint_add_to_pollset(&exec_ctx, endpoint_, pollset_); + grpc_pollset_set_destroy(pollset_set); + grpc_endpoint_add_to_pollset(endpoint_, pollset_); grpc_resolved_addresses_destroy(server_addresses); - grpc_exec_ctx_finish(&exec_ctx); } // Reads until an error is returned. // Returns true if an error was encountered before the deadline. bool ReadUntilError() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer read_buffer; grpc_slice_buffer_init(&read_buffer); bool retval = true; // Use a deadline of 3 seconds, which is a lot more than we should // need for a 1-second timeout, but this helps avoid flakes. - grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 3000; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 3000; while (true) { EventState state; - grpc_endpoint_read(&exec_ctx, endpoint_, &read_buffer, state.closure()); - if (!PollUntilDone(&exec_ctx, &state, deadline)) { + grpc_endpoint_read(endpoint_, &read_buffer, state.closure()); + if (!PollUntilDone(&state, deadline)) { retval = false; break; } if (state.error() != GRPC_ERROR_NONE) break; gpr_log(GPR_INFO, "client read %" PRIuPTR " bytes", read_buffer.length); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &read_buffer); + grpc_slice_buffer_reset_and_unref_internal(&read_buffer); } - grpc_endpoint_shutdown(&exec_ctx, endpoint_, + grpc_endpoint_shutdown(endpoint_, GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown")); - grpc_slice_buffer_destroy_internal(&exec_ctx, &read_buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&read_buffer); return retval; } void Shutdown() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_destroy(&exec_ctx, endpoint_); - grpc_pollset_shutdown(&exec_ctx, pollset_, + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_destroy(endpoint_); + grpc_pollset_shutdown(pollset_, GRPC_CLOSURE_CREATE(&Client::PollsetDestroy, pollset_, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } private: @@ -177,8 +174,7 @@ class Client { grpc_error* error() const { return error_; } private: - static void OnEventDone(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { + static void OnEventDone(void* arg, grpc_error* error) { gpr_log(GPR_INFO, "OnEventDone(): %s", grpc_error_string(error)); EventState* state = (EventState*)arg; state->error_ = GRPC_ERROR_REF(error); @@ -191,24 +187,23 @@ class Client { }; // Returns true if done, or false if deadline exceeded. - bool PollUntilDone(grpc_exec_ctx* exec_ctx, EventState* state, - grpc_millis deadline) { + bool PollUntilDone(EventState* state, grpc_millis deadline) { while (true) { grpc_pollset_worker* worker = nullptr; gpr_mu_lock(mu_); - GRPC_LOG_IF_ERROR("grpc_pollset_work", - grpc_pollset_work(exec_ctx, pollset_, &worker, - grpc_exec_ctx_now(exec_ctx) + 1000)); + GRPC_LOG_IF_ERROR( + "grpc_pollset_work", + grpc_pollset_work(pollset_, &worker, + grpc_core::ExecCtx::Get()->Now() + 1000)); gpr_mu_unlock(mu_); if (state != nullptr && state->done()) return true; - if (grpc_exec_ctx_now(exec_ctx) >= deadline) return false; + if (grpc_core::ExecCtx::Get()->Now() >= deadline) return false; } } - static void PollsetDestroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { + static void PollsetDestroy(void* arg, grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } diff --git a/test/core/transport/chttp2/varint_test.cc b/test/core/transport/chttp2/varint_test.cc index 413b461b3a..36760d0c72 100644 --- a/test/core/transport/chttp2/varint_test.cc +++ b/test/core/transport/chttp2/varint_test.cc @@ -18,6 +18,7 @@ #include "src/core/ext/transport/chttp2/transport/varint.h" +#include #include #include @@ -44,11 +45,13 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); TEST_VARINT(0, 1, 0, "\x00"); TEST_VARINT(128, 1, 0, "\x7f\x01"); TEST_VARINT(16384, 1, 0, "\x7f\x81\x7f"); TEST_VARINT(2097152, 1, 0, "\x7f\x81\xff\x7f"); TEST_VARINT(268435456, 1, 0, "\x7f\x81\xff\xff\x7f"); TEST_VARINT(0xffffffff, 1, 0, "\x7f\x80\xff\xff\xff\x0f"); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 11046e126e..f5894599e5 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -29,14 +29,13 @@ int g_counter; -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(error != GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; @@ -59,7 +58,7 @@ static void test_connectivity_state_name(void) { static void test_check(void) { grpc_connectivity_state_tracker tracker; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_error* error; gpr_log(GPR_DEBUG, "test_check"); grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -67,8 +66,7 @@ static void test_check(void) { GRPC_CHANNEL_IDLE); GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); } static void test_subscribe_then_unsubscribe(void) { @@ -76,23 +74,21 @@ static void test_subscribe_then_unsubscribe(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, - &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, nullptr, - closure); - grpc_exec_ctx_flush(&exec_ctx); + grpc_connectivity_state_notify_on_state_change(&tracker, nullptr, closure); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 1); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); } static void test_subscribe_then_destroy(void) { @@ -100,17 +96,18 @@ static void test_subscribe_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, - &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); + + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } @@ -120,28 +117,30 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( - &exec_ctx, &tracker, &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + &tracker, &state, closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); test_subscribe_then_destroy(); test_subscribe_with_failure_then_destroy(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index b60a9619fb..5c52ae8d5f 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -60,15 +60,15 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; m1 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m2 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m3 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("c"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(m1, m2)); GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); @@ -77,10 +77,10 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); - GRPC_MDELEM_UNREF(&exec_ctx, m1); - GRPC_MDELEM_UNREF(&exec_ctx, m2); - GRPC_MDELEM_UNREF(&exec_ctx, m3); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(m1); + GRPC_MDELEM_UNREF(m2); + GRPC_MDELEM_UNREF(m3); + grpc_shutdown(); } @@ -95,19 +95,15 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_copied_string(buffer), - intern_values))); + GRPC_MDELEM_UNREF(grpc_mdelem_from_slices( + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); } @@ -121,28 +117,28 @@ static void test_create_many_persistant_metadata(void) { gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); created[i] = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); GPR_ASSERT(grpc_mdelem_eq(md, created[i])); - GRPC_MDELEM_UNREF(&exec_ctx, md); + GRPC_MDELEM_UNREF(md); } /* cleanup phase */ for (i = 0; i < MANY; i++) { - GRPC_MDELEM_UNREF(&exec_ctx, created[i]); + GRPC_MDELEM_UNREF(created[i]); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); gpr_free(created); @@ -155,31 +151,25 @@ static void test_spin_creating_the_same_thing(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( - &exec_ctx, a = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( - &exec_ctx, b = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( - &exec_ctx, c = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); if (intern_keys && intern_values) { GPR_ASSERT(a.payload == b.payload); GPR_ASSERT(a.payload == c.payload); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); } @@ -188,16 +178,16 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; a = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); b = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); c = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(a, a)); GPR_ASSERT(grpc_mdelem_eq(b, b)); @@ -216,10 +206,10 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { GPR_ASSERT(a.payload != c.payload); GPR_ASSERT(b.payload != c.payload); } - GRPC_MDELEM_UNREF(&exec_ctx, a); - GRPC_MDELEM_UNREF(&exec_ctx, b); - GRPC_MDELEM_UNREF(&exec_ctx, c); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(a); + GRPC_MDELEM_UNREF(b); + GRPC_MDELEM_UNREF(c); + grpc_shutdown(); } @@ -235,7 +225,7 @@ static void test_things_stick_around(void) { gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); @@ -246,7 +236,7 @@ static void test_things_stick_around(void) { for (i = 0; i < nstrs; i++) { grpc_slice_ref_internal(strs[i]); - grpc_slice_unref_internal(&exec_ctx, strs[i]); + grpc_slice_unref_internal(strs[i]); } for (i = 0; i < nstrs; i++) { @@ -258,18 +248,17 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - grpc_slice_unref_internal(&exec_ctx, strs[shuf[i]]); + grpc_slice_unref_internal(strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); test = grpc_slice_intern(grpc_slice_from_static_string(buffer)); GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); - grpc_slice_unref_internal(&exec_ctx, test); + grpc_slice_unref_internal(test); gpr_free(buffer); } } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(strs); gpr_free(shuf); @@ -282,39 +271,38 @@ static void test_user_data_works(void) { gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; ud1 = static_cast(gpr_malloc(sizeof(int))); *ud1 = 1; ud2 = static_cast(gpr_malloc(sizeof(int))); *ud2 = 2; md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("123"))); grpc_mdelem_set_user_data(md, gpr_free, ud1); grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_shutdown(); } -static void verify_ascii_header_size(grpc_exec_ctx* exec_ctx, const char* key, - const char* value, bool intern_key, - bool intern_value) { +static void verify_ascii_header_size(const char* key, const char* value, + bool intern_key, bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_string(value), intern_value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); - GRPC_MDELEM_UNREF(exec_ctx, elem); + GRPC_MDELEM_UNREF(elem); } -static void verify_binary_header_size(grpc_exec_ctx* exec_ctx, const char* key, - const uint8_t* value, size_t value_len, - bool intern_key, bool intern_value) { +static void verify_binary_header_size(const char* key, const uint8_t* value, + size_t value_len, bool intern_key, + bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_buffer(value, value_len), intern_value)); GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); @@ -324,9 +312,9 @@ static void verify_binary_header_size(grpc_exec_ctx* exec_ctx, const char* key, grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice); size_t expected_size = 32 + strlen(key) + GRPC_SLICE_LENGTH(base64_encoded); GPR_ASSERT(expected_size == elem_size); - grpc_slice_unref_internal(exec_ctx, value_slice); - grpc_slice_unref_internal(exec_ctx, base64_encoded); - GRPC_MDELEM_UNREF(exec_ctx, elem); + grpc_slice_unref_internal(value_slice); + grpc_slice_unref_internal(base64_encoded); + GRPC_MDELEM_UNREF(elem); } #define BUFFER_SIZE 64 @@ -334,27 +322,23 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", intern_key, intern_value); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; uint8_t binary_value[BUFFER_SIZE] = {0}; for (uint8_t i = 0; i < BUFFER_SIZE; i++) { binary_value[i] = i; } - verify_ascii_header_size(&exec_ctx, "hello", "world", intern_key, - intern_value); - verify_ascii_header_size(&exec_ctx, "hello", - "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", intern_key, - intern_value); - verify_ascii_header_size(&exec_ctx, ":scheme", "http", intern_key, - intern_value); + verify_ascii_header_size("hello", "world", intern_key, intern_value); + verify_ascii_header_size("hello", "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + intern_key, intern_value); + verify_ascii_header_size(":scheme", "http", intern_key, intern_value); for (uint8_t i = 0; i < BUFFER_SIZE; i++) { - verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i, - intern_key, intern_value); + verify_binary_header_size("hello-bin", binary_value, i, intern_key, + intern_value); } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -362,13 +346,13 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, dup_value); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], GRPC_MDELEM_STORAGE_STATIC); grpc_mdelem q = - grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), + grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), maybe_dup(GRPC_MDVALUE(p), dup_value)); GPR_ASSERT(grpc_mdelem_eq(p, q)); if (dup_key || dup_value) { @@ -376,16 +360,16 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { } else { GPR_ASSERT(p.payload == q.payload); } - GRPC_MDELEM_UNREF(&exec_ctx, p); - GRPC_MDELEM_UNREF(&exec_ctx, q); + GRPC_MDELEM_UNREF(p); + GRPC_MDELEM_UNREF(q); } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_no_op(); for (int k = 0; k <= 1; k++) { for (int v = 0; v <= 1; v++) { @@ -400,5 +384,6 @@ int main(int argc, char** argv) { test_create_many_persistant_metadata(); test_things_stick_around(); test_user_data_works(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 7af5d12cb7..1ed6ccfba6 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -22,12 +22,11 @@ #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \ GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) -#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ - do { \ - grpc_exec_ctx my_exec_ctx = GRPC_EXEC_CTX_INIT; \ - GPR_ASSERT(grpc_http2_error_to_grpc_status(&my_exec_ctx, a, deadline) == \ - (b)); \ - grpc_exec_ctx_finish(&my_exec_ctx); \ +#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ + do { \ + grpc_core::ExecCtx exec_ctx; \ + GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ + \ } while (0) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) diff --git a/test/core/transport/stream_owned_slice_test.cc b/test/core/transport/stream_owned_slice_test.cc index e82df2117d..7831f67a04 100644 --- a/test/core/transport/stream_owned_slice_test.cc +++ b/test/core/transport/stream_owned_slice_test.cc @@ -20,12 +20,14 @@ #include "test/core/util/test_config.h" +#include #include -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); uint8_t buffer[] = "abc123"; grpc_stream_refcount r; @@ -39,5 +41,6 @@ int main(int argc, char** argv) { grpc_slice_unref(slice); GPR_ASSERT(r.refs.count == 1); + grpc_shutdown(); return 0; } diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index d9545efa49..4b35a581b1 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -40,13 +40,13 @@ typedef struct grpc_mock_endpoint { grpc_resource_user* resource_user; } grpc_mock_endpoint; -static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -54,44 +54,41 @@ static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, gpr_mu_unlock(&m->mu); } -static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } -static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read) { - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Endpoint Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->mu); - grpc_resource_user_shutdown(exec_ctx, m->resource_user); + grpc_resource_user_shutdown(m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void me_destroy(grpc_endpoint* ep) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; grpc_slice_buffer_destroy(&m->read_buffer); - grpc_resource_user_unref(exec_ctx, m->resource_user); + grpc_resource_user_unref(m->resource_user); gpr_free(m); } @@ -134,13 +131,12 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), return &m->base; } -void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice slice) { +void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read != nullptr) { grpc_slice_buffer_add(m->on_read_out, slice); - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { grpc_slice_buffer_add(&m->read_buffer, slice); diff --git a/test/core/util/mock_endpoint.h b/test/core/util/mock_endpoint.h index ccabaf7c3b..6521d3e8e8 100644 --- a/test/core/util/mock_endpoint.h +++ b/test/core/util/mock_endpoint.h @@ -23,8 +23,7 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota); -void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, - grpc_endpoint* mock_endpoint, +void grpc_mock_endpoint_put_read(grpc_endpoint* mock_endpoint, grpc_slice slice); #endif diff --git a/test/core/util/one_corpus_entry_fuzzer.cc b/test/core/util/one_corpus_entry_fuzzer.cc index c0b67da1e2..c745eb5dc6 100644 --- a/test/core/util/one_corpus_entry_fuzzer.cc +++ b/test/core/util/one_corpus_entry_fuzzer.cc @@ -18,7 +18,10 @@ #include +#include + #include +#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/load_file.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); @@ -30,10 +33,15 @@ int main(int argc, char** argv) { grpc_slice buffer; squelch = false; leak_check = false; + /* TODO(yashkt) Calling grpc_init breaks tests. Fix the tests and replace + * grpc_core::ExecCtx::GlobalInit with grpc_init and GlobalShutdown with + * grpc_shutdown */ GPR_ASSERT( GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer))); LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), GRPC_SLICE_LENGTH(buffer)); + grpc_core::ExecCtx::GlobalInit(); grpc_slice_unref(buffer); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index a9efe22b69..5f127cb960 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -49,22 +49,22 @@ struct passthru_endpoint { int halves; grpc_passthru_endpoint_stats* stats; grpc_passthru_endpoint_stats - dummy_stats; // used if constructor stats == NULL + dummy_stats; // used if constructor stats == nullptr bool shutdown; half client; half server; }; -static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { GRPC_CLOSURE_SCHED( - exec_ctx, cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); + cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); } else if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -77,8 +77,8 @@ static half* other_half(half* h) { return &h->parent->client; } -static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { half* m = other_half((half*)ep); gpr_mu_lock(&m->parent->mu); grpc_error* error = GRPC_ERROR_NONE; @@ -89,7 +89,7 @@ static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, for (size_t i = 0; i < slices->count; i++) { grpc_slice_buffer_add(m->on_read_out, grpc_slice_copy(slices->slices[i])); } - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { for (size_t i = 0; i < slices->count; i++) { @@ -98,52 +98,49 @@ static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } } gpr_mu_unlock(&m->parent->mu); - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + GRPC_CLOSURE_SCHED(cb, error); } -static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { GRPC_CLOSURE_SCHED( - exec_ctx, m->on_read, + m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } m = other_half(m); if (m->on_read) { GRPC_CLOSURE_SCHED( - exec_ctx, m->on_read, + m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->parent->mu); - grpc_resource_user_shutdown(exec_ctx, m->resource_user); + grpc_resource_user_shutdown(m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void me_destroy(grpc_endpoint* ep) { passthru_endpoint* p = ((half*)ep)->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { gpr_mu_unlock(&p->mu); gpr_mu_destroy(&p->mu); - grpc_slice_buffer_destroy_internal(exec_ctx, &p->client.read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &p->server.read_buffer); - grpc_resource_user_unref(exec_ctx, p->client.resource_user); - grpc_resource_user_unref(exec_ctx, p->server.resource_user); + grpc_slice_buffer_destroy_internal(&p->client.read_buffer); + grpc_slice_buffer_destroy_internal(&p->server.read_buffer); + grpc_resource_user_unref(p->client.resource_user); + grpc_resource_user_unref(p->server.resource_user); gpr_free(p); } else { gpr_mu_unlock(&p->mu); diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index edec50b424..7e76c8063f 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -40,22 +40,19 @@ typedef struct freereq { int done; } freereq; -static void destroy_pops_and_shutdown(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { +static void destroy_pops_and_shutdown(void* p, grpc_error* error) { grpc_pollset* pollset = grpc_polling_entity_pollset((grpc_polling_entity*)p); - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } -static void freed_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void freed_port_from_server(void* arg, grpc_error* error) { freereq* pr = (freereq*)arg; gpr_mu_lock(pr->mu); pr->done = 1; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); } @@ -65,7 +62,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_response rsp; freereq pr; char* path; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure* shutdown_closure; grpc_init(); @@ -87,30 +84,30 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_context_init(&context); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/free"); - grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_exec_ctx_flush(&exec_ctx); + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.done = 1; } } gpr_mu_unlock(pr.mu); - grpc_httpcli_context_destroy(&exec_ctx, &context); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), + grpc_httpcli_context_destroy(&context); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), shutdown_closure); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(path); grpc_http_response_destroy(&rsp); @@ -127,8 +124,7 @@ typedef struct portreq { grpc_httpcli_response response; } portreq; -static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void got_port_from_server(void* arg, grpc_error* error) { size_t i; int port = 0; portreq* pr = (portreq*)arg; @@ -154,8 +150,7 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, pr->port = 0; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); return; } @@ -172,12 +167,12 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, memset(&pr->response, 0, sizeof(pr->response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/pick_retry"); - grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req, - grpc_exec_ctx_now(exec_ctx) + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(pr->ctx, &pr->pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, pr, grpc_schedule_on_exec_ctx), &pr->response); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); return; } GPR_ASSERT(response); @@ -191,8 +186,7 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, pr->port = port; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); } @@ -200,53 +194,55 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure* shutdown_closure; grpc_init(); + { + grpc_core::ExecCtx exec_ctx; + memset(&pr, 0, sizeof(pr)); + memset(&req, 0, sizeof(req)); + grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(pollset, &pr.mu); + pr.pops = grpc_polling_entity_create_from_pollset(pollset); + shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); + pr.port = -1; + pr.server = const_cast(GRPC_PORT_SERVER_ADDRESS); + pr.ctx = &context; + + req.host = const_cast(GRPC_PORT_SERVER_ADDRESS); + req.http.path = const_cast("/get"); - memset(&pr, 0, sizeof(pr)); - memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(pollset, &pr.mu); - pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, - grpc_schedule_on_exec_ctx); - pr.port = -1; - pr.server = const_cast(GRPC_PORT_SERVER_ADDRESS); - pr.ctx = &context; + grpc_httpcli_context_init(&context); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("port_server_client/pick"); + grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + GRPC_CLOSURE_CREATE(got_port_from_server, &pr, + grpc_schedule_on_exec_ctx), + &pr.response); + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::Get()->Flush(); + gpr_mu_lock(pr.mu); + while (pr.port == -1) { + grpc_pollset_worker* worker = nullptr; + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + pr.port = 0; + } + } + gpr_mu_unlock(pr.mu); - req.host = const_cast(GRPC_PORT_SERVER_ADDRESS); - req.http.path = const_cast("/get"); + grpc_http_response_destroy(&pr.response); + grpc_httpcli_context_destroy(&context); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), + shutdown_closure); - grpc_httpcli_context_init(&context); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("port_server_client/pick"); - grpc_httpcli_get( - &exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, - GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), - &pr.response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(pr.mu); - while (pr.port == -1) { - grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { - pr.port = 0; - } + grpc_core::ExecCtx::Get()->Flush(); } - gpr_mu_unlock(pr.mu); - - grpc_http_response_destroy(&pr.response); - grpc_httpcli_context_destroy(&exec_ctx, &context); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - shutdown_closure); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return pr.port; diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index 4775b074eb..bcafc4e898 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -55,7 +55,7 @@ static void pretty_print_backoffs(reconnect_server* server) { } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -65,9 +65,9 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; peer = grpc_endpoint_get_peer(tcp); - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); if (peer) { last_colon = strrchr(peer, ':'); if (server->peer == nullptr) { diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index da34da6fd0..5f6af4e707 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -33,8 +33,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static void on_server_destroyed(grpc_exec_ctx* exec_ctx, void* data, - grpc_error* error) { +static void on_server_destroyed(void* data, grpc_error* error) { test_tcp_server* server = static_cast(data); server->shutdown = 1; } @@ -56,51 +55,46 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int port_added; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; addr->sin_family = AF_INET; addr->sin_port = htons((uint16_t)port); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); - grpc_error* error = grpc_tcp_server_create( - &exec_ctx, &server->shutdown_complete, nullptr, &server->tcp_server); + grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, + nullptr, &server->tcp_server); GPR_ASSERT(error == GRPC_ERROR_NONE); error = grpc_tcp_server_add_port(server->tcp_server, &resolved_addr, &port_added); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(port_added == port); - grpc_tcp_server_start(&exec_ctx, server->tcp_server, &server->pollset, 1, + grpc_tcp_server_start(server->tcp_server, &server->pollset, 1, server->on_connect, server->cb_data); gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port); - - grpc_exec_ctx_finish(&exec_ctx); } void test_tcp_server_poll(test_tcp_server* server, int seconds) { grpc_pollset_worker* worker = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); - GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, server->pollset, &worker, deadline)); + GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(server->pollset, &worker, deadline)); gpr_mu_unlock(server->mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -static void finish_pollset(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(arg)); +static void do_nothing(void* arg, grpc_error* error) {} +static void finish_pollset(void* arg, grpc_error* error) { + grpc_pollset_destroy(static_cast(arg)); } void test_tcp_server_destroy(test_tcp_server* server) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; - grpc_tcp_server_unref(&exec_ctx, server->tcp_server); + grpc_tcp_server_unref(server->tcp_server); GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), @@ -109,10 +103,10 @@ void test_tcp_server_destroy(test_tcp_server* server) { gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), shutdown_deadline) < 0) { test_tcp_server_poll(server, 1); } - grpc_pollset_shutdown(&exec_ctx, server->pollset, + grpc_pollset_shutdown(server->pollset, GRPC_CLOSURE_CREATE(finish_pollset, server->pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index 4544fb7f49..f95ed62463 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -45,24 +45,23 @@ typedef struct { grpc_closure* write_cb; } trickle_endpoint; -static void te_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void te_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_read(exec_ctx, te->wrapped, slices, cb); + grpc_endpoint_read(te->wrapped, slices, cb); } -static void maybe_call_write_cb_locked(grpc_exec_ctx* exec_ctx, - trickle_endpoint* te) { +static void maybe_call_write_cb_locked(trickle_endpoint* te) { if (te->write_cb != nullptr && (te->error != GRPC_ERROR_NONE || te->write_buffer.length <= WRITE_BUFFER_SIZE)) { - GRPC_CLOSURE_SCHED(exec_ctx, te->write_cb, GRPC_ERROR_REF(te->error)); + GRPC_CLOSURE_SCHED(te->write_cb, GRPC_ERROR_REF(te->error)); te->write_cb = nullptr; } } -static void te_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); GPR_ASSERT(te->write_cb == nullptr); @@ -74,47 +73,44 @@ static void te_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_slice_copy(slices->slices[i])); } te->write_cb = cb; - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); gpr_mu_unlock(&te->mu); } -static void te_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) { +static void te_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset(exec_ctx, te->wrapped, pollset); + grpc_endpoint_add_to_pollset(te->wrapped, pollset); } -static void te_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void te_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset_set(exec_ctx, te->wrapped, pollset_set); + grpc_endpoint_add_to_pollset_set(te->wrapped, pollset_set); } -static void te_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void te_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_delete_from_pollset_set(exec_ctx, te->wrapped, pollset_set); + grpc_endpoint_delete_from_pollset_set(te->wrapped, pollset_set); } -static void te_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (te->error == GRPC_ERROR_NONE) { te->error = GRPC_ERROR_REF(why); } - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); gpr_mu_unlock(&te->mu); - grpc_endpoint_shutdown(exec_ctx, te->wrapped, why); + grpc_endpoint_shutdown(te->wrapped, why); } -static void te_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void te_destroy(grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_destroy(exec_ctx, te->wrapped); + grpc_endpoint_destroy(te->wrapped); gpr_mu_destroy(&te->mu); - grpc_slice_buffer_destroy_internal(exec_ctx, &te->write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &te->writing_buffer); + grpc_slice_buffer_destroy_internal(&te->write_buffer); + grpc_slice_buffer_destroy_internal(&te->writing_buffer); GRPC_ERROR_UNREF(te->error); gpr_free(te); } @@ -134,8 +130,7 @@ static int te_get_fd(grpc_endpoint* ep) { return grpc_endpoint_get_fd(te->wrapped); } -static void te_finish_write(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void te_finish_write(void* arg, grpc_error* error) { trickle_endpoint* te = (trickle_endpoint*)arg; gpr_mu_lock(&te->mu); te->writing = false; @@ -173,8 +168,7 @@ static double ts2dbl(gpr_timespec s) { return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; } -size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep) { +size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (!te->writing && te->write_buffer.length > 0) { @@ -189,9 +183,9 @@ size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, te->writing = true; te->last_write = now; grpc_endpoint_write( - exec_ctx, te->wrapped, &te->writing_buffer, + te->wrapped, &te->writing_buffer, GRPC_CLOSURE_CREATE(te_finish_write, te, grpc_schedule_on_exec_ctx)); - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); } } size_t backlog = te->write_buffer.length; diff --git a/test/core/util/trickle_endpoint.h b/test/core/util/trickle_endpoint.h index 11c113bda8..cd07de905a 100644 --- a/test/core/util/trickle_endpoint.h +++ b/test/core/util/trickle_endpoint.h @@ -25,8 +25,7 @@ grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second); /* Allow up to \a bytes through the endpoint. Returns the new backlog. */ -size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, - grpc_endpoint* endpoint); +size_t grpc_trickle_endpoint_trickle(grpc_endpoint* endpoint); size_t grpc_trickle_get_backlog(grpc_endpoint* endpoint); diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index 0954b28df0..e829d5278b 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -212,13 +212,13 @@ class ClientChannelStressTest { }; void SetNextResolution(const std::vector& address_data) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port); - grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri( addresses, i, lb_uri, address_data[i].is_balancer, @@ -228,10 +228,9 @@ class ClientChannelStressTest { } grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args fake_result = {1, &fake_addresses}; - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator_, &fake_result); - grpc_lb_addresses_destroy(&exec_ctx, addresses); - grpc_exec_ctx_finish(&exec_ctx); + grpc_fake_resolver_response_generator_set_response(response_generator_, + &fake_result); + grpc_lb_addresses_destroy(addresses); } void KeepSendingRequests() { diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index d6ed2e5aa2..f330c01281 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -249,5 +249,8 @@ TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/cpp/common/channel_filter_test.cc b/test/cpp/common/channel_filter_test.cc index 638518107b..7bdd53f9e7 100644 --- a/test/cpp/common/channel_filter_test.cc +++ b/test/cpp/common/channel_filter_test.cc @@ -28,7 +28,7 @@ class MyChannelData : public ChannelData { public: MyChannelData() {} - grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_error* Init(grpc_channel_element* elem, grpc_channel_element_args* args) override { (void)args->channel_args; // Make sure field is available. return GRPC_ERROR_NONE; @@ -39,7 +39,7 @@ class MyCallData : public CallData { public: MyCallData() {} - grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_error* Init(grpc_call_element* elem, const grpc_call_element_args* args) override { (void)args->path; // Make sure field is available. return GRPC_ERROR_NONE; diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index f8bb12fde1..e6e6e71f42 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -112,13 +112,13 @@ class ClientLbEnd2endTest : public ::testing::Test { } void SetNextResolution(const std::vector& ports) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(ports.size(), nullptr); for (size_t i = 0; i < ports.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", ports[i]); - grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri(addresses, i, lb_uri, false /* is balancer */, @@ -130,11 +130,10 @@ class ClientLbEnd2endTest : public ::testing::Test { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* fake_result = grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1); - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator_, fake_result); - grpc_channel_args_destroy(&exec_ctx, fake_result); - grpc_lb_addresses_destroy(&exec_ctx, addresses); - grpc_exec_ctx_finish(&exec_ctx); + grpc_fake_resolver_response_generator_set_response(response_generator_, + fake_result); + grpc_channel_args_destroy(fake_result); + grpc_lb_addresses_destroy(addresses); } void ResetStub(const grpc::string& lb_policy_name = "") { diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index f260ea0016..c4430379db 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -100,7 +100,7 @@ int GetCallCounterValue() { class ChannelDataImpl : public ChannelData { public: - grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_error* Init(grpc_channel_element* elem, grpc_channel_element_args* args) { IncrementConnectionCounter(); return GRPC_ERROR_NONE; @@ -109,13 +109,12 @@ class ChannelDataImpl : public ChannelData { class CallDataImpl : public CallData { public: - void StartTransportStreamOpBatch(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, + void StartTransportStreamOpBatch(grpc_call_element* elem, TransportStreamOpBatch* op) override { // Incrementing the counter could be done from Init(), but we want // to test that the individual methods are actually called correctly. if (op->recv_initial_metadata() != nullptr) IncrementCallCounter(); - grpc_call_next_op(exec_ctx, elem, op->op()); + grpc_call_next_op(elem, op->op()); } }; diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index bbf3da4663..d4ee6b429f 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -454,13 +454,13 @@ class GrpclbEnd2endTest : public ::testing::Test { }; void SetNextResolution(const std::vector& address_data) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_lb_addresses* addresses = grpc_lb_addresses_create(address_data.size(), nullptr); for (size_t i = 0; i < address_data.size(); ++i) { char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port); - grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri( addresses, i, lb_uri, address_data[i].is_balancer, @@ -470,10 +470,9 @@ class GrpclbEnd2endTest : public ::testing::Test { } grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args fake_result = {1, &fake_addresses}; - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator_, &fake_result); - grpc_lb_addresses_destroy(&exec_ctx, addresses); - grpc_exec_ctx_finish(&exec_ctx); + grpc_fake_resolver_response_generator_set_response(response_generator_, + &fake_result); + grpc_lb_addresses_destroy(addresses); } const std::vector GetBackendPorts(const size_t start_index = 0) const { diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index 7b62080b49..a494d6f519 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -17,6 +17,7 @@ */ #include +#include #include #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -135,5 +136,8 @@ TEST_F(GrpclbTest, ParseResponseServerList) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index a469fbb7e3..64c53b1442 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -562,7 +562,7 @@ static void perform_request(client_fixture* cf) { #define BALANCERS_NAME "lb.name" static void setup_client(const server_fixture* lb_server, const server_fixture* backends, client_fixture* cf) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; char* expected_target_names = nullptr; const char* backends_name = lb_server->servers_hostport; @@ -574,7 +574,7 @@ static void setup_client(const server_fixture* lb_server, grpc_lb_addresses* addresses = grpc_lb_addresses_create(1, nullptr); char* lb_uri_str; gpr_asprintf(&lb_uri_str, "ipv4:%s", lb_server->servers_hostport); - grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); + grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str, true); GPR_ASSERT(lb_uri != nullptr); grpc_lb_addresses_set_address_from_uri(addresses, 0, lb_uri, true, lb_server->balancer_name, nullptr); @@ -586,7 +586,7 @@ static void setup_client(const server_fixture* lb_server, grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* fake_result = grpc_channel_args_copy_and_add(nullptr, &fake_addresses, 1); - grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); const grpc_arg new_args[] = { grpc_fake_transport_expected_targets_arg(expected_target_names), @@ -601,13 +601,12 @@ static void setup_client(const server_fixture* lb_server, grpc_fake_transport_security_credentials_create(); cf->client = grpc_secure_channel_create(fake_creds, cf->server_uri, args, nullptr); - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator, fake_result); - grpc_channel_args_destroy(&exec_ctx, fake_result); - grpc_channel_credentials_unref(&exec_ctx, fake_creds); - grpc_channel_args_destroy(&exec_ctx, args); + grpc_fake_resolver_response_generator_set_response(response_generator, + fake_result); + grpc_channel_args_destroy(fake_result); + grpc_channel_credentials_unref(fake_creds); + grpc_channel_args_destroy(args); grpc_fake_resolver_response_generator_unref(response_generator); - grpc_exec_ctx_finish(&exec_ctx); } static void teardown_client(client_fixture* cf) { diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index a45c577320..5c2c38c27d 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -311,12 +311,9 @@ static void BM_LameChannelCallCreateCoreSeparateBatch(benchmark::State& state) { } BENCHMARK(BM_LameChannelCallCreateCoreSeparateBatch); -static void FilterDestroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - gpr_free(arg); -} +static void FilterDestroy(void* arg, grpc_error* error) { gpr_free(arg); } -static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void DoNothing(void* arg, grpc_error* error) {} class FakeClientChannelFactory : public grpc_client_channel_factory { public: @@ -324,15 +321,12 @@ class FakeClientChannelFactory : public grpc_client_channel_factory { private: static void NoRef(grpc_client_channel_factory* factory) {} - static void NoUnref(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory) {} - static grpc_subchannel* CreateSubchannel(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory, + static void NoUnref(grpc_client_channel_factory* factory) {} + static grpc_subchannel* CreateSubchannel(grpc_client_channel_factory* factory, const grpc_subchannel_args* args) { return nullptr; } - static grpc_channel* CreateClientChannel(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory, + static grpc_channel* CreateClientChannel(grpc_client_channel_factory* factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args) { @@ -366,36 +360,32 @@ struct Fixture { namespace dummy_filter { -static void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void StartTransportStreamOp(grpc_call_element* elem, grpc_transport_stream_op_batch* op) {} -static void StartTransportOp(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void StartTransportOp(grpc_channel_element* elem, grpc_transport_op* op) {} -static grpc_error* InitCallElem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* InitCallElem(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_polling_entity* pollent) {} -static void DestroyCallElem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void DestroyCallElem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_sched_closure) {} -grpc_error* InitChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, +grpc_error* InitChannelElem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -void DestroyChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} +void DestroyChannelElem(grpc_channel_element* elem) {} -void GetChannelInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, +void GetChannelInfo(grpc_channel_element* elem, const grpc_channel_info* channel_info) {} static const grpc_channel_filter dummy_filter = {StartTransportStreamOp, @@ -422,41 +412,38 @@ size_t sizeof_stream; /* = sizeof(transport stream) */ const char* name; /* implementation of grpc_transport_init_stream */ -int InitStream(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_stream_refcount* refcount, - const void* server_data, gpr_arena* arena) { +int InitStream(grpc_transport* self, grpc_stream* stream, + grpc_stream_refcount* refcount, const void* server_data, + gpr_arena* arena) { return 0; } /* implementation of grpc_transport_set_pollset */ -void SetPollset(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_pollset* pollset) {} +void SetPollset(grpc_transport* self, grpc_stream* stream, + grpc_pollset* pollset) {} /* implementation of grpc_transport_set_pollset */ -void SetPollsetSet(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_pollset_set* pollset_set) {} +void SetPollsetSet(grpc_transport* self, grpc_stream* stream, + grpc_pollset_set* pollset_set) {} /* implementation of grpc_transport_perform_stream_op */ -void PerformStreamOp(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_transport_stream_op_batch* op) { - GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_NONE); +void PerformStreamOp(grpc_transport* self, grpc_stream* stream, + grpc_transport_stream_op_batch* op) { + GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_NONE); } /* implementation of grpc_transport_perform_op */ -void PerformOp(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_transport_op* op) {} +void PerformOp(grpc_transport* self, grpc_transport_op* op) {} /* implementation of grpc_transport_destroy_stream */ -void DestroyStream(grpc_exec_ctx* exec_ctx, grpc_transport* self, - grpc_stream* stream, grpc_closure* then_sched_closure) {} +void DestroyStream(grpc_transport* self, grpc_stream* stream, + grpc_closure* then_sched_closure) {} /* implementation of grpc_transport_destroy */ -void Destroy(grpc_exec_ctx* exec_ctx, grpc_transport* self) {} +void Destroy(grpc_transport* self) {} /* implementation of grpc_transport_get_endpoint */ -grpc_endpoint* GetEndpoint(grpc_exec_ctx* exec_ctx, grpc_transport* self) { - return nullptr; -} +grpc_endpoint* GetEndpoint(grpc_transport* self) { return nullptr; } static const grpc_transport_vtable dummy_transport_vtable = { 0, "dummy_http2", InitStream, @@ -472,8 +459,8 @@ class NoOp { public: class Op { public: - Op(grpc_exec_ctx* exec_ctx, NoOp* p, grpc_call_stack* s) {} - void Finish(grpc_exec_ctx* exec_ctx) {} + Op(NoOp* p, grpc_call_stack* s) {} + void Finish() {} }; }; @@ -489,13 +476,11 @@ class SendEmptyMetadata { class Op { public: - Op(grpc_exec_ctx* exec_ctx, SendEmptyMetadata* p, grpc_call_stack* s) { + Op(SendEmptyMetadata* p, grpc_call_stack* s) { grpc_metadata_batch_init(&batch_); p->op_payload_.send_initial_metadata.send_initial_metadata = &batch_; } - void Finish(grpc_exec_ctx* exec_ctx) { - grpc_metadata_batch_destroy(exec_ctx, &batch_); - } + void Finish() { grpc_metadata_batch_destroy(&batch_); } private: grpc_metadata_batch batch_; @@ -536,20 +521,20 @@ static void BM_IsolatedFilter(benchmark::State& state) { label << " #has_dummy_filter"; } - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; size_t channel_size = grpc_channel_stack_size( filters.size() == 0 ? nullptr : &filters[0], filters.size()); grpc_channel_stack* channel_stack = static_cast(gpr_zalloc(channel_size)); GPR_ASSERT(GRPC_LOG_IF_ERROR( "channel_stack_init", - grpc_channel_stack_init(&exec_ctx, 1, FilterDestroy, channel_stack, - &filters[0], filters.size(), &channel_args, + grpc_channel_stack_init(1, FilterDestroy, channel_stack, &filters[0], + filters.size(), &channel_args, fixture.flags & REQUIRES_TRANSPORT ? &dummy_transport::dummy_transport : nullptr, "CHANNEL", channel_stack))); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); grpc_call_stack* call_stack = static_cast(gpr_zalloc(channel_stack->call_stack_size)); grpc_millis deadline = GRPC_MILLIS_INF_FUTURE; @@ -568,12 +553,12 @@ static void BM_IsolatedFilter(benchmark::State& state) { call_args.arena = gpr_arena_create(kArenaSize); while (state.KeepRunning()) { GPR_TIMER_SCOPE("BenchmarkCycle", 0); - GRPC_ERROR_UNREF(grpc_call_stack_init(&exec_ctx, channel_stack, 1, - DoNothing, nullptr, &call_args)); - typename TestOp::Op op(&exec_ctx, &test_op_data, call_stack); - grpc_call_stack_destroy(&exec_ctx, call_stack, &final_info, nullptr); - op.Finish(&exec_ctx); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_ERROR_UNREF( + grpc_call_stack_init(channel_stack, 1, DoNothing, nullptr, &call_args)); + typename TestOp::Op op(&test_op_data, call_stack); + grpc_call_stack_destroy(call_stack, &final_info, nullptr); + op.Finish(); + grpc_core::ExecCtx::Get()->Flush(); // recreate arena every 64k iterations to avoid oom if (0 == (state.iterations() & 0xffff)) { gpr_arena_destroy(call_args.arena); @@ -581,8 +566,8 @@ static void BM_IsolatedFilter(benchmark::State& state) { } } gpr_arena_destroy(call_args.arena); - grpc_channel_stack_destroy(&exec_ctx, channel_stack); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_stack_destroy(channel_stack); + gpr_free(channel_stack); gpr_free(call_stack); @@ -632,59 +617,55 @@ typedef struct { grpc_call_combiner* call_combiner; } call_data; -static void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void StartTransportStreamOp(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = static_cast(elem->call_data); if (op->recv_initial_metadata) { GRPC_CALL_COMBINER_START( - exec_ctx, calld->call_combiner, + calld->call_combiner, op->payload->recv_initial_metadata.recv_initial_metadata_ready, GRPC_ERROR_NONE, "recv_initial_metadata"); } if (op->recv_message) { - GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, + GRPC_CALL_COMBINER_START(calld->call_combiner, op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE, "recv_message"); } - GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_complete, GRPC_ERROR_NONE); } -static void StartTransportOp(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static void StartTransportOp(grpc_channel_element* elem, grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } -static grpc_error* InitCallElem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* InitCallElem(grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = static_cast(elem->call_data); calld->call_combiner = args->call_combiner; return GRPC_ERROR_NONE; } -static void SetPollsetOrPollsetSet(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_polling_entity* pollent) {} -static void DestroyCallElem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void DestroyCallElem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* then_sched_closure) { - GRPC_CLOSURE_SCHED(exec_ctx, then_sched_closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(then_sched_closure, GRPC_ERROR_NONE); } -grpc_error* InitChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, +grpc_error* InitChannelElem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -void DestroyChannelElem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) {} +void DestroyChannelElem(grpc_channel_element* elem) {} -void GetChannelInfo(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, +void GetChannelInfo(grpc_channel_element* elem, const grpc_channel_info* channel_info) {} static const grpc_channel_filter isolated_call_filter = { @@ -711,10 +692,8 @@ class IsolatedCallFixture : public TrackCounters { builder, &isolated_call_filter::isolated_call_filter, nullptr, nullptr)); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - channel_ = grpc_channel_create_with_builder(&exec_ctx, builder, - GRPC_CLIENT_CHANNEL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + channel_ = grpc_channel_create_with_builder(builder, GRPC_CLIENT_CHANNEL); } cq_ = grpc_completion_queue_create_for_next(nullptr); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 3fff8b02d6..4b7310389c 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -50,22 +50,22 @@ static grpc_slice MakeSlice(std::vector bytes) { static void BM_HpackEncoderInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_compressor c; while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); - grpc_exec_ctx_flush(&exec_ctx); + grpc_chttp2_hpack_compressor_destroy(&c); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_HpackEncoderInitDestroy); static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_millis saved_now = grpc_exec_ctx_now(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_millis saved_now = grpc_core::ExecCtx::Get()->Now(); grpc_metadata_batch b; grpc_metadata_batch_init(&b); @@ -85,14 +85,13 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) { (size_t)1024, &stats, }; - grpc_chttp2_encode_header(&exec_ctx, &c, nullptr, 0, &b, &hopt, &outbuf); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_flush(&exec_ctx); + grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); + grpc_slice_buffer_reset_and_unref_internal(&outbuf); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_metadata_batch_destroy(&exec_ctx, &b); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_finish(&exec_ctx); + grpc_metadata_batch_destroy(&b); + grpc_chttp2_hpack_compressor_destroy(&c); + grpc_slice_buffer_destroy_internal(&outbuf); std::ostringstream label; label << "framing_bytes/iter:" @@ -109,17 +108,16 @@ BENCHMARK(BM_HpackEncoderEncodeDeadline); template static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; static bool logged_representative_output = false; grpc_metadata_batch b; grpc_metadata_batch_init(&b); - std::vector elems = Fixture::GetElems(&exec_ctx); + std::vector elems = Fixture::GetElems(); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", - grpc_metadata_batch_add_tail(&exec_ctx, &b, &storage[i], elems[i]))); + "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); } grpc_chttp2_hpack_compressor c; @@ -136,7 +134,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { (size_t)state.range(1), &stats, }; - grpc_chttp2_encode_header(&exec_ctx, &c, nullptr, 0, &b, &hopt, &outbuf); + grpc_chttp2_encode_header(&c, nullptr, 0, &b, &hopt, &outbuf); if (!logged_representative_output && state.iterations() > 3) { logged_representative_output = true; for (size_t i = 0; i < outbuf.count; i++) { @@ -145,13 +143,12 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) { gpr_free(s); } } - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_flush(&exec_ctx); + grpc_slice_buffer_reset_and_unref_internal(&outbuf); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_metadata_batch_destroy(&exec_ctx, &b); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_finish(&exec_ctx); + grpc_metadata_batch_destroy(&b); + grpc_chttp2_hpack_compressor_destroy(&c); + grpc_slice_buffer_destroy_internal(&outbuf); std::ostringstream label; label << "framing_bytes/iter:" @@ -169,15 +166,13 @@ namespace hpack_encoder_fixtures { class EmptyBatch { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { - return {}; - } + static std::vector GetElems() { return {}; } }; class SingleStaticElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return {GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE}; } }; @@ -185,9 +180,9 @@ class SingleStaticElem { class SingleInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("def")))}; } }; @@ -196,10 +191,10 @@ template class SingleInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { grpc_slice bytes = MakeBytes(); std::vector out = {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), + grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), grpc_slice_intern(bytes))}; grpc_slice_unref(bytes); return out; @@ -218,9 +213,9 @@ class SingleInternedBinaryElem { class SingleInternedKeyElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_from_static_string("def"))}; } }; @@ -228,9 +223,8 @@ class SingleInternedKeyElem { class SingleNonInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { - return {grpc_mdelem_from_slices(exec_ctx, - grpc_slice_from_static_string("abc"), + static std::vector GetElems() { + return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), grpc_slice_from_static_string("def"))}; } }; @@ -239,9 +233,9 @@ template class SingleNonInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { - return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_from_static_string("abc-bin"), MakeBytes())}; + static std::vector GetElems() { + return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc-bin"), + MakeBytes())}; } private: @@ -257,21 +251,21 @@ class SingleNonInternedBinaryElem { class RepresentativeClientInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_PATH, + GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP, GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_USER_AGENT, + GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -283,18 +277,18 @@ class RepresentativeClientInitialMetadata { class MoreRepresentativeClientInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, + grpc_mdelem_from_slices(GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string( "/grpc.test.FooService/BarMethod"))), - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_TRACE_BIN, + GRPC_MDSTR_GRPC_TRACE_BIN, grpc_slice_from_static_string("\x00\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f" "\x10\x11\x12\x13\x14\x15\x16\x17\x18" @@ -303,7 +297,7 @@ class MoreRepresentativeClientInitialMetadata { "\x29\x2a\x2b\x2c\x2d\x2e\x2f" "\x30")), grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_TAGS_BIN, + GRPC_MDSTR_GRPC_TAGS_BIN, grpc_slice_from_static_string("\x00\x01\x02\x03\x04\x05\x06\x07\x08" "\x09\x0a\x0b\x0c\x0d\x0e\x0f" "\x10\x11\x12\x13")), @@ -311,7 +305,7 @@ class MoreRepresentativeClientInitialMetadata { GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_USER_AGENT, + GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -320,7 +314,7 @@ class MoreRepresentativeClientInitialMetadata { class RepresentativeServerInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return {GRPC_MDELEM_STATUS_200, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP}; @@ -330,7 +324,7 @@ class RepresentativeServerInitialMetadata { class RepresentativeServerTrailingMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return {GRPC_MDELEM_GRPC_STATUS_0}; } }; @@ -431,48 +425,45 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, static void BM_HpackParserInitDestroy(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_parser p; while (state.KeepRunning()) { - grpc_chttp2_hpack_parser_init(&exec_ctx, &p); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); - grpc_exec_ctx_flush(&exec_ctx); + grpc_chttp2_hpack_parser_init(&p); + grpc_chttp2_hpack_parser_destroy(&p); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_HpackParserInitDestroy); -static void UnrefHeader(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); +static void UnrefHeader(void* user_data, grpc_mdelem md) { + GRPC_MDELEM_UNREF(md); } -template +template static void BM_HpackParserParseHeader(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; std::vector init_slices = Fixture::GetInitSlices(); std::vector benchmark_slices = Fixture::GetBenchmarkSlices(); grpc_chttp2_hpack_parser p; - grpc_chttp2_hpack_parser_init(&exec_ctx, &p); + grpc_chttp2_hpack_parser_init(&p); p.on_header = OnHeader; p.on_header_user_data = nullptr; for (auto slice : init_slices) { - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); } while (state.KeepRunning()) { for (auto slice : benchmark_slices) { - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_chttp2_hpack_parser_parse(&p, slice)); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } for (auto slice : init_slices) grpc_slice_unref(slice); for (auto slice : benchmark_slices) grpc_slice_unref(slice); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hpack_parser_destroy(&p); + track_counters.Finish(state); } @@ -769,8 +760,7 @@ class RepresentativeServerTrailingMetadata { static void free_timeout(void* p) { gpr_free(p); } // New implementation. -static void OnHeaderNew(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_mdelem md) { +static void OnHeaderNew(void* user_data, grpc_mdelem md) { if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT)) { grpc_millis* cached_timeout = static_cast(grpc_mdelem_get_user_data(md, free_timeout)); @@ -793,7 +783,7 @@ static void OnHeaderNew(grpc_exec_ctx* exec_ctx, void* user_data, } } benchmark::DoNotOptimize(timeout); - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } else { GPR_ASSERT(0); } diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index be4da4d0bd..fcb1677d09 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -58,7 +58,7 @@ class DummyEndpoint : public grpc_endpoint { ru_ = grpc_resource_user_create(Library::get().rq(), "dummy_endpoint"); } - void PushInput(grpc_exec_ctx* exec_ctx, grpc_slice slice) { + void PushInput(grpc_slice slice) { if (read_cb_ == nullptr) { GPR_ASSERT(!have_slice_); buffered_slice_ = slice; @@ -66,7 +66,7 @@ class DummyEndpoint : public grpc_endpoint { return; } grpc_slice_buffer_add(slices_, slice); - GRPC_CLOSURE_SCHED(exec_ctx, read_cb_, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(read_cb_, GRPC_ERROR_NONE); read_cb_ = nullptr; } @@ -77,50 +77,45 @@ class DummyEndpoint : public grpc_endpoint { bool have_slice_ = false; grpc_slice buffered_slice_; - void QueueRead(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* slices, - grpc_closure* cb) { + void QueueRead(grpc_slice_buffer* slices, grpc_closure* cb) { GPR_ASSERT(read_cb_ == nullptr); if (have_slice_) { have_slice_ = false; grpc_slice_buffer_add(slices, buffered_slice_); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); return; } read_cb_ = cb; slices_ = slices; } - static void read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { - static_cast(ep)->QueueRead(exec_ctx, slices, cb); + static void read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { + static_cast(ep)->QueueRead(slices, cb); } - static void write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + static void write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } static grpc_workqueue* get_workqueue(grpc_endpoint* ep) { return nullptr; } - static void add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) {} + static void add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} - static void add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset_set* pollset) {} + static void add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) { + } - static void delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, + static void delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} - static void shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { - grpc_resource_user_shutdown(exec_ctx, static_cast(ep)->ru_); - GRPC_CLOSURE_SCHED(exec_ctx, static_cast(ep)->read_cb_, - why); + static void shutdown(grpc_endpoint* ep, grpc_error* why) { + grpc_resource_user_shutdown(static_cast(ep)->ru_); + GRPC_CLOSURE_SCHED(static_cast(ep)->read_cb_, why); } - static void destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { - grpc_resource_user_unref(exec_ctx, static_cast(ep)->ru_); + static void destroy(grpc_endpoint* ep) { + grpc_resource_user_unref(static_cast(ep)->ru_); delete static_cast(ep); } @@ -136,29 +131,24 @@ class Fixture { Fixture(const grpc::ChannelArguments& args, bool client) { grpc_channel_args c_args = args.c_channel_args(); ep_ = new DummyEndpoint; - t_ = grpc_create_chttp2_transport(exec_ctx(), &c_args, ep_, client); - grpc_chttp2_transport_start_reading(exec_ctx(), t_, nullptr, nullptr); + t_ = grpc_create_chttp2_transport(&c_args, ep_, client); + grpc_chttp2_transport_start_reading(t_, nullptr, nullptr); FlushExecCtx(); } - void FlushExecCtx() { grpc_exec_ctx_flush(&exec_ctx_); } + void FlushExecCtx() { grpc_core::ExecCtx::Get()->Flush(); } - ~Fixture() { - grpc_transport_destroy(&exec_ctx_, t_); - grpc_exec_ctx_finish(&exec_ctx_); - } + ~Fixture() { grpc_transport_destroy(t_); } grpc_chttp2_transport* chttp2_transport() { return reinterpret_cast(t_); } grpc_transport* transport() { return t_; } - grpc_exec_ctx* exec_ctx() { return &exec_ctx_; } - void PushInput(grpc_slice slice) { ep_->PushInput(exec_ctx(), slice); } + void PushInput(grpc_slice slice) { ep_->PushInput(slice); } private: DummyEndpoint* ep_; - grpc_exec_ctx exec_ctx_ = GRPC_EXEC_CTX_INIT; grpc_transport* t_; }; @@ -175,8 +165,8 @@ std::unique_ptr MakeClosure( GRPC_CLOSURE_INIT(this, Execute, this, sched); } F f_; - static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - static_cast(arg)->f_(exec_ctx, error); + static void Execute(void* arg, grpc_error* error) { + static_cast(arg)->f_(error); } }; return std::unique_ptr(new C(f, sched)); @@ -188,8 +178,8 @@ grpc_closure* MakeOnceClosure( struct C : public grpc_closure { C(const F& f) : f_(f) {} F f_; - static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - static_cast(arg)->f_(exec_ctx, error); + static void Execute(void* arg, grpc_error* error) { + static_cast(arg)->f_(error); delete static_cast(arg); } }; @@ -220,22 +210,22 @@ class Stream { gpr_arena_destroy(arena_); arena_ = gpr_arena_create(4096); } - grpc_transport_init_stream(f_->exec_ctx(), f_->transport(), + grpc_transport_init_stream(f_->transport(), static_cast(stream_), &refcount_, nullptr, arena_); } - void DestroyThen(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { + void DestroyThen(grpc_closure* closure) { destroy_closure_ = closure; #ifndef NDEBUG - grpc_stream_unref(exec_ctx, &refcount_, "DestroyThen"); + grpc_stream_unref(&refcount_, "DestroyThen"); #else - grpc_stream_unref(exec_ctx, &refcount_); + grpc_stream_unref(&refcount_); #endif } - void Op(grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* op) { - grpc_transport_perform_stream_op(exec_ctx, f_->transport(), + void Op(grpc_transport_stream_op_batch* op) { + grpc_transport_perform_stream_op(f_->transport(), static_cast(stream_), op); } @@ -244,10 +234,9 @@ class Stream { } private: - static void FinishDestroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { + static void FinishDestroy(void* arg, grpc_error* error) { auto stream = static_cast(arg); - grpc_transport_destroy_stream(exec_ctx, stream->f_->transport(), + grpc_transport_destroy_stream(stream->f_->transport(), static_cast(stream->stream_), stream->destroy_closure_); gpr_event_set(&stream->done_, (void*)1); @@ -268,6 +257,7 @@ class Stream { static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -276,14 +266,13 @@ static void BM_StreamCreateDestroy(benchmark::State& state) { op.cancel_stream = true; op.payload = &op_payload; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - std::unique_ptr next = - MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { - if (!state.KeepRunning()) return; - s.Init(state); - s.Op(exec_ctx, &op); - s.DestroyThen(exec_ctx, next.get()); - }); - GRPC_CLOSURE_RUN(f.exec_ctx(), next.get(), GRPC_ERROR_NONE); + std::unique_ptr next = MakeClosure([&](grpc_error* error) { + if (!state.KeepRunning()) return; + s.Init(state); + s.Op(&op); + s.DestroyThen(next.get()); + }); + GRPC_CLOSURE_RUN(next.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); track_counters.Finish(state); } @@ -291,21 +280,21 @@ BENCHMARK(BM_StreamCreateDestroy); class RepresentativeClientInitialMetadata { public: - static std::vector GetElems(grpc_exec_ctx* exec_ctx) { + static std::vector GetElems() { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_PATH, + GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP, GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_USER_AGENT, + GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -314,6 +303,7 @@ class RepresentativeClientInitialMetadata { template static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op_batch op; @@ -330,34 +320,33 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { grpc_metadata_batch b; grpc_metadata_batch_init(&b); b.deadline = GRPC_MILLIS_INF_FUTURE; - std::vector elems = Metadata::GetElems(f.exec_ctx()); + std::vector elems = Metadata::GetElems(); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", - grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); + "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); } f.FlushExecCtx(); - start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + start = MakeClosure([&](grpc_error* error) { if (!state.KeepRunning()) return; s.Init(state); reset_op(); op.on_complete = done.get(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; - s.Op(exec_ctx, &op); + s.Op(&op); }); - done = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + done = MakeClosure([&](grpc_error* error) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(exec_ctx, &op); - s.DestroyThen(exec_ctx, start.get()); + s.Op(&op); + s.DestroyThen(start.get()); }); - GRPC_CLOSURE_SCHED(f.exec_ctx(), start.get(), GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(start.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); - grpc_metadata_batch_destroy(f.exec_ctx(), &b); + grpc_metadata_batch_destroy(&b); track_counters.Finish(state); } BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, @@ -365,6 +354,7 @@ BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -375,21 +365,19 @@ static void BM_TransportEmptyOp(benchmark::State& state) { memset(&op, 0, sizeof(op)); op.payload = &op_payload; }; - std::unique_ptr c = - MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { - if (!state.KeepRunning()) return; - reset_op(); - op.on_complete = c.get(); - s.Op(exec_ctx, &op); - }); - GRPC_CLOSURE_SCHED(f.exec_ctx(), c.get(), GRPC_ERROR_NONE); + std::unique_ptr c = MakeClosure([&](grpc_error* error) { + if (!state.KeepRunning()) return; + reset_op(); + op.on_complete = c.get(); + s.Op(&op); + }); + GRPC_CLOSURE_SCHED(c.get(), GRPC_ERROR_NONE); f.FlushExecCtx(); reset_op(); op.cancel_stream = true; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(f.exec_ctx(), &op); - s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, - grpc_error* error) {})); + s.Op(&op); + s.DestroyThen(MakeOnceClosure([](grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); } @@ -399,6 +387,7 @@ std::vector> done_events; static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr(new Stream(&f)); s->Init(state); @@ -420,39 +409,37 @@ static void BM_TransportStreamSend(benchmark::State& state) { grpc_metadata_batch_init(&b); b.deadline = GRPC_MILLIS_INF_FUTURE; std::vector elems = - RepresentativeClientInitialMetadata::GetElems(f.exec_ctx()); + RepresentativeClientInitialMetadata::GetElems(); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", - grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); + "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); } gpr_event* bm_done = new gpr_event; gpr_event_init(bm_done); - std::unique_ptr c = - MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { - if (!state.KeepRunning()) { - gpr_event_set(bm_done, (void*)1); - return; - } - // force outgoing window to be yuge - s->chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); - f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); - grpc_slice_buffer_stream_init(&send_stream, &send_buffer, 0); - reset_op(); - op.on_complete = c.get(); - op.send_message = true; - op.payload->send_message.send_message = &send_stream.base; - s->Op(exec_ctx, &op); - }); + std::unique_ptr c = MakeClosure([&](grpc_error* error) { + if (!state.KeepRunning()) { + gpr_event_set(bm_done, (void*)1); + return; + } + // force outgoing window to be yuge + s->chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); + f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); + grpc_slice_buffer_stream_init(&send_stream, &send_buffer, 0); + reset_op(); + op.on_complete = c.get(); + op.send_message = true; + op.payload->send_message.send_message = &send_stream.base; + s->Op(&op); + }); reset_op(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; op.on_complete = c.get(); - s->Op(f.exec_ctx(), &op); + s->Op(&op); f.FlushExecCtx(); gpr_event_wait(bm_done, gpr_inf_future(GPR_CLOCK_REALTIME)); @@ -461,13 +448,12 @@ static void BM_TransportStreamSend(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s->Op(f.exec_ctx(), &op); - s->DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, - grpc_error* error) {})); + s->Op(&op); + s->DestroyThen(MakeOnceClosure([](grpc_error* error) {})); f.FlushExecCtx(); s.reset(); track_counters.Finish(state); - grpc_metadata_batch_destroy(f.exec_ctx(), &b); + grpc_metadata_batch_destroy(&b); grpc_slice_buffer_destroy(&send_buffer); } BENCHMARK(BM_TransportStreamSend)->Range(0, 128 * 1024 * 1024); @@ -531,6 +517,7 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; + grpc_core::ExecCtx exec_ctx; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); @@ -551,16 +538,14 @@ static void BM_TransportStreamRecv(benchmark::State& state) { grpc_metadata_batch_init(&b_recv); b.deadline = GRPC_MILLIS_INF_FUTURE; std::vector elems = - RepresentativeClientInitialMetadata::GetElems(f.exec_ctx()); + RepresentativeClientInitialMetadata::GetElems(); std::vector storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", - grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); + "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); } - std::unique_ptr do_nothing = - MakeClosure([](grpc_exec_ctx* exec_ctx, grpc_error* error) {}); + std::unique_ptr do_nothing = MakeClosure([](grpc_error* error) {}); uint32_t received; @@ -569,51 +554,49 @@ static void BM_TransportStreamRecv(benchmark::State& state) { std::unique_ptr drain_continue; grpc_slice recv_slice; - std::unique_ptr c = - MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { - if (!state.KeepRunning()) return; - // force outgoing window to be yuge - s.chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); - f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); - received = 0; - reset_op(); - op.on_complete = do_nothing.get(); - op.recv_message = true; - op.payload->recv_message.recv_message = &recv_stream; - op.payload->recv_message.recv_message_ready = drain_start.get(); - s.Op(exec_ctx, &op); - f.PushInput(grpc_slice_ref(incoming_data)); - }); - - drain_start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + std::unique_ptr c = MakeClosure([&](grpc_error* error) { + if (!state.KeepRunning()) return; + // force outgoing window to be yuge + s.chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); + f.chttp2_transport()->flow_control->TestOnlyForceHugeWindow(); + received = 0; + reset_op(); + op.on_complete = do_nothing.get(); + op.recv_message = true; + op.payload->recv_message.recv_message = &recv_stream; + op.payload->recv_message.recv_message_ready = drain_start.get(); + s.Op(&op); + f.PushInput(grpc_slice_ref(incoming_data)); + }); + + drain_start = MakeClosure([&](grpc_error* error) { if (recv_stream == nullptr) { GPR_ASSERT(!state.KeepRunning()); return; } - GRPC_CLOSURE_RUN(exec_ctx, drain.get(), GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(drain.get(), GRPC_ERROR_NONE); }); - drain = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { + drain = MakeClosure([&](grpc_error* error) { do { if (received == recv_stream->length) { - grpc_byte_stream_destroy(exec_ctx, recv_stream); - GRPC_CLOSURE_SCHED(exec_ctx, c.get(), GRPC_ERROR_NONE); + grpc_byte_stream_destroy(recv_stream); + GRPC_CLOSURE_SCHED(c.get(), GRPC_ERROR_NONE); return; } - } while (grpc_byte_stream_next(exec_ctx, recv_stream, - recv_stream->length - received, + } while (grpc_byte_stream_next(recv_stream, recv_stream->length - received, drain_continue.get()) && GRPC_ERROR_NONE == - grpc_byte_stream_pull(exec_ctx, recv_stream, &recv_slice) && + grpc_byte_stream_pull(recv_stream, &recv_slice) && (received += GRPC_SLICE_LENGTH(recv_slice), - grpc_slice_unref_internal(exec_ctx, recv_slice), true)); + grpc_slice_unref_internal(recv_slice), true)); }); - drain_continue = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { - grpc_byte_stream_pull(exec_ctx, recv_stream, &recv_slice); + drain_continue = MakeClosure([&](grpc_error* error) { + grpc_byte_stream_pull(recv_stream, &recv_slice); received += GRPC_SLICE_LENGTH(recv_slice); - grpc_slice_unref_internal(exec_ctx, recv_slice); - GRPC_CLOSURE_RUN(exec_ctx, drain.get(), GRPC_ERROR_NONE); + grpc_slice_unref_internal(recv_slice); + GRPC_CLOSURE_RUN(drain.get(), GRPC_ERROR_NONE); }); reset_op(); @@ -624,7 +607,7 @@ static void BM_TransportStreamRecv(benchmark::State& state) { op.payload->recv_initial_metadata.recv_initial_metadata_ready = do_nothing.get(); op.on_complete = c.get(); - s.Op(f.exec_ctx(), &op); + s.Op(&op); f.PushInput(SLICE_FROM_BUFFER( "\x00\x00\x00\x04\x00\x00\x00\x00\x00" // Generated using: @@ -642,13 +625,12 @@ static void BM_TransportStreamRecv(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; - s.Op(f.exec_ctx(), &op); - s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, - grpc_error* error) {})); + s.Op(&op); + s.DestroyThen(MakeOnceClosure([](grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); - grpc_metadata_batch_destroy(f.exec_ctx(), &b); - grpc_metadata_batch_destroy(f.exec_ctx(), &b_recv); + grpc_metadata_batch_destroy(&b); + grpc_metadata_batch_destroy(&b_recv); grpc_slice_unref(incoming_data); } BENCHMARK(BM_TransportStreamRecv)->Range(0, 128 * 1024 * 1024); diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index 2434d4e84e..4d5a82c3f6 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -34,8 +34,7 @@ auto& force_library_initialization = Library::get(); static void BM_NoOpExecCtx(benchmark::State& state) { TrackCounters track_counters; while (state.KeepRunning()) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; } track_counters.Finish(state); } @@ -43,16 +42,16 @@ BENCHMARK(BM_NoOpExecCtx); static void BM_WellFlushed(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_WellFlushed); -static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void DoNothing(void* arg, grpc_error* error) {} static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) { TrackCounters track_counters; @@ -69,13 +68,13 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { TrackCounters track_counters; grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { benchmark::DoNotOptimize(GRPC_CLOSURE_INIT( &c, DoNothing, nullptr, grpc_combiner_scheduler(combiner))); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAgainstCombiner); @@ -84,41 +83,39 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_RUN(&exec_ctx, &c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureRunOnExecCtx); static void BM_ClosureCreateAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( - &exec_ctx, GRPC_CLOSURE_CREATE(DoNothing, nullptr, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureCreateAndRun); static void BM_ClosureInitAndRun(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure c; while (state.KeepRunning()) { GRPC_CLOSURE_RUN( - &exec_ctx, GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx), GRPC_ERROR_NONE); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureInitAndRun); @@ -127,12 +124,12 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnExecCtx); @@ -143,13 +140,13 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnExecCtx); @@ -162,14 +159,14 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnExecCtx); @@ -179,13 +176,13 @@ static void BM_AcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { gpr_mu_lock(&mu); - DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); + DoNothing(nullptr, GRPC_ERROR_NONE); gpr_mu_unlock(&mu); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_AcquireMutex); @@ -195,16 +192,16 @@ static void BM_TryAcquireMutex(benchmark::State& state) { // for comparison with the combiner stuff below gpr_mu mu; gpr_mu_init(&mu); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { if (gpr_mu_trylock(&mu)) { - DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); + DoNothing(nullptr, GRPC_ERROR_NONE); gpr_mu_unlock(&mu); } else { abort(); } } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_TryAcquireMutex); @@ -213,13 +210,13 @@ static void BM_AcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { gpr_spinlock_lock(&mu); - DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); + DoNothing(nullptr, GRPC_ERROR_NONE); gpr_spinlock_unlock(&mu); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_AcquireSpinlock); @@ -228,16 +225,16 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) { TrackCounters track_counters; // for comparison with the combiner stuff below gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { if (gpr_spinlock_trylock(&mu)) { - DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE); + DoNothing(nullptr, GRPC_ERROR_NONE); gpr_spinlock_unlock(&mu); } else { abort(); } } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_TryAcquireSpinlock); @@ -247,13 +244,13 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(); grpc_closure c; GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSchedOnCombiner); @@ -265,14 +262,14 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { grpc_closure c2; GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnCombiner); @@ -286,15 +283,15 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_combiner_scheduler(combiner)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched3OnCombiner); @@ -309,15 +306,15 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); - GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner1, "finished"); + GRPC_COMBINER_UNREF(combiner2, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched2OnTwoCombiners); @@ -338,17 +335,17 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { grpc_combiner_scheduler(combiner1)); GRPC_CLOSURE_INIT(&c4, DoNothing, nullptr, grpc_combiner_scheduler(combiner2)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE); - GRPC_CLOSURE_SCHED(&exec_ctx, &c4, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&c4, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); } - GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); - GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner1, "finished"); + GRPC_COMBINER_UNREF(combiner2, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureSched4OnTwoCombiners); @@ -362,13 +359,11 @@ class Rescheduler { GRPC_CLOSURE_INIT(&closure_, Step, this, scheduler); } - void ScheduleFirst(grpc_exec_ctx* exec_ctx) { - GRPC_CLOSURE_SCHED(exec_ctx, &closure_, GRPC_ERROR_NONE); - } + void ScheduleFirst() { GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); } void ScheduleFirstAgainstDifferentScheduler( - grpc_exec_ctx* exec_ctx, grpc_closure_scheduler* scheduler) { - GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(Step, this, scheduler), + grpc_closure_scheduler* scheduler) { + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(Step, this, scheduler), GRPC_ERROR_NONE); } @@ -376,47 +371,46 @@ class Rescheduler { benchmark::State& state_; grpc_closure closure_; - static void Step(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static void Step(void* arg, grpc_error* error) { Rescheduler* self = static_cast(arg); if (self->state_.KeepRunning()) { - GRPC_CLOSURE_SCHED(exec_ctx, &self->closure_, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&self->closure_, GRPC_ERROR_NONE); } } }; static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; Rescheduler r(state, grpc_schedule_on_exec_ctx); - r.ScheduleFirst(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + r.ScheduleFirst(); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnExecCtx); static void BM_ClosureReschedOnCombiner(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_scheduler(combiner)); - r.ScheduleFirst(&exec_ctx); - grpc_exec_ctx_flush(&exec_ctx); - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + r.ScheduleFirst(); + grpc_core::ExecCtx::Get()->Flush(); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombiner); static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); Rescheduler r(state, grpc_combiner_finally_scheduler(combiner)); - r.ScheduleFirstAgainstDifferentScheduler(&exec_ctx, - grpc_combiner_scheduler(combiner)); - grpc_exec_ctx_flush(&exec_ctx); - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); - grpc_exec_ctx_finish(&exec_ctx); + r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner)); + grpc_core::ExecCtx::Get()->Flush(); + GRPC_COMBINER_UNREF(combiner, "finished"); + track_counters.Finish(state); } BENCHMARK(BM_ClosureReschedOnCombinerFinally); diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index f0dede7333..97242598f1 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -66,7 +66,7 @@ static void BM_CreateDestroyCore(benchmark::State& state) { } BENCHMARK(BM_CreateDestroyCore); -static void DoneWithCompletionOnStack(grpc_exec_ctx* exec_ctx, void* arg, +static void DoneWithCompletionOnStack(void* arg, grpc_cq_completion* completion) {} class DummyTag final : public internal::CompletionQueueTag { @@ -81,11 +81,11 @@ static void BM_Pass1Cpp(benchmark::State& state) { while (state.KeepRunning()) { grpc_cq_completion completion; DummyTag dummy_tag; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag)); - grpc_cq_end_op(&exec_ctx, c_cq, &dummy_tag, GRPC_ERROR_NONE, - DoneWithCompletionOnStack, nullptr, &completion); - grpc_exec_ctx_finish(&exec_ctx); + grpc_cq_end_op(c_cq, &dummy_tag, GRPC_ERROR_NONE, DoneWithCompletionOnStack, + nullptr, &completion); + void* tag; bool ok; cq.Next(&tag, &ok); @@ -101,11 +101,11 @@ static void BM_Pass1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); - grpc_cq_end_op(&exec_ctx, cq, nullptr, GRPC_ERROR_NONE, - DoneWithCompletionOnStack, nullptr, &completion); - grpc_exec_ctx_finish(&exec_ctx); + grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, + nullptr, &completion); + grpc_completion_queue_next(cq, deadline, nullptr); } grpc_completion_queue_destroy(cq); @@ -120,11 +120,11 @@ static void BM_Pluck1Core(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); while (state.KeepRunning()) { grpc_cq_completion completion; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_cq_begin_op(cq, nullptr)); - grpc_cq_end_op(&exec_ctx, cq, nullptr, GRPC_ERROR_NONE, - DoneWithCompletionOnStack, nullptr, &completion); - grpc_exec_ctx_finish(&exec_ctx); + grpc_cq_end_op(cq, nullptr, GRPC_ERROR_NONE, DoneWithCompletionOnStack, + nullptr, &completion); + grpc_completion_queue_pluck(cq, nullptr, deadline, nullptr); } grpc_completion_queue_destroy(cq); diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 7ccebb55ee..874c834931 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -43,9 +43,8 @@ static grpc_completion_queue* g_cq; static grpc_event_engine_vtable g_vtable; static const grpc_event_engine_vtable* g_old_vtable; -static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, - grpc_closure* closure) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); +static void pollset_shutdown(grpc_pollset* ps, grpc_closure* closure) { + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } static void pollset_init(grpc_pollset* ps, gpr_mu** mu) { @@ -53,25 +52,20 @@ static void pollset_init(grpc_pollset* ps, gpr_mu** mu) { *mu = &ps->mu; } -static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* ps) { - gpr_mu_destroy(&ps->mu); -} +static void pollset_destroy(grpc_pollset* ps) { gpr_mu_destroy(&ps->mu); } -static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, - grpc_pollset_worker* worker) { +static grpc_error* pollset_kick(grpc_pollset* p, grpc_pollset_worker* worker) { return GRPC_ERROR_NONE; } /* Callback when the tag is dequeued from the completion queue. Does nothing */ -static void cq_done_cb(grpc_exec_ctx* exec_ctx, void* done_arg, - grpc_cq_completion* cq_completion) { +static void cq_done_cb(void* done_arg, grpc_cq_completion* cq_completion) { gpr_free(cq_completion); } /* Queues a completion tag if deadline is > 0. * Does nothing if deadline is 0 (i.e gpr_time_0(GPR_CLOCK_MONOTONIC)) */ -static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, - grpc_pollset_worker** worker, +static grpc_error* pollset_work(grpc_pollset* ps, grpc_pollset_worker** worker, grpc_millis deadline) { if (deadline == 0) { gpr_log(GPR_DEBUG, "no-op"); @@ -80,9 +74,9 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, gpr_mu_unlock(&ps->mu); GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag)); - grpc_cq_end_op(exec_ctx, g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, + grpc_cq_end_op(g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(&ps->mu); return GRPC_ERROR_NONE; } diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index bbd8b3c339..d12f475a49 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -246,14 +246,14 @@ template static void BM_ErrorGetStatus(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_status_code status; grpc_slice slice; - grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), - &status, &slice, nullptr, nullptr); + grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice, + nullptr, nullptr); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } @@ -261,13 +261,13 @@ template static void BM_ErrorGetStatusCode(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_status_code status; - grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), - &status, nullptr, nullptr, nullptr); + grpc_error_get_status(fixture.error(), fixture.deadline(), &status, nullptr, + nullptr, nullptr); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } @@ -275,13 +275,13 @@ template static void BM_ErrorHttpError(benchmark::State& state) { TrackCounters track_counters; Fixture fixture; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { grpc_http2_error_code error; - grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), - nullptr, nullptr, &error, nullptr); + grpc_error_get_status(fixture.error(), fixture.deadline(), nullptr, nullptr, + &error, nullptr); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 5e72213823..d6d7d41e5e 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -177,13 +177,13 @@ class TrickledCHTTP2 : public EndpointPairFixture { } void Step(bool update_stats) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; inc_time(); size_t client_backlog = - grpc_trickle_endpoint_trickle(&exec_ctx, endpoint_pair_.client); + grpc_trickle_endpoint_trickle(endpoint_pair_.client); size_t server_backlog = - grpc_trickle_endpoint_trickle(&exec_ctx, endpoint_pair_.server); - grpc_exec_ctx_finish(&exec_ctx); + grpc_trickle_endpoint_trickle(endpoint_pair_.server); + if (update_stats) { UpdateStats((grpc_chttp2_transport*)client_transport_, &client_stats_, client_backlog); diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc index 73bce08466..f1e7890fc0 100644 --- a/test/cpp/microbenchmarks/bm_metadata.cc +++ b/test/cpp/microbenchmarks/bm_metadata.cc @@ -90,11 +90,11 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlices); @@ -103,11 +103,11 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -119,13 +119,13 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex( TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem seed = grpc_mdelem_create(&exec_ctx, k, v, nullptr); + grpc_core::ExecCtx exec_ctx; + grpc_mdelem seed = grpc_mdelem_create(k, v, nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - GRPC_MDELEM_UNREF(&exec_ctx, seed); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(seed); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -136,11 +136,11 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -152,14 +152,12 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_from_static_string("key"); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_create(&exec_ctx, k, v, - reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF(grpc_mdelem_create( + k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(&exec_ctx); + track_counters.Finish(state); } BENCHMARK(BM_MetadataFromNonInternedSlicesWithBackingStore); @@ -170,14 +168,12 @@ static void BM_MetadataFromInternedSlicesWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_create(&exec_ctx, k, v, - reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF(grpc_mdelem_create( + k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); grpc_slice_unref(v); track_counters.Finish(state); @@ -190,14 +186,12 @@ static void BM_MetadataFromInternedKeyWithBackingStore( gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_from_static_string("value"); char backing_store[sizeof(grpc_mdelem_data)]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_create(&exec_ctx, k, v, - reinterpret_cast(backing_store))); + GRPC_MDELEM_UNREF(grpc_mdelem_create( + k, v, reinterpret_cast(backing_store))); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -207,11 +201,11 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) { TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_200; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -222,11 +216,11 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed( TrackCounters track_counters; gpr_slice k = GRPC_MDSTR_STATUS; gpr_slice v = GRPC_MDSTR_GZIP; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, nullptr)); + GRPC_MDELEM_UNREF(grpc_mdelem_create(k, v, nullptr)); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref(k); track_counters.Finish(state); } @@ -235,16 +229,15 @@ BENCHMARK(BM_MetadataFromStaticMetadataStringsNotIndexed); static void BM_MetadataRefUnrefExternal(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem el = - grpc_mdelem_create(&exec_ctx, grpc_slice_from_static_string("a"), - grpc_slice_from_static_string("b"), - reinterpret_cast(backing_store)); + grpc_core::ExecCtx exec_ctx; + grpc_mdelem el = grpc_mdelem_create( + grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), + reinterpret_cast(backing_store)); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(&exec_ctx, el); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(el); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefExternal); @@ -252,47 +245,47 @@ BENCHMARK(BM_MetadataRefUnrefExternal); static void BM_MetadataRefUnrefInterned(benchmark::State& state) { TrackCounters track_counters; char backing_store[sizeof(grpc_mdelem_data)]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key")); gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value")); grpc_mdelem el = grpc_mdelem_create( - &exec_ctx, k, v, reinterpret_cast(backing_store)); + k, v, reinterpret_cast(backing_store)); grpc_slice_unref(k); grpc_slice_unref(v); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(&exec_ctx, el); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(el); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefInterned); static void BM_MetadataRefUnrefAllocated(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem el = - grpc_mdelem_create(&exec_ctx, grpc_slice_from_static_string("a"), + grpc_mdelem_create(grpc_slice_from_static_string("a"), grpc_slice_from_static_string("b"), nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(&exec_ctx, el); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(el); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefAllocated); static void BM_MetadataRefUnrefStatic(benchmark::State& state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem el = - grpc_mdelem_create(&exec_ctx, GRPC_MDSTR_STATUS, GRPC_MDSTR_200, nullptr); + grpc_mdelem_create(GRPC_MDSTR_STATUS, GRPC_MDSTR_200, nullptr); while (state.KeepRunning()) { - GRPC_MDELEM_UNREF(&exec_ctx, GRPC_MDELEM_REF(el)); + GRPC_MDELEM_UNREF(GRPC_MDELEM_REF(el)); } - GRPC_MDELEM_UNREF(&exec_ctx, el); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(el); + track_counters.Finish(state); } BENCHMARK(BM_MetadataRefUnrefStatic); diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc index 4da79693f1..d9d5164cce 100644 --- a/test/cpp/microbenchmarks/bm_pollset.cc +++ b/test/cpp/microbenchmarks/bm_pollset.cc @@ -41,8 +41,8 @@ auto& force_library_initialization = Library::get(); -static void shutdown_ps(grpc_exec_ctx* exec_ctx, void* ps, grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast(ps)); +static void shutdown_ps(void* ps, grpc_error* error) { + grpc_pollset_destroy(static_cast(ps)); } static void BM_CreateDestroyPollset(benchmark::State& state) { @@ -50,7 +50,7 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { size_t ps_sz = grpc_pollset_size(); grpc_pollset* ps = static_cast(gpr_malloc(ps_sz)); gpr_mu* mu; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); @@ -58,11 +58,11 @@ static void BM_CreateDestroyPollset(benchmark::State& state) { memset(ps, 0, ps_sz); grpc_pollset_init(ps, &mu); gpr_mu_lock(mu); - grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); + grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -114,17 +114,17 @@ static void BM_PollEmptyPollset(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(mu); while (state.KeepRunning()) { - GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, nullptr, 0)); + GRPC_ERROR_UNREF(grpc_pollset_work(ps, nullptr, 0)); } grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); + grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -136,24 +136,23 @@ static void BM_PollAddFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_wakeup_fd wakeup_fd; GPR_ASSERT( GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&wakeup_fd))); grpc_fd* fd = grpc_fd_create(wakeup_fd.read_fd, "xxx"); while (state.KeepRunning()) { - grpc_pollset_add_fd(&exec_ctx, ps, fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(ps, fd); + grpc_core::ExecCtx::Get()->Flush(); } - grpc_fd_orphan(&exec_ctx, fd, nullptr, nullptr, false /* already_closed */, - "xxx"); + grpc_fd_orphan(fd, nullptr, nullptr, false /* already_closed */, "xxx"); grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); gpr_mu_lock(mu); - grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); + grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(ps); track_counters.Finish(state); } @@ -170,7 +169,7 @@ Closure* MakeClosure(F f, grpc_closure_scheduler* scheduler) { C(F f, grpc_closure_scheduler* scheduler) : f_(f) { GRPC_CLOSURE_INIT(this, C::cbfn, this, scheduler); } - static void cbfn(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static void cbfn(void* arg, grpc_error* error) { C* p = static_cast(arg); p->f_(); } @@ -219,11 +218,11 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { grpc_pollset* ps = static_cast(gpr_zalloc(ps_sz)); gpr_mu* mu; grpc_pollset_init(ps, &mu); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_wakeup_fd wakeup_fd; GRPC_ERROR_UNREF(grpc_wakeup_fd_init(&wakeup_fd)); grpc_fd* wakeup = grpc_fd_create(wakeup_fd.read_fd, "wakeup_read"); - grpc_pollset_add_fd(&exec_ctx, ps, wakeup); + grpc_pollset_add_fd(ps, wakeup); bool done = false; Closure* continue_closure = MakeClosure( [&]() { @@ -233,25 +232,23 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) { return; } GRPC_ERROR_UNREF(grpc_wakeup_fd_wakeup(&wakeup_fd)); - grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure); + grpc_fd_notify_on_read(wakeup, continue_closure); }, grpc_schedule_on_exec_ctx); GRPC_ERROR_UNREF(grpc_wakeup_fd_wakeup(&wakeup_fd)); - grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure); + grpc_fd_notify_on_read(wakeup, continue_closure); gpr_mu_lock(mu); while (!done) { - GRPC_ERROR_UNREF( - grpc_pollset_work(&exec_ctx, ps, nullptr, GRPC_MILLIS_INF_FUTURE)); + GRPC_ERROR_UNREF(grpc_pollset_work(ps, nullptr, GRPC_MILLIS_INF_FUTURE)); } - grpc_fd_orphan(&exec_ctx, wakeup, nullptr, nullptr, - false /* already_closed */, "done"); + grpc_fd_orphan(wakeup, nullptr, nullptr, false /* already_closed */, "done"); wakeup_fd.read_fd = 0; grpc_closure shutdown_ps_closure; GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure); + grpc_pollset_shutdown(ps, &shutdown_ps_closure); gpr_mu_unlock(mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&wakeup_fd); gpr_free(ps); track_counters.Finish(state); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 7e20843875..d1ede755a5 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -166,7 +166,7 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add server endpoint to server_ * */ @@ -174,20 +174,19 @@ class EndpointPairFixture : public BaseFixture { const grpc_channel_args* server_args = grpc_server_get_channel_args(server_->c_server()); server_transport_ = grpc_create_chttp2_transport( - &exec_ctx, server_args, endpoints.server, false /* is_client */); + server_args, endpoints.server, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server_->c_server(), &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(&exec_ctx, endpoints.server, pollsets[i]); + grpc_endpoint_add_to_pollset(endpoints.server, pollsets[i]); } - grpc_server_setup_transport(&exec_ctx, server_->c_server(), - server_transport_, nullptr, server_args); - grpc_chttp2_transport_start_reading(&exec_ctx, server_transport_, nullptr, - nullptr); + grpc_server_setup_transport(server_->c_server(), server_transport_, + nullptr, server_args); + grpc_chttp2_transport_start_reading(server_transport_, nullptr, nullptr); } /* create channel */ @@ -197,19 +196,15 @@ class EndpointPairFixture : public BaseFixture { fixture_configuration.ApplyCommonChannelArguments(&args); grpc_channel_args c_args = args.c_channel_args(); - client_transport_ = grpc_create_chttp2_transport(&exec_ctx, &c_args, - endpoints.client, true); + client_transport_ = + grpc_create_chttp2_transport(&c_args, endpoints.client, true); GPR_ASSERT(client_transport_); - grpc_channel* channel = - grpc_channel_create(&exec_ctx, "target", &c_args, - GRPC_CLIENT_DIRECT_CHANNEL, client_transport_); - grpc_chttp2_transport_start_reading(&exec_ctx, client_transport_, nullptr, - nullptr); + grpc_channel* channel = grpc_channel_create( + "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport_); + grpc_chttp2_transport_start_reading(client_transport_, nullptr, nullptr); channel_ = CreateChannelInternal("", channel); } - - grpc_exec_ctx_finish(&exec_ctx); } virtual ~EndpointPairFixture() { diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 6f1f0c44b9..3481d9d1aa 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -149,33 +149,33 @@ struct ArgsStruct { std::string expected_lb_policy; }; -void ArgsInit(grpc_exec_ctx* exec_ctx, ArgsStruct* args) { +void ArgsInit(ArgsStruct* args) { gpr_event_init(&args->ev); args->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); args->lock = grpc_combiner_create(); gpr_atm_rel_store(&args->done_atm, 0); args->channel_args = nullptr; } -void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +void DoNothing(void* arg, grpc_error* error) {} -void ArgsFinish(grpc_exec_ctx* exec_ctx, ArgsStruct* args) { +void ArgsFinish(ArgsStruct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, TestDeadline())); - grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); - grpc_pollset_set_destroy(exec_ctx, args->pollset_set); + grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_destroy(args->pollset_set); grpc_closure DoNothing_cb; GRPC_CLOSURE_INIT(&DoNothing_cb, DoNothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, args->pollset, &DoNothing_cb); + grpc_pollset_shutdown(args->pollset, &DoNothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_channel_args_destroy(exec_ctx, args->channel_args); - grpc_exec_ctx_flush(exec_ctx); - grpc_pollset_destroy(exec_ctx, args->pollset); + grpc_channel_args_destroy(args->channel_args); + grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); - GRPC_COMBINER_UNREF(exec_ctx, args->lock, NULL); + GRPC_COMBINER_UNREF(args->lock, nullptr); } gpr_timespec NSecondDeadline(int seconds) { @@ -196,14 +196,13 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { time_left.tv_sec, time_left.tv_nsec); GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0); grpc_pollset_worker* worker = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_mu_lock(args->mu); GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, + grpc_pollset_work(args->pollset, &worker, grpc_timespec_to_millis_round_up( NSecondDeadline(1)))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_finish(&exec_ctx); } gpr_event_set(&args->ev, (void*)1); } @@ -235,8 +234,7 @@ void CheckLBPolicyResultLocked(grpc_channel_args* channel_args, } } -void CheckResolverResultLocked(grpc_exec_ctx* exec_ctx, void* argsp, - grpc_error* err) { +void CheckResolverResultLocked(void* argsp, grpc_error* err) { ArgsStruct* args = (ArgsStruct*)argsp; grpc_channel_args* channel_args = args->channel_args; const grpc_arg* channel_arg = @@ -272,15 +270,14 @@ void CheckResolverResultLocked(grpc_exec_ctx* exec_ctx, void* argsp, } gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } TEST(ResolverComponentTest, TestResolvesRelevantRecords) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; ArgsStruct args; - ArgsInit(&exec_ctx, &args); + ArgsInit(&args); args.expected_addrs = ParseExpectedAddrs(FLAGS_expected_addrs); args.expected_service_config_string = FLAGS_expected_chosen_service_config; args.expected_lb_policy = FLAGS_expected_lb_policy; @@ -290,19 +287,18 @@ TEST(ResolverComponentTest, TestResolvesRelevantRecords) { FLAGS_local_dns_server_address.c_str(), FLAGS_target_name.c_str())); // create resolver and resolve - grpc_resolver* resolver = grpc_resolver_create(&exec_ctx, whole_uri, nullptr, - args.pollset_set, args.lock); + grpc_resolver* resolver = + grpc_resolver_create(whole_uri, nullptr, args.pollset_set, args.lock); gpr_free(whole_uri); grpc_closure on_resolver_result_changed; GRPC_CLOSURE_INIT(&on_resolver_result_changed, CheckResolverResultLocked, (void*)&args, grpc_combiner_scheduler(args.lock)); - grpc_resolver_next_locked(&exec_ctx, resolver, &args.channel_args, + grpc_resolver_next_locked(resolver, &args.channel_args, &on_resolver_result_changed); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); PollPollsetUntilRequestDone(&args); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, NULL); - ArgsFinish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_RESOLVER_UNREF(resolver, nullptr); + ArgsFinish(&args); } } // namespace diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 1c6f44dd7d..0b9dc83f2b 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -82,27 +82,26 @@ class EndpointPairFixture { ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add server endpoint to server_ */ { const grpc_channel_args* server_args = grpc_server_get_channel_args(server_->c_server()); grpc_transport* transport = grpc_create_chttp2_transport( - &exec_ctx, server_args, endpoints.server, false /* is_client */); + server_args, endpoints.server, false /* is_client */); grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server_->c_server(), &pollsets, &num_pollsets); for (size_t i = 0; i < num_pollsets; i++) { - grpc_endpoint_add_to_pollset(&exec_ctx, endpoints.server, pollsets[i]); + grpc_endpoint_add_to_pollset(endpoints.server, pollsets[i]); } - grpc_server_setup_transport(&exec_ctx, server_->c_server(), transport, - nullptr, server_args); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, - nullptr); + grpc_server_setup_transport(server_->c_server(), transport, nullptr, + server_args); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } /* create channel */ @@ -112,18 +111,15 @@ class EndpointPairFixture { ApplyCommonChannelArguments(&args); grpc_channel_args c_args = args.c_channel_args(); - grpc_transport* transport = grpc_create_chttp2_transport( - &exec_ctx, &c_args, endpoints.client, true); + grpc_transport* transport = + grpc_create_chttp2_transport(&c_args, endpoints.client, true); GPR_ASSERT(transport); grpc_channel* channel = grpc_channel_create( - &exec_ctx, "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, - nullptr); + "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); channel_ = CreateChannelInternal("", channel); } - - grpc_exec_ctx_finish(&exec_ctx); } virtual ~EndpointPairFixture() { diff --git a/test/cpp/server/server_builder_test.cc b/test/cpp/server/server_builder_test.cc index d18459cec9..694ce549c0 100644 --- a/test/cpp/server/server_builder_test.cc +++ b/test/cpp/server/server_builder_test.cc @@ -22,6 +22,8 @@ #include #include +#include + #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -77,5 +79,8 @@ TEST(ServerBuilderTest, CreateServerRepeatedPortWithDisallowedReusePort) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc index 8fb51bc663..d603b289c8 100644 --- a/test/cpp/util/byte_buffer_test.cc +++ b/test/cpp/util/byte_buffer_test.cc @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -109,5 +110,8 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc index 8a8962d7ee..c2e55f3374 100644 --- a/test/cpp/util/slice_test.cc +++ b/test/cpp/util/slice_test.cc @@ -18,6 +18,7 @@ #include +#include #include #include @@ -127,5 +128,8 @@ TEST_F(SliceTest, Cslice) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 355f3f4e23..7847b8ed1d 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -395,7 +395,7 @@ print >> C, 'static uint8_t g_bytes[] = {%s};' % ( ','.join('%d' % ord(c) for c in ''.join(all_strs))) print >> C print >> C, 'static void static_ref(void *unused) {}' -print >> C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' +print >> C, 'static void static_unref(void *unused) {}' print >> C, ('static const grpc_slice_refcount_vtable static_sub_vtable = ' '{static_ref, static_unref, grpc_slice_default_eq_impl, ' 'grpc_slice_default_hash_impl};') diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 072a677615..d439d99a8c 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -150,11 +150,11 @@ def gen_bucket_code(histogram): code = 'value = GPR_CLAMP(value, 0, %d);\n' % histogram.max map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' + code += ('GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) else: code += 'if (value < %d) {\n' % first_nontrivial - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' + code += ('GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) code += 'return;\n' code += '}' @@ -168,11 +168,11 @@ def gen_bucket_code(histogram): code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d;\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial) code += '_bkt.dbl = grpc_stats_table_%d[bucket];\n' % bounds_idx code += 'bucket -= (_val.uint < _bkt.uint);\n' - code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, bucket);\n' % histogram.name.upper() + code += 'GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, bucket);\n' % histogram.name.upper() code += 'return;\n' code += '}\n' - code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_%d, %d));\n' % (bounds_idx, histogram.buckets) + code += 'GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() + code += 'grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_%d, %d));\n' % (bounds_idx, histogram.buckets) return (code, bounds_idx) # utility: print a big comment block into a set of files @@ -240,13 +240,13 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "} grpc_stats_histogram_constants;" for ctr in inst_map['Counter']: - print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx) " + - "GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)") % ( + print >>H, ("#define GRPC_STATS_INC_%s() " + + "GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_%s)") % ( ctr.name.upper(), ctr.name.upper()) for histogram in inst_map['Histogram']: - print >>H, "#define GRPC_STATS_INC_%s(exec_ctx, value) grpc_stats_inc_%s((exec_ctx), (int)(value))" % ( + print >>H, "#define GRPC_STATS_INC_%s(value) grpc_stats_inc_%s( (int)(value))" % ( histogram.name.upper(), histogram.name.lower()) - print >>H, "void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int x);" % histogram.name.lower() + print >>H, "void grpc_stats_inc_%s(int x);" % histogram.name.lower() for i, tbl in enumerate(static_tables): print >>H, "extern const %s grpc_stats_table_%d[%d];" % (tbl[0], i, len(tbl[1])) @@ -254,7 +254,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) print >>H, "extern const int *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) - print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x);" % len(inst_map['Histogram']) + print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(int x);" % len(inst_map['Histogram']) print >>H print >>H, "#ifdef __cplusplus" @@ -309,7 +309,7 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C: tbl[0], i, len(tbl[1]), ','.join('%s' % x for x in tbl[1])) for histogram, code in zip(inst_map['Histogram'], histo_code): - print >>C, ("void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int value) {%s}") % ( + print >>C, ("void grpc_stats_inc_%s(int value) {%s}") % ( histogram.name.lower(), code) @@ -319,7 +319,7 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C: len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) print >>C, "const int *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) - print >>C, "void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x) = {%s};" % ( + print >>C, "void (*const grpc_stats_inc_histogram[%d])(int x) = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_inc_%s' % histogram.name.lower() for histogram in inst_map['Histogram'])) # patch qps_test bigquery schema -- cgit v1.2.3