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. --- test/core/http/httpcli_test.c | 44 +++++++++++++++++++----------------------- test/core/http/httpscli_test.c | 44 +++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 48 deletions(-) (limited to 'test/core/http') diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c index cc1c16d695..de339304d9 100644 --- a/test/core/http/httpcli_test.c +++ b/test/core/http/httpcli_test.c @@ -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,14 +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), NULL))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), NULL))); 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; + exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -77,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 = NULL; 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_exec_ctx_finish(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -100,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; + exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -117,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 = NULL; 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_exec_ctx_finish(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -138,13 +135,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(p)); +static void destroy_pops(void *p, grpc_error *error) { + grpc_pollset_destroy(grpc_polling_entity_pollset(p)); } int main(int argc, char **argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess *server; char *me = argv[0]; char *lslash = strrchr(me, '/'); @@ -193,12 +190,11 @@ int main(int argc, char **argv) { test_get(port); test_post(port); - grpc_httpcli_context_destroy(&exec_ctx, &g_context); + grpc_httpcli_context_destroy(&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_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.c b/test/core/http/httpscli_test.c index f8a3cfdd76..dde2fbfd66 100644 --- a/test/core/http/httpscli_test.c +++ b/test/core/http/httpscli_test.c @@ -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,14 +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), NULL))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), NULL))); 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; + exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -78,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 = NULL; 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_exec_ctx_finish(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -101,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; + exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -119,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 = NULL; 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_exec_ctx_finish(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -140,13 +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(p)); +static void destroy_pops(void *p, grpc_error *error) { + grpc_pollset_destroy(grpc_polling_entity_pollset(p)); } int main(int argc, char **argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess *server; char *me = argv[0]; char *lslash = strrchr(me, '/'); @@ -196,12 +193,11 @@ int main(int argc, char **argv) { test_get(port); test_post(port); - grpc_httpcli_context_destroy(&exec_ctx, &g_context); + grpc_httpcli_context_destroy(&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_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + grpc_exec_ctx_finish(); grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); -- cgit v1.2.3