grpc 1.19.0 → 1.20.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +4131 -7903
  3. data/include/grpc/grpc.h +11 -6
  4. data/include/grpc/grpc_security.h +51 -9
  5. data/include/grpc/impl/codegen/byte_buffer.h +13 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +4 -0
  7. data/include/grpc/impl/codegen/port_platform.h +37 -6
  8. data/include/grpc/impl/codegen/sync_posix.h +18 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +560 -236
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -2
  11. data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
  12. data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
  13. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +7 -4
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -2
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +105 -28
  16. data/src/core/ext/filters/client_channel/lb_policy.h +259 -141
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +789 -803
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +1 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +7 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +8 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +2 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +127 -219
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +103 -282
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +4 -10
  28. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +709 -906
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +8 -8
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -6
  33. data/src/core/ext/filters/client_channel/resolver.cc +54 -1
  34. data/src/core/ext/filters/client_channel/resolver.h +51 -22
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +34 -86
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +29 -41
  37. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +32 -78
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +109 -72
  39. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
  41. data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
  42. data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
  43. data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +69 -49
  45. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +11 -8
  46. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +568 -0
  47. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +141 -0
  48. data/src/core/ext/filters/client_channel/server_address.cc +0 -48
  49. data/src/core/ext/filters/client_channel/server_address.h +0 -10
  50. data/src/core/{lib/transport → ext/filters/client_channel}/service_config.cc +10 -5
  51. data/src/core/{lib/transport → ext/filters/client_channel}/service_config.h +16 -12
  52. data/src/core/ext/filters/client_channel/subchannel.cc +11 -16
  53. data/src/core/ext/filters/client_channel/subchannel.h +3 -0
  54. data/src/core/ext/filters/max_age/max_age_filter.cc +4 -1
  55. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -2
  56. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -45
  57. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +133 -134
  58. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
  59. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
  60. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
  61. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
  62. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -29
  63. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_data.cc +2 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
  67. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
  68. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
  69. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
  70. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +5 -4
  71. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
  72. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -1
  73. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  74. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -4
  75. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
  76. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +7 -6
  77. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
  78. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
  79. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -1
  80. data/src/core/ext/transport/chttp2/transport/internal.h +5 -4
  81. data/src/core/ext/transport/chttp2/transport/parsing.cc +9 -9
  82. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -1
  83. data/src/core/ext/transport/inproc/inproc_transport.cc +8 -0
  84. data/src/core/lib/channel/channel_args.cc +2 -0
  85. data/src/core/lib/channel/channel_args.h +3 -0
  86. data/src/core/lib/channel/channel_stack.h +1 -1
  87. data/src/core/lib/channel/channel_trace.cc +4 -4
  88. data/src/core/lib/channel/channel_trace.h +4 -4
  89. data/src/core/lib/channel/channelz.cc +32 -19
  90. data/src/core/lib/channel/channelz.h +4 -4
  91. data/src/core/lib/channel/channelz_registry.cc +1 -1
  92. data/src/core/lib/channel/context.h +0 -3
  93. data/src/core/lib/channel/handshaker_registry.cc +7 -3
  94. data/src/core/lib/compression/algorithm_metadata.h +3 -3
  95. data/src/core/lib/compression/compression.cc +1 -1
  96. data/src/core/lib/compression/compression_internal.cc +2 -2
  97. data/src/core/lib/compression/stream_compression_gzip.cc +1 -1
  98. data/src/core/lib/debug/trace.h +2 -1
  99. data/src/core/lib/gpr/cpu_posix.cc +5 -3
  100. data/src/core/lib/gpr/sync_posix.cc +65 -4
  101. data/src/core/lib/gprpp/atomic.h +75 -5
  102. data/src/core/lib/gprpp/fork.cc +0 -2
  103. data/src/core/lib/gprpp/orphanable.h +3 -2
  104. data/src/core/lib/gprpp/ref_counted.h +9 -11
  105. data/src/core/lib/gprpp/thd.h +42 -7
  106. data/src/core/lib/gprpp/thd_posix.cc +31 -13
  107. data/src/core/lib/gprpp/thd_windows.cc +47 -34
  108. data/src/core/lib/http/httpcli.cc +3 -2
  109. data/src/core/lib/http/httpcli_security_connector.cc +0 -1
  110. data/src/core/lib/http/parser.cc +2 -1
  111. data/src/core/lib/http/parser.h +2 -1
  112. data/src/core/lib/iomgr/buffer_list.h +1 -1
  113. data/src/core/lib/iomgr/endpoint.cc +2 -2
  114. data/src/core/lib/iomgr/endpoint.h +3 -2
  115. data/src/core/lib/iomgr/error.cc +9 -9
  116. data/src/core/lib/iomgr/error.h +4 -3
  117. data/src/core/lib/iomgr/ev_epoll1_linux.cc +6 -0
  118. data/src/core/lib/iomgr/ev_epollex_linux.cc +14 -9
  119. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -481
  120. data/src/core/lib/iomgr/ev_posix.cc +7 -3
  121. data/src/core/lib/iomgr/ev_posix.h +8 -0
  122. data/src/core/lib/iomgr/executor.cc +13 -0
  123. data/src/core/lib/iomgr/executor.h +2 -1
  124. data/src/core/lib/iomgr/internal_errqueue.cc +2 -4
  125. data/src/core/lib/iomgr/iomgr.cc +5 -0
  126. data/src/core/lib/iomgr/iomgr.h +7 -0
  127. data/src/core/lib/iomgr/iomgr_custom.cc +9 -2
  128. data/src/core/lib/iomgr/iomgr_internal.cc +6 -0
  129. data/src/core/lib/iomgr/iomgr_internal.h +9 -1
  130. data/src/core/lib/iomgr/iomgr_posix.cc +10 -2
  131. data/src/core/lib/iomgr/iomgr_windows.cc +10 -2
  132. data/src/core/lib/iomgr/port.h +19 -0
  133. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -4
  134. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  135. data/src/core/lib/iomgr/tcp_posix.cc +158 -54
  136. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  137. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
  138. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
  139. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  140. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -6
  141. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
  142. data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
  143. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -2
  144. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +28 -17
  145. data/src/core/lib/security/security_connector/ssl_utils.cc +134 -0
  146. data/src/core/lib/security/security_connector/ssl_utils.h +32 -0
  147. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
  148. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
  149. data/src/core/lib/security/transport/auth_filters.h +2 -2
  150. data/src/core/lib/security/transport/client_auth_filter.cc +35 -39
  151. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  152. data/src/core/lib/security/transport/security_handshaker.cc +4 -3
  153. data/src/core/lib/slice/percent_encoding.cc +3 -3
  154. data/src/core/lib/slice/percent_encoding.h +3 -3
  155. data/src/core/lib/slice/slice.cc +27 -30
  156. data/src/core/lib/slice/slice_hash_table.h +2 -2
  157. data/src/core/lib/slice/slice_intern.cc +1 -1
  158. data/src/core/lib/slice/slice_internal.h +14 -3
  159. data/src/core/lib/slice/slice_weak_hash_table.h +4 -4
  160. data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
  161. data/src/core/lib/surface/call.cc +8 -3
  162. data/src/core/lib/surface/completion_queue.cc +134 -148
  163. data/src/core/lib/surface/init.cc +78 -30
  164. data/src/core/lib/surface/init.h +1 -0
  165. data/src/core/lib/surface/lame_client.cc +4 -6
  166. data/src/core/lib/surface/version.cc +1 -1
  167. data/src/core/lib/transport/metadata.cc +66 -33
  168. data/src/core/lib/transport/metadata_batch.cc +1 -1
  169. data/src/core/lib/transport/metadata_batch.h +1 -1
  170. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  171. data/src/core/lib/transport/timeout_encoding.h +1 -1
  172. data/src/core/lib/transport/transport.h +4 -3
  173. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
  174. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
  175. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
  176. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
  177. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
  178. data/src/core/tsi/ssl_transport_security.cc +1 -5
  179. data/src/core/tsi/ssl_transport_security.h +24 -4
  180. data/src/ruby/bin/math_pb.rb +18 -16
  181. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  182. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  183. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  184. data/src/ruby/lib/grpc/version.rb +1 -1
  185. data/src/ruby/pb/README.md +1 -1
  186. data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
  187. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
  188. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
  189. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
  190. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
  191. data/third_party/cares/cares/ares.h +12 -0
  192. data/third_party/cares/cares/ares_create_query.c +5 -1
  193. data/third_party/cares/cares/ares_data.c +74 -73
  194. data/third_party/cares/cares/ares_destroy.c +6 -1
  195. data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
  196. data/third_party/cares/cares/ares_gethostbyname.c +15 -4
  197. data/third_party/cares/cares/ares_getnameinfo.c +11 -0
  198. data/third_party/cares/cares/ares_init.c +274 -173
  199. data/third_party/cares/cares/ares_library_init.c +21 -3
  200. data/third_party/cares/cares/ares_options.c +6 -2
  201. data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
  202. data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
  203. data/third_party/cares/cares/ares_platform.c +7 -0
  204. data/third_party/cares/cares/ares_private.h +19 -11
  205. data/third_party/cares/cares/ares_process.c +27 -2
  206. data/third_party/cares/cares/ares_rules.h +1 -1
  207. data/third_party/cares/cares/ares_search.c +7 -0
  208. data/third_party/cares/cares/ares_send.c +6 -0
  209. data/third_party/cares/cares/ares_strsplit.c +174 -0
  210. data/third_party/cares/cares/ares_strsplit.h +43 -0
  211. data/third_party/cares/cares/ares_version.h +4 -4
  212. data/third_party/cares/cares/config-win32.h +1 -1
  213. data/third_party/cares/cares/inet_ntop.c +2 -3
  214. data/third_party/cares/config_darwin/ares_config.h +3 -0
  215. data/third_party/cares/config_freebsd/ares_config.h +3 -0
  216. data/third_party/cares/config_linux/ares_config.h +3 -0
  217. data/third_party/cares/config_openbsd/ares_config.h +3 -0
  218. metadata +39 -37
  219. data/src/core/ext/filters/client_channel/request_routing.cc +0 -946
  220. data/src/core/ext/filters/client_channel/request_routing.h +0 -181
  221. data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
  222. data/src/core/lib/gprpp/atomic_with_std.h +0 -35
  223. data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
  224. data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
@@ -33,6 +33,7 @@
33
33
  #include "src/core/lib/debug/stats.h"
34
34
  #include "src/core/lib/debug/trace.h"
35
35
  #include "src/core/lib/gprpp/fork.h"
36
+ #include "src/core/lib/gprpp/mutex_lock.h"
36
37
  #include "src/core/lib/http/parser.h"
37
38
  #include "src/core/lib/iomgr/call_combiner.h"
38
39
  #include "src/core/lib/iomgr/combiner.h"
@@ -61,10 +62,15 @@ extern void grpc_register_built_in_plugins(void);
61
62
  static gpr_once g_basic_init = GPR_ONCE_INIT;
62
63
  static gpr_mu g_init_mu;
63
64
  static int g_initializations;
65
+ static gpr_cv* g_shutting_down_cv;
66
+ static bool g_shutting_down;
64
67
 
65
68
  static void do_basic_init(void) {
66
69
  gpr_log_verbosity_init();
67
70
  gpr_mu_init(&g_init_mu);
71
+ g_shutting_down_cv = static_cast<gpr_cv*>(malloc(sizeof(gpr_cv)));
72
+ gpr_cv_init(g_shutting_down_cv);
73
+ g_shutting_down = false;
68
74
  grpc_register_built_in_plugins();
69
75
  grpc_cq_global_init();
70
76
  g_initializations = 0;
@@ -118,8 +124,12 @@ void grpc_init(void) {
118
124
  int i;
119
125
  gpr_once_init(&g_basic_init, do_basic_init);
120
126
 
121
- gpr_mu_lock(&g_init_mu);
127
+ grpc_core::MutexLock lock(&g_init_mu);
122
128
  if (++g_initializations == 1) {
129
+ if (g_shutting_down) {
130
+ g_shutting_down = false;
131
+ gpr_cv_broadcast(g_shutting_down_cv);
132
+ }
123
133
  grpc_core::Fork::GlobalInit();
124
134
  grpc_fork_handlers_auto_register();
125
135
  gpr_time_init();
@@ -150,50 +160,88 @@ void grpc_init(void) {
150
160
  grpc_channel_init_finalize();
151
161
  grpc_iomgr_start();
152
162
  }
153
- gpr_mu_unlock(&g_init_mu);
154
163
 
155
164
  GRPC_API_TRACE("grpc_init(void)", 0, ());
156
165
  }
157
166
 
158
- void grpc_shutdown(void) {
167
+ void grpc_shutdown_internal_locked(void) {
159
168
  int i;
160
- GRPC_API_TRACE("grpc_shutdown(void)", 0, ());
161
- gpr_mu_lock(&g_init_mu);
162
- if (--g_initializations == 0) {
169
+ {
170
+ grpc_core::ExecCtx exec_ctx(0);
171
+ grpc_iomgr_shutdown_background_closure();
163
172
  {
164
- grpc_core::ExecCtx exec_ctx(0);
165
- grpc_iomgr_shutdown_background_closure();
166
- {
167
- grpc_timer_manager_set_threading(
168
- false); // shutdown timer_manager thread
169
- grpc_core::Executor::ShutdownAll();
170
- for (i = g_number_of_plugins; i >= 0; i--) {
171
- if (g_all_of_the_plugins[i].destroy != nullptr) {
172
- g_all_of_the_plugins[i].destroy();
173
- }
173
+ grpc_timer_manager_set_threading(false); // shutdown timer_manager thread
174
+ grpc_core::Executor::ShutdownAll();
175
+ for (i = g_number_of_plugins; i >= 0; i--) {
176
+ if (g_all_of_the_plugins[i].destroy != nullptr) {
177
+ g_all_of_the_plugins[i].destroy();
174
178
  }
175
179
  }
176
- grpc_iomgr_shutdown();
177
- gpr_timers_global_destroy();
178
- grpc_tracer_shutdown();
179
- grpc_mdctx_global_shutdown();
180
- grpc_core::HandshakerRegistry::Shutdown();
181
- grpc_slice_intern_shutdown();
182
- grpc_core::channelz::ChannelzRegistry::Shutdown();
183
- grpc_stats_shutdown();
184
- grpc_core::Fork::GlobalShutdown();
185
180
  }
186
- grpc_core::ExecCtx::GlobalShutdown();
187
- grpc_core::ApplicationCallbackExecCtx::GlobalShutdown();
181
+ grpc_iomgr_shutdown();
182
+ gpr_timers_global_destroy();
183
+ grpc_tracer_shutdown();
184
+ grpc_mdctx_global_shutdown();
185
+ grpc_core::HandshakerRegistry::Shutdown();
186
+ grpc_slice_intern_shutdown();
187
+ grpc_core::channelz::ChannelzRegistry::Shutdown();
188
+ grpc_stats_shutdown();
189
+ grpc_core::Fork::GlobalShutdown();
190
+ }
191
+ grpc_core::ExecCtx::GlobalShutdown();
192
+ grpc_core::ApplicationCallbackExecCtx::GlobalShutdown();
193
+ g_shutting_down = false;
194
+ gpr_cv_broadcast(g_shutting_down_cv);
195
+ }
196
+
197
+ void grpc_shutdown_internal(void* ignored) {
198
+ GRPC_API_TRACE("grpc_shutdown_internal", 0, ());
199
+ grpc_core::MutexLock lock(&g_init_mu);
200
+ // We have released lock from the shutdown thread and it is possible that
201
+ // another grpc_init has been called, and do nothing if that is the case.
202
+ if (--g_initializations != 0) {
203
+ return;
204
+ }
205
+ grpc_shutdown_internal_locked();
206
+ }
207
+
208
+ void grpc_shutdown(void) {
209
+ GRPC_API_TRACE("grpc_shutdown(void)", 0, ());
210
+ grpc_core::MutexLock lock(&g_init_mu);
211
+ if (--g_initializations == 0) {
212
+ g_initializations++;
213
+ g_shutting_down = true;
214
+ // spawn a detached thread to do the actual clean up in case we are
215
+ // currently in an executor thread.
216
+ grpc_core::Thread cleanup_thread(
217
+ "grpc_shutdown", grpc_shutdown_internal, nullptr, nullptr,
218
+ grpc_core::Thread::Options().set_joinable(false).set_tracked(false));
219
+ cleanup_thread.Start();
220
+ }
221
+ }
222
+
223
+ void grpc_shutdown_blocking(void) {
224
+ GRPC_API_TRACE("grpc_shutdown_blocking(void)", 0, ());
225
+ grpc_core::MutexLock lock(&g_init_mu);
226
+ if (--g_initializations == 0) {
227
+ g_shutting_down = true;
228
+ grpc_shutdown_internal_locked();
188
229
  }
189
- gpr_mu_unlock(&g_init_mu);
190
230
  }
191
231
 
192
232
  int grpc_is_initialized(void) {
193
233
  int r;
194
234
  gpr_once_init(&g_basic_init, do_basic_init);
195
- gpr_mu_lock(&g_init_mu);
235
+ grpc_core::MutexLock lock(&g_init_mu);
196
236
  r = g_initializations > 0;
197
- gpr_mu_unlock(&g_init_mu);
198
237
  return r;
199
238
  }
239
+
240
+ void grpc_maybe_wait_for_async_shutdown(void) {
241
+ gpr_once_init(&g_basic_init, do_basic_init);
242
+ grpc_core::MutexLock lock(&g_init_mu);
243
+ while (g_shutting_down) {
244
+ gpr_cv_wait(g_shutting_down_cv, &g_init_mu,
245
+ gpr_inf_future(GPR_CLOCK_REALTIME));
246
+ }
247
+ }
@@ -22,5 +22,6 @@
22
22
  void grpc_register_security_filters(void);
23
23
  void grpc_security_pre_init(void);
24
24
  void grpc_security_init(void);
25
+ void grpc_maybe_wait_for_async_shutdown(void);
25
26
 
26
27
  #endif /* GRPC_CORE_LIB_SURFACE_INIT_H */
@@ -25,10 +25,9 @@
25
25
  #include <grpc/support/alloc.h>
26
26
  #include <grpc/support/log.h>
27
27
 
28
- #include "src/core/lib/gprpp/atomic.h"
29
-
30
28
  #include "src/core/lib/channel/channel_stack.h"
31
29
  #include "src/core/lib/gpr/string.h"
30
+ #include "src/core/lib/gprpp/atomic.h"
32
31
  #include "src/core/lib/surface/api_trace.h"
33
32
  #include "src/core/lib/surface/call.h"
34
33
  #include "src/core/lib/surface/channel.h"
@@ -43,7 +42,7 @@ struct CallData {
43
42
  grpc_call_combiner* call_combiner;
44
43
  grpc_linked_mdelem status;
45
44
  grpc_linked_mdelem details;
46
- grpc_core::atomic<bool> filled_metadata;
45
+ grpc_core::Atomic<bool> filled_metadata;
47
46
  };
48
47
 
49
48
  struct ChannelData {
@@ -54,9 +53,8 @@ struct ChannelData {
54
53
  static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) {
55
54
  CallData* calld = static_cast<CallData*>(elem->call_data);
56
55
  bool expected = false;
57
- if (!calld->filled_metadata.compare_exchange_strong(
58
- expected, true, grpc_core::memory_order_relaxed,
59
- grpc_core::memory_order_relaxed)) {
56
+ if (!calld->filled_metadata.CompareExchangeStrong(
57
+ &expected, true, MemoryOrder::RELAXED, MemoryOrder::RELAXED)) {
60
58
  return;
61
59
  }
62
60
  ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
@@ -25,4 +25,4 @@
25
25
 
26
26
  const char* grpc_version_string(void) { return "7.0.0"; }
27
27
 
28
- const char* grpc_g_stands_for(void) { return "gold"; }
28
+ const char* grpc_g_stands_for(void) { return "godric"; }
@@ -71,6 +71,12 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_metadata(false, "metadata");
71
71
 
72
72
  typedef void (*destroy_user_data_func)(void* user_data);
73
73
 
74
+ struct UserData {
75
+ gpr_mu mu_user_data;
76
+ gpr_atm destroy_user_data;
77
+ gpr_atm user_data;
78
+ };
79
+
74
80
  /* Shadow structure for grpc_mdelem_data for interned elements */
75
81
  typedef struct interned_metadata {
76
82
  /* must be byte compatible with grpc_mdelem_data */
@@ -80,9 +86,7 @@ typedef struct interned_metadata {
80
86
  /* private only data */
81
87
  gpr_atm refcnt;
82
88
 
83
- gpr_mu mu_user_data;
84
- gpr_atm destroy_user_data;
85
- gpr_atm user_data;
89
+ UserData user_data;
86
90
 
87
91
  struct interned_metadata* bucket_next;
88
92
  } interned_metadata;
@@ -95,6 +99,8 @@ typedef struct allocated_metadata {
95
99
 
96
100
  /* private only data */
97
101
  gpr_atm refcnt;
102
+
103
+ UserData user_data;
98
104
  } allocated_metadata;
99
105
 
100
106
  typedef struct mdtab_shard {
@@ -178,16 +184,17 @@ static void gc_mdtab(mdtab_shard* shard) {
178
184
  for (i = 0; i < shard->capacity; i++) {
179
185
  prev_next = &shard->elems[i];
180
186
  for (md = shard->elems[i]; md; md = next) {
181
- void* user_data = (void*)gpr_atm_no_barrier_load(&md->user_data);
187
+ void* user_data =
188
+ (void*)gpr_atm_no_barrier_load(&md->user_data.user_data);
182
189
  next = md->bucket_next;
183
190
  if (gpr_atm_acq_load(&md->refcnt) == 0) {
184
191
  grpc_slice_unref_internal(md->key);
185
192
  grpc_slice_unref_internal(md->value);
186
- if (md->user_data) {
193
+ if (md->user_data.user_data) {
187
194
  ((destroy_user_data_func)gpr_atm_no_barrier_load(
188
- &md->destroy_user_data))(user_data);
195
+ &md->user_data.destroy_user_data))(user_data);
189
196
  }
190
- gpr_mu_destroy(&md->mu_user_data);
197
+ gpr_mu_destroy(&md->user_data.mu_user_data);
191
198
  gpr_free(md);
192
199
  *prev_next = next;
193
200
  num_freed++;
@@ -251,6 +258,9 @@ grpc_mdelem grpc_mdelem_create(
251
258
  allocated->key = grpc_slice_ref_internal(key);
252
259
  allocated->value = grpc_slice_ref_internal(value);
253
260
  gpr_atm_rel_store(&allocated->refcnt, 1);
261
+ allocated->user_data.user_data = 0;
262
+ allocated->user_data.destroy_user_data = 0;
263
+ gpr_mu_init(&allocated->user_data.mu_user_data);
254
264
  #ifndef NDEBUG
255
265
  if (grpc_trace_metadata.enabled()) {
256
266
  char* key_str = grpc_slice_to_c_string(allocated->key);
@@ -299,11 +309,11 @@ grpc_mdelem grpc_mdelem_create(
299
309
  gpr_atm_rel_store(&md->refcnt, 1);
300
310
  md->key = grpc_slice_ref_internal(key);
301
311
  md->value = grpc_slice_ref_internal(value);
302
- md->user_data = 0;
303
- md->destroy_user_data = 0;
312
+ md->user_data.user_data = 0;
313
+ md->user_data.destroy_user_data = 0;
304
314
  md->bucket_next = shard->elems[idx];
305
315
  shard->elems[idx] = md;
306
- gpr_mu_init(&md->mu_user_data);
316
+ gpr_mu_init(&md->user_data.mu_user_data);
307
317
  #ifndef NDEBUG
308
318
  if (grpc_trace_metadata.enabled()) {
309
319
  char* key_str = grpc_slice_to_c_string(md->key);
@@ -450,6 +460,13 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) {
450
460
  if (1 == prev_refcount) {
451
461
  grpc_slice_unref_internal(md->key);
452
462
  grpc_slice_unref_internal(md->value);
463
+ if (md->user_data.user_data) {
464
+ destroy_user_data_func destroy_user_data =
465
+ (destroy_user_data_func)gpr_atm_no_barrier_load(
466
+ &md->user_data.destroy_user_data);
467
+ destroy_user_data((void*)md->user_data.user_data);
468
+ }
469
+ gpr_mu_destroy(&md->user_data.mu_user_data);
453
470
  gpr_free(md);
454
471
  }
455
472
  break;
@@ -457,58 +474,74 @@ void grpc_mdelem_unref(grpc_mdelem gmd DEBUG_ARGS) {
457
474
  }
458
475
  }
459
476
 
477
+ static void* get_user_data(UserData* user_data, void (*destroy_func)(void*)) {
478
+ if (gpr_atm_acq_load(&user_data->destroy_user_data) ==
479
+ (gpr_atm)destroy_func) {
480
+ return (void*)gpr_atm_no_barrier_load(&user_data->user_data);
481
+ } else {
482
+ return nullptr;
483
+ }
484
+ }
485
+
460
486
  void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) {
461
487
  switch (GRPC_MDELEM_STORAGE(md)) {
462
488
  case GRPC_MDELEM_STORAGE_EXTERNAL:
463
- case GRPC_MDELEM_STORAGE_ALLOCATED:
464
489
  return nullptr;
465
490
  case GRPC_MDELEM_STORAGE_STATIC:
466
491
  return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) -
467
492
  grpc_static_mdelem_table];
493
+ case GRPC_MDELEM_STORAGE_ALLOCATED: {
494
+ allocated_metadata* am =
495
+ reinterpret_cast<allocated_metadata*>(GRPC_MDELEM_DATA(md));
496
+ return get_user_data(&am->user_data, destroy_func);
497
+ }
468
498
  case GRPC_MDELEM_STORAGE_INTERNED: {
469
499
  interned_metadata* im =
470
500
  reinterpret_cast<interned_metadata*> GRPC_MDELEM_DATA(md);
471
- void* result;
472
- if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) {
473
- return (void*)gpr_atm_no_barrier_load(&im->user_data);
474
- } else {
475
- return nullptr;
476
- }
477
- return result;
501
+ return get_user_data(&im->user_data, destroy_func);
478
502
  }
479
503
  }
480
504
  GPR_UNREACHABLE_CODE(return nullptr);
481
505
  }
482
506
 
507
+ static void* set_user_data(UserData* ud, void (*destroy_func)(void*),
508
+ void* user_data) {
509
+ GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr));
510
+ gpr_mu_lock(&ud->mu_user_data);
511
+ if (gpr_atm_no_barrier_load(&ud->destroy_user_data)) {
512
+ /* user data can only be set once */
513
+ gpr_mu_unlock(&ud->mu_user_data);
514
+ if (destroy_func != nullptr) {
515
+ destroy_func(user_data);
516
+ }
517
+ return (void*)gpr_atm_no_barrier_load(&ud->user_data);
518
+ }
519
+ gpr_atm_no_barrier_store(&ud->user_data, (gpr_atm)user_data);
520
+ gpr_atm_rel_store(&ud->destroy_user_data, (gpr_atm)destroy_func);
521
+ gpr_mu_unlock(&ud->mu_user_data);
522
+ return user_data;
523
+ }
524
+
483
525
  void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*),
484
526
  void* user_data) {
485
527
  switch (GRPC_MDELEM_STORAGE(md)) {
486
528
  case GRPC_MDELEM_STORAGE_EXTERNAL:
487
- case GRPC_MDELEM_STORAGE_ALLOCATED:
488
529
  destroy_func(user_data);
489
530
  return nullptr;
490
531
  case GRPC_MDELEM_STORAGE_STATIC:
491
532
  destroy_func(user_data);
492
533
  return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) -
493
534
  grpc_static_mdelem_table];
535
+ case GRPC_MDELEM_STORAGE_ALLOCATED: {
536
+ allocated_metadata* am =
537
+ reinterpret_cast<allocated_metadata*>(GRPC_MDELEM_DATA(md));
538
+ return set_user_data(&am->user_data, destroy_func, user_data);
539
+ }
494
540
  case GRPC_MDELEM_STORAGE_INTERNED: {
495
541
  interned_metadata* im =
496
542
  reinterpret_cast<interned_metadata*> GRPC_MDELEM_DATA(md);
497
543
  GPR_ASSERT(!is_mdelem_static(md));
498
- GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr));
499
- gpr_mu_lock(&im->mu_user_data);
500
- if (gpr_atm_no_barrier_load(&im->destroy_user_data)) {
501
- /* user data can only be set once */
502
- gpr_mu_unlock(&im->mu_user_data);
503
- if (destroy_func != nullptr) {
504
- destroy_func(user_data);
505
- }
506
- return (void*)gpr_atm_no_barrier_load(&im->user_data);
507
- }
508
- gpr_atm_no_barrier_store(&im->user_data, (gpr_atm)user_data);
509
- gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func);
510
- gpr_mu_unlock(&im->mu_user_data);
511
- return user_data;
544
+ return set_user_data(&im->user_data, destroy_func, user_data);
512
545
  }
513
546
  }
514
547
  GPR_UNREACHABLE_CODE(return nullptr);
@@ -227,7 +227,7 @@ void grpc_metadata_batch_remove(grpc_metadata_batch* batch,
227
227
  }
228
228
 
229
229
  void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
230
- grpc_slice value) {
230
+ const grpc_slice& value) {
231
231
  grpc_mdelem old_mdelem = storage->md;
232
232
  grpc_mdelem new_mdelem = grpc_mdelem_from_slices(
233
233
  grpc_slice_ref_internal(GRPC_MDKEY(old_mdelem)), value);
@@ -74,7 +74,7 @@ grpc_error* grpc_metadata_batch_substitute(grpc_metadata_batch* batch,
74
74
  grpc_mdelem new_value);
75
75
 
76
76
  void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
77
- grpc_slice value);
77
+ const grpc_slice& value);
78
78
 
79
79
  /** Add \a storage to the beginning of \a batch. storage->md is
80
80
  assumed to be valid.
@@ -89,7 +89,7 @@ static int is_all_whitespace(const char* p, const char* end) {
89
89
  return p == end;
90
90
  }
91
91
 
92
- int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout) {
92
+ int grpc_http2_decode_timeout(const grpc_slice& text, grpc_millis* timeout) {
93
93
  grpc_millis x = 0;
94
94
  const uint8_t* p = GRPC_SLICE_START_PTR(text);
95
95
  const uint8_t* end = GRPC_SLICE_END_PTR(text);
@@ -32,6 +32,6 @@
32
32
  /* Encode/decode timeouts to the GRPC over HTTP/2 format;
33
33
  encoding may round up arbitrarily */
34
34
  void grpc_http2_encode_timeout(grpc_millis timeout, char* buffer);
35
- int grpc_http2_decode_timeout(grpc_slice text, grpc_millis* timeout);
35
+ int grpc_http2_decode_timeout(const grpc_slice& text, grpc_millis* timeout);
36
36
 
37
37
  #endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */
@@ -111,10 +111,11 @@ void grpc_transport_move_stats(grpc_transport_stream_stats* from,
111
111
  // currently handling the batch). Once a filter or transport passes control
112
112
  // of the batch to the next handler, it cannot depend on the contents of
113
113
  // this struct anymore, because the next handler may reuse it.
114
- typedef struct {
115
- void* extra_arg;
114
+ struct grpc_handler_private_op_data {
115
+ void* extra_arg = nullptr;
116
116
  grpc_closure closure;
117
- } grpc_handler_private_op_data;
117
+ grpc_handler_private_op_data() { memset(&closure, 0, sizeof(closure)); }
118
+ };
118
119
 
119
120
  typedef struct grpc_transport_stream_op_batch_payload
120
121
  grpc_transport_stream_op_batch_payload;
@@ -363,7 +363,7 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c,
363
363
  alts_grpc_handshaker_client* client =
364
364
  reinterpret_cast<alts_grpc_handshaker_client*>(c);
365
365
  grpc_slice_unref_internal(client->recv_bytes);
366
- client->recv_bytes = grpc_slice_ref(*bytes_received);
366
+ client->recv_bytes = grpc_slice_ref_internal(*bytes_received);
367
367
  grpc_byte_buffer* buffer = get_serialized_next(bytes_received);
368
368
  if (buffer == nullptr) {
369
369
  gpr_log(GPR_ERROR, "get_serialized_next() failed");
@@ -406,7 +406,7 @@ static const alts_handshaker_client_vtable vtable = {
406
406
  alts_handshaker_client* alts_grpc_handshaker_client_create(
407
407
  alts_tsi_handshaker* handshaker, grpc_channel* channel,
408
408
  const char* handshaker_service_url, grpc_pollset_set* interested_parties,
409
- grpc_alts_credentials_options* options, grpc_slice target_name,
409
+ grpc_alts_credentials_options* options, const grpc_slice& target_name,
410
410
  grpc_iomgr_cb_func grpc_cb, tsi_handshaker_on_next_done_cb cb,
411
411
  void* user_data, alts_handshaker_client_vtable* vtable_for_testing,
412
412
  bool is_client) {
@@ -487,7 +487,7 @@ void alts_handshaker_client_set_recv_bytes_for_testing(
487
487
  GPR_ASSERT(c != nullptr);
488
488
  alts_grpc_handshaker_client* client =
489
489
  reinterpret_cast<alts_grpc_handshaker_client*>(c);
490
- client->recv_bytes = grpc_slice_ref(*recv_bytes);
490
+ client->recv_bytes = grpc_slice_ref_internal(*recv_bytes);
491
491
  }
492
492
 
493
493
  void alts_handshaker_client_set_fields_for_testing(