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:05:05 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:05:05 -0800
commitad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch)
tree6a657f8c6179d873b34505cdc24bce9462ca68eb /src/core/ext/filters/client_channel/subchannel_index.cc
parenta3df36cc2505a89c2f481eea4a66a87b3002844a (diff)
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, 33 insertions, 30 deletions
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);
}
}