aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/filters/client_channel/subchannel_index.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:47:54 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:47:54 -0800
commit8cf1470a51ea276ca84825e7495d4ee24743540d (patch)
tree72385cc865094115bc08cb813201d48cb09840bb /src/core/ext/filters/client_channel/subchannel_index.cc
parent1d4e99508409be052bd129ba507bae1fbe7eb7fa (diff)
Revert "Revert "All instances of exec_ctx being passed around in src/core removed""
Diffstat (limited to 'src/core/ext/filters/client_channel/subchannel_index.cc')
-rw-r--r--src/core/ext/filters/client_channel/subchannel_index.cc63
1 files changed, 30 insertions, 33 deletions
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());
}
}