grpc 1.49.1-x86_64-linux → 1.50.0.pre1-x86_64-linux

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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +33 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +112 -96
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +84 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -15
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +1 -1
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  258. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  259. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  260. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  261. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  262. data/src/ruby/lib/grpc/version.rb +1 -1
  263. data/src/ruby/spec/channel_spec.rb +5 -0
  264. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  265. data/src/ruby/spec/user_agent_spec.rb +1 -1
  266. metadata +33 -19
  267. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  268. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  269. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  270. data/src/core/lib/event_engine/promise.h +0 -78
  271. data/src/core/lib/gpr/env_windows.cc +0 -74
  272. data/src/core/lib/gpr/string_windows.h +0 -32
  273. data/src/core/lib/profiling/basic_timers.cc +0 -295
  274. data/src/core/lib/profiling/stap_timers.cc +0 -50
  275. data/src/core/lib/profiling/timers.h +0 -94
@@ -29,14 +29,6 @@
29
29
  #include <grpc/support/sync.h>
30
30
  #include <grpc/support/time.h>
31
31
 
32
- #include "src/core/lib/profiling/timers.h"
33
-
34
- #ifdef GPR_LOW_LEVEL_COUNTERS
35
- gpr_atm gpr_mu_locks = 0;
36
- gpr_atm gpr_counter_atm_cas = 0;
37
- gpr_atm gpr_counter_atm_add = 0;
38
- #endif
39
-
40
32
  void gpr_mu_init(gpr_mu* mu) {
41
33
  #ifdef GRPC_ASAN_ENABLED
42
34
  GPR_ASSERT(pthread_mutex_init(&mu->mutex, nullptr) == 0);
@@ -57,10 +49,6 @@ void gpr_mu_destroy(gpr_mu* mu) {
57
49
  }
58
50
 
59
51
  void gpr_mu_lock(gpr_mu* mu) {
60
- #ifdef GPR_LOW_LEVEL_COUNTERS
61
- GPR_ATM_INC_COUNTER(gpr_mu_locks);
62
- #endif
63
- GPR_TIMER_SCOPE("gpr_mu_lock", 0);
64
52
  #ifdef GRPC_ASAN_ENABLED
65
53
  GPR_ASSERT(pthread_mutex_lock(&mu->mutex) == 0);
66
54
  #else
@@ -69,7 +57,6 @@ void gpr_mu_lock(gpr_mu* mu) {
69
57
  }
70
58
 
71
59
  void gpr_mu_unlock(gpr_mu* mu) {
72
- GPR_TIMER_SCOPE("gpr_mu_unlock", 0);
73
60
  #ifdef GRPC_ASAN_ENABLED
74
61
  GPR_ASSERT(pthread_mutex_unlock(&mu->mutex) == 0);
75
62
  #else
@@ -78,7 +65,6 @@ void gpr_mu_unlock(gpr_mu* mu) {
78
65
  }
79
66
 
80
67
  int gpr_mu_trylock(gpr_mu* mu) {
81
- GPR_TIMER_SCOPE("gpr_mu_trylock", 0);
82
68
  int err = 0;
83
69
  #ifdef GRPC_ASAN_ENABLED
84
70
  err = pthread_mutex_trylock(&mu->mutex);
@@ -140,13 +140,7 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
140
140
 
141
141
  gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
142
142
 
143
- #ifdef GPR_LOW_LEVEL_COUNTERS
144
- gpr_atm gpr_now_call_count;
145
- #endif
146
143
  gpr_timespec gpr_now(gpr_clock_type clock_type) {
147
- #ifdef GPR_LOW_LEVEL_COUNTERS
148
- __atomic_fetch_add(&gpr_now_call_count, 1, __ATOMIC_RELAXED);
149
- #endif
150
144
  // validate clock type
151
145
  GPR_ASSERT(clock_type == GPR_CLOCK_MONOTONIC ||
152
146
  clock_type == GPR_CLOCK_REALTIME ||
@@ -28,7 +28,7 @@
28
28
  // low as a usec. Use other clock sources or gpr_precise_clock_now(),
29
29
  // where you need high resolution clocks.
30
30
  //
31
- // Using gpr_get_cycle_counter() is preferred to using ExecCtx::Get()->Now()
31
+ // Using gpr_get_cycle_counter() is preferred to using Timestamp::Now()
32
32
  // whenever possible.
33
33
 
34
34
  #if GPR_CYCLE_COUNTER_CUSTOM
@@ -29,12 +29,11 @@
29
29
  #include <grpc/support/log.h>
30
30
  #include <grpc/support/string_util.h>
31
31
 
32
- #include "src/core/lib/gpr/string_windows.h"
33
32
  #include "src/core/lib/gpr/tmpfile.h"
33
+ #include "src/core/lib/gprpp/tchar.h"
34
34
 
35
35
  FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
36
36
  FILE* result = NULL;
37
- LPTSTR template_string = NULL;
38
37
  TCHAR tmp_path[MAX_PATH];
39
38
  TCHAR tmp_filename[MAX_PATH];
40
39
  DWORD status;
@@ -43,15 +42,14 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
43
42
  if (tmp_filename_out != NULL) *tmp_filename_out = NULL;
44
43
 
45
44
  /* Convert our prefix to TCHAR. */
46
- template_string = gpr_char_to_tchar(prefix);
47
- GPR_ASSERT(template_string);
45
+ grpc_core::TcharString template_string = grpc_core::CharToTchar(prefix);
48
46
 
49
47
  /* Get the path to the best temporary folder available. */
50
48
  status = GetTempPath(MAX_PATH, tmp_path);
51
49
  if (status == 0 || status > MAX_PATH) goto end;
52
50
 
53
51
  /* Generate a unique filename with our template + temporary path. */
54
- success = GetTempFileName(tmp_path, template_string, 0, tmp_filename);
52
+ success = GetTempFileName(tmp_path, template_string.c_str(), 0, tmp_filename);
55
53
  if (!success) goto end;
56
54
 
57
55
  /* Open a file there. */
@@ -59,10 +57,10 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
59
57
 
60
58
  end:
61
59
  if (result && tmp_filename_out) {
62
- *tmp_filename_out = gpr_tchar_to_char(tmp_filename);
60
+ *tmp_filename_out =
61
+ gpr_strdup(grpc_core::TcharToChar(tmp_filename).c_str());
63
62
  }
64
63
 
65
- gpr_free(template_string);
66
64
  return result;
67
65
  }
68
66
 
@@ -153,6 +153,17 @@ inline uint32_t MixHash32(uint32_t a, uint32_t b) {
153
153
  return RotateLeft(a, 2u) ^ b;
154
154
  }
155
155
 
156
+ inline uint32_t RoundUpToPowerOf2(uint32_t v) {
157
+ v--;
158
+ v |= v >> 1;
159
+ v |= v >> 2;
160
+ v |= v >> 4;
161
+ v |= v >> 8;
162
+ v |= v >> 16;
163
+ v++;
164
+ return v;
165
+ }
166
+
156
167
  } // namespace grpc_core
157
168
 
158
169
  #define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
@@ -16,25 +16,38 @@
16
16
  *
17
17
  */
18
18
 
19
- #ifndef GRPC_CORE_LIB_GPR_ENV_H
20
- #define GRPC_CORE_LIB_GPR_ENV_H
19
+ #ifndef GRPC_CORE_LIB_GPRPP_ENV_H
20
+ #define GRPC_CORE_LIB_GPRPP_ENV_H
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
- #include <stdio.h>
24
+ #include <string>
25
25
 
26
- /* Env utility functions */
26
+ #include "absl/types/optional.h"
27
27
 
28
- /* Gets the environment variable value with the specified name.
29
- Returns a newly allocated string. It is the responsibility of the caller to
30
- gpr_free the return value if not NULL (which means that the environment
31
- variable exists). */
32
- char* gpr_getenv(const char* name);
28
+ namespace grpc_core {
29
+
30
+ // Gets the environment variable value with the specified name. */
31
+ absl::optional<std::string> GetEnv(const char* name);
33
32
 
34
33
  /* Sets the environment with the specified name to the specified value. */
35
- void gpr_setenv(const char* name, const char* value);
34
+ void SetEnv(const char* name, const char* value);
35
+ inline void SetEnv(const char* name, const std::string& value) {
36
+ SetEnv(name, value.c_str());
37
+ }
36
38
 
37
39
  /* Deletes the variable name from the environment. */
38
- void gpr_unsetenv(const char* name);
40
+ void UnsetEnv(const char* name);
41
+
42
+ template <typename T>
43
+ void SetOrUnsetEnv(const char* name, const absl::optional<T>& value) {
44
+ if (value.has_value()) {
45
+ SetEnv(name, value.value());
46
+ } else {
47
+ UnsetEnv(name);
48
+ }
49
+ }
50
+
51
+ } // namespace grpc_core
39
52
 
40
- #endif /* GRPC_CORE_LIB_GPR_ENV_H */
53
+ #endif /* GRPC_CORE_LIB_GPRPP_ENV_H */
@@ -23,21 +23,24 @@
23
23
 
24
24
  #include <grpc/support/port_platform.h>
25
25
 
26
+ #include <string>
27
+
28
+ #include "absl/types/optional.h"
29
+
26
30
  #ifdef GPR_LINUX_ENV
27
31
 
32
+ #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
28
33
  #include <dlfcn.h>
34
+ #endif
35
+
29
36
  #include <features.h>
30
37
  #include <stdlib.h>
31
- #include <string.h>
32
38
 
33
- #include <grpc/support/log.h>
34
- #include <grpc/support/string_util.h>
39
+ #include "src/core/lib/gprpp/env.h"
35
40
 
36
- #include "src/core/lib/gpr/env.h"
37
- #include "src/core/lib/gpr/string.h"
38
- #include "src/core/lib/gpr/useful.h"
41
+ namespace grpc_core {
39
42
 
40
- char* gpr_getenv(const char* name) {
43
+ absl::optional<std::string> GetEnv(const char* name) {
41
44
  char* result = nullptr;
42
45
  #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
43
46
  typedef char* (*getenv_type)(const char*);
@@ -45,9 +48,8 @@ char* gpr_getenv(const char* name) {
45
48
  /* Check to see which getenv variant is supported (go from most
46
49
  * to least secure) */
47
50
  if (getenv_func == nullptr) {
48
- const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
49
- for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) {
50
- getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
51
+ for (auto name : {"secure_getenv", "__secure_getenv", "getenv"}) {
52
+ getenv_func = reinterpret_cast<getenv_type>(dlsym(RTLD_DEFAULT, name));
51
53
  if (getenv_func != nullptr) {
52
54
  break;
53
55
  }
@@ -59,17 +61,20 @@ char* gpr_getenv(const char* name) {
59
61
  #else
60
62
  result = getenv(name);
61
63
  #endif
62
- return result == nullptr ? result : gpr_strdup(result);
64
+ if (result == nullptr) return absl::nullopt;
65
+ return result;
63
66
  }
64
67
 
65
- void gpr_setenv(const char* name, const char* value) {
68
+ void SetEnv(const char* name, const char* value) {
66
69
  int res = setenv(name, value, 1);
67
- GPR_ASSERT(res == 0);
70
+ if (res != 0) abort();
68
71
  }
69
72
 
70
- void gpr_unsetenv(const char* name) {
73
+ void UnsetEnv(const char* name) {
71
74
  int res = unsetenv(name);
72
- GPR_ASSERT(res == 0);
75
+ if (res != 0) abort();
73
76
  }
74
77
 
78
+ } // namespace grpc_core
79
+
75
80
  #endif /* GPR_LINUX_ENV */
@@ -22,25 +22,26 @@
22
22
 
23
23
  #include <stdlib.h>
24
24
 
25
- #include <grpc/support/log.h>
26
- #include <grpc/support/string_util.h>
25
+ #include "src/core/lib/gprpp/env.h"
27
26
 
28
- #include "src/core/lib/gpr/env.h"
29
- #include "src/core/lib/gpr/string.h"
27
+ namespace grpc_core {
30
28
 
31
- char* gpr_getenv(const char* name) {
29
+ absl::optional<std::string> GetEnv(const char* name) {
32
30
  char* result = getenv(name);
33
- return result == nullptr ? result : gpr_strdup(result);
31
+ if (result == nullptr) return absl::nullopt;
32
+ return result;
34
33
  }
35
34
 
36
- void gpr_setenv(const char* name, const char* value) {
35
+ void SetEnv(const char* name, const char* value) {
37
36
  int res = setenv(name, value, 1);
38
- GPR_ASSERT(res == 0);
37
+ if (res != 0) abort();
39
38
  }
40
39
 
41
- void gpr_unsetenv(const char* name) {
40
+ void UnsetEnv(const char* name) {
42
41
  int res = unsetenv(name);
43
- GPR_ASSERT(res == 0);
42
+ if (res != 0) abort();
44
43
  }
45
44
 
45
+ } // namespace grpc_core
46
+
46
47
  #endif /* GPR_POSIX_ENV */
@@ -0,0 +1,56 @@
1
+ /*
2
+ *
3
+ * Copyright 2015 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #ifdef GPR_WINDOWS_ENV
22
+
23
+ #include <windows.h>
24
+
25
+ #include <memory>
26
+
27
+ #include "src/core/lib/gprpp/env.h"
28
+ #include "src/core/lib/gprpp/tchar.h"
29
+
30
+ namespace grpc_core {
31
+
32
+ absl::optional<std::string> GetEnv(const char* name) {
33
+ auto tname = CharToTchar(name);
34
+ DWORD ret = GetEnvironmentVariable(tname.c_str(), NULL, 0);
35
+ if (ret == 0) return absl::nullopt;
36
+ std::unique_ptr<TCHAR[]> tresult(new TCHAR[ret]);
37
+ ret =
38
+ GetEnvironmentVariable(tname.c_str(), tresult.get(), ret * sizeof(TCHAR));
39
+ if (ret == 0) return absl::nullopt;
40
+ return TcharToChar(tresult.get());
41
+ }
42
+
43
+ void SetEnv(const char* name, const char* value) {
44
+ BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(),
45
+ CharToTchar(value).c_str());
46
+ if (!res) abort();
47
+ }
48
+
49
+ void UnsetEnv(const char* name) {
50
+ BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(), NULL);
51
+ if (!res) abort();
52
+ }
53
+
54
+ } // namespace grpc_core
55
+
56
+ #endif /* GPR_WINDOWS_ENV */
@@ -26,6 +26,7 @@
26
26
  #include <grpc/support/time.h>
27
27
 
28
28
  #include "src/core/lib/gprpp/global_config_env.h"
29
+ #include "src/core/lib/gprpp/no_destruct.h"
29
30
 
30
31
  /*
31
32
  * NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
@@ -43,7 +44,7 @@ GPR_GLOBAL_CONFIG_DEFINE_BOOL(grpc_enable_fork_support,
43
44
  "Enable fork support");
44
45
 
45
46
  namespace grpc_core {
46
- namespace internal {
47
+ namespace {
47
48
  // The exec_ctx_count has 2 modes, blocked and unblocked.
48
49
  // When unblocked, the count is 2-indexed; exec_ctx_count=2 indicates
49
50
  // 0 active ExecCtxs, exex_ctx_count=3 indicates 1 active ExecCtxs...
@@ -161,24 +162,13 @@ class ThreadState {
161
162
  int count_;
162
163
  };
163
164
 
164
- } // namespace internal
165
+ } // namespace
165
166
 
166
167
  void Fork::GlobalInit() {
167
168
  if (!override_enabled_) {
168
169
  support_enabled_.store(GPR_GLOBAL_CONFIG_GET(grpc_enable_fork_support),
169
170
  std::memory_order_relaxed);
170
171
  }
171
- if (support_enabled_.load(std::memory_order_relaxed)) {
172
- exec_ctx_state_ = new internal::ExecCtxState();
173
- thread_state_ = new internal::ThreadState();
174
- }
175
- }
176
-
177
- void Fork::GlobalShutdown() {
178
- if (support_enabled_.load(std::memory_order_relaxed)) {
179
- delete exec_ctx_state_;
180
- delete thread_state_;
181
- }
182
172
  }
183
173
 
184
174
  bool Fork::Enabled() {
@@ -191,9 +181,13 @@ void Fork::Enable(bool enable) {
191
181
  support_enabled_.store(enable, std::memory_order_relaxed);
192
182
  }
193
183
 
194
- void Fork::DoIncExecCtxCount() { exec_ctx_state_->IncExecCtxCount(); }
184
+ void Fork::DoIncExecCtxCount() {
185
+ NoDestructSingleton<ExecCtxState>::Get()->IncExecCtxCount();
186
+ }
195
187
 
196
- void Fork::DoDecExecCtxCount() { exec_ctx_state_->DecExecCtxCount(); }
188
+ void Fork::DoDecExecCtxCount() {
189
+ NoDestructSingleton<ExecCtxState>::Get()->DecExecCtxCount();
190
+ }
197
191
 
198
192
  void Fork::SetResetChildPollingEngineFunc(
199
193
  Fork::child_postfork_func reset_child_polling_engine) {
@@ -205,36 +199,34 @@ Fork::child_postfork_func Fork::GetResetChildPollingEngineFunc() {
205
199
 
206
200
  bool Fork::BlockExecCtx() {
207
201
  if (support_enabled_.load(std::memory_order_relaxed)) {
208
- return exec_ctx_state_->BlockExecCtx();
202
+ return NoDestructSingleton<ExecCtxState>::Get()->BlockExecCtx();
209
203
  }
210
204
  return false;
211
205
  }
212
206
 
213
207
  void Fork::AllowExecCtx() {
214
208
  if (support_enabled_.load(std::memory_order_relaxed)) {
215
- exec_ctx_state_->AllowExecCtx();
209
+ NoDestructSingleton<ExecCtxState>::Get()->AllowExecCtx();
216
210
  }
217
211
  }
218
212
 
219
213
  void Fork::IncThreadCount() {
220
214
  if (support_enabled_.load(std::memory_order_relaxed)) {
221
- thread_state_->IncThreadCount();
215
+ NoDestructSingleton<ThreadState>::Get()->IncThreadCount();
222
216
  }
223
217
  }
224
218
 
225
219
  void Fork::DecThreadCount() {
226
220
  if (support_enabled_.load(std::memory_order_relaxed)) {
227
- thread_state_->DecThreadCount();
221
+ NoDestructSingleton<ThreadState>::Get()->DecThreadCount();
228
222
  }
229
223
  }
230
224
  void Fork::AwaitThreads() {
231
225
  if (support_enabled_.load(std::memory_order_relaxed)) {
232
- thread_state_->AwaitThreads();
226
+ NoDestructSingleton<ThreadState>::Get()->AwaitThreads();
233
227
  }
234
228
  }
235
229
 
236
- internal::ExecCtxState* Fork::exec_ctx_state_ = nullptr;
237
- internal::ThreadState* Fork::thread_state_ = nullptr;
238
230
  std::atomic<bool> Fork::support_enabled_(false);
239
231
  bool Fork::override_enabled_ = false;
240
232
  Fork::child_postfork_func Fork::reset_child_polling_engine_ = nullptr;
@@ -30,17 +30,11 @@
30
30
 
31
31
  namespace grpc_core {
32
32
 
33
- namespace internal {
34
- class ExecCtxState;
35
- class ThreadState;
36
- } // namespace internal
37
-
38
33
  class Fork {
39
34
  public:
40
35
  typedef void (*child_postfork_func)(void);
41
36
 
42
37
  static void GlobalInit();
43
- static void GlobalShutdown();
44
38
 
45
39
  // Returns true if fork suppport is enabled, false otherwise
46
40
  static bool Enabled();
@@ -91,8 +85,6 @@ class Fork {
91
85
  static void DoIncExecCtxCount();
92
86
  static void DoDecExecCtxCount();
93
87
 
94
- static internal::ExecCtxState* exec_ctx_state_;
95
- static internal::ThreadState* thread_state_;
96
88
  static std::atomic<bool> support_enabled_;
97
89
  static bool override_enabled_;
98
90
  static child_postfork_func reset_child_polling_engine_;
@@ -28,12 +28,13 @@
28
28
  #include <type_traits>
29
29
 
30
30
  #include "absl/strings/str_format.h"
31
+ #include "absl/types/optional.h"
31
32
 
32
33
  #include <grpc/support/log.h>
33
34
  #include <grpc/support/string_util.h>
34
35
 
35
- #include "src/core/lib/gpr/env.h"
36
36
  #include "src/core/lib/gpr/string.h"
37
+ #include "src/core/lib/gprpp/env.h"
37
38
 
38
39
  namespace grpc_core {
39
40
 
@@ -60,14 +61,14 @@ void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func) {
60
61
  }
61
62
 
62
63
  UniquePtr<char> GlobalConfigEnv::GetValue() {
63
- return UniquePtr<char>(gpr_getenv(GetName()));
64
+ auto env = GetEnv(GetName());
65
+ return UniquePtr<char>(env.has_value() ? gpr_strdup(env.value().c_str())
66
+ : nullptr);
64
67
  }
65
68
 
66
- void GlobalConfigEnv::SetValue(const char* value) {
67
- gpr_setenv(GetName(), value);
68
- }
69
+ void GlobalConfigEnv::SetValue(const char* value) { SetEnv(GetName(), value); }
69
70
 
70
- void GlobalConfigEnv::Unset() { gpr_unsetenv(GetName()); }
71
+ void GlobalConfigEnv::Unset() { UnsetEnv(GetName()); }
71
72
 
72
73
  char* GlobalConfigEnv::GetName() {
73
74
  // This makes sure that name_ is in a canonical form having uppercase
@@ -0,0 +1,67 @@
1
+ // Copyright 2022 The gRPC Authors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef GRPC_CORE_LIB_GPRPP_NOTIFICATION_H
16
+ #define GRPC_CORE_LIB_GPRPP_NOTIFICATION_H
17
+
18
+ #include <grpc/support/port_platform.h>
19
+
20
+ #include "absl/time/clock.h"
21
+ #include "absl/time/time.h"
22
+
23
+ #include "src/core/lib/gprpp/sync.h"
24
+
25
+ namespace grpc_core {
26
+
27
+ // Polyfill for absl::Notification until we can use that type.
28
+ class Notification {
29
+ public:
30
+ void Notify() {
31
+ MutexLock lock(&mu_);
32
+ notified_ = true;
33
+ cv_.SignalAll();
34
+ }
35
+
36
+ void WaitForNotification() {
37
+ MutexLock lock(&mu_);
38
+ while (!notified_) {
39
+ cv_.Wait(&mu_);
40
+ }
41
+ }
42
+
43
+ bool WaitForNotificationWithTimeout(absl::Duration timeout) {
44
+ auto now = absl::Now();
45
+ auto deadline = now + timeout;
46
+ MutexLock lock(&mu_);
47
+ while (!notified_ && now < deadline) {
48
+ cv_.WaitWithTimeout(&mu_, deadline - now);
49
+ now = absl::Now();
50
+ }
51
+ return notified_;
52
+ }
53
+
54
+ bool HasBeenNotified() {
55
+ MutexLock lock(&mu_);
56
+ return notified_;
57
+ }
58
+
59
+ private:
60
+ Mutex mu_;
61
+ CondVar cv_;
62
+ bool notified_ = false;
63
+ };
64
+
65
+ } // namespace grpc_core
66
+
67
+ #endif // GRPC_CORE_LIB_GPRPP_NOTIFICATION_H
@@ -0,0 +1,40 @@
1
+ // Copyright 2022 gRPC authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H
16
+ #define GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H
17
+
18
+ #include <grpc/support/port_platform.h>
19
+
20
+ #include "src/core/lib/gprpp/sorted_pack.h"
21
+ #include "src/core/lib/gprpp/table.h"
22
+
23
+ namespace grpc_core {
24
+
25
+ namespace packed_table_detail {
26
+ template <typename A, typename B>
27
+ struct Cmp {
28
+ static constexpr bool kValue = alignof(A) > alignof(B) ||
29
+ (alignof(A) == alignof(B) &&
30
+ sizeof(A) > sizeof(B));
31
+ };
32
+ }; // namespace packed_table_detail
33
+
34
+ template <typename... T>
35
+ using PackedTable =
36
+ typename WithSortedPack<Table, packed_table_detail::Cmp, T...>::Type;
37
+
38
+ } // namespace grpc_core
39
+
40
+ #endif // GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H