Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | c506e24 | 2016-01-04 15:59:29 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 34 | #include <grpc/support/port_platform.h> |
| 35 | |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 36 | #include <limits.h> |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 37 | #include <memory.h> |
| 38 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | #include <grpc/grpc.h> |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 40 | #include <grpc/support/alloc.h> |
Craig Tiller | f3756c1 | 2015-07-01 17:21:01 -0700 | [diff] [blame] | 41 | #include <grpc/support/time.h> |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 42 | /* TODO(ctiller): find another way? - better not to include census here */ |
| 43 | #include "src/core/census/grpc_plugin.h" |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 44 | #include "src/core/channel/channel_stack.h" |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 45 | #include "src/core/channel/client_channel.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 46 | #include "src/core/channel/compress_filter.h" |
| 47 | #include "src/core/channel/connected_channel.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 48 | #include "src/core/channel/http_client_filter.h" |
| 49 | #include "src/core/channel/http_server_filter.h" |
David Garcia Quintas | 5c4543d | 2015-09-03 15:49:56 -0700 | [diff] [blame] | 50 | #include "src/core/client_config/lb_policies/pick_first.h" |
David Garcia Quintas | 4fb049b | 2015-09-03 17:26:06 -0700 | [diff] [blame] | 51 | #include "src/core/client_config/lb_policies/round_robin.h" |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 52 | #include "src/core/client_config/lb_policy_registry.h" |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 53 | #include "src/core/client_config/resolver_registry.h" |
| 54 | #include "src/core/client_config/resolvers/dns_resolver.h" |
Craig Tiller | 698d00c | 2015-07-20 12:32:58 -0700 | [diff] [blame] | 55 | #include "src/core/client_config/resolvers/sockaddr_resolver.h" |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 56 | #include "src/core/client_config/subchannel.h" |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 57 | #include "src/core/client_config/subchannel_index.h" |
Vijay Pai | c914c4a | 2015-04-13 07:00:07 -0700 | [diff] [blame] | 58 | #include "src/core/debug/trace.h" |
David Garcia Quintas | 4bc3463 | 2015-10-07 16:12:35 -0700 | [diff] [blame] | 59 | #include "src/core/iomgr/executor.h" |
Vijay Pai | c914c4a | 2015-04-13 07:00:07 -0700 | [diff] [blame] | 60 | #include "src/core/iomgr/iomgr.h" |
Vijay Pai | 6dfa7e6 | 2015-04-13 10:41:40 -0700 | [diff] [blame] | 61 | #include "src/core/profiling/timers.h" |
Masood Malekghassemi | 76c3d74 | 2015-08-19 18:22:53 -0700 | [diff] [blame] | 62 | #include "src/core/surface/api_trace.h" |
murgatroid99 | d47946b | 2015-03-09 14:27:07 -0700 | [diff] [blame] | 63 | #include "src/core/surface/call.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 64 | #include "src/core/surface/channel_init.h" |
Craig Tiller | c7e1a2a | 2015-11-02 14:17:32 -0800 | [diff] [blame] | 65 | #include "src/core/surface/completion_queue.h" |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 66 | #include "src/core/surface/init.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 67 | #include "src/core/surface/lame_client.h" |
| 68 | #include "src/core/surface/server.h" |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 69 | #include "src/core/surface/surface_trace.h" |
| 70 | #include "src/core/transport/chttp2_transport.h" |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 71 | #include "src/core/transport/connectivity_state.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 72 | #include "src/core/transport/transport_impl.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 73 | |
Craig Tiller | 6d1882b | 2015-12-03 13:28:10 -0800 | [diff] [blame] | 74 | #ifndef GRPC_DEFAULT_NAME_PREFIX |
| 75 | #define GRPC_DEFAULT_NAME_PREFIX "dns:///" |
| 76 | #endif |
| 77 | |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 78 | #define MAX_PLUGINS 128 |
| 79 | |
Craig Tiller | 8ace0bc | 2015-03-05 17:16:09 -0800 | [diff] [blame] | 80 | static gpr_once g_basic_init = GPR_ONCE_INIT; |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 81 | static gpr_mu g_init_mu; |
| 82 | static int g_initializations; |
| 83 | |
Craig Tiller | 8ace0bc | 2015-03-05 17:16:09 -0800 | [diff] [blame] | 84 | static void do_basic_init(void) { |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 85 | gpr_mu_init(&g_init_mu); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 86 | /* TODO(ctiller): ideally remove this strict linkage */ |
| 87 | grpc_register_plugin(census_grpc_plugin_init, census_grpc_plugin_destroy); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 88 | g_initializations = 0; |
| 89 | } |
| 90 | |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 91 | static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { |
vjpai | e7077b5 | 2016-03-21 20:58:44 -0700 | [diff] [blame] | 92 | return grpc_channel_stack_builder_append_filter( |
| 93 | builder, (const grpc_channel_filter *)arg, NULL, NULL); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static bool prepend_filter(grpc_channel_stack_builder *builder, void *arg) { |
vjpai | e7077b5 | 2016-03-21 20:58:44 -0700 | [diff] [blame] | 97 | return grpc_channel_stack_builder_prepend_filter( |
| 98 | builder, (const grpc_channel_filter *)arg, NULL, NULL); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static bool maybe_add_http_filter(grpc_channel_stack_builder *builder, |
| 102 | void *arg) { |
| 103 | grpc_transport *t = grpc_channel_stack_builder_get_transport(builder); |
| 104 | if (t && strstr(t->vtable->name, "http")) { |
vjpai | e7077b5 | 2016-03-21 20:58:44 -0700 | [diff] [blame] | 105 | return grpc_channel_stack_builder_prepend_filter( |
| 106 | builder, (const grpc_channel_filter *)arg, NULL, NULL); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | static void register_builtin_channel_init() { |
| 112 | grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, prepend_filter, |
| 113 | (void *)&grpc_compress_filter); |
Craig Tiller | d78d164 | 2016-02-21 22:18:51 -0800 | [diff] [blame] | 114 | grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, |
| 115 | prepend_filter, |
Craig Tiller | de67626 | 2016-02-19 12:28:34 -0800 | [diff] [blame] | 116 | (void *)&grpc_compress_filter); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 117 | grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter, |
| 118 | (void *)&grpc_compress_filter); |
| 119 | grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, |
| 120 | maybe_add_http_filter, |
| 121 | (void *)&grpc_http_client_filter); |
| 122 | grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, |
| 123 | grpc_add_connected_filter, NULL); |
Craig Tiller | de67626 | 2016-02-19 12:28:34 -0800 | [diff] [blame] | 124 | grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, |
| 125 | maybe_add_http_filter, |
| 126 | (void *)&grpc_http_client_filter); |
| 127 | grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, |
| 128 | grpc_add_connected_filter, NULL); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 129 | grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, |
| 130 | maybe_add_http_filter, |
| 131 | (void *)&grpc_http_server_filter); |
| 132 | grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, |
| 133 | grpc_add_connected_filter, NULL); |
| 134 | grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, append_filter, |
| 135 | (void *)&grpc_client_channel_filter); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 136 | grpc_channel_init_register_stage(GRPC_CLIENT_LAME_CHANNEL, INT_MAX, |
| 137 | append_filter, (void *)&grpc_lame_filter); |
| 138 | grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter, |
| 139 | (void *)&grpc_server_top_filter); |
| 140 | } |
| 141 | |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 142 | typedef struct grpc_plugin { |
| 143 | void (*init)(); |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 144 | void (*destroy)(); |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 145 | } grpc_plugin; |
| 146 | |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 147 | static grpc_plugin g_all_of_the_plugins[MAX_PLUGINS]; |
| 148 | static int g_number_of_plugins = 0; |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 149 | |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 150 | void grpc_register_plugin(void (*init)(void), void (*destroy)(void)) { |
Jan Tattermusch | 1b34aeb | 2015-12-17 10:37:10 -0800 | [diff] [blame] | 151 | GRPC_API_TRACE("grpc_register_plugin(init=%p, destroy=%p)", 2, |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 152 | ((void *)(intptr_t)init, (void *)(intptr_t)destroy)); |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 153 | GPR_ASSERT(g_number_of_plugins != MAX_PLUGINS); |
| 154 | g_all_of_the_plugins[g_number_of_plugins].init = init; |
| 155 | g_all_of_the_plugins[g_number_of_plugins].destroy = destroy; |
| 156 | g_number_of_plugins++; |
Hongwei Wang | ff6097a | 2015-08-12 17:48:56 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 159 | void grpc_init(void) { |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 160 | int i; |
Craig Tiller | 8ace0bc | 2015-03-05 17:16:09 -0800 | [diff] [blame] | 161 | gpr_once_init(&g_basic_init, do_basic_init); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 162 | |
| 163 | gpr_mu_lock(&g_init_mu); |
| 164 | if (++g_initializations == 1) { |
Craig Tiller | f3756c1 | 2015-07-01 17:21:01 -0700 | [diff] [blame] | 165 | gpr_time_init(); |
Craig Tiller | 0e72ede | 2015-11-19 07:48:53 -0800 | [diff] [blame] | 166 | grpc_mdctx_global_init(); |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 167 | grpc_channel_init_init(); |
David Garcia Quintas | 5c4543d | 2015-09-03 15:49:56 -0700 | [diff] [blame] | 168 | grpc_lb_policy_registry_init(grpc_pick_first_lb_factory_create()); |
| 169 | grpc_register_lb_policy(grpc_pick_first_lb_factory_create()); |
David Garcia Quintas | 4fb049b | 2015-09-03 17:26:06 -0700 | [diff] [blame] | 170 | grpc_register_lb_policy(grpc_round_robin_lb_factory_create()); |
Craig Tiller | 6d1882b | 2015-12-03 13:28:10 -0800 | [diff] [blame] | 171 | grpc_resolver_registry_init(GRPC_DEFAULT_NAME_PREFIX); |
Craig Tiller | bc85be1 | 2015-08-24 10:36:39 -0700 | [diff] [blame] | 172 | grpc_register_resolver_type(grpc_dns_resolver_factory_create()); |
| 173 | grpc_register_resolver_type(grpc_ipv4_resolver_factory_create()); |
| 174 | grpc_register_resolver_type(grpc_ipv6_resolver_factory_create()); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 175 | #ifdef GPR_POSIX_SOCKET |
Craig Tiller | bc85be1 | 2015-08-24 10:36:39 -0700 | [diff] [blame] | 176 | grpc_register_resolver_type(grpc_unix_resolver_factory_create()); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 177 | #endif |
Masood Malekghassemi | 76c3d74 | 2015-08-19 18:22:53 -0700 | [diff] [blame] | 178 | grpc_register_tracer("api", &grpc_api_trace); |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 179 | grpc_register_tracer("channel", &grpc_trace_channel); |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 180 | grpc_register_tracer("http", &grpc_http_trace); |
Craig Tiller | 6a8c038 | 2015-04-28 10:01:22 -0700 | [diff] [blame] | 181 | grpc_register_tracer("flowctl", &grpc_flowctl_trace); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 182 | grpc_register_tracer("connectivity_state", &grpc_connectivity_state_trace); |
Craig Tiller | d78d164 | 2016-02-21 22:18:51 -0800 | [diff] [blame] | 183 | grpc_register_tracer("channel_stack_builder", |
| 184 | &grpc_trace_channel_stack_builder); |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 185 | grpc_security_pre_init(); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 186 | grpc_iomgr_init(); |
David Garcia Quintas | 4bc3463 | 2015-10-07 16:12:35 -0700 | [diff] [blame] | 187 | grpc_executor_init(); |
Craig Tiller | 9aadeb8 | 2015-04-15 11:01:08 -0700 | [diff] [blame] | 188 | grpc_tracer_init("GRPC_TRACE"); |
Craig Tiller | 0ba432d | 2015-10-09 16:57:11 -0700 | [diff] [blame] | 189 | gpr_timers_global_init(); |
Craig Tiller | c7e1a2a | 2015-11-02 14:17:32 -0800 | [diff] [blame] | 190 | grpc_cq_global_init(); |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 191 | grpc_subchannel_index_init(); |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 192 | for (i = 0; i < g_number_of_plugins; i++) { |
| 193 | if (g_all_of_the_plugins[i].init != NULL) { |
| 194 | g_all_of_the_plugins[i].init(); |
Hongwei Wang | 35d5a0f | 2015-07-24 11:14:23 -0700 | [diff] [blame] | 195 | } |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 196 | } |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 197 | /* register channel finalization AFTER all plugins, to ensure that it's run |
| 198 | * at the appropriate time */ |
| 199 | grpc_register_security_filters(); |
| 200 | register_builtin_channel_init(); |
| 201 | /* no more changes to channel init pipelines */ |
| 202 | grpc_channel_init_finalize(); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 203 | } |
| 204 | gpr_mu_unlock(&g_init_mu); |
Masood Malekghassemi | 76c3d74 | 2015-08-19 18:22:53 -0700 | [diff] [blame] | 205 | GRPC_API_TRACE("grpc_init(void)", 0, ()); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 208 | void grpc_shutdown(void) { |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 209 | int i; |
Masood Malekghassemi | 76c3d74 | 2015-08-19 18:22:53 -0700 | [diff] [blame] | 210 | GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 211 | gpr_mu_lock(&g_init_mu); |
| 212 | if (--g_initializations == 0) { |
David Garcia Quintas | 4bc3463 | 2015-10-07 16:12:35 -0700 | [diff] [blame] | 213 | grpc_executor_shutdown(); |
Craig Tiller | c7e1a2a | 2015-11-02 14:17:32 -0800 | [diff] [blame] | 214 | grpc_cq_global_shutdown(); |
| 215 | grpc_iomgr_shutdown(); |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 216 | grpc_subchannel_index_shutdown(); |
Craig Tiller | 0ba432d | 2015-10-09 16:57:11 -0700 | [diff] [blame] | 217 | gpr_timers_global_destroy(); |
Craig Tiller | 2f300e2 | 2015-06-04 08:28:43 -0700 | [diff] [blame] | 218 | grpc_tracer_shutdown(); |
Craig Tiller | f1c6191 | 2015-07-01 07:19:22 -0700 | [diff] [blame] | 219 | grpc_resolver_registry_shutdown(); |
Craig Tiller | df62b97 | 2015-12-09 15:50:19 -0800 | [diff] [blame] | 220 | grpc_lb_policy_registry_shutdown(); |
Hongwei Wang | 85ad685 | 2015-08-13 16:13:10 -0700 | [diff] [blame] | 221 | for (i = 0; i < g_number_of_plugins; i++) { |
| 222 | if (g_all_of_the_plugins[i].destroy != NULL) { |
| 223 | g_all_of_the_plugins[i].destroy(); |
Hongwei Wang | 35d5a0f | 2015-07-24 11:14:23 -0700 | [diff] [blame] | 224 | } |
Hongwei Wang | a3780a8 | 2015-07-17 15:27:18 -0700 | [diff] [blame] | 225 | } |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 226 | grpc_channel_init_shutdown(); |
Craig Tiller | 0e72ede | 2015-11-19 07:48:53 -0800 | [diff] [blame] | 227 | grpc_mdctx_global_shutdown(); |
Craig Tiller | 35108f6 | 2015-02-17 11:24:15 -0800 | [diff] [blame] | 228 | } |
| 229 | gpr_mu_unlock(&g_init_mu); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 230 | } |
Craig Tiller | 60fd361 | 2015-03-05 16:24:22 -0800 | [diff] [blame] | 231 | |
| 232 | int grpc_is_initialized(void) { |
| 233 | int r; |
Craig Tiller | 8ace0bc | 2015-03-05 17:16:09 -0800 | [diff] [blame] | 234 | gpr_once_init(&g_basic_init, do_basic_init); |
Craig Tiller | 60fd361 | 2015-03-05 16:24:22 -0800 | [diff] [blame] | 235 | gpr_mu_lock(&g_init_mu); |
| 236 | r = g_initializations > 0; |
| 237 | gpr_mu_unlock(&g_init_mu); |
| 238 | return r; |
| 239 | } |