Change return type to bool

pull/11703/head
yang-g 7 years ago
parent 533fbd362f
commit 7d6b914f98
  1. 2
      src/core/ext/filters/client_channel/channel_connectivity.c
  2. 2
      src/core/lib/surface/alarm.c
  3. 4
      src/core/lib/surface/call.c
  4. 2
      src/core/lib/surface/channel_ping.c
  5. 18
      src/core/lib/surface/completion_queue.c
  6. 6
      src/core/lib/surface/completion_queue.h
  7. 6
      src/core/lib/surface/server.c
  8. 6
      test/core/surface/completion_queue_test.c
  9. 4
      test/core/surface/completion_queue_threading_test.c
  10. 6
      test/cpp/microbenchmarks/bm_cq.cc
  11. 2
      test/cpp/microbenchmarks/bm_cq_multiple_threads.cc

@ -208,7 +208,7 @@ void grpc_channel_watch_connectivity_state(
7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec,
(int)deadline.clock_type, cq, tag));
GPR_ASSERT(grpc_cq_begin_op(cq, tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
gpr_mu_init(&w->mu);
GRPC_CLOSURE_INIT(&w->on_complete, watch_complete, w,

@ -50,7 +50,7 @@ grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline,
alarm->cq = cq;
alarm->tag = tag;
GPR_ASSERT(grpc_cq_begin_op(cq, tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
GRPC_CLOSURE_INIT(&alarm->on_alarm, alarm_cb, alarm,
grpc_schedule_on_exec_ctx);
grpc_timer_init(&exec_ctx, &alarm->alarm,

@ -1422,7 +1422,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx,
if (nops == 0) {
if (!is_notify_tag_closure) {
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag));
grpc_cq_end_op(exec_ctx, call->cq, notify_tag, GRPC_ERROR_NONE,
free_no_op_completion, NULL,
gpr_malloc(sizeof(grpc_cq_completion)));
@ -1723,7 +1723,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx,
GRPC_CALL_INTERNAL_REF(call, "completion");
if (!is_notify_tag_closure) {
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag));
}
gpr_ref_init(&bctl->steps_to_complete, num_completion_callbacks_needed);

@ -59,7 +59,7 @@ void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq,
GRPC_CLOSURE_INIT(&pr->closure, ping_done, pr, grpc_schedule_on_exec_ctx);
op->send_ping = &pr->closure;
op->bind_pollset = grpc_cq_pollset(cq);
GPR_ASSERT(grpc_cq_begin_op(cq, tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
top_elem->filter->start_transport_op(&exec_ctx, top_elem, op);
grpc_exec_ctx_finish(&exec_ctx);
}

@ -196,7 +196,7 @@ typedef struct cq_vtable {
void (*init)(void *data);
void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq);
void (*destroy)(void *data);
int (*begin_op)(grpc_completion_queue *cq, void *tag);
bool (*begin_op)(grpc_completion_queue *cq, void *tag);
void (*end_op)(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, void *tag,
grpc_error *error,
void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg,
@ -288,8 +288,8 @@ static void cq_shutdown_next(grpc_exec_ctx *exec_ctx,
static void cq_shutdown_pluck(grpc_exec_ctx *exec_ctx,
grpc_completion_queue *cq);
static int cq_begin_op_for_next(grpc_completion_queue *cq, void *tag);
static int cq_begin_op_for_pluck(grpc_completion_queue *cq, void *tag);
static bool cq_begin_op_for_next(grpc_completion_queue *cq, void *tag);
static bool cq_begin_op_for_pluck(grpc_completion_queue *cq, void *tag);
static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx,
grpc_completion_queue *cq, void *tag,
@ -549,28 +549,28 @@ static void cq_check_tag(grpc_completion_queue *cq, void *tag, bool lock_cq) {
static void cq_check_tag(grpc_completion_queue *cq, void *tag, bool lock_cq) {}
#endif
static int cq_begin_op_for_next(grpc_completion_queue *cq, void *tag) {
static bool cq_begin_op_for_next(grpc_completion_queue *cq, void *tag) {
cq_next_data *cqd = DATA_FROM_CQ(cq);
while (true) {
gpr_atm count = gpr_atm_no_barrier_load(&cqd->pending_events);
if (count == 0) {
cq_check_tag(cq, tag, true); /* Used in debug builds only */
return 1;
return false;
} else if (gpr_atm_no_barrier_cas(&cqd->pending_events, count, count + 1)) {
break;
}
}
return 0;
return true;
}
static int cq_begin_op_for_pluck(grpc_completion_queue *cq, void *tag) {
static bool cq_begin_op_for_pluck(grpc_completion_queue *cq, void *tag) {
cq_pluck_data *cqd = DATA_FROM_CQ(cq);
GPR_ASSERT(!cqd->shutdown_called);
gpr_ref(&cqd->pending_events);
return 0;
return true;
}
int grpc_cq_begin_op(grpc_completion_queue *cq, void *tag) {
bool grpc_cq_begin_op(grpc_completion_queue *cq, void *tag) {
#ifndef NDEBUG
gpr_mu_lock(cq->mu);
if (cq->outstanding_tag_count == cq->outstanding_tag_capacity) {

@ -72,9 +72,9 @@ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc);
/* Flag that an operation is beginning: the completion channel will not finish
shutdown until a corrensponding grpc_cq_end_* call is made.
\a tag is currently used only in debug builds. Return 0 on success and 1 if
completion_queue has been shutdown. */
int grpc_cq_begin_op(grpc_completion_queue *cc, void *tag);
\a tag is currently used only in debug builds. Return true on success, and
false if completion_queue has been shutdown. */
bool grpc_cq_begin_op(grpc_completion_queue *cc, void *tag);
/* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to
grpc_cq_begin_op */

@ -1259,7 +1259,7 @@ void grpc_server_shutdown_and_notify(grpc_server *server,
}
/* stay locked, and gather up some stuff to do */
GPR_ASSERT(grpc_cq_begin_op(cq, tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
if (server->shutdown_published) {
grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown,
NULL, gpr_malloc(sizeof(grpc_cq_completion)));
@ -1446,7 +1446,7 @@ grpc_call_error grpc_server_request_call(
error = GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
goto done;
}
if (grpc_cq_begin_op(cq_for_notification, tag)) {
if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
gpr_free(rc);
error = GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
goto done;
@ -1500,7 +1500,7 @@ grpc_call_error grpc_server_request_registered_call(
error = GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
goto done;
}
if (grpc_cq_begin_op(cq_for_notification, tag)) {
if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
gpr_free(rc);
error = GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
goto done;

@ -144,7 +144,7 @@ static void test_cq_end_op(void) {
cc = grpc_completion_queue_create(
grpc_completion_queue_factory_lookup(&attr), &attr, NULL);
GPR_ASSERT(grpc_cq_begin_op(cc, tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(cc, tag));
grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE,
do_nothing_end_completion, NULL, &completion);
@ -233,7 +233,7 @@ static void test_pluck(void) {
grpc_completion_queue_factory_lookup(&attr), &attr, NULL);
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]) == 0);
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, NULL, &completions[i]);
}
@ -245,7 +245,7 @@ static void test_pluck(void) {
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]) == 0);
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, NULL, &completions[i]);
}

@ -107,7 +107,7 @@ static void test_too_many_plucks(void) {
GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT);
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]) == 0);
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, NULL, &completions[i]);
}
@ -153,7 +153,7 @@ static void producer_thread(void *arg) {
gpr_log(GPR_INFO, "producer %d phase 1", opt->id);
for (i = 0; i < TEST_THREAD_EVENTS; i++) {
GPR_ASSERT(grpc_cq_begin_op(opt->cc, (void *)(intptr_t)1) == 0);
GPR_ASSERT(grpc_cq_begin_op(opt->cc, (void *)(intptr_t)1));
}
gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id);

@ -83,7 +83,7 @@ static void BM_Pass1Cpp(benchmark::State& state) {
grpc_cq_completion completion;
DummyTag dummy_tag;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(c_cq, &dummy_tag));
grpc_cq_end_op(&exec_ctx, c_cq, &dummy_tag, GRPC_ERROR_NONE,
DoneWithCompletionOnStack, NULL, &completion);
grpc_exec_ctx_finish(&exec_ctx);
@ -103,7 +103,7 @@ static void BM_Pass1Core(benchmark::State& state) {
while (state.KeepRunning()) {
grpc_cq_completion completion;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GPR_ASSERT(grpc_cq_begin_op(cq, NULL) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, NULL));
grpc_cq_end_op(&exec_ctx, cq, NULL, GRPC_ERROR_NONE,
DoneWithCompletionOnStack, NULL, &completion);
grpc_exec_ctx_finish(&exec_ctx);
@ -122,7 +122,7 @@ static void BM_Pluck1Core(benchmark::State& state) {
while (state.KeepRunning()) {
grpc_cq_completion completion;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GPR_ASSERT(grpc_cq_begin_op(cq, NULL) == 0);
GPR_ASSERT(grpc_cq_begin_op(cq, NULL));
grpc_cq_end_op(&exec_ctx, cq, NULL, GRPC_ERROR_NONE,
DoneWithCompletionOnStack, NULL, &completion);
grpc_exec_ctx_finish(&exec_ctx);

@ -78,7 +78,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps,
}
gpr_mu_unlock(&ps->mu);
GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag) == 0);
GPR_ASSERT(grpc_cq_begin_op(g_cq, g_tag));
grpc_cq_end_op(exec_ctx, g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, NULL,
(grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion)));
grpc_exec_ctx_flush(exec_ctx);

Loading…
Cancel
Save