grpc 1.37.1 → 1.38.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 (544) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +64 -58
  3. data/include/grpc/event_engine/README.md +38 -0
  4. data/include/grpc/event_engine/channel_args.h +28 -0
  5. data/include/grpc/event_engine/event_engine.h +336 -0
  6. data/include/grpc/event_engine/port.h +39 -0
  7. data/include/grpc/event_engine/slice_allocator.h +81 -0
  8. data/include/grpc/grpc.h +2 -2
  9. data/include/grpc/grpc_security_constants.h +14 -0
  10. data/include/grpc/impl/codegen/grpc_types.h +11 -0
  11. data/include/grpc/impl/codegen/port_platform.h +5 -0
  12. data/include/grpc/module.modulemap +14 -14
  13. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -3
  14. data/src/core/ext/filters/client_channel/channel_connectivity.cc +177 -202
  15. data/src/core/ext/filters/client_channel/client_channel.cc +628 -3101
  16. data/src/core/ext/filters/client_channel/client_channel.h +489 -55
  17. data/src/core/ext/filters/client_channel/client_channel_channelz.h +1 -1
  18. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -1
  19. data/src/core/ext/filters/client_channel/config_selector.h +1 -1
  20. data/src/core/ext/filters/client_channel/connector.h +1 -1
  21. data/src/core/ext/filters/client_channel/dynamic_filters.cc +9 -10
  22. data/src/core/ext/filters/client_channel/dynamic_filters.h +3 -3
  23. data/src/core/ext/filters/client_channel/health/health_check_client.cc +26 -27
  24. data/src/core/ext/filters/client_channel/health/health_check_client.h +27 -26
  25. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +24 -21
  26. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy.h +4 -4
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +6 -6
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -43
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +2 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -5
  33. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +14 -12
  34. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +4 -4
  35. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +1 -1
  36. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +15 -15
  37. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +36 -30
  38. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +23 -23
  39. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +31 -46
  40. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +84 -61
  41. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  42. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -4
  43. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  44. data/src/core/ext/filters/client_channel/resolver.h +2 -2
  45. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +23 -15
  46. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -1
  47. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +3 -3
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +14 -14
  50. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +33 -24
  51. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +1 -1
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  53. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  54. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +17 -9
  55. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +20 -28
  56. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +7 -5
  57. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -11
  58. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  59. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +43 -28
  60. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +32 -239
  61. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +20 -49
  62. data/src/core/ext/filters/client_channel/retry_filter.cc +2188 -0
  63. data/src/core/ext/filters/client_channel/retry_filter.h +30 -0
  64. data/src/core/ext/filters/client_channel/retry_service_config.cc +287 -0
  65. data/src/core/ext/filters/client_channel/retry_service_config.h +90 -0
  66. data/src/core/ext/filters/client_channel/server_address.cc +1 -1
  67. data/src/core/ext/filters/client_channel/service_config.cc +15 -14
  68. data/src/core/ext/filters/client_channel/service_config.h +7 -6
  69. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +5 -4
  70. data/src/core/ext/filters/client_channel/service_config_parser.cc +6 -6
  71. data/src/core/ext/filters/client_channel/service_config_parser.h +7 -4
  72. data/src/core/ext/filters/client_channel/subchannel.cc +17 -16
  73. data/src/core/ext/filters/client_channel/subchannel.h +7 -6
  74. data/src/core/ext/filters/client_idle/client_idle_filter.cc +16 -15
  75. data/src/core/ext/filters/deadline/deadline_filter.cc +10 -10
  76. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +19 -18
  77. data/src/core/ext/filters/fault_injection/service_config_parser.cc +5 -5
  78. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  79. data/src/core/ext/filters/http/client/http_client_filter.cc +28 -21
  80. data/src/core/ext/filters/http/client_authority_filter.cc +3 -3
  81. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +23 -22
  82. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +21 -21
  83. data/src/core/ext/filters/http/server/http_server_filter.cc +27 -23
  84. data/src/core/ext/filters/max_age/max_age_filter.cc +12 -10
  85. data/src/core/ext/filters/message_size/message_size_filter.cc +14 -11
  86. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  87. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +4 -3
  88. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +7 -7
  89. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +7 -7
  90. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +2 -2
  91. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  92. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +3 -3
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +44 -45
  94. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -2
  95. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +3 -4
  96. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +2 -2
  97. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -4
  98. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +129 -116
  99. data/src/core/ext/transport/chttp2/transport/context_list.cc +4 -5
  100. data/src/core/ext/transport/chttp2/transport/context_list.h +4 -4
  101. data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
  102. data/src/core/ext/transport/chttp2/transport/flow_control.h +8 -8
  103. data/src/core/ext/transport/chttp2/transport/frame_data.cc +8 -8
  104. data/src/core/ext/transport/chttp2/transport/frame_data.h +10 -10
  105. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +7 -8
  106. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +6 -6
  107. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +7 -8
  108. data/src/core/ext/transport/chttp2/transport/frame_ping.h +7 -6
  109. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +7 -7
  110. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +6 -6
  111. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -5
  112. data/src/core/ext/transport/chttp2/transport/frame_settings.h +6 -6
  113. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -6
  114. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +4 -6
  115. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +237 -208
  116. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +10 -10
  117. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +4 -3
  118. data/src/core/ext/transport/chttp2/transport/hpack_table.h +4 -4
  119. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
  120. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +2 -2
  121. data/src/core/ext/transport/chttp2/transport/internal.h +31 -27
  122. data/src/core/ext/transport/chttp2/transport/parsing.cc +63 -56
  123. data/src/core/ext/transport/chttp2/transport/writing.cc +7 -3
  124. data/src/core/ext/transport/inproc/inproc_transport.cc +30 -29
  125. data/src/core/ext/xds/certificate_provider_factory.h +1 -1
  126. data/src/core/ext/xds/certificate_provider_store.h +3 -3
  127. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +3 -3
  128. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +2 -2
  129. data/src/core/ext/xds/xds_api.cc +101 -93
  130. data/src/core/ext/xds/xds_api.h +6 -6
  131. data/src/core/ext/xds/xds_bootstrap.cc +97 -159
  132. data/src/core/ext/xds/xds_bootstrap.h +19 -24
  133. data/src/core/ext/xds/xds_certificate_provider.cc +4 -4
  134. data/src/core/ext/xds/xds_certificate_provider.h +4 -4
  135. data/src/core/ext/xds/xds_channel_args.h +5 -2
  136. data/src/core/ext/xds/xds_client.cc +310 -178
  137. data/src/core/ext/xds/xds_client.h +41 -27
  138. data/src/core/ext/xds/xds_client_stats.h +3 -2
  139. data/src/core/ext/xds/xds_server_config_fetcher.cc +34 -20
  140. data/src/core/lib/{iomgr → address_utils}/parse_address.cc +17 -17
  141. data/src/core/lib/{iomgr → address_utils}/parse_address.h +7 -7
  142. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.cc +3 -20
  143. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.h +6 -11
  144. data/src/core/lib/channel/channel_stack.cc +10 -9
  145. data/src/core/lib/channel/channel_stack.h +10 -9
  146. data/src/core/lib/channel/channel_stack_builder.cc +2 -2
  147. data/src/core/lib/channel/channel_stack_builder.h +1 -1
  148. data/src/core/lib/channel/channelz.cc +21 -13
  149. data/src/core/lib/channel/connected_channel.cc +4 -4
  150. data/src/core/lib/channel/handshaker.cc +7 -6
  151. data/src/core/lib/channel/handshaker.h +5 -5
  152. data/src/core/lib/event_engine/slice_allocator.cc +59 -0
  153. data/src/core/lib/event_engine/sockaddr.cc +38 -0
  154. data/src/core/lib/gprpp/ref_counted.h +28 -14
  155. data/src/core/lib/gprpp/status_helper.cc +407 -0
  156. data/src/core/lib/gprpp/status_helper.h +180 -0
  157. data/src/core/lib/http/httpcli.cc +11 -11
  158. data/src/core/lib/http/httpcli_security_connector.cc +11 -7
  159. data/src/core/lib/http/parser.cc +16 -16
  160. data/src/core/lib/http/parser.h +4 -4
  161. data/src/core/lib/iomgr/buffer_list.cc +7 -9
  162. data/src/core/lib/iomgr/buffer_list.h +4 -5
  163. data/src/core/lib/iomgr/call_combiner.cc +15 -12
  164. data/src/core/lib/iomgr/call_combiner.h +12 -14
  165. data/src/core/lib/iomgr/cfstream_handle.cc +3 -3
  166. data/src/core/lib/iomgr/cfstream_handle.h +1 -1
  167. data/src/core/lib/iomgr/closure.h +7 -6
  168. data/src/core/lib/iomgr/combiner.cc +14 -12
  169. data/src/core/lib/iomgr/combiner.h +2 -2
  170. data/src/core/lib/iomgr/endpoint.cc +1 -1
  171. data/src/core/lib/iomgr/endpoint.h +2 -2
  172. data/src/core/lib/iomgr/endpoint_cfstream.cc +11 -13
  173. data/src/core/lib/iomgr/endpoint_pair_windows.cc +1 -1
  174. data/src/core/lib/iomgr/error.cc +167 -61
  175. data/src/core/lib/iomgr/error.h +217 -106
  176. data/src/core/lib/iomgr/error_cfstream.cc +3 -2
  177. data/src/core/lib/iomgr/error_cfstream.h +2 -2
  178. data/src/core/lib/iomgr/error_internal.h +5 -1
  179. data/src/core/lib/iomgr/ev_apple.cc +5 -5
  180. data/src/core/lib/iomgr/ev_epoll1_linux.cc +19 -19
  181. data/src/core/lib/iomgr/ev_epollex_linux.cc +48 -45
  182. data/src/core/lib/iomgr/ev_poll_posix.cc +26 -23
  183. data/src/core/lib/iomgr/ev_posix.cc +9 -8
  184. data/src/core/lib/iomgr/ev_posix.h +9 -9
  185. data/src/core/lib/iomgr/exec_ctx.cc +4 -4
  186. data/src/core/lib/iomgr/exec_ctx.h +1 -1
  187. data/src/core/lib/iomgr/executor.cc +8 -8
  188. data/src/core/lib/iomgr/executor.h +2 -2
  189. data/src/core/lib/iomgr/iomgr.cc +1 -1
  190. data/src/core/lib/iomgr/iomgr.h +1 -1
  191. data/src/core/lib/iomgr/iomgr_custom.cc +1 -1
  192. data/src/core/lib/iomgr/iomgr_internal.cc +2 -2
  193. data/src/core/lib/iomgr/iomgr_internal.h +3 -3
  194. data/src/core/lib/iomgr/iomgr_posix.cc +1 -1
  195. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +2 -2
  196. data/src/core/lib/iomgr/iomgr_windows.cc +1 -1
  197. data/src/core/lib/iomgr/load_file.cc +4 -4
  198. data/src/core/lib/iomgr/load_file.h +2 -2
  199. data/src/core/lib/iomgr/lockfree_event.cc +5 -5
  200. data/src/core/lib/iomgr/lockfree_event.h +1 -1
  201. data/src/core/lib/iomgr/pollset.cc +5 -5
  202. data/src/core/lib/iomgr/pollset.h +9 -9
  203. data/src/core/lib/iomgr/pollset_custom.cc +5 -5
  204. data/src/core/lib/iomgr/pollset_windows.cc +5 -5
  205. data/src/core/lib/iomgr/port.h +1 -1
  206. data/src/core/lib/iomgr/python_util.h +1 -1
  207. data/src/core/lib/iomgr/resolve_address.cc +3 -3
  208. data/src/core/lib/iomgr/resolve_address.h +6 -6
  209. data/src/core/lib/iomgr/resolve_address_custom.cc +10 -9
  210. data/src/core/lib/iomgr/resolve_address_custom.h +3 -3
  211. data/src/core/lib/iomgr/resolve_address_posix.cc +3 -3
  212. data/src/core/lib/iomgr/resolve_address_windows.cc +4 -4
  213. data/src/core/lib/iomgr/resource_quota.cc +11 -10
  214. data/src/core/lib/iomgr/socket_utils_common_posix.cc +22 -20
  215. data/src/core/lib/iomgr/socket_utils_posix.h +20 -20
  216. data/src/core/lib/iomgr/tcp_client_cfstream.cc +4 -4
  217. data/src/core/lib/iomgr/tcp_client_custom.cc +5 -6
  218. data/src/core/lib/iomgr/tcp_client_posix.cc +15 -17
  219. data/src/core/lib/iomgr/tcp_client_posix.h +3 -4
  220. data/src/core/lib/iomgr/tcp_client_windows.cc +5 -5
  221. data/src/core/lib/iomgr/tcp_custom.cc +14 -16
  222. data/src/core/lib/iomgr/tcp_custom.h +13 -12
  223. data/src/core/lib/iomgr/tcp_posix.cc +36 -34
  224. data/src/core/lib/iomgr/tcp_server.cc +6 -6
  225. data/src/core/lib/iomgr/tcp_server.h +12 -11
  226. data/src/core/lib/iomgr/tcp_server_custom.cc +23 -21
  227. data/src/core/lib/iomgr/tcp_server_posix.cc +22 -21
  228. data/src/core/lib/iomgr/tcp_server_utils_posix.h +13 -12
  229. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +19 -17
  230. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +9 -9
  231. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc +4 -4
  232. data/src/core/lib/iomgr/tcp_server_windows.cc +26 -25
  233. data/src/core/lib/iomgr/tcp_uv.cc +25 -23
  234. data/src/core/lib/iomgr/tcp_windows.cc +13 -13
  235. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  236. data/src/core/lib/iomgr/timer_custom.cc +2 -1
  237. data/src/core/lib/iomgr/timer_custom.h +1 -1
  238. data/src/core/lib/iomgr/timer_generic.cc +6 -6
  239. data/src/core/lib/iomgr/udp_server.cc +21 -20
  240. data/src/core/lib/iomgr/unix_sockets_posix.cc +3 -3
  241. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -2
  242. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +10 -7
  243. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +3 -3
  244. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +4 -4
  245. data/src/core/lib/iomgr/wakeup_fd_posix.cc +3 -3
  246. data/src/core/lib/iomgr/wakeup_fd_posix.h +8 -6
  247. data/src/core/lib/iomgr/work_serializer.h +17 -1
  248. data/src/core/lib/json/json.h +1 -1
  249. data/src/core/lib/json/json_reader.cc +4 -4
  250. data/src/core/lib/matchers/matchers.cc +39 -39
  251. data/src/core/lib/matchers/matchers.h +28 -28
  252. data/src/core/lib/security/credentials/composite/composite_credentials.cc +4 -4
  253. data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -2
  254. data/src/core/lib/security/credentials/credentials.h +2 -2
  255. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +17 -13
  256. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +13 -11
  257. data/src/core/lib/security/credentials/external/aws_request_signer.cc +2 -1
  258. data/src/core/lib/security/credentials/external/aws_request_signer.h +1 -1
  259. data/src/core/lib/security/credentials/external/external_account_credentials.cc +15 -12
  260. data/src/core/lib/security/credentials/external/external_account_credentials.h +9 -8
  261. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -4
  262. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +4 -3
  263. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +8 -8
  264. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +9 -7
  265. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -2
  266. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -2
  267. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +9 -9
  268. data/src/core/lib/security/credentials/iam/iam_credentials.cc +2 -2
  269. data/src/core/lib/security/credentials/iam/iam_credentials.h +2 -2
  270. data/src/core/lib/security/credentials/jwt/json_token.cc +2 -2
  271. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +3 -3
  272. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -2
  273. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +7 -5
  274. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +21 -19
  275. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -5
  276. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +5 -5
  277. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -2
  278. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +8 -7
  279. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +9 -9
  280. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +19 -13
  281. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +4 -0
  282. data/src/core/lib/security/credentials/xds/xds_credentials.cc +3 -3
  283. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -3
  284. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -3
  285. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +2 -2
  286. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +12 -2
  287. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +1 -1
  288. data/src/core/lib/security/security_connector/local/local_security_connector.cc +14 -4
  289. data/src/core/lib/security/security_connector/security_connector.h +9 -4
  290. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +16 -6
  291. data/src/core/lib/security/security_connector/ssl_utils.cc +22 -4
  292. data/src/core/lib/security/security_connector/ssl_utils.h +4 -4
  293. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +56 -60
  294. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +66 -48
  295. data/src/core/lib/security/transport/client_auth_filter.cc +18 -10
  296. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  297. data/src/core/lib/security/transport/security_handshaker.cc +33 -32
  298. data/src/core/lib/security/transport/server_auth_filter.cc +19 -13
  299. data/src/core/lib/security/transport/tsi_error.cc +2 -1
  300. data/src/core/lib/security/transport/tsi_error.h +2 -1
  301. data/src/core/lib/security/util/json_util.cc +2 -2
  302. data/src/core/lib/security/util/json_util.h +1 -1
  303. data/src/core/lib/surface/call.cc +46 -45
  304. data/src/core/lib/surface/call.h +2 -2
  305. data/src/core/lib/surface/channel.cc +6 -6
  306. data/src/core/lib/surface/channel.h +3 -2
  307. data/src/core/lib/surface/channel_ping.cc +1 -1
  308. data/src/core/lib/surface/completion_queue.cc +46 -47
  309. data/src/core/lib/surface/completion_queue.h +2 -1
  310. data/src/core/lib/surface/lame_client.cc +11 -11
  311. data/src/core/lib/surface/lame_client.h +1 -1
  312. data/src/core/lib/surface/server.cc +28 -22
  313. data/src/core/lib/surface/server.h +16 -15
  314. data/src/core/lib/surface/validate_metadata.cc +7 -7
  315. data/src/core/lib/surface/validate_metadata.h +3 -2
  316. data/src/core/lib/surface/version.cc +4 -2
  317. data/src/core/lib/transport/byte_stream.cc +5 -5
  318. data/src/core/lib/transport/byte_stream.h +8 -8
  319. data/src/core/lib/transport/connectivity_state.cc +1 -1
  320. data/src/core/lib/transport/error_utils.cc +19 -8
  321. data/src/core/lib/transport/error_utils.h +11 -5
  322. data/src/core/lib/transport/metadata_batch.cc +37 -37
  323. data/src/core/lib/transport/metadata_batch.h +19 -18
  324. data/src/core/lib/transport/transport.cc +4 -3
  325. data/src/core/lib/transport/transport.h +4 -4
  326. data/src/core/lib/transport/transport_op_string.cc +5 -5
  327. data/src/core/tsi/alts/crypt/gsec.h +4 -0
  328. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  329. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +7 -6
  330. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +2 -1
  331. data/src/core/tsi/ssl_transport_security.cc +32 -14
  332. data/src/core/tsi/ssl_transport_security.h +3 -4
  333. data/src/ruby/bin/math_services_pb.rb +1 -1
  334. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  335. data/src/ruby/lib/grpc/version.rb +1 -1
  336. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +1 -1
  337. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +6 -6
  338. data/third_party/abseil-cpp/absl/algorithm/container.h +3 -3
  339. data/third_party/abseil-cpp/absl/base/attributes.h +24 -4
  340. data/third_party/abseil-cpp/absl/base/call_once.h +2 -9
  341. data/third_party/abseil-cpp/absl/base/config.h +37 -9
  342. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +24 -10
  343. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +4 -1
  344. data/third_party/abseil-cpp/absl/base/internal/endian.h +61 -0
  345. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +2 -3
  346. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +34 -32
  347. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +16 -6
  348. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +11 -2
  349. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +14 -5
  350. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +2 -2
  351. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +3 -3
  352. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +2 -2
  353. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +11 -11
  354. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +5 -5
  355. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +1 -1
  356. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +5 -2
  357. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +43 -42
  358. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +111 -7
  359. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +0 -76
  360. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +1 -3
  361. data/third_party/abseil-cpp/absl/base/log_severity.h +4 -4
  362. data/third_party/abseil-cpp/absl/base/macros.h +11 -0
  363. data/third_party/abseil-cpp/absl/base/optimization.h +10 -7
  364. data/third_party/abseil-cpp/absl/base/options.h +1 -1
  365. data/third_party/abseil-cpp/absl/base/port.h +0 -1
  366. data/third_party/abseil-cpp/absl/base/thread_annotations.h +1 -1
  367. data/third_party/abseil-cpp/absl/container/fixed_array.h +2 -2
  368. data/third_party/abseil-cpp/absl/container/inlined_vector.h +5 -3
  369. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +1 -1
  370. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +5 -1
  371. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +2 -1
  372. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +2 -1
  373. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +141 -66
  374. data/third_party/abseil-cpp/absl/container/internal/layout.h +4 -4
  375. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +14 -1
  376. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +136 -136
  377. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +16 -12
  378. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +5 -2
  379. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +3 -12
  380. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +6 -1
  381. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +3 -5
  382. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +2 -2
  383. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +2 -2
  384. data/third_party/abseil-cpp/absl/hash/internal/city.cc +15 -12
  385. data/third_party/abseil-cpp/absl/hash/internal/city.h +1 -19
  386. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +25 -10
  387. data/third_party/abseil-cpp/absl/hash/internal/hash.h +86 -37
  388. data/third_party/abseil-cpp/absl/hash/internal/wyhash.cc +111 -0
  389. data/third_party/abseil-cpp/absl/hash/internal/wyhash.h +48 -0
  390. data/third_party/abseil-cpp/absl/meta/type_traits.h +16 -2
  391. data/third_party/abseil-cpp/absl/numeric/bits.h +177 -0
  392. data/third_party/abseil-cpp/absl/numeric/int128.cc +3 -3
  393. data/third_party/abseil-cpp/absl/numeric/internal/bits.h +358 -0
  394. data/third_party/abseil-cpp/absl/numeric/internal/representation.h +55 -0
  395. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +18 -0
  396. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +4 -7
  397. data/third_party/abseil-cpp/absl/status/status.cc +29 -22
  398. data/third_party/abseil-cpp/absl/status/status.h +81 -20
  399. data/third_party/abseil-cpp/absl/status/statusor.h +3 -3
  400. data/third_party/abseil-cpp/absl/strings/charconv.cc +5 -5
  401. data/third_party/abseil-cpp/absl/strings/cord.cc +326 -371
  402. data/third_party/abseil-cpp/absl/strings/cord.h +182 -64
  403. data/third_party/abseil-cpp/absl/strings/escaping.cc +4 -4
  404. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +6 -6
  405. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +83 -0
  406. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +387 -17
  407. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +146 -0
  408. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.cc +897 -0
  409. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +589 -0
  410. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring_reader.h +114 -0
  411. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +14 -0
  412. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +14 -0
  413. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +15 -1
  414. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +19 -4
  415. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +14 -0
  416. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +36 -18
  417. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +14 -0
  418. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +14 -0
  419. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +14 -0
  420. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +15 -40
  421. data/third_party/abseil-cpp/absl/strings/internal/string_constant.h +64 -0
  422. data/third_party/abseil-cpp/absl/strings/match.cc +6 -3
  423. data/third_party/abseil-cpp/absl/strings/match.h +16 -6
  424. data/third_party/abseil-cpp/absl/strings/numbers.cc +132 -4
  425. data/third_party/abseil-cpp/absl/strings/numbers.h +10 -10
  426. data/third_party/abseil-cpp/absl/strings/str_join.h +1 -1
  427. data/third_party/abseil-cpp/absl/strings/str_split.h +38 -4
  428. data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +154 -0
  429. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +2 -1
  430. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +2 -2
  431. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +4 -4
  432. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +1 -65
  433. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -6
  434. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +71 -59
  435. data/third_party/abseil-cpp/absl/synchronization/mutex.h +79 -62
  436. data/third_party/abseil-cpp/absl/time/clock.cc +146 -130
  437. data/third_party/abseil-cpp/absl/time/clock.h +2 -2
  438. data/third_party/abseil-cpp/absl/time/duration.cc +3 -2
  439. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +7 -11
  440. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +7 -1
  441. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +4 -4
  442. data/third_party/abseil-cpp/absl/time/time.cc +4 -3
  443. data/third_party/abseil-cpp/absl/time/time.h +26 -24
  444. data/third_party/abseil-cpp/absl/types/internal/variant.h +1 -1
  445. data/third_party/abseil-cpp/absl/types/variant.h +9 -4
  446. data/third_party/boringssl-with-bazel/err_data.c +477 -461
  447. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bool.c +1 -1
  448. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +1 -1
  449. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +18 -8
  450. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -2
  451. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_locl.h +5 -0
  452. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -1
  453. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +1 -1
  454. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_tls.c +1 -88
  455. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +14 -3
  456. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +119 -273
  457. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +87 -80
  458. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +1 -0
  459. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +1 -1
  460. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +11 -3
  461. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +25 -2
  462. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +10 -2
  463. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +4 -43
  464. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +4 -0
  465. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +0 -1
  466. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +0 -4
  467. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +104 -93
  468. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/internal.h +39 -0
  469. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +43 -46
  470. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +43 -46
  471. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cbc.c +33 -22
  472. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cfb.c +9 -8
  473. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ctr.c +9 -8
  474. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm.c +17 -13
  475. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +1 -22
  476. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ofb.c +2 -1
  477. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +26 -7
  478. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/fips.c +79 -0
  479. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +14 -9
  480. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +45 -48
  481. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +38 -43
  482. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +37 -45
  483. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +103 -42
  484. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +58 -37
  485. data/third_party/boringssl-with-bazel/src/crypto/internal.h +65 -0
  486. data/third_party/boringssl-with-bazel/src/crypto/mem.c +14 -0
  487. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +3 -3
  488. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +1 -1
  489. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +95 -48
  490. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/rand_extra.c +1 -1
  491. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +0 -28
  492. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +19 -0
  493. data/third_party/boringssl-with-bazel/src/crypto/x509/t_req.c +2 -0
  494. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +19 -25
  495. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +3 -2
  496. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +39 -89
  497. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +9 -16
  498. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +1 -1
  499. data/third_party/boringssl-with-bazel/src/crypto/x509/x_algor.c +21 -17
  500. data/third_party/boringssl-with-bazel/src/crypto/x509/x_attrib.c +7 -25
  501. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +5 -0
  502. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +25 -22
  503. data/third_party/boringssl-with-bazel/src/crypto/x509/x_val.c +2 -0
  504. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +2 -4
  505. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  506. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -0
  507. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +0 -3
  508. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +120 -41
  509. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +9 -0
  510. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +0 -8
  511. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +24 -4
  512. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +5 -2
  513. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +19 -0
  514. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +3 -2
  515. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +1 -38
  516. data/third_party/boringssl-with-bazel/src/{crypto/x509/x509_r2x.c → include/openssl/evp_errors.h} +41 -58
  517. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +24 -5
  518. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +2 -0
  519. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +9 -1
  520. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +2 -2
  521. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +185 -17
  522. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +1 -0
  523. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +416 -121
  524. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +2 -0
  525. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +5 -0
  526. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +444 -0
  527. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +244 -1
  528. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +43 -12
  529. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +149 -8
  530. data/third_party/boringssl-with-bazel/src/ssl/internal.h +220 -46
  531. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +7 -1
  532. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -6
  533. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +23 -26
  534. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +74 -15
  535. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +98 -64
  536. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +34 -4
  537. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +205 -100
  538. data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +4 -2
  539. metadata +68 -45
  540. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +0 -88
  541. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +0 -88
  542. data/third_party/abseil-cpp/absl/base/internal/bits.h +0 -219
  543. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +0 -249
  544. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/is_fips.c +0 -29
@@ -31,22 +31,23 @@
31
31
  //
32
32
  // MutexLock - An RAII wrapper to acquire and release a `Mutex` for exclusive/
33
33
  // write access within the current scope.
34
+ //
34
35
  // ReaderMutexLock
35
36
  // - An RAII wrapper to acquire and release a `Mutex` for shared/read
36
37
  // access within the current scope.
37
38
  //
38
39
  // WriterMutexLock
39
- // - Alias for `MutexLock` above, designed for use in distinguishing
40
- // reader and writer locks within code.
40
+ // - Effectively an alias for `MutexLock` above, designed for use in
41
+ // distinguishing reader and writer locks within code.
41
42
  //
42
43
  // In addition to simple mutex locks, this file also defines ways to perform
43
44
  // locking under certain conditions.
44
45
  //
45
- // Condition - (Preferred) Used to wait for a particular predicate that
46
- // depends on state protected by the `Mutex` to become true.
47
- // CondVar - A lower-level variant of `Condition` that relies on
48
- // application code to explicitly signal the `CondVar` when
49
- // a condition has been met.
46
+ // Condition - (Preferred) Used to wait for a particular predicate that
47
+ // depends on state protected by the `Mutex` to become true.
48
+ // CondVar - A lower-level variant of `Condition` that relies on
49
+ // application code to explicitly signal the `CondVar` when
50
+ // a condition has been met.
50
51
  //
51
52
  // See below for more information on using `Condition` or `CondVar`.
52
53
  //
@@ -72,15 +73,6 @@
72
73
  #include "absl/synchronization/internal/per_thread_sem.h"
73
74
  #include "absl/time/time.h"
74
75
 
75
- // Decide if we should use the non-production implementation because
76
- // the production implementation hasn't been fully ported yet.
77
- #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX
78
- #error ABSL_INTERNAL_USE_NONPROD_MUTEX cannot be directly set
79
- #elif defined(ABSL_LOW_LEVEL_ALLOC_MISSING)
80
- #define ABSL_INTERNAL_USE_NONPROD_MUTEX 1
81
- #include "absl/synchronization/internal/mutex_nonprod.inc"
82
- #endif
83
-
84
76
  namespace absl {
85
77
  ABSL_NAMESPACE_BEGIN
86
78
 
@@ -155,7 +147,7 @@ class ABSL_LOCKABLE Mutex {
155
147
  //
156
148
  // Example usage:
157
149
  // namespace foo {
158
- // ABSL_CONST_INIT Mutex mu(absl::kConstInit);
150
+ // ABSL_CONST_INIT absl::Mutex mu(absl::kConstInit);
159
151
  // }
160
152
  explicit constexpr Mutex(absl::ConstInitType);
161
153
 
@@ -170,7 +162,7 @@ class ABSL_LOCKABLE Mutex {
170
162
  // Mutex::Unlock()
171
163
  //
172
164
  // Releases this `Mutex` and returns it from the exclusive/write state to the
173
- // free state. Caller must hold the `Mutex` exclusively.
165
+ // free state. Calling thread must hold the `Mutex` exclusively.
174
166
  void Unlock() ABSL_UNLOCK_FUNCTION();
175
167
 
176
168
  // Mutex::TryLock()
@@ -461,24 +453,13 @@ class ABSL_LOCKABLE Mutex {
461
453
  static void InternalAttemptToUseMutexInFatalSignalHandler();
462
454
 
463
455
  private:
464
- #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX
465
- friend class CondVar;
466
-
467
- synchronization_internal::MutexImpl *impl() { return impl_.get(); }
468
-
469
- synchronization_internal::SynchronizationStorage<
470
- synchronization_internal::MutexImpl>
471
- impl_;
472
- #else
473
456
  std::atomic<intptr_t> mu_; // The Mutex state.
474
457
 
475
458
  // Post()/Wait() versus associated PerThreadSem; in class for required
476
459
  // friendship with PerThreadSem.
477
- static inline void IncrementSynchSem(Mutex *mu,
478
- base_internal::PerThreadSynch *w);
479
- static inline bool DecrementSynchSem(
480
- Mutex *mu, base_internal::PerThreadSynch *w,
481
- synchronization_internal::KernelTimeout t);
460
+ static void IncrementSynchSem(Mutex *mu, base_internal::PerThreadSynch *w);
461
+ static bool DecrementSynchSem(Mutex *mu, base_internal::PerThreadSynch *w,
462
+ synchronization_internal::KernelTimeout t);
482
463
 
483
464
  // slow path acquire
484
465
  void LockSlowLoop(SynchWaitParams *waitp, int flags);
@@ -504,7 +485,6 @@ class ABSL_LOCKABLE Mutex {
504
485
  void Trans(MuHow how); // used for CondVar->Mutex transfer
505
486
  void Fer(
506
487
  base_internal::PerThreadSynch *w); // used for CondVar->Mutex transfer
507
- #endif
508
488
 
509
489
  // Catch the error of writing Mutex when intending MutexLock.
510
490
  Mutex(const volatile Mutex * /*ignored*/) {} // NOLINT(runtime/explicit)
@@ -525,22 +505,36 @@ class ABSL_LOCKABLE Mutex {
525
505
  // Example:
526
506
  //
527
507
  // Class Foo {
528
- //
508
+ // public:
529
509
  // Foo::Bar* Baz() {
530
- // MutexLock l(&lock_);
510
+ // MutexLock lock(&mu_);
531
511
  // ...
532
512
  // return bar;
533
513
  // }
534
514
  //
535
515
  // private:
536
- // Mutex lock_;
516
+ // Mutex mu_;
537
517
  // };
538
518
  class ABSL_SCOPED_LOCKABLE MutexLock {
539
519
  public:
520
+ // Constructors
521
+
522
+ // Calls `mu->Lock()` and returns when that call returns. That is, `*mu` is
523
+ // guaranteed to be locked when this object is constructed. Requires that
524
+ // `mu` be dereferenceable.
540
525
  explicit MutexLock(Mutex *mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
541
526
  this->mu_->Lock();
542
527
  }
543
528
 
529
+ // Like above, but calls `mu->LockWhen(cond)` instead. That is, in addition to
530
+ // the above, the condition given by `cond` is also guaranteed to hold when
531
+ // this object is constructed.
532
+ explicit MutexLock(Mutex *mu, const Condition &cond)
533
+ ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
534
+ : mu_(mu) {
535
+ this->mu_->LockWhen(cond);
536
+ }
537
+
544
538
  MutexLock(const MutexLock &) = delete; // NOLINT(runtime/mutex)
545
539
  MutexLock(MutexLock&&) = delete; // NOLINT(runtime/mutex)
546
540
  MutexLock& operator=(const MutexLock&) = delete;
@@ -562,6 +556,12 @@ class ABSL_SCOPED_LOCKABLE ReaderMutexLock {
562
556
  mu->ReaderLock();
563
557
  }
564
558
 
559
+ explicit ReaderMutexLock(Mutex *mu, const Condition &cond)
560
+ ABSL_SHARED_LOCK_FUNCTION(mu)
561
+ : mu_(mu) {
562
+ mu->ReaderLockWhen(cond);
563
+ }
564
+
565
565
  ReaderMutexLock(const ReaderMutexLock&) = delete;
566
566
  ReaderMutexLock(ReaderMutexLock&&) = delete;
567
567
  ReaderMutexLock& operator=(const ReaderMutexLock&) = delete;
@@ -584,6 +584,12 @@ class ABSL_SCOPED_LOCKABLE WriterMutexLock {
584
584
  mu->WriterLock();
585
585
  }
586
586
 
587
+ explicit WriterMutexLock(Mutex *mu, const Condition &cond)
588
+ ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
589
+ : mu_(mu) {
590
+ mu->WriterLockWhen(cond);
591
+ }
592
+
587
593
  WriterMutexLock(const WriterMutexLock&) = delete;
588
594
  WriterMutexLock(WriterMutexLock&&) = delete;
589
595
  WriterMutexLock& operator=(const WriterMutexLock&) = delete;
@@ -622,16 +628,26 @@ class ABSL_SCOPED_LOCKABLE WriterMutexLock {
622
628
  // `noexcept`; until then this requirement cannot be enforced in the
623
629
  // type system.)
624
630
  //
625
- // Note: to use a `Condition`, you need only construct it and pass it within the
626
- // appropriate `Mutex' member function, such as `Mutex::Await()`.
631
+ // Note: to use a `Condition`, you need only construct it and pass it to a
632
+ // suitable `Mutex' member function, such as `Mutex::Await()`, or to the
633
+ // constructor of one of the scope guard classes.
627
634
  //
628
- // Example:
635
+ // Example using LockWhen/Unlock:
629
636
  //
630
637
  // // assume count_ is not internal reference count
631
638
  // int count_ ABSL_GUARDED_BY(mu_);
639
+ // Condition count_is_zero(+[](int *count) { return *count == 0; }, &count_);
640
+ //
641
+ // mu_.LockWhen(count_is_zero);
642
+ // // ...
643
+ // mu_.Unlock();
632
644
  //
633
- // mu_.LockWhen(Condition(+[](int* count) { return *count == 0; },
634
- // &count_));
645
+ // Example using a scope guard:
646
+ //
647
+ // {
648
+ // MutexLock lock(&mu_, count_is_zero);
649
+ // // ...
650
+ // }
635
651
  //
636
652
  // When multiple threads are waiting on exactly the same condition, make sure
637
653
  // that they are constructed with the same parameters (same pointer to function
@@ -686,10 +702,10 @@ class Condition {
686
702
  // };
687
703
  // mu_.Await(Condition(&reached));
688
704
  //
689
- // NOTE: never use "mu_.AssertHeld()" instead of "mu_.AssertReadHeld()" in the
690
- // lambda as it may be called when the mutex is being unlocked from a scope
691
- // holding only a reader lock, which will make the assertion not fulfilled and
692
- // crash the binary.
705
+ // NOTE: never use "mu_.AssertHeld()" instead of "mu_.AssertReaderHeld()" in
706
+ // the lambda as it may be called when the mutex is being unlocked from a
707
+ // scope holding only a reader lock, which will make the assertion not
708
+ // fulfilled and crash the binary.
693
709
 
694
710
  // See class comment for performance advice. In particular, if there
695
711
  // might be more than one waiter for the same condition, make sure
@@ -838,17 +854,10 @@ class CondVar {
838
854
  void EnableDebugLog(const char *name);
839
855
 
840
856
  private:
841
- #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX
842
- synchronization_internal::CondVarImpl *impl() { return impl_.get(); }
843
- synchronization_internal::SynchronizationStorage<
844
- synchronization_internal::CondVarImpl>
845
- impl_;
846
- #else
847
857
  bool WaitCommon(Mutex *mutex, synchronization_internal::KernelTimeout t);
848
858
  void Remove(base_internal::PerThreadSynch *s);
849
859
  void Wakeup(base_internal::PerThreadSynch *w);
850
860
  std::atomic<intptr_t> cv_; // Condition variable state.
851
- #endif
852
861
  CondVar(const CondVar&) = delete;
853
862
  CondVar& operator=(const CondVar&) = delete;
854
863
  };
@@ -870,6 +879,15 @@ class ABSL_SCOPED_LOCKABLE MutexLockMaybe {
870
879
  this->mu_->Lock();
871
880
  }
872
881
  }
882
+
883
+ explicit MutexLockMaybe(Mutex *mu, const Condition &cond)
884
+ ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
885
+ : mu_(mu) {
886
+ if (this->mu_ != nullptr) {
887
+ this->mu_->LockWhen(cond);
888
+ }
889
+ }
890
+
873
891
  ~MutexLockMaybe() ABSL_UNLOCK_FUNCTION() {
874
892
  if (this->mu_ != nullptr) { this->mu_->Unlock(); }
875
893
  }
@@ -892,6 +910,13 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
892
910
  : mu_(mu) {
893
911
  this->mu_->Lock();
894
912
  }
913
+
914
+ explicit ReleasableMutexLock(Mutex *mu, const Condition &cond)
915
+ ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
916
+ : mu_(mu) {
917
+ this->mu_->LockWhen(cond);
918
+ }
919
+
895
920
  ~ReleasableMutexLock() ABSL_UNLOCK_FUNCTION() {
896
921
  if (this->mu_ != nullptr) { this->mu_->Unlock(); }
897
922
  }
@@ -906,12 +931,6 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
906
931
  ReleasableMutexLock& operator=(ReleasableMutexLock&&) = delete;
907
932
  };
908
933
 
909
- #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX
910
-
911
- inline constexpr Mutex::Mutex(absl::ConstInitType) : impl_(absl::kConstInit) {}
912
-
913
- #else
914
-
915
934
  inline Mutex::Mutex() : mu_(0) {
916
935
  ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static);
917
936
  }
@@ -920,8 +939,6 @@ inline constexpr Mutex::Mutex(absl::ConstInitType) : mu_(0) {}
920
939
 
921
940
  inline CondVar::CondVar() : cv_(0) {}
922
941
 
923
- #endif // ABSL_INTERNAL_USE_NONPROD_MUTEX
924
-
925
942
  // static
926
943
  template <typename T>
927
944
  bool Condition::CastAndCallMethod(const Condition *c) {
@@ -988,7 +1005,7 @@ void RegisterMutexProfiler(void (*fn)(int64_t wait_timestamp));
988
1005
  //
989
1006
  // This has the same memory ordering concerns as RegisterMutexProfiler() above.
990
1007
  void RegisterMutexTracer(void (*fn)(const char *msg, const void *obj,
991
- int64_t wait_cycles));
1008
+ int64_t wait_cycles));
992
1009
 
993
1010
  // TODO(gfalcon): Combine RegisterMutexProfiler() and RegisterMutexTracer()
994
1011
  // into a single interface, since they are only ever called in pairs.
@@ -1059,7 +1076,7 @@ ABSL_NAMESPACE_END
1059
1076
  // By changing our extension points to be extern "C", we dodge this
1060
1077
  // check.
1061
1078
  extern "C" {
1062
- void AbslInternalMutexYield();
1079
+ void ABSL_INTERNAL_C_SYMBOL(AbslInternalMutexYield)();
1063
1080
  } // extern "C"
1064
1081
 
1065
1082
  #endif // ABSL_SYNCHRONIZATION_MUTEX_H_
@@ -15,6 +15,7 @@
15
15
  #include "absl/time/clock.h"
16
16
 
17
17
  #include "absl/base/attributes.h"
18
+ #include "absl/base/optimization.h"
18
19
 
19
20
  #ifdef _WIN32
20
21
  #include <windows.h>
@@ -74,9 +75,7 @@ ABSL_NAMESPACE_END
74
75
  #if !ABSL_USE_CYCLECLOCK_FOR_GET_CURRENT_TIME_NANOS
75
76
  namespace absl {
76
77
  ABSL_NAMESPACE_BEGIN
77
- int64_t GetCurrentTimeNanos() {
78
- return GET_CURRENT_TIME_NANOS_FROM_SYSTEM();
79
- }
78
+ int64_t GetCurrentTimeNanos() { return GET_CURRENT_TIME_NANOS_FROM_SYSTEM(); }
80
79
  ABSL_NAMESPACE_END
81
80
  } // namespace absl
82
81
  #else // Use the cyclecounter-based implementation below.
@@ -87,13 +86,6 @@ ABSL_NAMESPACE_END
87
86
  ::absl::time_internal::UnscaledCycleClockWrapperForGetCurrentTime::Now()
88
87
  #endif
89
88
 
90
- // The following counters are used only by the test code.
91
- static int64_t stats_initializations;
92
- static int64_t stats_reinitializations;
93
- static int64_t stats_calibrations;
94
- static int64_t stats_slow_paths;
95
- static int64_t stats_fast_slow_paths;
96
-
97
89
  namespace absl {
98
90
  ABSL_NAMESPACE_BEGIN
99
91
  namespace time_internal {
@@ -107,72 +99,6 @@ class UnscaledCycleClockWrapperForGetCurrentTime {
107
99
 
108
100
  // uint64_t is used in this module to provide an extra bit in multiplications
109
101
 
110
- // Return the time in ns as told by the kernel interface. Place in *cycleclock
111
- // the value of the cycleclock at about the time of the syscall.
112
- // This call represents the time base that this module synchronizes to.
113
- // Ensures that *cycleclock does not step back by up to (1 << 16) from
114
- // last_cycleclock, to discard small backward counter steps. (Larger steps are
115
- // assumed to be complete resyncs, which shouldn't happen. If they do, a full
116
- // reinitialization of the outer algorithm should occur.)
117
- static int64_t GetCurrentTimeNanosFromKernel(uint64_t last_cycleclock,
118
- uint64_t *cycleclock) {
119
- // We try to read clock values at about the same time as the kernel clock.
120
- // This value gets adjusted up or down as estimate of how long that should
121
- // take, so we can reject attempts that take unusually long.
122
- static std::atomic<uint64_t> approx_syscall_time_in_cycles{10 * 1000};
123
-
124
- uint64_t local_approx_syscall_time_in_cycles = // local copy
125
- approx_syscall_time_in_cycles.load(std::memory_order_relaxed);
126
-
127
- int64_t current_time_nanos_from_system;
128
- uint64_t before_cycles;
129
- uint64_t after_cycles;
130
- uint64_t elapsed_cycles;
131
- int loops = 0;
132
- do {
133
- before_cycles = GET_CURRENT_TIME_NANOS_CYCLECLOCK_NOW();
134
- current_time_nanos_from_system = GET_CURRENT_TIME_NANOS_FROM_SYSTEM();
135
- after_cycles = GET_CURRENT_TIME_NANOS_CYCLECLOCK_NOW();
136
- // elapsed_cycles is unsigned, so is large on overflow
137
- elapsed_cycles = after_cycles - before_cycles;
138
- if (elapsed_cycles >= local_approx_syscall_time_in_cycles &&
139
- ++loops == 20) { // clock changed frequencies? Back off.
140
- loops = 0;
141
- if (local_approx_syscall_time_in_cycles < 1000 * 1000) {
142
- local_approx_syscall_time_in_cycles =
143
- (local_approx_syscall_time_in_cycles + 1) << 1;
144
- }
145
- approx_syscall_time_in_cycles.store(
146
- local_approx_syscall_time_in_cycles,
147
- std::memory_order_relaxed);
148
- }
149
- } while (elapsed_cycles >= local_approx_syscall_time_in_cycles ||
150
- last_cycleclock - after_cycles < (static_cast<uint64_t>(1) << 16));
151
-
152
- // Number of times in a row we've seen a kernel time call take substantially
153
- // less than approx_syscall_time_in_cycles.
154
- static std::atomic<uint32_t> seen_smaller{ 0 };
155
-
156
- // Adjust approx_syscall_time_in_cycles to be within a factor of 2
157
- // of the typical time to execute one iteration of the loop above.
158
- if ((local_approx_syscall_time_in_cycles >> 1) < elapsed_cycles) {
159
- // measured time is no smaller than half current approximation
160
- seen_smaller.store(0, std::memory_order_relaxed);
161
- } else if (seen_smaller.fetch_add(1, std::memory_order_relaxed) >= 3) {
162
- // smaller delays several times in a row; reduce approximation by 12.5%
163
- const uint64_t new_approximation =
164
- local_approx_syscall_time_in_cycles -
165
- (local_approx_syscall_time_in_cycles >> 3);
166
- approx_syscall_time_in_cycles.store(new_approximation,
167
- std::memory_order_relaxed);
168
- seen_smaller.store(0, std::memory_order_relaxed);
169
- }
170
-
171
- *cycleclock = after_cycles;
172
- return current_time_nanos_from_system;
173
- }
174
-
175
-
176
102
  // ---------------------------------------------------------------------
177
103
  // An implementation of reader-write locks that use no atomic ops in the read
178
104
  // case. This is a generalization of Lamport's method for reading a multiword
@@ -224,32 +150,110 @@ static_assert(((kMinNSBetweenSamples << (kScale + 1)) >> (kScale + 1)) ==
224
150
  kMinNSBetweenSamples,
225
151
  "cannot represent kMaxBetweenSamplesNSScaled");
226
152
 
227
- // A reader-writer lock protecting the static locations below.
228
- // See SeqAcquire() and SeqRelease() above.
229
- ABSL_CONST_INIT static absl::base_internal::SpinLock lock(
230
- absl::kConstInit, base_internal::SCHEDULE_KERNEL_ONLY);
231
- ABSL_CONST_INIT static std::atomic<uint64_t> seq(0);
232
-
233
153
  // data from a sample of the kernel's time value
234
154
  struct TimeSampleAtomic {
235
- std::atomic<uint64_t> raw_ns; // raw kernel time
236
- std::atomic<uint64_t> base_ns; // our estimate of time
237
- std::atomic<uint64_t> base_cycles; // cycle counter reading
238
- std::atomic<uint64_t> nsscaled_per_cycle; // cycle period
155
+ std::atomic<uint64_t> raw_ns{0}; // raw kernel time
156
+ std::atomic<uint64_t> base_ns{0}; // our estimate of time
157
+ std::atomic<uint64_t> base_cycles{0}; // cycle counter reading
158
+ std::atomic<uint64_t> nsscaled_per_cycle{0}; // cycle period
239
159
  // cycles before we'll sample again (a scaled reciprocal of the period,
240
160
  // to avoid a division on the fast path).
241
- std::atomic<uint64_t> min_cycles_per_sample;
161
+ std::atomic<uint64_t> min_cycles_per_sample{0};
242
162
  };
243
163
  // Same again, but with non-atomic types
244
164
  struct TimeSample {
245
- uint64_t raw_ns; // raw kernel time
246
- uint64_t base_ns; // our estimate of time
247
- uint64_t base_cycles; // cycle counter reading
248
- uint64_t nsscaled_per_cycle; // cycle period
249
- uint64_t min_cycles_per_sample; // approx cycles before next sample
165
+ uint64_t raw_ns = 0; // raw kernel time
166
+ uint64_t base_ns = 0; // our estimate of time
167
+ uint64_t base_cycles = 0; // cycle counter reading
168
+ uint64_t nsscaled_per_cycle = 0; // cycle period
169
+ uint64_t min_cycles_per_sample = 0; // approx cycles before next sample
250
170
  };
251
171
 
252
- static struct TimeSampleAtomic last_sample; // the last sample; under seq
172
+ struct ABSL_CACHELINE_ALIGNED TimeState {
173
+ std::atomic<uint64_t> seq{0};
174
+ TimeSampleAtomic last_sample; // the last sample; under seq
175
+
176
+ // The following counters are used only by the test code.
177
+ int64_t stats_initializations{0};
178
+ int64_t stats_reinitializations{0};
179
+ int64_t stats_calibrations{0};
180
+ int64_t stats_slow_paths{0};
181
+ int64_t stats_fast_slow_paths{0};
182
+
183
+ uint64_t last_now_cycles ABSL_GUARDED_BY(lock){0};
184
+
185
+ // Used by GetCurrentTimeNanosFromKernel().
186
+ // We try to read clock values at about the same time as the kernel clock.
187
+ // This value gets adjusted up or down as estimate of how long that should
188
+ // take, so we can reject attempts that take unusually long.
189
+ std::atomic<uint64_t> approx_syscall_time_in_cycles{10 * 1000};
190
+ // Number of times in a row we've seen a kernel time call take substantially
191
+ // less than approx_syscall_time_in_cycles.
192
+ std::atomic<uint32_t> kernel_time_seen_smaller{0};
193
+
194
+ // A reader-writer lock protecting the static locations below.
195
+ // See SeqAcquire() and SeqRelease() above.
196
+ absl::base_internal::SpinLock lock{absl::kConstInit,
197
+ base_internal::SCHEDULE_KERNEL_ONLY};
198
+ };
199
+ ABSL_CONST_INIT static TimeState time_state{};
200
+
201
+ // Return the time in ns as told by the kernel interface. Place in *cycleclock
202
+ // the value of the cycleclock at about the time of the syscall.
203
+ // This call represents the time base that this module synchronizes to.
204
+ // Ensures that *cycleclock does not step back by up to (1 << 16) from
205
+ // last_cycleclock, to discard small backward counter steps. (Larger steps are
206
+ // assumed to be complete resyncs, which shouldn't happen. If they do, a full
207
+ // reinitialization of the outer algorithm should occur.)
208
+ static int64_t GetCurrentTimeNanosFromKernel(uint64_t last_cycleclock,
209
+ uint64_t *cycleclock)
210
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(time_state.lock) {
211
+ uint64_t local_approx_syscall_time_in_cycles = // local copy
212
+ time_state.approx_syscall_time_in_cycles.load(std::memory_order_relaxed);
213
+
214
+ int64_t current_time_nanos_from_system;
215
+ uint64_t before_cycles;
216
+ uint64_t after_cycles;
217
+ uint64_t elapsed_cycles;
218
+ int loops = 0;
219
+ do {
220
+ before_cycles = GET_CURRENT_TIME_NANOS_CYCLECLOCK_NOW();
221
+ current_time_nanos_from_system = GET_CURRENT_TIME_NANOS_FROM_SYSTEM();
222
+ after_cycles = GET_CURRENT_TIME_NANOS_CYCLECLOCK_NOW();
223
+ // elapsed_cycles is unsigned, so is large on overflow
224
+ elapsed_cycles = after_cycles - before_cycles;
225
+ if (elapsed_cycles >= local_approx_syscall_time_in_cycles &&
226
+ ++loops == 20) { // clock changed frequencies? Back off.
227
+ loops = 0;
228
+ if (local_approx_syscall_time_in_cycles < 1000 * 1000) {
229
+ local_approx_syscall_time_in_cycles =
230
+ (local_approx_syscall_time_in_cycles + 1) << 1;
231
+ }
232
+ time_state.approx_syscall_time_in_cycles.store(
233
+ local_approx_syscall_time_in_cycles, std::memory_order_relaxed);
234
+ }
235
+ } while (elapsed_cycles >= local_approx_syscall_time_in_cycles ||
236
+ last_cycleclock - after_cycles < (static_cast<uint64_t>(1) << 16));
237
+
238
+ // Adjust approx_syscall_time_in_cycles to be within a factor of 2
239
+ // of the typical time to execute one iteration of the loop above.
240
+ if ((local_approx_syscall_time_in_cycles >> 1) < elapsed_cycles) {
241
+ // measured time is no smaller than half current approximation
242
+ time_state.kernel_time_seen_smaller.store(0, std::memory_order_relaxed);
243
+ } else if (time_state.kernel_time_seen_smaller.fetch_add(
244
+ 1, std::memory_order_relaxed) >= 3) {
245
+ // smaller delays several times in a row; reduce approximation by 12.5%
246
+ const uint64_t new_approximation =
247
+ local_approx_syscall_time_in_cycles -
248
+ (local_approx_syscall_time_in_cycles >> 3);
249
+ time_state.approx_syscall_time_in_cycles.store(new_approximation,
250
+ std::memory_order_relaxed);
251
+ time_state.kernel_time_seen_smaller.store(0, std::memory_order_relaxed);
252
+ }
253
+
254
+ *cycleclock = after_cycles;
255
+ return current_time_nanos_from_system;
256
+ }
253
257
 
254
258
  static int64_t GetCurrentTimeNanosSlowPath() ABSL_ATTRIBUTE_COLD;
255
259
 
@@ -317,14 +321,15 @@ int64_t GetCurrentTimeNanos() {
317
321
  // Acquire pairs with the barrier in SeqRelease - if this load sees that
318
322
  // store, the shared-data reads necessarily see that SeqRelease's updates
319
323
  // to the same shared data.
320
- seq_read0 = seq.load(std::memory_order_acquire);
324
+ seq_read0 = time_state.seq.load(std::memory_order_acquire);
321
325
 
322
- base_ns = last_sample.base_ns.load(std::memory_order_relaxed);
323
- base_cycles = last_sample.base_cycles.load(std::memory_order_relaxed);
326
+ base_ns = time_state.last_sample.base_ns.load(std::memory_order_relaxed);
327
+ base_cycles =
328
+ time_state.last_sample.base_cycles.load(std::memory_order_relaxed);
324
329
  nsscaled_per_cycle =
325
- last_sample.nsscaled_per_cycle.load(std::memory_order_relaxed);
326
- min_cycles_per_sample =
327
- last_sample.min_cycles_per_sample.load(std::memory_order_relaxed);
330
+ time_state.last_sample.nsscaled_per_cycle.load(std::memory_order_relaxed);
331
+ min_cycles_per_sample = time_state.last_sample.min_cycles_per_sample.load(
332
+ std::memory_order_relaxed);
328
333
 
329
334
  // This acquire fence pairs with the release fence in SeqAcquire. Since it
330
335
  // is sequenced between reads of shared data and seq_read1, the reads of
@@ -335,7 +340,7 @@ int64_t GetCurrentTimeNanos() {
335
340
  // shared-data writes are effectively release ordered. Therefore if our
336
341
  // shared-data reads see any of a particular update's shared-data writes,
337
342
  // seq_read1 is guaranteed to see that update's SeqAcquire.
338
- seq_read1 = seq.load(std::memory_order_relaxed);
343
+ seq_read1 = time_state.seq.load(std::memory_order_relaxed);
339
344
 
340
345
  // Fast path. Return if min_cycles_per_sample has not yet elapsed since the
341
346
  // last sample, and we read a consistent sample. The fast path activates
@@ -348,9 +353,9 @@ int64_t GetCurrentTimeNanos() {
348
353
  // last_sample was updated). This is harmless, because delta_cycles will wrap
349
354
  // and report a time much much bigger than min_cycles_per_sample. In that case
350
355
  // we will take the slow path.
351
- uint64_t delta_cycles = now_cycles - base_cycles;
356
+ uint64_t delta_cycles;
352
357
  if (seq_read0 == seq_read1 && (seq_read0 & 1) == 0 &&
353
- delta_cycles < min_cycles_per_sample) {
358
+ (delta_cycles = now_cycles - base_cycles) < min_cycles_per_sample) {
354
359
  return base_ns + ((delta_cycles * nsscaled_per_cycle) >> kScale);
355
360
  }
356
361
  return GetCurrentTimeNanosSlowPath();
@@ -390,24 +395,25 @@ static uint64_t UpdateLastSample(
390
395
  // TODO(absl-team): Remove this attribute when our compiler is smart enough
391
396
  // to do the right thing.
392
397
  ABSL_ATTRIBUTE_NOINLINE
393
- static int64_t GetCurrentTimeNanosSlowPath() ABSL_LOCKS_EXCLUDED(lock) {
398
+ static int64_t GetCurrentTimeNanosSlowPath()
399
+ ABSL_LOCKS_EXCLUDED(time_state.lock) {
394
400
  // Serialize access to slow-path. Fast-path readers are not blocked yet, and
395
401
  // code below must not modify last_sample until the seqlock is acquired.
396
- lock.Lock();
402
+ time_state.lock.Lock();
397
403
 
398
404
  // Sample the kernel time base. This is the definition of
399
405
  // "now" if we take the slow path.
400
- static uint64_t last_now_cycles; // protected by lock
401
406
  uint64_t now_cycles;
402
- uint64_t now_ns = GetCurrentTimeNanosFromKernel(last_now_cycles, &now_cycles);
403
- last_now_cycles = now_cycles;
407
+ uint64_t now_ns =
408
+ GetCurrentTimeNanosFromKernel(time_state.last_now_cycles, &now_cycles);
409
+ time_state.last_now_cycles = now_cycles;
404
410
 
405
411
  uint64_t estimated_base_ns;
406
412
 
407
413
  // ----------
408
414
  // Read the "last_sample" values again; this time holding the write lock.
409
415
  struct TimeSample sample;
410
- ReadTimeSampleAtomic(&last_sample, &sample);
416
+ ReadTimeSampleAtomic(&time_state.last_sample, &sample);
411
417
 
412
418
  // ----------
413
419
  // Try running the fast path again; another thread may have updated the
@@ -418,13 +424,13 @@ static int64_t GetCurrentTimeNanosSlowPath() ABSL_LOCKS_EXCLUDED(lock) {
418
424
  // so that blocked readers can make progress without blocking new readers.
419
425
  estimated_base_ns = sample.base_ns +
420
426
  ((delta_cycles * sample.nsscaled_per_cycle) >> kScale);
421
- stats_fast_slow_paths++;
427
+ time_state.stats_fast_slow_paths++;
422
428
  } else {
423
429
  estimated_base_ns =
424
430
  UpdateLastSample(now_cycles, now_ns, delta_cycles, &sample);
425
431
  }
426
432
 
427
- lock.Unlock();
433
+ time_state.lock.Unlock();
428
434
 
429
435
  return estimated_base_ns;
430
436
  }
@@ -435,9 +441,10 @@ static int64_t GetCurrentTimeNanosSlowPath() ABSL_LOCKS_EXCLUDED(lock) {
435
441
  static uint64_t UpdateLastSample(uint64_t now_cycles, uint64_t now_ns,
436
442
  uint64_t delta_cycles,
437
443
  const struct TimeSample *sample)
438
- ABSL_EXCLUSIVE_LOCKS_REQUIRED(lock) {
444
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(time_state.lock) {
439
445
  uint64_t estimated_base_ns = now_ns;
440
- uint64_t lock_value = SeqAcquire(&seq); // acquire seqlock to block readers
446
+ uint64_t lock_value =
447
+ SeqAcquire(&time_state.seq); // acquire seqlock to block readers
441
448
 
442
449
  // The 5s in the next if-statement limits the time for which we will trust
443
450
  // the cycle counter and our last sample to give a reasonable result.
@@ -447,12 +454,16 @@ static uint64_t UpdateLastSample(uint64_t now_cycles, uint64_t now_ns,
447
454
  sample->raw_ns + static_cast<uint64_t>(5) * 1000 * 1000 * 1000 < now_ns ||
448
455
  now_ns < sample->raw_ns || now_cycles < sample->base_cycles) {
449
456
  // record this sample, and forget any previously known slope.
450
- last_sample.raw_ns.store(now_ns, std::memory_order_relaxed);
451
- last_sample.base_ns.store(estimated_base_ns, std::memory_order_relaxed);
452
- last_sample.base_cycles.store(now_cycles, std::memory_order_relaxed);
453
- last_sample.nsscaled_per_cycle.store(0, std::memory_order_relaxed);
454
- last_sample.min_cycles_per_sample.store(0, std::memory_order_relaxed);
455
- stats_initializations++;
457
+ time_state.last_sample.raw_ns.store(now_ns, std::memory_order_relaxed);
458
+ time_state.last_sample.base_ns.store(estimated_base_ns,
459
+ std::memory_order_relaxed);
460
+ time_state.last_sample.base_cycles.store(now_cycles,
461
+ std::memory_order_relaxed);
462
+ time_state.last_sample.nsscaled_per_cycle.store(0,
463
+ std::memory_order_relaxed);
464
+ time_state.last_sample.min_cycles_per_sample.store(
465
+ 0, std::memory_order_relaxed);
466
+ time_state.stats_initializations++;
456
467
  } else if (sample->raw_ns + 500 * 1000 * 1000 < now_ns &&
457
468
  sample->base_cycles + 50 < now_cycles) {
458
469
  // Enough time has passed to compute the cycle time.
@@ -495,28 +506,32 @@ static uint64_t UpdateLastSample(uint64_t now_cycles, uint64_t now_ns,
495
506
  if (new_nsscaled_per_cycle != 0 &&
496
507
  diff_ns < 100 * 1000 * 1000 && -diff_ns < 100 * 1000 * 1000) {
497
508
  // record the cycle time measurement
498
- last_sample.nsscaled_per_cycle.store(
509
+ time_state.last_sample.nsscaled_per_cycle.store(
499
510
  new_nsscaled_per_cycle, std::memory_order_relaxed);
500
511
  uint64_t new_min_cycles_per_sample =
501
512
  SafeDivideAndScale(kMinNSBetweenSamples, new_nsscaled_per_cycle);
502
- last_sample.min_cycles_per_sample.store(
513
+ time_state.last_sample.min_cycles_per_sample.store(
503
514
  new_min_cycles_per_sample, std::memory_order_relaxed);
504
- stats_calibrations++;
515
+ time_state.stats_calibrations++;
505
516
  } else { // something went wrong; forget the slope
506
- last_sample.nsscaled_per_cycle.store(0, std::memory_order_relaxed);
507
- last_sample.min_cycles_per_sample.store(0, std::memory_order_relaxed);
517
+ time_state.last_sample.nsscaled_per_cycle.store(
518
+ 0, std::memory_order_relaxed);
519
+ time_state.last_sample.min_cycles_per_sample.store(
520
+ 0, std::memory_order_relaxed);
508
521
  estimated_base_ns = now_ns;
509
- stats_reinitializations++;
522
+ time_state.stats_reinitializations++;
510
523
  }
511
- last_sample.raw_ns.store(now_ns, std::memory_order_relaxed);
512
- last_sample.base_ns.store(estimated_base_ns, std::memory_order_relaxed);
513
- last_sample.base_cycles.store(now_cycles, std::memory_order_relaxed);
524
+ time_state.last_sample.raw_ns.store(now_ns, std::memory_order_relaxed);
525
+ time_state.last_sample.base_ns.store(estimated_base_ns,
526
+ std::memory_order_relaxed);
527
+ time_state.last_sample.base_cycles.store(now_cycles,
528
+ std::memory_order_relaxed);
514
529
  } else {
515
530
  // have a sample, but no slope; waiting for enough time for a calibration
516
- stats_slow_paths++;
531
+ time_state.stats_slow_paths++;
517
532
  }
518
533
 
519
- SeqRelease(&seq, lock_value); // release the readers
534
+ SeqRelease(&time_state.seq, lock_value); // release the readers
520
535
 
521
536
  return estimated_base_ns;
522
537
  }
@@ -558,7 +573,8 @@ ABSL_NAMESPACE_END
558
573
 
559
574
  extern "C" {
560
575
 
561
- ABSL_ATTRIBUTE_WEAK void AbslInternalSleepFor(absl::Duration duration) {
576
+ ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(
577
+ absl::Duration duration) {
562
578
  while (duration > absl::ZeroDuration()) {
563
579
  absl::Duration to_sleep = std::min(duration, absl::MaxSleep());
564
580
  absl::SleepOnce(to_sleep);