grpc 1.49.0.pre1-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 (277) 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 +41 -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 +114 -103
  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 +87 -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 +38 -18
  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 +19 -16
  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 +5 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +5 -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/ext/grpc/extconf.rb +1 -1
  258. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  259. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  260. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  261. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  262. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  263. data/src/ruby/lib/grpc/version.rb +1 -1
  264. data/src/ruby/spec/channel_spec.rb +5 -0
  265. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  266. data/src/ruby/spec/user_agent_spec.rb +1 -1
  267. metadata +32 -19
  268. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  269. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  270. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  271. data/src/core/lib/event_engine/promise.h +0 -78
  272. data/src/core/lib/gpr/env_windows.cc +0 -74
  273. data/src/core/lib/gpr/string_windows.h +0 -32
  274. data/src/core/lib/profiling/basic_timers.cc +0 -295
  275. data/src/core/lib/profiling/stap_timers.cc +0 -50
  276. data/src/core/lib/profiling/timers.h +0 -94
  277. data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
@@ -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
@@ -55,14 +55,12 @@ class RefCountedPtr {
55
55
 
56
56
  // Move assignment.
57
57
  RefCountedPtr& operator=(RefCountedPtr&& other) noexcept {
58
- reset(other.value_);
59
- other.value_ = nullptr;
58
+ reset(std::exchange(other.value_, nullptr));
60
59
  return *this;
61
60
  }
62
61
  template <typename Y>
63
62
  RefCountedPtr& operator=(RefCountedPtr<Y>&& other) noexcept {
64
- reset(other.value_);
65
- other.value_ = nullptr;
63
+ reset(std::exchange(other.value_, nullptr));
66
64
  return *this;
67
65
  }
68
66
 
@@ -108,39 +106,32 @@ class RefCountedPtr {
108
106
 
109
107
  // If value is non-null, we take ownership of a ref to it.
110
108
  void reset(T* value = nullptr) {
111
- if (value_ != nullptr) value_->Unref();
112
- value_ = value;
109
+ T* old_value = std::exchange(value_, value);
110
+ if (old_value != nullptr) old_value->Unref();
113
111
  }
114
112
  void reset(const DebugLocation& location, const char* reason,
115
113
  T* value = nullptr) {
116
- if (value_ != nullptr) value_->Unref(location, reason);
117
- value_ = value;
114
+ T* old_value = std::exchange(value_, value);
115
+ if (old_value != nullptr) old_value->Unref(location, reason);
118
116
  }
119
117
  template <typename Y>
120
118
  void reset(Y* value = nullptr) {
121
119
  static_assert(std::has_virtual_destructor<T>::value,
122
120
  "T does not have a virtual dtor");
123
- if (value_ != nullptr) value_->Unref();
124
- value_ = static_cast<T*>(value);
121
+ reset(static_cast<T*>(value));
125
122
  }
126
123
  template <typename Y>
127
124
  void reset(const DebugLocation& location, const char* reason,
128
125
  Y* value = nullptr) {
129
126
  static_assert(std::has_virtual_destructor<T>::value,
130
127
  "T does not have a virtual dtor");
131
- if (value_ != nullptr) value_->Unref(location, reason);
132
- value_ = static_cast<T*>(value);
128
+ reset(location, reason, static_cast<T*>(value));
133
129
  }
134
130
 
135
- // TODO(roth): This method exists solely as a transition mechanism to allow
136
- // us to pass a ref to idiomatic C code that does not use RefCountedPtr<>.
137
- // Once all of our code has been converted to idiomatic C++, this
138
- // method should go away.
139
- T* release() {
140
- T* value = value_;
141
- value_ = nullptr;
142
- return value;
143
- }
131
+ // This method is mostly useful for interoperating with C code.
132
+ // Eventually use within core should be banned, except at the surface API
133
+ // boundaries.
134
+ T* release() { return std::exchange(value_, nullptr); }
144
135
 
145
136
  T* get() const { return value_; }
146
137
 
@@ -207,14 +198,12 @@ class WeakRefCountedPtr {
207
198
 
208
199
  // Move assignment.
209
200
  WeakRefCountedPtr& operator=(WeakRefCountedPtr&& other) noexcept {
210
- reset(other.value_);
211
- other.value_ = nullptr;
201
+ reset(std::exchange(other.value_, nullptr));
212
202
  return *this;
213
203
  }
214
204
  template <typename Y>
215
205
  WeakRefCountedPtr& operator=(WeakRefCountedPtr<Y>&& other) noexcept {
216
- reset(other.value_);
217
- other.value_ = nullptr;
206
+ reset(std::exchange(other.value_, nullptr));
218
207
  return *this;
219
208
  }
220
209
 
@@ -260,28 +249,26 @@ class WeakRefCountedPtr {
260
249
 
261
250
  // If value is non-null, we take ownership of a ref to it.
262
251
  void reset(T* value = nullptr) {
263
- if (value_ != nullptr) value_->WeakUnref();
264
- value_ = value;
252
+ T* old_value = std::exchange(value_, value);
253
+ if (old_value != nullptr) old_value->WeakUnref();
265
254
  }
266
255
  void reset(const DebugLocation& location, const char* reason,
267
256
  T* value = nullptr) {
268
- if (value_ != nullptr) value_->WeakUnref(location, reason);
269
- value_ = value;
257
+ T* old_value = std::exchange(value_, value);
258
+ if (old_value != nullptr) old_value->WeakUnref(location, reason);
270
259
  }
271
260
  template <typename Y>
272
261
  void reset(Y* value = nullptr) {
273
262
  static_assert(std::has_virtual_destructor<T>::value,
274
263
  "T does not have a virtual dtor");
275
- if (value_ != nullptr) value_->WeakUnref();
276
- value_ = static_cast<T*>(value);
264
+ reset(static_cast<T*>(value));
277
265
  }
278
266
  template <typename Y>
279
267
  void reset(const DebugLocation& location, const char* reason,
280
268
  Y* value = nullptr) {
281
269
  static_assert(std::has_virtual_destructor<T>::value,
282
270
  "T does not have a virtual dtor");
283
- if (value_ != nullptr) value_->WeakUnref(location, reason);
284
- value_ = static_cast<T*>(value);
271
+ reset(location, reason, static_cast<T*>(value));
285
272
  }
286
273
 
287
274
  // TODO(roth): This method exists solely as a transition mechanism to allow
@@ -0,0 +1,98 @@
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_SORTED_PACK_H
16
+ #define GRPC_CORE_LIB_GPRPP_SORTED_PACK_H
17
+
18
+ #include <grpc/support/port_platform.h>
19
+
20
+ #include <type_traits>
21
+
22
+ namespace grpc_core {
23
+
24
+ namespace sorted_pack_detail {
25
+
26
+ // A list of types
27
+ template <typename... A>
28
+ struct Typelist {
29
+ template <template <typename...> class T>
30
+ using Instantiate = T<A...>;
31
+
32
+ template <typename C>
33
+ using PushFront = Typelist<C, A...>;
34
+ };
35
+
36
+ // Find the smallest element of Args, and the rest of the elements
37
+ template <template <typename, typename> class Cmp, typename Args>
38
+ struct Smallest;
39
+
40
+ template <template <typename, typename> class Cmp, typename Arg,
41
+ typename... Args>
42
+ struct Smallest<Cmp, Typelist<Arg, Args...>> {
43
+ using SmallestRest = Smallest<Cmp, Typelist<Args...>>;
44
+ using PrevSmallest = typename SmallestRest::Result;
45
+ using PrevRest = typename SmallestRest::Rest;
46
+ static constexpr bool kCmpResult = Cmp<Arg, PrevSmallest>::kValue;
47
+ using Result = typename std::conditional<kCmpResult, Arg, PrevSmallest>::type;
48
+ using Prefix = typename std::conditional<kCmpResult, PrevSmallest, Arg>::type;
49
+ using Rest = typename PrevRest::template PushFront<Prefix>;
50
+ };
51
+
52
+ template <template <typename, typename> class Cmp, typename Arg>
53
+ struct Smallest<Cmp, Typelist<Arg>> {
54
+ using Result = Arg;
55
+ using Rest = Typelist<>;
56
+ };
57
+
58
+ // Sort a list of types into a typelist
59
+ template <template <typename, typename> class Cmp, typename Args>
60
+ struct Sorted;
61
+
62
+ template <template <typename, typename> class Cmp, typename... Args>
63
+ struct Sorted<Cmp, Typelist<Args...>> {
64
+ using SmallestResult = Smallest<Cmp, Typelist<Args...>>;
65
+ using SmallestType = typename SmallestResult::Result;
66
+ using RestOfTypes = typename SmallestResult::Rest;
67
+ using SortedRestOfTypes = typename Sorted<Cmp, RestOfTypes>::Result;
68
+ using Result = typename SortedRestOfTypes::template PushFront<SmallestType>;
69
+ };
70
+
71
+ template <template <typename, typename> class Cmp, typename Arg>
72
+ struct Sorted<Cmp, Typelist<Arg>> {
73
+ using Result = Typelist<Arg>;
74
+ };
75
+
76
+ template <template <typename, typename> class Cmp>
77
+ struct Sorted<Cmp, Typelist<>> {
78
+ using Result = Typelist<>;
79
+ };
80
+
81
+ } // namespace sorted_pack_detail
82
+
83
+ // Given a type T<A...>, and a type comparator Cmp<P,Q>, and some set of types
84
+ // Args...:
85
+ // Sort Args... using Cmp into SortedArgs..., then instantiate T<SortedArgs...>
86
+ // as Type.
87
+ // Cmp<P,Q> should have a single constant `kValue` that is true if P < Q.
88
+ template <template <typename...> class T,
89
+ template <typename, typename> class Cmp, typename... Args>
90
+ struct WithSortedPack {
91
+ using Type = typename sorted_pack_detail::Sorted<
92
+ Cmp,
93
+ sorted_pack_detail::Typelist<Args...>>::Result::template Instantiate<T>;
94
+ };
95
+
96
+ } // namespace grpc_core
97
+
98
+ #endif // GRPC_CORE_LIB_GPRPP_SORTED_PACK_H
@@ -38,6 +38,12 @@ struct google_rpc_Status;
38
38
  struct upb_Arena;
39
39
  }
40
40
 
41
+ #define RETURN_IF_ERROR(expr) \
42
+ do { \
43
+ const absl::Status status = (expr); \
44
+ if (!status.ok()) return status; \
45
+ } while (0)
46
+
41
47
  namespace grpc_core {
42
48
 
43
49
  /// This enum should have the same value of grpc_error_ints
@@ -218,7 +218,7 @@ class Table {
218
218
 
219
219
  // Check if this table has index I.
220
220
  template <size_t I>
221
- absl::enable_if_t < I<sizeof...(Ts), bool> has() const {
221
+ absl::enable_if_t<(I < sizeof...(Ts)), bool> has() const {
222
222
  return present_bits_.is_set(I);
223
223
  }
224
224
 
@@ -317,6 +317,14 @@ class Table {
317
317
  ForEachImpl(std::move(f), absl::make_index_sequence<sizeof...(Ts)>());
318
318
  }
319
319
 
320
+ // Iterate through each set field in the table if it exists in Vs, in the
321
+ // order of Vs.
322
+ template <typename F, typename... Vs>
323
+ void ForEachIn(F f) const {
324
+ ForEachImpl(std::move(f),
325
+ absl::index_sequence<table_detail::IndexOf<Vs, Ts...>()...>());
326
+ }
327
+
320
328
  // Count the number of set fields in the table
321
329
  size_t count() const { return present_bits_.count(); }
322
330
 
@@ -0,0 +1,49 @@
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
+ #include <grpc/support/port_platform.h>
16
+
17
+ #include "src/core/lib/gprpp/tchar.h"
18
+
19
+ #ifdef GPR_WINDOWS
20
+
21
+ namespace grpc_core {
22
+
23
+ #if defined UNICODE || defined _UNICODE
24
+ TcharString CharToTchar(std::string input) {
25
+ int needed = MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, NULL, 0);
26
+ if (needed <= 0) return TcharString();
27
+ TcharString ret(needed, L'\0');
28
+ MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1,
29
+ const_cast<LPTSTR>(ret.data()), needed);
30
+ return ret;
31
+ }
32
+
33
+ std::string TcharToChar(TcharString input) {
34
+ int needed =
35
+ WideCharToMultiByte(CP_UTF8, 0, input.c_str(), -1, NULL, 0, NULL, NULL);
36
+ if (needed <= 0) return std::string();
37
+ std::string ret(needed, '\0');
38
+ WideCharToMultiByte(CP_UTF8, 0, input.c_str(), -1,
39
+ const_cast<LPSTR>(ret.data()), needed, NULL, NULL);
40
+ return ret;
41
+ }
42
+ #else
43
+ TcharString CharToTchar(std::string input) { return input; }
44
+ std::string TcharToChar(TcharString input) { return input; }
45
+ #endif
46
+
47
+ } // namespace grpc_core
48
+
49
+ #endif
@@ -0,0 +1,33 @@
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_TCHAR_H
16
+ #define GRPC_CORE_LIB_GPRPP_TCHAR_H
17
+
18
+ #include <grpc/support/port_platform.h>
19
+
20
+ #ifdef GPR_WINDOWS
21
+ #include <string>
22
+
23
+ namespace grpc_core {
24
+
25
+ using TcharString = std::basic_string<TCHAR>;
26
+
27
+ TcharString CharToTchar(std::string input);
28
+ std::string TcharToChar(TcharString input);
29
+
30
+ } // namespace grpc_core
31
+ #endif
32
+
33
+ #endif // GRPC_CORE_LIB_GPRPP_TCHAR_H
@@ -28,6 +28,8 @@
28
28
  #include <grpc/impl/codegen/gpr_types.h>
29
29
  #include <grpc/support/log.h>
30
30
 
31
+ #include "src/core/lib/gprpp/no_destruct.h"
32
+
31
33
  namespace grpc_core {
32
34
 
33
35
  namespace {
@@ -35,6 +37,13 @@ namespace {
35
37
  std::atomic<int64_t> g_process_epoch_seconds;
36
38
  std::atomic<gpr_cycle_counter> g_process_epoch_cycles;
37
39
 
40
+ class GprNowTimeSource final : public Timestamp::Source {
41
+ public:
42
+ Timestamp Now() override {
43
+ return Timestamp::FromTimespecRoundDown(gpr_now(GPR_CLOCK_MONOTONIC));
44
+ }
45
+ };
46
+
38
47
  GPR_ATTRIBUTE_NOINLINE std::pair<int64_t, gpr_cycle_counter> InitTime() {
39
48
  gpr_cycle_counter cycles_start = 0;
40
49
  gpr_cycle_counter cycles_end = 0;
@@ -133,6 +142,18 @@ int64_t TimespanToMillisRoundDown(gpr_timespec ts) {
133
142
 
134
143
  } // namespace
135
144
 
145
+ GPR_THREAD_LOCAL(Timestamp::Source*)
146
+ Timestamp::thread_local_time_source_{
147
+ NoDestructSingleton<GprNowTimeSource>::Get()};
148
+
149
+ Timestamp ScopedTimeCache::Now() {
150
+ if (!cached_time_.has_value()) {
151
+ previous()->InvalidateCache();
152
+ cached_time_ = previous()->Now();
153
+ }
154
+ return cached_time_.value();
155
+ }
156
+
136
157
  Timestamp Timestamp::FromTimespecRoundUp(gpr_timespec ts) {
137
158
  return FromMillisecondsAfterProcessEpoch(TimespanToMillisRoundUp(gpr_time_sub(
138
159
  gpr_convert_clock_type(ts, GPR_CLOCK_MONOTONIC), StartTime())));
@@ -23,11 +23,14 @@
23
23
  #include <ostream>
24
24
  #include <string>
25
25
 
26
+ #include "absl/types/optional.h"
27
+
26
28
  #include <grpc/event_engine/event_engine.h>
27
29
  #include <grpc/impl/codegen/gpr_types.h>
28
30
  #include <grpc/support/time.h>
29
31
 
30
32
  #include "src/core/lib/gpr/time_precise.h"
33
+ #include "src/core/lib/gpr/tls.h"
31
34
  #include "src/core/lib/gpr/useful.h"
32
35
 
33
36
  namespace grpc_core {
@@ -61,6 +64,35 @@ class Duration;
61
64
  // Timestamp represents a discrete point in time.
62
65
  class Timestamp {
63
66
  public:
67
+ // Base interface for time providers.
68
+ class Source {
69
+ public:
70
+ // Return the current time.
71
+ virtual Timestamp Now() = 0;
72
+ virtual void InvalidateCache() {}
73
+
74
+ protected:
75
+ // We don't delete through this interface, so non-virtual dtor is fine.
76
+ ~Source() = default;
77
+ };
78
+
79
+ class ScopedSource : public Source {
80
+ public:
81
+ ScopedSource() : previous_(thread_local_time_source_) {
82
+ thread_local_time_source_ = this;
83
+ }
84
+ ScopedSource(const ScopedSource&) = delete;
85
+ ScopedSource& operator=(const ScopedSource&) = delete;
86
+ void InvalidateCache() override { previous_->InvalidateCache(); }
87
+
88
+ protected:
89
+ ~ScopedSource() { thread_local_time_source_ = previous_; }
90
+ Source* previous() const { return previous_; }
91
+
92
+ private:
93
+ Source* const previous_;
94
+ };
95
+
64
96
  constexpr Timestamp() = default;
65
97
  // Constructs a Timestamp from a gpr_timespec.
66
98
  static Timestamp FromTimespecRoundDown(gpr_timespec t);
@@ -70,6 +102,8 @@ class Timestamp {
70
102
  static Timestamp FromCycleCounterRoundUp(gpr_cycle_counter c);
71
103
  static Timestamp FromCycleCounterRoundDown(gpr_cycle_counter c);
72
104
 
105
+ static Timestamp Now() { return thread_local_time_source_->Now(); }
106
+
73
107
  static constexpr Timestamp FromMillisecondsAfterProcessEpoch(int64_t millis) {
74
108
  return Timestamp(millis);
75
109
  }
@@ -116,6 +150,21 @@ class Timestamp {
116
150
  explicit constexpr Timestamp(int64_t millis) : millis_(millis) {}
117
151
 
118
152
  int64_t millis_ = 0;
153
+ static GPR_THREAD_LOCAL(Timestamp::Source*) thread_local_time_source_;
154
+ };
155
+
156
+ class ScopedTimeCache final : public Timestamp::ScopedSource {
157
+ public:
158
+ Timestamp Now() override;
159
+
160
+ void InvalidateCache() override {
161
+ cached_time_ = absl::nullopt;
162
+ Timestamp::ScopedSource::InvalidateCache();
163
+ }
164
+ void TestOnlySetNow(Timestamp now) { cached_time_ = now; }
165
+
166
+ private:
167
+ absl::optional<Timestamp> cached_time_;
119
168
  };
120
169
 
121
170
  // Duration represents a span of time.
@@ -200,6 +249,7 @@ class Duration {
200
249
  }
201
250
  return *this;
202
251
  }
252
+ Duration& operator*=(double multiplier);
203
253
  Duration& operator+=(Duration other) {
204
254
  millis_ += other.millis_;
205
255
  return *this;
@@ -287,6 +337,11 @@ inline Duration Duration::FromSecondsAsDouble(double seconds) {
287
337
  return Milliseconds(static_cast<int64_t>(millis));
288
338
  }
289
339
 
340
+ inline Duration& Duration::operator*=(double multiplier) {
341
+ *this = *this * multiplier;
342
+ return *this;
343
+ }
344
+
290
345
  inline Timestamp& Timestamp::operator+=(Duration duration) {
291
346
  return *this = (*this + duration);
292
347
  }
@@ -0,0 +1,61 @@
1
+ // Copyright 2020 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
+ #include <grpc/support/port_platform.h>
16
+
17
+ #include "src/core/lib/gprpp/validation_errors.h"
18
+
19
+ #include <algorithm>
20
+ #include <utility>
21
+
22
+ #include "absl/status/status.h"
23
+ #include "absl/strings/str_cat.h"
24
+ #include "absl/strings/str_join.h"
25
+ #include "absl/strings/strip.h"
26
+
27
+ namespace grpc_core {
28
+
29
+ void ValidationErrors::PushField(absl::string_view ext) {
30
+ // Skip leading '.' for top-level field names.
31
+ if (fields_.empty()) absl::ConsumePrefix(&ext, ".");
32
+ fields_.emplace_back(std::string(ext));
33
+ }
34
+
35
+ void ValidationErrors::PopField() { fields_.pop_back(); }
36
+
37
+ void ValidationErrors::AddError(absl::string_view error) {
38
+ field_errors_[absl::StrJoin(fields_, "")].emplace_back(error);
39
+ }
40
+
41
+ bool ValidationErrors::FieldHasErrors() const {
42
+ return field_errors_.find(absl::StrJoin(fields_, "")) != field_errors_.end();
43
+ }
44
+
45
+ absl::Status ValidationErrors::status(absl::string_view prefix) const {
46
+ if (field_errors_.empty()) return absl::OkStatus();
47
+ std::vector<std::string> errors;
48
+ for (const auto& p : field_errors_) {
49
+ if (p.second.size() > 1) {
50
+ errors.emplace_back(absl::StrCat("field:", p.first, " errors:[",
51
+ absl::StrJoin(p.second, "; "), "]"));
52
+ } else {
53
+ errors.emplace_back(
54
+ absl::StrCat("field:", p.first, " error:", p.second[0]));
55
+ }
56
+ }
57
+ return absl::InvalidArgumentError(
58
+ absl::StrCat(prefix, ": [", absl::StrJoin(errors, "; "), "]"));
59
+ }
60
+
61
+ } // namespace grpc_core