grpc 1.7.3 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +2106 -2116
- data/include/grpc/census.h +1 -432
- data/include/grpc/compression.h +9 -9
- data/include/grpc/grpc.h +115 -98
- data/include/grpc/grpc_cronet.h +3 -3
- data/include/grpc/grpc_posix.h +4 -4
- data/include/grpc/grpc_security.h +160 -88
- data/include/grpc/grpc_security_constants.h +7 -0
- data/include/grpc/impl/codegen/atm.h +9 -1
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +13 -4
- data/include/grpc/impl/codegen/atm_gcc_sync.h +6 -5
- data/include/grpc/impl/codegen/atm_windows.h +23 -22
- data/include/grpc/impl/codegen/byte_buffer.h +14 -14
- data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
- data/include/grpc/impl/codegen/connectivity_state.h +0 -2
- data/include/grpc/impl/codegen/grpc_types.h +32 -28
- data/include/grpc/impl/codegen/port_platform.h +48 -0
- data/include/grpc/impl/codegen/slice.h +10 -10
- data/include/grpc/impl/codegen/sync_generic.h +9 -3
- data/include/grpc/slice.h +16 -17
- data/include/grpc/slice_buffer.h +22 -22
- data/include/grpc/support/alloc.h +11 -11
- data/include/grpc/support/avl.h +28 -20
- data/include/grpc/support/cmdline.h +13 -13
- data/include/grpc/support/histogram.h +17 -17
- data/include/grpc/support/host_port.h +2 -2
- data/include/grpc/support/log.h +9 -9
- data/include/grpc/support/log_windows.h +1 -1
- data/include/grpc/support/string_util.h +2 -2
- data/include/grpc/support/subprocess.h +5 -5
- data/include/grpc/support/sync.h +43 -27
- data/include/grpc/support/thd.h +6 -6
- data/include/grpc/support/tls_gcc.h +1 -1
- data/include/grpc/support/tls_pthread.h +1 -1
- data/src/core/ext/census/{grpc_context.c → grpc_context.cc} +5 -8
- data/src/core/ext/filters/client_channel/backup_poller.cc +165 -0
- data/src/core/ext/{census/grpc_filter.h → filters/client_channel/backup_poller.h} +12 -7
- data/src/core/ext/filters/client_channel/{channel_connectivity.c → channel_connectivity.cc} +45 -42
- data/src/core/ext/filters/client_channel/{client_channel.c → client_channel.cc} +452 -417
- data/src/core/ext/filters/client_channel/client_channel.h +16 -8
- data/src/core/ext/filters/client_channel/{client_channel_factory.c → client_channel_factory.cc} +0 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.h +29 -21
- data/src/core/ext/filters/client_channel/{client_channel_plugin.c → client_channel_plugin.cc} +15 -19
- data/src/core/ext/filters/client_channel/{connector.c → connector.cc} +0 -0
- data/src/core/ext/filters/client_channel/connector.h +29 -21
- data/src/core/ext/filters/client_channel/{http_connect_handshaker.c → http_connect_handshaker.cc} +10 -10
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +8 -0
- data/src/core/ext/filters/client_channel/{http_proxy.c → http_proxy.cc} +14 -14
- data/src/core/ext/filters/client_channel/http_proxy.h +8 -0
- data/src/core/ext/filters/client_channel/{lb_policy.c → lb_policy.cc} +47 -48
- data/src/core/ext/filters/client_channel/lb_policy.h +76 -70
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/{client_load_reporting_filter.c → client_load_reporting_filter.cc} +28 -29
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +9 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/{grpclb.c → grpclb.cc} +554 -563
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +9 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +17 -9
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/{grpclb_channel_secure.c → grpclb_channel_secure.cc} +17 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/{grpclb_client_stats.c → grpclb_client_stats.cc} +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +9 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/{load_balancer_api.c → load_balancer_api.cc} +64 -67
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +20 -21
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +599 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +695 -0
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +270 -0
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +153 -0
- data/src/core/ext/filters/client_channel/{lb_policy_factory.c → lb_policy_factory.cc} +10 -10
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +48 -40
- data/src/core/ext/filters/client_channel/{lb_policy_registry.c → lb_policy_registry.cc} +9 -9
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +11 -3
- data/src/core/ext/filters/client_channel/{parse_address.c → parse_address.cc} +24 -24
- data/src/core/ext/filters/client_channel/parse_address.h +14 -6
- data/src/core/ext/filters/client_channel/{proxy_mapper.c → proxy_mapper.cc} +0 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.h +8 -0
- data/src/core/ext/filters/client_channel/{proxy_mapper_registry.c → proxy_mapper_registry.cc} +0 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +8 -0
- data/src/core/ext/filters/client_channel/{resolver.c → resolver.cc} +21 -23
- data/src/core/ext/filters/client_channel/resolver.h +33 -27
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/{dns_resolver_ares.c → dns_resolver_ares.cc} +133 -133
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +18 -9
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/{grpc_ares_ev_driver_posix.c → grpc_ares_ev_driver_posix.cc} +58 -56
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/{grpc_ares_wrapper.c → grpc_ares_wrapper.cc} +118 -115
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +23 -15
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +60 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/{dns_resolver.c → dns_resolver.cc} +100 -94
- data/src/core/ext/filters/client_channel/resolver/fake/{fake_resolver.c → fake_resolver.cc} +14 -14
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +9 -1
- data/src/core/ext/filters/client_channel/resolver/sockaddr/{sockaddr_resolver.c → sockaddr_resolver.cc} +60 -60
- data/src/core/ext/filters/client_channel/{resolver_factory.c → resolver_factory.cc} +2 -2
- data/src/core/ext/filters/client_channel/resolver_factory.h +27 -19
- data/src/core/ext/filters/client_channel/{resolver_registry.c → resolver_registry.cc} +35 -35
- data/src/core/ext/filters/client_channel/resolver_registry.h +18 -10
- data/src/core/ext/filters/client_channel/{retry_throttle.c → retry_throttle.cc} +10 -10
- data/src/core/ext/filters/client_channel/retry_throttle.h +8 -0
- data/src/core/ext/filters/client_channel/{subchannel.c → subchannel.cc} +210 -213
- data/src/core/ext/filters/client_channel/subchannel.h +68 -60
- data/src/core/ext/filters/client_channel/{subchannel_index.c → subchannel_index.cc} +52 -52
- data/src/core/ext/filters/client_channel/subchannel_index.h +22 -14
- data/src/core/ext/filters/client_channel/{uri_parser.c → uri_parser.cc} +29 -27
- data/src/core/ext/filters/client_channel/uri_parser.h +18 -10
- data/src/core/ext/filters/deadline/{deadline_filter.c → deadline_filter.cc} +12 -15
- data/src/core/ext/filters/deadline/deadline_filter.h +11 -2
- data/src/core/ext/filters/http/client/{http_client_filter.c → http_client_filter.cc} +83 -83
- data/src/core/ext/filters/http/client/http_client_filter.h +8 -0
- data/src/core/ext/filters/http/{http_filters_plugin.c → http_filters_plugin.cc} +20 -21
- data/src/core/ext/filters/http/message_compress/{message_compress_filter.c → message_compress_filter.cc} +84 -83
- data/src/core/ext/filters/http/message_compress/message_compress_filter.h +9 -1
- data/src/core/ext/filters/http/server/{http_server_filter.c → http_server_filter.cc} +80 -78
- data/src/core/ext/filters/http/server/http_server_filter.h +8 -0
- data/src/core/ext/filters/load_reporting/{server_load_reporting_filter.c → server_load_reporting_filter.cc} +29 -29
- data/src/core/ext/filters/load_reporting/server_load_reporting_filter.h +9 -1
- data/src/core/ext/filters/load_reporting/{server_load_reporting_plugin.c → server_load_reporting_plugin.cc} +11 -11
- data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +13 -5
- data/src/core/ext/filters/max_age/{max_age_filter.c → max_age_filter.cc} +46 -56
- data/src/core/ext/filters/max_age/max_age_filter.h +8 -0
- data/src/core/ext/filters/message_size/{message_size_filter.c → message_size_filter.cc} +62 -40
- data/src/core/ext/filters/message_size/message_size_filter.h +8 -0
- data/src/core/ext/filters/workarounds/{workaround_cronet_compression_filter.c → workaround_cronet_compression_filter.cc} +11 -11
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +8 -0
- data/src/core/ext/filters/workarounds/{workaround_utils.c → workaround_utils.cc} +7 -7
- data/src/core/ext/filters/workarounds/workaround_utils.h +9 -1
- data/src/core/ext/transport/chttp2/alpn/{alpn.c → alpn.cc} +3 -3
- data/src/core/ext/transport/chttp2/alpn/alpn.h +10 -2
- data/src/core/ext/transport/chttp2/client/{chttp2_connector.c → chttp2_connector.cc} +49 -45
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +8 -0
- data/src/core/ext/transport/chttp2/client/insecure/{channel_create.c → channel_create.cc} +28 -27
- data/src/core/ext/transport/chttp2/client/insecure/{channel_create_posix.c → channel_create_posix.cc} +14 -13
- data/src/core/ext/transport/chttp2/client/secure/{secure_channel_create.c → secure_channel_create.cc} +68 -66
- data/src/core/ext/transport/chttp2/server/{chttp2_server.c → chttp2_server.cc} +76 -77
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +11 -3
- data/src/core/ext/transport/chttp2/server/insecure/{server_chttp2.c → server_chttp2.cc} +3 -3
- data/src/core/ext/transport/chttp2/server/insecure/{server_chttp2_posix.c → server_chttp2_posix.cc} +13 -12
- data/src/core/ext/transport/chttp2/server/secure/{server_secure_chttp2.c → server_secure_chttp2.cc} +12 -10
- data/src/core/ext/transport/chttp2/transport/{bin_decoder.c → bin_decoder.cc} +7 -7
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +15 -7
- data/src/core/ext/transport/chttp2/transport/{bin_encoder.c → bin_encoder.cc} +11 -11
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +8 -0
- data/src/core/ext/transport/chttp2/transport/{chttp2_plugin.c → chttp2_plugin.cc} +2 -9
- data/src/core/ext/transport/chttp2/transport/{chttp2_transport.c → chttp2_transport.cc} +778 -778
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +14 -10
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +385 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +337 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +8 -0
- data/src/core/ext/transport/chttp2/transport/{frame_data.c → frame_data.cc} +34 -34
- data/src/core/ext/transport/chttp2/transport/frame_data.h +25 -17
- data/src/core/ext/transport/chttp2/transport/{frame_goaway.c → frame_goaway.cc} +18 -18
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +18 -10
- data/src/core/ext/transport/chttp2/transport/{frame_ping.c → frame_ping.cc} +18 -19
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +12 -4
- data/src/core/ext/transport/chttp2/transport/{frame_rst_stream.c → frame_rst_stream.cc} +16 -16
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +16 -8
- data/src/core/ext/transport/chttp2/transport/{frame_settings.c → frame_settings.cc} +23 -24
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +17 -9
- data/src/core/ext/transport/chttp2/transport/{frame_window_update.c → frame_window_update.cc} +22 -24
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +14 -6
- data/src/core/ext/transport/chttp2/transport/{hpack_encoder.c → hpack_encoder.cc} +206 -161
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +23 -13
- data/src/core/ext/transport/chttp2/transport/{hpack_parser.c → hpack_parser.cc} +340 -334
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +30 -22
- data/src/core/ext/transport/chttp2/transport/{hpack_table.c → hpack_table.cc} +25 -25
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +19 -11
- data/src/core/ext/transport/chttp2/transport/{http2_settings.c → http2_settings.cc} +1 -1
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +10 -2
- data/src/core/ext/transport/chttp2/transport/{huffsyms.c → huffsyms.cc} +0 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +8 -0
- data/src/core/ext/transport/chttp2/transport/{incoming_metadata.c → incoming_metadata.cc} +14 -13
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +18 -10
- data/src/core/ext/transport/chttp2/transport/internal.h +214 -340
- data/src/core/ext/transport/chttp2/transport/{parsing.c → parsing.cc} +152 -141
- data/src/core/ext/transport/chttp2/transport/{stream_lists.c → stream_lists.cc} +53 -53
- data/src/core/ext/transport/chttp2/transport/{stream_map.c → stream_map.cc} +35 -34
- data/src/core/ext/transport/chttp2/transport/stream_map.h +22 -14
- data/src/core/ext/transport/chttp2/transport/{varint.c → varint.cc} +0 -0
- data/src/core/ext/transport/chttp2/transport/varint.h +8 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +636 -0
- data/src/core/ext/transport/inproc/{inproc_plugin.c → inproc_plugin.cc} +5 -6
- data/src/core/ext/transport/inproc/{inproc_transport.c → inproc_transport.cc} +479 -544
- data/src/core/ext/transport/inproc/inproc_transport.h +4 -4
- data/src/core/lib/backoff/backoff.cc +80 -0
- data/src/core/lib/backoff/backoff.h +83 -0
- data/src/core/lib/channel/{channel_args.c → channel_args.cc} +92 -92
- data/src/core/lib/channel/channel_args.h +45 -37
- data/src/core/lib/channel/{channel_stack.c → channel_stack.cc} +67 -68
- data/src/core/lib/channel/channel_stack.h +76 -75
- data/src/core/lib/channel/{channel_stack_builder.c → channel_stack_builder.cc} +91 -91
- data/src/core/lib/channel/channel_stack_builder.h +45 -45
- data/src/core/lib/channel/{connected_channel.c → connected_channel.cc} +70 -70
- data/src/core/lib/channel/connected_channel.h +12 -4
- data/src/core/lib/channel/context.h +2 -2
- data/src/core/lib/channel/{handshaker.c → handshaker.cc} +7 -9
- data/src/core/lib/channel/handshaker.h +9 -1
- data/src/core/lib/channel/{handshaker_factory.c → handshaker_factory.cc} +7 -7
- data/src/core/lib/channel/handshaker_factory.h +18 -10
- data/src/core/lib/channel/{handshaker_registry.c → handshaker_registry.cc} +0 -0
- data/src/core/lib/channel/handshaker_registry.h +8 -0
- data/src/core/lib/compression/algorithm_metadata.h +8 -0
- data/src/core/lib/compression/{compression.c → compression.cc} +9 -9
- data/src/core/lib/compression/{message_compress.c → message_compress.cc} +0 -0
- data/src/core/lib/compression/message_compress.h +8 -0
- data/src/core/lib/compression/{stream_compression.c → stream_compression.cc} +12 -12
- data/src/core/lib/compression/stream_compression.h +27 -19
- data/src/core/lib/compression/{stream_compression_gzip.c → stream_compression_gzip.cc} +35 -36
- data/src/core/lib/compression/stream_compression_gzip.h +8 -0
- data/src/core/lib/compression/{stream_compression_identity.c → stream_compression_identity.cc} +19 -20
- data/src/core/lib/compression/stream_compression_identity.h +8 -0
- data/src/core/lib/debug/{stats.c → stats.cc} +19 -19
- data/src/core/lib/debug/stats.h +17 -9
- data/src/core/lib/debug/{stats_data.c → stats_data.cc} +45 -22
- data/src/core/lib/debug/stats_data.h +58 -19
- data/src/core/lib/debug/trace.cc +142 -0
- data/src/core/lib/debug/trace.h +74 -14
- data/src/core/lib/http/{format_request.c → format_request.cc} +10 -10
- data/src/core/lib/http/format_request.h +12 -4
- data/src/core/lib/http/{httpcli.c → httpcli.cc} +80 -80
- data/src/core/lib/http/httpcli.h +41 -33
- data/src/core/lib/http/{httpcli_security_connector.c → httpcli_security_connector.cc} +69 -55
- data/src/core/lib/http/{parser.c → parser.cc} +42 -42
- data/src/core/lib/http/parser.h +28 -20
- data/src/core/lib/{support → iomgr}/block_annotate.h +17 -8
- data/src/core/lib/iomgr/{call_combiner.c → call_combiner.cc} +29 -17
- data/src/core/lib/iomgr/call_combiner.h +9 -1
- data/src/core/lib/iomgr/closure.h +220 -62
- data/src/core/lib/iomgr/{combiner.c → combiner.cc} +63 -62
- data/src/core/lib/iomgr/combiner.h +16 -8
- data/src/core/lib/iomgr/{endpoint.c → endpoint.cc} +6 -0
- data/src/core/lib/iomgr/endpoint.h +47 -32
- data/src/core/lib/iomgr/endpoint_pair.h +12 -4
- data/src/core/lib/iomgr/{endpoint_pair_posix.c → endpoint_pair_posix.cc} +3 -3
- data/src/core/lib/iomgr/{endpoint_pair_uv.c → endpoint_pair_uv.cc} +2 -2
- data/src/core/lib/iomgr/{endpoint_pair_windows.c → endpoint_pair_windows.cc} +6 -6
- data/src/core/lib/iomgr/{error.c → error.cc} +125 -124
- data/src/core/lib/iomgr/error.h +32 -27
- data/src/core/lib/iomgr/error_internal.h +11 -2
- data/src/core/lib/iomgr/{ev_epoll1_linux.c → ev_epoll1_linux.cc} +214 -215
- data/src/core/lib/iomgr/ev_epoll1_linux.h +9 -1
- data/src/core/lib/iomgr/ev_epollex_linux.cc +1488 -0
- data/src/core/lib/iomgr/ev_epollex_linux.h +9 -1
- data/src/core/lib/iomgr/{ev_epollsig_linux.c → ev_epollsig_linux.cc} +304 -305
- data/src/core/lib/iomgr/ev_epollsig_linux.h +12 -4
- data/src/core/lib/iomgr/{ev_poll_posix.c → ev_poll_posix.cc} +272 -283
- data/src/core/lib/iomgr/ev_poll_posix.h +10 -2
- data/src/core/lib/iomgr/ev_posix.cc +288 -0
- data/src/core/lib/iomgr/ev_posix.h +75 -67
- data/src/core/lib/iomgr/{ev_windows.c → ev_windows.cc} +2 -2
- data/src/core/lib/iomgr/exec_ctx.cc +177 -0
- data/src/core/lib/iomgr/exec_ctx.h +35 -13
- data/src/core/lib/iomgr/{executor.c → executor.cc} +34 -35
- data/src/core/lib/iomgr/executor.h +12 -4
- data/src/core/lib/iomgr/{fork_posix.c → fork_posix.cc} +0 -0
- data/src/core/lib/iomgr/{fork_windows.c → fork_windows.cc} +0 -0
- data/src/core/lib/iomgr/gethostname.h +9 -1
- data/src/core/lib/iomgr/{gethostname_fallback.c → gethostname_fallback.cc} +2 -1
- data/src/core/lib/iomgr/{gethostname_host_name_max.c → gethostname_host_name_max.cc} +4 -3
- data/src/core/lib/iomgr/{gethostname_sysconf.c → gethostname_sysconf.cc} +3 -2
- data/src/core/lib/iomgr/{iocp_windows.c → iocp_windows.cc} +23 -25
- data/src/core/lib/iomgr/iocp_windows.h +17 -3
- data/src/core/lib/iomgr/{iomgr.c → iomgr.cc} +25 -19
- data/src/core/lib/iomgr/iomgr.h +11 -3
- data/src/core/lib/iomgr/iomgr_internal.h +13 -5
- data/src/core/lib/iomgr/{iomgr_posix.c → iomgr_posix.cc} +0 -1
- data/src/core/lib/iomgr/{iomgr_uv.c → iomgr_uv.cc} +1 -1
- data/src/core/lib/iomgr/iomgr_uv.h +8 -0
- data/src/core/lib/iomgr/{iomgr_windows.c → iomgr_windows.cc} +0 -0
- data/src/core/lib/iomgr/{is_epollexclusive_available.c → is_epollexclusive_available.cc} +1 -1
- data/src/core/lib/iomgr/is_epollexclusive_available.h +8 -0
- data/src/core/lib/iomgr/{load_file.c → load_file.cc} +12 -12
- data/src/core/lib/iomgr/load_file.h +2 -2
- data/src/core/lib/iomgr/{lockfree_event.c → lockfree_event.cc} +76 -68
- data/src/core/lib/iomgr/lockfree_event.h +30 -11
- data/src/core/lib/iomgr/{network_status_tracker.c → network_status_tracker.cc} +3 -2
- data/src/core/lib/iomgr/network_status_tracker.h +2 -2
- data/src/core/lib/iomgr/{polling_entity.c → polling_entity.cc} +18 -18
- data/src/core/lib/iomgr/polling_entity.h +21 -13
- data/src/core/lib/iomgr/pollset.h +17 -11
- data/src/core/lib/iomgr/pollset_set.h +23 -15
- data/src/core/lib/iomgr/{pollset_set_uv.c → pollset_set_uv.cc} +0 -0
- data/src/core/lib/iomgr/{pollset_set_windows.c → pollset_set_windows.cc} +0 -0
- data/src/core/lib/iomgr/{pollset_uv.c → pollset_uv.cc} +31 -29
- data/src/core/lib/iomgr/pollset_uv.h +8 -0
- data/src/core/lib/iomgr/{pollset_windows.c → pollset_windows.cc} +24 -24
- data/src/core/lib/iomgr/pollset_windows.h +17 -4
- data/src/core/lib/iomgr/port.h +10 -0
- data/src/core/lib/iomgr/resolve_address.h +18 -10
- data/src/core/lib/iomgr/{resolve_address_posix.c → resolve_address_posix.cc} +40 -40
- data/src/core/lib/iomgr/{resolve_address_uv.c → resolve_address_uv.cc} +61 -56
- data/src/core/lib/iomgr/{resolve_address_windows.c → resolve_address_windows.cc} +36 -34
- data/src/core/lib/iomgr/{resource_quota.c → resource_quota.cc} +209 -180
- data/src/core/lib/iomgr/resource_quota.h +45 -37
- data/src/core/lib/iomgr/{sockaddr_utils.c → sockaddr_utils.cc} +61 -61
- data/src/core/lib/iomgr/sockaddr_utils.h +23 -15
- data/src/core/lib/iomgr/sockaddr_windows.h +6 -0
- data/src/core/lib/iomgr/{socket_factory_posix.c → socket_factory_posix.cc} +20 -20
- data/src/core/lib/iomgr/socket_factory_posix.h +15 -15
- data/src/core/lib/iomgr/{socket_mutator.c → socket_mutator.cc} +18 -18
- data/src/core/lib/iomgr/socket_mutator.h +11 -11
- data/src/core/lib/iomgr/socket_utils.h +9 -1
- data/src/core/lib/iomgr/{socket_utils_common_posix.c → socket_utils_common_posix.cc} +28 -28
- data/src/core/lib/iomgr/{socket_utils_linux.c → socket_utils_linux.cc} +3 -3
- data/src/core/lib/iomgr/{socket_utils_posix.c → socket_utils_posix.cc} +3 -3
- data/src/core/lib/iomgr/socket_utils_posix.h +26 -18
- data/src/core/lib/iomgr/{socket_utils_uv.c → socket_utils_uv.cc} +1 -1
- data/src/core/lib/iomgr/{socket_utils_windows.c → socket_utils_windows.cc} +2 -2
- data/src/core/lib/iomgr/{socket_windows.c → socket_windows.cc} +18 -18
- data/src/core/lib/iomgr/socket_windows.h +26 -13
- data/src/core/lib/iomgr/tcp_client.h +14 -6
- data/src/core/lib/iomgr/{tcp_client_posix.c → tcp_client_posix.cc} +69 -70
- data/src/core/lib/iomgr/tcp_client_posix.h +11 -3
- data/src/core/lib/iomgr/{tcp_client_uv.c → tcp_client_uv.cc} +47 -48
- data/src/core/lib/iomgr/{tcp_client_windows.c → tcp_client_windows.cc} +46 -44
- data/src/core/lib/iomgr/{tcp_posix.c → tcp_posix.cc} +198 -175
- data/src/core/lib/iomgr/tcp_posix.h +15 -7
- data/src/core/lib/iomgr/tcp_server.h +31 -23
- data/src/core/lib/iomgr/{tcp_server_posix.c → tcp_server_posix.cc} +78 -77
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +27 -19
- data/src/core/lib/iomgr/{tcp_server_utils_posix_common.c → tcp_server_utils_posix_common.cc} +27 -27
- data/src/core/lib/iomgr/{tcp_server_utils_posix_ifaddrs.c → tcp_server_utils_posix_ifaddrs.cc} +25 -25
- data/src/core/lib/iomgr/{tcp_server_utils_posix_noifaddrs.c → tcp_server_utils_posix_noifaddrs.cc} +2 -2
- data/src/core/lib/iomgr/{tcp_server_uv.c → tcp_server_uv.cc} +133 -105
- data/src/core/lib/iomgr/{tcp_server_windows.c → tcp_server_windows.cc} +81 -77
- data/src/core/lib/iomgr/tcp_uv.cc +420 -0
- data/src/core/lib/iomgr/tcp_uv.h +18 -4
- data/src/core/lib/iomgr/{tcp_windows.c → tcp_windows.cc} +90 -79
- data/src/core/lib/iomgr/tcp_windows.h +17 -4
- data/src/core/lib/iomgr/{time_averaged_stats.c → time_averaged_stats.cc} +0 -0
- data/src/core/lib/iomgr/time_averaged_stats.h +8 -0
- data/src/core/lib/iomgr/timer.h +16 -9
- data/src/core/lib/iomgr/{timer_generic.c → timer_generic.cc} +130 -171
- data/src/core/lib/iomgr/timer_generic.h +4 -4
- data/src/core/lib/iomgr/{timer_heap.c → timer_heap.cc} +20 -21
- data/src/core/lib/iomgr/timer_heap.h +16 -8
- data/src/core/lib/iomgr/{timer_manager.c → timer_manager.cc} +54 -52
- data/src/core/lib/iomgr/timer_manager.h +8 -0
- data/src/core/lib/iomgr/{timer_uv.c → timer_uv.cc} +22 -24
- data/src/core/lib/iomgr/timer_uv.h +2 -2
- data/src/core/lib/iomgr/{udp_server.c → udp_server.cc} +75 -75
- data/src/core/lib/iomgr/udp_server.h +25 -17
- data/src/core/lib/iomgr/{unix_sockets_posix.c → unix_sockets_posix.cc} +22 -21
- data/src/core/lib/iomgr/unix_sockets_posix.h +14 -6
- data/src/core/lib/iomgr/{unix_sockets_posix_noop.c → unix_sockets_posix_noop.cc} +5 -5
- data/src/core/lib/iomgr/{wakeup_fd_cv.c → wakeup_fd_cv.cc} +2 -2
- data/src/core/lib/iomgr/wakeup_fd_cv.h +10 -0
- data/src/core/lib/iomgr/{wakeup_fd_eventfd.c → wakeup_fd_eventfd.cc} +0 -0
- data/src/core/lib/iomgr/{wakeup_fd_nospecial.c → wakeup_fd_nospecial.cc} +0 -0
- data/src/core/lib/iomgr/{wakeup_fd_pipe.c → wakeup_fd_pipe.cc} +1 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.h +9 -1
- data/src/core/lib/iomgr/{wakeup_fd_posix.c → wakeup_fd_posix.cc} +6 -7
- data/src/core/lib/iomgr/wakeup_fd_posix.h +8 -0
- data/src/core/lib/json/{json.c → json.cc} +0 -0
- data/src/core/lib/json/json.h +8 -0
- data/src/core/lib/json/{json_reader.c → json_reader.cc} +18 -18
- data/src/core/lib/json/json_reader.h +26 -18
- data/src/core/lib/json/{json_string.c → json_string.cc} +57 -57
- data/src/core/lib/json/{json_writer.c → json_writer.cc} +20 -20
- data/src/core/lib/json/json_writer.h +23 -15
- data/src/core/lib/profiling/{basic_timers.c → basic_timers.cc} +34 -34
- data/src/core/lib/profiling/{stap_timers.c → stap_timers.cc} +5 -5
- data/src/core/lib/profiling/timers.h +6 -6
- data/src/core/lib/security/context/{security_context.c → security_context.cc} +98 -95
- data/src/core/lib/security/context/security_context.h +27 -29
- data/src/core/lib/security/credentials/composite/{composite_credentials.c → composite_credentials.cc} +79 -73
- data/src/core/lib/security/credentials/composite/composite_credentials.h +17 -9
- data/src/core/lib/security/credentials/{credentials.c → credentials.cc} +97 -92
- data/src/core/lib/security/credentials/credentials.h +83 -75
- data/src/core/lib/security/credentials/{credentials_metadata.c → credentials_metadata.cc} +7 -6
- data/src/core/lib/security/credentials/fake/{fake_credentials.c → fake_credentials.cc} +39 -36
- data/src/core/lib/security/credentials/fake/fake_credentials.h +13 -5
- data/src/core/lib/security/credentials/google_default/{credentials_generic.c → credentials_generic.cc} +5 -5
- data/src/core/lib/security/credentials/google_default/{google_default_credentials.c → google_default_credentials.cc} +55 -55
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +9 -1
- data/src/core/lib/security/credentials/iam/{iam_credentials.c → iam_credentials.cc} +19 -18
- data/src/core/lib/security/credentials/jwt/{json_token.c → json_token.cc} +80 -75
- data/src/core/lib/security/credentials/jwt/json_token.h +23 -15
- data/src/core/lib/security/credentials/jwt/{jwt_credentials.c → jwt_credentials.cc} +45 -41
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +11 -3
- data/src/core/lib/security/credentials/jwt/{jwt_verifier.c → jwt_verifier.cc} +262 -252
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +38 -30
- data/src/core/lib/security/credentials/oauth2/{oauth2_credentials.c → oauth2_credentials.cc} +138 -141
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +30 -22
- data/src/core/lib/security/credentials/plugin/{plugin_credentials.c → plugin_credentials.cc} +52 -53
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +7 -7
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +344 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +27 -0
- data/src/core/lib/security/transport/auth_filters.h +16 -0
- data/src/core/lib/security/transport/{client_auth_filter.c → client_auth_filter.cc} +127 -115
- data/src/core/lib/security/transport/{lb_targets_info.c → lb_targets_info.cc} +16 -13
- data/src/core/lib/security/transport/lb_targets_info.h +11 -3
- data/src/core/lib/security/transport/{secure_endpoint.c → secure_endpoint.cc} +84 -76
- data/src/core/lib/security/transport/secure_endpoint.h +13 -5
- data/src/core/lib/security/transport/security_connector.cc +1121 -0
- data/src/core/lib/security/transport/security_connector.h +97 -79
- data/src/core/lib/security/transport/{security_handshaker.c → security_handshaker.cc} +139 -132
- data/src/core/lib/security/transport/security_handshaker.h +11 -3
- data/src/core/lib/security/transport/{server_auth_filter.c → server_auth_filter.cc} +68 -68
- data/src/core/lib/security/transport/{tsi_error.c → tsi_error.cc} +1 -1
- data/src/core/lib/security/transport/tsi_error.h +9 -1
- data/src/core/lib/security/util/{json_util.c → json_util.cc} +11 -11
- data/src/core/lib/security/util/json_util.h +12 -4
- data/src/core/lib/slice/{b64.c → b64.cc} +15 -15
- data/src/core/lib/slice/b64.h +12 -4
- data/src/core/lib/slice/{percent_encoding.c → percent_encoding.cc} +15 -15
- data/src/core/lib/slice/percent_encoding.h +11 -3
- data/src/core/lib/slice/{slice.c → slice.cc} +64 -64
- data/src/core/lib/slice/{slice_buffer.c → slice_buffer.cc} +38 -38
- data/src/core/lib/slice/{slice_hash_table.c → slice_hash_table.cc} +7 -7
- data/src/core/lib/slice/slice_hash_table.h +19 -11
- data/src/core/lib/slice/{slice_intern.c → slice_intern.cc} +35 -34
- data/src/core/lib/slice/slice_internal.h +17 -6
- data/src/core/lib/slice/{slice_string_helpers.c → slice_string_helpers.cc} +9 -9
- data/src/core/lib/slice/slice_string_helpers.h +3 -3
- data/src/core/lib/support/abstract.h +29 -0
- data/src/core/lib/support/{alloc.c → alloc.cc} +22 -22
- data/src/core/lib/support/{arena.c → arena.cc} +12 -12
- data/src/core/lib/support/arena.h +11 -3
- data/src/core/lib/support/{atm.c → atm.cc} +1 -1
- data/src/core/lib/support/{avl.c → avl.cc} +71 -70
- data/src/core/lib/support/{cmdline.c → cmdline.cc} +62 -62
- data/src/core/lib/support/{cpu_iphone.c → cpu_iphone.cc} +2 -0
- data/src/core/lib/support/{cpu_linux.c → cpu_linux.cc} +10 -0
- data/src/core/lib/support/{cpu_posix.c → cpu_posix.cc} +27 -4
- data/src/core/lib/support/{cpu_windows.c → cpu_windows.cc} +1 -0
- data/src/core/lib/support/env.h +3 -3
- data/src/core/lib/support/{env_linux.c → env_linux.cc} +11 -11
- data/src/core/lib/support/{env_posix.c → env_posix.cc} +4 -4
- data/src/core/lib/support/{env_windows.c → env_windows.cc} +5 -5
- data/src/core/lib/support/{fork.c → fork.cc} +2 -2
- data/src/core/lib/support/{histogram.c → histogram.cc} +25 -26
- data/src/core/lib/support/{host_port.c → host_port.cc} +16 -16
- data/src/core/lib/support/{log.c → log.cc} +8 -8
- data/src/core/lib/support/{log_android.c → log_android.cc} +7 -7
- data/src/core/lib/support/{log_linux.c → log_linux.cc} +8 -8
- data/src/core/lib/support/{log_posix.c → log_posix.cc} +9 -10
- data/src/core/lib/support/{log_windows.c → log_windows.cc} +7 -7
- data/src/core/lib/support/manual_constructor.h +211 -0
- data/src/core/lib/support/memory.h +41 -0
- data/src/core/lib/support/mpscq.cc +114 -0
- data/src/core/lib/support/mpscq.h +45 -7
- data/src/core/lib/support/{murmur_hash.c → murmur_hash.cc} +9 -12
- data/src/core/lib/support/murmur_hash.h +9 -1
- data/src/core/lib/support/spinlock.h +8 -1
- data/src/core/lib/support/{string.c → string.cc} +56 -55
- data/src/core/lib/support/string.h +21 -21
- data/src/core/lib/support/{string_posix.c → string_posix.cc} +5 -4
- data/src/core/lib/support/{string_util_windows.c → string_util_windows.cc} +9 -6
- data/src/core/lib/support/{string_windows.c → string_windows.cc} +3 -2
- data/src/core/lib/support/string_windows.h +8 -0
- data/src/core/lib/support/{subprocess_posix.c → subprocess_posix.cc} +13 -13
- data/src/core/lib/support/{subprocess_windows.c → subprocess_windows.cc} +9 -9
- data/src/core/lib/support/{sync.c → sync.cc} +22 -22
- data/src/core/lib/support/{sync_posix.c → sync_posix.cc} +6 -2
- data/src/core/lib/support/{sync_windows.c → sync_windows.cc} +14 -14
- data/src/core/lib/support/{thd.c → thd.cc} +0 -0
- data/src/core/lib/support/{thd_posix.c → thd_posix.cc} +10 -10
- data/src/core/lib/support/{thd_windows.c → thd_windows.cc} +10 -10
- data/src/core/lib/support/{time.c → time.cc} +0 -0
- data/src/core/lib/support/{time_posix.c → time_posix.cc} +5 -6
- data/src/core/lib/support/{time_precise.c → time_precise.cc} +6 -4
- data/src/core/lib/support/time_precise.h +9 -1
- data/src/core/lib/support/{time_windows.c → time_windows.cc} +2 -3
- data/src/core/lib/support/{tls_pthread.c → tls_pthread.cc} +2 -2
- data/src/core/lib/support/tmpfile.h +1 -1
- data/src/core/lib/support/{tmpfile_msys.c → tmpfile_msys.cc} +2 -2
- data/src/core/lib/support/{tmpfile_posix.c → tmpfile_posix.cc} +7 -7
- data/src/core/lib/support/{tmpfile_windows.c → tmpfile_windows.cc} +2 -2
- data/src/core/lib/support/{wrap_memcpy.c → wrap_memcpy.cc} +4 -2
- data/src/core/lib/surface/{alarm.c → alarm.cc} +32 -31
- data/src/core/lib/surface/alarm_internal.h +10 -2
- data/src/core/lib/surface/{api_trace.c → api_trace.cc} +1 -1
- data/src/core/lib/surface/api_trace.h +2 -2
- data/src/core/lib/surface/{byte_buffer.c → byte_buffer.cc} +13 -13
- data/src/core/lib/surface/{byte_buffer_reader.c → byte_buffer_reader.cc} +9 -9
- data/src/core/lib/surface/{call.c → call.cc} +379 -372
- data/src/core/lib/surface/call.h +37 -38
- data/src/core/lib/surface/{call_details.c → call_details.cc} +0 -0
- data/src/core/lib/surface/{call_log_batch.c → call_log_batch.cc} +13 -11
- data/src/core/lib/surface/call_test_only.h +5 -5
- data/src/core/lib/surface/{channel.c → channel.cc} +94 -95
- data/src/core/lib/surface/channel.h +29 -21
- data/src/core/lib/surface/{channel_init.c → channel_init.cc} +13 -13
- data/src/core/lib/surface/channel_init.h +6 -6
- data/src/core/lib/surface/{channel_ping.c → channel_ping.cc} +12 -12
- data/src/core/lib/surface/{channel_stack_type.c → channel_stack_type.cc} +1 -1
- data/src/core/lib/surface/channel_stack_type.h +9 -1
- data/src/core/lib/surface/{completion_queue.c → completion_queue.cc} +416 -379
- data/src/core/lib/surface/completion_queue.h +29 -29
- data/src/core/lib/surface/{completion_queue_factory.c → completion_queue_factory.cc} +1 -1
- data/src/core/lib/surface/completion_queue_factory.h +8 -0
- data/src/core/lib/surface/{event_string.c → event_string.cc} +9 -9
- data/src/core/lib/surface/event_string.h +9 -1
- data/src/core/lib/surface/{init.c → init.cc} +16 -39
- data/src/core/lib/surface/init.h +8 -0
- data/src/core/lib/surface/{init_secure.c → init_secure.cc} +12 -25
- data/src/core/lib/surface/lame_client.cc +38 -40
- data/src/core/lib/surface/lame_client.h +8 -0
- data/src/core/lib/surface/{metadata_array.c → metadata_array.cc} +0 -0
- data/src/core/lib/surface/{server.c → server.cc} +340 -404
- data/src/core/lib/surface/server.h +22 -14
- data/src/core/lib/surface/{validate_metadata.c → validate_metadata.cc} +10 -9
- data/src/core/lib/surface/validate_metadata.h +10 -2
- data/src/core/lib/surface/{version.c → version.cc} +2 -2
- data/src/core/lib/transport/bdp_estimator.cc +84 -0
- data/src/core/lib/transport/bdp_estimator.h +67 -42
- data/src/core/lib/transport/{byte_stream.c → byte_stream.cc} +51 -51
- data/src/core/lib/transport/byte_stream.h +41 -33
- data/src/core/lib/transport/{connectivity_state.c → connectivity_state.cc} +36 -40
- data/src/core/lib/transport/connectivity_state.h +29 -21
- data/src/core/lib/transport/{error_utils.c → error_utils.cc} +26 -22
- data/src/core/lib/transport/error_utils.h +18 -6
- data/src/core/lib/transport/{metadata.c → metadata.cc} +92 -88
- data/src/core/lib/transport/metadata.h +22 -20
- data/src/core/lib/transport/{metadata_batch.c → metadata_batch.cc} +78 -79
- data/src/core/lib/transport/metadata_batch.h +46 -45
- data/src/core/lib/transport/pid_controller.cc +48 -0
- data/src/core/lib/transport/pid_controller.h +84 -32
- data/src/core/lib/transport/{service_config.c → service_config.cc} +66 -48
- data/src/core/lib/transport/service_config.h +11 -2
- data/src/core/lib/transport/{static_metadata.c → static_metadata.cc} +2 -2
- data/src/core/lib/transport/static_metadata.h +30 -23
- data/src/core/lib/transport/{status_conversion.c → status_conversion.cc} +4 -3
- data/src/core/lib/transport/status_conversion.h +12 -2
- data/src/core/lib/transport/{timeout_encoding.c → timeout_encoding.cc} +28 -61
- data/src/core/lib/transport/timeout_encoding.h +11 -2
- data/src/core/lib/transport/{transport.c → transport.cc} +79 -79
- data/src/core/lib/transport/transport.h +78 -80
- data/src/core/lib/transport/transport_impl.h +27 -19
- data/src/core/lib/transport/{transport_op_string.c → transport_op_string.cc} +32 -30
- data/src/core/plugin_registry/{grpc_plugin_registry.c → grpc_plugin_registry.cc} +34 -38
- data/src/core/tsi/{fake_transport_security.c → fake_transport_security.cc} +141 -132
- data/src/core/tsi/fake_transport_security.h +5 -5
- data/src/core/tsi/{gts_transport_security.c → gts_transport_security.cc} +4 -4
- data/src/core/tsi/gts_transport_security.h +11 -3
- data/src/core/tsi/{ssl_transport_security.c → ssl_transport_security.cc} +309 -300
- data/src/core/tsi/ssl_transport_security.h +25 -25
- data/src/core/tsi/ssl_types.h +8 -0
- data/src/core/tsi/{transport_security.c → transport_security.cc} +94 -87
- data/src/core/tsi/transport_security.h +55 -55
- data/src/core/tsi/{transport_security_adapter.c → transport_security_adapter.cc} +58 -55
- data/src/core/tsi/transport_security_adapter.h +2 -2
- data/src/core/tsi/{transport_security_grpc.c → transport_security_grpc.cc} +21 -21
- data/src/core/tsi/transport_security_grpc.h +19 -19
- data/src/core/tsi/transport_security_interface.h +41 -41
- data/src/ruby/ext/grpc/extconf.rb +4 -2
- data/src/ruby/ext/grpc/rb_byte_buffer.c +5 -5
- data/src/ruby/ext/grpc/rb_byte_buffer.h +2 -2
- data/src/ruby/ext/grpc/rb_call.c +41 -42
- data/src/ruby/ext/grpc/rb_call.h +6 -6
- data/src/ruby/ext/grpc/rb_call_credentials.c +30 -30
- data/src/ruby/ext/grpc/rb_channel.c +87 -87
- data/src/ruby/ext/grpc/rb_channel_credentials.c +23 -23
- data/src/ruby/ext/grpc/rb_completion_queue.c +11 -11
- data/src/ruby/ext/grpc/rb_completion_queue.h +3 -3
- data/src/ruby/ext/grpc/rb_compression_options.c +20 -20
- data/src/ruby/ext/grpc/rb_event_thread.c +14 -14
- data/src/ruby/ext/grpc/rb_event_thread.h +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +8 -8
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -58
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +242 -306
- data/src/ruby/ext/grpc/rb_server.c +23 -23
- data/src/ruby/ext/grpc/rb_server_credentials.c +13 -13
- data/src/ruby/lib/grpc/generic/rpc_server.rb +25 -12
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +14 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +29 -0
- data/third_party/cares/config_freebsd/ares_config.h +502 -0
- data/third_party/cares/config_openbsd/ares_config.h +502 -0
- metadata +302 -328
- data/src/core/ext/census/aggregation.h +0 -51
- data/src/core/ext/census/base_resources.c +0 -56
- data/src/core/ext/census/base_resources.h +0 -24
- data/src/core/ext/census/census_interface.h +0 -61
- data/src/core/ext/census/census_rpc_stats.h +0 -86
- data/src/core/ext/census/context.c +0 -496
- data/src/core/ext/census/gen/census.pb.c +0 -161
- data/src/core/ext/census/gen/census.pb.h +0 -280
- data/src/core/ext/census/gen/trace_context.pb.c +0 -39
- data/src/core/ext/census/gen/trace_context.pb.h +0 -78
- data/src/core/ext/census/grpc_filter.c +0 -196
- data/src/core/ext/census/grpc_plugin.c +0 -70
- data/src/core/ext/census/initialize.c +0 -51
- data/src/core/ext/census/intrusive_hash_map.c +0 -305
- data/src/core/ext/census/intrusive_hash_map.h +0 -152
- data/src/core/ext/census/intrusive_hash_map_internal.h +0 -48
- data/src/core/ext/census/mlog.c +0 -586
- data/src/core/ext/census/mlog.h +0 -80
- data/src/core/ext/census/operation.c +0 -48
- data/src/core/ext/census/placeholders.c +0 -49
- data/src/core/ext/census/resource.c +0 -303
- data/src/core/ext/census/resource.h +0 -48
- data/src/core/ext/census/rpc_metric_id.h +0 -36
- data/src/core/ext/census/trace_context.c +0 -71
- data/src/core/ext/census/trace_context.h +0 -56
- data/src/core/ext/census/trace_label.h +0 -46
- data/src/core/ext/census/trace_propagation.h +0 -48
- data/src/core/ext/census/trace_status.h +0 -30
- data/src/core/ext/census/trace_string.h +0 -35
- data/src/core/ext/census/tracing.c +0 -55
- data/src/core/ext/census/tracing.h +0 -109
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +0 -714
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +0 -924
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.c +0 -60
- data/src/core/ext/transport/chttp2/transport/flow_control.c +0 -502
- data/src/core/ext/transport/chttp2/transport/writing.c +0 -534
- data/src/core/lib/debug/trace.c +0 -146
- data/src/core/lib/iomgr/closure.c +0 -219
- data/src/core/lib/iomgr/ev_epollex_linux.c +0 -1461
- data/src/core/lib/iomgr/ev_posix.c +0 -266
- data/src/core/lib/iomgr/exec_ctx.c +0 -113
- data/src/core/lib/iomgr/tcp_uv.c +0 -381
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +0 -194
- data/src/core/lib/security/transport/security_connector.c +0 -914
- data/src/core/lib/support/backoff.c +0 -72
- data/src/core/lib/support/backoff.h +0 -56
- data/src/core/lib/support/mpscq.c +0 -79
- data/src/core/lib/support/stack_lockfree.c +0 -137
- data/src/core/lib/support/stack_lockfree.h +0 -38
- data/src/core/lib/transport/bdp_estimator.c +0 -110
- data/src/core/lib/transport/pid_controller.c +0 -63
@@ -22,8 +22,16 @@
|
|
22
22
|
#include "src/core/lib/iomgr/ev_posix.h"
|
23
23
|
#include "src/core/lib/iomgr/port.h"
|
24
24
|
|
25
|
+
#ifdef __cplusplus
|
26
|
+
extern "C" {
|
27
|
+
#endif
|
28
|
+
|
25
29
|
// a polling engine that utilizes a singleton epoll set and turnstile polling
|
26
30
|
|
27
|
-
const grpc_event_engine_vtable
|
31
|
+
const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request);
|
32
|
+
|
33
|
+
#ifdef __cplusplus
|
34
|
+
}
|
35
|
+
#endif
|
28
36
|
|
29
37
|
#endif /* GRPC_CORE_LIB_IOMGR_EV_EPOLL1_LINUX_H */
|
@@ -0,0 +1,1488 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2017 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "src/core/lib/iomgr/port.h"
|
20
|
+
|
21
|
+
#include <grpc/support/log.h>
|
22
|
+
|
23
|
+
/* This polling engine is only relevant on linux kernels supporting epoll() */
|
24
|
+
#ifdef GRPC_LINUX_EPOLL
|
25
|
+
|
26
|
+
#include "src/core/lib/iomgr/ev_epollex_linux.h"
|
27
|
+
|
28
|
+
#include <assert.h>
|
29
|
+
#include <errno.h>
|
30
|
+
#include <limits.h>
|
31
|
+
#include <poll.h>
|
32
|
+
#include <pthread.h>
|
33
|
+
#include <string.h>
|
34
|
+
#include <sys/socket.h>
|
35
|
+
#include <sys/syscall.h>
|
36
|
+
#include <unistd.h>
|
37
|
+
|
38
|
+
#include <grpc/support/alloc.h>
|
39
|
+
#include <grpc/support/string_util.h>
|
40
|
+
#include <grpc/support/tls.h>
|
41
|
+
#include <grpc/support/useful.h>
|
42
|
+
|
43
|
+
#include "src/core/lib/debug/stats.h"
|
44
|
+
#include "src/core/lib/iomgr/block_annotate.h"
|
45
|
+
#include "src/core/lib/iomgr/iomgr_internal.h"
|
46
|
+
#include "src/core/lib/iomgr/is_epollexclusive_available.h"
|
47
|
+
#include "src/core/lib/iomgr/lockfree_event.h"
|
48
|
+
#include "src/core/lib/iomgr/sys_epoll_wrapper.h"
|
49
|
+
#include "src/core/lib/iomgr/timer.h"
|
50
|
+
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
|
51
|
+
#include "src/core/lib/profiling/timers.h"
|
52
|
+
#include "src/core/lib/support/manual_constructor.h"
|
53
|
+
#include "src/core/lib/support/spinlock.h"
|
54
|
+
|
55
|
+
// debug aid: create workers on the heap (allows asan to spot
|
56
|
+
// use-after-destruction)
|
57
|
+
//#define GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP 1
|
58
|
+
|
59
|
+
#define MAX_EPOLL_EVENTS 100
|
60
|
+
#define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5
|
61
|
+
|
62
|
+
grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false,
|
63
|
+
"pollable_refcount");
|
64
|
+
|
65
|
+
/*******************************************************************************
|
66
|
+
* pollable Declarations
|
67
|
+
*/
|
68
|
+
|
69
|
+
typedef enum { PO_MULTI, PO_FD, PO_EMPTY } pollable_type;
|
70
|
+
|
71
|
+
typedef struct pollable pollable;
|
72
|
+
|
73
|
+
/// A pollable is something that can be polled: it has an epoll set to poll on,
|
74
|
+
/// and a wakeup fd for kicks
|
75
|
+
/// There are three broad types:
|
76
|
+
/// - PO_EMPTY - the empty pollable, used before file descriptors are added to
|
77
|
+
/// a pollset
|
78
|
+
/// - PO_FD - a pollable containing only one FD - used to optimize single-fd
|
79
|
+
/// pollsets (which are common with synchronous api usage)
|
80
|
+
/// - PO_MULTI - a pollable containing many fds
|
81
|
+
struct pollable {
|
82
|
+
pollable_type type; // immutable
|
83
|
+
gpr_refcount refs;
|
84
|
+
|
85
|
+
int epfd;
|
86
|
+
grpc_wakeup_fd wakeup;
|
87
|
+
|
88
|
+
// only for type fd... one ref to the owner fd
|
89
|
+
grpc_fd* owner_fd;
|
90
|
+
|
91
|
+
grpc_pollset_set* pollset_set;
|
92
|
+
pollable* next;
|
93
|
+
pollable* prev;
|
94
|
+
|
95
|
+
gpr_mu mu;
|
96
|
+
grpc_pollset_worker* root_worker;
|
97
|
+
|
98
|
+
int event_cursor;
|
99
|
+
int event_count;
|
100
|
+
struct epoll_event events[MAX_EPOLL_EVENTS];
|
101
|
+
};
|
102
|
+
|
103
|
+
static const char* pollable_type_string(pollable_type t) {
|
104
|
+
switch (t) {
|
105
|
+
case PO_MULTI:
|
106
|
+
return "pollset";
|
107
|
+
case PO_FD:
|
108
|
+
return "fd";
|
109
|
+
case PO_EMPTY:
|
110
|
+
return "empty";
|
111
|
+
}
|
112
|
+
return "<invalid>";
|
113
|
+
}
|
114
|
+
|
115
|
+
static char* pollable_desc(pollable* p) {
|
116
|
+
char* out;
|
117
|
+
gpr_asprintf(&out, "type=%s epfd=%d wakeup=%d", pollable_type_string(p->type),
|
118
|
+
p->epfd, p->wakeup.read_fd);
|
119
|
+
return out;
|
120
|
+
}
|
121
|
+
|
122
|
+
/// Shared empty pollable - used by pollset to poll on until the first fd is
|
123
|
+
/// added
|
124
|
+
static pollable* g_empty_pollable;
|
125
|
+
|
126
|
+
static grpc_error* pollable_create(pollable_type type, pollable** p);
|
127
|
+
#ifdef NDEBUG
|
128
|
+
static pollable* pollable_ref(pollable* p);
|
129
|
+
static void pollable_unref(pollable* p);
|
130
|
+
#define POLLABLE_REF(p, r) pollable_ref(p)
|
131
|
+
#define POLLABLE_UNREF(p, r) pollable_unref(p)
|
132
|
+
#else
|
133
|
+
static pollable* pollable_ref(pollable* p, int line, const char* reason);
|
134
|
+
static void pollable_unref(pollable* p, int line, const char* reason);
|
135
|
+
#define POLLABLE_REF(p, r) pollable_ref((p), __LINE__, (r))
|
136
|
+
#define POLLABLE_UNREF(p, r) pollable_unref((p), __LINE__, (r))
|
137
|
+
#endif
|
138
|
+
|
139
|
+
/*******************************************************************************
|
140
|
+
* Fd Declarations
|
141
|
+
*/
|
142
|
+
|
143
|
+
struct grpc_fd {
|
144
|
+
int fd;
|
145
|
+
/* refst format:
|
146
|
+
bit 0 : 1=Active / 0=Orphaned
|
147
|
+
bits 1-n : refcount
|
148
|
+
Ref/Unref by two to avoid altering the orphaned bit */
|
149
|
+
gpr_atm refst;
|
150
|
+
|
151
|
+
gpr_mu orphan_mu;
|
152
|
+
|
153
|
+
gpr_mu pollable_mu;
|
154
|
+
pollable* pollable_obj;
|
155
|
+
|
156
|
+
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> read_closure;
|
157
|
+
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> write_closure;
|
158
|
+
|
159
|
+
struct grpc_fd* freelist_next;
|
160
|
+
grpc_closure* on_done_closure;
|
161
|
+
|
162
|
+
/* The pollset that last noticed that the fd is readable. The actual type
|
163
|
+
* stored in this is (grpc_pollset *) */
|
164
|
+
gpr_atm read_notifier_pollset;
|
165
|
+
|
166
|
+
grpc_iomgr_object iomgr_object;
|
167
|
+
};
|
168
|
+
|
169
|
+
static void fd_global_init(void);
|
170
|
+
static void fd_global_shutdown(void);
|
171
|
+
|
172
|
+
/*******************************************************************************
|
173
|
+
* Pollset Declarations
|
174
|
+
*/
|
175
|
+
|
176
|
+
typedef struct {
|
177
|
+
grpc_pollset_worker* next;
|
178
|
+
grpc_pollset_worker* prev;
|
179
|
+
} pwlink;
|
180
|
+
|
181
|
+
typedef enum { PWLINK_POLLABLE = 0, PWLINK_POLLSET, PWLINK_COUNT } pwlinks;
|
182
|
+
|
183
|
+
struct grpc_pollset_worker {
|
184
|
+
bool kicked;
|
185
|
+
bool initialized_cv;
|
186
|
+
#ifndef NDEBUG
|
187
|
+
// debug aid: which thread started this worker
|
188
|
+
pid_t originator;
|
189
|
+
#endif
|
190
|
+
gpr_cv cv;
|
191
|
+
grpc_pollset* pollset;
|
192
|
+
pollable* pollable_obj;
|
193
|
+
|
194
|
+
pwlink links[PWLINK_COUNT];
|
195
|
+
};
|
196
|
+
|
197
|
+
struct grpc_pollset {
|
198
|
+
gpr_mu mu;
|
199
|
+
pollable* active_pollable;
|
200
|
+
bool kicked_without_poller;
|
201
|
+
grpc_closure* shutdown_closure;
|
202
|
+
grpc_pollset_worker* root_worker;
|
203
|
+
int containing_pollset_set_count;
|
204
|
+
};
|
205
|
+
|
206
|
+
/*******************************************************************************
|
207
|
+
* Pollset-set Declarations
|
208
|
+
*/
|
209
|
+
|
210
|
+
struct grpc_pollset_set {
|
211
|
+
gpr_refcount refs;
|
212
|
+
gpr_mu mu;
|
213
|
+
grpc_pollset_set* parent;
|
214
|
+
|
215
|
+
size_t pollset_count;
|
216
|
+
size_t pollset_capacity;
|
217
|
+
grpc_pollset** pollsets;
|
218
|
+
|
219
|
+
size_t fd_count;
|
220
|
+
size_t fd_capacity;
|
221
|
+
grpc_fd** fds;
|
222
|
+
};
|
223
|
+
|
224
|
+
/*******************************************************************************
|
225
|
+
* Common helpers
|
226
|
+
*/
|
227
|
+
|
228
|
+
static bool append_error(grpc_error** composite, grpc_error* error,
|
229
|
+
const char* desc) {
|
230
|
+
if (error == GRPC_ERROR_NONE) return true;
|
231
|
+
if (*composite == GRPC_ERROR_NONE) {
|
232
|
+
*composite = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc);
|
233
|
+
}
|
234
|
+
*composite = grpc_error_add_child(*composite, error);
|
235
|
+
return false;
|
236
|
+
}
|
237
|
+
|
238
|
+
/*******************************************************************************
|
239
|
+
* Fd Definitions
|
240
|
+
*/
|
241
|
+
|
242
|
+
/* We need to keep a freelist not because of any concerns of malloc performance
|
243
|
+
* but instead so that implementations with multiple threads in (for example)
|
244
|
+
* epoll_wait deal with the race between pollset removal and incoming poll
|
245
|
+
* notifications.
|
246
|
+
*
|
247
|
+
* The problem is that the poller ultimately holds a reference to this
|
248
|
+
* object, so it is very difficult to know when is safe to free it, at least
|
249
|
+
* without some expensive synchronization.
|
250
|
+
*
|
251
|
+
* If we keep the object freelisted, in the worst case losing this race just
|
252
|
+
* becomes a spurious read notification on a reused fd.
|
253
|
+
*/
|
254
|
+
|
255
|
+
static grpc_fd* fd_freelist = nullptr;
|
256
|
+
static gpr_mu fd_freelist_mu;
|
257
|
+
|
258
|
+
#ifndef NDEBUG
|
259
|
+
#define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__)
|
260
|
+
#define UNREF_BY(ec, fd, n, reason) \
|
261
|
+
unref_by(ec, fd, n, reason, __FILE__, __LINE__)
|
262
|
+
static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file,
|
263
|
+
int line) {
|
264
|
+
if (grpc_trace_fd_refcount.enabled()) {
|
265
|
+
gpr_log(GPR_DEBUG,
|
266
|
+
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
267
|
+
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
268
|
+
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
|
269
|
+
}
|
270
|
+
#else
|
271
|
+
#define REF_BY(fd, n, reason) ref_by(fd, n)
|
272
|
+
#define UNREF_BY(ec, fd, n, reason) unref_by(ec, fd, n)
|
273
|
+
static void ref_by(grpc_fd* fd, int n) {
|
274
|
+
#endif
|
275
|
+
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
|
276
|
+
}
|
277
|
+
|
278
|
+
static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
|
279
|
+
grpc_fd* fd = (grpc_fd*)arg;
|
280
|
+
/* Add the fd to the freelist */
|
281
|
+
grpc_iomgr_unregister_object(&fd->iomgr_object);
|
282
|
+
POLLABLE_UNREF(fd->pollable_obj, "fd_pollable");
|
283
|
+
gpr_mu_destroy(&fd->pollable_mu);
|
284
|
+
gpr_mu_destroy(&fd->orphan_mu);
|
285
|
+
gpr_mu_lock(&fd_freelist_mu);
|
286
|
+
fd->freelist_next = fd_freelist;
|
287
|
+
fd_freelist = fd;
|
288
|
+
|
289
|
+
fd->read_closure->DestroyEvent();
|
290
|
+
fd->write_closure->DestroyEvent();
|
291
|
+
|
292
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
293
|
+
}
|
294
|
+
|
295
|
+
#ifndef NDEBUG
|
296
|
+
static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n,
|
297
|
+
const char* reason, const char* file, int line) {
|
298
|
+
if (grpc_trace_fd_refcount.enabled()) {
|
299
|
+
gpr_log(GPR_DEBUG,
|
300
|
+
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
301
|
+
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
302
|
+
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
|
303
|
+
}
|
304
|
+
#else
|
305
|
+
static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n) {
|
306
|
+
#endif
|
307
|
+
gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n);
|
308
|
+
if (old == n) {
|
309
|
+
GRPC_CLOSURE_SCHED(
|
310
|
+
exec_ctx,
|
311
|
+
GRPC_CLOSURE_CREATE(fd_destroy, fd, grpc_schedule_on_exec_ctx),
|
312
|
+
GRPC_ERROR_NONE);
|
313
|
+
} else {
|
314
|
+
GPR_ASSERT(old > n);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
|
319
|
+
|
320
|
+
static void fd_global_shutdown(void) {
|
321
|
+
gpr_mu_lock(&fd_freelist_mu);
|
322
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
323
|
+
while (fd_freelist != nullptr) {
|
324
|
+
grpc_fd* fd = fd_freelist;
|
325
|
+
fd_freelist = fd_freelist->freelist_next;
|
326
|
+
gpr_free(fd);
|
327
|
+
}
|
328
|
+
gpr_mu_destroy(&fd_freelist_mu);
|
329
|
+
}
|
330
|
+
|
331
|
+
static grpc_fd* fd_create(int fd, const char* name) {
|
332
|
+
grpc_fd* new_fd = nullptr;
|
333
|
+
|
334
|
+
gpr_mu_lock(&fd_freelist_mu);
|
335
|
+
if (fd_freelist != nullptr) {
|
336
|
+
new_fd = fd_freelist;
|
337
|
+
fd_freelist = fd_freelist->freelist_next;
|
338
|
+
}
|
339
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
340
|
+
|
341
|
+
if (new_fd == nullptr) {
|
342
|
+
new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
|
343
|
+
new_fd->read_closure.Init();
|
344
|
+
new_fd->write_closure.Init();
|
345
|
+
}
|
346
|
+
|
347
|
+
gpr_mu_init(&new_fd->pollable_mu);
|
348
|
+
gpr_mu_init(&new_fd->orphan_mu);
|
349
|
+
new_fd->pollable_obj = nullptr;
|
350
|
+
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
|
351
|
+
new_fd->fd = fd;
|
352
|
+
new_fd->read_closure->InitEvent();
|
353
|
+
new_fd->write_closure->InitEvent();
|
354
|
+
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
|
355
|
+
|
356
|
+
new_fd->freelist_next = nullptr;
|
357
|
+
new_fd->on_done_closure = nullptr;
|
358
|
+
|
359
|
+
char* fd_name;
|
360
|
+
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
|
361
|
+
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
|
362
|
+
#ifndef NDEBUG
|
363
|
+
if (grpc_trace_fd_refcount.enabled()) {
|
364
|
+
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name);
|
365
|
+
}
|
366
|
+
#endif
|
367
|
+
gpr_free(fd_name);
|
368
|
+
return new_fd;
|
369
|
+
}
|
370
|
+
|
371
|
+
static int fd_wrapped_fd(grpc_fd* fd) {
|
372
|
+
int ret_fd = fd->fd;
|
373
|
+
return (gpr_atm_acq_load(&fd->refst) & 1) ? ret_fd : -1;
|
374
|
+
}
|
375
|
+
|
376
|
+
static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
|
377
|
+
grpc_closure* on_done, int* release_fd,
|
378
|
+
bool already_closed, const char* reason) {
|
379
|
+
bool is_fd_closed = already_closed;
|
380
|
+
|
381
|
+
gpr_mu_lock(&fd->orphan_mu);
|
382
|
+
|
383
|
+
fd->on_done_closure = on_done;
|
384
|
+
|
385
|
+
/* If release_fd is not NULL, we should be relinquishing control of the file
|
386
|
+
descriptor fd->fd (but we still own the grpc_fd structure). */
|
387
|
+
if (release_fd != nullptr) {
|
388
|
+
*release_fd = fd->fd;
|
389
|
+
} else if (!is_fd_closed) {
|
390
|
+
close(fd->fd);
|
391
|
+
is_fd_closed = true;
|
392
|
+
}
|
393
|
+
|
394
|
+
if (!is_fd_closed) {
|
395
|
+
gpr_log(GPR_DEBUG, "TODO: handle fd removal?");
|
396
|
+
}
|
397
|
+
|
398
|
+
/* Remove the active status but keep referenced. We want this grpc_fd struct
|
399
|
+
to be alive (and not added to freelist) until the end of this function */
|
400
|
+
REF_BY(fd, 1, reason);
|
401
|
+
|
402
|
+
GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_NONE);
|
403
|
+
|
404
|
+
gpr_mu_unlock(&fd->orphan_mu);
|
405
|
+
|
406
|
+
UNREF_BY(exec_ctx, fd, 2, reason); /* Drop the reference */
|
407
|
+
}
|
408
|
+
|
409
|
+
static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx,
|
410
|
+
grpc_fd* fd) {
|
411
|
+
gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset);
|
412
|
+
return (grpc_pollset*)notifier;
|
413
|
+
}
|
414
|
+
|
415
|
+
static bool fd_is_shutdown(grpc_fd* fd) {
|
416
|
+
return fd->read_closure->IsShutdown();
|
417
|
+
}
|
418
|
+
|
419
|
+
/* Might be called multiple times */
|
420
|
+
static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) {
|
421
|
+
if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) {
|
422
|
+
shutdown(fd->fd, SHUT_RDWR);
|
423
|
+
fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why));
|
424
|
+
}
|
425
|
+
GRPC_ERROR_UNREF(why);
|
426
|
+
}
|
427
|
+
|
428
|
+
static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
|
429
|
+
grpc_closure* closure) {
|
430
|
+
fd->read_closure->NotifyOn(exec_ctx, closure);
|
431
|
+
}
|
432
|
+
|
433
|
+
static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
|
434
|
+
grpc_closure* closure) {
|
435
|
+
fd->write_closure->NotifyOn(exec_ctx, closure);
|
436
|
+
}
|
437
|
+
|
438
|
+
/*******************************************************************************
|
439
|
+
* Pollable Definitions
|
440
|
+
*/
|
441
|
+
|
442
|
+
static grpc_error* pollable_create(pollable_type type, pollable** p) {
|
443
|
+
*p = nullptr;
|
444
|
+
|
445
|
+
int epfd = epoll_create1(EPOLL_CLOEXEC);
|
446
|
+
if (epfd == -1) {
|
447
|
+
return GRPC_OS_ERROR(errno, "epoll_create1");
|
448
|
+
}
|
449
|
+
*p = (pollable*)gpr_malloc(sizeof(**p));
|
450
|
+
grpc_error* err = grpc_wakeup_fd_init(&(*p)->wakeup);
|
451
|
+
if (err != GRPC_ERROR_NONE) {
|
452
|
+
close(epfd);
|
453
|
+
gpr_free(*p);
|
454
|
+
*p = nullptr;
|
455
|
+
return err;
|
456
|
+
}
|
457
|
+
struct epoll_event ev;
|
458
|
+
ev.events = (uint32_t)(EPOLLIN | EPOLLET);
|
459
|
+
ev.data.ptr = (void*)(1 | (intptr_t) & (*p)->wakeup);
|
460
|
+
if (epoll_ctl(epfd, EPOLL_CTL_ADD, (*p)->wakeup.read_fd, &ev) != 0) {
|
461
|
+
err = GRPC_OS_ERROR(errno, "epoll_ctl");
|
462
|
+
close(epfd);
|
463
|
+
grpc_wakeup_fd_destroy(&(*p)->wakeup);
|
464
|
+
gpr_free(*p);
|
465
|
+
*p = nullptr;
|
466
|
+
return err;
|
467
|
+
}
|
468
|
+
|
469
|
+
(*p)->type = type;
|
470
|
+
gpr_ref_init(&(*p)->refs, 1);
|
471
|
+
gpr_mu_init(&(*p)->mu);
|
472
|
+
(*p)->epfd = epfd;
|
473
|
+
(*p)->owner_fd = nullptr;
|
474
|
+
(*p)->pollset_set = nullptr;
|
475
|
+
(*p)->next = (*p)->prev = *p;
|
476
|
+
(*p)->root_worker = nullptr;
|
477
|
+
(*p)->event_cursor = 0;
|
478
|
+
(*p)->event_count = 0;
|
479
|
+
return GRPC_ERROR_NONE;
|
480
|
+
}
|
481
|
+
|
482
|
+
#ifdef NDEBUG
|
483
|
+
static pollable* pollable_ref(pollable* p) {
|
484
|
+
#else
|
485
|
+
static pollable* pollable_ref(pollable* p, int line, const char* reason) {
|
486
|
+
if (grpc_trace_pollable_refcount.enabled()) {
|
487
|
+
int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
|
488
|
+
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
|
489
|
+
"POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason);
|
490
|
+
}
|
491
|
+
#endif
|
492
|
+
gpr_ref(&p->refs);
|
493
|
+
return p;
|
494
|
+
}
|
495
|
+
|
496
|
+
#ifdef NDEBUG
|
497
|
+
static void pollable_unref(pollable* p) {
|
498
|
+
#else
|
499
|
+
static void pollable_unref(pollable* p, int line, const char* reason) {
|
500
|
+
if (p == nullptr) return;
|
501
|
+
if (grpc_trace_pollable_refcount.enabled()) {
|
502
|
+
int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
|
503
|
+
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
|
504
|
+
"POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason);
|
505
|
+
}
|
506
|
+
#endif
|
507
|
+
if (p != nullptr && gpr_unref(&p->refs)) {
|
508
|
+
close(p->epfd);
|
509
|
+
grpc_wakeup_fd_destroy(&p->wakeup);
|
510
|
+
gpr_free(p);
|
511
|
+
}
|
512
|
+
}
|
513
|
+
|
514
|
+
static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) {
|
515
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
516
|
+
static const char* err_desc = "pollable_add_fd";
|
517
|
+
const int epfd = p->epfd;
|
518
|
+
|
519
|
+
if (grpc_polling_trace.enabled()) {
|
520
|
+
gpr_log(GPR_DEBUG, "add fd %p (%d) to pollable %p", fd, fd->fd, p);
|
521
|
+
}
|
522
|
+
|
523
|
+
struct epoll_event ev_fd;
|
524
|
+
ev_fd.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE);
|
525
|
+
ev_fd.data.ptr = fd;
|
526
|
+
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd->fd, &ev_fd) != 0) {
|
527
|
+
switch (errno) {
|
528
|
+
case EEXIST:
|
529
|
+
break;
|
530
|
+
default:
|
531
|
+
append_error(&error, GRPC_OS_ERROR(errno, "epoll_ctl"), err_desc);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
return error;
|
536
|
+
}
|
537
|
+
|
538
|
+
/*******************************************************************************
|
539
|
+
* Pollset Definitions
|
540
|
+
*/
|
541
|
+
|
542
|
+
GPR_TLS_DECL(g_current_thread_pollset);
|
543
|
+
GPR_TLS_DECL(g_current_thread_worker);
|
544
|
+
|
545
|
+
/* Global state management */
|
546
|
+
static grpc_error* pollset_global_init(void) {
|
547
|
+
gpr_tls_init(&g_current_thread_pollset);
|
548
|
+
gpr_tls_init(&g_current_thread_worker);
|
549
|
+
return pollable_create(PO_EMPTY, &g_empty_pollable);
|
550
|
+
}
|
551
|
+
|
552
|
+
static void pollset_global_shutdown(void) {
|
553
|
+
POLLABLE_UNREF(g_empty_pollable, "g_empty_pollable");
|
554
|
+
gpr_tls_destroy(&g_current_thread_pollset);
|
555
|
+
gpr_tls_destroy(&g_current_thread_worker);
|
556
|
+
}
|
557
|
+
|
558
|
+
/* pollset->mu must be held while calling this function */
|
559
|
+
static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx,
|
560
|
+
grpc_pollset* pollset) {
|
561
|
+
if (grpc_polling_trace.enabled()) {
|
562
|
+
gpr_log(GPR_DEBUG,
|
563
|
+
"PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) "
|
564
|
+
"rw=%p (target:NULL) cpsc=%d (target:0)",
|
565
|
+
pollset, pollset->active_pollable, pollset->shutdown_closure,
|
566
|
+
pollset->root_worker, pollset->containing_pollset_set_count);
|
567
|
+
}
|
568
|
+
if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr &&
|
569
|
+
pollset->containing_pollset_set_count == 0) {
|
570
|
+
GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE);
|
571
|
+
pollset->shutdown_closure = nullptr;
|
572
|
+
}
|
573
|
+
}
|
574
|
+
|
575
|
+
/* pollset->mu must be held before calling this function,
|
576
|
+
* pollset->active_pollable->mu & specific_worker->pollable_obj->mu must not be
|
577
|
+
* held */
|
578
|
+
static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx,
|
579
|
+
grpc_pollset_worker* specific_worker) {
|
580
|
+
pollable* p = specific_worker->pollable_obj;
|
581
|
+
grpc_core::mu_guard lock(&p->mu);
|
582
|
+
GPR_ASSERT(specific_worker != nullptr);
|
583
|
+
if (specific_worker->kicked) {
|
584
|
+
if (grpc_polling_trace.enabled()) {
|
585
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p);
|
586
|
+
}
|
587
|
+
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx);
|
588
|
+
return GRPC_ERROR_NONE;
|
589
|
+
}
|
590
|
+
if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) {
|
591
|
+
if (grpc_polling_trace.enabled()) {
|
592
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p);
|
593
|
+
}
|
594
|
+
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
|
595
|
+
specific_worker->kicked = true;
|
596
|
+
return GRPC_ERROR_NONE;
|
597
|
+
}
|
598
|
+
if (specific_worker == p->root_worker) {
|
599
|
+
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx);
|
600
|
+
if (grpc_polling_trace.enabled()) {
|
601
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p);
|
602
|
+
}
|
603
|
+
specific_worker->kicked = true;
|
604
|
+
grpc_error* error = grpc_wakeup_fd_wakeup(&p->wakeup);
|
605
|
+
return error;
|
606
|
+
}
|
607
|
+
if (specific_worker->initialized_cv) {
|
608
|
+
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx);
|
609
|
+
if (grpc_polling_trace.enabled()) {
|
610
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p);
|
611
|
+
}
|
612
|
+
specific_worker->kicked = true;
|
613
|
+
gpr_cv_signal(&specific_worker->cv);
|
614
|
+
return GRPC_ERROR_NONE;
|
615
|
+
}
|
616
|
+
// we can get here during end_worker after removing specific_worker from the
|
617
|
+
// pollable list but before removing it from the pollset list
|
618
|
+
return GRPC_ERROR_NONE;
|
619
|
+
}
|
620
|
+
|
621
|
+
static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
622
|
+
grpc_pollset_worker* specific_worker) {
|
623
|
+
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
|
624
|
+
if (grpc_polling_trace.enabled()) {
|
625
|
+
gpr_log(GPR_DEBUG,
|
626
|
+
"PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p",
|
627
|
+
pollset, specific_worker,
|
628
|
+
(void*)gpr_tls_get(&g_current_thread_pollset),
|
629
|
+
(void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker);
|
630
|
+
}
|
631
|
+
if (specific_worker == nullptr) {
|
632
|
+
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
|
633
|
+
if (pollset->root_worker == nullptr) {
|
634
|
+
if (grpc_polling_trace.enabled()) {
|
635
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset);
|
636
|
+
}
|
637
|
+
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx);
|
638
|
+
pollset->kicked_without_poller = true;
|
639
|
+
return GRPC_ERROR_NONE;
|
640
|
+
} else {
|
641
|
+
// We've been asked to kick a poller, but we haven't been told which one
|
642
|
+
// ... any will do
|
643
|
+
// We look at the pollset worker list because:
|
644
|
+
// 1. the pollable list may include workers from other pollers, so we'd
|
645
|
+
// need to do an O(N) search
|
646
|
+
// 2. we'd additionally need to take the pollable lock, which we've so
|
647
|
+
// far avoided
|
648
|
+
// Now, we would prefer to wake a poller in cv_wait, and not in
|
649
|
+
// epoll_wait (since the latter would imply the need to do an additional
|
650
|
+
// wakeup)
|
651
|
+
// We know that if a worker is at the root of a pollable, it's (likely)
|
652
|
+
// also the root of a pollset, and we know that if a worker is NOT at
|
653
|
+
// the root of a pollset, it's (likely) not at the root of a pollable,
|
654
|
+
// so we take our chances and choose the SECOND worker enqueued against
|
655
|
+
// the pollset as a worker that's likely to be in cv_wait
|
656
|
+
return kick_one_worker(
|
657
|
+
exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next);
|
658
|
+
}
|
659
|
+
} else {
|
660
|
+
if (grpc_polling_trace.enabled()) {
|
661
|
+
gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset);
|
662
|
+
}
|
663
|
+
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
|
664
|
+
return GRPC_ERROR_NONE;
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
return kick_one_worker(exec_ctx, specific_worker);
|
668
|
+
}
|
669
|
+
}
|
670
|
+
|
671
|
+
static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx,
|
672
|
+
grpc_pollset* pollset) {
|
673
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
674
|
+
const char* err_desc = "pollset_kick_all";
|
675
|
+
grpc_pollset_worker* w = pollset->root_worker;
|
676
|
+
if (w != nullptr) {
|
677
|
+
do {
|
678
|
+
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
|
679
|
+
append_error(&error, kick_one_worker(exec_ctx, w), err_desc);
|
680
|
+
w = w->links[PWLINK_POLLSET].next;
|
681
|
+
} while (w != pollset->root_worker);
|
682
|
+
}
|
683
|
+
return error;
|
684
|
+
}
|
685
|
+
|
686
|
+
static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
|
687
|
+
gpr_mu_init(&pollset->mu);
|
688
|
+
pollset->active_pollable = POLLABLE_REF(g_empty_pollable, "pollset");
|
689
|
+
*mu = &pollset->mu;
|
690
|
+
}
|
691
|
+
|
692
|
+
static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx,
|
693
|
+
grpc_millis millis) {
|
694
|
+
if (millis == GRPC_MILLIS_INF_FUTURE) return -1;
|
695
|
+
grpc_millis delta = millis - grpc_exec_ctx_now(exec_ctx);
|
696
|
+
if (delta > INT_MAX)
|
697
|
+
return INT_MAX;
|
698
|
+
else if (delta < 0)
|
699
|
+
return 0;
|
700
|
+
else
|
701
|
+
return (int)delta;
|
702
|
+
}
|
703
|
+
|
704
|
+
static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
|
705
|
+
grpc_pollset* notifier) {
|
706
|
+
fd->read_closure->SetReady(exec_ctx);
|
707
|
+
|
708
|
+
/* Note, it is possible that fd_become_readable might be called twice with
|
709
|
+
different 'notifier's when an fd becomes readable and it is in two epoll
|
710
|
+
sets (This can happen briefly during polling island merges). In such cases
|
711
|
+
it does not really matter which notifer is set as the read_notifier_pollset
|
712
|
+
(They would both point to the same polling island anyway) */
|
713
|
+
/* Use release store to match with acquire load in fd_get_read_notifier */
|
714
|
+
gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
|
715
|
+
}
|
716
|
+
|
717
|
+
static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) {
|
718
|
+
fd->write_closure->SetReady(exec_ctx);
|
719
|
+
}
|
720
|
+
|
721
|
+
static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) {
|
722
|
+
gpr_mu_lock(&fd->pollable_mu);
|
723
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
724
|
+
static const char* err_desc = "fd_get_or_become_pollable";
|
725
|
+
if (fd->pollable_obj == nullptr) {
|
726
|
+
if (append_error(&error, pollable_create(PO_FD, &fd->pollable_obj),
|
727
|
+
err_desc)) {
|
728
|
+
fd->pollable_obj->owner_fd = fd;
|
729
|
+
if (!append_error(&error, pollable_add_fd(fd->pollable_obj, fd),
|
730
|
+
err_desc)) {
|
731
|
+
POLLABLE_UNREF(fd->pollable_obj, "fd_pollable");
|
732
|
+
fd->pollable_obj = nullptr;
|
733
|
+
}
|
734
|
+
}
|
735
|
+
}
|
736
|
+
if (error == GRPC_ERROR_NONE) {
|
737
|
+
GPR_ASSERT(fd->pollable_obj != nullptr);
|
738
|
+
*p = POLLABLE_REF(fd->pollable_obj, "pollset");
|
739
|
+
} else {
|
740
|
+
GPR_ASSERT(fd->pollable_obj == nullptr);
|
741
|
+
*p = nullptr;
|
742
|
+
}
|
743
|
+
gpr_mu_unlock(&fd->pollable_mu);
|
744
|
+
return error;
|
745
|
+
}
|
746
|
+
|
747
|
+
/* pollset->po.mu lock must be held by the caller before calling this */
|
748
|
+
static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
749
|
+
grpc_closure* closure) {
|
750
|
+
GPR_ASSERT(pollset->shutdown_closure == nullptr);
|
751
|
+
pollset->shutdown_closure = closure;
|
752
|
+
GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset));
|
753
|
+
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
754
|
+
}
|
755
|
+
|
756
|
+
static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx,
|
757
|
+
grpc_pollset* pollset,
|
758
|
+
pollable* pollable_obj, bool drain) {
|
759
|
+
static const char* err_desc = "pollset_process_events";
|
760
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
761
|
+
for (int i = 0; (drain || i < MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL) &&
|
762
|
+
pollable_obj->event_cursor != pollable_obj->event_count;
|
763
|
+
i++) {
|
764
|
+
int n = pollable_obj->event_cursor++;
|
765
|
+
struct epoll_event* ev = &pollable_obj->events[n];
|
766
|
+
void* data_ptr = ev->data.ptr;
|
767
|
+
if (1 & (intptr_t)data_ptr) {
|
768
|
+
if (grpc_polling_trace.enabled()) {
|
769
|
+
gpr_log(GPR_DEBUG, "PS:%p got pollset_wakeup %p", pollset, data_ptr);
|
770
|
+
}
|
771
|
+
append_error(&error,
|
772
|
+
grpc_wakeup_fd_consume_wakeup(
|
773
|
+
(grpc_wakeup_fd*)((~(intptr_t)1) & (intptr_t)data_ptr)),
|
774
|
+
err_desc);
|
775
|
+
} else {
|
776
|
+
grpc_fd* fd = (grpc_fd*)data_ptr;
|
777
|
+
bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0;
|
778
|
+
bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0;
|
779
|
+
bool write_ev = (ev->events & EPOLLOUT) != 0;
|
780
|
+
if (grpc_polling_trace.enabled()) {
|
781
|
+
gpr_log(GPR_DEBUG,
|
782
|
+
"PS:%p got fd %p: cancel=%d read=%d "
|
783
|
+
"write=%d",
|
784
|
+
pollset, fd, cancel, read_ev, write_ev);
|
785
|
+
}
|
786
|
+
if (read_ev || cancel) {
|
787
|
+
fd_become_readable(exec_ctx, fd, pollset);
|
788
|
+
}
|
789
|
+
if (write_ev || cancel) {
|
790
|
+
fd_become_writable(exec_ctx, fd);
|
791
|
+
}
|
792
|
+
}
|
793
|
+
}
|
794
|
+
|
795
|
+
return error;
|
796
|
+
}
|
797
|
+
|
798
|
+
/* pollset_shutdown is guaranteed to be called before pollset_destroy. */
|
799
|
+
static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) {
|
800
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
801
|
+
pollset->active_pollable = nullptr;
|
802
|
+
}
|
803
|
+
|
804
|
+
static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p,
|
805
|
+
grpc_millis deadline) {
|
806
|
+
int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline);
|
807
|
+
|
808
|
+
if (grpc_polling_trace.enabled()) {
|
809
|
+
char* desc = pollable_desc(p);
|
810
|
+
gpr_log(GPR_DEBUG, "POLLABLE:%p[%s] poll for %dms", p, desc, timeout);
|
811
|
+
gpr_free(desc);
|
812
|
+
}
|
813
|
+
|
814
|
+
if (timeout != 0) {
|
815
|
+
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
816
|
+
}
|
817
|
+
int r;
|
818
|
+
do {
|
819
|
+
GRPC_STATS_INC_SYSCALL_POLL(exec_ctx);
|
820
|
+
r = epoll_wait(p->epfd, p->events, MAX_EPOLL_EVENTS, timeout);
|
821
|
+
} while (r < 0 && errno == EINTR);
|
822
|
+
if (timeout != 0) {
|
823
|
+
GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx);
|
824
|
+
}
|
825
|
+
|
826
|
+
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
|
827
|
+
|
828
|
+
if (grpc_polling_trace.enabled()) {
|
829
|
+
gpr_log(GPR_DEBUG, "POLLABLE:%p got %d events", p, r);
|
830
|
+
}
|
831
|
+
|
832
|
+
p->event_cursor = 0;
|
833
|
+
p->event_count = r;
|
834
|
+
|
835
|
+
return GRPC_ERROR_NONE;
|
836
|
+
}
|
837
|
+
|
838
|
+
/* Return true if first in list */
|
839
|
+
static bool worker_insert(grpc_pollset_worker** root_worker,
|
840
|
+
grpc_pollset_worker* worker, pwlinks link) {
|
841
|
+
if (*root_worker == nullptr) {
|
842
|
+
*root_worker = worker;
|
843
|
+
worker->links[link].next = worker->links[link].prev = worker;
|
844
|
+
return true;
|
845
|
+
} else {
|
846
|
+
worker->links[link].next = *root_worker;
|
847
|
+
worker->links[link].prev = worker->links[link].next->links[link].prev;
|
848
|
+
worker->links[link].next->links[link].prev = worker;
|
849
|
+
worker->links[link].prev->links[link].next = worker;
|
850
|
+
return false;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
|
854
|
+
/* returns the new root IFF the root changed */
|
855
|
+
typedef enum { WRR_NEW_ROOT, WRR_EMPTIED, WRR_REMOVED } worker_remove_result;
|
856
|
+
|
857
|
+
static worker_remove_result worker_remove(grpc_pollset_worker** root_worker,
|
858
|
+
grpc_pollset_worker* worker,
|
859
|
+
pwlinks link) {
|
860
|
+
if (worker == *root_worker) {
|
861
|
+
if (worker == worker->links[link].next) {
|
862
|
+
*root_worker = nullptr;
|
863
|
+
return WRR_EMPTIED;
|
864
|
+
} else {
|
865
|
+
*root_worker = worker->links[link].next;
|
866
|
+
worker->links[link].prev->links[link].next = worker->links[link].next;
|
867
|
+
worker->links[link].next->links[link].prev = worker->links[link].prev;
|
868
|
+
return WRR_NEW_ROOT;
|
869
|
+
}
|
870
|
+
} else {
|
871
|
+
worker->links[link].prev->links[link].next = worker->links[link].next;
|
872
|
+
worker->links[link].next->links[link].prev = worker->links[link].prev;
|
873
|
+
return WRR_REMOVED;
|
874
|
+
}
|
875
|
+
}
|
876
|
+
|
877
|
+
/* Return true if this thread should poll */
|
878
|
+
static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
879
|
+
grpc_pollset_worker* worker,
|
880
|
+
grpc_pollset_worker** worker_hdl,
|
881
|
+
grpc_millis deadline) {
|
882
|
+
bool do_poll = (pollset->shutdown_closure == nullptr);
|
883
|
+
if (worker_hdl != nullptr) *worker_hdl = worker;
|
884
|
+
worker->initialized_cv = false;
|
885
|
+
worker->kicked = false;
|
886
|
+
worker->pollset = pollset;
|
887
|
+
worker->pollable_obj =
|
888
|
+
POLLABLE_REF(pollset->active_pollable, "pollset_worker");
|
889
|
+
worker_insert(&pollset->root_worker, worker, PWLINK_POLLSET);
|
890
|
+
gpr_mu_lock(&worker->pollable_obj->mu);
|
891
|
+
if (!worker_insert(&worker->pollable_obj->root_worker, worker,
|
892
|
+
PWLINK_POLLABLE)) {
|
893
|
+
worker->initialized_cv = true;
|
894
|
+
gpr_cv_init(&worker->cv);
|
895
|
+
gpr_mu_unlock(&pollset->mu);
|
896
|
+
if (grpc_polling_trace.enabled() &&
|
897
|
+
worker->pollable_obj->root_worker != worker) {
|
898
|
+
gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset,
|
899
|
+
worker->pollable_obj, worker,
|
900
|
+
poll_deadline_to_millis_timeout(exec_ctx, deadline));
|
901
|
+
}
|
902
|
+
while (do_poll && worker->pollable_obj->root_worker != worker) {
|
903
|
+
if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu,
|
904
|
+
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) {
|
905
|
+
if (grpc_polling_trace.enabled()) {
|
906
|
+
gpr_log(GPR_DEBUG, "PS:%p timeout_wait %p w=%p", pollset,
|
907
|
+
worker->pollable_obj, worker);
|
908
|
+
}
|
909
|
+
do_poll = false;
|
910
|
+
} else if (worker->kicked) {
|
911
|
+
if (grpc_polling_trace.enabled()) {
|
912
|
+
gpr_log(GPR_DEBUG, "PS:%p wakeup %p w=%p", pollset,
|
913
|
+
worker->pollable_obj, worker);
|
914
|
+
}
|
915
|
+
do_poll = false;
|
916
|
+
} else if (grpc_polling_trace.enabled() &&
|
917
|
+
worker->pollable_obj->root_worker != worker) {
|
918
|
+
gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset,
|
919
|
+
worker->pollable_obj, worker);
|
920
|
+
}
|
921
|
+
}
|
922
|
+
grpc_exec_ctx_invalidate_now(exec_ctx);
|
923
|
+
} else {
|
924
|
+
gpr_mu_unlock(&pollset->mu);
|
925
|
+
}
|
926
|
+
gpr_mu_unlock(&worker->pollable_obj->mu);
|
927
|
+
|
928
|
+
return do_poll;
|
929
|
+
}
|
930
|
+
|
931
|
+
static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
932
|
+
grpc_pollset_worker* worker,
|
933
|
+
grpc_pollset_worker** worker_hdl) {
|
934
|
+
gpr_mu_lock(&pollset->mu);
|
935
|
+
gpr_mu_lock(&worker->pollable_obj->mu);
|
936
|
+
switch (worker_remove(&worker->pollable_obj->root_worker, worker,
|
937
|
+
PWLINK_POLLABLE)) {
|
938
|
+
case WRR_NEW_ROOT: {
|
939
|
+
// wakeup new poller
|
940
|
+
grpc_pollset_worker* new_root = worker->pollable_obj->root_worker;
|
941
|
+
GPR_ASSERT(new_root->initialized_cv);
|
942
|
+
gpr_cv_signal(&new_root->cv);
|
943
|
+
break;
|
944
|
+
}
|
945
|
+
case WRR_EMPTIED:
|
946
|
+
if (pollset->active_pollable != worker->pollable_obj) {
|
947
|
+
// pollable no longer being polled: flush events
|
948
|
+
pollable_process_events(exec_ctx, pollset, worker->pollable_obj, true);
|
949
|
+
}
|
950
|
+
break;
|
951
|
+
case WRR_REMOVED:
|
952
|
+
break;
|
953
|
+
}
|
954
|
+
gpr_mu_unlock(&worker->pollable_obj->mu);
|
955
|
+
POLLABLE_UNREF(worker->pollable_obj, "pollset_worker");
|
956
|
+
if (worker_remove(&pollset->root_worker, worker, PWLINK_POLLSET) ==
|
957
|
+
WRR_EMPTIED) {
|
958
|
+
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
959
|
+
}
|
960
|
+
if (worker->initialized_cv) {
|
961
|
+
gpr_cv_destroy(&worker->cv);
|
962
|
+
}
|
963
|
+
}
|
964
|
+
|
965
|
+
#ifndef NDEBUG
|
966
|
+
static long gettid(void) { return syscall(__NR_gettid); }
|
967
|
+
#endif
|
968
|
+
|
969
|
+
/* pollset->mu lock must be held by the caller before calling this.
|
970
|
+
The function pollset_work() may temporarily release the lock (pollset->po.mu)
|
971
|
+
during the course of its execution but it will always re-acquire the lock and
|
972
|
+
ensure that it is held by the time the function returns */
|
973
|
+
static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
974
|
+
grpc_pollset_worker** worker_hdl,
|
975
|
+
grpc_millis deadline) {
|
976
|
+
#ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP
|
977
|
+
grpc_pollset_worker* worker =
|
978
|
+
(grpc_pollset_worker*)gpr_malloc(sizeof(*worker));
|
979
|
+
#define WORKER_PTR (worker)
|
980
|
+
#else
|
981
|
+
grpc_pollset_worker worker;
|
982
|
+
#define WORKER_PTR (&worker)
|
983
|
+
#endif
|
984
|
+
#ifndef NDEBUG
|
985
|
+
WORKER_PTR->originator = gettid();
|
986
|
+
#endif
|
987
|
+
if (grpc_polling_trace.enabled()) {
|
988
|
+
gpr_log(GPR_DEBUG,
|
989
|
+
"PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR
|
990
|
+
" kwp=%d pollable=%p",
|
991
|
+
pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(exec_ctx),
|
992
|
+
deadline, pollset->kicked_without_poller, pollset->active_pollable);
|
993
|
+
}
|
994
|
+
static const char* err_desc = "pollset_work";
|
995
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
996
|
+
if (pollset->kicked_without_poller) {
|
997
|
+
pollset->kicked_without_poller = false;
|
998
|
+
} else {
|
999
|
+
if (begin_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl, deadline)) {
|
1000
|
+
gpr_tls_set(&g_current_thread_pollset, (intptr_t)pollset);
|
1001
|
+
gpr_tls_set(&g_current_thread_worker, (intptr_t)WORKER_PTR);
|
1002
|
+
if (WORKER_PTR->pollable_obj->event_cursor ==
|
1003
|
+
WORKER_PTR->pollable_obj->event_count) {
|
1004
|
+
append_error(
|
1005
|
+
&error,
|
1006
|
+
pollable_epoll(exec_ctx, WORKER_PTR->pollable_obj, deadline),
|
1007
|
+
err_desc);
|
1008
|
+
}
|
1009
|
+
append_error(&error,
|
1010
|
+
pollable_process_events(exec_ctx, pollset,
|
1011
|
+
WORKER_PTR->pollable_obj, false),
|
1012
|
+
err_desc);
|
1013
|
+
grpc_exec_ctx_flush(exec_ctx);
|
1014
|
+
gpr_tls_set(&g_current_thread_pollset, 0);
|
1015
|
+
gpr_tls_set(&g_current_thread_worker, 0);
|
1016
|
+
}
|
1017
|
+
end_worker(exec_ctx, pollset, WORKER_PTR, worker_hdl);
|
1018
|
+
}
|
1019
|
+
#ifdef GRPC_EPOLLEX_CREATE_WORKERS_ON_HEAP
|
1020
|
+
gpr_free(worker);
|
1021
|
+
#endif
|
1022
|
+
#undef WORKER_PTR
|
1023
|
+
return error;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked(
|
1027
|
+
grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* fd) {
|
1028
|
+
static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd";
|
1029
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1030
|
+
if (grpc_polling_trace.enabled()) {
|
1031
|
+
gpr_log(GPR_DEBUG,
|
1032
|
+
"PS:%p add fd %p (%d); transition pollable from empty to fd",
|
1033
|
+
pollset, fd, fd->fd);
|
1034
|
+
}
|
1035
|
+
append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc);
|
1036
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1037
|
+
append_error(&error, fd_get_or_become_pollable(fd, &pollset->active_pollable),
|
1038
|
+
err_desc);
|
1039
|
+
return error;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked(
|
1043
|
+
grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* and_add_fd) {
|
1044
|
+
static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi";
|
1045
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1046
|
+
if (grpc_polling_trace.enabled()) {
|
1047
|
+
gpr_log(
|
1048
|
+
GPR_DEBUG,
|
1049
|
+
"PS:%p add fd %p (%d); transition pollable from fd %p to multipoller",
|
1050
|
+
pollset, and_add_fd, and_add_fd ? and_add_fd->fd : -1,
|
1051
|
+
pollset->active_pollable->owner_fd);
|
1052
|
+
}
|
1053
|
+
append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc);
|
1054
|
+
grpc_fd* initial_fd = pollset->active_pollable->owner_fd;
|
1055
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1056
|
+
pollset->active_pollable = nullptr;
|
1057
|
+
if (append_error(&error, pollable_create(PO_MULTI, &pollset->active_pollable),
|
1058
|
+
err_desc)) {
|
1059
|
+
append_error(&error, pollable_add_fd(pollset->active_pollable, initial_fd),
|
1060
|
+
err_desc);
|
1061
|
+
if (and_add_fd != nullptr) {
|
1062
|
+
append_error(&error,
|
1063
|
+
pollable_add_fd(pollset->active_pollable, and_add_fd),
|
1064
|
+
err_desc);
|
1065
|
+
}
|
1066
|
+
}
|
1067
|
+
return error;
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
/* expects pollsets locked, flag whether fd is locked or not */
|
1071
|
+
static grpc_error* pollset_add_fd_locked(grpc_exec_ctx* exec_ctx,
|
1072
|
+
grpc_pollset* pollset, grpc_fd* fd) {
|
1073
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1074
|
+
pollable* po_at_start =
|
1075
|
+
POLLABLE_REF(pollset->active_pollable, "pollset_add_fd");
|
1076
|
+
switch (pollset->active_pollable->type) {
|
1077
|
+
case PO_EMPTY:
|
1078
|
+
/* empty pollable --> single fd pollable */
|
1079
|
+
error = pollset_transition_pollable_from_empty_to_fd_locked(exec_ctx,
|
1080
|
+
pollset, fd);
|
1081
|
+
break;
|
1082
|
+
case PO_FD:
|
1083
|
+
gpr_mu_lock(&po_at_start->owner_fd->orphan_mu);
|
1084
|
+
if ((gpr_atm_no_barrier_load(&pollset->active_pollable->owner_fd->refst) &
|
1085
|
+
1) == 0) {
|
1086
|
+
error = pollset_transition_pollable_from_empty_to_fd_locked(
|
1087
|
+
exec_ctx, pollset, fd);
|
1088
|
+
} else {
|
1089
|
+
/* fd --> multipoller */
|
1090
|
+
error = pollset_transition_pollable_from_fd_to_multi_locked(
|
1091
|
+
exec_ctx, pollset, fd);
|
1092
|
+
}
|
1093
|
+
gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu);
|
1094
|
+
break;
|
1095
|
+
case PO_MULTI:
|
1096
|
+
error = pollable_add_fd(pollset->active_pollable, fd);
|
1097
|
+
break;
|
1098
|
+
}
|
1099
|
+
if (error != GRPC_ERROR_NONE) {
|
1100
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1101
|
+
pollset->active_pollable = po_at_start;
|
1102
|
+
} else {
|
1103
|
+
POLLABLE_UNREF(po_at_start, "pollset_add_fd");
|
1104
|
+
}
|
1105
|
+
return error;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx,
|
1109
|
+
grpc_pollset* pollset,
|
1110
|
+
pollable** pollable_obj) {
|
1111
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1112
|
+
pollable* po_at_start =
|
1113
|
+
POLLABLE_REF(pollset->active_pollable, "pollset_as_multipollable");
|
1114
|
+
switch (pollset->active_pollable->type) {
|
1115
|
+
case PO_EMPTY:
|
1116
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1117
|
+
error = pollable_create(PO_MULTI, &pollset->active_pollable);
|
1118
|
+
break;
|
1119
|
+
case PO_FD:
|
1120
|
+
gpr_mu_lock(&po_at_start->owner_fd->orphan_mu);
|
1121
|
+
if ((gpr_atm_no_barrier_load(&pollset->active_pollable->owner_fd->refst) &
|
1122
|
+
1) == 0) {
|
1123
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1124
|
+
error = pollable_create(PO_MULTI, &pollset->active_pollable);
|
1125
|
+
} else {
|
1126
|
+
error = pollset_transition_pollable_from_fd_to_multi_locked(
|
1127
|
+
exec_ctx, pollset, nullptr);
|
1128
|
+
}
|
1129
|
+
gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu);
|
1130
|
+
break;
|
1131
|
+
case PO_MULTI:
|
1132
|
+
break;
|
1133
|
+
}
|
1134
|
+
if (error != GRPC_ERROR_NONE) {
|
1135
|
+
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1136
|
+
pollset->active_pollable = po_at_start;
|
1137
|
+
*pollable_obj = nullptr;
|
1138
|
+
} else {
|
1139
|
+
*pollable_obj = POLLABLE_REF(pollset->active_pollable, "pollset_set");
|
1140
|
+
POLLABLE_UNREF(po_at_start, "pollset_as_multipollable");
|
1141
|
+
}
|
1142
|
+
return error;
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
|
1146
|
+
grpc_fd* fd) {
|
1147
|
+
gpr_mu_lock(&pollset->mu);
|
1148
|
+
grpc_error* error = pollset_add_fd_locked(exec_ctx, pollset, fd);
|
1149
|
+
gpr_mu_unlock(&pollset->mu);
|
1150
|
+
GRPC_LOG_IF_ERROR("pollset_add_fd", error);
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
/*******************************************************************************
|
1154
|
+
* Pollset-set Definitions
|
1155
|
+
*/
|
1156
|
+
|
1157
|
+
static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) {
|
1158
|
+
gpr_mu_lock(&pss->mu);
|
1159
|
+
while (pss->parent != nullptr) {
|
1160
|
+
gpr_mu_unlock(&pss->mu);
|
1161
|
+
pss = pss->parent;
|
1162
|
+
gpr_mu_lock(&pss->mu);
|
1163
|
+
}
|
1164
|
+
return pss;
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
static grpc_pollset_set* pollset_set_create(void) {
|
1168
|
+
grpc_pollset_set* pss = (grpc_pollset_set*)gpr_zalloc(sizeof(*pss));
|
1169
|
+
gpr_mu_init(&pss->mu);
|
1170
|
+
gpr_ref_init(&pss->refs, 1);
|
1171
|
+
return pss;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
static void pollset_set_unref(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) {
|
1175
|
+
if (pss == nullptr) return;
|
1176
|
+
if (!gpr_unref(&pss->refs)) return;
|
1177
|
+
pollset_set_unref(exec_ctx, pss->parent);
|
1178
|
+
gpr_mu_destroy(&pss->mu);
|
1179
|
+
for (size_t i = 0; i < pss->pollset_count; i++) {
|
1180
|
+
gpr_mu_lock(&pss->pollsets[i]->mu);
|
1181
|
+
if (0 == --pss->pollsets[i]->containing_pollset_set_count) {
|
1182
|
+
pollset_maybe_finish_shutdown(exec_ctx, pss->pollsets[i]);
|
1183
|
+
}
|
1184
|
+
gpr_mu_unlock(&pss->pollsets[i]->mu);
|
1185
|
+
}
|
1186
|
+
for (size_t i = 0; i < pss->fd_count; i++) {
|
1187
|
+
UNREF_BY(exec_ctx, pss->fds[i], 2, "pollset_set");
|
1188
|
+
}
|
1189
|
+
gpr_free(pss->pollsets);
|
1190
|
+
gpr_free(pss->fds);
|
1191
|
+
gpr_free(pss);
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
static void pollset_set_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss,
|
1195
|
+
grpc_fd* fd) {
|
1196
|
+
if (grpc_polling_trace.enabled()) {
|
1197
|
+
gpr_log(GPR_DEBUG, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd);
|
1198
|
+
}
|
1199
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1200
|
+
static const char* err_desc = "pollset_set_add_fd";
|
1201
|
+
pss = pss_lock_adam(pss);
|
1202
|
+
for (size_t i = 0; i < pss->pollset_count; i++) {
|
1203
|
+
append_error(&error, pollable_add_fd(pss->pollsets[i]->active_pollable, fd),
|
1204
|
+
err_desc);
|
1205
|
+
}
|
1206
|
+
if (pss->fd_count == pss->fd_capacity) {
|
1207
|
+
pss->fd_capacity = GPR_MAX(pss->fd_capacity * 2, 8);
|
1208
|
+
pss->fds =
|
1209
|
+
(grpc_fd**)gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds));
|
1210
|
+
}
|
1211
|
+
REF_BY(fd, 2, "pollset_set");
|
1212
|
+
pss->fds[pss->fd_count++] = fd;
|
1213
|
+
gpr_mu_unlock(&pss->mu);
|
1214
|
+
|
1215
|
+
GRPC_LOG_IF_ERROR(err_desc, error);
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
static void pollset_set_del_fd(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss,
|
1219
|
+
grpc_fd* fd) {
|
1220
|
+
if (grpc_polling_trace.enabled()) {
|
1221
|
+
gpr_log(GPR_DEBUG, "PSS:%p: del fd %p", pss, fd);
|
1222
|
+
}
|
1223
|
+
pss = pss_lock_adam(pss);
|
1224
|
+
size_t i;
|
1225
|
+
for (i = 0; i < pss->fd_count; i++) {
|
1226
|
+
if (pss->fds[i] == fd) {
|
1227
|
+
UNREF_BY(exec_ctx, fd, 2, "pollset_set");
|
1228
|
+
break;
|
1229
|
+
}
|
1230
|
+
}
|
1231
|
+
GPR_ASSERT(i != pss->fd_count);
|
1232
|
+
for (; i < pss->fd_count - 1; i++) {
|
1233
|
+
pss->fds[i] = pss->fds[i + 1];
|
1234
|
+
}
|
1235
|
+
pss->fd_count--;
|
1236
|
+
gpr_mu_unlock(&pss->mu);
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
static void pollset_set_del_pollset(grpc_exec_ctx* exec_ctx,
|
1240
|
+
grpc_pollset_set* pss, grpc_pollset* ps) {
|
1241
|
+
if (grpc_polling_trace.enabled()) {
|
1242
|
+
gpr_log(GPR_DEBUG, "PSS:%p: del pollset %p", pss, ps);
|
1243
|
+
}
|
1244
|
+
pss = pss_lock_adam(pss);
|
1245
|
+
size_t i;
|
1246
|
+
for (i = 0; i < pss->pollset_count; i++) {
|
1247
|
+
if (pss->pollsets[i] == ps) {
|
1248
|
+
break;
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
GPR_ASSERT(i != pss->pollset_count);
|
1252
|
+
for (; i < pss->pollset_count - 1; i++) {
|
1253
|
+
pss->pollsets[i] = pss->pollsets[i + 1];
|
1254
|
+
}
|
1255
|
+
pss->pollset_count--;
|
1256
|
+
gpr_mu_unlock(&pss->mu);
|
1257
|
+
gpr_mu_lock(&ps->mu);
|
1258
|
+
if (0 == --ps->containing_pollset_set_count) {
|
1259
|
+
pollset_maybe_finish_shutdown(exec_ctx, ps);
|
1260
|
+
}
|
1261
|
+
gpr_mu_unlock(&ps->mu);
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
// add all fds to pollables, and output a new array of unorphaned out_fds
|
1265
|
+
// assumes pollsets are multipollable
|
1266
|
+
static grpc_error* add_fds_to_pollsets(grpc_exec_ctx* exec_ctx, grpc_fd** fds,
|
1267
|
+
size_t fd_count, grpc_pollset** pollsets,
|
1268
|
+
size_t pollset_count,
|
1269
|
+
const char* err_desc, grpc_fd** out_fds,
|
1270
|
+
size_t* out_fd_count) {
|
1271
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1272
|
+
for (size_t i = 0; i < fd_count; i++) {
|
1273
|
+
gpr_mu_lock(&fds[i]->orphan_mu);
|
1274
|
+
if ((gpr_atm_no_barrier_load(&fds[i]->refst) & 1) == 0) {
|
1275
|
+
gpr_mu_unlock(&fds[i]->orphan_mu);
|
1276
|
+
UNREF_BY(exec_ctx, fds[i], 2, "pollset_set");
|
1277
|
+
} else {
|
1278
|
+
for (size_t j = 0; j < pollset_count; j++) {
|
1279
|
+
append_error(&error,
|
1280
|
+
pollable_add_fd(pollsets[j]->active_pollable, fds[i]),
|
1281
|
+
err_desc);
|
1282
|
+
}
|
1283
|
+
gpr_mu_unlock(&fds[i]->orphan_mu);
|
1284
|
+
out_fds[(*out_fd_count)++] = fds[i];
|
1285
|
+
}
|
1286
|
+
}
|
1287
|
+
return error;
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx,
|
1291
|
+
grpc_pollset_set* pss, grpc_pollset* ps) {
|
1292
|
+
if (grpc_polling_trace.enabled()) {
|
1293
|
+
gpr_log(GPR_DEBUG, "PSS:%p: add pollset %p", pss, ps);
|
1294
|
+
}
|
1295
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1296
|
+
static const char* err_desc = "pollset_set_add_pollset";
|
1297
|
+
pollable* pollable_obj = nullptr;
|
1298
|
+
gpr_mu_lock(&ps->mu);
|
1299
|
+
if (!GRPC_LOG_IF_ERROR(err_desc, pollset_as_multipollable_locked(
|
1300
|
+
exec_ctx, ps, &pollable_obj))) {
|
1301
|
+
GPR_ASSERT(pollable_obj == nullptr);
|
1302
|
+
gpr_mu_unlock(&ps->mu);
|
1303
|
+
return;
|
1304
|
+
}
|
1305
|
+
ps->containing_pollset_set_count++;
|
1306
|
+
gpr_mu_unlock(&ps->mu);
|
1307
|
+
pss = pss_lock_adam(pss);
|
1308
|
+
size_t initial_fd_count = pss->fd_count;
|
1309
|
+
pss->fd_count = 0;
|
1310
|
+
append_error(&error,
|
1311
|
+
add_fds_to_pollsets(exec_ctx, pss->fds, initial_fd_count, &ps, 1,
|
1312
|
+
err_desc, pss->fds, &pss->fd_count),
|
1313
|
+
err_desc);
|
1314
|
+
if (pss->pollset_count == pss->pollset_capacity) {
|
1315
|
+
pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8);
|
1316
|
+
pss->pollsets = (grpc_pollset**)gpr_realloc(
|
1317
|
+
pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets));
|
1318
|
+
}
|
1319
|
+
pss->pollsets[pss->pollset_count++] = ps;
|
1320
|
+
gpr_mu_unlock(&pss->mu);
|
1321
|
+
POLLABLE_UNREF(pollable_obj, "pollset_set");
|
1322
|
+
|
1323
|
+
GRPC_LOG_IF_ERROR(err_desc, error);
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx,
|
1327
|
+
grpc_pollset_set* a,
|
1328
|
+
grpc_pollset_set* b) {
|
1329
|
+
if (grpc_polling_trace.enabled()) {
|
1330
|
+
gpr_log(GPR_DEBUG, "PSS: merge (%p, %p)", a, b);
|
1331
|
+
}
|
1332
|
+
grpc_error* error = GRPC_ERROR_NONE;
|
1333
|
+
static const char* err_desc = "pollset_set_add_fd";
|
1334
|
+
for (;;) {
|
1335
|
+
if (a == b) {
|
1336
|
+
// pollset ancestors are the same: nothing to do
|
1337
|
+
return;
|
1338
|
+
}
|
1339
|
+
if (a > b) {
|
1340
|
+
GPR_SWAP(grpc_pollset_set*, a, b);
|
1341
|
+
}
|
1342
|
+
gpr_mu* a_mu = &a->mu;
|
1343
|
+
gpr_mu* b_mu = &b->mu;
|
1344
|
+
gpr_mu_lock(a_mu);
|
1345
|
+
gpr_mu_lock(b_mu);
|
1346
|
+
if (a->parent != nullptr) {
|
1347
|
+
a = a->parent;
|
1348
|
+
} else if (b->parent != nullptr) {
|
1349
|
+
b = b->parent;
|
1350
|
+
} else {
|
1351
|
+
break; // exit loop, both pollsets locked
|
1352
|
+
}
|
1353
|
+
gpr_mu_unlock(a_mu);
|
1354
|
+
gpr_mu_unlock(b_mu);
|
1355
|
+
}
|
1356
|
+
// try to do the least copying possible
|
1357
|
+
// TODO(ctiller): there's probably a better heuristic here
|
1358
|
+
const size_t a_size = a->fd_count + a->pollset_count;
|
1359
|
+
const size_t b_size = b->fd_count + b->pollset_count;
|
1360
|
+
if (b_size > a_size) {
|
1361
|
+
GPR_SWAP(grpc_pollset_set*, a, b);
|
1362
|
+
}
|
1363
|
+
if (grpc_polling_trace.enabled()) {
|
1364
|
+
gpr_log(GPR_DEBUG, "PSS: parent %p to %p", b, a);
|
1365
|
+
}
|
1366
|
+
gpr_ref(&a->refs);
|
1367
|
+
b->parent = a;
|
1368
|
+
if (a->fd_capacity < a->fd_count + b->fd_count) {
|
1369
|
+
a->fd_capacity = GPR_MAX(2 * a->fd_capacity, a->fd_count + b->fd_count);
|
1370
|
+
a->fds = (grpc_fd**)gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds));
|
1371
|
+
}
|
1372
|
+
size_t initial_a_fd_count = a->fd_count;
|
1373
|
+
a->fd_count = 0;
|
1374
|
+
append_error(
|
1375
|
+
&error,
|
1376
|
+
add_fds_to_pollsets(exec_ctx, a->fds, initial_a_fd_count, b->pollsets,
|
1377
|
+
b->pollset_count, "merge_a2b", a->fds, &a->fd_count),
|
1378
|
+
err_desc);
|
1379
|
+
append_error(
|
1380
|
+
&error,
|
1381
|
+
add_fds_to_pollsets(exec_ctx, b->fds, b->fd_count, a->pollsets,
|
1382
|
+
a->pollset_count, "merge_b2a", a->fds, &a->fd_count),
|
1383
|
+
err_desc);
|
1384
|
+
if (a->pollset_capacity < a->pollset_count + b->pollset_count) {
|
1385
|
+
a->pollset_capacity =
|
1386
|
+
GPR_MAX(2 * a->pollset_capacity, a->pollset_count + b->pollset_count);
|
1387
|
+
a->pollsets = (grpc_pollset**)gpr_realloc(
|
1388
|
+
a->pollsets, a->pollset_capacity * sizeof(*a->pollsets));
|
1389
|
+
}
|
1390
|
+
if (b->pollset_count > 0) {
|
1391
|
+
memcpy(a->pollsets + a->pollset_count, b->pollsets,
|
1392
|
+
b->pollset_count * sizeof(*b->pollsets));
|
1393
|
+
}
|
1394
|
+
a->pollset_count += b->pollset_count;
|
1395
|
+
gpr_free(b->fds);
|
1396
|
+
gpr_free(b->pollsets);
|
1397
|
+
b->fds = nullptr;
|
1398
|
+
b->pollsets = nullptr;
|
1399
|
+
b->fd_count = b->fd_capacity = b->pollset_count = b->pollset_capacity = 0;
|
1400
|
+
gpr_mu_unlock(&a->mu);
|
1401
|
+
gpr_mu_unlock(&b->mu);
|
1402
|
+
}
|
1403
|
+
|
1404
|
+
static void pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx,
|
1405
|
+
grpc_pollset_set* bag,
|
1406
|
+
grpc_pollset_set* item) {}
|
1407
|
+
|
1408
|
+
/*******************************************************************************
|
1409
|
+
* Event engine binding
|
1410
|
+
*/
|
1411
|
+
|
1412
|
+
static void shutdown_engine(void) {
|
1413
|
+
fd_global_shutdown();
|
1414
|
+
pollset_global_shutdown();
|
1415
|
+
}
|
1416
|
+
|
1417
|
+
static const grpc_event_engine_vtable vtable = {
|
1418
|
+
sizeof(grpc_pollset),
|
1419
|
+
|
1420
|
+
fd_create,
|
1421
|
+
fd_wrapped_fd,
|
1422
|
+
fd_orphan,
|
1423
|
+
fd_shutdown,
|
1424
|
+
fd_notify_on_read,
|
1425
|
+
fd_notify_on_write,
|
1426
|
+
fd_is_shutdown,
|
1427
|
+
fd_get_read_notifier_pollset,
|
1428
|
+
|
1429
|
+
pollset_init,
|
1430
|
+
pollset_shutdown,
|
1431
|
+
pollset_destroy,
|
1432
|
+
pollset_work,
|
1433
|
+
pollset_kick,
|
1434
|
+
pollset_add_fd,
|
1435
|
+
|
1436
|
+
pollset_set_create,
|
1437
|
+
pollset_set_unref, // destroy ==> unref 1 public ref
|
1438
|
+
pollset_set_add_pollset,
|
1439
|
+
pollset_set_del_pollset,
|
1440
|
+
pollset_set_add_pollset_set,
|
1441
|
+
pollset_set_del_pollset_set,
|
1442
|
+
pollset_set_add_fd,
|
1443
|
+
pollset_set_del_fd,
|
1444
|
+
|
1445
|
+
shutdown_engine,
|
1446
|
+
};
|
1447
|
+
|
1448
|
+
const grpc_event_engine_vtable* grpc_init_epollex_linux(
|
1449
|
+
bool explicitly_requested) {
|
1450
|
+
if (!explicitly_requested) {
|
1451
|
+
return nullptr;
|
1452
|
+
}
|
1453
|
+
|
1454
|
+
if (!grpc_has_wakeup_fd()) {
|
1455
|
+
gpr_log(GPR_ERROR, "Skipping epollex because of no wakeup fd.");
|
1456
|
+
return nullptr;
|
1457
|
+
}
|
1458
|
+
|
1459
|
+
if (!grpc_is_epollexclusive_available()) {
|
1460
|
+
gpr_log(GPR_INFO, "Skipping epollex because it is not supported.");
|
1461
|
+
return nullptr;
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
fd_global_init();
|
1465
|
+
|
1466
|
+
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
|
1467
|
+
pollset_global_shutdown();
|
1468
|
+
fd_global_shutdown();
|
1469
|
+
return nullptr;
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
return &vtable;
|
1473
|
+
}
|
1474
|
+
|
1475
|
+
#else /* defined(GRPC_LINUX_EPOLL) */
|
1476
|
+
#if defined(GRPC_POSIX_SOCKET)
|
1477
|
+
#include "src/core/lib/iomgr/ev_epollex_linux.h"
|
1478
|
+
/* If GRPC_LINUX_EPOLL is not defined, it means epoll is not available. Return
|
1479
|
+
* NULL */
|
1480
|
+
const grpc_event_engine_vtable* grpc_init_epollex_linux(
|
1481
|
+
bool explicitly_requested) {
|
1482
|
+
gpr_log(GPR_ERROR,
|
1483
|
+
"Skipping epollex becuase GRPC_LINUX_EPOLL is not defined.");
|
1484
|
+
return NULL;
|
1485
|
+
}
|
1486
|
+
#endif /* defined(GRPC_POSIX_SOCKET) */
|
1487
|
+
|
1488
|
+
#endif /* !defined(GRPC_LINUX_EPOLL) */
|