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
data/src/core/lib/debug/trace.c
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
*
|
3
|
-
* Copyright 2015 gRPC authors.
|
4
|
-
*
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
* you may not use this file except in compliance with the License.
|
7
|
-
* You may obtain a copy of the License at
|
8
|
-
*
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
*
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
* See the License for the specific language governing permissions and
|
15
|
-
* limitations under the License.
|
16
|
-
*
|
17
|
-
*/
|
18
|
-
|
19
|
-
#include "src/core/lib/debug/trace.h"
|
20
|
-
|
21
|
-
#include <string.h>
|
22
|
-
|
23
|
-
#include <grpc/support/alloc.h>
|
24
|
-
#include <grpc/support/log.h>
|
25
|
-
#include "src/core/lib/support/env.h"
|
26
|
-
|
27
|
-
int grpc_tracer_set_enabled(const char *name, int enabled);
|
28
|
-
|
29
|
-
typedef struct tracer {
|
30
|
-
grpc_tracer_flag *flag;
|
31
|
-
struct tracer *next;
|
32
|
-
} tracer;
|
33
|
-
static tracer *tracers;
|
34
|
-
|
35
|
-
#ifdef GRPC_THREADSAFE_TRACER
|
36
|
-
#define TRACER_SET(flag, on) gpr_atm_no_barrier_store(&(flag).value, (on))
|
37
|
-
#else
|
38
|
-
#define TRACER_SET(flag, on) (flag).value = (on)
|
39
|
-
#endif
|
40
|
-
|
41
|
-
void grpc_register_tracer(grpc_tracer_flag *flag) {
|
42
|
-
tracer *t = (tracer *)gpr_malloc(sizeof(*t));
|
43
|
-
t->flag = flag;
|
44
|
-
t->next = tracers;
|
45
|
-
TRACER_SET(*flag, false);
|
46
|
-
tracers = t;
|
47
|
-
}
|
48
|
-
|
49
|
-
static void add(const char *beg, const char *end, char ***ss, size_t *ns) {
|
50
|
-
size_t n = *ns;
|
51
|
-
size_t np = n + 1;
|
52
|
-
char *s;
|
53
|
-
size_t len;
|
54
|
-
GPR_ASSERT(end >= beg);
|
55
|
-
len = (size_t)(end - beg);
|
56
|
-
s = (char *)gpr_malloc(len + 1);
|
57
|
-
memcpy(s, beg, len);
|
58
|
-
s[len] = 0;
|
59
|
-
*ss = (char **)gpr_realloc(*ss, sizeof(char **) * np);
|
60
|
-
(*ss)[n] = s;
|
61
|
-
*ns = np;
|
62
|
-
}
|
63
|
-
|
64
|
-
static void split(const char *s, char ***ss, size_t *ns) {
|
65
|
-
const char *c = strchr(s, ',');
|
66
|
-
if (c == NULL) {
|
67
|
-
add(s, s + strlen(s), ss, ns);
|
68
|
-
} else {
|
69
|
-
add(s, c, ss, ns);
|
70
|
-
split(c + 1, ss, ns);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
static void parse(const char *s) {
|
75
|
-
char **strings = NULL;
|
76
|
-
size_t nstrings = 0;
|
77
|
-
size_t i;
|
78
|
-
split(s, &strings, &nstrings);
|
79
|
-
|
80
|
-
for (i = 0; i < nstrings; i++) {
|
81
|
-
if (strings[i][0] == '-') {
|
82
|
-
grpc_tracer_set_enabled(strings[i] + 1, 0);
|
83
|
-
} else {
|
84
|
-
grpc_tracer_set_enabled(strings[i], 1);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
for (i = 0; i < nstrings; i++) {
|
89
|
-
gpr_free(strings[i]);
|
90
|
-
}
|
91
|
-
gpr_free(strings);
|
92
|
-
}
|
93
|
-
|
94
|
-
static void list_tracers() {
|
95
|
-
gpr_log(GPR_DEBUG, "available tracers:");
|
96
|
-
tracer *t;
|
97
|
-
for (t = tracers; t; t = t->next) {
|
98
|
-
gpr_log(GPR_DEBUG, "\t%s", t->flag->name);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
void grpc_tracer_init(const char *env_var) {
|
103
|
-
char *e = gpr_getenv(env_var);
|
104
|
-
if (e != NULL) {
|
105
|
-
parse(e);
|
106
|
-
gpr_free(e);
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
void grpc_tracer_shutdown(void) {
|
111
|
-
while (tracers) {
|
112
|
-
tracer *t = tracers;
|
113
|
-
tracers = t->next;
|
114
|
-
gpr_free(t);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
int grpc_tracer_set_enabled(const char *name, int enabled) {
|
119
|
-
tracer *t;
|
120
|
-
if (0 == strcmp(name, "all")) {
|
121
|
-
for (t = tracers; t; t = t->next) {
|
122
|
-
TRACER_SET(*t->flag, enabled);
|
123
|
-
}
|
124
|
-
} else if (0 == strcmp(name, "list_tracers")) {
|
125
|
-
list_tracers();
|
126
|
-
} else if (0 == strcmp(name, "refcount")) {
|
127
|
-
for (t = tracers; t; t = t->next) {
|
128
|
-
if (strstr(t->flag->name, "refcount") != NULL) {
|
129
|
-
TRACER_SET(*t->flag, enabled);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
} else {
|
133
|
-
int found = 0;
|
134
|
-
for (t = tracers; t; t = t->next) {
|
135
|
-
if (0 == strcmp(name, t->flag->name)) {
|
136
|
-
TRACER_SET(*t->flag, enabled);
|
137
|
-
found = 1;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
if (!found) {
|
141
|
-
gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
|
142
|
-
return 0; /* early return */
|
143
|
-
}
|
144
|
-
}
|
145
|
-
return 1;
|
146
|
-
}
|
@@ -1,219 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
*
|
3
|
-
* Copyright 2015 gRPC authors.
|
4
|
-
*
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
* you may not use this file except in compliance with the License.
|
7
|
-
* You may obtain a copy of the License at
|
8
|
-
*
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
*
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
* See the License for the specific language governing permissions and
|
15
|
-
* limitations under the License.
|
16
|
-
*
|
17
|
-
*/
|
18
|
-
|
19
|
-
#include "src/core/lib/iomgr/closure.h"
|
20
|
-
|
21
|
-
#include <assert.h>
|
22
|
-
#include <grpc/support/alloc.h>
|
23
|
-
#include <grpc/support/log.h>
|
24
|
-
|
25
|
-
#include "src/core/lib/profiling/timers.h"
|
26
|
-
|
27
|
-
#ifndef NDEBUG
|
28
|
-
grpc_tracer_flag grpc_trace_closure = GRPC_TRACER_INITIALIZER(false, "closure");
|
29
|
-
#endif
|
30
|
-
|
31
|
-
#ifndef NDEBUG
|
32
|
-
grpc_closure *grpc_closure_init(const char *file, int line,
|
33
|
-
grpc_closure *closure, grpc_iomgr_cb_func cb,
|
34
|
-
void *cb_arg,
|
35
|
-
grpc_closure_scheduler *scheduler) {
|
36
|
-
#else
|
37
|
-
grpc_closure *grpc_closure_init(grpc_closure *closure, grpc_iomgr_cb_func cb,
|
38
|
-
void *cb_arg,
|
39
|
-
grpc_closure_scheduler *scheduler) {
|
40
|
-
#endif
|
41
|
-
closure->cb = cb;
|
42
|
-
closure->cb_arg = cb_arg;
|
43
|
-
closure->scheduler = scheduler;
|
44
|
-
#ifndef NDEBUG
|
45
|
-
closure->scheduled = false;
|
46
|
-
closure->file_initiated = NULL;
|
47
|
-
closure->line_initiated = 0;
|
48
|
-
closure->run = false;
|
49
|
-
closure->file_created = file;
|
50
|
-
closure->line_created = line;
|
51
|
-
#endif
|
52
|
-
return closure;
|
53
|
-
}
|
54
|
-
|
55
|
-
void grpc_closure_list_init(grpc_closure_list *closure_list) {
|
56
|
-
closure_list->head = closure_list->tail = NULL;
|
57
|
-
}
|
58
|
-
|
59
|
-
bool grpc_closure_list_append(grpc_closure_list *closure_list,
|
60
|
-
grpc_closure *closure, grpc_error *error) {
|
61
|
-
if (closure == NULL) {
|
62
|
-
GRPC_ERROR_UNREF(error);
|
63
|
-
return false;
|
64
|
-
}
|
65
|
-
closure->error_data.error = error;
|
66
|
-
closure->next_data.next = NULL;
|
67
|
-
bool was_empty = (closure_list->head == NULL);
|
68
|
-
if (was_empty) {
|
69
|
-
closure_list->head = closure;
|
70
|
-
} else {
|
71
|
-
closure_list->tail->next_data.next = closure;
|
72
|
-
}
|
73
|
-
closure_list->tail = closure;
|
74
|
-
return was_empty;
|
75
|
-
}
|
76
|
-
|
77
|
-
void grpc_closure_list_fail_all(grpc_closure_list *list,
|
78
|
-
grpc_error *forced_failure) {
|
79
|
-
for (grpc_closure *c = list->head; c != NULL; c = c->next_data.next) {
|
80
|
-
if (c->error_data.error == GRPC_ERROR_NONE) {
|
81
|
-
c->error_data.error = GRPC_ERROR_REF(forced_failure);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
GRPC_ERROR_UNREF(forced_failure);
|
85
|
-
}
|
86
|
-
|
87
|
-
bool grpc_closure_list_empty(grpc_closure_list closure_list) {
|
88
|
-
return closure_list.head == NULL;
|
89
|
-
}
|
90
|
-
|
91
|
-
void grpc_closure_list_move(grpc_closure_list *src, grpc_closure_list *dst) {
|
92
|
-
if (src->head == NULL) {
|
93
|
-
return;
|
94
|
-
}
|
95
|
-
if (dst->head == NULL) {
|
96
|
-
*dst = *src;
|
97
|
-
} else {
|
98
|
-
dst->tail->next_data.next = src->head;
|
99
|
-
dst->tail = src->tail;
|
100
|
-
}
|
101
|
-
src->head = src->tail = NULL;
|
102
|
-
}
|
103
|
-
|
104
|
-
typedef struct {
|
105
|
-
grpc_iomgr_cb_func cb;
|
106
|
-
void *cb_arg;
|
107
|
-
grpc_closure wrapper;
|
108
|
-
} wrapped_closure;
|
109
|
-
|
110
|
-
static void closure_wrapper(grpc_exec_ctx *exec_ctx, void *arg,
|
111
|
-
grpc_error *error) {
|
112
|
-
wrapped_closure *wc = (wrapped_closure *)arg;
|
113
|
-
grpc_iomgr_cb_func cb = wc->cb;
|
114
|
-
void *cb_arg = wc->cb_arg;
|
115
|
-
gpr_free(wc);
|
116
|
-
cb(exec_ctx, cb_arg, error);
|
117
|
-
}
|
118
|
-
|
119
|
-
#ifndef NDEBUG
|
120
|
-
grpc_closure *grpc_closure_create(const char *file, int line,
|
121
|
-
grpc_iomgr_cb_func cb, void *cb_arg,
|
122
|
-
grpc_closure_scheduler *scheduler) {
|
123
|
-
#else
|
124
|
-
grpc_closure *grpc_closure_create(grpc_iomgr_cb_func cb, void *cb_arg,
|
125
|
-
grpc_closure_scheduler *scheduler) {
|
126
|
-
#endif
|
127
|
-
wrapped_closure *wc = (wrapped_closure *)gpr_malloc(sizeof(*wc));
|
128
|
-
wc->cb = cb;
|
129
|
-
wc->cb_arg = cb_arg;
|
130
|
-
#ifndef NDEBUG
|
131
|
-
grpc_closure_init(file, line, &wc->wrapper, closure_wrapper, wc, scheduler);
|
132
|
-
#else
|
133
|
-
grpc_closure_init(&wc->wrapper, closure_wrapper, wc, scheduler);
|
134
|
-
#endif
|
135
|
-
return &wc->wrapper;
|
136
|
-
}
|
137
|
-
|
138
|
-
#ifndef NDEBUG
|
139
|
-
void grpc_closure_run(const char *file, int line, grpc_exec_ctx *exec_ctx,
|
140
|
-
grpc_closure *c, grpc_error *error) {
|
141
|
-
#else
|
142
|
-
void grpc_closure_run(grpc_exec_ctx *exec_ctx, grpc_closure *c,
|
143
|
-
grpc_error *error) {
|
144
|
-
#endif
|
145
|
-
GPR_TIMER_BEGIN("grpc_closure_run", 0);
|
146
|
-
if (c != NULL) {
|
147
|
-
#ifndef NDEBUG
|
148
|
-
c->file_initiated = file;
|
149
|
-
c->line_initiated = line;
|
150
|
-
c->run = true;
|
151
|
-
#endif
|
152
|
-
assert(c->cb);
|
153
|
-
c->scheduler->vtable->run(exec_ctx, c, error);
|
154
|
-
} else {
|
155
|
-
GRPC_ERROR_UNREF(error);
|
156
|
-
}
|
157
|
-
GPR_TIMER_END("grpc_closure_run", 0);
|
158
|
-
}
|
159
|
-
|
160
|
-
#ifndef NDEBUG
|
161
|
-
void grpc_closure_sched(const char *file, int line, grpc_exec_ctx *exec_ctx,
|
162
|
-
grpc_closure *c, grpc_error *error) {
|
163
|
-
#else
|
164
|
-
void grpc_closure_sched(grpc_exec_ctx *exec_ctx, grpc_closure *c,
|
165
|
-
grpc_error *error) {
|
166
|
-
#endif
|
167
|
-
GPR_TIMER_BEGIN("grpc_closure_sched", 0);
|
168
|
-
if (c != NULL) {
|
169
|
-
#ifndef NDEBUG
|
170
|
-
if (c->scheduled) {
|
171
|
-
gpr_log(GPR_ERROR,
|
172
|
-
"Closure already scheduled. (closure: %p, created: [%s:%d], "
|
173
|
-
"previously scheduled at: [%s: %d] run?: %s",
|
174
|
-
c, c->file_created, c->line_created, c->file_initiated,
|
175
|
-
c->line_initiated, c->run ? "true" : "false");
|
176
|
-
abort();
|
177
|
-
}
|
178
|
-
c->scheduled = true;
|
179
|
-
c->file_initiated = file;
|
180
|
-
c->line_initiated = line;
|
181
|
-
c->run = false;
|
182
|
-
#endif
|
183
|
-
assert(c->cb);
|
184
|
-
c->scheduler->vtable->sched(exec_ctx, c, error);
|
185
|
-
} else {
|
186
|
-
GRPC_ERROR_UNREF(error);
|
187
|
-
}
|
188
|
-
GPR_TIMER_END("grpc_closure_sched", 0);
|
189
|
-
}
|
190
|
-
|
191
|
-
#ifndef NDEBUG
|
192
|
-
void grpc_closure_list_sched(const char *file, int line,
|
193
|
-
grpc_exec_ctx *exec_ctx, grpc_closure_list *list) {
|
194
|
-
#else
|
195
|
-
void grpc_closure_list_sched(grpc_exec_ctx *exec_ctx, grpc_closure_list *list) {
|
196
|
-
#endif
|
197
|
-
grpc_closure *c = list->head;
|
198
|
-
while (c != NULL) {
|
199
|
-
grpc_closure *next = c->next_data.next;
|
200
|
-
#ifndef NDEBUG
|
201
|
-
if (c->scheduled) {
|
202
|
-
gpr_log(GPR_ERROR,
|
203
|
-
"Closure already scheduled. (closure: %p, created: [%s:%d], "
|
204
|
-
"previously scheduled at: [%s: %d] run?: %s",
|
205
|
-
c, c->file_created, c->line_created, c->file_initiated,
|
206
|
-
c->line_initiated, c->run ? "true" : "false");
|
207
|
-
abort();
|
208
|
-
}
|
209
|
-
c->scheduled = true;
|
210
|
-
c->file_initiated = file;
|
211
|
-
c->line_initiated = line;
|
212
|
-
c->run = false;
|
213
|
-
#endif
|
214
|
-
assert(c->cb);
|
215
|
-
c->scheduler->vtable->sched(exec_ctx, c, c->error_data.error);
|
216
|
-
c = next;
|
217
|
-
}
|
218
|
-
list->head = list->tail = NULL;
|
219
|
-
}
|
@@ -1,1461 +0,0 @@
|
|
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
|
-
/* This polling engine is only relevant on linux kernels supporting epoll() */
|
22
|
-
#ifdef GRPC_LINUX_EPOLL
|
23
|
-
|
24
|
-
#include "src/core/lib/iomgr/ev_epollex_linux.h"
|
25
|
-
|
26
|
-
#include <assert.h>
|
27
|
-
#include <errno.h>
|
28
|
-
#include <poll.h>
|
29
|
-
#include <pthread.h>
|
30
|
-
#include <string.h>
|
31
|
-
#include <sys/socket.h>
|
32
|
-
#include <unistd.h>
|
33
|
-
|
34
|
-
#include <grpc/support/alloc.h>
|
35
|
-
#include <grpc/support/log.h>
|
36
|
-
#include <grpc/support/string_util.h>
|
37
|
-
#include <grpc/support/tls.h>
|
38
|
-
#include <grpc/support/useful.h>
|
39
|
-
|
40
|
-
#include "src/core/lib/debug/stats.h"
|
41
|
-
#include "src/core/lib/iomgr/ev_posix.h"
|
42
|
-
#include "src/core/lib/iomgr/iomgr_internal.h"
|
43
|
-
#include "src/core/lib/iomgr/is_epollexclusive_available.h"
|
44
|
-
#include "src/core/lib/iomgr/lockfree_event.h"
|
45
|
-
#include "src/core/lib/iomgr/sys_epoll_wrapper.h"
|
46
|
-
#include "src/core/lib/iomgr/timer.h"
|
47
|
-
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
|
48
|
-
#include "src/core/lib/profiling/timers.h"
|
49
|
-
#include "src/core/lib/support/block_annotate.h"
|
50
|
-
#include "src/core/lib/support/spinlock.h"
|
51
|
-
|
52
|
-
/*******************************************************************************
|
53
|
-
* Polling object
|
54
|
-
*/
|
55
|
-
|
56
|
-
typedef enum {
|
57
|
-
PO_POLLING_GROUP,
|
58
|
-
PO_POLLSET_SET,
|
59
|
-
PO_POLLSET,
|
60
|
-
PO_FD, /* ordering is important: we always want to lock pollsets before fds:
|
61
|
-
this guarantees that using an fd as a pollable is safe */
|
62
|
-
PO_EMPTY_POLLABLE,
|
63
|
-
PO_COUNT
|
64
|
-
} polling_obj_type;
|
65
|
-
|
66
|
-
typedef struct polling_obj polling_obj;
|
67
|
-
typedef struct polling_group polling_group;
|
68
|
-
|
69
|
-
struct polling_obj {
|
70
|
-
gpr_mu mu;
|
71
|
-
polling_obj_type type;
|
72
|
-
polling_group *group;
|
73
|
-
struct polling_obj *next;
|
74
|
-
struct polling_obj *prev;
|
75
|
-
};
|
76
|
-
|
77
|
-
struct polling_group {
|
78
|
-
polling_obj po;
|
79
|
-
gpr_refcount refs;
|
80
|
-
};
|
81
|
-
|
82
|
-
static void po_init(polling_obj *po, polling_obj_type type);
|
83
|
-
static void po_destroy(polling_obj *po);
|
84
|
-
static void po_join(grpc_exec_ctx *exec_ctx, polling_obj *a, polling_obj *b);
|
85
|
-
static int po_cmp(polling_obj *a, polling_obj *b);
|
86
|
-
|
87
|
-
static void pg_create(grpc_exec_ctx *exec_ctx, polling_obj **initial_po,
|
88
|
-
size_t initial_po_count);
|
89
|
-
static polling_group *pg_ref(polling_group *pg);
|
90
|
-
static void pg_unref(polling_group *pg);
|
91
|
-
static void pg_merge(grpc_exec_ctx *exec_ctx, polling_group *a,
|
92
|
-
polling_group *b);
|
93
|
-
static void pg_join(grpc_exec_ctx *exec_ctx, polling_group *pg,
|
94
|
-
polling_obj *po);
|
95
|
-
|
96
|
-
/*******************************************************************************
|
97
|
-
* pollable Declarations
|
98
|
-
*/
|
99
|
-
|
100
|
-
typedef struct pollable {
|
101
|
-
polling_obj po;
|
102
|
-
int epfd;
|
103
|
-
grpc_wakeup_fd wakeup;
|
104
|
-
grpc_pollset_worker *root_worker;
|
105
|
-
} pollable;
|
106
|
-
|
107
|
-
static const char *polling_obj_type_string(polling_obj_type t) {
|
108
|
-
switch (t) {
|
109
|
-
case PO_POLLING_GROUP:
|
110
|
-
return "polling_group";
|
111
|
-
case PO_POLLSET_SET:
|
112
|
-
return "pollset_set";
|
113
|
-
case PO_POLLSET:
|
114
|
-
return "pollset";
|
115
|
-
case PO_FD:
|
116
|
-
return "fd";
|
117
|
-
case PO_EMPTY_POLLABLE:
|
118
|
-
return "empty_pollable";
|
119
|
-
case PO_COUNT:
|
120
|
-
return "<invalid:count>";
|
121
|
-
}
|
122
|
-
return "<invalid>";
|
123
|
-
}
|
124
|
-
|
125
|
-
static char *pollable_desc(pollable *p) {
|
126
|
-
char *out;
|
127
|
-
gpr_asprintf(&out, "type=%s group=%p epfd=%d wakeup=%d",
|
128
|
-
polling_obj_type_string(p->po.type), p->po.group, p->epfd,
|
129
|
-
p->wakeup.read_fd);
|
130
|
-
return out;
|
131
|
-
}
|
132
|
-
|
133
|
-
static pollable g_empty_pollable;
|
134
|
-
|
135
|
-
static void pollable_init(pollable *p, polling_obj_type type);
|
136
|
-
static void pollable_destroy(pollable *p);
|
137
|
-
/* ensure that p->epfd, p->wakeup are initialized; p->po.mu must be held */
|
138
|
-
static grpc_error *pollable_materialize(pollable *p);
|
139
|
-
|
140
|
-
/*******************************************************************************
|
141
|
-
* Fd Declarations
|
142
|
-
*/
|
143
|
-
|
144
|
-
struct grpc_fd {
|
145
|
-
pollable pollable_obj;
|
146
|
-
int fd;
|
147
|
-
/* refst format:
|
148
|
-
bit 0 : 1=Active / 0=Orphaned
|
149
|
-
bits 1-n : refcount
|
150
|
-
Ref/Unref by two to avoid altering the orphaned bit */
|
151
|
-
gpr_atm refst;
|
152
|
-
|
153
|
-
/* The fd is either closed or we relinquished control of it. In either
|
154
|
-
cases, this indicates that the 'fd' on this structure is no longer
|
155
|
-
valid */
|
156
|
-
gpr_mu orphaned_mu;
|
157
|
-
bool orphaned;
|
158
|
-
|
159
|
-
gpr_atm read_closure;
|
160
|
-
gpr_atm write_closure;
|
161
|
-
|
162
|
-
struct grpc_fd *freelist_next;
|
163
|
-
grpc_closure *on_done_closure;
|
164
|
-
|
165
|
-
/* The pollset that last noticed that the fd is readable. The actual type
|
166
|
-
* stored in this is (grpc_pollset *) */
|
167
|
-
gpr_atm read_notifier_pollset;
|
168
|
-
|
169
|
-
grpc_iomgr_object iomgr_object;
|
170
|
-
};
|
171
|
-
|
172
|
-
static void fd_global_init(void);
|
173
|
-
static void fd_global_shutdown(void);
|
174
|
-
|
175
|
-
/*******************************************************************************
|
176
|
-
* Pollset Declarations
|
177
|
-
*/
|
178
|
-
|
179
|
-
typedef struct pollset_worker_link {
|
180
|
-
grpc_pollset_worker *next;
|
181
|
-
grpc_pollset_worker *prev;
|
182
|
-
} pollset_worker_link;
|
183
|
-
|
184
|
-
typedef enum {
|
185
|
-
PWL_POLLSET,
|
186
|
-
PWL_POLLABLE,
|
187
|
-
POLLSET_WORKER_LINK_COUNT
|
188
|
-
} pollset_worker_links;
|
189
|
-
|
190
|
-
struct grpc_pollset_worker {
|
191
|
-
bool kicked;
|
192
|
-
bool initialized_cv;
|
193
|
-
pollset_worker_link links[POLLSET_WORKER_LINK_COUNT];
|
194
|
-
gpr_cv cv;
|
195
|
-
grpc_pollset *pollset;
|
196
|
-
pollable *pollable_obj;
|
197
|
-
};
|
198
|
-
|
199
|
-
#define MAX_EPOLL_EVENTS 100
|
200
|
-
#define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5
|
201
|
-
|
202
|
-
struct grpc_pollset {
|
203
|
-
pollable pollable_obj;
|
204
|
-
pollable *current_pollable_obj;
|
205
|
-
int kick_alls_pending;
|
206
|
-
bool kicked_without_poller;
|
207
|
-
grpc_closure *shutdown_closure;
|
208
|
-
grpc_pollset_worker *root_worker;
|
209
|
-
|
210
|
-
int event_cursor;
|
211
|
-
int event_count;
|
212
|
-
struct epoll_event events[MAX_EPOLL_EVENTS];
|
213
|
-
};
|
214
|
-
|
215
|
-
/*******************************************************************************
|
216
|
-
* Pollset-set Declarations
|
217
|
-
*/
|
218
|
-
struct grpc_pollset_set {
|
219
|
-
polling_obj po;
|
220
|
-
};
|
221
|
-
|
222
|
-
/*******************************************************************************
|
223
|
-
* Common helpers
|
224
|
-
*/
|
225
|
-
|
226
|
-
static bool append_error(grpc_error **composite, grpc_error *error,
|
227
|
-
const char *desc) {
|
228
|
-
if (error == GRPC_ERROR_NONE) return true;
|
229
|
-
if (*composite == GRPC_ERROR_NONE) {
|
230
|
-
*composite = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc);
|
231
|
-
}
|
232
|
-
*composite = grpc_error_add_child(*composite, error);
|
233
|
-
return false;
|
234
|
-
}
|
235
|
-
|
236
|
-
/*******************************************************************************
|
237
|
-
* Fd Definitions
|
238
|
-
*/
|
239
|
-
|
240
|
-
/* We need to keep a freelist not because of any concerns of malloc performance
|
241
|
-
* but instead so that implementations with multiple threads in (for example)
|
242
|
-
* epoll_wait deal with the race between pollset removal and incoming poll
|
243
|
-
* notifications.
|
244
|
-
*
|
245
|
-
* The problem is that the poller ultimately holds a reference to this
|
246
|
-
* object, so it is very difficult to know when is safe to free it, at least
|
247
|
-
* without some expensive synchronization.
|
248
|
-
*
|
249
|
-
* If we keep the object freelisted, in the worst case losing this race just
|
250
|
-
* becomes a spurious read notification on a reused fd.
|
251
|
-
*/
|
252
|
-
|
253
|
-
/* The alarm system needs to be able to wakeup 'some poller' sometimes
|
254
|
-
* (specifically when a new alarm needs to be triggered earlier than the next
|
255
|
-
* alarm 'epoch'). This wakeup_fd gives us something to alert on when such a
|
256
|
-
* case occurs. */
|
257
|
-
|
258
|
-
static grpc_fd *fd_freelist = NULL;
|
259
|
-
static gpr_mu fd_freelist_mu;
|
260
|
-
|
261
|
-
#ifndef NDEBUG
|
262
|
-
#define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__)
|
263
|
-
#define UNREF_BY(ec, fd, n, reason) \
|
264
|
-
unref_by(ec, fd, n, reason, __FILE__, __LINE__)
|
265
|
-
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
|
266
|
-
int line) {
|
267
|
-
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
|
268
|
-
gpr_log(GPR_DEBUG,
|
269
|
-
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
270
|
-
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
271
|
-
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
|
272
|
-
}
|
273
|
-
#else
|
274
|
-
#define REF_BY(fd, n, reason) ref_by(fd, n)
|
275
|
-
#define UNREF_BY(ec, fd, n, reason) unref_by(ec, fd, n)
|
276
|
-
static void ref_by(grpc_fd *fd, int n) {
|
277
|
-
#endif
|
278
|
-
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
|
279
|
-
}
|
280
|
-
|
281
|
-
static void fd_destroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
|
282
|
-
grpc_fd *fd = (grpc_fd *)arg;
|
283
|
-
/* Add the fd to the freelist */
|
284
|
-
grpc_iomgr_unregister_object(&fd->iomgr_object);
|
285
|
-
pollable_destroy(&fd->pollable_obj);
|
286
|
-
gpr_mu_destroy(&fd->orphaned_mu);
|
287
|
-
gpr_mu_lock(&fd_freelist_mu);
|
288
|
-
fd->freelist_next = fd_freelist;
|
289
|
-
fd_freelist = fd;
|
290
|
-
|
291
|
-
grpc_lfev_destroy(&fd->read_closure);
|
292
|
-
grpc_lfev_destroy(&fd->write_closure);
|
293
|
-
|
294
|
-
gpr_mu_unlock(&fd_freelist_mu);
|
295
|
-
}
|
296
|
-
|
297
|
-
#ifndef NDEBUG
|
298
|
-
static void unref_by(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int n,
|
299
|
-
const char *reason, const char *file, int line) {
|
300
|
-
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
|
301
|
-
gpr_log(GPR_DEBUG,
|
302
|
-
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
303
|
-
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
304
|
-
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
|
305
|
-
}
|
306
|
-
#else
|
307
|
-
static void unref_by(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int n) {
|
308
|
-
#endif
|
309
|
-
gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n);
|
310
|
-
if (old == n) {
|
311
|
-
GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(fd_destroy, fd,
|
312
|
-
grpc_schedule_on_exec_ctx),
|
313
|
-
GRPC_ERROR_NONE);
|
314
|
-
} else {
|
315
|
-
GPR_ASSERT(old > n);
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
|
-
static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
|
320
|
-
|
321
|
-
static void fd_global_shutdown(void) {
|
322
|
-
gpr_mu_lock(&fd_freelist_mu);
|
323
|
-
gpr_mu_unlock(&fd_freelist_mu);
|
324
|
-
while (fd_freelist != NULL) {
|
325
|
-
grpc_fd *fd = fd_freelist;
|
326
|
-
fd_freelist = fd_freelist->freelist_next;
|
327
|
-
gpr_free(fd);
|
328
|
-
}
|
329
|
-
gpr_mu_destroy(&fd_freelist_mu);
|
330
|
-
}
|
331
|
-
|
332
|
-
static grpc_fd *fd_create(int fd, const char *name) {
|
333
|
-
grpc_fd *new_fd = NULL;
|
334
|
-
|
335
|
-
gpr_mu_lock(&fd_freelist_mu);
|
336
|
-
if (fd_freelist != NULL) {
|
337
|
-
new_fd = fd_freelist;
|
338
|
-
fd_freelist = fd_freelist->freelist_next;
|
339
|
-
}
|
340
|
-
gpr_mu_unlock(&fd_freelist_mu);
|
341
|
-
|
342
|
-
if (new_fd == NULL) {
|
343
|
-
new_fd = (grpc_fd *)gpr_malloc(sizeof(grpc_fd));
|
344
|
-
}
|
345
|
-
|
346
|
-
pollable_init(&new_fd->pollable_obj, PO_FD);
|
347
|
-
|
348
|
-
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
|
349
|
-
new_fd->fd = fd;
|
350
|
-
gpr_mu_init(&new_fd->orphaned_mu);
|
351
|
-
new_fd->orphaned = false;
|
352
|
-
grpc_lfev_init(&new_fd->read_closure);
|
353
|
-
grpc_lfev_init(&new_fd->write_closure);
|
354
|
-
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
|
355
|
-
|
356
|
-
new_fd->freelist_next = NULL;
|
357
|
-
new_fd->on_done_closure = NULL;
|
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_TRACER_ON(grpc_trace_fd_refcount)) {
|
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 = -1;
|
373
|
-
gpr_mu_lock(&fd->orphaned_mu);
|
374
|
-
if (!fd->orphaned) {
|
375
|
-
ret_fd = fd->fd;
|
376
|
-
}
|
377
|
-
gpr_mu_unlock(&fd->orphaned_mu);
|
378
|
-
|
379
|
-
return ret_fd;
|
380
|
-
}
|
381
|
-
|
382
|
-
static void fd_orphan(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
383
|
-
grpc_closure *on_done, int *release_fd,
|
384
|
-
bool already_closed, const char *reason) {
|
385
|
-
bool is_fd_closed = already_closed;
|
386
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
387
|
-
|
388
|
-
gpr_mu_lock(&fd->pollable_obj.po.mu);
|
389
|
-
gpr_mu_lock(&fd->orphaned_mu);
|
390
|
-
fd->on_done_closure = on_done;
|
391
|
-
|
392
|
-
/* If release_fd is not NULL, we should be relinquishing control of the file
|
393
|
-
descriptor fd->fd (but we still own the grpc_fd structure). */
|
394
|
-
if (release_fd != NULL) {
|
395
|
-
*release_fd = fd->fd;
|
396
|
-
} else if (!is_fd_closed) {
|
397
|
-
close(fd->fd);
|
398
|
-
is_fd_closed = true;
|
399
|
-
}
|
400
|
-
|
401
|
-
fd->orphaned = true;
|
402
|
-
|
403
|
-
if (!is_fd_closed) {
|
404
|
-
gpr_log(GPR_DEBUG, "TODO: handle fd removal?");
|
405
|
-
}
|
406
|
-
|
407
|
-
/* Remove the active status but keep referenced. We want this grpc_fd struct
|
408
|
-
to be alive (and not added to freelist) until the end of this function */
|
409
|
-
REF_BY(fd, 1, reason);
|
410
|
-
|
411
|
-
GRPC_CLOSURE_SCHED(exec_ctx, fd->on_done_closure, GRPC_ERROR_REF(error));
|
412
|
-
|
413
|
-
gpr_mu_unlock(&fd->orphaned_mu);
|
414
|
-
gpr_mu_unlock(&fd->pollable_obj.po.mu);
|
415
|
-
UNREF_BY(exec_ctx, fd, 2, reason); /* Drop the reference */
|
416
|
-
GRPC_LOG_IF_ERROR("fd_orphan", GRPC_ERROR_REF(error));
|
417
|
-
GRPC_ERROR_UNREF(error);
|
418
|
-
}
|
419
|
-
|
420
|
-
static grpc_pollset *fd_get_read_notifier_pollset(grpc_exec_ctx *exec_ctx,
|
421
|
-
grpc_fd *fd) {
|
422
|
-
gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset);
|
423
|
-
return (grpc_pollset *)notifier;
|
424
|
-
}
|
425
|
-
|
426
|
-
static bool fd_is_shutdown(grpc_fd *fd) {
|
427
|
-
return grpc_lfev_is_shutdown(&fd->read_closure);
|
428
|
-
}
|
429
|
-
|
430
|
-
/* Might be called multiple times */
|
431
|
-
static void fd_shutdown(grpc_exec_ctx *exec_ctx, grpc_fd *fd, grpc_error *why) {
|
432
|
-
if (grpc_lfev_set_shutdown(exec_ctx, &fd->read_closure,
|
433
|
-
GRPC_ERROR_REF(why))) {
|
434
|
-
shutdown(fd->fd, SHUT_RDWR);
|
435
|
-
grpc_lfev_set_shutdown(exec_ctx, &fd->write_closure, GRPC_ERROR_REF(why));
|
436
|
-
}
|
437
|
-
GRPC_ERROR_UNREF(why);
|
438
|
-
}
|
439
|
-
|
440
|
-
static void fd_notify_on_read(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
441
|
-
grpc_closure *closure) {
|
442
|
-
grpc_lfev_notify_on(exec_ctx, &fd->read_closure, closure, "read");
|
443
|
-
}
|
444
|
-
|
445
|
-
static void fd_notify_on_write(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
446
|
-
grpc_closure *closure) {
|
447
|
-
grpc_lfev_notify_on(exec_ctx, &fd->write_closure, closure, "write");
|
448
|
-
}
|
449
|
-
|
450
|
-
/*******************************************************************************
|
451
|
-
* Pollable Definitions
|
452
|
-
*/
|
453
|
-
|
454
|
-
static void pollable_init(pollable *p, polling_obj_type type) {
|
455
|
-
po_init(&p->po, type);
|
456
|
-
p->root_worker = NULL;
|
457
|
-
p->epfd = -1;
|
458
|
-
}
|
459
|
-
|
460
|
-
static void pollable_destroy(pollable *p) {
|
461
|
-
po_destroy(&p->po);
|
462
|
-
if (p->epfd != -1) {
|
463
|
-
close(p->epfd);
|
464
|
-
grpc_wakeup_fd_destroy(&p->wakeup);
|
465
|
-
}
|
466
|
-
}
|
467
|
-
|
468
|
-
/* ensure that p->epfd, p->wakeup are initialized; p->po.mu must be held */
|
469
|
-
static grpc_error *pollable_materialize(pollable *p) {
|
470
|
-
if (p->epfd == -1) {
|
471
|
-
int new_epfd = epoll_create1(EPOLL_CLOEXEC);
|
472
|
-
if (new_epfd < 0) {
|
473
|
-
return GRPC_OS_ERROR(errno, "epoll_create1");
|
474
|
-
}
|
475
|
-
grpc_error *err = grpc_wakeup_fd_init(&p->wakeup);
|
476
|
-
if (err != GRPC_ERROR_NONE) {
|
477
|
-
close(new_epfd);
|
478
|
-
return err;
|
479
|
-
}
|
480
|
-
struct epoll_event ev;
|
481
|
-
ev.events = (uint32_t)(EPOLLIN | EPOLLET);
|
482
|
-
ev.data.ptr = (void *)(1 | (intptr_t)&p->wakeup);
|
483
|
-
if (epoll_ctl(new_epfd, EPOLL_CTL_ADD, p->wakeup.read_fd, &ev) != 0) {
|
484
|
-
err = GRPC_OS_ERROR(errno, "epoll_ctl");
|
485
|
-
close(new_epfd);
|
486
|
-
grpc_wakeup_fd_destroy(&p->wakeup);
|
487
|
-
return err;
|
488
|
-
}
|
489
|
-
|
490
|
-
p->epfd = new_epfd;
|
491
|
-
}
|
492
|
-
return GRPC_ERROR_NONE;
|
493
|
-
}
|
494
|
-
|
495
|
-
/* pollable must be materialized */
|
496
|
-
static grpc_error *pollable_add_fd(pollable *p, grpc_fd *fd) {
|
497
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
498
|
-
static const char *err_desc = "pollable_add_fd";
|
499
|
-
const int epfd = p->epfd;
|
500
|
-
GPR_ASSERT(epfd != -1);
|
501
|
-
|
502
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
503
|
-
gpr_log(GPR_DEBUG, "add fd %p (%d) to pollable %p", fd, fd->fd, p);
|
504
|
-
}
|
505
|
-
|
506
|
-
gpr_mu_lock(&fd->orphaned_mu);
|
507
|
-
if (fd->orphaned) {
|
508
|
-
gpr_mu_unlock(&fd->orphaned_mu);
|
509
|
-
return GRPC_ERROR_NONE;
|
510
|
-
}
|
511
|
-
struct epoll_event ev_fd;
|
512
|
-
ev_fd.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLOUT | EPOLLEXCLUSIVE);
|
513
|
-
ev_fd.data.ptr = fd;
|
514
|
-
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd->fd, &ev_fd) != 0) {
|
515
|
-
switch (errno) {
|
516
|
-
case EEXIST:
|
517
|
-
break;
|
518
|
-
default:
|
519
|
-
append_error(&error, GRPC_OS_ERROR(errno, "epoll_ctl"), err_desc);
|
520
|
-
}
|
521
|
-
}
|
522
|
-
gpr_mu_unlock(&fd->orphaned_mu);
|
523
|
-
|
524
|
-
return error;
|
525
|
-
}
|
526
|
-
|
527
|
-
/*******************************************************************************
|
528
|
-
* Pollset Definitions
|
529
|
-
*/
|
530
|
-
|
531
|
-
GPR_TLS_DECL(g_current_thread_pollset);
|
532
|
-
GPR_TLS_DECL(g_current_thread_worker);
|
533
|
-
|
534
|
-
/* Global state management */
|
535
|
-
static grpc_error *pollset_global_init(void) {
|
536
|
-
gpr_tls_init(&g_current_thread_pollset);
|
537
|
-
gpr_tls_init(&g_current_thread_worker);
|
538
|
-
pollable_init(&g_empty_pollable, PO_EMPTY_POLLABLE);
|
539
|
-
return GRPC_ERROR_NONE;
|
540
|
-
}
|
541
|
-
|
542
|
-
static void pollset_global_shutdown(void) {
|
543
|
-
pollable_destroy(&g_empty_pollable);
|
544
|
-
gpr_tls_destroy(&g_current_thread_pollset);
|
545
|
-
gpr_tls_destroy(&g_current_thread_worker);
|
546
|
-
}
|
547
|
-
|
548
|
-
static void pollset_maybe_finish_shutdown(grpc_exec_ctx *exec_ctx,
|
549
|
-
grpc_pollset *pollset) {
|
550
|
-
if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL &&
|
551
|
-
pollset->kick_alls_pending == 0) {
|
552
|
-
GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE);
|
553
|
-
pollset->shutdown_closure = NULL;
|
554
|
-
}
|
555
|
-
}
|
556
|
-
|
557
|
-
static void do_kick_all(grpc_exec_ctx *exec_ctx, void *arg,
|
558
|
-
grpc_error *error_unused) {
|
559
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
560
|
-
grpc_pollset *pollset = (grpc_pollset *)arg;
|
561
|
-
gpr_mu_lock(&pollset->pollable_obj.po.mu);
|
562
|
-
if (pollset->root_worker != NULL) {
|
563
|
-
grpc_pollset_worker *worker = pollset->root_worker;
|
564
|
-
do {
|
565
|
-
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
|
566
|
-
if (worker->pollable_obj != &pollset->pollable_obj) {
|
567
|
-
gpr_mu_lock(&worker->pollable_obj->po.mu);
|
568
|
-
}
|
569
|
-
if (worker->initialized_cv && worker != pollset->root_worker) {
|
570
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
571
|
-
gpr_log(GPR_DEBUG, "PS:%p kickall_via_cv %p (pollable %p vs %p)",
|
572
|
-
pollset, worker, &pollset->pollable_obj,
|
573
|
-
worker->pollable_obj);
|
574
|
-
}
|
575
|
-
worker->kicked = true;
|
576
|
-
gpr_cv_signal(&worker->cv);
|
577
|
-
} else {
|
578
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
579
|
-
gpr_log(GPR_DEBUG, "PS:%p kickall_via_wakeup %p (pollable %p vs %p)",
|
580
|
-
pollset, worker, &pollset->pollable_obj,
|
581
|
-
worker->pollable_obj);
|
582
|
-
}
|
583
|
-
append_error(&error,
|
584
|
-
grpc_wakeup_fd_wakeup(&worker->pollable_obj->wakeup),
|
585
|
-
"pollset_shutdown");
|
586
|
-
}
|
587
|
-
if (worker->pollable_obj != &pollset->pollable_obj) {
|
588
|
-
gpr_mu_unlock(&worker->pollable_obj->po.mu);
|
589
|
-
}
|
590
|
-
|
591
|
-
worker = worker->links[PWL_POLLSET].next;
|
592
|
-
} while (worker != pollset->root_worker);
|
593
|
-
}
|
594
|
-
pollset->kick_alls_pending--;
|
595
|
-
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
596
|
-
gpr_mu_unlock(&pollset->pollable_obj.po.mu);
|
597
|
-
GRPC_LOG_IF_ERROR("kick_all", error);
|
598
|
-
}
|
599
|
-
|
600
|
-
static void pollset_kick_all(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset) {
|
601
|
-
pollset->kick_alls_pending++;
|
602
|
-
GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(do_kick_all, pollset,
|
603
|
-
grpc_schedule_on_exec_ctx),
|
604
|
-
GRPC_ERROR_NONE);
|
605
|
-
}
|
606
|
-
|
607
|
-
static grpc_error *pollset_kick_inner(grpc_pollset *pollset, pollable *p,
|
608
|
-
grpc_pollset_worker *specific_worker) {
|
609
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
610
|
-
gpr_log(GPR_DEBUG,
|
611
|
-
"PS:%p kick %p tls_pollset=%p tls_worker=%p "
|
612
|
-
"root_worker=(pollset:%p pollable:%p)",
|
613
|
-
p, specific_worker, (void *)gpr_tls_get(&g_current_thread_pollset),
|
614
|
-
(void *)gpr_tls_get(&g_current_thread_worker), pollset->root_worker,
|
615
|
-
p->root_worker);
|
616
|
-
}
|
617
|
-
if (specific_worker == NULL) {
|
618
|
-
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
|
619
|
-
if (pollset->root_worker == NULL) {
|
620
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
621
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", p);
|
622
|
-
}
|
623
|
-
pollset->kicked_without_poller = true;
|
624
|
-
return GRPC_ERROR_NONE;
|
625
|
-
} else {
|
626
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
627
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_any_via_wakeup_fd", p);
|
628
|
-
}
|
629
|
-
grpc_error *err = pollable_materialize(p);
|
630
|
-
if (err != GRPC_ERROR_NONE) return err;
|
631
|
-
return grpc_wakeup_fd_wakeup(&p->wakeup);
|
632
|
-
}
|
633
|
-
} else {
|
634
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
635
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", p);
|
636
|
-
}
|
637
|
-
return GRPC_ERROR_NONE;
|
638
|
-
}
|
639
|
-
} else if (specific_worker->kicked) {
|
640
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
641
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p);
|
642
|
-
}
|
643
|
-
return GRPC_ERROR_NONE;
|
644
|
-
} else if (gpr_tls_get(&g_current_thread_worker) ==
|
645
|
-
(intptr_t)specific_worker) {
|
646
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
647
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p);
|
648
|
-
}
|
649
|
-
specific_worker->kicked = true;
|
650
|
-
return GRPC_ERROR_NONE;
|
651
|
-
} else if (specific_worker == p->root_worker) {
|
652
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
653
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p);
|
654
|
-
}
|
655
|
-
grpc_error *err = pollable_materialize(p);
|
656
|
-
if (err != GRPC_ERROR_NONE) return err;
|
657
|
-
specific_worker->kicked = true;
|
658
|
-
return grpc_wakeup_fd_wakeup(&p->wakeup);
|
659
|
-
} else {
|
660
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
661
|
-
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p);
|
662
|
-
}
|
663
|
-
specific_worker->kicked = true;
|
664
|
-
gpr_cv_signal(&specific_worker->cv);
|
665
|
-
return GRPC_ERROR_NONE;
|
666
|
-
}
|
667
|
-
}
|
668
|
-
|
669
|
-
/* p->po.mu must be held before calling this function */
|
670
|
-
static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
671
|
-
grpc_pollset_worker *specific_worker) {
|
672
|
-
pollable *p = pollset->current_pollable_obj;
|
673
|
-
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
|
674
|
-
if (p != &pollset->pollable_obj) {
|
675
|
-
gpr_mu_lock(&p->po.mu);
|
676
|
-
}
|
677
|
-
grpc_error *error = pollset_kick_inner(pollset, p, specific_worker);
|
678
|
-
if (p != &pollset->pollable_obj) {
|
679
|
-
gpr_mu_unlock(&p->po.mu);
|
680
|
-
}
|
681
|
-
return error;
|
682
|
-
}
|
683
|
-
|
684
|
-
static void pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
|
685
|
-
pollable_init(&pollset->pollable_obj, PO_POLLSET);
|
686
|
-
pollset->current_pollable_obj = &g_empty_pollable;
|
687
|
-
pollset->kicked_without_poller = false;
|
688
|
-
pollset->shutdown_closure = NULL;
|
689
|
-
pollset->root_worker = NULL;
|
690
|
-
*mu = &pollset->pollable_obj.po.mu;
|
691
|
-
}
|
692
|
-
|
693
|
-
/* Convert a timespec to milliseconds:
|
694
|
-
- Very small or negative poll times are clamped to zero to do a non-blocking
|
695
|
-
poll (which becomes spin polling)
|
696
|
-
- Other small values are rounded up to one millisecond
|
697
|
-
- Longer than a millisecond polls are rounded up to the next nearest
|
698
|
-
millisecond to avoid spinning
|
699
|
-
- Infinite timeouts are converted to -1 */
|
700
|
-
static int poll_deadline_to_millis_timeout(gpr_timespec deadline,
|
701
|
-
gpr_timespec now) {
|
702
|
-
gpr_timespec timeout;
|
703
|
-
if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) {
|
704
|
-
return -1;
|
705
|
-
}
|
706
|
-
|
707
|
-
if (gpr_time_cmp(deadline, now) <= 0) {
|
708
|
-
return 0;
|
709
|
-
}
|
710
|
-
|
711
|
-
static const gpr_timespec round_up = {
|
712
|
-
0, /* tv_sec */
|
713
|
-
GPR_NS_PER_MS - 1, /* tv_nsec */
|
714
|
-
GPR_TIMESPAN /* clock_type */
|
715
|
-
};
|
716
|
-
timeout = gpr_time_sub(deadline, now);
|
717
|
-
int millis = gpr_time_to_millis(gpr_time_add(timeout, round_up));
|
718
|
-
return millis >= 1 ? millis : 1;
|
719
|
-
}
|
720
|
-
|
721
|
-
static void fd_become_readable(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
722
|
-
grpc_pollset *notifier) {
|
723
|
-
grpc_lfev_set_ready(exec_ctx, &fd->read_closure, "read");
|
724
|
-
|
725
|
-
/* Note, it is possible that fd_become_readable might be called twice with
|
726
|
-
different 'notifier's when an fd becomes readable and it is in two epoll
|
727
|
-
sets (This can happen briefly during polling island merges). In such cases
|
728
|
-
it does not really matter which notifer is set as the read_notifier_pollset
|
729
|
-
(They would both point to the same polling island anyway) */
|
730
|
-
/* Use release store to match with acquire load in fd_get_read_notifier */
|
731
|
-
gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
|
732
|
-
}
|
733
|
-
|
734
|
-
static void fd_become_writable(grpc_exec_ctx *exec_ctx, grpc_fd *fd) {
|
735
|
-
grpc_lfev_set_ready(exec_ctx, &fd->write_closure, "write");
|
736
|
-
}
|
737
|
-
|
738
|
-
static grpc_error *fd_become_pollable_locked(grpc_fd *fd) {
|
739
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
740
|
-
static const char *err_desc = "fd_become_pollable";
|
741
|
-
if (append_error(&error, pollable_materialize(&fd->pollable_obj), err_desc)) {
|
742
|
-
append_error(&error, pollable_add_fd(&fd->pollable_obj, fd), err_desc);
|
743
|
-
}
|
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 == NULL);
|
751
|
-
pollset->shutdown_closure = closure;
|
752
|
-
pollset_kick_all(exec_ctx, pollset);
|
753
|
-
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
754
|
-
}
|
755
|
-
|
756
|
-
static bool pollset_is_pollable_fd(grpc_pollset *pollset, pollable *p) {
|
757
|
-
return p != &g_empty_pollable && p != &pollset->pollable_obj;
|
758
|
-
}
|
759
|
-
|
760
|
-
static grpc_error *pollset_process_events(grpc_exec_ctx *exec_ctx,
|
761
|
-
grpc_pollset *pollset, bool drain) {
|
762
|
-
static const char *err_desc = "pollset_process_events";
|
763
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
764
|
-
for (int i = 0; (drain || i < MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL) &&
|
765
|
-
pollset->event_cursor != pollset->event_count;
|
766
|
-
i++) {
|
767
|
-
int n = pollset->event_cursor++;
|
768
|
-
struct epoll_event *ev = &pollset->events[n];
|
769
|
-
void *data_ptr = ev->data.ptr;
|
770
|
-
if (1 & (intptr_t)data_ptr) {
|
771
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
772
|
-
gpr_log(GPR_DEBUG, "PS:%p got pollset_wakeup %p", pollset, data_ptr);
|
773
|
-
}
|
774
|
-
append_error(&error,
|
775
|
-
grpc_wakeup_fd_consume_wakeup(
|
776
|
-
(grpc_wakeup_fd *)((~(intptr_t)1) & (intptr_t)data_ptr)),
|
777
|
-
err_desc);
|
778
|
-
} else {
|
779
|
-
grpc_fd *fd = (grpc_fd *)data_ptr;
|
780
|
-
bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0;
|
781
|
-
bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0;
|
782
|
-
bool write_ev = (ev->events & EPOLLOUT) != 0;
|
783
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
784
|
-
gpr_log(GPR_DEBUG,
|
785
|
-
"PS:%p got fd %p: cancel=%d read=%d "
|
786
|
-
"write=%d",
|
787
|
-
pollset, fd, cancel, read_ev, write_ev);
|
788
|
-
}
|
789
|
-
if (read_ev || cancel) {
|
790
|
-
fd_become_readable(exec_ctx, fd, pollset);
|
791
|
-
}
|
792
|
-
if (write_ev || cancel) {
|
793
|
-
fd_become_writable(exec_ctx, fd);
|
794
|
-
}
|
795
|
-
}
|
796
|
-
}
|
797
|
-
|
798
|
-
return error;
|
799
|
-
}
|
800
|
-
|
801
|
-
/* pollset_shutdown is guaranteed to be called before pollset_destroy. */
|
802
|
-
static void pollset_destroy(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset) {
|
803
|
-
pollable_destroy(&pollset->pollable_obj);
|
804
|
-
if (pollset_is_pollable_fd(pollset, pollset->current_pollable_obj)) {
|
805
|
-
UNREF_BY(exec_ctx, (grpc_fd *)pollset->current_pollable_obj, 2,
|
806
|
-
"pollset_pollable");
|
807
|
-
}
|
808
|
-
GRPC_LOG_IF_ERROR("pollset_process_events",
|
809
|
-
pollset_process_events(exec_ctx, pollset, true));
|
810
|
-
}
|
811
|
-
|
812
|
-
static grpc_error *pollset_epoll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
813
|
-
pollable *p, gpr_timespec now,
|
814
|
-
gpr_timespec deadline) {
|
815
|
-
int timeout = poll_deadline_to_millis_timeout(deadline, now);
|
816
|
-
|
817
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
818
|
-
char *desc = pollable_desc(p);
|
819
|
-
gpr_log(GPR_DEBUG, "PS:%p poll %p[%s] for %dms", pollset, p, desc, timeout);
|
820
|
-
gpr_free(desc);
|
821
|
-
}
|
822
|
-
|
823
|
-
if (timeout != 0) {
|
824
|
-
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
825
|
-
}
|
826
|
-
int r;
|
827
|
-
do {
|
828
|
-
GRPC_STATS_INC_SYSCALL_POLL(exec_ctx);
|
829
|
-
r = epoll_wait(p->epfd, pollset->events, MAX_EPOLL_EVENTS, timeout);
|
830
|
-
} while (r < 0 && errno == EINTR);
|
831
|
-
if (timeout != 0) {
|
832
|
-
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
833
|
-
}
|
834
|
-
|
835
|
-
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
|
836
|
-
|
837
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
838
|
-
gpr_log(GPR_DEBUG, "PS:%p poll %p got %d events", pollset, p, r);
|
839
|
-
}
|
840
|
-
|
841
|
-
pollset->event_cursor = 0;
|
842
|
-
pollset->event_count = r;
|
843
|
-
|
844
|
-
return GRPC_ERROR_NONE;
|
845
|
-
}
|
846
|
-
|
847
|
-
/* Return true if first in list */
|
848
|
-
static bool worker_insert(grpc_pollset_worker **root, pollset_worker_links link,
|
849
|
-
grpc_pollset_worker *worker) {
|
850
|
-
if (*root == NULL) {
|
851
|
-
*root = worker;
|
852
|
-
worker->links[link].next = worker->links[link].prev = worker;
|
853
|
-
return true;
|
854
|
-
} else {
|
855
|
-
worker->links[link].next = *root;
|
856
|
-
worker->links[link].prev = worker->links[link].next->links[link].prev;
|
857
|
-
worker->links[link].next->links[link].prev = worker;
|
858
|
-
worker->links[link].prev->links[link].next = worker;
|
859
|
-
return false;
|
860
|
-
}
|
861
|
-
}
|
862
|
-
|
863
|
-
/* Return true if last in list */
|
864
|
-
typedef enum { EMPTIED, NEW_ROOT, REMOVED } worker_remove_result;
|
865
|
-
|
866
|
-
static worker_remove_result worker_remove(grpc_pollset_worker **root,
|
867
|
-
pollset_worker_links link,
|
868
|
-
grpc_pollset_worker *worker) {
|
869
|
-
if (worker == *root) {
|
870
|
-
if (worker == worker->links[link].next) {
|
871
|
-
*root = NULL;
|
872
|
-
return EMPTIED;
|
873
|
-
} else {
|
874
|
-
*root = worker->links[link].next;
|
875
|
-
worker->links[link].prev->links[link].next = worker->links[link].next;
|
876
|
-
worker->links[link].next->links[link].prev = worker->links[link].prev;
|
877
|
-
return NEW_ROOT;
|
878
|
-
}
|
879
|
-
} else {
|
880
|
-
worker->links[link].prev->links[link].next = worker->links[link].next;
|
881
|
-
worker->links[link].next->links[link].prev = worker->links[link].prev;
|
882
|
-
return REMOVED;
|
883
|
-
}
|
884
|
-
}
|
885
|
-
|
886
|
-
/* Return true if this thread should poll */
|
887
|
-
static bool begin_worker(grpc_pollset *pollset, grpc_pollset_worker *worker,
|
888
|
-
grpc_pollset_worker **worker_hdl, gpr_timespec *now,
|
889
|
-
gpr_timespec deadline) {
|
890
|
-
bool do_poll = true;
|
891
|
-
if (worker_hdl != NULL) *worker_hdl = worker;
|
892
|
-
worker->initialized_cv = false;
|
893
|
-
worker->kicked = false;
|
894
|
-
worker->pollset = pollset;
|
895
|
-
worker->pollable_obj = pollset->current_pollable_obj;
|
896
|
-
|
897
|
-
if (pollset_is_pollable_fd(pollset, worker->pollable_obj)) {
|
898
|
-
REF_BY((grpc_fd *)worker->pollable_obj, 2, "one_poll");
|
899
|
-
}
|
900
|
-
|
901
|
-
worker_insert(&pollset->root_worker, PWL_POLLSET, worker);
|
902
|
-
if (!worker_insert(&worker->pollable_obj->root_worker, PWL_POLLABLE,
|
903
|
-
worker)) {
|
904
|
-
worker->initialized_cv = true;
|
905
|
-
gpr_cv_init(&worker->cv);
|
906
|
-
if (worker->pollable_obj != &pollset->pollable_obj) {
|
907
|
-
gpr_mu_unlock(&pollset->pollable_obj.po.mu);
|
908
|
-
}
|
909
|
-
if (GRPC_TRACER_ON(grpc_polling_trace) &&
|
910
|
-
worker->pollable_obj->root_worker != worker) {
|
911
|
-
gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset,
|
912
|
-
worker->pollable_obj, worker,
|
913
|
-
poll_deadline_to_millis_timeout(deadline, *now));
|
914
|
-
}
|
915
|
-
while (do_poll && worker->pollable_obj->root_worker != worker) {
|
916
|
-
if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->po.mu, deadline)) {
|
917
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
918
|
-
gpr_log(GPR_DEBUG, "PS:%p timeout_wait %p w=%p", pollset,
|
919
|
-
worker->pollable_obj, worker);
|
920
|
-
}
|
921
|
-
do_poll = false;
|
922
|
-
} else if (worker->kicked) {
|
923
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
924
|
-
gpr_log(GPR_DEBUG, "PS:%p wakeup %p w=%p", pollset,
|
925
|
-
worker->pollable_obj, worker);
|
926
|
-
}
|
927
|
-
do_poll = false;
|
928
|
-
} else if (GRPC_TRACER_ON(grpc_polling_trace) &&
|
929
|
-
worker->pollable_obj->root_worker != worker) {
|
930
|
-
gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset,
|
931
|
-
worker->pollable_obj, worker);
|
932
|
-
}
|
933
|
-
}
|
934
|
-
if (worker->pollable_obj != &pollset->pollable_obj) {
|
935
|
-
gpr_mu_unlock(&worker->pollable_obj->po.mu);
|
936
|
-
gpr_mu_lock(&pollset->pollable_obj.po.mu);
|
937
|
-
gpr_mu_lock(&worker->pollable_obj->po.mu);
|
938
|
-
}
|
939
|
-
*now = gpr_now(now->clock_type);
|
940
|
-
}
|
941
|
-
|
942
|
-
return do_poll && pollset->shutdown_closure == NULL &&
|
943
|
-
pollset->current_pollable_obj == worker->pollable_obj;
|
944
|
-
}
|
945
|
-
|
946
|
-
static void end_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
947
|
-
grpc_pollset_worker *worker,
|
948
|
-
grpc_pollset_worker **worker_hdl) {
|
949
|
-
if (NEW_ROOT ==
|
950
|
-
worker_remove(&worker->pollable_obj->root_worker, PWL_POLLABLE, worker)) {
|
951
|
-
gpr_cv_signal(&worker->pollable_obj->root_worker->cv);
|
952
|
-
}
|
953
|
-
if (worker->initialized_cv) {
|
954
|
-
gpr_cv_destroy(&worker->cv);
|
955
|
-
}
|
956
|
-
if (pollset_is_pollable_fd(pollset, worker->pollable_obj)) {
|
957
|
-
UNREF_BY(exec_ctx, (grpc_fd *)worker->pollable_obj, 2, "one_poll");
|
958
|
-
}
|
959
|
-
if (EMPTIED == worker_remove(&pollset->root_worker, PWL_POLLSET, worker)) {
|
960
|
-
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
961
|
-
}
|
962
|
-
}
|
963
|
-
|
964
|
-
/* pollset->po.mu lock must be held by the caller before calling this.
|
965
|
-
The function pollset_work() may temporarily release the lock (pollset->po.mu)
|
966
|
-
during the course of its execution but it will always re-acquire the lock and
|
967
|
-
ensure that it is held by the time the function returns */
|
968
|
-
static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
969
|
-
grpc_pollset_worker **worker_hdl,
|
970
|
-
gpr_timespec now, gpr_timespec deadline) {
|
971
|
-
grpc_pollset_worker worker;
|
972
|
-
if (0 && GRPC_TRACER_ON(grpc_polling_trace)) {
|
973
|
-
gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRId64
|
974
|
-
".%09d deadline=%" PRId64 ".%09d kwp=%d root_worker=%p",
|
975
|
-
pollset, worker_hdl, &worker, now.tv_sec, now.tv_nsec,
|
976
|
-
deadline.tv_sec, deadline.tv_nsec, pollset->kicked_without_poller,
|
977
|
-
pollset->root_worker);
|
978
|
-
}
|
979
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
980
|
-
static const char *err_desc = "pollset_work";
|
981
|
-
if (pollset->kicked_without_poller) {
|
982
|
-
pollset->kicked_without_poller = false;
|
983
|
-
return GRPC_ERROR_NONE;
|
984
|
-
}
|
985
|
-
if (pollset->current_pollable_obj != &pollset->pollable_obj) {
|
986
|
-
gpr_mu_lock(&pollset->current_pollable_obj->po.mu);
|
987
|
-
}
|
988
|
-
if (begin_worker(pollset, &worker, worker_hdl, &now, deadline)) {
|
989
|
-
gpr_tls_set(&g_current_thread_pollset, (intptr_t)pollset);
|
990
|
-
gpr_tls_set(&g_current_thread_worker, (intptr_t)&worker);
|
991
|
-
GPR_ASSERT(!pollset->shutdown_closure);
|
992
|
-
append_error(&error, pollable_materialize(worker.pollable_obj), err_desc);
|
993
|
-
if (worker.pollable_obj != &pollset->pollable_obj) {
|
994
|
-
gpr_mu_unlock(&worker.pollable_obj->po.mu);
|
995
|
-
}
|
996
|
-
gpr_mu_unlock(&pollset->pollable_obj.po.mu);
|
997
|
-
if (pollset->event_cursor == pollset->event_count) {
|
998
|
-
append_error(&error, pollset_epoll(exec_ctx, pollset, worker.pollable_obj,
|
999
|
-
now, deadline),
|
1000
|
-
err_desc);
|
1001
|
-
}
|
1002
|
-
append_error(&error, pollset_process_events(exec_ctx, pollset, false),
|
1003
|
-
err_desc);
|
1004
|
-
gpr_mu_lock(&pollset->pollable_obj.po.mu);
|
1005
|
-
if (worker.pollable_obj != &pollset->pollable_obj) {
|
1006
|
-
gpr_mu_lock(&worker.pollable_obj->po.mu);
|
1007
|
-
}
|
1008
|
-
gpr_tls_set(&g_current_thread_pollset, 0);
|
1009
|
-
gpr_tls_set(&g_current_thread_worker, 0);
|
1010
|
-
pollset_maybe_finish_shutdown(exec_ctx, pollset);
|
1011
|
-
}
|
1012
|
-
end_worker(exec_ctx, pollset, &worker, worker_hdl);
|
1013
|
-
if (worker.pollable_obj != &pollset->pollable_obj) {
|
1014
|
-
gpr_mu_unlock(&worker.pollable_obj->po.mu);
|
1015
|
-
}
|
1016
|
-
if (grpc_exec_ctx_has_work(exec_ctx)) {
|
1017
|
-
gpr_mu_unlock(&pollset->pollable_obj.po.mu);
|
1018
|
-
grpc_exec_ctx_flush(exec_ctx);
|
1019
|
-
gpr_mu_lock(&pollset->pollable_obj.po.mu);
|
1020
|
-
}
|
1021
|
-
return error;
|
1022
|
-
}
|
1023
|
-
|
1024
|
-
static void unref_fd_no_longer_poller(grpc_exec_ctx *exec_ctx, void *arg,
|
1025
|
-
grpc_error *error) {
|
1026
|
-
grpc_fd *fd = (grpc_fd *)arg;
|
1027
|
-
UNREF_BY(exec_ctx, fd, 2, "pollset_pollable");
|
1028
|
-
}
|
1029
|
-
|
1030
|
-
/* expects pollsets locked, flag whether fd is locked or not */
|
1031
|
-
static grpc_error *pollset_add_fd_locked(grpc_exec_ctx *exec_ctx,
|
1032
|
-
grpc_pollset *pollset, grpc_fd *fd,
|
1033
|
-
bool fd_locked) {
|
1034
|
-
static const char *err_desc = "pollset_add_fd";
|
1035
|
-
grpc_error *error = GRPC_ERROR_NONE;
|
1036
|
-
if (pollset->current_pollable_obj == &g_empty_pollable) {
|
1037
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
1038
|
-
gpr_log(GPR_DEBUG,
|
1039
|
-
"PS:%p add fd %p; transition pollable from empty to fd", pollset,
|
1040
|
-
fd);
|
1041
|
-
}
|
1042
|
-
/* empty pollable --> single fd pollable */
|
1043
|
-
pollset_kick_all(exec_ctx, pollset);
|
1044
|
-
pollset->current_pollable_obj = &fd->pollable_obj;
|
1045
|
-
if (!fd_locked) gpr_mu_lock(&fd->pollable_obj.po.mu);
|
1046
|
-
append_error(&error, fd_become_pollable_locked(fd), err_desc);
|
1047
|
-
if (!fd_locked) gpr_mu_unlock(&fd->pollable_obj.po.mu);
|
1048
|
-
REF_BY(fd, 2, "pollset_pollable");
|
1049
|
-
} else if (pollset->current_pollable_obj == &pollset->pollable_obj) {
|
1050
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
1051
|
-
gpr_log(GPR_DEBUG, "PS:%p add fd %p; already multipolling", pollset, fd);
|
1052
|
-
}
|
1053
|
-
append_error(&error, pollable_add_fd(pollset->current_pollable_obj, fd),
|
1054
|
-
err_desc);
|
1055
|
-
} else if (pollset->current_pollable_obj != &fd->pollable_obj) {
|
1056
|
-
grpc_fd *had_fd = (grpc_fd *)pollset->current_pollable_obj;
|
1057
|
-
if (GRPC_TRACER_ON(grpc_polling_trace)) {
|
1058
|
-
gpr_log(GPR_DEBUG,
|
1059
|
-
"PS:%p add fd %p; transition pollable from fd %p to multipoller",
|
1060
|
-
pollset, fd, had_fd);
|
1061
|
-
}
|
1062
|
-
/* Introduce a spurious completion.
|
1063
|
-
If we do not, then it may be that the fd-specific epoll set consumed
|
1064
|
-
a completion without being polled, leading to a missed edge going up. */
|
1065
|
-
grpc_lfev_set_ready(exec_ctx, &had_fd->read_closure, "read");
|
1066
|
-
grpc_lfev_set_ready(exec_ctx, &had_fd->write_closure, "write");
|
1067
|
-
pollset_kick_all(exec_ctx, pollset);
|
1068
|
-
pollset->current_pollable_obj = &pollset->pollable_obj;
|
1069
|
-
if (append_error(&error, pollable_materialize(&pollset->pollable_obj),
|
1070
|
-
err_desc)) {
|
1071
|
-
pollable_add_fd(&pollset->pollable_obj, had_fd);
|
1072
|
-
pollable_add_fd(&pollset->pollable_obj, fd);
|
1073
|
-
}
|
1074
|
-
GRPC_CLOSURE_SCHED(exec_ctx,
|
1075
|
-
GRPC_CLOSURE_CREATE(unref_fd_no_longer_poller, had_fd,
|
1076
|
-
grpc_schedule_on_exec_ctx),
|
1077
|
-
GRPC_ERROR_NONE);
|
1078
|
-
}
|
1079
|
-
return error;
|
1080
|
-
}
|
1081
|
-
|
1082
|
-
static void pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
1083
|
-
grpc_fd *fd) {
|
1084
|
-
gpr_mu_lock(&pollset->pollable_obj.po.mu);
|
1085
|
-
grpc_error *error = pollset_add_fd_locked(exec_ctx, pollset, fd, false);
|
1086
|
-
gpr_mu_unlock(&pollset->pollable_obj.po.mu);
|
1087
|
-
GRPC_LOG_IF_ERROR("pollset_add_fd", error);
|
1088
|
-
}
|
1089
|
-
|
1090
|
-
/*******************************************************************************
|
1091
|
-
* Pollset-set Definitions
|
1092
|
-
*/
|
1093
|
-
|
1094
|
-
static grpc_pollset_set *pollset_set_create(void) {
|
1095
|
-
grpc_pollset_set *pss = (grpc_pollset_set *)gpr_zalloc(sizeof(*pss));
|
1096
|
-
po_init(&pss->po, PO_POLLSET_SET);
|
1097
|
-
return pss;
|
1098
|
-
}
|
1099
|
-
|
1100
|
-
static void pollset_set_destroy(grpc_exec_ctx *exec_ctx,
|
1101
|
-
grpc_pollset_set *pss) {
|
1102
|
-
po_destroy(&pss->po);
|
1103
|
-
gpr_free(pss);
|
1104
|
-
}
|
1105
|
-
|
1106
|
-
static void pollset_set_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
|
1107
|
-
grpc_fd *fd) {
|
1108
|
-
po_join(exec_ctx, &pss->po, &fd->pollable_obj.po);
|
1109
|
-
}
|
1110
|
-
|
1111
|
-
static void pollset_set_del_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
|
1112
|
-
grpc_fd *fd) {}
|
1113
|
-
|
1114
|
-
static void pollset_set_add_pollset(grpc_exec_ctx *exec_ctx,
|
1115
|
-
grpc_pollset_set *pss, grpc_pollset *ps) {
|
1116
|
-
po_join(exec_ctx, &pss->po, &ps->pollable_obj.po);
|
1117
|
-
}
|
1118
|
-
|
1119
|
-
static void pollset_set_del_pollset(grpc_exec_ctx *exec_ctx,
|
1120
|
-
grpc_pollset_set *pss, grpc_pollset *ps) {}
|
1121
|
-
|
1122
|
-
static void pollset_set_add_pollset_set(grpc_exec_ctx *exec_ctx,
|
1123
|
-
grpc_pollset_set *bag,
|
1124
|
-
grpc_pollset_set *item) {
|
1125
|
-
po_join(exec_ctx, &bag->po, &item->po);
|
1126
|
-
}
|
1127
|
-
|
1128
|
-
static void pollset_set_del_pollset_set(grpc_exec_ctx *exec_ctx,
|
1129
|
-
grpc_pollset_set *bag,
|
1130
|
-
grpc_pollset_set *item) {}
|
1131
|
-
|
1132
|
-
static void po_init(polling_obj *po, polling_obj_type type) {
|
1133
|
-
gpr_mu_init(&po->mu);
|
1134
|
-
po->type = type;
|
1135
|
-
po->group = NULL;
|
1136
|
-
po->next = po;
|
1137
|
-
po->prev = po;
|
1138
|
-
}
|
1139
|
-
|
1140
|
-
static polling_group *pg_lock_latest(polling_group *pg) {
|
1141
|
-
/* assumes pg unlocked; consumes ref, returns ref */
|
1142
|
-
gpr_mu_lock(&pg->po.mu);
|
1143
|
-
while (pg->po.group != NULL) {
|
1144
|
-
polling_group *new_pg = pg_ref(pg->po.group);
|
1145
|
-
gpr_mu_unlock(&pg->po.mu);
|
1146
|
-
pg_unref(pg);
|
1147
|
-
pg = new_pg;
|
1148
|
-
gpr_mu_lock(&pg->po.mu);
|
1149
|
-
}
|
1150
|
-
return pg;
|
1151
|
-
}
|
1152
|
-
|
1153
|
-
static void po_destroy(polling_obj *po) {
|
1154
|
-
if (po->group != NULL) {
|
1155
|
-
polling_group *pg = pg_lock_latest(po->group);
|
1156
|
-
po->prev->next = po->next;
|
1157
|
-
po->next->prev = po->prev;
|
1158
|
-
gpr_mu_unlock(&pg->po.mu);
|
1159
|
-
pg_unref(pg);
|
1160
|
-
}
|
1161
|
-
gpr_mu_destroy(&po->mu);
|
1162
|
-
}
|
1163
|
-
|
1164
|
-
static polling_group *pg_ref(polling_group *pg) {
|
1165
|
-
gpr_ref(&pg->refs);
|
1166
|
-
return pg;
|
1167
|
-
}
|
1168
|
-
|
1169
|
-
static void pg_unref(polling_group *pg) {
|
1170
|
-
if (gpr_unref(&pg->refs)) {
|
1171
|
-
po_destroy(&pg->po);
|
1172
|
-
gpr_free(pg);
|
1173
|
-
}
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
static int po_cmp(polling_obj *a, polling_obj *b) {
|
1177
|
-
if (a == b) return 0;
|
1178
|
-
if (a->type < b->type) return -1;
|
1179
|
-
if (a->type > b->type) return 1;
|
1180
|
-
if (a < b) return -1;
|
1181
|
-
assert(a > b);
|
1182
|
-
return 1;
|
1183
|
-
}
|
1184
|
-
|
1185
|
-
static void po_join(grpc_exec_ctx *exec_ctx, polling_obj *a, polling_obj *b) {
|
1186
|
-
switch (po_cmp(a, b)) {
|
1187
|
-
case 0:
|
1188
|
-
return;
|
1189
|
-
case 1:
|
1190
|
-
GPR_SWAP(polling_obj *, a, b);
|
1191
|
-
/* fall through */
|
1192
|
-
case -1:
|
1193
|
-
gpr_mu_lock(&a->mu);
|
1194
|
-
gpr_mu_lock(&b->mu);
|
1195
|
-
|
1196
|
-
if (a->group == NULL) {
|
1197
|
-
if (b->group == NULL) {
|
1198
|
-
polling_obj *initial_po[] = {a, b};
|
1199
|
-
pg_create(exec_ctx, initial_po, GPR_ARRAY_SIZE(initial_po));
|
1200
|
-
gpr_mu_unlock(&a->mu);
|
1201
|
-
gpr_mu_unlock(&b->mu);
|
1202
|
-
} else {
|
1203
|
-
polling_group *b_group = pg_ref(b->group);
|
1204
|
-
gpr_mu_unlock(&b->mu);
|
1205
|
-
gpr_mu_unlock(&a->mu);
|
1206
|
-
pg_join(exec_ctx, b_group, a);
|
1207
|
-
}
|
1208
|
-
} else if (b->group == NULL) {
|
1209
|
-
polling_group *a_group = pg_ref(a->group);
|
1210
|
-
gpr_mu_unlock(&a->mu);
|
1211
|
-
gpr_mu_unlock(&b->mu);
|
1212
|
-
pg_join(exec_ctx, a_group, b);
|
1213
|
-
} else if (a->group == b->group) {
|
1214
|
-
/* nothing to do */
|
1215
|
-
gpr_mu_unlock(&a->mu);
|
1216
|
-
gpr_mu_unlock(&b->mu);
|
1217
|
-
} else {
|
1218
|
-
polling_group *a_group = pg_ref(a->group);
|
1219
|
-
polling_group *b_group = pg_ref(b->group);
|
1220
|
-
gpr_mu_unlock(&a->mu);
|
1221
|
-
gpr_mu_unlock(&b->mu);
|
1222
|
-
pg_merge(exec_ctx, a_group, b_group);
|
1223
|
-
}
|
1224
|
-
}
|
1225
|
-
}
|
1226
|
-
|
1227
|
-
static void pg_notify(grpc_exec_ctx *exec_ctx, polling_obj *a, polling_obj *b) {
|
1228
|
-
if (a->type == PO_FD && b->type == PO_POLLSET) {
|
1229
|
-
pollset_add_fd_locked(exec_ctx, (grpc_pollset *)b, (grpc_fd *)a, true);
|
1230
|
-
} else if (a->type == PO_POLLSET && b->type == PO_FD) {
|
1231
|
-
pollset_add_fd_locked(exec_ctx, (grpc_pollset *)a, (grpc_fd *)b, true);
|
1232
|
-
}
|
1233
|
-
}
|
1234
|
-
|
1235
|
-
static void pg_broadcast(grpc_exec_ctx *exec_ctx, polling_group *from,
|
1236
|
-
polling_group *to) {
|
1237
|
-
for (polling_obj *a = from->po.next; a != &from->po; a = a->next) {
|
1238
|
-
for (polling_obj *b = to->po.next; b != &to->po; b = b->next) {
|
1239
|
-
if (po_cmp(a, b) < 0) {
|
1240
|
-
gpr_mu_lock(&a->mu);
|
1241
|
-
gpr_mu_lock(&b->mu);
|
1242
|
-
} else {
|
1243
|
-
GPR_ASSERT(po_cmp(a, b) != 0);
|
1244
|
-
gpr_mu_lock(&b->mu);
|
1245
|
-
gpr_mu_lock(&a->mu);
|
1246
|
-
}
|
1247
|
-
pg_notify(exec_ctx, a, b);
|
1248
|
-
gpr_mu_unlock(&a->mu);
|
1249
|
-
gpr_mu_unlock(&b->mu);
|
1250
|
-
}
|
1251
|
-
}
|
1252
|
-
}
|
1253
|
-
|
1254
|
-
static void pg_create(grpc_exec_ctx *exec_ctx, polling_obj **initial_po,
|
1255
|
-
size_t initial_po_count) {
|
1256
|
-
/* assumes all polling objects in initial_po are locked */
|
1257
|
-
polling_group *pg = (polling_group *)gpr_malloc(sizeof(*pg));
|
1258
|
-
po_init(&pg->po, PO_POLLING_GROUP);
|
1259
|
-
gpr_ref_init(&pg->refs, (int)initial_po_count);
|
1260
|
-
for (size_t i = 0; i < initial_po_count; i++) {
|
1261
|
-
GPR_ASSERT(initial_po[i]->group == NULL);
|
1262
|
-
initial_po[i]->group = pg;
|
1263
|
-
}
|
1264
|
-
for (size_t i = 1; i < initial_po_count; i++) {
|
1265
|
-
initial_po[i]->prev = initial_po[i - 1];
|
1266
|
-
}
|
1267
|
-
for (size_t i = 0; i < initial_po_count - 1; i++) {
|
1268
|
-
initial_po[i]->next = initial_po[i + 1];
|
1269
|
-
}
|
1270
|
-
initial_po[0]->prev = &pg->po;
|
1271
|
-
initial_po[initial_po_count - 1]->next = &pg->po;
|
1272
|
-
pg->po.next = initial_po[0];
|
1273
|
-
pg->po.prev = initial_po[initial_po_count - 1];
|
1274
|
-
for (size_t i = 1; i < initial_po_count; i++) {
|
1275
|
-
for (size_t j = 0; j < i; j++) {
|
1276
|
-
pg_notify(exec_ctx, initial_po[i], initial_po[j]);
|
1277
|
-
}
|
1278
|
-
}
|
1279
|
-
}
|
1280
|
-
|
1281
|
-
static void pg_join(grpc_exec_ctx *exec_ctx, polling_group *pg,
|
1282
|
-
polling_obj *po) {
|
1283
|
-
/* assumes neither pg nor po are locked; consumes one ref to pg */
|
1284
|
-
pg = pg_lock_latest(pg);
|
1285
|
-
/* pg locked */
|
1286
|
-
for (polling_obj *existing = pg->po.next /* skip pg - it's just a stub */;
|
1287
|
-
existing != &pg->po; existing = existing->next) {
|
1288
|
-
if (po_cmp(po, existing) < 0) {
|
1289
|
-
gpr_mu_lock(&po->mu);
|
1290
|
-
gpr_mu_lock(&existing->mu);
|
1291
|
-
} else {
|
1292
|
-
GPR_ASSERT(po_cmp(po, existing) != 0);
|
1293
|
-
gpr_mu_lock(&existing->mu);
|
1294
|
-
gpr_mu_lock(&po->mu);
|
1295
|
-
}
|
1296
|
-
/* pg, po, existing locked */
|
1297
|
-
if (po->group != NULL) {
|
1298
|
-
gpr_mu_unlock(&pg->po.mu);
|
1299
|
-
polling_group *po_group = pg_ref(po->group);
|
1300
|
-
gpr_mu_unlock(&po->mu);
|
1301
|
-
gpr_mu_unlock(&existing->mu);
|
1302
|
-
pg_merge(exec_ctx, pg, po_group);
|
1303
|
-
/* early exit: polling obj picked up a group during joining: we needed
|
1304
|
-
to do a full merge */
|
1305
|
-
return;
|
1306
|
-
}
|
1307
|
-
pg_notify(exec_ctx, po, existing);
|
1308
|
-
gpr_mu_unlock(&po->mu);
|
1309
|
-
gpr_mu_unlock(&existing->mu);
|
1310
|
-
}
|
1311
|
-
gpr_mu_lock(&po->mu);
|
1312
|
-
if (po->group != NULL) {
|
1313
|
-
gpr_mu_unlock(&pg->po.mu);
|
1314
|
-
polling_group *po_group = pg_ref(po->group);
|
1315
|
-
gpr_mu_unlock(&po->mu);
|
1316
|
-
pg_merge(exec_ctx, pg, po_group);
|
1317
|
-
/* early exit: polling obj picked up a group during joining: we needed
|
1318
|
-
to do a full merge */
|
1319
|
-
return;
|
1320
|
-
}
|
1321
|
-
po->group = pg;
|
1322
|
-
po->next = &pg->po;
|
1323
|
-
po->prev = pg->po.prev;
|
1324
|
-
po->prev->next = po->next->prev = po;
|
1325
|
-
gpr_mu_unlock(&pg->po.mu);
|
1326
|
-
gpr_mu_unlock(&po->mu);
|
1327
|
-
}
|
1328
|
-
|
1329
|
-
static void pg_merge(grpc_exec_ctx *exec_ctx, polling_group *a,
|
1330
|
-
polling_group *b) {
|
1331
|
-
for (;;) {
|
1332
|
-
if (a == b) {
|
1333
|
-
pg_unref(a);
|
1334
|
-
pg_unref(b);
|
1335
|
-
return;
|
1336
|
-
}
|
1337
|
-
if (a > b) GPR_SWAP(polling_group *, a, b);
|
1338
|
-
gpr_mu_lock(&a->po.mu);
|
1339
|
-
gpr_mu_lock(&b->po.mu);
|
1340
|
-
if (a->po.group != NULL) {
|
1341
|
-
polling_group *m2 = pg_ref(a->po.group);
|
1342
|
-
gpr_mu_unlock(&a->po.mu);
|
1343
|
-
gpr_mu_unlock(&b->po.mu);
|
1344
|
-
pg_unref(a);
|
1345
|
-
a = m2;
|
1346
|
-
} else if (b->po.group != NULL) {
|
1347
|
-
polling_group *m2 = pg_ref(b->po.group);
|
1348
|
-
gpr_mu_unlock(&a->po.mu);
|
1349
|
-
gpr_mu_unlock(&b->po.mu);
|
1350
|
-
pg_unref(b);
|
1351
|
-
b = m2;
|
1352
|
-
} else {
|
1353
|
-
break;
|
1354
|
-
}
|
1355
|
-
}
|
1356
|
-
polling_group **unref = NULL;
|
1357
|
-
size_t unref_count = 0;
|
1358
|
-
size_t unref_cap = 0;
|
1359
|
-
b->po.group = a;
|
1360
|
-
pg_broadcast(exec_ctx, a, b);
|
1361
|
-
pg_broadcast(exec_ctx, b, a);
|
1362
|
-
while (b->po.next != &b->po) {
|
1363
|
-
polling_obj *po = b->po.next;
|
1364
|
-
gpr_mu_lock(&po->mu);
|
1365
|
-
if (unref_count == unref_cap) {
|
1366
|
-
unref_cap = GPR_MAX(8, 3 * unref_cap / 2);
|
1367
|
-
unref = (polling_group **)gpr_realloc(unref, unref_cap * sizeof(*unref));
|
1368
|
-
}
|
1369
|
-
unref[unref_count++] = po->group;
|
1370
|
-
po->group = pg_ref(a);
|
1371
|
-
// unlink from b
|
1372
|
-
po->prev->next = po->next;
|
1373
|
-
po->next->prev = po->prev;
|
1374
|
-
// link to a
|
1375
|
-
po->next = &a->po;
|
1376
|
-
po->prev = a->po.prev;
|
1377
|
-
po->next->prev = po->prev->next = po;
|
1378
|
-
gpr_mu_unlock(&po->mu);
|
1379
|
-
}
|
1380
|
-
gpr_mu_unlock(&a->po.mu);
|
1381
|
-
gpr_mu_unlock(&b->po.mu);
|
1382
|
-
for (size_t i = 0; i < unref_count; i++) {
|
1383
|
-
pg_unref(unref[i]);
|
1384
|
-
}
|
1385
|
-
gpr_free(unref);
|
1386
|
-
pg_unref(b);
|
1387
|
-
}
|
1388
|
-
|
1389
|
-
/*******************************************************************************
|
1390
|
-
* Event engine binding
|
1391
|
-
*/
|
1392
|
-
|
1393
|
-
static void shutdown_engine(void) {
|
1394
|
-
fd_global_shutdown();
|
1395
|
-
pollset_global_shutdown();
|
1396
|
-
}
|
1397
|
-
|
1398
|
-
static const grpc_event_engine_vtable vtable = {
|
1399
|
-
sizeof(grpc_pollset),
|
1400
|
-
|
1401
|
-
fd_create,
|
1402
|
-
fd_wrapped_fd,
|
1403
|
-
fd_orphan,
|
1404
|
-
fd_shutdown,
|
1405
|
-
fd_notify_on_read,
|
1406
|
-
fd_notify_on_write,
|
1407
|
-
fd_is_shutdown,
|
1408
|
-
fd_get_read_notifier_pollset,
|
1409
|
-
|
1410
|
-
pollset_init,
|
1411
|
-
pollset_shutdown,
|
1412
|
-
pollset_destroy,
|
1413
|
-
pollset_work,
|
1414
|
-
pollset_kick,
|
1415
|
-
pollset_add_fd,
|
1416
|
-
|
1417
|
-
pollset_set_create,
|
1418
|
-
pollset_set_destroy,
|
1419
|
-
pollset_set_add_pollset,
|
1420
|
-
pollset_set_del_pollset,
|
1421
|
-
pollset_set_add_pollset_set,
|
1422
|
-
pollset_set_del_pollset_set,
|
1423
|
-
pollset_set_add_fd,
|
1424
|
-
pollset_set_del_fd,
|
1425
|
-
|
1426
|
-
shutdown_engine,
|
1427
|
-
};
|
1428
|
-
|
1429
|
-
const grpc_event_engine_vtable *grpc_init_epollex_linux(
|
1430
|
-
bool explicitly_requested) {
|
1431
|
-
if (!grpc_has_wakeup_fd()) {
|
1432
|
-
return NULL;
|
1433
|
-
}
|
1434
|
-
|
1435
|
-
if (!grpc_is_epollexclusive_available()) {
|
1436
|
-
return NULL;
|
1437
|
-
}
|
1438
|
-
|
1439
|
-
fd_global_init();
|
1440
|
-
|
1441
|
-
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
|
1442
|
-
pollset_global_shutdown();
|
1443
|
-
fd_global_shutdown();
|
1444
|
-
return NULL;
|
1445
|
-
}
|
1446
|
-
|
1447
|
-
return &vtable;
|
1448
|
-
}
|
1449
|
-
|
1450
|
-
#else /* defined(GRPC_LINUX_EPOLL) */
|
1451
|
-
#if defined(GRPC_POSIX_SOCKET)
|
1452
|
-
#include "src/core/lib/iomgr/ev_posix.h"
|
1453
|
-
/* If GRPC_LINUX_EPOLL is not defined, it means epoll is not available. Return
|
1454
|
-
* NULL */
|
1455
|
-
const grpc_event_engine_vtable *grpc_init_epollex_linux(
|
1456
|
-
bool explicitly_requested) {
|
1457
|
-
return NULL;
|
1458
|
-
}
|
1459
|
-
#endif /* defined(GRPC_POSIX_SOCKET) */
|
1460
|
-
|
1461
|
-
#endif /* !defined(GRPC_LINUX_EPOLL) */
|