aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/surface/server.c
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-04-11 15:05:46 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-04-11 15:05:46 -0700
commit9d9313cfc650e79b44f95d9b7fd9e75e2dc38111 (patch)
tree76c23d6654c8aef2689e6dd19ffb8be7284cb35e /src/core/lib/surface/server.c
parent380c3a7e1e801cf5a24164a518dc59d6c431f5db (diff)
Threading robustness
Move server startup to a separate thread. Where there is no opportunity for failure, do not return bool.
Diffstat (limited to 'src/core/lib/surface/server.c')
-rw-r--r--src/core/lib/surface/server.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c
index 191ee75252..6ac3181482 100644
--- a/src/core/lib/surface/server.c
+++ b/src/core/lib/surface/server.c
@@ -44,6 +44,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
+#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/stack_lockfree.h"
@@ -1077,8 +1078,16 @@ void *grpc_server_register_method(
return m;
}
+static void start_listeners(grpc_exec_ctx *exec_ctx, void *s,
+ grpc_error *error) {
+ grpc_server *server = s;
+ for (listener *l = server->listeners; l; l = l->next) {
+ l->start(exec_ctx, server, l->arg, server->pollsets, server->pollset_count);
+ }
+ server_unref(exec_ctx, server);
+}
+
void grpc_server_start(grpc_server *server) {
- listener *l;
size_t i;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -1112,10 +1121,10 @@ void grpc_server_start(grpc_server *server) {
(size_t)server->max_requested_calls_per_cq, server);
}
- for (l = server->listeners; l; l = l->next) {
- l->start(&exec_ctx, server, l->arg, server->pollsets,
- server->pollset_count);
- }
+ server_ref(server);
+ grpc_closure_sched(&exec_ctx, grpc_closure_create(start_listeners, server,
+ grpc_executor_scheduler),
+ GRPC_ERROR_NONE);
grpc_exec_ctx_finish(&exec_ctx);
}