grpc 1.55.0 → 1.58.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +783 -492
- data/include/grpc/event_engine/event_engine.h +26 -36
- data/include/grpc/event_engine/memory_allocator.h +2 -2
- data/include/grpc/grpc_audit_logging.h +96 -0
- data/include/grpc/grpc_security.h +19 -0
- data/include/grpc/impl/channel_arg_names.h +371 -0
- data/include/grpc/impl/grpc_types.h +1 -350
- data/include/grpc/module.modulemap +3 -0
- data/include/grpc/support/json.h +218 -0
- data/include/grpc/support/port_platform.h +29 -23
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +6 -1
- data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +2 -1
- data/src/core/ext/filters/client_channel/backend_metric.cc +2 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +4 -4
- data/src/core/ext/filters/client_channel/client_channel.cc +137 -115
- data/src/core/ext/filters/client_channel/client_channel.h +6 -0
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +19 -18
- data/src/core/ext/filters/client_channel/client_channel_internal.h +16 -21
- data/src/core/ext/filters/client_channel/config_selector.h +9 -24
- data/src/core/ext/filters/client_channel/dynamic_filters.h +3 -3
- data/src/core/ext/filters/client_channel/http_proxy.cc +6 -1
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +27 -53
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +23 -9
- data/src/core/ext/filters/client_channel/lb_policy/backend_metric_data.h +3 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +25 -35
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +84 -136
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -1
- data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +480 -0
- data/src/core/ext/filters/client_channel/lb_policy/health_check_client.h +52 -0
- data/src/core/ext/filters/client_channel/lb_policy/health_check_client_internal.h +202 -0
- data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +6 -9
- data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric_internal.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +132 -74
- data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +9 -2
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +168 -104
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.h +20 -0
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +14 -43
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +22 -14
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +18 -1
- data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +33 -88
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +7 -5
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +57 -22
- data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/static_stride_scheduler.cc +76 -6
- data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +53 -43
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +17 -52
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +55 -114
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +8 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +32 -83
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +21 -67
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +62 -133
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +23 -62
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +24 -93
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +102 -11
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -37
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +4 -1
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_plugin.cc +6 -0
- data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +135 -73
- data/src/core/ext/filters/client_channel/resolver/dns/event_engine/service_config_helper.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +28 -27
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +10 -4
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +1 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +25 -13
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +428 -256
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +32 -1
- data/src/core/ext/filters/client_channel/retry_filter.cc +39 -2498
- data/src/core/ext/filters/client_channel/retry_filter.h +92 -1
- data/src/core/ext/filters/client_channel/retry_filter_legacy_call_data.cc +2052 -0
- data/src/core/ext/filters/client_channel/retry_filter_legacy_call_data.h +442 -0
- data/src/core/ext/filters/client_channel/retry_service_config.cc +2 -1
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +40 -90
- data/src/core/ext/filters/client_channel/subchannel.cc +17 -199
- data/src/core/ext/filters/client_channel/subchannel.h +14 -48
- data/src/core/ext/filters/client_channel/subchannel_interface_internal.h +3 -0
- data/src/core/ext/filters/deadline/deadline_filter.cc +1 -1
- data/src/core/ext/filters/http/client/http_client_filter.cc +1 -0
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +6 -5
- data/src/core/ext/filters/http/server/http_server_filter.cc +1 -1
- data/src/core/ext/filters/message_size/message_size_filter.cc +1 -0
- data/src/core/ext/filters/rbac/rbac_filter.cc +40 -111
- data/src/core/ext/filters/rbac/rbac_filter.h +12 -30
- data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +94 -3
- data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +6 -8
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +164 -88
- data/src/core/ext/filters/stateful_session/stateful_session_filter.h +16 -7
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +15 -16
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +463 -519
- data/src/core/ext/transport/chttp2/transport/decode_huff.cc +6569 -174
- data/src/core/ext/transport/chttp2/transport/decode_huff.h +2278 -441
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +46 -95
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +6 -20
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc +176 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +326 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +631 -547
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +157 -11
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +47 -33
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +19 -5
- data/src/core/ext/transport/chttp2/transport/internal.h +39 -76
- data/src/core/ext/transport/chttp2/transport/parsing.cc +43 -22
- data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.cc +80 -0
- data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.h +55 -0
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +98 -0
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.h +73 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +82 -91
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -0
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +27 -6
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +143 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +2 -9
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +0 -39
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +13 -8
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +35 -6
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +17 -13
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +85 -20
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +26 -7
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +45 -3
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.c +4 -3
- data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.h +21 -0
- data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c +30 -6
- data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.h +180 -0
- data/src/core/ext/upb-generated/envoy/data/accesslog/v3/accesslog.upb.c +558 -0
- data/src/core/ext/upb-generated/envoy/data/accesslog/v3/accesslog.upb.h +2710 -0
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +30 -11
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +53 -24
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +30 -5
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +110 -0
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +41 -15
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +150 -27
- data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/pick_first/v3/pick_first.upb.c +47 -0
- data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/pick_first/v3/pick_first.upb.h +93 -0
- data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.c +11 -2
- data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.h +15 -0
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +88 -76
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +11 -12
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +0 -5
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +162 -160
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +129 -118
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +141 -135
- data/src/core/ext/upbdefs-generated/envoy/config/metrics/v3/metrics_service.upbdefs.c +19 -12
- data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.c +38 -30
- data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/data/accesslog/v3/accesslog.upbdefs.c +402 -0
- data/src/core/ext/upbdefs-generated/envoy/data/accesslog/v3/accesslog.upbdefs.h +111 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +80 -74
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +63 -47
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +315 -293
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +29 -29
- data/src/core/ext/xds/certificate_provider_store.cc +4 -9
- data/src/core/ext/xds/certificate_provider_store.h +1 -1
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +30 -42
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +14 -9
- data/src/core/ext/xds/xds_api.cc +9 -6
- data/src/core/ext/xds/xds_api.h +3 -2
- data/src/core/ext/xds/xds_audit_logger_registry.cc +122 -0
- data/src/core/ext/xds/xds_audit_logger_registry.h +68 -0
- data/src/core/ext/xds/xds_bootstrap_grpc.cc +51 -36
- data/src/core/ext/xds/xds_bootstrap_grpc.h +10 -13
- data/src/core/ext/xds/xds_client.cc +5 -4
- data/src/core/ext/xds/xds_client_grpc.cc +12 -6
- data/src/core/ext/xds/xds_client_grpc.h +16 -2
- data/src/core/ext/xds/xds_client_stats.h +11 -1
- data/src/core/ext/xds/xds_cluster.cc +46 -35
- data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +11 -8
- data/src/core/ext/xds/xds_common_types.cc +3 -1
- data/src/core/ext/xds/xds_endpoint.cc +4 -7
- data/src/core/ext/xds/xds_health_status.cc +0 -17
- data/src/core/ext/xds/xds_health_status.h +5 -25
- data/src/core/ext/xds/xds_http_fault_filter.cc +14 -12
- data/src/core/ext/xds/xds_http_rbac_filter.cc +147 -65
- data/src/core/ext/xds/xds_http_stateful_session_filter.cc +13 -10
- data/src/core/ext/xds/xds_lb_policy_registry.cc +58 -16
- data/src/core/ext/xds/xds_listener.cc +1 -0
- data/src/core/ext/xds/xds_route_config.cc +44 -3
- data/src/core/ext/xds/xds_transport_grpc.cc +2 -1
- data/src/core/lib/address_utils/parse_address.cc +63 -1
- data/src/core/lib/address_utils/parse_address.h +8 -0
- data/src/core/lib/address_utils/sockaddr_utils.cc +46 -1
- data/src/core/lib/address_utils/sockaddr_utils.h +2 -2
- data/src/core/lib/avl/avl.h +15 -173
- data/src/core/lib/backoff/random_early_detection.h +5 -0
- data/src/core/lib/channel/call_tracer.cc +289 -0
- data/src/core/lib/channel/call_tracer.h +35 -0
- data/src/core/lib/channel/channel_args.cc +120 -46
- data/src/core/lib/channel/channel_args.h +52 -4
- data/src/core/lib/channel/channel_trace.cc +16 -12
- data/src/core/lib/channel/channelz.cc +159 -132
- data/src/core/lib/channel/channelz.h +42 -35
- data/src/core/lib/channel/channelz_registry.cc +23 -20
- data/src/core/lib/channel/connected_channel.cc +21 -8
- data/src/core/lib/channel/promise_based_filter.cc +4 -5
- data/src/core/lib/channel/promise_based_filter.h +3 -0
- data/src/core/lib/compression/compression_internal.cc +8 -7
- data/src/core/lib/config/config_vars.cc +20 -18
- data/src/core/lib/config/config_vars.h +4 -4
- data/src/core/lib/config/load_config.cc +13 -0
- data/src/core/lib/config/load_config.h +6 -0
- data/src/core/lib/debug/event_log.h +1 -1
- data/src/core/lib/debug/stats_data.cc +93 -21
- data/src/core/lib/debug/stats_data.h +42 -1
- data/src/core/lib/debug/trace.cc +21 -55
- data/src/core/lib/debug/trace.h +3 -1
- data/src/core/lib/event_engine/ares_resolver.cc +712 -0
- data/src/core/lib/event_engine/ares_resolver.h +150 -0
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +218 -0
- data/src/core/lib/event_engine/cf_engine/cf_engine.h +86 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +354 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +146 -0
- data/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h +79 -0
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +229 -0
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +117 -0
- data/src/core/lib/event_engine/default_event_engine.cc +13 -1
- data/src/core/lib/event_engine/default_event_engine_factory.cc +14 -2
- data/src/core/lib/event_engine/event_engine.cc +0 -12
- data/src/core/lib/event_engine/forkable.cc +62 -43
- data/src/core/lib/event_engine/forkable.h +15 -0
- data/src/core/lib/event_engine/grpc_polled_fd.h +73 -0
- data/src/core/lib/event_engine/handle_containers.h +0 -4
- data/src/core/lib/event_engine/poller.h +2 -2
- data/src/core/lib/event_engine/posix.h +4 -0
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +5 -7
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +29 -9
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +10 -1
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +197 -0
- data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +7 -18
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +28 -14
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +12 -1
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +82 -21
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +22 -14
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +70 -31
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +12 -8
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +4 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +43 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +6 -0
- data/src/core/lib/event_engine/posix_engine/timer.h +10 -37
- data/src/core/lib/event_engine/posix_engine/timer_manager.h +1 -1
- data/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +2 -0
- data/src/core/lib/event_engine/shim.cc +7 -1
- data/src/core/lib/event_engine/tcp_socket_utils.cc +67 -7
- data/src/core/lib/event_engine/tcp_socket_utils.h +3 -0
- data/src/core/lib/event_engine/{thread_pool.cc → thread_pool/original_thread_pool.cc} +28 -25
- data/src/core/lib/event_engine/{thread_pool.h → thread_pool/original_thread_pool.h} +11 -15
- data/src/core/lib/event_engine/thread_pool/thread_count.cc +58 -0
- data/src/core/lib/event_engine/thread_pool/thread_count.h +161 -0
- data/src/core/lib/event_engine/{executor/executor.h → thread_pool/thread_pool.h} +21 -9
- data/src/core/lib/event_engine/thread_pool/thread_pool_factory.cc +47 -0
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +517 -0
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +223 -0
- data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.cc +157 -0
- data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.h +104 -0
- data/src/core/lib/event_engine/windows/iocp.cc +4 -3
- data/src/core/lib/event_engine/windows/iocp.h +3 -3
- data/src/core/lib/event_engine/windows/win_socket.cc +6 -6
- data/src/core/lib/event_engine/windows/win_socket.h +4 -4
- data/src/core/lib/event_engine/windows/windows_endpoint.cc +60 -59
- data/src/core/lib/event_engine/windows/windows_endpoint.h +17 -13
- data/src/core/lib/event_engine/windows/windows_engine.cc +21 -18
- data/src/core/lib/event_engine/windows/windows_engine.h +14 -18
- data/src/core/lib/event_engine/windows/windows_listener.cc +3 -3
- data/src/core/lib/event_engine/windows/windows_listener.h +3 -2
- data/src/core/lib/event_engine/work_queue/basic_work_queue.cc +63 -0
- data/src/core/lib/event_engine/work_queue/basic_work_queue.h +71 -0
- data/src/core/lib/event_engine/work_queue/work_queue.h +62 -0
- data/src/core/lib/experiments/config.cc +112 -29
- data/src/core/lib/experiments/config.h +33 -5
- data/src/core/lib/experiments/experiments.cc +226 -64
- data/src/core/lib/experiments/experiments.h +93 -30
- data/src/core/lib/gpr/log_internal.h +55 -0
- data/src/core/lib/gprpp/crash.cc +10 -0
- data/src/core/lib/gprpp/crash.h +3 -0
- data/src/core/lib/gprpp/dual_ref_counted.h +9 -9
- data/src/core/lib/gprpp/fork.cc +8 -9
- data/src/core/lib/gprpp/fork.h +6 -5
- data/src/core/lib/gprpp/if_list.h +4530 -0
- data/src/core/lib/gprpp/orphanable.h +3 -3
- data/src/core/lib/gprpp/per_cpu.cc +33 -0
- data/src/core/lib/gprpp/per_cpu.h +29 -6
- data/src/core/lib/gprpp/ref_counted.h +9 -7
- data/src/core/lib/gprpp/ref_counted_string.cc +44 -0
- data/src/core/lib/gprpp/ref_counted_string.h +146 -0
- data/src/core/lib/gprpp/sorted_pack.h +3 -12
- data/src/core/lib/gprpp/status_helper.h +16 -15
- data/src/core/lib/gprpp/time.cc +1 -0
- data/src/core/lib/gprpp/time.h +13 -1
- data/src/core/lib/gprpp/type_list.h +32 -0
- data/src/core/lib/gprpp/work_serializer.cc +36 -0
- data/src/core/lib/gprpp/work_serializer.h +5 -0
- data/src/core/lib/http/httpcli.h +6 -9
- data/src/core/lib/http/httpcli_security_connector.cc +1 -0
- data/src/core/lib/iomgr/buffer_list.cc +2 -0
- data/src/core/lib/iomgr/cfstream_handle.cc +1 -1
- data/src/core/lib/iomgr/endpoint_cfstream.cc +10 -8
- data/src/core/lib/iomgr/error.cc +32 -2
- data/src/core/lib/iomgr/error.h +9 -10
- data/src/core/lib/iomgr/ev_apple.cc +12 -12
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +15 -10
- data/src/core/lib/iomgr/ev_poll_posix.cc +6 -5
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +22 -23
- data/src/core/lib/iomgr/exec_ctx.h +11 -0
- data/src/core/lib/iomgr/iocp_windows.cc +24 -3
- data/src/core/lib/iomgr/iocp_windows.h +11 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +1 -1
- data/src/core/lib/iomgr/pollset.h +4 -5
- data/src/core/lib/iomgr/port.h +10 -0
- data/src/core/lib/iomgr/resolve_address.cc +13 -1
- data/src/core/lib/iomgr/resolve_address.h +17 -3
- data/src/core/lib/iomgr/sockaddr_posix.h +7 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +33 -2
- data/src/core/lib/iomgr/socket_utils_posix.cc +2 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +6 -0
- data/src/core/lib/iomgr/socket_windows.cc +61 -7
- data/src/core/lib/iomgr/socket_windows.h +9 -2
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +14 -3
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +24 -7
- data/src/core/lib/iomgr/tcp_server_posix.cc +184 -120
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +13 -1
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +26 -2
- data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_windows.cc +1 -3
- data/src/core/lib/iomgr/vsock.cc +59 -0
- data/src/core/lib/iomgr/vsock.h +38 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.h +3 -6
- data/src/core/lib/json/json.h +2 -166
- data/src/core/lib/json/json_object_loader.cc +8 -9
- data/src/core/lib/json/json_object_loader.h +25 -18
- data/src/core/lib/json/json_reader.cc +13 -6
- data/src/core/lib/json/json_util.cc +6 -11
- data/src/core/lib/json/json_writer.cc +7 -8
- data/src/core/lib/load_balancing/delegating_helper.h +115 -0
- data/src/core/lib/load_balancing/lb_policy.h +33 -0
- data/src/core/lib/load_balancing/lb_policy_registry.cc +2 -1
- data/src/core/lib/load_balancing/subchannel_interface.h +6 -0
- data/src/core/lib/matchers/matchers.cc +3 -4
- data/src/core/lib/matchers/matchers.h +2 -1
- data/src/core/lib/promise/activity.cc +5 -0
- data/src/core/lib/promise/activity.h +10 -0
- data/src/core/lib/promise/detail/basic_seq.h +1 -372
- data/src/core/lib/promise/detail/promise_factory.h +1 -1
- data/src/core/lib/promise/detail/seq_state.h +2076 -0
- data/src/core/lib/promise/party.cc +31 -13
- data/src/core/lib/promise/party.h +12 -3
- data/src/core/lib/promise/pipe.h +9 -2
- data/src/core/lib/promise/prioritized_race.h +95 -0
- data/src/core/lib/promise/seq.h +19 -2
- data/src/core/lib/promise/sleep.cc +2 -1
- data/src/core/lib/promise/sleep.h +5 -10
- data/src/core/lib/promise/try_seq.h +34 -2
- data/src/core/lib/resolver/resolver_factory.h +3 -2
- data/src/core/lib/resolver/server_address.cc +9 -102
- data/src/core/lib/resolver/server_address.h +10 -70
- data/src/core/lib/resource_quota/api.cc +1 -0
- data/src/core/lib/resource_quota/arena.cc +2 -0
- data/src/core/lib/resource_quota/arena.h +42 -8
- data/src/core/lib/resource_quota/memory_quota.cc +7 -8
- data/src/core/lib/resource_quota/memory_quota.h +2 -3
- data/src/core/lib/resource_quota/resource_quota.h +1 -0
- data/src/core/lib/security/authorization/audit_logging.cc +98 -0
- data/src/core/lib/security/authorization/audit_logging.h +73 -0
- data/src/core/lib/security/authorization/authorization_policy_provider.h +1 -1
- data/src/core/lib/security/authorization/grpc_authorization_engine.cc +47 -2
- data/src/core/lib/security/authorization/grpc_authorization_engine.h +18 -1
- data/src/core/lib/security/authorization/rbac_policy.cc +36 -4
- data/src/core/lib/security/authorization/rbac_policy.h +19 -2
- data/src/core/lib/security/authorization/stdout_logger.cc +75 -0
- data/src/core/lib/security/authorization/stdout_logger.h +61 -0
- data/src/core/lib/security/certificate_provider/certificate_provider_factory.h +8 -4
- data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +8 -18
- data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +14 -8
- data/src/core/lib/security/credentials/channel_creds_registry.h +51 -27
- data/src/core/lib/security/credentials/channel_creds_registry_init.cc +169 -9
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +1 -1
- data/src/core/lib/security/credentials/composite/composite_credentials.h +3 -1
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +19 -12
- data/src/core/lib/security/credentials/external/aws_request_signer.cc +8 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +44 -3
- data/src/core/lib/security/credentials/external/external_account_credentials.h +6 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +1 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +1 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +30 -38
- data/src/core/lib/security/credentials/fake/fake_credentials.h +28 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +32 -14
- data/src/core/lib/security/credentials/jwt/json_token.h +4 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +4 -2
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +43 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +8 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +5 -1
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +2 -1
- data/src/core/lib/security/credentials/tls/tls_credentials.h +3 -1
- data/src/core/lib/security/credentials/xds/xds_credentials.cc +1 -0
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +2 -5
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -0
- data/src/core/lib/security/security_connector/ssl_utils.cc +3 -1
- data/src/core/lib/security/security_connector/ssl_utils.h +1 -1
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +1 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +8 -5
- data/src/core/lib/security/transport/security_handshaker.cc +1 -0
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -0
- data/src/core/lib/security/util/json_util.cc +1 -0
- data/src/core/lib/service_config/service_config_call_data.h +54 -20
- data/src/core/lib/service_config/service_config_impl.cc +2 -1
- data/src/core/lib/slice/slice.h +16 -0
- data/src/core/lib/surface/call.cc +100 -59
- data/src/core/lib/surface/channel.cc +1 -0
- data/src/core/lib/surface/completion_queue.cc +16 -2
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +67 -64
- data/src/core/lib/surface/server.h +1 -15
- data/src/core/lib/surface/validate_metadata.cc +37 -22
- data/src/core/lib/surface/validate_metadata.h +13 -3
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/batch_builder.cc +15 -12
- data/src/core/lib/transport/batch_builder.h +39 -35
- data/src/core/lib/transport/metadata_batch.cc +7 -7
- data/src/core/lib/transport/metadata_batch.h +86 -48
- data/src/core/lib/transport/parsed_metadata.h +34 -20
- data/src/core/lib/transport/simple_slice_based_metadata.h +9 -2
- data/src/core/plugin_registry/grpc_plugin_registry.cc +0 -2
- data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +2 -0
- data/src/core/tsi/alts/crypt/aes_gcm.cc +27 -2
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +4 -6
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -2
- data/src/core/tsi/ssl_transport_security.cc +44 -9
- data/src/core/tsi/ssl_transport_security.h +13 -1
- data/src/ruby/bin/math_pb.rb +24 -18
- data/src/ruby/ext/grpc/extconf.rb +27 -27
- data/src/ruby/ext/grpc/rb_call.c +62 -39
- data/src/ruby/ext/grpc/rb_call_credentials.c +0 -1
- data/src/ruby/ext/grpc/rb_channel.c +109 -84
- data/src/ruby/ext/grpc/rb_channel.h +1 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +16 -2
- data/src/ruby/ext/grpc/rb_channel_args.h +4 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +0 -1
- data/src/ruby/ext/grpc/rb_compression_options.c +0 -1
- data/src/ruby/ext/grpc/rb_event_thread.c +22 -6
- data/src/ruby/ext/grpc/rb_event_thread.h +1 -0
- data/src/ruby/ext/grpc/rb_grpc.c +192 -30
- data/src/ruby/ext/grpc/rb_grpc.h +8 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
- data/src/ruby/ext/grpc/rb_server.c +62 -45
- data/src/ruby/ext/grpc/rb_server_credentials.c +0 -1
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +0 -1
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +0 -1
- data/src/ruby/lib/grpc/generic/active_call.rb +9 -14
- data/src/ruby/lib/grpc/generic/bidi_call.rb +2 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +24 -13
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +24 -3
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +25 -111
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +25 -2
- data/src/ruby/pb/test/client.rb +16 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
- data/third_party/abseil-cpp/absl/algorithm/container.h +3 -2
- data/third_party/abseil-cpp/absl/base/attributes.h +58 -5
- data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
- data/third_party/abseil-cpp/absl/base/casts.h +8 -8
- data/third_party/abseil-cpp/absl/base/config.h +89 -106
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +26 -1
- data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +2 -2
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +50 -39
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +2 -1
- data/third_party/abseil-cpp/absl/base/internal/prefetch.h +17 -18
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +32 -3
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +24 -4
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +31 -73
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +9 -8
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +11 -11
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +23 -32
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +2 -3
- data/third_party/abseil-cpp/absl/base/options.h +1 -1
- data/third_party/abseil-cpp/absl/base/policy_checks.h +3 -3
- data/third_party/abseil-cpp/absl/base/prefetch.h +198 -0
- data/third_party/abseil-cpp/absl/container/fixed_array.h +54 -29
- data/third_party/abseil-cpp/absl/container/flat_hash_map.h +5 -1
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +6 -2
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +167 -79
- data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -1
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +3 -21
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +1 -1
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +46 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +85 -26
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +35 -18
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +70 -29
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +437 -236
- data/third_party/abseil-cpp/absl/crc/crc32c.h +8 -1
- data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +14 -8
- data/third_party/abseil-cpp/absl/crc/internal/crc.cc +4 -35
- data/third_party/abseil-cpp/absl/crc/internal/crc.h +2 -10
- data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +1 -1
- data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.cc +1 -1
- data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.h +4 -4
- data/third_party/abseil-cpp/absl/crc/internal/crc_internal.h +8 -10
- data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy_x86_64.cc +17 -19
- data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +8 -8
- data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +2 -1
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +59 -23
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +1 -1
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +1 -1
- data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +1 -1
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +43 -19
- data/third_party/abseil-cpp/absl/debugging/symbolize_emscripten.inc +3 -0
- data/third_party/abseil-cpp/absl/flags/commandlineflag.h +1 -1
- data/third_party/abseil-cpp/absl/flags/internal/commandlineflag.cc +1 -1
- data/third_party/abseil-cpp/absl/flags/internal/flag.cc +2 -2
- data/third_party/abseil-cpp/absl/flags/internal/flag.h +16 -15
- data/third_party/abseil-cpp/absl/flags/internal/flag_msvc.inc +1 -1
- data/third_party/abseil-cpp/absl/flags/marshalling.cc +43 -2
- data/third_party/abseil-cpp/absl/flags/marshalling.h +5 -0
- data/third_party/abseil-cpp/absl/functional/any_invocable.h +9 -1
- data/third_party/abseil-cpp/absl/functional/bind_front.h +1 -1
- data/third_party/abseil-cpp/absl/functional/function_ref.h +3 -3
- data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +37 -24
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +19 -9
- data/third_party/abseil-cpp/absl/hash/hash.h +7 -4
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +38 -15
- data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +6 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +48 -373
- data/third_party/abseil-cpp/absl/numeric/bits.h +4 -4
- data/third_party/abseil-cpp/absl/numeric/int128.cc +20 -8
- data/third_party/abseil-cpp/absl/numeric/int128.h +36 -39
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +0 -3
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +47 -30
- data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +4 -3
- data/third_party/abseil-cpp/absl/random/internal/generate_real.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/platform.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +4 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +1 -1
- data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +1 -1
- data/third_party/abseil-cpp/absl/status/internal/status_internal.h +4 -0
- data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +12 -24
- data/third_party/abseil-cpp/absl/status/status.cc +11 -7
- data/third_party/abseil-cpp/absl/status/status.h +11 -2
- data/third_party/abseil-cpp/absl/status/statusor.h +22 -8
- data/third_party/abseil-cpp/absl/strings/ascii.cc +54 -6
- data/third_party/abseil-cpp/absl/strings/charconv.cc +21 -4
- data/third_party/abseil-cpp/absl/strings/charconv.h +2 -2
- data/third_party/abseil-cpp/absl/strings/cord.cc +1 -2
- data/third_party/abseil-cpp/absl/strings/cord.h +32 -5
- data/third_party/abseil-cpp/absl/strings/cord_analysis.cc +23 -1
- data/third_party/abseil-cpp/absl/strings/cord_analysis.h +18 -0
- data/third_party/abseil-cpp/absl/strings/cord_buffer.h +2 -5
- data/third_party/abseil-cpp/absl/strings/escaping.cc +10 -32
- data/third_party/abseil-cpp/absl/strings/escaping.h +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +2 -4
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +3 -3
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +0 -1
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +15 -13
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.cc +13 -4
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.h +8 -0
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.cc +5 -3
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.h +4 -7
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +8 -0
- data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.cc +46 -20
- data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.h +1 -34
- data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +2 -1
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +23 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +1 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +2 -77
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +4 -112
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +10 -31
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +8 -8
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +5 -20
- data/third_party/abseil-cpp/absl/strings/internal/str_format/constexpr_parser.h +1 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +9 -9
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +56 -6
- data/third_party/abseil-cpp/absl/strings/match.cc +87 -0
- data/third_party/abseil-cpp/absl/strings/match.h +19 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +154 -122
- data/third_party/abseil-cpp/absl/strings/numbers.h +1 -6
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +7 -50
- data/third_party/abseil-cpp/absl/strings/str_cat.h +83 -15
- data/third_party/abseil-cpp/absl/strings/str_format.h +6 -3
- data/third_party/abseil-cpp/absl/strings/str_split.cc +9 -6
- data/third_party/abseil-cpp/absl/strings/string_view.cc +26 -4
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +5 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +63 -43
- data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.cc +111 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.h +63 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +11 -7
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.cc +225 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +122 -114
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +12 -8
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +10 -1
- data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.cc +167 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.h +60 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.cc +122 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.h +65 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.cc +91 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.h +56 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +19 -113
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.cc +42 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.h +90 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.cc +151 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.h +70 -0
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +407 -411
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +152 -118
- data/third_party/abseil-cpp/absl/time/clock.cc +6 -7
- data/third_party/abseil-cpp/absl/time/duration.cc +24 -26
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +1 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +3 -3
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +8 -6
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +6 -3
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +4 -2
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +4 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +322 -295
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +8 -17
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +51 -33
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +7 -2
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +128 -2
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +5 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +34 -34
- data/third_party/abseil-cpp/absl/time/time.cc +9 -2
- data/third_party/abseil-cpp/absl/time/time.h +115 -15
- data/third_party/abseil-cpp/absl/types/internal/optional.h +0 -52
- data/third_party/abseil-cpp/absl/types/internal/span.h +2 -2
- data/third_party/abseil-cpp/absl/types/internal/variant.h +2 -2
- data/third_party/abseil-cpp/absl/types/optional.h +15 -13
- data/third_party/abseil-cpp/absl/types/span.h +1 -2
- data/third_party/boringssl-with-bazel/err_data.c +554 -553
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +7 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_mbstr.c +9 -8
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strex.c +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strnid.c +6 -6
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +34 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +11 -4
- data/third_party/boringssl-with-bazel/src/crypto/asn1/internal.h +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +10 -6
- data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +7 -4
- data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +9 -7
- data/third_party/boringssl-with-bazel/src/crypto/bio/bio_mem.c +7 -8
- data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/bio/errno.c +92 -0
- data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +7 -50
- data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +23 -22
- data/third_party/boringssl-with-bazel/src/crypto/bio/internal.h +16 -6
- data/third_party/boringssl-with-bazel/src/crypto/bio/pair.c +4 -2
- data/third_party/boringssl-with-bazel/src/crypto/bio/socket.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c +11 -2
- data/third_party/boringssl-with-bazel/src/crypto/blake2/blake2.c +31 -22
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/chacha/chacha.c +19 -1
- data/third_party/boringssl-with-bazel/src/crypto/chacha/internal.h +8 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_tls.c +29 -26
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +8 -0
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +189 -13
- data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +31 -192
- data/third_party/boringssl-with-bazel/src/crypto/conf/conf_def.h +3 -7
- data/third_party/boringssl-with-bazel/src/crypto/conf/internal.h +8 -0
- data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_apple.c +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_fuchsia.c +0 -1
- data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_linux.c +0 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_freebsd.c → cpu_aarch64_openbsd.c} +23 -24
- data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_sysreg.c +93 -0
- data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_win.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_freebsd.c +0 -1
- data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.c +0 -2
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +55 -50
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_arm.c → curve25519/curve25519_64_adx.c} +4 -24
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519_tables.h +2834 -7442
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +26 -8
- data/third_party/boringssl-with-bazel/src/crypto/dh_extra/dh_asn1.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/dh_extra/params.c +5 -0
- data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +20 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/ec_asn1.c +110 -72
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/ec_derive.c +4 -3
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +42 -34
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +17 -11
- data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/err/err.c +23 -21
- data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +35 -12
- data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec.c +2 -4
- data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec_asn1.c +3 -7
- data/third_party/boringssl-with-bazel/src/crypto/evp/p_rsa.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/evp/pbkdf.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/evp/print.c +7 -6
- data/third_party/boringssl-with-bazel/src/crypto/ex_data.c +34 -72
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.c +12 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd.c +5 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +12 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +17 -18
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery_inv.c +51 -15
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/rsaz_exp.c +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/delocate.h +5 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/check.c +37 -8
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.c +41 -19
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/internal.h +9 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/builtin_curves.h +277 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +204 -428
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +31 -64
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +17 -13
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +105 -143
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +19 -19
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +16 -18
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-nistz.c +27 -30
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +23 -26
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +24 -24
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +21 -37
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +31 -31
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +16 -16
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +11 -5
- data/third_party/boringssl-with-bazel/src/crypto/{hkdf → fipsmodule/hkdf}/hkdf.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cbc.c +2 -10
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ctr.c +1 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm.c +115 -133
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm_nohw.c +12 -14
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +57 -47
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ofb.c +1 -8
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/polyval.c +27 -28
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +40 -26
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +21 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +38 -19
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +2 -41
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +76 -16
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/padding.c +5 -288
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +143 -83
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +126 -233
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +113 -24
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/service_indicator/service_indicator.c +4 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/internal.h +8 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/kdf.c +33 -0
- data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +169 -6
- data/third_party/boringssl-with-bazel/src/crypto/internal.h +216 -87
- data/third_party/boringssl-with-bazel/src/crypto/kyber/kyber.c +23 -15
- data/third_party/boringssl-with-bazel/src/crypto/mem.c +7 -8
- data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +25 -46
- data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +6 -13
- data/third_party/boringssl-with-bazel/src/crypto/pem/pem_lib.c +18 -14
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/p5_pbev2.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +8 -5
- data/third_party/boringssl-with-bazel/src/crypto/pool/internal.h +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +7 -6
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/forkunsafe.c +6 -12
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/getentropy.c +52 -0
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{fuchsia.c → ios.c} +8 -8
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/trusty.c +38 -0
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +41 -19
- data/third_party/boringssl-with-bazel/src/crypto/{refcount_c11.c → refcount.c} +11 -17
- data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/internal.h +77 -0
- data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_crypt.c +568 -0
- data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +152 -72
- data/third_party/boringssl-with-bazel/src/crypto/thread_none.c +0 -8
- data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +6 -35
- data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +5 -26
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +62 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +230 -60
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +35 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +580 -120
- data/third_party/boringssl-with-bazel/src/crypto/x509/a_sign.c +27 -18
- data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +8 -19
- data/third_party/boringssl-with-bazel/src/crypto/x509/by_file.c +0 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/name_print.c +17 -39
- data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +39 -48
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +1 -141
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_d2.c +1 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_lu.c +2 -4
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +72 -23
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +8 -12
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +19 -20
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +22 -29
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509spki.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +5 -5
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +2 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +33 -46
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +3 -5
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_lib.c +16 -49
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +14 -26
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +4 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +17 -10
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +5 -7
- data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +4 -119
- data/third_party/boringssl-with-bazel/src/include/openssl/asm_base.h +207 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +11 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +37 -112
- data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +11 -5
- data/third_party/boringssl-with-bazel/src/include/openssl/blake2.h +1 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/bn.h +0 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +6 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/conf.h +5 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +4 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +0 -21
- data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +28 -11
- data/third_party/boringssl-with-bazel/src/include/openssl/ec_key.h +19 -6
- data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +14 -10
- data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +34 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +2 -11
- data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +0 -3
- data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +13 -14
- data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +91 -62
- data/third_party/boringssl-with-bazel/src/include/openssl/span.h +26 -19
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +275 -96
- data/third_party/boringssl-with-bazel/src/include/openssl/stack.h +236 -213
- data/third_party/boringssl-with-bazel/src/include/openssl/target.h +201 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/thread.h +1 -25
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +8 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +758 -603
- data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +45 -12
- data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +11 -6
- data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +10 -68
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +20 -20
- data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +24 -16
- data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +69 -29
- data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +37 -18
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +209 -209
- data/third_party/boringssl-with-bazel/src/ssl/ssl_file.cc +4 -4
- data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +46 -155
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +209 -33
- data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +17 -4
- data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +27 -19
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +2 -3
- data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +5 -21
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +5 -2
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_adx.h +691 -0
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_msvc.h +1281 -0
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64_msvc.h +2002 -0
- data/third_party/cares/cares/include/ares.h +23 -1
- data/third_party/cares/cares/{src/lib → include}/ares_nameser.h +9 -7
- data/third_party/cares/cares/include/ares_rules.h +2 -2
- data/third_party/cares/cares/include/ares_version.h +3 -3
- data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +266 -0
- data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +240 -0
- data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +49 -80
- data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +37 -43
- data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +12 -4
- data/third_party/cares/cares/src/lib/ares_data.c +16 -0
- data/third_party/cares/cares/src/lib/ares_data.h +7 -0
- data/third_party/cares/cares/src/lib/ares_destroy.c +8 -0
- data/third_party/cares/cares/src/lib/ares_expand_name.c +17 -6
- data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +1 -0
- data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +156 -78
- data/third_party/cares/cares/src/lib/ares_gethostbyname.c +130 -326
- data/third_party/cares/cares/src/lib/ares_init.c +97 -485
- data/third_party/cares/cares/src/lib/ares_library_init.c +2 -89
- data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +23 -142
- data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +22 -142
- data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +184 -0
- data/third_party/cares/cares/src/lib/ares_private.h +30 -16
- data/third_party/cares/cares/src/lib/ares_process.c +55 -16
- data/third_party/cares/cares/src/lib/ares_query.c +1 -35
- data/third_party/cares/cares/src/lib/ares_rand.c +279 -0
- data/third_party/cares/cares/src/lib/ares_send.c +5 -7
- data/third_party/cares/cares/src/lib/ares_strdup.c +12 -19
- data/third_party/cares/cares/src/lib/ares_strsplit.c +44 -128
- data/third_party/cares/cares/src/lib/ares_strsplit.h +9 -10
- data/third_party/cares/cares/src/lib/inet_net_pton.c +78 -116
- data/third_party/cares/cares/src/tools/ares_getopt.h +53 -0
- data/third_party/upb/upb/collections/map.c +3 -3
- metadata +106 -45
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +0 -175
- data/src/core/ext/filters/client_channel/health/health_check_client.h +0 -43
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc +0 -42
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h +0 -64
- data/src/core/ext/transport/chttp2/transport/stream_map.cc +0 -177
- data/src/core/ext/transport/chttp2/transport/stream_map.h +0 -68
- data/src/core/lib/promise/detail/basic_join.h +0 -197
- data/src/core/lib/promise/detail/switch.h +0 -1455
- data/src/core/lib/promise/try_join.h +0 -82
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +0 -403
- data/third_party/boringssl-with-bazel/src/crypto/refcount_lock.c +0 -52
- data/third_party/cares/cares/src/lib/ares_library_init.h +0 -43
- data/third_party/re2/util/benchmark.h +0 -156
- data/third_party/re2/util/flags.h +0 -26
- data/third_party/re2/util/malloc_counter.h +0 -19
- data/third_party/re2/util/pcre.cc +0 -1025
- data/third_party/re2/util/pcre.h +0 -681
- data/third_party/re2/util/test.h +0 -50
- data/third_party/upb/upb/mini_table.h +0 -36
- data/third_party/zlib/gzclose.c +0 -25
- data/third_party/zlib/gzlib.c +0 -639
- data/third_party/zlib/gzread.c +0 -650
- data/third_party/zlib/gzwrite.c +0 -677
@@ -35,10 +35,9 @@
|
|
35
35
|
|
36
36
|
#include <algorithm>
|
37
37
|
#include <atomic>
|
38
|
-
#include <cinttypes>
|
39
38
|
#include <cstddef>
|
39
|
+
#include <cstdlib>
|
40
40
|
#include <cstring>
|
41
|
-
#include <iterator>
|
42
41
|
#include <thread> // NOLINT(build/c++11)
|
43
42
|
|
44
43
|
#include "absl/base/attributes.h"
|
@@ -55,7 +54,6 @@
|
|
55
54
|
#include "absl/base/internal/thread_identity.h"
|
56
55
|
#include "absl/base/internal/tsan_mutex_interface.h"
|
57
56
|
#include "absl/base/optimization.h"
|
58
|
-
#include "absl/base/port.h"
|
59
57
|
#include "absl/debugging/stacktrace.h"
|
60
58
|
#include "absl/debugging/symbolize.h"
|
61
59
|
#include "absl/synchronization/internal/graphcycles.h"
|
@@ -63,6 +61,7 @@
|
|
63
61
|
#include "absl/time/time.h"
|
64
62
|
|
65
63
|
using absl::base_internal::CurrentThreadIdentityIfPresent;
|
64
|
+
using absl::base_internal::CycleClock;
|
66
65
|
using absl::base_internal::PerThreadSynch;
|
67
66
|
using absl::base_internal::SchedulingGuard;
|
68
67
|
using absl::base_internal::ThreadIdentity;
|
@@ -98,18 +97,15 @@ ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
|
|
98
97
|
absl::base_internal::AtomicHook<void (*)(int64_t wait_cycles)>
|
99
98
|
submit_profile_data;
|
100
99
|
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES absl::base_internal::AtomicHook<void (*)(
|
101
|
-
const char
|
100
|
+
const char* msg, const void* obj, int64_t wait_cycles)>
|
102
101
|
mutex_tracer;
|
103
102
|
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
|
104
|
-
|
105
|
-
|
106
|
-
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES absl::base_internal::AtomicHook<
|
107
|
-
bool (*)(const void *pc, char *out, int out_size)>
|
108
|
-
symbolizer(absl::Symbolize);
|
103
|
+
absl::base_internal::AtomicHook<void (*)(const char* msg, const void* cv)>
|
104
|
+
cond_var_tracer;
|
109
105
|
|
110
106
|
} // namespace
|
111
107
|
|
112
|
-
static inline bool EvalConditionAnnotated(const Condition
|
108
|
+
static inline bool EvalConditionAnnotated(const Condition* cond, Mutex* mu,
|
113
109
|
bool locking, bool trylock,
|
114
110
|
bool read_lock);
|
115
111
|
|
@@ -117,19 +113,15 @@ void RegisterMutexProfiler(void (*fn)(int64_t wait_cycles)) {
|
|
117
113
|
submit_profile_data.Store(fn);
|
118
114
|
}
|
119
115
|
|
120
|
-
void RegisterMutexTracer(void (*fn)(const char
|
116
|
+
void RegisterMutexTracer(void (*fn)(const char* msg, const void* obj,
|
121
117
|
int64_t wait_cycles)) {
|
122
118
|
mutex_tracer.Store(fn);
|
123
119
|
}
|
124
120
|
|
125
|
-
void RegisterCondVarTracer(void (*fn)(const char
|
121
|
+
void RegisterCondVarTracer(void (*fn)(const char* msg, const void* cv)) {
|
126
122
|
cond_var_tracer.Store(fn);
|
127
123
|
}
|
128
124
|
|
129
|
-
void RegisterSymbolizer(bool (*fn)(const void *pc, char *out, int out_size)) {
|
130
|
-
symbolizer.Store(fn);
|
131
|
-
}
|
132
|
-
|
133
125
|
namespace {
|
134
126
|
// Represents the strategy for spin and yield.
|
135
127
|
// See the comment in GetMutexGlobals() for more information.
|
@@ -148,25 +140,24 @@ absl::Duration MeasureTimeToYield() {
|
|
148
140
|
return absl::Now() - before;
|
149
141
|
}
|
150
142
|
|
151
|
-
const MutexGlobals
|
143
|
+
const MutexGlobals& GetMutexGlobals() {
|
152
144
|
ABSL_CONST_INIT static MutexGlobals data;
|
153
145
|
absl::base_internal::LowLevelCallOnce(&data.once, [&]() {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
// aggressive then spin many times before yielding. If the mode is
|
162
|
-
// gentle then spin only a few times before yielding. Aggressive spinning
|
163
|
-
// is used to ensure that an Unlock() call, which must get the spin lock
|
164
|
-
// for any thread to make progress gets it without undue delay.
|
165
|
-
if (num_cpus > 1) {
|
146
|
+
if (absl::base_internal::NumCPUs() > 1) {
|
147
|
+
// If this is multiprocessor, allow spinning. If the mode is
|
148
|
+
// aggressive then spin many times before yielding. If the mode is
|
149
|
+
// gentle then spin only a few times before yielding. Aggressive spinning
|
150
|
+
// is used to ensure that an Unlock() call, which must get the spin lock
|
151
|
+
// for any thread to make progress gets it without undue delay.
|
152
|
+
data.spinloop_iterations = 1500;
|
166
153
|
data.mutex_sleep_spins[AGGRESSIVE] = 5000;
|
167
154
|
data.mutex_sleep_spins[GENTLE] = 250;
|
168
155
|
data.mutex_sleep_time = absl::Microseconds(10);
|
169
156
|
} else {
|
157
|
+
// If this a uniprocessor, only yield/sleep. Real-time threads are often
|
158
|
+
// unable to yield, so the sleep time needs to be long enough to keep
|
159
|
+
// the calling thread asleep until scheduling happens.
|
160
|
+
data.spinloop_iterations = 0;
|
170
161
|
data.mutex_sleep_spins[AGGRESSIVE] = 0;
|
171
162
|
data.mutex_sleep_spins[GENTLE] = 0;
|
172
163
|
data.mutex_sleep_time = MeasureTimeToYield() * 5;
|
@@ -219,8 +210,7 @@ static void AtomicSetBits(std::atomic<intptr_t>* pv, intptr_t bits,
|
|
219
210
|
v = pv->load(std::memory_order_relaxed);
|
220
211
|
} while ((v & bits) != bits &&
|
221
212
|
((v & wait_until_clear) != 0 ||
|
222
|
-
!pv->compare_exchange_weak(v, v | bits,
|
223
|
-
std::memory_order_release,
|
213
|
+
!pv->compare_exchange_weak(v, v | bits, std::memory_order_release,
|
224
214
|
std::memory_order_relaxed)));
|
225
215
|
}
|
226
216
|
|
@@ -235,8 +225,7 @@ static void AtomicClearBits(std::atomic<intptr_t>* pv, intptr_t bits,
|
|
235
225
|
v = pv->load(std::memory_order_relaxed);
|
236
226
|
} while ((v & bits) != 0 &&
|
237
227
|
((v & wait_until_clear) != 0 ||
|
238
|
-
!pv->compare_exchange_weak(v, v & ~bits,
|
239
|
-
std::memory_order_release,
|
228
|
+
!pv->compare_exchange_weak(v, v & ~bits, std::memory_order_release,
|
240
229
|
std::memory_order_relaxed)));
|
241
230
|
}
|
242
231
|
|
@@ -247,7 +236,7 @@ ABSL_CONST_INIT static absl::base_internal::SpinLock deadlock_graph_mu(
|
|
247
236
|
absl::kConstInit, base_internal::SCHEDULE_KERNEL_ONLY);
|
248
237
|
|
249
238
|
// Graph used to detect deadlocks.
|
250
|
-
ABSL_CONST_INIT static GraphCycles
|
239
|
+
ABSL_CONST_INIT static GraphCycles* deadlock_graph
|
251
240
|
ABSL_GUARDED_BY(deadlock_graph_mu) ABSL_PT_GUARDED_BY(deadlock_graph_mu);
|
252
241
|
|
253
242
|
//------------------------------------------------------------------
|
@@ -291,7 +280,7 @@ enum { // Event flags
|
|
291
280
|
// Properties of the events.
|
292
281
|
static const struct {
|
293
282
|
int flags;
|
294
|
-
const char
|
283
|
+
const char* msg;
|
295
284
|
} event_properties[] = {
|
296
285
|
{SYNCH_F_LCK_W | SYNCH_F_TRY, "TryLock succeeded "},
|
297
286
|
{0, "TryLock failed "},
|
@@ -316,12 +305,12 @@ ABSL_CONST_INIT static absl::base_internal::SpinLock synch_event_mu(
|
|
316
305
|
// Can't be too small, as it's used for deadlock detection information.
|
317
306
|
static constexpr uint32_t kNSynchEvent = 1031;
|
318
307
|
|
319
|
-
static struct SynchEvent {
|
308
|
+
static struct SynchEvent { // this is a trivial hash table for the events
|
320
309
|
// struct is freed when refcount reaches 0
|
321
310
|
int refcount ABSL_GUARDED_BY(synch_event_mu);
|
322
311
|
|
323
312
|
// buckets have linear, 0-terminated chains
|
324
|
-
SynchEvent
|
313
|
+
SynchEvent* next ABSL_GUARDED_BY(synch_event_mu);
|
325
314
|
|
326
315
|
// Constant after initialization
|
327
316
|
uintptr_t masked_addr; // object at this address is called "name"
|
@@ -329,13 +318,13 @@ static struct SynchEvent { // this is a trivial hash table for the events
|
|
329
318
|
// No explicit synchronization used. Instead we assume that the
|
330
319
|
// client who enables/disables invariants/logging on a Mutex does so
|
331
320
|
// while the Mutex is not being concurrently accessed by others.
|
332
|
-
void (*invariant)(void
|
333
|
-
void
|
334
|
-
bool log;
|
321
|
+
void (*invariant)(void* arg); // called on each event
|
322
|
+
void* arg; // first arg to (*invariant)()
|
323
|
+
bool log; // logging turned on
|
335
324
|
|
336
325
|
// Constant after initialization
|
337
|
-
char name[1];
|
338
|
-
}
|
326
|
+
char name[1]; // actually longer---NUL-terminated string
|
327
|
+
}* synch_event[kNSynchEvent] ABSL_GUARDED_BY(synch_event_mu);
|
339
328
|
|
340
329
|
// Ensure that the object at "addr" has a SynchEvent struct associated with it,
|
341
330
|
// set "bits" in the word there (waiting until lockbit is clear before doing
|
@@ -344,11 +333,11 @@ static struct SynchEvent { // this is a trivial hash table for the events
|
|
344
333
|
// the string name is copied into it.
|
345
334
|
// When used with a mutex, the caller should also ensure that kMuEvent
|
346
335
|
// is set in the mutex word, and similarly for condition variables and kCVEvent.
|
347
|
-
static SynchEvent
|
348
|
-
const char
|
336
|
+
static SynchEvent* EnsureSynchEvent(std::atomic<intptr_t>* addr,
|
337
|
+
const char* name, intptr_t bits,
|
349
338
|
intptr_t lockbit) {
|
350
339
|
uint32_t h = reinterpret_cast<uintptr_t>(addr) % kNSynchEvent;
|
351
|
-
SynchEvent
|
340
|
+
SynchEvent* e;
|
352
341
|
// first look for existing SynchEvent struct..
|
353
342
|
synch_event_mu.Lock();
|
354
343
|
for (e = synch_event[h];
|
@@ -360,9 +349,9 @@ static SynchEvent *EnsureSynchEvent(std::atomic<intptr_t> *addr,
|
|
360
349
|
name = "";
|
361
350
|
}
|
362
351
|
size_t l = strlen(name);
|
363
|
-
e = reinterpret_cast<SynchEvent
|
352
|
+
e = reinterpret_cast<SynchEvent*>(
|
364
353
|
base_internal::LowLevelAlloc::Alloc(sizeof(*e) + l));
|
365
|
-
e->refcount = 2;
|
354
|
+
e->refcount = 2; // one for return value, one for linked list
|
366
355
|
e->masked_addr = base_internal::HidePtr(addr);
|
367
356
|
e->invariant = nullptr;
|
368
357
|
e->arg = nullptr;
|
@@ -372,19 +361,19 @@ static SynchEvent *EnsureSynchEvent(std::atomic<intptr_t> *addr,
|
|
372
361
|
AtomicSetBits(addr, bits, lockbit);
|
373
362
|
synch_event[h] = e;
|
374
363
|
} else {
|
375
|
-
e->refcount++;
|
364
|
+
e->refcount++; // for return value
|
376
365
|
}
|
377
366
|
synch_event_mu.Unlock();
|
378
367
|
return e;
|
379
368
|
}
|
380
369
|
|
381
370
|
// Deallocate the SynchEvent *e, whose refcount has fallen to zero.
|
382
|
-
static void DeleteSynchEvent(SynchEvent
|
371
|
+
static void DeleteSynchEvent(SynchEvent* e) {
|
383
372
|
base_internal::LowLevelAlloc::Free(e);
|
384
373
|
}
|
385
374
|
|
386
375
|
// Decrement the reference count of *e, or do nothing if e==null.
|
387
|
-
static void UnrefSynchEvent(SynchEvent
|
376
|
+
static void UnrefSynchEvent(SynchEvent* e) {
|
388
377
|
if (e != nullptr) {
|
389
378
|
synch_event_mu.Lock();
|
390
379
|
bool del = (--(e->refcount) == 0);
|
@@ -398,11 +387,11 @@ static void UnrefSynchEvent(SynchEvent *e) {
|
|
398
387
|
// Forget the mapping from the object (Mutex or CondVar) at address addr
|
399
388
|
// to SynchEvent object, and clear "bits" in its word (waiting until lockbit
|
400
389
|
// is clear before doing so).
|
401
|
-
static void ForgetSynchEvent(std::atomic<intptr_t
|
390
|
+
static void ForgetSynchEvent(std::atomic<intptr_t>* addr, intptr_t bits,
|
402
391
|
intptr_t lockbit) {
|
403
392
|
uint32_t h = reinterpret_cast<uintptr_t>(addr) % kNSynchEvent;
|
404
|
-
SynchEvent
|
405
|
-
SynchEvent
|
393
|
+
SynchEvent** pe;
|
394
|
+
SynchEvent* e;
|
406
395
|
synch_event_mu.Lock();
|
407
396
|
for (pe = &synch_event[h];
|
408
397
|
(e = *pe) != nullptr && e->masked_addr != base_internal::HidePtr(addr);
|
@@ -423,9 +412,9 @@ static void ForgetSynchEvent(std::atomic<intptr_t> *addr, intptr_t bits,
|
|
423
412
|
// Return a refcounted reference to the SynchEvent of the object at address
|
424
413
|
// "addr", if any. The pointer returned is valid until the UnrefSynchEvent() is
|
425
414
|
// called.
|
426
|
-
static SynchEvent
|
415
|
+
static SynchEvent* GetSynchEvent(const void* addr) {
|
427
416
|
uint32_t h = reinterpret_cast<uintptr_t>(addr) % kNSynchEvent;
|
428
|
-
SynchEvent
|
417
|
+
SynchEvent* e;
|
429
418
|
synch_event_mu.Lock();
|
430
419
|
for (e = synch_event[h];
|
431
420
|
e != nullptr && e->masked_addr != base_internal::HidePtr(addr);
|
@@ -440,17 +429,17 @@ static SynchEvent *GetSynchEvent(const void *addr) {
|
|
440
429
|
|
441
430
|
// Called when an event "ev" occurs on a Mutex of CondVar "obj"
|
442
431
|
// if event recording is on
|
443
|
-
static void PostSynchEvent(void
|
444
|
-
SynchEvent
|
432
|
+
static void PostSynchEvent(void* obj, int ev) {
|
433
|
+
SynchEvent* e = GetSynchEvent(obj);
|
445
434
|
// logging is on if event recording is on and either there's no event struct,
|
446
435
|
// or it explicitly says to log
|
447
436
|
if (e == nullptr || e->log) {
|
448
|
-
void
|
437
|
+
void* pcs[40];
|
449
438
|
int n = absl::GetStackTrace(pcs, ABSL_ARRAYSIZE(pcs), 1);
|
450
439
|
// A buffer with enough space for the ASCII for all the PCs, even on a
|
451
440
|
// 64-bit machine.
|
452
441
|
char buffer[ABSL_ARRAYSIZE(pcs) * 24];
|
453
|
-
int pos = snprintf(buffer, sizeof
|
442
|
+
int pos = snprintf(buffer, sizeof(buffer), " @");
|
454
443
|
for (int i = 0; i != n; i++) {
|
455
444
|
int b = snprintf(&buffer[pos], sizeof(buffer) - static_cast<size_t>(pos),
|
456
445
|
" %p", pcs[i]);
|
@@ -472,13 +461,13 @@ static void PostSynchEvent(void *obj, int ev) {
|
|
472
461
|
// get false positive race reports later.
|
473
462
|
// Reuse EvalConditionAnnotated to properly call into user code.
|
474
463
|
struct local {
|
475
|
-
static bool pred(SynchEvent
|
464
|
+
static bool pred(SynchEvent* ev) {
|
476
465
|
(*ev->invariant)(ev->arg);
|
477
466
|
return false;
|
478
467
|
}
|
479
468
|
};
|
480
469
|
Condition cond(&local::pred, e);
|
481
|
-
Mutex
|
470
|
+
Mutex* mu = static_cast<Mutex*>(obj);
|
482
471
|
const bool locking = (flags & SYNCH_F_UNLOCK) == 0;
|
483
472
|
const bool trylock = (flags & SYNCH_F_TRY) != 0;
|
484
473
|
const bool read_lock = (flags & SYNCH_F_R) != 0;
|
@@ -504,32 +493,32 @@ static void PostSynchEvent(void *obj, int ev) {
|
|
504
493
|
// PerThreadSynch struct points at the most recent SynchWaitParams struct when
|
505
494
|
// the thread is on a Mutex's waiter queue.
|
506
495
|
struct SynchWaitParams {
|
507
|
-
SynchWaitParams(Mutex::MuHow how_arg, const Condition
|
508
|
-
KernelTimeout timeout_arg, Mutex
|
509
|
-
PerThreadSynch
|
510
|
-
std::atomic<intptr_t
|
496
|
+
SynchWaitParams(Mutex::MuHow how_arg, const Condition* cond_arg,
|
497
|
+
KernelTimeout timeout_arg, Mutex* cvmu_arg,
|
498
|
+
PerThreadSynch* thread_arg,
|
499
|
+
std::atomic<intptr_t>* cv_word_arg)
|
511
500
|
: how(how_arg),
|
512
501
|
cond(cond_arg),
|
513
502
|
timeout(timeout_arg),
|
514
503
|
cvmu(cvmu_arg),
|
515
504
|
thread(thread_arg),
|
516
505
|
cv_word(cv_word_arg),
|
517
|
-
contention_start_cycles(
|
506
|
+
contention_start_cycles(CycleClock::Now()),
|
518
507
|
should_submit_contention_data(false) {}
|
519
508
|
|
520
509
|
const Mutex::MuHow how; // How this thread needs to wait.
|
521
|
-
const Condition
|
522
|
-
|
523
|
-
|
510
|
+
const Condition* cond; // The condition that this thread is waiting for.
|
511
|
+
// In Mutex, this field is set to zero if a timeout
|
512
|
+
// expires.
|
524
513
|
KernelTimeout timeout; // timeout expiry---absolute time
|
525
514
|
// In Mutex, this field is set to zero if a timeout
|
526
515
|
// expires.
|
527
|
-
Mutex
|
528
|
-
PerThreadSynch
|
516
|
+
Mutex* const cvmu; // used for transfer from cond var to mutex
|
517
|
+
PerThreadSynch* const thread; // thread that is waiting
|
529
518
|
|
530
519
|
// If not null, thread should be enqueued on the CondVar whose state
|
531
520
|
// word is cv_word instead of queueing normally on the Mutex.
|
532
|
-
std::atomic<intptr_t
|
521
|
+
std::atomic<intptr_t>* cv_word;
|
533
522
|
|
534
523
|
int64_t contention_start_cycles; // Time (in cycles) when this thread started
|
535
524
|
// to contend for the mutex.
|
@@ -537,12 +526,12 @@ struct SynchWaitParams {
|
|
537
526
|
};
|
538
527
|
|
539
528
|
struct SynchLocksHeld {
|
540
|
-
int n;
|
541
|
-
bool overflow;
|
529
|
+
int n; // number of valid entries in locks[]
|
530
|
+
bool overflow; // true iff we overflowed the array at some point
|
542
531
|
struct {
|
543
|
-
Mutex
|
544
|
-
int32_t count;
|
545
|
-
GraphId id;
|
532
|
+
Mutex* mu; // lock acquired
|
533
|
+
int32_t count; // times acquired
|
534
|
+
GraphId id; // deadlock_graph id of acquired lock
|
546
535
|
} locks[40];
|
547
536
|
// If a thread overfills the array during deadlock detection, we
|
548
537
|
// continue, discarding information as needed. If no overflow has
|
@@ -552,11 +541,11 @@ struct SynchLocksHeld {
|
|
552
541
|
|
553
542
|
// A sentinel value in lists that is not 0.
|
554
543
|
// A 0 value is used to mean "not on a list".
|
555
|
-
static PerThreadSynch
|
556
|
-
|
544
|
+
static PerThreadSynch* const kPerThreadSynchNull =
|
545
|
+
reinterpret_cast<PerThreadSynch*>(1);
|
557
546
|
|
558
|
-
static SynchLocksHeld
|
559
|
-
SynchLocksHeld
|
547
|
+
static SynchLocksHeld* LocksHeldAlloc() {
|
548
|
+
SynchLocksHeld* ret = reinterpret_cast<SynchLocksHeld*>(
|
560
549
|
base_internal::LowLevelAlloc::Alloc(sizeof(SynchLocksHeld)));
|
561
550
|
ret->n = 0;
|
562
551
|
ret->overflow = false;
|
@@ -564,24 +553,24 @@ static SynchLocksHeld *LocksHeldAlloc() {
|
|
564
553
|
}
|
565
554
|
|
566
555
|
// Return the PerThreadSynch-struct for this thread.
|
567
|
-
static PerThreadSynch
|
568
|
-
ThreadIdentity
|
556
|
+
static PerThreadSynch* Synch_GetPerThread() {
|
557
|
+
ThreadIdentity* identity = GetOrCreateCurrentThreadIdentity();
|
569
558
|
return &identity->per_thread_synch;
|
570
559
|
}
|
571
560
|
|
572
|
-
static PerThreadSynch
|
561
|
+
static PerThreadSynch* Synch_GetPerThreadAnnotated(Mutex* mu) {
|
573
562
|
if (mu) {
|
574
563
|
ABSL_TSAN_MUTEX_PRE_DIVERT(mu, 0);
|
575
564
|
}
|
576
|
-
PerThreadSynch
|
565
|
+
PerThreadSynch* w = Synch_GetPerThread();
|
577
566
|
if (mu) {
|
578
567
|
ABSL_TSAN_MUTEX_POST_DIVERT(mu, 0);
|
579
568
|
}
|
580
569
|
return w;
|
581
570
|
}
|
582
571
|
|
583
|
-
static SynchLocksHeld
|
584
|
-
PerThreadSynch
|
572
|
+
static SynchLocksHeld* Synch_GetAllLocks() {
|
573
|
+
PerThreadSynch* s = Synch_GetPerThread();
|
585
574
|
if (s->all_locks == nullptr) {
|
586
575
|
s->all_locks = LocksHeldAlloc(); // Freed by ReclaimThreadIdentity.
|
587
576
|
}
|
@@ -589,7 +578,7 @@ static SynchLocksHeld *Synch_GetAllLocks() {
|
|
589
578
|
}
|
590
579
|
|
591
580
|
// Post on "w"'s associated PerThreadSem.
|
592
|
-
void Mutex::IncrementSynchSem(Mutex
|
581
|
+
void Mutex::IncrementSynchSem(Mutex* mu, PerThreadSynch* w) {
|
593
582
|
if (mu) {
|
594
583
|
ABSL_TSAN_MUTEX_PRE_DIVERT(mu, 0);
|
595
584
|
// We miss synchronization around passing PerThreadSynch between threads
|
@@ -605,7 +594,7 @@ void Mutex::IncrementSynchSem(Mutex *mu, PerThreadSynch *w) {
|
|
605
594
|
}
|
606
595
|
|
607
596
|
// Wait on "w"'s associated PerThreadSem; returns false if timeout expired.
|
608
|
-
bool Mutex::DecrementSynchSem(Mutex
|
597
|
+
bool Mutex::DecrementSynchSem(Mutex* mu, PerThreadSynch* w, KernelTimeout t) {
|
609
598
|
if (mu) {
|
610
599
|
ABSL_TSAN_MUTEX_PRE_DIVERT(mu, 0);
|
611
600
|
}
|
@@ -626,7 +615,7 @@ bool Mutex::DecrementSynchSem(Mutex *mu, PerThreadSynch *w, KernelTimeout t) {
|
|
626
615
|
// Mutex code checking that the "waitp" field has not been reused.
|
627
616
|
void Mutex::InternalAttemptToUseMutexInFatalSignalHandler() {
|
628
617
|
// Fix the per-thread state only if it exists.
|
629
|
-
ThreadIdentity
|
618
|
+
ThreadIdentity* identity = CurrentThreadIdentityIfPresent();
|
630
619
|
if (identity != nullptr) {
|
631
620
|
identity->per_thread_synch.suppress_fatal_errors = true;
|
632
621
|
}
|
@@ -635,21 +624,6 @@ void Mutex::InternalAttemptToUseMutexInFatalSignalHandler() {
|
|
635
624
|
std::memory_order_release);
|
636
625
|
}
|
637
626
|
|
638
|
-
// --------------------------time support
|
639
|
-
|
640
|
-
// Return the current time plus the timeout. Use the same clock as
|
641
|
-
// PerThreadSem::Wait() for consistency. Unfortunately, we don't have
|
642
|
-
// such a choice when a deadline is given directly.
|
643
|
-
static absl::Time DeadlineFromTimeout(absl::Duration timeout) {
|
644
|
-
#ifndef _WIN32
|
645
|
-
struct timeval tv;
|
646
|
-
gettimeofday(&tv, nullptr);
|
647
|
-
return absl::TimeFromTimeval(tv) + timeout;
|
648
|
-
#else
|
649
|
-
return absl::Now() + timeout;
|
650
|
-
#endif
|
651
|
-
}
|
652
|
-
|
653
627
|
// --------------------------Mutexes
|
654
628
|
|
655
629
|
// In the layout below, the msb of the bottom byte is currently unused. Also,
|
@@ -660,24 +634,29 @@ static absl::Time DeadlineFromTimeout(absl::Duration timeout) {
|
|
660
634
|
// bit-twiddling trick in Mutex::Unlock().
|
661
635
|
// o kMuWriter / kMuReader == kMuWrWait / kMuWait,
|
662
636
|
// to enable the bit-twiddling trick in CheckForMutexCorruption().
|
663
|
-
static const intptr_t kMuReader
|
664
|
-
|
665
|
-
static const intptr_t kMuWait = 0x0004L; // threads are waiting
|
666
|
-
static const intptr_t kMuWriter = 0x0008L; // a writer holds the lock
|
667
|
-
static const intptr_t kMuEvent = 0x0010L; // record this mutex's events
|
637
|
+
static const intptr_t kMuReader = 0x0001L; // a reader holds the lock
|
638
|
+
// There's a designated waker.
|
668
639
|
// INVARIANT1: there's a thread that was blocked on the mutex, is
|
669
640
|
// no longer, yet has not yet acquired the mutex. If there's a
|
670
641
|
// designated waker, all threads can avoid taking the slow path in
|
671
642
|
// unlock because the designated waker will subsequently acquire
|
672
643
|
// the lock and wake someone. To maintain INVARIANT1 the bit is
|
673
644
|
// set when a thread is unblocked(INV1a), and threads that were
|
674
|
-
// unblocked reset the bit when they either acquire or re-block
|
675
|
-
|
676
|
-
static const intptr_t
|
677
|
-
|
678
|
-
static const intptr_t
|
679
|
-
|
680
|
-
|
645
|
+
// unblocked reset the bit when they either acquire or re-block (INV1b).
|
646
|
+
static const intptr_t kMuDesig = 0x0002L;
|
647
|
+
static const intptr_t kMuWait = 0x0004L; // threads are waiting
|
648
|
+
static const intptr_t kMuWriter = 0x0008L; // a writer holds the lock
|
649
|
+
static const intptr_t kMuEvent = 0x0010L; // record this mutex's events
|
650
|
+
// Runnable writer is waiting for a reader.
|
651
|
+
// If set, new readers will not lock the mutex to avoid writer starvation.
|
652
|
+
// Note: if a reader has higher priority than the writer, it will still lock
|
653
|
+
// the mutex ahead of the waiting writer, but in a very inefficient manner:
|
654
|
+
// the reader will first queue itself and block, but then the last unlocking
|
655
|
+
// reader will wake it.
|
656
|
+
static const intptr_t kMuWrWait = 0x0020L;
|
657
|
+
static const intptr_t kMuSpin = 0x0040L; // spinlock protects wait list
|
658
|
+
static const intptr_t kMuLow = 0x00ffL; // mask all mutex bits
|
659
|
+
static const intptr_t kMuHigh = ~kMuLow; // mask pointer/reader count
|
681
660
|
|
682
661
|
// Hack to make constant values available to gdb pretty printer
|
683
662
|
enum {
|
@@ -773,8 +752,8 @@ Mutex::~Mutex() {
|
|
773
752
|
ABSL_TSAN_MUTEX_DESTROY(this, __tsan_mutex_not_static);
|
774
753
|
}
|
775
754
|
|
776
|
-
void Mutex::EnableDebugLog(const char
|
777
|
-
SynchEvent
|
755
|
+
void Mutex::EnableDebugLog(const char* name) {
|
756
|
+
SynchEvent* e = EnsureSynchEvent(&this->mu_, name, kMuEvent, kMuSpin);
|
778
757
|
e->log = true;
|
779
758
|
UnrefSynchEvent(e);
|
780
759
|
}
|
@@ -783,11 +762,10 @@ void EnableMutexInvariantDebugging(bool enabled) {
|
|
783
762
|
synch_check_invariants.store(enabled, std::memory_order_release);
|
784
763
|
}
|
785
764
|
|
786
|
-
void Mutex::EnableInvariantDebugging(void (*invariant)(void *)
|
787
|
-
void *arg) {
|
765
|
+
void Mutex::EnableInvariantDebugging(void (*invariant)(void*), void* arg) {
|
788
766
|
if (synch_check_invariants.load(std::memory_order_acquire) &&
|
789
767
|
invariant != nullptr) {
|
790
|
-
SynchEvent
|
768
|
+
SynchEvent* e = EnsureSynchEvent(&this->mu_, nullptr, kMuEvent, kMuSpin);
|
791
769
|
e->invariant = invariant;
|
792
770
|
e->arg = arg;
|
793
771
|
UnrefSynchEvent(e);
|
@@ -803,15 +781,15 @@ void SetMutexDeadlockDetectionMode(OnDeadlockCycle mode) {
|
|
803
781
|
// waiters with the same condition, type of lock, and thread priority.
|
804
782
|
//
|
805
783
|
// Requires that x and y be waiting on the same Mutex queue.
|
806
|
-
static bool MuEquivalentWaiter(PerThreadSynch
|
784
|
+
static bool MuEquivalentWaiter(PerThreadSynch* x, PerThreadSynch* y) {
|
807
785
|
return x->waitp->how == y->waitp->how && x->priority == y->priority &&
|
808
786
|
Condition::GuaranteedEqual(x->waitp->cond, y->waitp->cond);
|
809
787
|
}
|
810
788
|
|
811
789
|
// Given the contents of a mutex word containing a PerThreadSynch pointer,
|
812
790
|
// return the pointer.
|
813
|
-
static inline PerThreadSynch
|
814
|
-
return reinterpret_cast<PerThreadSynch
|
791
|
+
static inline PerThreadSynch* GetPerThreadSynch(intptr_t v) {
|
792
|
+
return reinterpret_cast<PerThreadSynch*>(v & kMuHigh);
|
815
793
|
}
|
816
794
|
|
817
795
|
// The next several routines maintain the per-thread next and skip fields
|
@@ -869,17 +847,17 @@ static inline PerThreadSynch *GetPerThreadSynch(intptr_t v) {
|
|
869
847
|
// except those in the added node and the former "head" node. This implies
|
870
848
|
// that the new node is added after head, and so must be the new head or the
|
871
849
|
// new front of the queue.
|
872
|
-
static PerThreadSynch
|
873
|
-
PerThreadSynch
|
874
|
-
PerThreadSynch
|
875
|
-
PerThreadSynch
|
850
|
+
static PerThreadSynch* Skip(PerThreadSynch* x) {
|
851
|
+
PerThreadSynch* x0 = nullptr;
|
852
|
+
PerThreadSynch* x1 = x;
|
853
|
+
PerThreadSynch* x2 = x->skip;
|
876
854
|
if (x2 != nullptr) {
|
877
855
|
// Each iteration attempts to advance sequence (x0,x1,x2) to next sequence
|
878
856
|
// such that x1 == x0->skip && x2 == x1->skip
|
879
857
|
while ((x0 = x1, x1 = x2, x2 = x2->skip) != nullptr) {
|
880
|
-
x0->skip = x2;
|
858
|
+
x0->skip = x2; // short-circuit skip from x0 to x2
|
881
859
|
}
|
882
|
-
x->skip = x1;
|
860
|
+
x->skip = x1; // short-circuit skip from x to result
|
883
861
|
}
|
884
862
|
return x1;
|
885
863
|
}
|
@@ -888,7 +866,7 @@ static PerThreadSynch *Skip(PerThreadSynch *x) {
|
|
888
866
|
// The latter is going to be removed out of order, because of a timeout.
|
889
867
|
// Check whether "ancestor" has a skip field pointing to "to_be_removed",
|
890
868
|
// and fix it if it does.
|
891
|
-
static void FixSkip(PerThreadSynch
|
869
|
+
static void FixSkip(PerThreadSynch* ancestor, PerThreadSynch* to_be_removed) {
|
892
870
|
if (ancestor->skip == to_be_removed) { // ancestor->skip left dangling
|
893
871
|
if (to_be_removed->skip != nullptr) {
|
894
872
|
ancestor->skip = to_be_removed->skip; // can skip past to_be_removed
|
@@ -900,7 +878,7 @@ static void FixSkip(PerThreadSynch *ancestor, PerThreadSynch *to_be_removed) {
|
|
900
878
|
}
|
901
879
|
}
|
902
880
|
|
903
|
-
static void CondVarEnqueue(SynchWaitParams
|
881
|
+
static void CondVarEnqueue(SynchWaitParams* waitp);
|
904
882
|
|
905
883
|
// Enqueue thread "waitp->thread" on a waiter queue.
|
906
884
|
// Called with mutex spinlock held if head != nullptr
|
@@ -921,8 +899,8 @@ static void CondVarEnqueue(SynchWaitParams *waitp);
|
|
921
899
|
// returned. This mechanism is used by CondVar to queue a thread on the
|
922
900
|
// condition variable queue instead of the mutex queue in implementing Wait().
|
923
901
|
// In this case, Enqueue() can return nullptr (if head==nullptr).
|
924
|
-
static PerThreadSynch
|
925
|
-
|
902
|
+
static PerThreadSynch* Enqueue(PerThreadSynch* head, SynchWaitParams* waitp,
|
903
|
+
intptr_t mu, int flags) {
|
926
904
|
// If we have been given a cv_word, call CondVarEnqueue() and return
|
927
905
|
// the previous head of the Mutex waiter queue.
|
928
906
|
if (waitp->cv_word != nullptr) {
|
@@ -930,42 +908,43 @@ static PerThreadSynch *Enqueue(PerThreadSynch *head,
|
|
930
908
|
return head;
|
931
909
|
}
|
932
910
|
|
933
|
-
PerThreadSynch
|
911
|
+
PerThreadSynch* s = waitp->thread;
|
934
912
|
ABSL_RAW_CHECK(
|
935
913
|
s->waitp == nullptr || // normal case
|
936
914
|
s->waitp == waitp || // Fer()---transfer from condition variable
|
937
915
|
s->suppress_fatal_errors,
|
938
916
|
"detected illegal recursion into Mutex code");
|
939
917
|
s->waitp = waitp;
|
940
|
-
s->skip = nullptr;
|
941
|
-
s->may_skip = true;
|
942
|
-
s->wake = false;
|
918
|
+
s->skip = nullptr; // maintain skip invariant (see above)
|
919
|
+
s->may_skip = true; // always true on entering queue
|
920
|
+
s->wake = false; // not being woken
|
943
921
|
s->cond_waiter = ((flags & kMuIsCond) != 0);
|
922
|
+
#ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
|
923
|
+
int64_t now_cycles = CycleClock::Now();
|
924
|
+
if (s->next_priority_read_cycles < now_cycles) {
|
925
|
+
// Every so often, update our idea of the thread's priority.
|
926
|
+
// pthread_getschedparam() is 5% of the block/wakeup time;
|
927
|
+
// CycleClock::Now() is 0.5%.
|
928
|
+
int policy;
|
929
|
+
struct sched_param param;
|
930
|
+
const int err = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
931
|
+
if (err != 0) {
|
932
|
+
ABSL_RAW_LOG(ERROR, "pthread_getschedparam failed: %d", err);
|
933
|
+
} else {
|
934
|
+
s->priority = param.sched_priority;
|
935
|
+
s->next_priority_read_cycles =
|
936
|
+
now_cycles + static_cast<int64_t>(CycleClock::Frequency());
|
937
|
+
}
|
938
|
+
}
|
939
|
+
#endif
|
944
940
|
if (head == nullptr) { // s is the only waiter
|
945
941
|
s->next = s; // it's the only entry in the cycle
|
946
942
|
s->readers = mu; // reader count is from mu word
|
947
943
|
s->maybe_unlocking = false; // no one is searching an empty list
|
948
944
|
head = s; // s is new head
|
949
945
|
} else {
|
950
|
-
PerThreadSynch
|
946
|
+
PerThreadSynch* enqueue_after = nullptr; // we'll put s after this element
|
951
947
|
#ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
|
952
|
-
int64_t now_cycles = base_internal::CycleClock::Now();
|
953
|
-
if (s->next_priority_read_cycles < now_cycles) {
|
954
|
-
// Every so often, update our idea of the thread's priority.
|
955
|
-
// pthread_getschedparam() is 5% of the block/wakeup time;
|
956
|
-
// base_internal::CycleClock::Now() is 0.5%.
|
957
|
-
int policy;
|
958
|
-
struct sched_param param;
|
959
|
-
const int err = pthread_getschedparam(pthread_self(), &policy, ¶m);
|
960
|
-
if (err != 0) {
|
961
|
-
ABSL_RAW_LOG(ERROR, "pthread_getschedparam failed: %d", err);
|
962
|
-
} else {
|
963
|
-
s->priority = param.sched_priority;
|
964
|
-
s->next_priority_read_cycles =
|
965
|
-
now_cycles +
|
966
|
-
static_cast<int64_t>(base_internal::CycleClock::Frequency());
|
967
|
-
}
|
968
|
-
}
|
969
948
|
if (s->priority > head->priority) { // s's priority is above head's
|
970
949
|
// try to put s in priority-fifo order, or failing that at the front.
|
971
950
|
if (!head->maybe_unlocking) {
|
@@ -975,20 +954,20 @@ static PerThreadSynch *Enqueue(PerThreadSynch *head,
|
|
975
954
|
// Within a skip chain, all waiters have the same priority, so we can
|
976
955
|
// skip forward through the chains until we find one with a lower
|
977
956
|
// priority than the waiter to be enqueued.
|
978
|
-
PerThreadSynch
|
957
|
+
PerThreadSynch* advance_to = head; // next value of enqueue_after
|
979
958
|
do {
|
980
959
|
enqueue_after = advance_to;
|
981
960
|
// (side-effect: optimizes skip chain)
|
982
961
|
advance_to = Skip(enqueue_after->next);
|
983
962
|
} while (s->priority <= advance_to->priority);
|
984
|
-
|
985
|
-
|
963
|
+
// termination guaranteed because s->priority > head->priority
|
964
|
+
// and head is the end of a skip chain
|
986
965
|
} else if (waitp->how == kExclusive &&
|
987
966
|
Condition::GuaranteedEqual(waitp->cond, nullptr)) {
|
988
967
|
// An unlocker could be scanning the queue, but we know it will recheck
|
989
968
|
// the queue front for writers that have no condition, which is what s
|
990
969
|
// is, so an insert at front is safe.
|
991
|
-
enqueue_after = head;
|
970
|
+
enqueue_after = head; // add after head, at front
|
992
971
|
}
|
993
972
|
}
|
994
973
|
#endif
|
@@ -1013,12 +992,12 @@ static PerThreadSynch *Enqueue(PerThreadSynch *head,
|
|
1013
992
|
enqueue_after->skip = enqueue_after->next;
|
1014
993
|
}
|
1015
994
|
if (MuEquivalentWaiter(s, s->next)) { // s->may_skip is known to be true
|
1016
|
-
s->skip = s->next;
|
995
|
+
s->skip = s->next; // s may skip to its successor
|
1017
996
|
}
|
1018
|
-
} else {
|
1019
|
-
|
997
|
+
} else { // enqueue not done any other way, so
|
998
|
+
// we're inserting s at the back
|
1020
999
|
// s will become new head; copy data from head into it
|
1021
|
-
s->next = head->next;
|
1000
|
+
s->next = head->next; // add s after head
|
1022
1001
|
head->next = s;
|
1023
1002
|
s->readers = head->readers; // reader count is from previous head
|
1024
1003
|
s->maybe_unlocking = head->maybe_unlocking; // same for unlock hint
|
@@ -1037,17 +1016,17 @@ static PerThreadSynch *Enqueue(PerThreadSynch *head,
|
|
1037
1016
|
// whose last element is head. The new head element is returned, or null
|
1038
1017
|
// if the list is made empty.
|
1039
1018
|
// Dequeue is called with both spinlock and Mutex held.
|
1040
|
-
static PerThreadSynch
|
1041
|
-
PerThreadSynch
|
1042
|
-
pw->next = w->next;
|
1043
|
-
if (head == w) {
|
1019
|
+
static PerThreadSynch* Dequeue(PerThreadSynch* head, PerThreadSynch* pw) {
|
1020
|
+
PerThreadSynch* w = pw->next;
|
1021
|
+
pw->next = w->next; // snip w out of list
|
1022
|
+
if (head == w) { // we removed the head
|
1044
1023
|
head = (pw == w) ? nullptr : pw; // either emptied list, or pw is new head
|
1045
1024
|
} else if (pw != head && MuEquivalentWaiter(pw, pw->next)) {
|
1046
1025
|
// pw can skip to its new successor
|
1047
1026
|
if (pw->next->skip !=
|
1048
1027
|
nullptr) { // either skip to its successors skip target
|
1049
1028
|
pw->skip = pw->next->skip;
|
1050
|
-
} else {
|
1029
|
+
} else { // or to pw's successor
|
1051
1030
|
pw->skip = pw->next;
|
1052
1031
|
}
|
1053
1032
|
}
|
@@ -1060,27 +1039,27 @@ static PerThreadSynch *Dequeue(PerThreadSynch *head, PerThreadSynch *pw) {
|
|
1060
1039
|
// singly-linked list wake_list in the order found. Assumes that
|
1061
1040
|
// there is only one such element if the element has how == kExclusive.
|
1062
1041
|
// Return the new head.
|
1063
|
-
static PerThreadSynch
|
1064
|
-
PerThreadSynch
|
1065
|
-
PerThreadSynch
|
1066
|
-
PerThreadSynch
|
1067
|
-
PerThreadSynch
|
1042
|
+
static PerThreadSynch* DequeueAllWakeable(PerThreadSynch* head,
|
1043
|
+
PerThreadSynch* pw,
|
1044
|
+
PerThreadSynch** wake_tail) {
|
1045
|
+
PerThreadSynch* orig_h = head;
|
1046
|
+
PerThreadSynch* w = pw->next;
|
1068
1047
|
bool skipped = false;
|
1069
1048
|
do {
|
1070
|
-
if (w->wake) {
|
1049
|
+
if (w->wake) { // remove this element
|
1071
1050
|
ABSL_RAW_CHECK(pw->skip == nullptr, "bad skip in DequeueAllWakeable");
|
1072
1051
|
// we're removing pw's successor so either pw->skip is zero or we should
|
1073
1052
|
// already have removed pw since if pw->skip!=null, pw has the same
|
1074
1053
|
// condition as w.
|
1075
1054
|
head = Dequeue(head, pw);
|
1076
|
-
w->next = *wake_tail;
|
1077
|
-
*wake_tail = w;
|
1078
|
-
wake_tail = &w->next;
|
1055
|
+
w->next = *wake_tail; // keep list terminated
|
1056
|
+
*wake_tail = w; // add w to wake_list;
|
1057
|
+
wake_tail = &w->next; // next addition to end
|
1079
1058
|
if (w->waitp->how == kExclusive) { // wake at most 1 writer
|
1080
1059
|
break;
|
1081
1060
|
}
|
1082
|
-
} else {
|
1083
|
-
pw = Skip(w);
|
1061
|
+
} else { // not waking this one; skip
|
1062
|
+
pw = Skip(w); // skip as much as possible
|
1084
1063
|
skipped = true;
|
1085
1064
|
}
|
1086
1065
|
w = pw->next;
|
@@ -1098,7 +1077,7 @@ static PerThreadSynch *DequeueAllWakeable(PerThreadSynch *head,
|
|
1098
1077
|
|
1099
1078
|
// Try to remove thread s from the list of waiters on this mutex.
|
1100
1079
|
// Does nothing if s is not on the waiter list.
|
1101
|
-
void Mutex::TryRemove(PerThreadSynch
|
1080
|
+
void Mutex::TryRemove(PerThreadSynch* s) {
|
1102
1081
|
SchedulingGuard::ScopedDisable disable_rescheduling;
|
1103
1082
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1104
1083
|
// acquire spinlock & lock
|
@@ -1106,16 +1085,16 @@ void Mutex::TryRemove(PerThreadSynch *s) {
|
|
1106
1085
|
mu_.compare_exchange_strong(v, v | kMuSpin | kMuWriter,
|
1107
1086
|
std::memory_order_acquire,
|
1108
1087
|
std::memory_order_relaxed)) {
|
1109
|
-
PerThreadSynch
|
1088
|
+
PerThreadSynch* h = GetPerThreadSynch(v);
|
1110
1089
|
if (h != nullptr) {
|
1111
|
-
PerThreadSynch
|
1112
|
-
PerThreadSynch
|
1090
|
+
PerThreadSynch* pw = h; // pw is w's predecessor
|
1091
|
+
PerThreadSynch* w;
|
1113
1092
|
if ((w = pw->next) != s) { // search for thread,
|
1114
1093
|
do { // processing at least one element
|
1115
1094
|
// If the current element isn't equivalent to the waiter to be
|
1116
1095
|
// removed, we can skip the entire chain.
|
1117
1096
|
if (!MuEquivalentWaiter(s, w)) {
|
1118
|
-
pw = Skip(w);
|
1097
|
+
pw = Skip(w); // so skip all that won't match
|
1119
1098
|
// we don't have to worry about dangling skip fields
|
1120
1099
|
// in the threads we skipped; none can point to s
|
1121
1100
|
// because they are in a different equivalence class.
|
@@ -1127,7 +1106,7 @@ void Mutex::TryRemove(PerThreadSynch *s) {
|
|
1127
1106
|
// process the first thread again.
|
1128
1107
|
} while ((w = pw->next) != s && pw != h);
|
1129
1108
|
}
|
1130
|
-
if (w == s) {
|
1109
|
+
if (w == s) { // found thread; remove it
|
1131
1110
|
// pw->skip may be non-zero here; the loop above ensured that
|
1132
1111
|
// no ancestor of s can skip to s, so removal is safe anyway.
|
1133
1112
|
h = Dequeue(h, pw);
|
@@ -1136,16 +1115,15 @@ void Mutex::TryRemove(PerThreadSynch *s) {
|
|
1136
1115
|
}
|
1137
1116
|
}
|
1138
1117
|
intptr_t nv;
|
1139
|
-
do {
|
1118
|
+
do { // release spinlock and lock
|
1140
1119
|
v = mu_.load(std::memory_order_relaxed);
|
1141
1120
|
nv = v & (kMuDesig | kMuEvent);
|
1142
1121
|
if (h != nullptr) {
|
1143
1122
|
nv |= kMuWait | reinterpret_cast<intptr_t>(h);
|
1144
|
-
h->readers = 0;
|
1123
|
+
h->readers = 0; // we hold writer lock
|
1145
1124
|
h->maybe_unlocking = false; // finished unlocking
|
1146
1125
|
}
|
1147
|
-
} while (!mu_.compare_exchange_weak(v, nv,
|
1148
|
-
std::memory_order_release,
|
1126
|
+
} while (!mu_.compare_exchange_weak(v, nv, std::memory_order_release,
|
1149
1127
|
std::memory_order_relaxed));
|
1150
1128
|
}
|
1151
1129
|
}
|
@@ -1155,7 +1133,7 @@ void Mutex::TryRemove(PerThreadSynch *s) {
|
|
1155
1133
|
// if the wait extends past the absolute time specified, even if "s" is still
|
1156
1134
|
// on the mutex queue. In this case, remove "s" from the queue and return
|
1157
1135
|
// true, otherwise return false.
|
1158
|
-
void Mutex::Block(PerThreadSynch
|
1136
|
+
void Mutex::Block(PerThreadSynch* s) {
|
1159
1137
|
while (s->state.load(std::memory_order_acquire) == PerThreadSynch::kQueued) {
|
1160
1138
|
if (!DecrementSynchSem(this, s, s->waitp->timeout)) {
|
1161
1139
|
// After a timeout, we go into a spin loop until we remove ourselves
|
@@ -1174,7 +1152,7 @@ void Mutex::Block(PerThreadSynch *s) {
|
|
1174
1152
|
// is not on the queue.
|
1175
1153
|
this->TryRemove(s);
|
1176
1154
|
}
|
1177
|
-
s->waitp->timeout = KernelTimeout::Never();
|
1155
|
+
s->waitp->timeout = KernelTimeout::Never(); // timeout is satisfied
|
1178
1156
|
s->waitp->cond = nullptr; // condition no longer relevant for wakeups
|
1179
1157
|
}
|
1180
1158
|
}
|
@@ -1184,8 +1162,8 @@ void Mutex::Block(PerThreadSynch *s) {
|
|
1184
1162
|
}
|
1185
1163
|
|
1186
1164
|
// Wake thread w, and return the next thread in the list.
|
1187
|
-
PerThreadSynch
|
1188
|
-
PerThreadSynch
|
1165
|
+
PerThreadSynch* Mutex::Wakeup(PerThreadSynch* w) {
|
1166
|
+
PerThreadSynch* next = w->next;
|
1189
1167
|
w->next = nullptr;
|
1190
1168
|
w->state.store(PerThreadSynch::kAvailable, std::memory_order_release);
|
1191
1169
|
IncrementSynchSem(this, w);
|
@@ -1193,7 +1171,7 @@ PerThreadSynch *Mutex::Wakeup(PerThreadSynch *w) {
|
|
1193
1171
|
return next;
|
1194
1172
|
}
|
1195
1173
|
|
1196
|
-
static GraphId GetGraphIdLocked(Mutex
|
1174
|
+
static GraphId GetGraphIdLocked(Mutex* mu)
|
1197
1175
|
ABSL_EXCLUSIVE_LOCKS_REQUIRED(deadlock_graph_mu) {
|
1198
1176
|
if (!deadlock_graph) { // (re)create the deadlock graph.
|
1199
1177
|
deadlock_graph =
|
@@ -1203,7 +1181,7 @@ static GraphId GetGraphIdLocked(Mutex *mu)
|
|
1203
1181
|
return deadlock_graph->GetId(mu);
|
1204
1182
|
}
|
1205
1183
|
|
1206
|
-
static GraphId GetGraphId(Mutex
|
1184
|
+
static GraphId GetGraphId(Mutex* mu) ABSL_LOCKS_EXCLUDED(deadlock_graph_mu) {
|
1207
1185
|
deadlock_graph_mu.Lock();
|
1208
1186
|
GraphId id = GetGraphIdLocked(mu);
|
1209
1187
|
deadlock_graph_mu.Unlock();
|
@@ -1213,7 +1191,7 @@ static GraphId GetGraphId(Mutex *mu) ABSL_LOCKS_EXCLUDED(deadlock_graph_mu) {
|
|
1213
1191
|
// Record a lock acquisition. This is used in debug mode for deadlock
|
1214
1192
|
// detection. The held_locks pointer points to the relevant data
|
1215
1193
|
// structure for each case.
|
1216
|
-
static void LockEnter(Mutex* mu, GraphId id, SynchLocksHeld
|
1194
|
+
static void LockEnter(Mutex* mu, GraphId id, SynchLocksHeld* held_locks) {
|
1217
1195
|
int n = held_locks->n;
|
1218
1196
|
int i = 0;
|
1219
1197
|
while (i != n && held_locks->locks[i].id != id) {
|
@@ -1237,7 +1215,7 @@ static void LockEnter(Mutex* mu, GraphId id, SynchLocksHeld *held_locks) {
|
|
1237
1215
|
// eventually followed by a call to LockLeave(mu, id, x) by the same thread.
|
1238
1216
|
// It does not process the event if is not needed when deadlock detection is
|
1239
1217
|
// disabled.
|
1240
|
-
static void LockLeave(Mutex* mu, GraphId id, SynchLocksHeld
|
1218
|
+
static void LockLeave(Mutex* mu, GraphId id, SynchLocksHeld* held_locks) {
|
1241
1219
|
int n = held_locks->n;
|
1242
1220
|
int i = 0;
|
1243
1221
|
while (i != n && held_locks->locks[i].id != id) {
|
@@ -1252,11 +1230,11 @@ static void LockLeave(Mutex* mu, GraphId id, SynchLocksHeld *held_locks) {
|
|
1252
1230
|
i++;
|
1253
1231
|
}
|
1254
1232
|
if (i == n) { // mu missing means releasing unheld lock
|
1255
|
-
SynchEvent
|
1233
|
+
SynchEvent* mu_events = GetSynchEvent(mu);
|
1256
1234
|
ABSL_RAW_LOG(FATAL,
|
1257
1235
|
"thread releasing lock it does not hold: %p %s; "
|
1258
1236
|
,
|
1259
|
-
static_cast<void
|
1237
|
+
static_cast<void*>(mu),
|
1260
1238
|
mu_events == nullptr ? "" : mu_events->name);
|
1261
1239
|
}
|
1262
1240
|
}
|
@@ -1273,7 +1251,7 @@ static void LockLeave(Mutex* mu, GraphId id, SynchLocksHeld *held_locks) {
|
|
1273
1251
|
}
|
1274
1252
|
|
1275
1253
|
// Call LockEnter() if in debug mode and deadlock detection is enabled.
|
1276
|
-
static inline void DebugOnlyLockEnter(Mutex
|
1254
|
+
static inline void DebugOnlyLockEnter(Mutex* mu) {
|
1277
1255
|
if (kDebugMode) {
|
1278
1256
|
if (synch_deadlock_detection.load(std::memory_order_acquire) !=
|
1279
1257
|
OnDeadlockCycle::kIgnore) {
|
@@ -1283,7 +1261,7 @@ static inline void DebugOnlyLockEnter(Mutex *mu) {
|
|
1283
1261
|
}
|
1284
1262
|
|
1285
1263
|
// Call LockEnter() if in debug mode and deadlock detection is enabled.
|
1286
|
-
static inline void DebugOnlyLockEnter(Mutex
|
1264
|
+
static inline void DebugOnlyLockEnter(Mutex* mu, GraphId id) {
|
1287
1265
|
if (kDebugMode) {
|
1288
1266
|
if (synch_deadlock_detection.load(std::memory_order_acquire) !=
|
1289
1267
|
OnDeadlockCycle::kIgnore) {
|
@@ -1293,7 +1271,7 @@ static inline void DebugOnlyLockEnter(Mutex *mu, GraphId id) {
|
|
1293
1271
|
}
|
1294
1272
|
|
1295
1273
|
// Call LockLeave() if in debug mode and deadlock detection is enabled.
|
1296
|
-
static inline void DebugOnlyLockLeave(Mutex
|
1274
|
+
static inline void DebugOnlyLockLeave(Mutex* mu) {
|
1297
1275
|
if (kDebugMode) {
|
1298
1276
|
if (synch_deadlock_detection.load(std::memory_order_acquire) !=
|
1299
1277
|
OnDeadlockCycle::kIgnore) {
|
@@ -1302,9 +1280,9 @@ static inline void DebugOnlyLockLeave(Mutex *mu) {
|
|
1302
1280
|
}
|
1303
1281
|
}
|
1304
1282
|
|
1305
|
-
static char
|
1283
|
+
static char* StackString(void** pcs, int n, char* buf, int maxlen,
|
1306
1284
|
bool symbolize) {
|
1307
|
-
static
|
1285
|
+
static constexpr int kSymLen = 200;
|
1308
1286
|
char sym[kSymLen];
|
1309
1287
|
int len = 0;
|
1310
1288
|
for (int i = 0; i != n; i++) {
|
@@ -1312,7 +1290,7 @@ static char *StackString(void **pcs, int n, char *buf, int maxlen,
|
|
1312
1290
|
return buf;
|
1313
1291
|
size_t count = static_cast<size_t>(maxlen - len);
|
1314
1292
|
if (symbolize) {
|
1315
|
-
if (!
|
1293
|
+
if (!absl::Symbolize(pcs[i], sym, kSymLen)) {
|
1316
1294
|
sym[0] = '\0';
|
1317
1295
|
}
|
1318
1296
|
snprintf(buf + len, count, "%s\t@ %p %s\n", (i == 0 ? "\n" : ""), pcs[i],
|
@@ -1325,15 +1303,17 @@ static char *StackString(void **pcs, int n, char *buf, int maxlen,
|
|
1325
1303
|
return buf;
|
1326
1304
|
}
|
1327
1305
|
|
1328
|
-
static char
|
1329
|
-
void
|
1306
|
+
static char* CurrentStackString(char* buf, int maxlen, bool symbolize) {
|
1307
|
+
void* pcs[40];
|
1330
1308
|
return StackString(pcs, absl::GetStackTrace(pcs, ABSL_ARRAYSIZE(pcs), 2), buf,
|
1331
1309
|
maxlen, symbolize);
|
1332
1310
|
}
|
1333
1311
|
|
1334
1312
|
namespace {
|
1335
|
-
enum {
|
1336
|
-
|
1313
|
+
enum {
|
1314
|
+
kMaxDeadlockPathLen = 10
|
1315
|
+
}; // maximum length of a deadlock cycle;
|
1316
|
+
// a path this long would be remarkable
|
1337
1317
|
// Buffers required to report a deadlock.
|
1338
1318
|
// We do not allocate them on stack to avoid large stack frame.
|
1339
1319
|
struct DeadlockReportBuffers {
|
@@ -1343,11 +1323,11 @@ struct DeadlockReportBuffers {
|
|
1343
1323
|
|
1344
1324
|
struct ScopedDeadlockReportBuffers {
|
1345
1325
|
ScopedDeadlockReportBuffers() {
|
1346
|
-
b = reinterpret_cast<DeadlockReportBuffers
|
1326
|
+
b = reinterpret_cast<DeadlockReportBuffers*>(
|
1347
1327
|
base_internal::LowLevelAlloc::Alloc(sizeof(*b)));
|
1348
1328
|
}
|
1349
1329
|
~ScopedDeadlockReportBuffers() { base_internal::LowLevelAlloc::Free(b); }
|
1350
|
-
DeadlockReportBuffers
|
1330
|
+
DeadlockReportBuffers* b;
|
1351
1331
|
};
|
1352
1332
|
|
1353
1333
|
// Helper to pass to GraphCycles::UpdateStackTrace.
|
@@ -1358,13 +1338,13 @@ int GetStack(void** stack, int max_depth) {
|
|
1358
1338
|
|
1359
1339
|
// Called in debug mode when a thread is about to acquire a lock in a way that
|
1360
1340
|
// may block.
|
1361
|
-
static GraphId DeadlockCheck(Mutex
|
1341
|
+
static GraphId DeadlockCheck(Mutex* mu) {
|
1362
1342
|
if (synch_deadlock_detection.load(std::memory_order_acquire) ==
|
1363
1343
|
OnDeadlockCycle::kIgnore) {
|
1364
1344
|
return InvalidGraphId();
|
1365
1345
|
}
|
1366
1346
|
|
1367
|
-
SynchLocksHeld
|
1347
|
+
SynchLocksHeld* all_locks = Synch_GetAllLocks();
|
1368
1348
|
|
1369
1349
|
absl::base_internal::SpinLockHolder lock(&deadlock_graph_mu);
|
1370
1350
|
const GraphId mu_id = GetGraphIdLocked(mu);
|
@@ -1386,8 +1366,8 @@ static GraphId DeadlockCheck(Mutex *mu) {
|
|
1386
1366
|
// For each other mutex already held by this thread:
|
1387
1367
|
for (int i = 0; i != all_locks->n; i++) {
|
1388
1368
|
const GraphId other_node_id = all_locks->locks[i].id;
|
1389
|
-
const Mutex
|
1390
|
-
static_cast<const Mutex
|
1369
|
+
const Mutex* other =
|
1370
|
+
static_cast<const Mutex*>(deadlock_graph->Ptr(other_node_id));
|
1391
1371
|
if (other == nullptr) {
|
1392
1372
|
// Ignore stale lock
|
1393
1373
|
continue;
|
@@ -1396,7 +1376,7 @@ static GraphId DeadlockCheck(Mutex *mu) {
|
|
1396
1376
|
// Add the acquired-before edge to the graph.
|
1397
1377
|
if (!deadlock_graph->InsertEdge(other_node_id, mu_id)) {
|
1398
1378
|
ScopedDeadlockReportBuffers scoped_buffers;
|
1399
|
-
DeadlockReportBuffers
|
1379
|
+
DeadlockReportBuffers* b = scoped_buffers.b;
|
1400
1380
|
static int number_of_reported_deadlocks = 0;
|
1401
1381
|
number_of_reported_deadlocks++;
|
1402
1382
|
// Symbolize only 2 first deadlock report to avoid huge slowdowns.
|
@@ -1407,37 +1387,40 @@ static GraphId DeadlockCheck(Mutex *mu) {
|
|
1407
1387
|
for (int j = 0; j != all_locks->n; j++) {
|
1408
1388
|
void* pr = deadlock_graph->Ptr(all_locks->locks[j].id);
|
1409
1389
|
if (pr != nullptr) {
|
1410
|
-
snprintf(b->buf + len, sizeof
|
1390
|
+
snprintf(b->buf + len, sizeof(b->buf) - len, " %p", pr);
|
1411
1391
|
len += strlen(&b->buf[len]);
|
1412
1392
|
}
|
1413
1393
|
}
|
1414
1394
|
ABSL_RAW_LOG(ERROR,
|
1415
1395
|
"Acquiring absl::Mutex %p while holding %s; a cycle in the "
|
1416
1396
|
"historical lock ordering graph has been observed",
|
1417
|
-
static_cast<void
|
1397
|
+
static_cast<void*>(mu), b->buf);
|
1418
1398
|
ABSL_RAW_LOG(ERROR, "Cycle: ");
|
1419
|
-
int path_len = deadlock_graph->FindPath(
|
1420
|
-
|
1421
|
-
for (int j = 0; j != path_len; j++) {
|
1399
|
+
int path_len = deadlock_graph->FindPath(mu_id, other_node_id,
|
1400
|
+
ABSL_ARRAYSIZE(b->path), b->path);
|
1401
|
+
for (int j = 0; j != path_len && j != ABSL_ARRAYSIZE(b->path); j++) {
|
1422
1402
|
GraphId id = b->path[j];
|
1423
|
-
Mutex
|
1403
|
+
Mutex* path_mu = static_cast<Mutex*>(deadlock_graph->Ptr(id));
|
1424
1404
|
if (path_mu == nullptr) continue;
|
1425
1405
|
void** stack;
|
1426
1406
|
int depth = deadlock_graph->GetStackTrace(id, &stack);
|
1427
1407
|
snprintf(b->buf, sizeof(b->buf),
|
1428
|
-
"mutex@%p stack: ", static_cast<void
|
1408
|
+
"mutex@%p stack: ", static_cast<void*>(path_mu));
|
1429
1409
|
StackString(stack, depth, b->buf + strlen(b->buf),
|
1430
1410
|
static_cast<int>(sizeof(b->buf) - strlen(b->buf)),
|
1431
1411
|
symbolize);
|
1432
1412
|
ABSL_RAW_LOG(ERROR, "%s", b->buf);
|
1433
1413
|
}
|
1414
|
+
if (path_len > static_cast<int>(ABSL_ARRAYSIZE(b->path))) {
|
1415
|
+
ABSL_RAW_LOG(ERROR, "(long cycle; list truncated)");
|
1416
|
+
}
|
1434
1417
|
if (synch_deadlock_detection.load(std::memory_order_acquire) ==
|
1435
1418
|
OnDeadlockCycle::kAbort) {
|
1436
1419
|
deadlock_graph_mu.Unlock(); // avoid deadlock in fatal sighandler
|
1437
1420
|
ABSL_RAW_LOG(FATAL, "dying due to potential deadlock");
|
1438
1421
|
return mu_id;
|
1439
1422
|
}
|
1440
|
-
break;
|
1423
|
+
break; // report at most one potential deadlock per acquisition
|
1441
1424
|
}
|
1442
1425
|
}
|
1443
1426
|
|
@@ -1446,7 +1429,7 @@ static GraphId DeadlockCheck(Mutex *mu) {
|
|
1446
1429
|
|
1447
1430
|
// Invoke DeadlockCheck() iff we're in debug mode and
|
1448
1431
|
// deadlock checking has been enabled.
|
1449
|
-
static inline GraphId DebugOnlyDeadlockCheck(Mutex
|
1432
|
+
static inline GraphId DebugOnlyDeadlockCheck(Mutex* mu) {
|
1450
1433
|
if (kDebugMode && synch_deadlock_detection.load(std::memory_order_acquire) !=
|
1451
1434
|
OnDeadlockCycle::kIgnore) {
|
1452
1435
|
return DeadlockCheck(mu);
|
@@ -1473,13 +1456,13 @@ void Mutex::AssertNotHeld() const {
|
|
1473
1456
|
(mu_.load(std::memory_order_relaxed) & (kMuWriter | kMuReader)) != 0 &&
|
1474
1457
|
synch_deadlock_detection.load(std::memory_order_acquire) !=
|
1475
1458
|
OnDeadlockCycle::kIgnore) {
|
1476
|
-
GraphId id = GetGraphId(const_cast<Mutex
|
1477
|
-
SynchLocksHeld
|
1459
|
+
GraphId id = GetGraphId(const_cast<Mutex*>(this));
|
1460
|
+
SynchLocksHeld* locks = Synch_GetAllLocks();
|
1478
1461
|
for (int i = 0; i != locks->n; i++) {
|
1479
1462
|
if (locks->locks[i].id == id) {
|
1480
|
-
SynchEvent
|
1463
|
+
SynchEvent* mu_events = GetSynchEvent(this);
|
1481
1464
|
ABSL_RAW_LOG(FATAL, "thread should not hold mutex %p %s",
|
1482
|
-
static_cast<const void
|
1465
|
+
static_cast<const void*>(this),
|
1483
1466
|
(mu_events == nullptr ? "" : mu_events->name));
|
1484
1467
|
}
|
1485
1468
|
}
|
@@ -1492,8 +1475,8 @@ static bool TryAcquireWithSpinning(std::atomic<intptr_t>* mu) {
|
|
1492
1475
|
int c = GetMutexGlobals().spinloop_iterations;
|
1493
1476
|
do { // do/while somewhat faster on AMD
|
1494
1477
|
intptr_t v = mu->load(std::memory_order_relaxed);
|
1495
|
-
if ((v & (kMuReader|kMuEvent)) != 0) {
|
1496
|
-
return false;
|
1478
|
+
if ((v & (kMuReader | kMuEvent)) != 0) {
|
1479
|
+
return false; // a reader or tracing -> give up
|
1497
1480
|
} else if (((v & kMuWriter) == 0) && // no holder -> try to acquire
|
1498
1481
|
mu->compare_exchange_strong(v, kMuWriter | v,
|
1499
1482
|
std::memory_order_acquire,
|
@@ -1510,8 +1493,7 @@ void Mutex::Lock() {
|
|
1510
1493
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1511
1494
|
// try fast acquire, then spin loop
|
1512
1495
|
if ((v & (kMuWriter | kMuReader | kMuEvent)) != 0 ||
|
1513
|
-
!mu_.compare_exchange_strong(v, kMuWriter | v,
|
1514
|
-
std::memory_order_acquire,
|
1496
|
+
!mu_.compare_exchange_strong(v, kMuWriter | v, std::memory_order_acquire,
|
1515
1497
|
std::memory_order_relaxed)) {
|
1516
1498
|
// try spin acquire, then slow loop
|
1517
1499
|
if (!TryAcquireWithSpinning(&this->mu_)) {
|
@@ -1537,7 +1519,7 @@ void Mutex::ReaderLock() {
|
|
1537
1519
|
ABSL_TSAN_MUTEX_POST_LOCK(this, __tsan_mutex_read_lock, 0);
|
1538
1520
|
}
|
1539
1521
|
|
1540
|
-
void Mutex::LockWhen(const Condition
|
1522
|
+
void Mutex::LockWhen(const Condition& cond) {
|
1541
1523
|
ABSL_TSAN_MUTEX_PRE_LOCK(this, 0);
|
1542
1524
|
GraphId id = DebugOnlyDeadlockCheck(this);
|
1543
1525
|
this->LockSlow(kExclusive, &cond, 0);
|
@@ -1545,21 +1527,26 @@ void Mutex::LockWhen(const Condition &cond) {
|
|
1545
1527
|
ABSL_TSAN_MUTEX_POST_LOCK(this, 0, 0);
|
1546
1528
|
}
|
1547
1529
|
|
1548
|
-
bool Mutex::LockWhenWithTimeout(const Condition
|
1549
|
-
|
1530
|
+
bool Mutex::LockWhenWithTimeout(const Condition& cond, absl::Duration timeout) {
|
1531
|
+
ABSL_TSAN_MUTEX_PRE_LOCK(this, 0);
|
1532
|
+
GraphId id = DebugOnlyDeadlockCheck(this);
|
1533
|
+
bool res = LockSlowWithDeadline(kExclusive, &cond, KernelTimeout(timeout), 0);
|
1534
|
+
DebugOnlyLockEnter(this, id);
|
1535
|
+
ABSL_TSAN_MUTEX_POST_LOCK(this, 0, 0);
|
1536
|
+
return res;
|
1550
1537
|
}
|
1551
1538
|
|
1552
|
-
bool Mutex::LockWhenWithDeadline(const Condition
|
1539
|
+
bool Mutex::LockWhenWithDeadline(const Condition& cond, absl::Time deadline) {
|
1553
1540
|
ABSL_TSAN_MUTEX_PRE_LOCK(this, 0);
|
1554
1541
|
GraphId id = DebugOnlyDeadlockCheck(this);
|
1555
|
-
bool res =
|
1556
|
-
|
1542
|
+
bool res =
|
1543
|
+
LockSlowWithDeadline(kExclusive, &cond, KernelTimeout(deadline), 0);
|
1557
1544
|
DebugOnlyLockEnter(this, id);
|
1558
1545
|
ABSL_TSAN_MUTEX_POST_LOCK(this, 0, 0);
|
1559
1546
|
return res;
|
1560
1547
|
}
|
1561
1548
|
|
1562
|
-
void Mutex::ReaderLockWhen(const Condition
|
1549
|
+
void Mutex::ReaderLockWhen(const Condition& cond) {
|
1563
1550
|
ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_read_lock);
|
1564
1551
|
GraphId id = DebugOnlyDeadlockCheck(this);
|
1565
1552
|
this->LockSlow(kShared, &cond, 0);
|
@@ -1567,12 +1554,17 @@ void Mutex::ReaderLockWhen(const Condition &cond) {
|
|
1567
1554
|
ABSL_TSAN_MUTEX_POST_LOCK(this, __tsan_mutex_read_lock, 0);
|
1568
1555
|
}
|
1569
1556
|
|
1570
|
-
bool Mutex::ReaderLockWhenWithTimeout(const Condition
|
1557
|
+
bool Mutex::ReaderLockWhenWithTimeout(const Condition& cond,
|
1571
1558
|
absl::Duration timeout) {
|
1572
|
-
|
1559
|
+
ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_read_lock);
|
1560
|
+
GraphId id = DebugOnlyDeadlockCheck(this);
|
1561
|
+
bool res = LockSlowWithDeadline(kShared, &cond, KernelTimeout(timeout), 0);
|
1562
|
+
DebugOnlyLockEnter(this, id);
|
1563
|
+
ABSL_TSAN_MUTEX_POST_LOCK(this, __tsan_mutex_read_lock, 0);
|
1564
|
+
return res;
|
1573
1565
|
}
|
1574
1566
|
|
1575
|
-
bool Mutex::ReaderLockWhenWithDeadline(const Condition
|
1567
|
+
bool Mutex::ReaderLockWhenWithDeadline(const Condition& cond,
|
1576
1568
|
absl::Time deadline) {
|
1577
1569
|
ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_read_lock);
|
1578
1570
|
GraphId id = DebugOnlyDeadlockCheck(this);
|
@@ -1582,23 +1574,34 @@ bool Mutex::ReaderLockWhenWithDeadline(const Condition &cond,
|
|
1582
1574
|
return res;
|
1583
1575
|
}
|
1584
1576
|
|
1585
|
-
void Mutex::Await(const Condition
|
1586
|
-
if (cond.Eval()) {
|
1577
|
+
void Mutex::Await(const Condition& cond) {
|
1578
|
+
if (cond.Eval()) { // condition already true; nothing to do
|
1587
1579
|
if (kDebugMode) {
|
1588
1580
|
this->AssertReaderHeld();
|
1589
1581
|
}
|
1590
|
-
} else {
|
1582
|
+
} else { // normal case
|
1591
1583
|
ABSL_RAW_CHECK(this->AwaitCommon(cond, KernelTimeout::Never()),
|
1592
1584
|
"condition untrue on return from Await");
|
1593
1585
|
}
|
1594
1586
|
}
|
1595
1587
|
|
1596
|
-
bool Mutex::AwaitWithTimeout(const Condition
|
1597
|
-
|
1588
|
+
bool Mutex::AwaitWithTimeout(const Condition& cond, absl::Duration timeout) {
|
1589
|
+
if (cond.Eval()) { // condition already true; nothing to do
|
1590
|
+
if (kDebugMode) {
|
1591
|
+
this->AssertReaderHeld();
|
1592
|
+
}
|
1593
|
+
return true;
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
KernelTimeout t{timeout};
|
1597
|
+
bool res = this->AwaitCommon(cond, t);
|
1598
|
+
ABSL_RAW_CHECK(res || t.has_timeout(),
|
1599
|
+
"condition untrue on return from Await");
|
1600
|
+
return res;
|
1598
1601
|
}
|
1599
1602
|
|
1600
|
-
bool Mutex::AwaitWithDeadline(const Condition
|
1601
|
-
if (cond.Eval()) {
|
1603
|
+
bool Mutex::AwaitWithDeadline(const Condition& cond, absl::Time deadline) {
|
1604
|
+
if (cond.Eval()) { // condition already true; nothing to do
|
1602
1605
|
if (kDebugMode) {
|
1603
1606
|
this->AssertReaderHeld();
|
1604
1607
|
}
|
@@ -1612,14 +1615,14 @@ bool Mutex::AwaitWithDeadline(const Condition &cond, absl::Time deadline) {
|
|
1612
1615
|
return res;
|
1613
1616
|
}
|
1614
1617
|
|
1615
|
-
bool Mutex::AwaitCommon(const Condition
|
1618
|
+
bool Mutex::AwaitCommon(const Condition& cond, KernelTimeout t) {
|
1616
1619
|
this->AssertReaderHeld();
|
1617
1620
|
MuHow how =
|
1618
1621
|
(mu_.load(std::memory_order_relaxed) & kMuWriter) ? kExclusive : kShared;
|
1619
1622
|
ABSL_TSAN_MUTEX_PRE_UNLOCK(this, TsanFlags(how));
|
1620
|
-
SynchWaitParams waitp(
|
1621
|
-
|
1622
|
-
|
1623
|
+
SynchWaitParams waitp(how, &cond, t, nullptr /*no cvmu*/,
|
1624
|
+
Synch_GetPerThreadAnnotated(this),
|
1625
|
+
nullptr /*no cv_word*/);
|
1623
1626
|
int flags = kMuHasBlocked;
|
1624
1627
|
if (!Condition::GuaranteedEqual(&cond, nullptr)) {
|
1625
1628
|
flags |= kMuIsCond;
|
@@ -1639,14 +1642,13 @@ bool Mutex::TryLock() {
|
|
1639
1642
|
ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_try_lock);
|
1640
1643
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1641
1644
|
if ((v & (kMuWriter | kMuReader | kMuEvent)) == 0 && // try fast acquire
|
1642
|
-
mu_.compare_exchange_strong(v, kMuWriter | v,
|
1643
|
-
std::memory_order_acquire,
|
1645
|
+
mu_.compare_exchange_strong(v, kMuWriter | v, std::memory_order_acquire,
|
1644
1646
|
std::memory_order_relaxed)) {
|
1645
1647
|
DebugOnlyLockEnter(this);
|
1646
1648
|
ABSL_TSAN_MUTEX_POST_LOCK(this, __tsan_mutex_try_lock, 0);
|
1647
1649
|
return true;
|
1648
1650
|
}
|
1649
|
-
if ((v & kMuEvent) != 0) {
|
1651
|
+
if ((v & kMuEvent) != 0) { // we're recording events
|
1650
1652
|
if ((v & kExclusive->slow_need_zero) == 0 && // try fast acquire
|
1651
1653
|
mu_.compare_exchange_strong(
|
1652
1654
|
v, (kExclusive->fast_or | v) + kExclusive->fast_add,
|
@@ -1672,7 +1674,7 @@ bool Mutex::ReaderTryLock() {
|
|
1672
1674
|
// changing (typically because the reader count changes) under the CAS. We
|
1673
1675
|
// limit the number of attempts to avoid having to think about livelock.
|
1674
1676
|
int loop_limit = 5;
|
1675
|
-
while ((v & (kMuWriter|kMuWait|kMuEvent)) == 0 && loop_limit != 0) {
|
1677
|
+
while ((v & (kMuWriter | kMuWait | kMuEvent)) == 0 && loop_limit != 0) {
|
1676
1678
|
if (mu_.compare_exchange_strong(v, (kMuReader | v) + kMuOne,
|
1677
1679
|
std::memory_order_acquire,
|
1678
1680
|
std::memory_order_relaxed)) {
|
@@ -1684,7 +1686,7 @@ bool Mutex::ReaderTryLock() {
|
|
1684
1686
|
loop_limit--;
|
1685
1687
|
v = mu_.load(std::memory_order_relaxed);
|
1686
1688
|
}
|
1687
|
-
if ((v & kMuEvent) != 0) {
|
1689
|
+
if ((v & kMuEvent) != 0) { // we're recording events
|
1688
1690
|
loop_limit = 5;
|
1689
1691
|
while ((v & kShared->slow_need_zero) == 0 && loop_limit != 0) {
|
1690
1692
|
if (mu_.compare_exchange_strong(v, (kMuReader | v) + kMuOne,
|
@@ -1723,7 +1725,7 @@ void Mutex::Unlock() {
|
|
1723
1725
|
// should_try_cas is whether we'll try a compare-and-swap immediately.
|
1724
1726
|
// NOTE: optimized out when kDebugMode is false.
|
1725
1727
|
bool should_try_cas = ((v & (kMuEvent | kMuWriter)) == kMuWriter &&
|
1726
|
-
|
1728
|
+
(v & (kMuWait | kMuDesig)) != kMuWait);
|
1727
1729
|
// But, we can use an alternate computation of it, that compilers
|
1728
1730
|
// currently don't find on their own. When that changes, this function
|
1729
1731
|
// can be simplified.
|
@@ -1740,10 +1742,9 @@ void Mutex::Unlock() {
|
|
1740
1742
|
static_cast<long long>(v), static_cast<long long>(x),
|
1741
1743
|
static_cast<long long>(y));
|
1742
1744
|
}
|
1743
|
-
if (x < y &&
|
1744
|
-
|
1745
|
-
|
1746
|
-
std::memory_order_relaxed)) {
|
1745
|
+
if (x < y && mu_.compare_exchange_strong(v, v & ~(kMuWrWait | kMuWriter),
|
1746
|
+
std::memory_order_release,
|
1747
|
+
std::memory_order_relaxed)) {
|
1747
1748
|
// fast writer release (writer with no waiters or with designated waker)
|
1748
1749
|
} else {
|
1749
1750
|
this->UnlockSlow(nullptr /*no waitp*/); // take slow path
|
@@ -1753,7 +1754,7 @@ void Mutex::Unlock() {
|
|
1753
1754
|
|
1754
1755
|
// Requires v to represent a reader-locked state.
|
1755
1756
|
static bool ExactlyOneReader(intptr_t v) {
|
1756
|
-
assert((v & (kMuWriter|kMuReader)) == kMuReader);
|
1757
|
+
assert((v & (kMuWriter | kMuReader)) == kMuReader);
|
1757
1758
|
assert((v & kMuHigh) != 0);
|
1758
1759
|
// The more straightforward "(v & kMuHigh) == kMuOne" also works, but
|
1759
1760
|
// on some architectures the following generates slightly smaller code.
|
@@ -1766,12 +1767,11 @@ void Mutex::ReaderUnlock() {
|
|
1766
1767
|
ABSL_TSAN_MUTEX_PRE_UNLOCK(this, __tsan_mutex_read_lock);
|
1767
1768
|
DebugOnlyLockLeave(this);
|
1768
1769
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1769
|
-
assert((v & (kMuWriter|kMuReader)) == kMuReader);
|
1770
|
-
if ((v & (kMuReader|kMuWait|kMuEvent)) == kMuReader) {
|
1770
|
+
assert((v & (kMuWriter | kMuReader)) == kMuReader);
|
1771
|
+
if ((v & (kMuReader | kMuWait | kMuEvent)) == kMuReader) {
|
1771
1772
|
// fast reader release (reader with no waiters)
|
1772
|
-
intptr_t clear = ExactlyOneReader(v) ? kMuReader|kMuOne : kMuOne;
|
1773
|
-
if (mu_.compare_exchange_strong(v, v - clear,
|
1774
|
-
std::memory_order_release,
|
1773
|
+
intptr_t clear = ExactlyOneReader(v) ? kMuReader | kMuOne : kMuOne;
|
1774
|
+
if (mu_.compare_exchange_strong(v, v - clear, std::memory_order_release,
|
1775
1775
|
std::memory_order_relaxed)) {
|
1776
1776
|
ABSL_TSAN_MUTEX_POST_UNLOCK(this, __tsan_mutex_read_lock);
|
1777
1777
|
return;
|
@@ -1810,7 +1810,7 @@ static intptr_t IgnoreWaitingWritersMask(int flag) {
|
|
1810
1810
|
}
|
1811
1811
|
|
1812
1812
|
// Internal version of LockWhen(). See LockSlowWithDeadline()
|
1813
|
-
ABSL_ATTRIBUTE_NOINLINE void Mutex::LockSlow(MuHow how, const Condition
|
1813
|
+
ABSL_ATTRIBUTE_NOINLINE void Mutex::LockSlow(MuHow how, const Condition* cond,
|
1814
1814
|
int flags) {
|
1815
1815
|
ABSL_RAW_CHECK(
|
1816
1816
|
this->LockSlowWithDeadline(how, cond, KernelTimeout::Never(), flags),
|
@@ -1818,7 +1818,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::LockSlow(MuHow how, const Condition *cond,
|
|
1818
1818
|
}
|
1819
1819
|
|
1820
1820
|
// Compute cond->Eval() and tell race detectors that we do it under mutex mu.
|
1821
|
-
static inline bool EvalConditionAnnotated(const Condition
|
1821
|
+
static inline bool EvalConditionAnnotated(const Condition* cond, Mutex* mu,
|
1822
1822
|
bool locking, bool trylock,
|
1823
1823
|
bool read_lock) {
|
1824
1824
|
// Delicate annotation dance.
|
@@ -1868,7 +1868,7 @@ static inline bool EvalConditionAnnotated(const Condition *cond, Mutex *mu,
|
|
1868
1868
|
// tsan). As the result there is no tsan-visible synchronization between the
|
1869
1869
|
// addition and this thread. So if we would enable race detection here,
|
1870
1870
|
// it would race with the predicate initialization.
|
1871
|
-
static inline bool EvalConditionIgnored(Mutex
|
1871
|
+
static inline bool EvalConditionIgnored(Mutex* mu, const Condition* cond) {
|
1872
1872
|
// Memory accesses are already ignored inside of lock/unlock operations,
|
1873
1873
|
// but synchronization operations are also ignored. When we evaluate the
|
1874
1874
|
// predicate we must ignore only memory accesses but not synchronization,
|
@@ -1893,7 +1893,7 @@ static inline bool EvalConditionIgnored(Mutex *mu, const Condition *cond) {
|
|
1893
1893
|
// obstruct this call
|
1894
1894
|
// - kMuIsCond indicates that this is a conditional acquire (condition variable,
|
1895
1895
|
// Await, LockWhen) so contention profiling should be suppressed.
|
1896
|
-
bool Mutex::LockSlowWithDeadline(MuHow how, const Condition
|
1896
|
+
bool Mutex::LockSlowWithDeadline(MuHow how, const Condition* cond,
|
1897
1897
|
KernelTimeout t, int flags) {
|
1898
1898
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1899
1899
|
bool unlock = false;
|
@@ -1910,9 +1910,9 @@ bool Mutex::LockSlowWithDeadline(MuHow how, const Condition *cond,
|
|
1910
1910
|
}
|
1911
1911
|
unlock = true;
|
1912
1912
|
}
|
1913
|
-
SynchWaitParams waitp(
|
1914
|
-
|
1915
|
-
|
1913
|
+
SynchWaitParams waitp(how, cond, t, nullptr /*no cvmu*/,
|
1914
|
+
Synch_GetPerThreadAnnotated(this),
|
1915
|
+
nullptr /*no cv_word*/);
|
1916
1916
|
if (!Condition::GuaranteedEqual(cond, nullptr)) {
|
1917
1917
|
flags |= kMuIsCond;
|
1918
1918
|
}
|
@@ -1953,20 +1953,20 @@ static void CheckForMutexCorruption(intptr_t v, const char* label) {
|
|
1953
1953
|
if (ABSL_PREDICT_TRUE((w & (w << 3) & (kMuWriter | kMuWrWait)) == 0)) return;
|
1954
1954
|
RAW_CHECK_FMT((v & (kMuWriter | kMuReader)) != (kMuWriter | kMuReader),
|
1955
1955
|
"%s: Mutex corrupt: both reader and writer lock held: %p",
|
1956
|
-
label, reinterpret_cast<void
|
1956
|
+
label, reinterpret_cast<void*>(v));
|
1957
1957
|
RAW_CHECK_FMT((v & (kMuWait | kMuWrWait)) != kMuWrWait,
|
1958
|
-
"%s: Mutex corrupt: waiting writer with no waiters: %p",
|
1959
|
-
|
1958
|
+
"%s: Mutex corrupt: waiting writer with no waiters: %p", label,
|
1959
|
+
reinterpret_cast<void*>(v));
|
1960
1960
|
assert(false);
|
1961
1961
|
}
|
1962
1962
|
|
1963
|
-
void Mutex::LockSlowLoop(SynchWaitParams
|
1963
|
+
void Mutex::LockSlowLoop(SynchWaitParams* waitp, int flags) {
|
1964
1964
|
SchedulingGuard::ScopedDisable disable_rescheduling;
|
1965
1965
|
int c = 0;
|
1966
1966
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
1967
1967
|
if ((v & kMuEvent) != 0) {
|
1968
|
-
PostSynchEvent(
|
1969
|
-
|
1968
|
+
PostSynchEvent(
|
1969
|
+
this, waitp->how == kExclusive ? SYNCH_EV_LOCK : SYNCH_EV_READERLOCK);
|
1970
1970
|
}
|
1971
1971
|
ABSL_RAW_CHECK(
|
1972
1972
|
waitp->thread->waitp == nullptr || waitp->thread->suppress_fatal_errors,
|
@@ -1991,11 +1991,11 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
1991
1991
|
flags |= kMuHasBlocked;
|
1992
1992
|
c = 0;
|
1993
1993
|
}
|
1994
|
-
} else {
|
1994
|
+
} else { // need to access waiter list
|
1995
1995
|
bool dowait = false;
|
1996
|
-
if ((v & (kMuSpin|kMuWait)) == 0) {
|
1996
|
+
if ((v & (kMuSpin | kMuWait)) == 0) { // no waiters
|
1997
1997
|
// This thread tries to become the one and only waiter.
|
1998
|
-
PerThreadSynch
|
1998
|
+
PerThreadSynch* new_h = Enqueue(nullptr, waitp, v, flags);
|
1999
1999
|
intptr_t nv =
|
2000
2000
|
(v & ClearDesignatedWakerMask(flags & kMuHasBlocked) & kMuLow) |
|
2001
2001
|
kMuWait;
|
@@ -2007,7 +2007,7 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2007
2007
|
v, reinterpret_cast<intptr_t>(new_h) | nv,
|
2008
2008
|
std::memory_order_release, std::memory_order_relaxed)) {
|
2009
2009
|
dowait = true;
|
2010
|
-
} else {
|
2010
|
+
} else { // attempted Enqueue() failed
|
2011
2011
|
// zero out the waitp field set by Enqueue()
|
2012
2012
|
waitp->thread->waitp = nullptr;
|
2013
2013
|
}
|
@@ -2020,9 +2020,9 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2020
2020
|
(v & ClearDesignatedWakerMask(flags & kMuHasBlocked)) |
|
2021
2021
|
kMuSpin | kMuReader,
|
2022
2022
|
std::memory_order_acquire, std::memory_order_relaxed)) {
|
2023
|
-
PerThreadSynch
|
2024
|
-
h->readers += kMuOne;
|
2025
|
-
do {
|
2023
|
+
PerThreadSynch* h = GetPerThreadSynch(v);
|
2024
|
+
h->readers += kMuOne; // inc reader count in waiter
|
2025
|
+
do { // release spinlock
|
2026
2026
|
v = mu_.load(std::memory_order_relaxed);
|
2027
2027
|
} while (!mu_.compare_exchange_weak(v, (v & ~kMuSpin) | kMuReader,
|
2028
2028
|
std::memory_order_release,
|
@@ -2032,7 +2032,7 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2032
2032
|
waitp->how == kShared)) {
|
2033
2033
|
break; // we timed out, or condition true, so return
|
2034
2034
|
}
|
2035
|
-
this->UnlockSlow(waitp);
|
2035
|
+
this->UnlockSlow(waitp); // got lock but condition false
|
2036
2036
|
this->Block(waitp->thread);
|
2037
2037
|
flags |= kMuHasBlocked;
|
2038
2038
|
c = 0;
|
@@ -2043,18 +2043,19 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2043
2043
|
(v & ClearDesignatedWakerMask(flags & kMuHasBlocked)) |
|
2044
2044
|
kMuSpin | kMuWait,
|
2045
2045
|
std::memory_order_acquire, std::memory_order_relaxed)) {
|
2046
|
-
PerThreadSynch
|
2047
|
-
PerThreadSynch
|
2046
|
+
PerThreadSynch* h = GetPerThreadSynch(v);
|
2047
|
+
PerThreadSynch* new_h = Enqueue(h, waitp, v, flags);
|
2048
2048
|
intptr_t wr_wait = 0;
|
2049
2049
|
ABSL_RAW_CHECK(new_h != nullptr, "Enqueue to list failed");
|
2050
2050
|
if (waitp->how == kExclusive && (v & kMuReader) != 0) {
|
2051
|
-
wr_wait = kMuWrWait;
|
2051
|
+
wr_wait = kMuWrWait; // give priority to a waiting writer
|
2052
2052
|
}
|
2053
|
-
do {
|
2053
|
+
do { // release spinlock
|
2054
2054
|
v = mu_.load(std::memory_order_relaxed);
|
2055
2055
|
} while (!mu_.compare_exchange_weak(
|
2056
|
-
v,
|
2057
|
-
|
2056
|
+
v,
|
2057
|
+
(v & (kMuLow & ~kMuSpin)) | kMuWait | wr_wait |
|
2058
|
+
reinterpret_cast<intptr_t>(new_h),
|
2058
2059
|
std::memory_order_release, std::memory_order_relaxed));
|
2059
2060
|
dowait = true;
|
2060
2061
|
}
|
@@ -2074,9 +2075,9 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2074
2075
|
waitp->thread->waitp == nullptr || waitp->thread->suppress_fatal_errors,
|
2075
2076
|
"detected illegal recursion into Mutex code");
|
2076
2077
|
if ((v & kMuEvent) != 0) {
|
2077
|
-
PostSynchEvent(this,
|
2078
|
-
|
2079
|
-
|
2078
|
+
PostSynchEvent(this, waitp->how == kExclusive
|
2079
|
+
? SYNCH_EV_LOCK_RETURNING
|
2080
|
+
: SYNCH_EV_READERLOCK_RETURNING);
|
2080
2081
|
}
|
2081
2082
|
}
|
2082
2083
|
|
@@ -2085,28 +2086,28 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
|
|
2085
2086
|
// which holds the lock but is not runnable because its condition is false
|
2086
2087
|
// or it is in the process of blocking on a condition variable; it must requeue
|
2087
2088
|
// itself on the mutex/condvar to wait for its condition to become true.
|
2088
|
-
ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams
|
2089
|
+
ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams* waitp) {
|
2089
2090
|
SchedulingGuard::ScopedDisable disable_rescheduling;
|
2090
2091
|
intptr_t v = mu_.load(std::memory_order_relaxed);
|
2091
2092
|
this->AssertReaderHeld();
|
2092
2093
|
CheckForMutexCorruption(v, "Unlock");
|
2093
2094
|
if ((v & kMuEvent) != 0) {
|
2094
|
-
PostSynchEvent(
|
2095
|
-
|
2095
|
+
PostSynchEvent(
|
2096
|
+
this, (v & kMuWriter) != 0 ? SYNCH_EV_UNLOCK : SYNCH_EV_READERUNLOCK);
|
2096
2097
|
}
|
2097
2098
|
int c = 0;
|
2098
2099
|
// the waiter under consideration to wake, or zero
|
2099
|
-
PerThreadSynch
|
2100
|
+
PerThreadSynch* w = nullptr;
|
2100
2101
|
// the predecessor to w or zero
|
2101
|
-
PerThreadSynch
|
2102
|
+
PerThreadSynch* pw = nullptr;
|
2102
2103
|
// head of the list searched previously, or zero
|
2103
|
-
PerThreadSynch
|
2104
|
+
PerThreadSynch* old_h = nullptr;
|
2104
2105
|
// a condition that's known to be false.
|
2105
|
-
const Condition
|
2106
|
-
PerThreadSynch
|
2107
|
-
intptr_t wr_wait = 0;
|
2108
|
-
|
2109
|
-
|
2106
|
+
const Condition* known_false = nullptr;
|
2107
|
+
PerThreadSynch* wake_list = kPerThreadSynchNull; // list of threads to wake
|
2108
|
+
intptr_t wr_wait = 0; // set to kMuWrWait if we wake a reader and a
|
2109
|
+
// later writer could have acquired the lock
|
2110
|
+
// (starvation avoidance)
|
2110
2111
|
ABSL_RAW_CHECK(waitp == nullptr || waitp->thread->waitp == nullptr ||
|
2111
2112
|
waitp->thread->suppress_fatal_errors,
|
2112
2113
|
"detected illegal recursion into Mutex code");
|
@@ -2126,8 +2127,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2126
2127
|
} else if ((v & (kMuReader | kMuWait)) == kMuReader && waitp == nullptr) {
|
2127
2128
|
// fast reader release (reader with no waiters)
|
2128
2129
|
intptr_t clear = ExactlyOneReader(v) ? kMuReader | kMuOne : kMuOne;
|
2129
|
-
if (mu_.compare_exchange_strong(v, v - clear,
|
2130
|
-
std::memory_order_release,
|
2130
|
+
if (mu_.compare_exchange_strong(v, v - clear, std::memory_order_release,
|
2131
2131
|
std::memory_order_relaxed)) {
|
2132
2132
|
return;
|
2133
2133
|
}
|
@@ -2135,16 +2135,16 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2135
2135
|
mu_.compare_exchange_strong(v, v | kMuSpin,
|
2136
2136
|
std::memory_order_acquire,
|
2137
2137
|
std::memory_order_relaxed)) {
|
2138
|
-
if ((v & kMuWait) == 0) {
|
2138
|
+
if ((v & kMuWait) == 0) { // no one to wake
|
2139
2139
|
intptr_t nv;
|
2140
2140
|
bool do_enqueue = true; // always Enqueue() the first time
|
2141
2141
|
ABSL_RAW_CHECK(waitp != nullptr,
|
2142
2142
|
"UnlockSlow is confused"); // about to sleep
|
2143
|
-
do {
|
2143
|
+
do { // must loop to release spinlock as reader count may change
|
2144
2144
|
v = mu_.load(std::memory_order_relaxed);
|
2145
2145
|
// decrement reader count if there are readers
|
2146
|
-
intptr_t new_readers = (v >= kMuOne)?
|
2147
|
-
PerThreadSynch
|
2146
|
+
intptr_t new_readers = (v >= kMuOne) ? v - kMuOne : v;
|
2147
|
+
PerThreadSynch* new_h = nullptr;
|
2148
2148
|
if (do_enqueue) {
|
2149
2149
|
// If we are enqueuing on a CondVar (waitp->cv_word != nullptr) then
|
2150
2150
|
// we must not retry here. The initial attempt will always have
|
@@ -2168,21 +2168,20 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2168
2168
|
}
|
2169
2169
|
// release spinlock & our lock; retry if reader-count changed
|
2170
2170
|
// (writer count cannot change since we hold lock)
|
2171
|
-
} while (!mu_.compare_exchange_weak(v, nv,
|
2172
|
-
std::memory_order_release,
|
2171
|
+
} while (!mu_.compare_exchange_weak(v, nv, std::memory_order_release,
|
2173
2172
|
std::memory_order_relaxed));
|
2174
2173
|
break;
|
2175
2174
|
}
|
2176
2175
|
|
2177
2176
|
// There are waiters.
|
2178
2177
|
// Set h to the head of the circular waiter list.
|
2179
|
-
PerThreadSynch
|
2178
|
+
PerThreadSynch* h = GetPerThreadSynch(v);
|
2180
2179
|
if ((v & kMuReader) != 0 && (h->readers & kMuHigh) > kMuOne) {
|
2181
2180
|
// a reader but not the last
|
2182
|
-
h->readers -= kMuOne;
|
2183
|
-
intptr_t nv = v;
|
2181
|
+
h->readers -= kMuOne; // release our lock
|
2182
|
+
intptr_t nv = v; // normally just release spinlock
|
2184
2183
|
if (waitp != nullptr) { // but waitp!=nullptr => must queue ourselves
|
2185
|
-
PerThreadSynch
|
2184
|
+
PerThreadSynch* new_h = Enqueue(h, waitp, v, kMuIsCond);
|
2186
2185
|
ABSL_RAW_CHECK(new_h != nullptr,
|
2187
2186
|
"waiters disappeared during Enqueue()!");
|
2188
2187
|
nv &= kMuLow;
|
@@ -2200,8 +2199,8 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2200
2199
|
|
2201
2200
|
// The lock is becoming free, and there's a waiter
|
2202
2201
|
if (old_h != nullptr &&
|
2203
|
-
!old_h->may_skip) {
|
2204
|
-
old_h->may_skip = true;
|
2202
|
+
!old_h->may_skip) { // we used old_h as a terminator
|
2203
|
+
old_h->may_skip = true; // allow old_h to skip once more
|
2205
2204
|
ABSL_RAW_CHECK(old_h->skip == nullptr, "illegal skip from head");
|
2206
2205
|
if (h != old_h && MuEquivalentWaiter(old_h, old_h->next)) {
|
2207
2206
|
old_h->skip = old_h->next; // old_h not head & can skip to successor
|
@@ -2210,7 +2209,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2210
2209
|
if (h->next->waitp->how == kExclusive &&
|
2211
2210
|
Condition::GuaranteedEqual(h->next->waitp->cond, nullptr)) {
|
2212
2211
|
// easy case: writer with no condition; no need to search
|
2213
|
-
pw = h;
|
2212
|
+
pw = h; // wake w, the successor of h (=pw)
|
2214
2213
|
w = h->next;
|
2215
2214
|
w->wake = true;
|
2216
2215
|
// We are waking up a writer. This writer may be racing against
|
@@ -2233,13 +2232,13 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2233
2232
|
// waiter has a condition or is a reader. We avoid searching over
|
2234
2233
|
// waiters we've searched on previous iterations by starting at
|
2235
2234
|
// old_h if it's set. If old_h==h, there's no one to wakeup at all.
|
2236
|
-
if (old_h == h) {
|
2237
|
-
|
2238
|
-
intptr_t nv = (v & ~(kMuReader|kMuWriter|kMuWrWait));
|
2235
|
+
if (old_h == h) { // we've searched before, and nothing's new
|
2236
|
+
// so there's no one to wake.
|
2237
|
+
intptr_t nv = (v & ~(kMuReader | kMuWriter | kMuWrWait));
|
2239
2238
|
h->readers = 0;
|
2240
|
-
h->maybe_unlocking = false;
|
2241
|
-
if (waitp != nullptr) {
|
2242
|
-
PerThreadSynch
|
2239
|
+
h->maybe_unlocking = false; // finished unlocking
|
2240
|
+
if (waitp != nullptr) { // we must queue ourselves and sleep
|
2241
|
+
PerThreadSynch* new_h = Enqueue(h, waitp, v, kMuIsCond);
|
2243
2242
|
nv &= kMuLow;
|
2244
2243
|
if (new_h != nullptr) {
|
2245
2244
|
nv |= kMuWait | reinterpret_cast<intptr_t>(new_h);
|
@@ -2253,12 +2252,12 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2253
2252
|
}
|
2254
2253
|
|
2255
2254
|
// set up to walk the list
|
2256
|
-
PerThreadSynch
|
2257
|
-
PerThreadSynch
|
2255
|
+
PerThreadSynch* w_walk; // current waiter during list walk
|
2256
|
+
PerThreadSynch* pw_walk; // previous waiter during list walk
|
2258
2257
|
if (old_h != nullptr) { // we've searched up to old_h before
|
2259
2258
|
pw_walk = old_h;
|
2260
2259
|
w_walk = old_h->next;
|
2261
|
-
} else {
|
2260
|
+
} else { // no prior search, start at beginning
|
2262
2261
|
pw_walk =
|
2263
2262
|
nullptr; // h->next's predecessor may change; don't record it
|
2264
2263
|
w_walk = h->next;
|
@@ -2284,7 +2283,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2284
2283
|
// to walk the path from w_walk to h inclusive. (TryRemove() can remove
|
2285
2284
|
// a waiter anywhere, but it acquires both the spinlock and the Mutex)
|
2286
2285
|
|
2287
|
-
old_h = h;
|
2286
|
+
old_h = h; // remember we searched to here
|
2288
2287
|
|
2289
2288
|
// Walk the path upto and including h looking for waiters we can wake.
|
2290
2289
|
while (pw_walk != h) {
|
@@ -2296,24 +2295,24 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2296
2295
|
// is in fact true
|
2297
2296
|
EvalConditionIgnored(this, w_walk->waitp->cond))) {
|
2298
2297
|
if (w == nullptr) {
|
2299
|
-
w_walk->wake = true;
|
2298
|
+
w_walk->wake = true; // can wake this waiter
|
2300
2299
|
w = w_walk;
|
2301
2300
|
pw = pw_walk;
|
2302
2301
|
if (w_walk->waitp->how == kExclusive) {
|
2303
2302
|
wr_wait = kMuWrWait;
|
2304
|
-
break;
|
2303
|
+
break; // bail if waking this writer
|
2305
2304
|
}
|
2306
2305
|
} else if (w_walk->waitp->how == kShared) { // wake if a reader
|
2307
2306
|
w_walk->wake = true;
|
2308
|
-
} else {
|
2307
|
+
} else { // writer with true condition
|
2309
2308
|
wr_wait = kMuWrWait;
|
2310
2309
|
}
|
2311
|
-
} else {
|
2310
|
+
} else { // can't wake; condition false
|
2312
2311
|
known_false = w_walk->waitp->cond; // remember last false condition
|
2313
2312
|
}
|
2314
|
-
if (w_walk->wake) {
|
2315
|
-
pw_walk = w_walk;
|
2316
|
-
} else {
|
2313
|
+
if (w_walk->wake) { // we're waking reader w_walk
|
2314
|
+
pw_walk = w_walk; // don't skip similar waiters
|
2315
|
+
} else { // not waking; skip as much as possible
|
2317
2316
|
pw_walk = Skip(w_walk);
|
2318
2317
|
}
|
2319
2318
|
// If pw_walk == h, then load of pw_walk->next can race with
|
@@ -2340,8 +2339,8 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2340
2339
|
h = DequeueAllWakeable(h, pw, &wake_list);
|
2341
2340
|
|
2342
2341
|
intptr_t nv = (v & kMuEvent) | kMuDesig;
|
2343
|
-
|
2344
|
-
|
2342
|
+
// assume no waiters left,
|
2343
|
+
// set kMuDesig for INV1a
|
2345
2344
|
|
2346
2345
|
if (waitp != nullptr) { // we must queue ourselves and sleep
|
2347
2346
|
h = Enqueue(h, waitp, v, kMuIsCond);
|
@@ -2354,7 +2353,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2354
2353
|
|
2355
2354
|
if (h != nullptr) { // there are waiters left
|
2356
2355
|
h->readers = 0;
|
2357
|
-
h->maybe_unlocking = false;
|
2356
|
+
h->maybe_unlocking = false; // finished unlocking
|
2358
2357
|
nv |= wr_wait | kMuWait | reinterpret_cast<intptr_t>(h);
|
2359
2358
|
}
|
2360
2359
|
|
@@ -2365,12 +2364,12 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2365
2364
|
}
|
2366
2365
|
// aggressive here; no one can proceed till we do
|
2367
2366
|
c = synchronization_internal::MutexDelay(c, AGGRESSIVE);
|
2368
|
-
}
|
2367
|
+
} // end of for(;;)-loop
|
2369
2368
|
|
2370
2369
|
if (wake_list != kPerThreadSynchNull) {
|
2371
2370
|
int64_t total_wait_cycles = 0;
|
2372
2371
|
int64_t max_wait_cycles = 0;
|
2373
|
-
int64_t now =
|
2372
|
+
int64_t now = CycleClock::Now();
|
2374
2373
|
do {
|
2375
2374
|
// Profile lock contention events only if the waiter was trying to acquire
|
2376
2375
|
// the lock, not waiting on a condition variable or Condition.
|
@@ -2382,7 +2381,7 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
|
|
2382
2381
|
wake_list->waitp->contention_start_cycles = now;
|
2383
2382
|
wake_list->waitp->should_submit_contention_data = true;
|
2384
2383
|
}
|
2385
|
-
wake_list = Wakeup(wake_list);
|
2384
|
+
wake_list = Wakeup(wake_list); // wake waiters
|
2386
2385
|
} while (wake_list != kPerThreadSynchNull);
|
2387
2386
|
if (total_wait_cycles > 0) {
|
2388
2387
|
mutex_tracer("slow release", this, total_wait_cycles);
|
@@ -2410,7 +2409,7 @@ void Mutex::Trans(MuHow how) {
|
|
2410
2409
|
// condition variable. If this mutex is free, we simply wake the thread.
|
2411
2410
|
// It will later acquire the mutex with high probability. Otherwise, we
|
2412
2411
|
// enqueue thread w on this mutex.
|
2413
|
-
void Mutex::Fer(PerThreadSynch
|
2412
|
+
void Mutex::Fer(PerThreadSynch* w) {
|
2414
2413
|
SchedulingGuard::ScopedDisable disable_rescheduling;
|
2415
2414
|
int c = 0;
|
2416
2415
|
ABSL_RAW_CHECK(w->waitp->cond == nullptr,
|
@@ -2435,9 +2434,9 @@ void Mutex::Fer(PerThreadSynch *w) {
|
|
2435
2434
|
IncrementSynchSem(this, w);
|
2436
2435
|
return;
|
2437
2436
|
} else {
|
2438
|
-
if ((v & (kMuSpin|kMuWait)) == 0) {
|
2437
|
+
if ((v & (kMuSpin | kMuWait)) == 0) { // no waiters
|
2439
2438
|
// This thread tries to become the one and only waiter.
|
2440
|
-
PerThreadSynch
|
2439
|
+
PerThreadSynch* new_h = Enqueue(nullptr, w->waitp, v, kMuIsCond);
|
2441
2440
|
ABSL_RAW_CHECK(new_h != nullptr,
|
2442
2441
|
"Enqueue failed"); // we must queue ourselves
|
2443
2442
|
if (mu_.compare_exchange_strong(
|
@@ -2447,8 +2446,8 @@ void Mutex::Fer(PerThreadSynch *w) {
|
|
2447
2446
|
}
|
2448
2447
|
} else if ((v & kMuSpin) == 0 &&
|
2449
2448
|
mu_.compare_exchange_strong(v, v | kMuSpin | kMuWait)) {
|
2450
|
-
PerThreadSynch
|
2451
|
-
PerThreadSynch
|
2449
|
+
PerThreadSynch* h = GetPerThreadSynch(v);
|
2450
|
+
PerThreadSynch* new_h = Enqueue(h, w->waitp, v, kMuIsCond);
|
2452
2451
|
ABSL_RAW_CHECK(new_h != nullptr,
|
2453
2452
|
"Enqueue failed"); // we must queue ourselves
|
2454
2453
|
do {
|
@@ -2467,19 +2466,18 @@ void Mutex::Fer(PerThreadSynch *w) {
|
|
2467
2466
|
|
2468
2467
|
void Mutex::AssertHeld() const {
|
2469
2468
|
if ((mu_.load(std::memory_order_relaxed) & kMuWriter) == 0) {
|
2470
|
-
SynchEvent
|
2469
|
+
SynchEvent* e = GetSynchEvent(this);
|
2471
2470
|
ABSL_RAW_LOG(FATAL, "thread should hold write lock on Mutex %p %s",
|
2472
|
-
static_cast<const void
|
2473
|
-
(e == nullptr ? "" : e->name));
|
2471
|
+
static_cast<const void*>(this), (e == nullptr ? "" : e->name));
|
2474
2472
|
}
|
2475
2473
|
}
|
2476
2474
|
|
2477
2475
|
void Mutex::AssertReaderHeld() const {
|
2478
2476
|
if ((mu_.load(std::memory_order_relaxed) & (kMuReader | kMuWriter)) == 0) {
|
2479
|
-
SynchEvent
|
2480
|
-
ABSL_RAW_LOG(
|
2481
|
-
|
2482
|
-
|
2477
|
+
SynchEvent* e = GetSynchEvent(this);
|
2478
|
+
ABSL_RAW_LOG(FATAL,
|
2479
|
+
"thread should hold at least a read lock on Mutex %p %s",
|
2480
|
+
static_cast<const void*>(this), (e == nullptr ? "" : e->name));
|
2483
2481
|
}
|
2484
2482
|
}
|
2485
2483
|
|
@@ -2490,13 +2488,17 @@ static const intptr_t kCvEvent = 0x0002L; // record events
|
|
2490
2488
|
static const intptr_t kCvLow = 0x0003L; // low order bits of CV
|
2491
2489
|
|
2492
2490
|
// Hack to make constant values available to gdb pretty printer
|
2493
|
-
enum {
|
2491
|
+
enum {
|
2492
|
+
kGdbCvSpin = kCvSpin,
|
2493
|
+
kGdbCvEvent = kCvEvent,
|
2494
|
+
kGdbCvLow = kCvLow,
|
2495
|
+
};
|
2494
2496
|
|
2495
2497
|
static_assert(PerThreadSynch::kAlignment > kCvLow,
|
2496
2498
|
"PerThreadSynch::kAlignment must be greater than kCvLow");
|
2497
2499
|
|
2498
|
-
void CondVar::EnableDebugLog(const char
|
2499
|
-
SynchEvent
|
2500
|
+
void CondVar::EnableDebugLog(const char* name) {
|
2501
|
+
SynchEvent* e = EnsureSynchEvent(&this->cv_, name, kCvEvent, kCvSpin);
|
2500
2502
|
e->log = true;
|
2501
2503
|
UnrefSynchEvent(e);
|
2502
2504
|
}
|
@@ -2507,25 +2509,23 @@ CondVar::~CondVar() {
|
|
2507
2509
|
}
|
2508
2510
|
}
|
2509
2511
|
|
2510
|
-
|
2511
2512
|
// Remove thread s from the list of waiters on this condition variable.
|
2512
|
-
void CondVar::Remove(PerThreadSynch
|
2513
|
+
void CondVar::Remove(PerThreadSynch* s) {
|
2513
2514
|
SchedulingGuard::ScopedDisable disable_rescheduling;
|
2514
2515
|
intptr_t v;
|
2515
2516
|
int c = 0;
|
2516
2517
|
for (v = cv_.load(std::memory_order_relaxed);;
|
2517
2518
|
v = cv_.load(std::memory_order_relaxed)) {
|
2518
2519
|
if ((v & kCvSpin) == 0 && // attempt to acquire spinlock
|
2519
|
-
cv_.compare_exchange_strong(v, v | kCvSpin,
|
2520
|
-
std::memory_order_acquire,
|
2520
|
+
cv_.compare_exchange_strong(v, v | kCvSpin, std::memory_order_acquire,
|
2521
2521
|
std::memory_order_relaxed)) {
|
2522
|
-
PerThreadSynch
|
2522
|
+
PerThreadSynch* h = reinterpret_cast<PerThreadSynch*>(v & ~kCvLow);
|
2523
2523
|
if (h != nullptr) {
|
2524
|
-
PerThreadSynch
|
2524
|
+
PerThreadSynch* w = h;
|
2525
2525
|
while (w->next != s && w->next != h) { // search for thread
|
2526
2526
|
w = w->next;
|
2527
2527
|
}
|
2528
|
-
if (w->next == s) {
|
2528
|
+
if (w->next == s) { // found thread; remove it
|
2529
2529
|
w->next = s->next;
|
2530
2530
|
if (h == s) {
|
2531
2531
|
h = (w == s) ? nullptr : w;
|
@@ -2534,7 +2534,7 @@ void CondVar::Remove(PerThreadSynch *s) {
|
|
2534
2534
|
s->state.store(PerThreadSynch::kAvailable, std::memory_order_release);
|
2535
2535
|
}
|
2536
2536
|
}
|
2537
|
-
|
2537
|
+
// release spinlock
|
2538
2538
|
cv_.store((v & kCvEvent) | reinterpret_cast<intptr_t>(h),
|
2539
2539
|
std::memory_order_release);
|
2540
2540
|
return;
|
@@ -2557,14 +2557,14 @@ void CondVar::Remove(PerThreadSynch *s) {
|
|
2557
2557
|
// variable queue just before the mutex is to be unlocked, and (most
|
2558
2558
|
// importantly) after any call to an external routine that might re-enter the
|
2559
2559
|
// mutex code.
|
2560
|
-
static void CondVarEnqueue(SynchWaitParams
|
2560
|
+
static void CondVarEnqueue(SynchWaitParams* waitp) {
|
2561
2561
|
// This thread might be transferred to the Mutex queue by Fer() when
|
2562
2562
|
// we are woken. To make sure that is what happens, Enqueue() doesn't
|
2563
2563
|
// call CondVarEnqueue() again but instead uses its normal code. We
|
2564
2564
|
// must do this before we queue ourselves so that cv_word will be null
|
2565
2565
|
// when seen by the dequeuer, who may wish immediately to requeue
|
2566
2566
|
// this thread on another queue.
|
2567
|
-
std::atomic<intptr_t
|
2567
|
+
std::atomic<intptr_t>* cv_word = waitp->cv_word;
|
2568
2568
|
waitp->cv_word = nullptr;
|
2569
2569
|
|
2570
2570
|
intptr_t v = cv_word->load(std::memory_order_relaxed);
|
@@ -2577,8 +2577,8 @@ static void CondVarEnqueue(SynchWaitParams *waitp) {
|
|
2577
2577
|
v = cv_word->load(std::memory_order_relaxed);
|
2578
2578
|
}
|
2579
2579
|
ABSL_RAW_CHECK(waitp->thread->waitp == nullptr, "waiting when shouldn't be");
|
2580
|
-
waitp->thread->waitp = waitp;
|
2581
|
-
PerThreadSynch
|
2580
|
+
waitp->thread->waitp = waitp; // prepare ourselves for waiting
|
2581
|
+
PerThreadSynch* h = reinterpret_cast<PerThreadSynch*>(v & ~kCvLow);
|
2582
2582
|
if (h == nullptr) { // add this thread to waiter list
|
2583
2583
|
waitp->thread->next = waitp->thread;
|
2584
2584
|
} else {
|
@@ -2591,8 +2591,8 @@ static void CondVarEnqueue(SynchWaitParams *waitp) {
|
|
2591
2591
|
std::memory_order_release);
|
2592
2592
|
}
|
2593
2593
|
|
2594
|
-
bool CondVar::WaitCommon(Mutex
|
2595
|
-
bool rc = false;
|
2594
|
+
bool CondVar::WaitCommon(Mutex* mutex, KernelTimeout t) {
|
2595
|
+
bool rc = false; // return value; true iff we timed-out
|
2596
2596
|
|
2597
2597
|
intptr_t mutex_v = mutex->mu_.load(std::memory_order_relaxed);
|
2598
2598
|
Mutex::MuHow mutex_how = ((mutex_v & kMuWriter) != 0) ? kExclusive : kShared;
|
@@ -2659,27 +2659,25 @@ bool CondVar::WaitCommon(Mutex *mutex, KernelTimeout t) {
|
|
2659
2659
|
return rc;
|
2660
2660
|
}
|
2661
2661
|
|
2662
|
-
bool CondVar::WaitWithTimeout(Mutex
|
2663
|
-
return
|
2662
|
+
bool CondVar::WaitWithTimeout(Mutex* mu, absl::Duration timeout) {
|
2663
|
+
return WaitCommon(mu, KernelTimeout(timeout));
|
2664
2664
|
}
|
2665
2665
|
|
2666
|
-
bool CondVar::WaitWithDeadline(Mutex
|
2666
|
+
bool CondVar::WaitWithDeadline(Mutex* mu, absl::Time deadline) {
|
2667
2667
|
return WaitCommon(mu, KernelTimeout(deadline));
|
2668
2668
|
}
|
2669
2669
|
|
2670
|
-
void CondVar::Wait(Mutex
|
2671
|
-
WaitCommon(mu, KernelTimeout::Never());
|
2672
|
-
}
|
2670
|
+
void CondVar::Wait(Mutex* mu) { WaitCommon(mu, KernelTimeout::Never()); }
|
2673
2671
|
|
2674
2672
|
// Wake thread w
|
2675
2673
|
// If it was a timed wait, w will be waiting on w->cv
|
2676
2674
|
// Otherwise, if it was not a Mutex mutex, w will be waiting on w->sem
|
2677
2675
|
// Otherwise, w is transferred to the Mutex mutex via Mutex::Fer().
|
2678
|
-
void CondVar::Wakeup(PerThreadSynch
|
2676
|
+
void CondVar::Wakeup(PerThreadSynch* w) {
|
2679
2677
|
if (w->waitp->timeout.has_timeout() || w->waitp->cvmu == nullptr) {
|
2680
2678
|
// The waiting thread only needs to observe "w->state == kAvailable" to be
|
2681
2679
|
// released, we must cache "cvmu" before clearing "next".
|
2682
|
-
Mutex
|
2680
|
+
Mutex* mu = w->waitp->cvmu;
|
2683
2681
|
w->next = nullptr;
|
2684
2682
|
w->state.store(PerThreadSynch::kAvailable, std::memory_order_release);
|
2685
2683
|
Mutex::IncrementSynchSem(mu, w);
|
@@ -2696,11 +2694,10 @@ void CondVar::Signal() {
|
|
2696
2694
|
for (v = cv_.load(std::memory_order_relaxed); v != 0;
|
2697
2695
|
v = cv_.load(std::memory_order_relaxed)) {
|
2698
2696
|
if ((v & kCvSpin) == 0 && // attempt to acquire spinlock
|
2699
|
-
cv_.compare_exchange_strong(v, v | kCvSpin,
|
2700
|
-
std::memory_order_acquire,
|
2697
|
+
cv_.compare_exchange_strong(v, v | kCvSpin, std::memory_order_acquire,
|
2701
2698
|
std::memory_order_relaxed)) {
|
2702
|
-
PerThreadSynch
|
2703
|
-
PerThreadSynch
|
2699
|
+
PerThreadSynch* h = reinterpret_cast<PerThreadSynch*>(v & ~kCvLow);
|
2700
|
+
PerThreadSynch* w = nullptr;
|
2704
2701
|
if (h != nullptr) { // remove first waiter
|
2705
2702
|
w = h->next;
|
2706
2703
|
if (w == h) {
|
@@ -2709,11 +2706,11 @@ void CondVar::Signal() {
|
|
2709
2706
|
h->next = w->next;
|
2710
2707
|
}
|
2711
2708
|
}
|
2712
|
-
|
2709
|
+
// release spinlock
|
2713
2710
|
cv_.store((v & kCvEvent) | reinterpret_cast<intptr_t>(h),
|
2714
2711
|
std::memory_order_release);
|
2715
2712
|
if (w != nullptr) {
|
2716
|
-
CondVar::Wakeup(w);
|
2713
|
+
CondVar::Wakeup(w); // wake waiter, if there was one
|
2717
2714
|
cond_var_tracer("Signal wakeup", this);
|
2718
2715
|
}
|
2719
2716
|
if ((v & kCvEvent) != 0) {
|
@@ -2728,7 +2725,7 @@ void CondVar::Signal() {
|
|
2728
2725
|
ABSL_TSAN_MUTEX_POST_SIGNAL(nullptr, 0);
|
2729
2726
|
}
|
2730
2727
|
|
2731
|
-
void CondVar::SignalAll
|
2728
|
+
void CondVar::SignalAll() {
|
2732
2729
|
ABSL_TSAN_MUTEX_PRE_SIGNAL(nullptr, 0);
|
2733
2730
|
intptr_t v;
|
2734
2731
|
int c = 0;
|
@@ -2742,11 +2739,11 @@ void CondVar::SignalAll () {
|
|
2742
2739
|
if ((v & kCvSpin) == 0 &&
|
2743
2740
|
cv_.compare_exchange_strong(v, v & kCvEvent, std::memory_order_acquire,
|
2744
2741
|
std::memory_order_relaxed)) {
|
2745
|
-
PerThreadSynch
|
2742
|
+
PerThreadSynch* h = reinterpret_cast<PerThreadSynch*>(v & ~kCvLow);
|
2746
2743
|
if (h != nullptr) {
|
2747
|
-
PerThreadSynch
|
2748
|
-
PerThreadSynch
|
2749
|
-
do {
|
2744
|
+
PerThreadSynch* w;
|
2745
|
+
PerThreadSynch* n = h->next;
|
2746
|
+
do { // for every thread, wake it up
|
2750
2747
|
w = n;
|
2751
2748
|
n = n->next;
|
2752
2749
|
CondVar::Wakeup(w);
|
@@ -2774,42 +2771,41 @@ void ReleasableMutexLock::Release() {
|
|
2774
2771
|
}
|
2775
2772
|
|
2776
2773
|
#ifdef ABSL_HAVE_THREAD_SANITIZER
|
2777
|
-
extern "C" void __tsan_read1(void
|
2774
|
+
extern "C" void __tsan_read1(void* addr);
|
2778
2775
|
#else
|
2779
2776
|
#define __tsan_read1(addr) // do nothing if TSan not enabled
|
2780
2777
|
#endif
|
2781
2778
|
|
2782
2779
|
// A function that just returns its argument, dereferenced
|
2783
|
-
static bool Dereference(void
|
2780
|
+
static bool Dereference(void* arg) {
|
2784
2781
|
// ThreadSanitizer does not instrument this file for memory accesses.
|
2785
2782
|
// This function dereferences a user variable that can participate
|
2786
2783
|
// in a data race, so we need to manually tell TSan about this memory access.
|
2787
2784
|
__tsan_read1(arg);
|
2788
|
-
return *(static_cast<bool
|
2785
|
+
return *(static_cast<bool*>(arg));
|
2789
2786
|
}
|
2790
2787
|
|
2791
2788
|
ABSL_CONST_INIT const Condition Condition::kTrue;
|
2792
2789
|
|
2793
|
-
Condition::Condition(bool (*func)(void
|
2794
|
-
: eval_(&CallVoidPtrFunction),
|
2795
|
-
arg_(arg) {
|
2790
|
+
Condition::Condition(bool (*func)(void*), void* arg)
|
2791
|
+
: eval_(&CallVoidPtrFunction), arg_(arg) {
|
2796
2792
|
static_assert(sizeof(&func) <= sizeof(callback_),
|
2797
2793
|
"An overlarge function pointer passed to Condition.");
|
2798
2794
|
StoreCallback(func);
|
2799
2795
|
}
|
2800
2796
|
|
2801
|
-
bool Condition::CallVoidPtrFunction(const Condition
|
2802
|
-
using FunctionPointer = bool (*)(void
|
2797
|
+
bool Condition::CallVoidPtrFunction(const Condition* c) {
|
2798
|
+
using FunctionPointer = bool (*)(void*);
|
2803
2799
|
FunctionPointer function_pointer;
|
2804
2800
|
std::memcpy(&function_pointer, c->callback_, sizeof(function_pointer));
|
2805
2801
|
return (*function_pointer)(c->arg_);
|
2806
2802
|
}
|
2807
2803
|
|
2808
|
-
Condition::Condition(const bool
|
2804
|
+
Condition::Condition(const bool* cond)
|
2809
2805
|
: eval_(CallVoidPtrFunction),
|
2810
2806
|
// const_cast is safe since Dereference does not modify arg
|
2811
|
-
arg_(const_cast<bool
|
2812
|
-
using FunctionPointer = bool (*)(void
|
2807
|
+
arg_(const_cast<bool*>(cond)) {
|
2808
|
+
using FunctionPointer = bool (*)(void*);
|
2813
2809
|
const FunctionPointer dereference = Dereference;
|
2814
2810
|
StoreCallback(dereference);
|
2815
2811
|
}
|
@@ -2819,7 +2815,7 @@ bool Condition::Eval() const {
|
|
2819
2815
|
return (this->eval_ == nullptr) || (*this->eval_)(this);
|
2820
2816
|
}
|
2821
2817
|
|
2822
|
-
bool Condition::GuaranteedEqual(const Condition
|
2818
|
+
bool Condition::GuaranteedEqual(const Condition* a, const Condition* b) {
|
2823
2819
|
// kTrue logic.
|
2824
2820
|
if (a == nullptr || a->eval_ == nullptr) {
|
2825
2821
|
return b == nullptr || b->eval_ == nullptr;
|