diff options
Diffstat (limited to 'test/core/iomgr')
-rw-r--r-- | test/core/iomgr/endpoint_pair_test.c | 6 | ||||
-rw-r--r-- | test/core/iomgr/fd_posix_test.c | 56 | ||||
-rw-r--r-- | test/core/iomgr/tcp_client_posix_test.c | 44 | ||||
-rw-r--r-- | test/core/iomgr/tcp_posix_test.c | 56 | ||||
-rw-r--r-- | test/core/iomgr/tcp_server_posix_test.c | 16 | ||||
-rw-r--r-- | test/core/iomgr/workqueue_test.c | 16 |
6 files changed, 91 insertions, 103 deletions
diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c index c02e414935..c3a91088a5 100644 --- a/test/core/iomgr/endpoint_pair_test.c +++ b/test/core/iomgr/endpoint_pair_test.c @@ -42,7 +42,7 @@ #include "test/core/iomgr/endpoint_tests.h" #include "test/core/util/test_config.h" -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; static void clean_up(void) {} @@ -73,17 +73,15 @@ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { int main(int argc, char **argv) { grpc_closure destroyed; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_mu_init(&g_mu); grpc_test_init(argc, argv); grpc_init(); g_pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); grpc_closure_init(&destroyed, destroy_pollset, g_pollset); grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); - gpr_mu_destroy(&g_mu); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 9e00f8a43e..8c64a2e787 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -53,7 +53,7 @@ #include "src/core/iomgr/iomgr.h" #include "test/core/util/test_config.h" -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; /* buffer size used to send and receive data. @@ -182,10 +182,10 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, grpc_fd_orphan(exec_ctx, sv->em_fd, NULL, NULL, "b"); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); sv->done = 1; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } /* Called when a new TCP connection request arrives in the listening port. */ @@ -252,18 +252,18 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { /* Wait and shutdown a sever. */ static void server_wait_and_shutdown(server *sv) { - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (!sv->done) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } /* ===An upload client to test notify_on_write=== */ @@ -310,9 +310,9 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ ssize_t write_once = 0; if (!success) { - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); client_session_shutdown_cb(exec_ctx, arg, 1); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); return; } @@ -322,7 +322,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ } while (write_once > 0); if (errno == EAGAIN) { - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { cl->write_closure.cb = client_session_write; cl->write_closure.cb_arg = cl; @@ -331,7 +331,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ } else { client_session_shutdown_cb(exec_ctx, arg, 1); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } else { gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno)); abort(); @@ -367,18 +367,18 @@ static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) { /* Wait for the signal to shutdown a client. */ static void client_wait_and_shutdown(client *cl) { - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker *worker = NULL; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } /* Test grpc_fd. Start an upload server and client, upload a stream of @@ -413,20 +413,20 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx, void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } static void second_read_callback(grpc_exec_ctx *exec_ctx, void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } /* Test that changing the callback we use for notify_on_read actually works. @@ -468,18 +468,18 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(result == 1); /* And now wait for it to run. */ - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (a.cb_that_ran == NULL) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); /* And drain the socket so we can generate a new read edge */ result = read(sv[0], &data, 1); @@ -492,19 +492,19 @@ static void test_grpc_fd_change(void) { result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (b.cb_that_ran == NULL) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_fd_orphan(&exec_ctx, em_fd, NULL, NULL, "d"); grpc_exec_ctx_finish(&exec_ctx); @@ -522,7 +522,6 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_iomgr_init(); - gpr_mu_init(&g_mu); g_pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); test_grpc_fd(); @@ -531,7 +530,6 @@ int main(int argc, char **argv) { grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); gpr_free(g_pollset); - gpr_mu_destroy(&g_mu); grpc_iomgr_shutdown(); return 0; } diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 51581a8cb0..ac666080fe 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -51,7 +51,7 @@ #include "test/core/util/test_config.h" static grpc_pollset_set *g_pollset_set; -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; static int g_connections_complete = 0; static grpc_endpoint *g_connecting = NULL; @@ -61,10 +61,10 @@ static gpr_timespec test_deadline(void) { } static void finish_connection() { - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); g_connections_complete++; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) { @@ -102,9 +102,9 @@ void test_succeeds(void) { GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len)); GPR_ASSERT(0 == listen(svr_fd, 1)); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); connections_complete_before = g_connections_complete; - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); /* connect to it */ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0); @@ -121,19 +121,19 @@ void test_succeeds(void) { GPR_ASSERT(r >= 0); close(r); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (g_connections_complete == connections_complete_before) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); } @@ -150,9 +150,9 @@ void test_fails(void) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); connections_complete_before = g_connections_complete; - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); /* connect to a broken address */ grpc_closure_init(&done, must_fail, NULL); @@ -160,7 +160,7 @@ void test_fails(void) { (struct sockaddr *)&addr, addr_len, gpr_inf_future(GPR_CLOCK_REALTIME)); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); /* wait for the connection callback to finish */ while (g_connections_complete == connections_complete_before) { @@ -170,12 +170,12 @@ void test_fails(void) { if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) { grpc_pollset_work(&exec_ctx, g_pollset, &worker, now, polling_deadline); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); } @@ -220,16 +220,16 @@ void test_times_out(void) { connect_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); connections_complete_before = g_connections_complete; - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_closure_init(&done, must_fail, NULL); grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, (struct sockaddr *)&addr, addr_len, connect_deadline); /* Make sure the event doesn't trigger early */ - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); for (;;) { grpc_pollset_worker *worker = NULL; gpr_timespec now = gpr_now(connect_deadline.clock_type); @@ -257,11 +257,11 @@ void test_times_out(void) { if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) { grpc_pollset_work(&exec_ctx, g_pollset, &worker, now, polling_deadline); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); @@ -282,7 +282,6 @@ int main(int argc, char **argv) { grpc_init(); g_pollset_set = grpc_pollset_set_create(); g_pollset = gpr_malloc(grpc_pollset_size()); - gpr_mu_init(&g_mu); grpc_pollset_init(g_pollset, &g_mu); grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset); grpc_exec_ctx_finish(&exec_ctx); @@ -296,6 +295,5 @@ int main(int argc, char **argv) { grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); - gpr_mu_destroy(&g_mu); return 0; } diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index d6758f8fe1..4351642ab6 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -48,7 +48,7 @@ #include "test/core/iomgr/endpoint_tests.h" #include "test/core/util/test_config.h" -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; /* @@ -146,7 +146,7 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { GPR_ASSERT(success); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); current_data = state->read_bytes % 256; read_bytes = count_slices(state->incoming.slices, state->incoming.count, ¤t_data); @@ -154,10 +154,10 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } else { grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } } @@ -189,17 +189,17 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_endpoint_destroy(&exec_ctx, ep); @@ -235,17 +235,17 @@ static void large_read_test(size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_endpoint_destroy(&exec_ctx, ep); @@ -284,11 +284,11 @@ static void write_done(grpc_exec_ctx *exec_ctx, void *user_data /* write_socket_state */, bool success) { struct write_socket_state *state = (struct write_socket_state *)user_data; gpr_log(GPR_INFO, "Write done callback called"); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); state->write_done = 1; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { @@ -305,11 +305,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { for (;;) { grpc_pollset_worker *worker = NULL; - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10)); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); do { bytes_read = @@ -364,7 +364,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); drain_socket_blocking(sv[0], num_bytes, num_bytes); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); for (;;) { grpc_pollset_worker *worker = NULL; if (state.write_done) { @@ -372,11 +372,11 @@ static void write_test(size_t num_bytes, size_t slice_size) { } grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&outgoing); grpc_endpoint_destroy(&exec_ctx, ep); @@ -424,27 +424,27 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); grpc_exec_ctx_finish(&exec_ctx); @@ -514,16 +514,14 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); g_pollset = gpr_malloc(grpc_pollset_size()); - gpr_mu_init(&g_mu); grpc_pollset_init(g_pollset, &g_mu); run_tests(); - grpc_endpoint_tests(configs[0], g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); grpc_closure_init(&destroyed, destroy_pollset, g_pollset); grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); - gpr_mu_destroy(&g_mu); return 0; } diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index ed627734bf..7933468355 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -52,7 +52,7 @@ #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; static int g_nconnects = 0; @@ -117,11 +117,11 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, grpc_endpoint_shutdown(exec_ctx, tcp); grpc_endpoint_destroy(exec_ctx, tcp); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); on_connect_result_set(&g_result, acceptor); g_nconnects++; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } static void test_no_op(void) { @@ -178,7 +178,7 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote, int clifd = socket(remote->sa_family, SOCK_STREAM, 0); int nconnects_before; - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); nconnects_before = g_nconnects; on_connect_result_init(&g_result); GPR_ASSERT(clifd >= 0); @@ -190,16 +190,16 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote, grpc_pollset_worker *worker = NULL; grpc_pollset_work(exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(exec_ctx); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); GPR_ASSERT(g_nconnects == nconnects_before + 1); close(clifd); *result = g_result; - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } /* Tests a tcp server with multiple ports. TODO(daniel-j-born): Multiple fds for @@ -315,7 +315,6 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); g_pollset = gpr_malloc(grpc_pollset_size()); - gpr_mu_init(&g_mu); grpc_pollset_init(g_pollset, &g_mu); test_no_op(); @@ -330,6 +329,5 @@ int main(int argc, char **argv) { grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(g_pollset); - gpr_mu_destroy(&g_mu); return 0; } diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c index f557042e39..8a1faf6303 100644 --- a/test/core/iomgr/workqueue_test.c +++ b/test/core/iomgr/workqueue_test.c @@ -39,15 +39,15 @@ #include "test/core/util/test_config.h" -static gpr_mu g_mu; +static gpr_mu *g_mu; static grpc_pollset *g_pollset; static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, bool success) { GPR_ASSERT(success == 1); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); *(int *)p = 1; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); } static void test_ref_unref(void) { @@ -71,11 +71,11 @@ static void test_add_closure(void) { grpc_workqueue_push(wq, &c, 1); grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); GPR_ASSERT(!done); grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); @@ -96,11 +96,11 @@ static void test_flush(void) { grpc_workqueue_flush(&exec_ctx, wq); grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_mu); GPR_ASSERT(!done); grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), deadline); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); @@ -117,7 +117,6 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - gpr_mu_init(&g_mu); g_pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); @@ -131,6 +130,5 @@ int main(int argc, char **argv) { grpc_shutdown(); gpr_free(g_pollset); - gpr_mu_destroy(&g_mu); return 0; } |