diff options
author | 2015-10-04 23:09:47 -0700 | |
---|---|---|
committer | 2015-10-04 23:09:47 -0700 | |
commit | f747bbc04327c9ef02690cd7466ec6786967c4fe (patch) | |
tree | b031152a4387370999e91d9922fef90efc86f3ac /src/core/surface | |
parent | cb954cfc2858829fe7bff785b1a5d5204bfd338f (diff) |
s/grpc_alarm/grpc_timer && s/grpc_cq_alarm/grpc_alarm
Diffstat (limited to 'src/core/surface')
-rw-r--r-- | src/core/surface/alarm.c | 83 | ||||
-rw-r--r-- | src/core/surface/call.c | 10 | ||||
-rw-r--r-- | src/core/surface/channel_connectivity.c | 8 | ||||
-rw-r--r-- | src/core/surface/completion_queue.c | 47 | ||||
-rw-r--r-- | src/core/surface/completion_queue.h | 26 |
5 files changed, 102 insertions, 72 deletions
diff --git a/src/core/surface/alarm.c b/src/core/surface/alarm.c new file mode 100644 index 0000000000..7c47dd56f8 --- /dev/null +++ b/src/core/surface/alarm.c @@ -0,0 +1,83 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/iomgr/timer.h" +#include "src/core/surface/completion_queue.h" +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> + +struct grpc_alarm { + grpc_timer alarm; + grpc_cq_completion completion; + /** completion queue where events about this alarm will be posted */ + grpc_completion_queue *cq; + /** user supplied tag */ + void *tag; +}; + +static void do_nothing_end_completion(grpc_exec_ctx *exec_ctx, void *arg, + grpc_cq_completion *c) {} + +static void alarm_cb(grpc_exec_ctx *exec_ctx, void *arg, int success) { + grpc_alarm *alarm = arg; + grpc_cq_end_op(exec_ctx, alarm->cq, alarm->tag, success, + do_nothing_end_completion, NULL, &alarm->completion); +} + +grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline, + void *tag) { + grpc_alarm *alarm = gpr_malloc(sizeof(grpc_alarm)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + GRPC_CQ_INTERNAL_REF(cq, "alarm"); + alarm->cq = cq; + alarm->tag = tag; + + grpc_timer_init(&exec_ctx, &alarm->alarm, deadline, alarm_cb, alarm, + gpr_now(GPR_CLOCK_MONOTONIC)); + grpc_cq_begin_op(cq); + grpc_exec_ctx_finish(&exec_ctx); + return alarm; +} + +void grpc_alarm_cancel(grpc_alarm *alarm) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_cancel(&exec_ctx, &alarm->alarm); + grpc_exec_ctx_finish(&exec_ctx); +} + +void grpc_alarm_destroy(grpc_alarm *alarm) { + grpc_alarm_cancel(alarm); + GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); + gpr_free(alarm); +} diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 0b917f1561..4aa3ac3cd3 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -42,7 +42,7 @@ #include <grpc/support/useful.h> #include "src/core/channel/channel_stack.h" -#include "src/core/iomgr/alarm.h" +#include "src/core/iomgr/timer.h" #include "src/core/profiling/timers.h" #include "src/core/support/string.h" #include "src/core/surface/byte_buffer_queue.h" @@ -236,7 +236,7 @@ struct grpc_call { grpc_call_context_element context[GRPC_CONTEXT_COUNT]; /* Deadline alarm - if have_alarm is non-zero */ - grpc_alarm alarm; + grpc_timer alarm; /* Call refcount - to keep the call alive during asynchronous operations */ gpr_refcount internal_refcount; @@ -986,7 +986,7 @@ static void call_on_done_recv(grpc_exec_ctx *exec_ctx, void *pc, int success) { GPR_ASSERT(call->read_state <= READ_STATE_STREAM_CLOSED); call->read_state = READ_STATE_STREAM_CLOSED; if (call->have_alarm) { - grpc_alarm_cancel(exec_ctx, &call->alarm); + grpc_timer_cancel(exec_ctx, &call->alarm); } /* propagate cancellation to any interested children */ child_call = call->first_child; @@ -1298,7 +1298,7 @@ void grpc_call_destroy(grpc_call *c) { GPR_ASSERT(!c->destroy_called); c->destroy_called = 1; if (c->have_alarm) { - grpc_alarm_cancel(&exec_ctx, &c->alarm); + grpc_timer_cancel(&exec_ctx, &c->alarm); } cancel = c->read_state != READ_STATE_STREAM_CLOSED; unlock(&exec_ctx, c); @@ -1417,7 +1417,7 @@ static void set_deadline_alarm(grpc_exec_ctx *exec_ctx, grpc_call *call, GRPC_CALL_INTERNAL_REF(call, "alarm"); call->have_alarm = 1; call->send_deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); - grpc_alarm_init(exec_ctx, &call->alarm, call->send_deadline, call_alarm, call, + grpc_timer_init(exec_ctx, &call->alarm, call->send_deadline, call_alarm, call, gpr_now(GPR_CLOCK_MONOTONIC)); } diff --git a/src/core/surface/channel_connectivity.c b/src/core/surface/channel_connectivity.c index 47cbab154f..b992437d78 100644 --- a/src/core/surface/channel_connectivity.c +++ b/src/core/surface/channel_connectivity.c @@ -37,7 +37,7 @@ #include <grpc/support/log.h> #include "src/core/channel/client_channel.h" -#include "src/core/iomgr/alarm.h" +#include "src/core/iomgr/timer.h" #include "src/core/surface/completion_queue.h" grpc_connectivity_state grpc_channel_check_connectivity_state( @@ -74,7 +74,7 @@ typedef struct { int success; int removed; grpc_closure on_complete; - grpc_alarm alarm; + grpc_timer alarm; grpc_connectivity_state state; grpc_completion_queue *cq; grpc_cq_completion completion_storage; @@ -131,7 +131,7 @@ static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, gpr_mu_lock(&w->mu); w->success = 1; gpr_mu_unlock(&w->mu); - grpc_alarm_cancel(exec_ctx, &w->alarm); + grpc_timer_cancel(exec_ctx, &w->alarm); } gpr_mu_lock(&w->mu); @@ -187,7 +187,7 @@ void grpc_channel_watch_connectivity_state( w->tag = tag; w->channel = channel; - grpc_alarm_init(&exec_ctx, &w->alarm, + grpc_timer_init(&exec_ctx, &w->alarm, gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), timeout_complete, w, gpr_now(GPR_CLOCK_MONOTONIC)); diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 31ec1b68da..d73e5a7b46 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -36,6 +36,7 @@ #include <stdio.h> #include <string.h> +#include "src/core/iomgr/timer.h" #include "src/core/iomgr/pollset.h" #include "src/core/support/string.h" #include "src/core/surface/call.h" @@ -71,6 +72,15 @@ struct grpc_completion_queue { grpc_closure pollset_destroy_done; }; +struct grpc_cq_alarm { + grpc_timer alarm; + grpc_cq_completion completion; + /** completion queue where events about this alarm will be posted */ + grpc_completion_queue *cq; + /** user supplied tag */ + void *tag; +}; + static void on_pollset_destroy_done(grpc_exec_ctx *exec_ctx, void *cc, int success); @@ -355,40 +365,3 @@ grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) { void grpc_cq_mark_server_cq(grpc_completion_queue *cc) { cc->is_server_cq = 1; } int grpc_cq_is_server_cq(grpc_completion_queue *cc) { return cc->is_server_cq; } - -static void do_nothing_end_completion(grpc_exec_ctx *exec_ctx, void *arg, - grpc_cq_completion *c) {} - -static void cq_alarm_cb(grpc_exec_ctx *exec_ctx, void *arg, int success) { - grpc_cq_alarm *cq_alarm = arg; - grpc_cq_end_op(exec_ctx, cq_alarm->cq, cq_alarm->tag, success, - do_nothing_end_completion, NULL, &cq_alarm->completion); -} - -grpc_cq_alarm *grpc_cq_alarm_create(grpc_completion_queue *cq, - gpr_timespec deadline, void *tag) { - 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"); - cq_alarm->cq = cq; - cq_alarm->tag = tag; - - grpc_alarm_init(&exec_ctx, &cq_alarm->alarm, deadline, cq_alarm_cb, cq_alarm, - gpr_now(GPR_CLOCK_MONOTONIC)); - grpc_cq_begin_op(cq); - grpc_exec_ctx_finish(&exec_ctx); - return cq_alarm; -} - -void grpc_cq_alarm_cancel(grpc_cq_alarm *cq_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_cq_alarm *cq_alarm) { - grpc_cq_alarm_cancel(cq_alarm); - GRPC_CQ_INTERNAL_UNREF(cq_alarm->cq, "cq_alarm"); - gpr_free(cq_alarm); -} diff --git a/src/core/surface/completion_queue.h b/src/core/surface/completion_queue.h index 12a7e9a147..5f8282e542 100644 --- a/src/core/surface/completion_queue.h +++ b/src/core/surface/completion_queue.h @@ -36,7 +36,6 @@ /* Internal API for completion queues */ -#include "src/core/iomgr/alarm.h" #include "src/core/iomgr/pollset.h" #include <grpc/grpc.h> @@ -52,16 +51,6 @@ typedef struct grpc_cq_completion { gpr_uintptr next; } grpc_cq_completion; -/** An alarm associated with a completion queue. */ -typedef struct grpc_cq_alarm { - grpc_alarm alarm; - grpc_cq_completion completion; - /** completion queue where events about this alarm will be posted */ - grpc_completion_queue *cq; - /** user supplied tag */ - void *tag; -} grpc_cq_alarm; - #ifdef GRPC_CQ_REF_COUNT_DEBUG void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason, const char *file, int line); @@ -94,19 +83,4 @@ grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc); void grpc_cq_mark_server_cq(grpc_completion_queue *cc); int grpc_cq_is_server_cq(grpc_completion_queue *cc); -/** Create a completion queue alarm instance associated to \a cq. - * - * 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 - * success bit will be true, false otherwise (ie, upon cancellation). */ -grpc_cq_alarm *grpc_cq_alarm_create(grpc_completion_queue *cq, - gpr_timespec deadline, void *tag); - -/** Cancel a completion queue alarm. Calling this function ove an alarm that has - * already run has no effect. */ -void grpc_cq_alarm_cancel(grpc_cq_alarm *cq_alarm); - -/** Destroy the given completion queue alarm, cancelling it in the process. */ -void grpc_cq_alarm_destroy(grpc_cq_alarm *cq_alarm); - #endif /* GRPC_INTERNAL_CORE_SURFACE_COMPLETION_QUEUE_H */ |