static void test_ref_unref(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); GRPC_WORKQUEUE_REF(wq, "test"); GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "test"); GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy"); grpc_exec_ctx_finish(&exec_ctx); }
static void really_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock) { GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p really_destroy", lock)); GPR_ASSERT(gpr_atm_no_barrier_load(&lock->state) == 0); gpr_mpscq_destroy(&lock->queue); GRPC_WORKQUEUE_UNREF(exec_ctx, lock->optional_workqueue, "combiner"); gpr_free(lock); }
static void test_flush(void) { grpc_closure c; int done = 0; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); grpc_pollset_worker *worker = NULL; grpc_closure_init(&c, must_succeed, &done); grpc_exec_ctx_enqueue(&exec_ctx, &c, true, NULL); grpc_workqueue_flush(&exec_ctx, wq); grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); gpr_mu_lock(g_mu); while (!done) { grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), deadline); } gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy"); grpc_exec_ctx_finish(&exec_ctx); }
static void test_add_closure(void) { grpc_closure c; int done = 0; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); grpc_pollset_worker worker; grpc_closure_init(&c, must_succeed, &done); grpc_workqueue_push(wq, &c, 1); grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); GPR_ASSERT(!done); grpc_pollset_work(&exec_ctx, &g_pollset, &worker, gpr_now(deadline.clock_type), deadline); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy"); grpc_exec_ctx_finish(&exec_ctx); }