diff options
author | 2017-10-13 16:07:13 -0700 | |
---|---|---|
committer | 2017-10-18 17:12:19 -0700 | |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /src/core/lib/surface/alarm.cc | |
parent | 6bf5f833efe2cb9e2ecc14358dd9699cd5d05263 (diff) |
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.
Diffstat (limited to 'src/core/lib/surface/alarm.cc')
-rw-r--r-- | src/core/lib/surface/alarm.cc | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 16a16bfd93..4f3bc5172d 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -47,11 +47,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; + ExecCtx _local_exec_ctx; if (alarm->cq != NULL) { - GRPC_CQ_INTERNAL_UNREF(&exec_ctx, alarm->cq, "alarm"); + GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); gpr_free(alarm); } } @@ -82,20 +82,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); } @@ -118,22 +117,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_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_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); + grpc_exec_ctx_finish(); } 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); + ExecCtx _local_exec_ctx; + grpc_timer_cancel(&alarm->alarm); + grpc_exec_ctx_finish(); } void grpc_alarm_destroy(grpc_alarm *alarm, void *reserved) { |