Removed exec_ctx from cq_alarm's functions

pull/3618/head
David Garcia Quintas 9 years ago
parent 0dfbdf6e54
commit cb954cfc28
  1. 17
      src/core/surface/completion_queue.c
  2. 7
      src/core/surface/completion_queue.h
  3. 18
      test/core/surface/completion_queue_test.c

@ -365,27 +365,30 @@ static void cq_alarm_cb(grpc_exec_ctx *exec_ctx, void *arg, int success) {
do_nothing_end_completion, NULL, &cq_alarm->completion); do_nothing_end_completion, NULL, &cq_alarm->completion);
} }
grpc_cq_alarm *grpc_cq_alarm_create(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *grpc_cq_alarm_create(grpc_completion_queue *cq,
grpc_completion_queue *cq,
gpr_timespec deadline, void *tag) { gpr_timespec deadline, void *tag) {
grpc_cq_alarm *cq_alarm = gpr_malloc(sizeof(grpc_cq_alarm)); grpc_cq_alarm *cq_alarm = gpr_malloc(sizeof(grpc_cq_alarm));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GRPC_CQ_INTERNAL_REF(cq, "cq_alarm"); GRPC_CQ_INTERNAL_REF(cq, "cq_alarm");
cq_alarm->cq = cq; cq_alarm->cq = cq;
cq_alarm->tag = tag; cq_alarm->tag = tag;
grpc_alarm_init(exec_ctx, &cq_alarm->alarm, deadline, cq_alarm_cb, cq_alarm, grpc_alarm_init(&exec_ctx, &cq_alarm->alarm, deadline, cq_alarm_cb, cq_alarm,
gpr_now(GPR_CLOCK_MONOTONIC)); gpr_now(GPR_CLOCK_MONOTONIC));
grpc_cq_begin_op(cq); grpc_cq_begin_op(cq);
grpc_exec_ctx_finish(&exec_ctx);
return cq_alarm; return cq_alarm;
} }
void grpc_cq_alarm_cancel(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *cq_alarm) { void grpc_cq_alarm_cancel(grpc_cq_alarm *cq_alarm) {
grpc_alarm_cancel(exec_ctx, &cq_alarm->alarm); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_alarm_cancel(&exec_ctx, &cq_alarm->alarm);
grpc_exec_ctx_finish(&exec_ctx);
} }
void grpc_cq_alarm_destroy(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *cq_alarm) { void grpc_cq_alarm_destroy(grpc_cq_alarm *cq_alarm) {
grpc_cq_alarm_cancel(exec_ctx, cq_alarm); grpc_cq_alarm_cancel(cq_alarm);
GRPC_CQ_INTERNAL_UNREF(cq_alarm->cq, "cq_alarm"); GRPC_CQ_INTERNAL_UNREF(cq_alarm->cq, "cq_alarm");
gpr_free(cq_alarm); gpr_free(cq_alarm);
} }

@ -99,15 +99,14 @@ int grpc_cq_is_server_cq(grpc_completion_queue *cc);
* Once the alarm expires (at \a deadline) or it's cancelled (see ...), an event * Once the alarm expires (at \a deadline) or it's cancelled (see ...), an event
* with tag \a tag will be added to \a cq. If the alarm expired, the event's * with tag \a tag will be added to \a cq. If the alarm expired, the event's
* success bit will be true, false otherwise (ie, upon cancellation). */ * success bit will be true, false otherwise (ie, upon cancellation). */
grpc_cq_alarm *grpc_cq_alarm_create(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *grpc_cq_alarm_create(grpc_completion_queue *cq,
grpc_completion_queue *cq,
gpr_timespec deadline, void *tag); gpr_timespec deadline, void *tag);
/** Cancel a completion queue alarm. Calling this function ove an alarm that has /** Cancel a completion queue alarm. Calling this function ove an alarm that has
* already run has no effect. */ * already run has no effect. */
void grpc_cq_alarm_cancel(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *cq_alarm); void grpc_cq_alarm_cancel(grpc_cq_alarm *cq_alarm);
/** Destroy the given completion queue alarm, cancelling it in the process. */ /** Destroy the given completion queue alarm, cancelling it in the process. */
void grpc_cq_alarm_destroy(grpc_exec_ctx *exec_ctx, grpc_cq_alarm *cq_alarm); void grpc_cq_alarm_destroy(grpc_cq_alarm *cq_alarm);
#endif /* GRPC_INTERNAL_CORE_SURFACE_COMPLETION_QUEUE_H */ #endif /* GRPC_INTERNAL_CORE_SURFACE_COMPLETION_QUEUE_H */

@ -104,7 +104,6 @@ static void test_cq_end_op(void) {
static void test_cq_alarm(void) { static void test_cq_alarm(void) {
grpc_completion_queue *cc; grpc_completion_queue *cc;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
LOG_TEST("test_cq_alarm"); LOG_TEST("test_cq_alarm");
cc = grpc_completion_queue_create(NULL); cc = grpc_completion_queue_create(NULL);
@ -112,35 +111,32 @@ static void test_cq_alarm(void) {
/* regular expiry */ /* regular expiry */
grpc_event ev; grpc_event ev;
void *tag = create_test_tag(); void *tag = create_test_tag();
grpc_cq_alarm *cq_alarm = grpc_cq_alarm_create( grpc_cq_alarm *cq_alarm =
&exec_ctx, cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), tag); grpc_cq_alarm_create(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), tag);
ev = grpc_completion_queue_next(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2), ev = grpc_completion_queue_next(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2),
NULL); NULL);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
GPR_ASSERT(ev.tag == tag); GPR_ASSERT(ev.tag == tag);
GPR_ASSERT(ev.success); GPR_ASSERT(ev.success);
grpc_cq_alarm_destroy(&exec_ctx, cq_alarm); grpc_cq_alarm_destroy(cq_alarm);
} }
{ {
/* cancellation */ /* cancellation */
grpc_event ev; grpc_event ev;
void *tag = create_test_tag(); void *tag = create_test_tag();
grpc_cq_alarm *cq_alarm = grpc_cq_alarm_create( grpc_cq_alarm *cq_alarm =
&exec_ctx, cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2), tag); grpc_cq_alarm_create(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2), tag);
grpc_cq_alarm_cancel(&exec_ctx, cq_alarm); grpc_cq_alarm_cancel(cq_alarm);
GPR_ASSERT(grpc_exec_ctx_flush(&exec_ctx) == 1);
ev = grpc_completion_queue_next(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), ev = grpc_completion_queue_next(cc, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1),
NULL); NULL);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
GPR_ASSERT(ev.tag == tag); GPR_ASSERT(ev.tag == tag);
GPR_ASSERT(ev.success == 0); GPR_ASSERT(ev.success == 0);
grpc_cq_alarm_destroy(&exec_ctx, cq_alarm); grpc_cq_alarm_destroy(cq_alarm);
} }
shutdown_and_destroy(cc); shutdown_and_destroy(cc);
grpc_exec_ctx_finish(&exec_ctx);
} }
static void test_shutdown_then_next_polling(void) { static void test_shutdown_then_next_polling(void) {

Loading…
Cancel
Save