diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-10-13 16:07:13 -0700 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2017-10-18 17:12:19 -0700 |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /src/core/ext/filters/client_channel/subchannel_index.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/ext/filters/client_channel/subchannel_index.cc')
-rw-r--r-- | src/core/ext/filters/client_channel/subchannel_index.cc | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 1f466ec0b8..f7e0725767 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,9 +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) { @@ -136,32 +132,30 @@ 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; + ExecCtx _local_exec_ctx; gpr_mu_destroy(&g_mu); gpr_avl_unref(g_subchannel_index, &exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); } } 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, &exec_ctx); 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, &exec_ctx), "index_find"); + gpr_avl_unref(index, &exec_ctx); 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 = NULL; bool need_to_unref_constructed; @@ -172,11 +166,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, &exec_ctx); 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, &exec_ctx); if (c != NULL) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -186,8 +180,8 @@ grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, } 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, &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: @@ -199,41 +193,40 @@ 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, &exec_ctx); } - gpr_avl_unref(index, exec_ctx); + gpr_avl_unref(index, &exec_ctx); } 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, &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, exec_ctx); + grpc_subchannel *c = (grpc_subchannel *)gpr_avl_get(index, key, &exec_ctx); if (c != constructed) { - gpr_avl_unref(index, exec_ctx); + 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, exec_ctx), key, exec_ctx); + gpr_avl_remove(gpr_avl_ref(index, &exec_ctx), key, &exec_ctx); gpr_mu_lock(&g_mu); if (index.root == g_subchannel_index.root) { @@ -242,8 +235,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, &exec_ctx); + gpr_avl_unref(index, &exec_ctx); } } |