diff options
author | 2015-09-22 12:32:31 -0700 | |
---|---|---|
committer | 2015-09-22 12:32:31 -0700 | |
commit | 8af4c337181322cc4fb396199c90f574cfb4163f (patch) | |
tree | 04e56ca390586007392fa65063df9019c178d406 /src/core/iomgr | |
parent | e7db29f8c74da29d88c1f373ae52a27982eb2c87 (diff) |
Final patches for rename
Diffstat (limited to 'src/core/iomgr')
-rw-r--r-- | src/core/iomgr/alarm.c | 6 | ||||
-rw-r--r-- | src/core/iomgr/alarm_internal.h | 2 | ||||
-rw-r--r-- | src/core/iomgr/closure.c | 16 | ||||
-rw-r--r-- | src/core/iomgr/closure.h | 5 | ||||
-rw-r--r-- | src/core/iomgr/exec_ctx.c | 62 | ||||
-rw-r--r-- | src/core/iomgr/exec_ctx.h | 11 | ||||
-rw-r--r-- | src/core/iomgr/iomgr.c | 4 | ||||
-rw-r--r-- | src/core/iomgr/pollset_posix.c | 12 | ||||
-rw-r--r-- | src/core/iomgr/tcp_client_posix.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/tcp_posix.c | 20 | ||||
-rw-r--r-- | src/core/iomgr/tcp_server_posix.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/workqueue.h | 11 | ||||
-rw-r--r-- | src/core/iomgr/workqueue_posix.c | 8 |
13 files changed, 108 insertions, 53 deletions
diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index 6e56ccacf5..31de551151 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -105,10 +105,10 @@ grpc_alarm_list_init (gpr_timespec now) } void -grpc_alarm_list_shutdown (grpc_closure_list * closure_list) +grpc_alarm_list_shutdown (grpc_exec_ctx *exec_ctx) { int i; - run_some_expired_alarms (gpr_inf_future (exec_ctx, g_clock_type), NULL, 0); + run_some_expired_alarms (exec_ctx, gpr_inf_future (g_clock_type), NULL, 0); for (i = 0; i < NUM_SHARDS; i++) { shard_type *shard = &g_shards[i]; @@ -373,7 +373,7 @@ int grpc_alarm_check (grpc_exec_ctx * exec_ctx, gpr_timespec now, gpr_timespec * next) { GPR_ASSERT (now.clock_type == g_clock_type); - return run_some_expired_alarms (now, next, gpr_time_cmp (now, gpr_inf_future (exec_ctx, now.clock_type)) != 0); + return run_some_expired_alarms (exec_ctx, now, next, gpr_time_cmp (now, gpr_inf_future (now.clock_type)) != 0); } gpr_timespec diff --git a/src/core/iomgr/alarm_internal.h b/src/core/iomgr/alarm_internal.h index 18ab48746f..398124d83b 100644 --- a/src/core/iomgr/alarm_internal.h +++ b/src/core/iomgr/alarm_internal.h @@ -51,7 +51,7 @@ int grpc_alarm_check (grpc_exec_ctx * exec_ctx, gpr_timespec now, gpr_timespec * next); void grpc_alarm_list_init (gpr_timespec now); -void grpc_alarm_list_shutdown (grpc_closure_list * closure_list); +void grpc_alarm_list_shutdown (grpc_exec_ctx * exec_ctx); gpr_timespec grpc_alarm_list_next_timeout (void); diff --git a/src/core/iomgr/closure.c b/src/core/iomgr/closure.c index cd02aac75e..4c1a1233d6 100644 --- a/src/core/iomgr/closure.c +++ b/src/core/iomgr/closure.c @@ -59,22 +59,6 @@ grpc_closure_list_add (grpc_closure_list * closure_list, grpc_closure * closure, closure_list->tail = closure; } -void -grpc_closure_list_run (grpc_closure_list * closure_list) -{ - while (!grpc_closure_list_empty (*closure_list)) - { - grpc_closure *c = closure_list->head; - closure_list->head = closure_list->tail = NULL; - while (c != NULL) - { - grpc_closure *next = c->next; - c->cb (exec_ctx, c->cb_arg, c->success); - c = next; - } - } -} - int grpc_closure_list_empty (grpc_closure_list closure_list) { diff --git a/src/core/iomgr/closure.h b/src/core/iomgr/closure.h index 90d9e328a1..e76e157f6a 100644 --- a/src/core/iomgr/closure.h +++ b/src/core/iomgr/closure.h @@ -39,6 +39,10 @@ struct grpc_closure; typedef struct grpc_closure grpc_closure; +/* forward declaration for exec_ctx.h */ +struct grpc_exec_ctx; +typedef struct grpc_exec_ctx grpc_exec_ctx; + typedef struct grpc_closure_list { grpc_closure *head; @@ -77,7 +81,6 @@ void grpc_closure_init (grpc_closure * closure, grpc_iomgr_cb_func cb, void *cb_ { NULL, NULL } void grpc_closure_list_add (grpc_closure_list * list, grpc_closure * closure, int success); -void grpc_closure_list_run (grpc_closure_list * list); void grpc_closure_list_move (grpc_closure_list * src, grpc_closure_list * dst); int grpc_closure_list_empty (grpc_closure_list list); diff --git a/src/core/iomgr/exec_ctx.c b/src/core/iomgr/exec_ctx.c new file mode 100644 index 0000000000..d5a8cf4475 --- /dev/null +++ b/src/core/iomgr/exec_ctx.c @@ -0,0 +1,62 @@ +/* + * + * 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/exec_ctx.h" + +void +grpc_exec_ctx_flush (grpc_exec_ctx *exec_ctx) +{ + while (!grpc_closure_list_empty (exec_ctx->closure_list)) + { + grpc_closure *c = closure_list->head; + closure_list->head = closure_list->tail = NULL; + while (c != NULL) + { + grpc_closure *next = c->next; + c->cb (exec_ctx, c->cb_arg, c->success); + c = next; + } + } +} + +void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) { + grpc_exec_ctx_flush(exec_ctx); +} + +void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, int success) { + grpc_closure_list_add(&exec_ctx->closure_list, closure, success); +} + +void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, grpc_closure_list *list) { + grpc_closure_list_move(list, &exec_ctx->closure_list); +} diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h index 4d30feb26b..ff084abeba 100644 --- a/src/core/iomgr/exec_ctx.h +++ b/src/core/iomgr/exec_ctx.h @@ -36,4 +36,15 @@ #include "src/core/iomgr/closure.h" +struct grpc_exec_ctx { + grpc_closure_list closure_list; +}; + +#define GRPC_EXEC_CTX_INIT { GRPC_CLOSURE_LIST_INIT } + +void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx); +void grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx); +void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, int success); +void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, grpc_closure_list *list); + #endif diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index 6a0f6c4937..30da17fdd8 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -113,7 +113,7 @@ grpc_iomgr_shutdown (void) } last_warning_time = gpr_now (GPR_CLOCK_REALTIME); } - if (grpc_alarm_check (gpr_inf_future (&exec_ctx, GPR_CLOCK_MONOTONIC), NULL)) + if (grpc_alarm_check (&exec_ctx, gpr_inf_future (GPR_CLOCK_MONOTONIC), NULL)) { gpr_mu_unlock (&g_mu); grpc_exec_ctx_finish (&exec_ctx); @@ -142,7 +142,7 @@ grpc_iomgr_shutdown (void) } gpr_mu_unlock (&g_mu); - grpc_alarm_list_shutdown (&closure_list); + grpc_alarm_list_shutdown (&exec_ctx); grpc_exec_ctx_finish (&exec_ctx); /* ensure all threads have left g_mu */ diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 2f08dd0f70..fedc0d8aed 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -217,7 +217,7 @@ grpc_pollset_work (grpc_exec_ctx * exec_ctx, grpc_pollset * pollset, grpc_pollse grpc_wakeup_fd_init (&worker->wakeup_fd); if (!grpc_pollset_has_workers (pollset) && !grpc_closure_list_empty (pollset->idle_jobs)) { - grpc_closure_list_move (exec_ctx, &pollset->idle_jobs); + grpc_exec_ctx_enqueue_list (exec_ctx, &pollset->idle_jobs); goto done; } if (grpc_alarm_check (exec_ctx, now, &deadline)) @@ -251,7 +251,7 @@ grpc_pollset_work (grpc_exec_ctx * exec_ctx, grpc_pollset * pollset, grpc_pollse done: if (!locked) { - grpc_closure_list_run (closure_list); + grpc_exec_ctx_flush (exec_ctx); gpr_mu_lock (&pollset->mu); locked = 1; } @@ -271,7 +271,7 @@ done: pollset->called_shutdown = 1; gpr_mu_unlock (&pollset->mu); finish_shutdown (exec_ctx, pollset); - grpc_closure_list_run (closure_list); + grpc_exec_ctx_flush (exec_ctx); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * grpc_pollset_work. @@ -397,7 +397,7 @@ basic_do_promote (grpc_exec_ctx * exec_ctx, void *args, int success) if (fds[0] && !grpc_fd_is_orphaned (fds[0])) { - grpc_platform_become_multipoller (pollset, fds, GPR_ARRAY_SIZE (exec_ctx, fds)); + grpc_platform_become_multipoller (exec_ctx, pollset, fds, GPR_ARRAY_SIZE (fds)); GRPC_FD_UNREF (fds[0], "basicpoll"); } else @@ -417,8 +417,6 @@ basic_do_promote (grpc_exec_ctx * exec_ctx, void *args, int success) /* Matching ref in basic_pollset_add_fd */ GRPC_FD_UNREF (fd, "basicpoll_add"); - - grpc_closure_list_run (closure_list); } static void @@ -445,7 +443,7 @@ basic_pollset_add_fd (grpc_exec_ctx * exec_ctx, grpc_pollset * pollset, grpc_fd } else if (!grpc_fd_is_orphaned (fds[0])) { - grpc_platform_become_multipoller (pollset, fds, GPR_ARRAY_SIZE (exec_ctx, fds)); + grpc_platform_become_multipoller (exec_ctx, pollset, fds, GPR_ARRAY_SIZE (fds)); GRPC_FD_UNREF (fds[0], "basicpoll"); } else diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index e3cecd3a36..3949ce6f24 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -315,7 +315,7 @@ grpc_tcp_client_connect (grpc_exec_ctx * exec_ctx, grpc_closure * closure, grpc_ } gpr_mu_lock (&ac->mu); - grpc_alarm_init (&ac->alarm, gpr_convert_clock_type (deadline, GPR_CLOCK_MONOTONIC), tc_on_alarm, ac, gpr_now (exec_ctx, GPR_CLOCK_MONOTONIC)); + grpc_alarm_init (exec_ctx, &ac->alarm, gpr_convert_clock_type (deadline, GPR_CLOCK_MONOTONIC), tc_on_alarm, ac, gpr_now (GPR_CLOCK_MONOTONIC)); grpc_fd_notify_on_write (exec_ctx, ac->fd, &ac->write_closure); gpr_mu_unlock (&ac->mu); diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index b24bc2e11e..cd0769a48b 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -95,10 +95,8 @@ typedef struct char *peer_string; } grpc_tcp; -static void tcp_handle_read (void *arg /* grpc_tcp */ , int success, - grpc_closure_list * closure_list); -static void tcp_handle_write (void *arg /* grpc_tcp */ , int success, - grpc_closure_list * closure_list); +static void tcp_handle_read (grpc_exec_ctx * exec_ctx, void *arg /* grpc_tcp */ , int success); +static void tcp_handle_write (grpc_exec_ctx * exec_ctx, void *arg /* grpc_tcp */ , int success); static void tcp_shutdown (grpc_exec_ctx * exec_ctx, grpc_endpoint * ep) @@ -117,11 +115,11 @@ tcp_free (grpc_exec_ctx * exec_ctx, grpc_tcp * tcp) /*#define GRPC_TCP_REFCOUNT_DEBUG*/ #ifdef GRPC_TCP_REFCOUNT_DEBUG -#define TCP_UNREF(tcp, reason, cl) \ - tcp_unref((tcp), (cl), (reason), __FILE__, __LINE__) +#define TCP_UNREF(cl, tcp, reason) \ + tcp_unref((cl), (tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) static void -tcp_unref (grpc_tcp * tcp, grpc_closure_list * closure_list, const char *reason, const char *file, int line) +tcp_unref (grpc_exec_ctx *exec_ctx, grpc_tcp * tcp, const char *reason, const char *file, int line) { gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "TCP unref %p : %s %d -> %d", tcp, reason, tcp->refcount.count, tcp->refcount.count - 1); if (gpr_unref (&tcp->refcount)) @@ -137,7 +135,7 @@ tcp_ref (grpc_tcp * tcp, const char *reason, const char *file, int line) gpr_ref (&tcp->refcount); } #else -#define TCP_UNREF(tcp, reason, cl) tcp_unref((tcp), (cl)) +#define TCP_UNREF(cl, tcp, reason) tcp_unref((cl), (tcp)) #define TCP_REF(tcp, reason) tcp_ref((tcp)) static void tcp_unref (grpc_exec_ctx * exec_ctx, grpc_tcp * tcp) @@ -273,8 +271,7 @@ tcp_continue_read (grpc_exec_ctx * exec_ctx, grpc_tcp * tcp) } static void -tcp_handle_read (void *arg /* grpc_tcp */ , int success, - grpc_closure_list * closure_list) +tcp_handle_read (grpc_exec_ctx * exec_ctx, void *arg /* grpc_tcp */ , int success) { grpc_tcp *tcp = (grpc_tcp *) arg; GPR_ASSERT (!tcp->finished_edge); @@ -401,8 +398,7 @@ tcp_flush (grpc_tcp * tcp) } static void -tcp_handle_write (void *arg /* grpc_tcp */ , int success, - grpc_closure_list * closure_list) +tcp_handle_write (grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */ , int success) { grpc_tcp *tcp = (grpc_tcp *) arg; flush_result status; diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 5e83b8b3fd..79e8039c79 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -387,7 +387,7 @@ on_read (grpc_exec_ctx * exec_ctx, void *arg, int success) { grpc_pollset_add_fd (exec_ctx, sp->server->pollsets[i], fdobj); } - sp->server->on_accept_cb (sp->server->on_accept_cb_arg, grpc_tcp_create (exec_ctx, fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE, addr_str)); + sp->server->on_accept_cb (exec_ctx, sp->server->on_accept_cb_arg, grpc_tcp_create (fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE, addr_str)); gpr_free (name); gpr_free (addr_str); diff --git a/src/core/iomgr/workqueue.h b/src/core/iomgr/workqueue.h index c5d7c64e83..0790fdb006 100644 --- a/src/core/iomgr/workqueue.h +++ b/src/core/iomgr/workqueue.h @@ -37,6 +37,7 @@ #include "src/core/iomgr/iomgr.h" #include "src/core/iomgr/pollset.h" #include "src/core/iomgr/closure.h" +#include "src/core/iomgr/exec_ctx.h" #ifdef GPR_POSIX_SOCKET #include "src/core/iomgr/workqueue_posix.h" @@ -51,7 +52,7 @@ struct grpc_workqueue; typedef struct grpc_workqueue grpc_workqueue; /** Create a work queue */ -grpc_workqueue *grpc_workqueue_create (grpc_closure_list * closure_list); +grpc_workqueue *grpc_workqueue_create (grpc_exec_ctx *exec_ctx); void grpc_workqueue_flush (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue); @@ -59,13 +60,13 @@ void grpc_workqueue_flush (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue) #ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG #define GRPC_WORKQUEUE_REF(p, r) \ grpc_workqueue_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_WORKQUEUE_UNREF(p, r, cl) \ - grpc_workqueue_unref((p), (cl), __FILE__, __LINE__, (r)) +#define GRPC_WORKQUEUE_UNREF(cl, p, r) \ + grpc_workqueue_unref((cl), (p), __FILE__, __LINE__, (r)) void grpc_workqueue_ref (grpc_workqueue * workqueue, const char *file, int line, const char *reason); -void grpc_workqueue_unref (grpc_workqueue * workqueue, grpc_closure_list * closure_list, const char *file, int line, const char *reason); +void grpc_workqueue_unref (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue, const char *file, int line, const char *reason); #else #define GRPC_WORKQUEUE_REF(p, r) grpc_workqueue_ref((p)) -#define GRPC_WORKQUEUE_UNREF(p, r, cl) grpc_workqueue_unref((p), (cl)) +#define GRPC_WORKQUEUE_UNREF(cl, p, r) grpc_workqueue_unref((cl), (p)) void grpc_workqueue_ref (grpc_workqueue * workqueue); void grpc_workqueue_unref (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue); #endif diff --git a/src/core/iomgr/workqueue_posix.c b/src/core/iomgr/workqueue_posix.c index a407fb61a4..91ac0f32e4 100644 --- a/src/core/iomgr/workqueue_posix.c +++ b/src/core/iomgr/workqueue_posix.c @@ -48,7 +48,7 @@ static void on_readable (grpc_exec_ctx * exec_ctx, void *arg, int success); grpc_workqueue * -grpc_workqueue_create (grpc_closure_list * closure_list) +grpc_workqueue_create (grpc_exec_ctx *exec_ctx) { char name[32]; grpc_workqueue *workqueue = gpr_malloc (sizeof (grpc_workqueue)); @@ -85,7 +85,7 @@ grpc_workqueue_ref (grpc_workqueue * workqueue) #ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG void -grpc_workqueue_unref (grpc_workqueue * workqueue, grpc_closure_list * closure_list, const char *file, int line, const char *reason) +grpc_workqueue_unref (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue, const char *file, int line, const char *reason) { gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "WORKQUEUE:%p unref %d -> %d %s", workqueue, (int) workqueue->refs.count, (int) workqueue->refs.count - 1, reason); #else @@ -109,7 +109,7 @@ void grpc_workqueue_flush (grpc_exec_ctx * exec_ctx, grpc_workqueue * workqueue) { gpr_mu_lock (&workqueue->mu); - grpc_closure_list_move (exec_ctx, &workqueue->closure_list); + grpc_closure_list_move (&exec_ctx->closure_list, &workqueue->closure_list); gpr_mu_unlock (&workqueue->mu); } @@ -130,7 +130,7 @@ on_readable (grpc_exec_ctx * exec_ctx, void *arg, int success) else { gpr_mu_lock (&workqueue->mu); - grpc_closure_list_move (exec_ctx, &workqueue->closure_list); + grpc_closure_list_move (&exec_ctx->closure_list, &workqueue->closure_list); grpc_wakeup_fd_consume_wakeup (&workqueue->wakeup_fd); gpr_mu_unlock (&workqueue->mu); grpc_fd_notify_on_read (exec_ctx, workqueue->wakeup_read_fd, &workqueue->read_closure); |