grpc 1.6.7 → 1.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +579 -77
- data/include/grpc/byte_buffer.h +1 -63
- data/include/grpc/compression.h +27 -5
- data/include/grpc/fork.h +24 -0
- data/include/grpc/grpc.h +12 -6
- data/include/grpc/grpc_security.h +28 -7
- data/include/grpc/impl/codegen/atm.h +1 -0
- data/include/grpc/impl/codegen/byte_buffer.h +86 -0
- data/include/grpc/impl/codegen/compression_types.h +63 -5
- data/include/grpc/impl/codegen/fork.h +48 -0
- data/include/grpc/impl/codegen/grpc_types.h +26 -9
- data/include/grpc/impl/codegen/port_platform.h +11 -4
- data/include/grpc/impl/codegen/slice.h +6 -1
- data/include/grpc/impl/codegen/sync.h +3 -1
- data/include/grpc/impl/codegen/sync_custom.h +36 -0
- data/include/grpc/module.modulemap +75 -3
- data/include/grpc/slice.h +1 -5
- data/include/grpc/support/sync_custom.h +24 -0
- data/src/core/ext/census/base_resources.c +14 -14
- data/src/core/ext/census/context.c +7 -5
- data/src/core/ext/census/grpc_filter.c +12 -14
- data/src/core/ext/census/mlog.c +2 -1
- data/src/core/ext/census/resource.c +13 -9
- data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
- data/src/core/ext/filters/client_channel/client_channel.c +418 -439
- data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
- data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
- data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
- data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
- data/src/core/ext/filters/client_channel/subchannel.c +30 -30
- data/src/core/ext/filters/client_channel/subchannel.h +1 -4
- data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
- data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
- data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
- data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
- data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
- data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
- data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
- data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
- data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
- data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
- data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
- data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
- data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
- data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
- data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
- data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
- data/src/core/lib/channel/channel_args.c +112 -12
- data/src/core/lib/channel/channel_args.h +31 -0
- data/src/core/lib/channel/channel_stack.c +1 -15
- data/src/core/lib/channel/channel_stack.h +3 -10
- data/src/core/lib/channel/channel_stack_builder.c +41 -10
- data/src/core/lib/channel/channel_stack_builder.h +10 -0
- data/src/core/lib/channel/connected_channel.c +94 -23
- data/src/core/lib/channel/handshaker.c +8 -6
- data/src/core/lib/channel/handshaker_registry.c +1 -1
- data/src/core/lib/compression/algorithm_metadata.h +14 -0
- data/src/core/lib/compression/compression.c +101 -1
- data/src/core/lib/compression/stream_compression.c +32 -146
- data/src/core/lib/compression/stream_compression.h +28 -4
- data/src/core/lib/compression/stream_compression_gzip.c +228 -0
- data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
- data/src/core/lib/compression/stream_compression_identity.c +94 -0
- data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
- data/src/core/lib/debug/stats.c +174 -0
- data/src/core/lib/debug/stats.h +61 -0
- data/src/core/lib/debug/stats_data.c +687 -0
- data/src/core/lib/debug/stats_data.h +470 -0
- data/src/core/lib/debug/trace.c +3 -3
- data/src/core/lib/debug/trace.h +1 -1
- data/src/core/lib/http/format_request.c +1 -1
- data/src/core/lib/http/httpcli.c +8 -7
- data/src/core/lib/http/httpcli_security_connector.c +2 -1
- data/src/core/lib/http/parser.c +4 -3
- data/src/core/lib/iomgr/call_combiner.c +202 -0
- data/src/core/lib/iomgr/call_combiner.h +121 -0
- data/src/core/lib/iomgr/closure.c +18 -4
- data/src/core/lib/iomgr/combiner.c +11 -4
- data/src/core/lib/iomgr/error.c +26 -24
- data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
- data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
- data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
- data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
- data/src/core/lib/iomgr/ev_posix.c +5 -9
- data/src/core/lib/iomgr/ev_posix.h +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +6 -1
- data/src/core/lib/iomgr/executor.c +142 -36
- data/src/core/lib/iomgr/executor.h +6 -1
- data/src/core/lib/iomgr/fork_posix.c +88 -0
- data/src/core/lib/iomgr/fork_windows.c +39 -0
- data/src/core/lib/iomgr/iocp_windows.c +2 -0
- data/src/core/lib/iomgr/iomgr.c +2 -8
- data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
- data/src/core/lib/iomgr/load_file.c +2 -1
- data/src/core/lib/iomgr/polling_entity.c +9 -9
- data/src/core/lib/iomgr/polling_entity.h +7 -1
- data/src/core/lib/iomgr/pollset.h +1 -1
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/port.h +4 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
- data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
- data/src/core/lib/iomgr/resource_quota.c +24 -19
- data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
- data/src/core/lib/iomgr/socket_mutator.c +4 -4
- data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
- data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
- data/src/core/lib/iomgr/tcp_posix.c +181 -20
- data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
- data/src/core/lib/iomgr/timer.h +4 -0
- data/src/core/lib/iomgr/timer_generic.c +138 -3
- data/src/core/lib/iomgr/timer_generic.h +3 -0
- data/src/core/lib/iomgr/timer_heap.c +4 -4
- data/src/core/lib/iomgr/timer_manager.c +2 -2
- data/src/core/lib/iomgr/timer_uv.c +2 -0
- data/src/core/lib/iomgr/udp_server.c +10 -8
- data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
- data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
- data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
- data/src/core/lib/json/json.c +1 -1
- data/src/core/lib/json/json_string.c +13 -13
- data/src/core/lib/profiling/timers.h +18 -8
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/transport/client_auth_filter.c +68 -135
- data/src/core/lib/security/transport/secure_endpoint.c +110 -90
- data/src/core/lib/security/transport/secure_endpoint.h +8 -3
- data/src/core/lib/security/transport/security_connector.c +10 -12
- data/src/core/lib/security/transport/security_handshaker.c +45 -24
- data/src/core/lib/security/transport/server_auth_filter.c +71 -20
- data/src/core/lib/slice/b64.c +2 -2
- data/src/core/lib/slice/slice.c +16 -14
- data/src/core/lib/slice/slice_buffer.c +5 -4
- data/src/core/lib/slice/slice_hash_table.c +3 -2
- data/src/core/lib/slice/slice_intern.c +8 -5
- data/src/core/lib/support/block_annotate.h +22 -0
- data/src/core/lib/support/fork.c +62 -0
- data/src/core/lib/support/fork.h +35 -0
- data/src/core/lib/support/log_linux.c +1 -1
- data/src/core/lib/support/string.c +15 -1
- data/src/core/lib/support/string.h +3 -0
- data/src/core/lib/support/thd_internal.h +6 -0
- data/src/core/lib/support/thd_posix.c +56 -0
- data/src/core/lib/support/thd_windows.c +2 -0
- data/src/core/lib/surface/alarm.c +22 -15
- data/src/core/lib/surface/byte_buffer.c +4 -2
- data/src/core/lib/surface/call.c +442 -141
- data/src/core/lib/surface/call.h +6 -6
- data/src/core/lib/surface/call_log_batch.c +1 -1
- data/src/core/lib/surface/call_test_only.h +12 -0
- data/src/core/lib/surface/channel.c +39 -4
- data/src/core/lib/surface/channel_init.c +6 -6
- data/src/core/lib/surface/channel_ping.c +2 -2
- data/src/core/lib/surface/completion_queue.c +56 -57
- data/src/core/lib/surface/init.c +17 -3
- data/src/core/lib/surface/init_secure.c +5 -1
- data/src/core/lib/surface/lame_client.cc +9 -10
- data/src/core/lib/surface/server.c +81 -72
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/byte_stream.c +1 -0
- data/src/core/lib/transport/byte_stream.h +3 -1
- data/src/core/lib/transport/connectivity_state.c +2 -1
- data/src/core/lib/transport/metadata.c +7 -4
- data/src/core/lib/transport/metadata_batch.c +18 -16
- data/src/core/lib/transport/metadata_batch.h +1 -0
- data/src/core/lib/transport/service_config.c +5 -3
- data/src/core/lib/transport/static_metadata.c +395 -614
- data/src/core/lib/transport/static_metadata.h +165 -133
- data/src/core/lib/transport/status_conversion.c +1 -1
- data/src/core/lib/transport/transport.c +20 -20
- data/src/core/lib/transport/transport.h +8 -5
- data/src/core/lib/transport/transport_impl.h +0 -3
- data/src/core/lib/transport/transport_op_string.c +8 -1
- data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
- data/src/core/tsi/fake_transport_security.c +133 -2
- data/src/core/tsi/fake_transport_security.h +5 -0
- data/src/core/tsi/ssl_transport_security.c +105 -8
- data/src/core/tsi/ssl_transport_security.h +30 -7
- data/src/core/tsi/transport_security.h +8 -2
- data/src/core/tsi/transport_security_grpc.c +20 -13
- data/src/core/tsi/transport_security_grpc.h +13 -9
- data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
- data/src/ruby/lib/grpc.rb +1 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
- data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
- data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
- data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
- data/src/ruby/spec/channel_connection_spec.rb +1 -34
- data/src/ruby/spec/client_server_spec.rb +188 -82
- data/src/ruby/spec/generic/active_call_spec.rb +65 -11
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/spec_helper.rb +4 -0
- data/src/ruby/spec/support/helpers.rb +73 -0
- data/src/ruby/spec/support/services.rb +147 -0
- data/third_party/cares/ares_build.h +21 -62
- data/third_party/cares/cares/ares.h +23 -1
- data/third_party/cares/cares/ares__close_sockets.c +2 -2
- data/third_party/cares/cares/ares_create_query.c +3 -3
- data/third_party/cares/cares/ares_expand_name.c +6 -2
- data/third_party/cares/cares/ares_expand_string.c +1 -1
- data/third_party/cares/cares/ares_getnameinfo.c +27 -7
- data/third_party/cares/cares/ares_init.c +407 -39
- data/third_party/cares/cares/ares_library_init.c +10 -0
- data/third_party/cares/cares/ares_library_init.h +2 -1
- data/third_party/cares/cares/ares_nowarn.c +6 -6
- data/third_party/cares/cares/ares_nowarn.h +2 -2
- data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
- data/third_party/cares/cares/ares_private.h +11 -0
- data/third_party/cares/cares/ares_process.c +126 -37
- data/third_party/cares/cares/ares_version.h +2 -2
- data/third_party/cares/cares/ares_writev.c +2 -2
- data/third_party/cares/cares/config-win32.h +8 -34
- data/third_party/cares/cares/inet_net_pton.c +2 -2
- data/third_party/cares/cares/setup_once.h +5 -5
- data/third_party/cares/config_darwin/ares_config.h +98 -196
- data/third_party/cares/config_linux/ares_config.h +103 -203
- metadata +47 -20
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
@@ -31,8 +31,6 @@
|
|
31
31
|
|
32
32
|
#include "src/core/lib/debug/trace.h"
|
33
33
|
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
|
34
|
-
#include "src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h"
|
35
|
-
#include "src/core/lib/iomgr/ev_epoll_thread_pool_linux.h"
|
36
34
|
#include "src/core/lib/iomgr/ev_epollex_linux.h"
|
37
35
|
#include "src/core/lib/iomgr/ev_epollsig_linux.h"
|
38
36
|
#include "src/core/lib/iomgr/ev_poll_posix.h"
|
@@ -64,10 +62,8 @@ typedef struct {
|
|
64
62
|
} event_engine_factory;
|
65
63
|
|
66
64
|
static const event_engine_factory g_factories[] = {
|
67
|
-
{"epollsig", grpc_init_epollsig_linux},
|
68
65
|
{"epoll1", grpc_init_epoll1_linux},
|
69
|
-
{"
|
70
|
-
{"epoll-limited", grpc_init_epoll_limited_pollers_linux},
|
66
|
+
{"epollsig", grpc_init_epollsig_linux},
|
71
67
|
{"poll", grpc_init_poll_posix},
|
72
68
|
{"poll-cv", grpc_init_poll_cv_posix},
|
73
69
|
{"epollex", grpc_init_epollex_linux},
|
@@ -80,10 +76,10 @@ static void add(const char *beg, const char *end, char ***ss, size_t *ns) {
|
|
80
76
|
size_t len;
|
81
77
|
GPR_ASSERT(end >= beg);
|
82
78
|
len = (size_t)(end - beg);
|
83
|
-
s = gpr_malloc(len + 1);
|
79
|
+
s = (char *)gpr_malloc(len + 1);
|
84
80
|
memcpy(s, beg, len);
|
85
81
|
s[len] = 0;
|
86
|
-
*ss = gpr_realloc(*ss, sizeof(char **) * np);
|
82
|
+
*ss = (char **)gpr_realloc(*ss, sizeof(char **) * np);
|
87
83
|
(*ss)[n] = s;
|
88
84
|
*ns = np;
|
89
85
|
}
|
@@ -214,9 +210,9 @@ grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
|
214
210
|
return g_event_engine->pollset_work(exec_ctx, pollset, worker, now, deadline);
|
215
211
|
}
|
216
212
|
|
217
|
-
grpc_error *grpc_pollset_kick(grpc_pollset *pollset,
|
213
|
+
grpc_error *grpc_pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
218
214
|
grpc_pollset_worker *specific_worker) {
|
219
|
-
return g_event_engine->pollset_kick(pollset, specific_worker);
|
215
|
+
return g_event_engine->pollset_kick(exec_ctx, pollset, specific_worker);
|
220
216
|
}
|
221
217
|
|
222
218
|
void grpc_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
@@ -54,7 +54,7 @@ typedef struct grpc_event_engine_vtable {
|
|
54
54
|
grpc_error *(*pollset_work)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
55
55
|
grpc_pollset_worker **worker, gpr_timespec now,
|
56
56
|
gpr_timespec deadline);
|
57
|
-
grpc_error *(*pollset_kick)(grpc_pollset *pollset,
|
57
|
+
grpc_error *(*pollset_kick)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
58
58
|
grpc_pollset_worker *specific_worker);
|
59
59
|
void (*pollset_add_fd)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
60
60
|
struct grpc_fd *fd);
|
@@ -19,6 +19,7 @@
|
|
19
19
|
#ifndef GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
|
20
20
|
#define GRPC_CORE_LIB_IOMGR_EXEC_CTX_H
|
21
21
|
|
22
|
+
#include <grpc/support/cpu.h>
|
22
23
|
#include "src/core/lib/iomgr/closure.h"
|
23
24
|
|
24
25
|
/* #define GRPC_EXECUTION_CONTEXT_SANITIZER 1 */
|
@@ -62,6 +63,7 @@ struct grpc_exec_ctx {
|
|
62
63
|
/** last active combiner in the active combiner list */
|
63
64
|
grpc_combiner *last_combiner;
|
64
65
|
uintptr_t flags;
|
66
|
+
unsigned starting_cpu;
|
65
67
|
void *check_ready_to_finish_arg;
|
66
68
|
bool (*check_ready_to_finish)(grpc_exec_ctx *exec_ctx, void *arg);
|
67
69
|
};
|
@@ -69,7 +71,10 @@ struct grpc_exec_ctx {
|
|
69
71
|
/* initializer for grpc_exec_ctx:
|
70
72
|
prefer to use GRPC_EXEC_CTX_INIT whenever possible */
|
71
73
|
#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \
|
72
|
-
{
|
74
|
+
{ \
|
75
|
+
GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, gpr_cpu_current_cpu(), \
|
76
|
+
finish_check_arg, finish_check \
|
77
|
+
}
|
73
78
|
|
74
79
|
/* initialize an execution context at the top level of an API call into grpc
|
75
80
|
(this is safe to use elsewhere, though possibly not as efficient) */
|
@@ -28,6 +28,7 @@
|
|
28
28
|
#include <grpc/support/tls.h>
|
29
29
|
#include <grpc/support/useful.h>
|
30
30
|
|
31
|
+
#include "src/core/lib/debug/stats.h"
|
31
32
|
#include "src/core/lib/iomgr/exec_ctx.h"
|
32
33
|
#include "src/core/lib/support/spinlock.h"
|
33
34
|
|
@@ -39,6 +40,7 @@ typedef struct {
|
|
39
40
|
grpc_closure_list elems;
|
40
41
|
size_t depth;
|
41
42
|
bool shutdown;
|
43
|
+
bool queued_long_job;
|
42
44
|
gpr_thd_id id;
|
43
45
|
} thread_state;
|
44
46
|
|
@@ -49,6 +51,9 @@ static gpr_spinlock g_adding_thread_lock = GPR_SPINLOCK_STATIC_INITIALIZER;
|
|
49
51
|
|
50
52
|
GPR_TLS_DECL(g_this_thread_state);
|
51
53
|
|
54
|
+
static grpc_tracer_flag executor_trace =
|
55
|
+
GRPC_TRACER_INITIALIZER(false, "executor");
|
56
|
+
|
52
57
|
static void executor_thread(void *arg);
|
53
58
|
|
54
59
|
static size_t run_closures(grpc_exec_ctx *exec_ctx, grpc_closure_list list) {
|
@@ -58,6 +63,14 @@ static size_t run_closures(grpc_exec_ctx *exec_ctx, grpc_closure_list list) {
|
|
58
63
|
while (c != NULL) {
|
59
64
|
grpc_closure *next = c->next_data.next;
|
60
65
|
grpc_error *error = c->error_data.error;
|
66
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
67
|
+
#ifndef NDEBUG
|
68
|
+
gpr_log(GPR_DEBUG, "EXECUTOR: run %p [created by %s:%d]", c,
|
69
|
+
c->file_created, c->line_created);
|
70
|
+
#else
|
71
|
+
gpr_log(GPR_DEBUG, "EXECUTOR: run %p", c);
|
72
|
+
#endif
|
73
|
+
}
|
61
74
|
#ifndef NDEBUG
|
62
75
|
c->scheduled = false;
|
63
76
|
#endif
|
@@ -65,6 +78,7 @@ static size_t run_closures(grpc_exec_ctx *exec_ctx, grpc_closure_list list) {
|
|
65
78
|
GRPC_ERROR_UNREF(error);
|
66
79
|
c = next;
|
67
80
|
n++;
|
81
|
+
grpc_exec_ctx_flush(exec_ctx);
|
68
82
|
}
|
69
83
|
|
70
84
|
return n;
|
@@ -81,7 +95,8 @@ void grpc_executor_set_threading(grpc_exec_ctx *exec_ctx, bool threading) {
|
|
81
95
|
g_max_threads = GPR_MAX(1, 2 * gpr_cpu_num_cores());
|
82
96
|
gpr_atm_no_barrier_store(&g_cur_threads, 1);
|
83
97
|
gpr_tls_init(&g_this_thread_state);
|
84
|
-
g_thread_state =
|
98
|
+
g_thread_state =
|
99
|
+
(thread_state *)gpr_zalloc(sizeof(thread_state) * g_max_threads);
|
85
100
|
for (size_t i = 0; i < g_max_threads; i++) {
|
86
101
|
gpr_mu_init(&g_thread_state[i].mu);
|
87
102
|
gpr_cv_init(&g_thread_state[i].cv);
|
@@ -119,6 +134,7 @@ void grpc_executor_set_threading(grpc_exec_ctx *exec_ctx, bool threading) {
|
|
119
134
|
}
|
120
135
|
|
121
136
|
void grpc_executor_init(grpc_exec_ctx *exec_ctx) {
|
137
|
+
grpc_register_tracer(&executor_trace);
|
122
138
|
gpr_atm_no_barrier_store(&g_cur_threads, 0);
|
123
139
|
grpc_executor_set_threading(exec_ctx, true);
|
124
140
|
}
|
@@ -128,7 +144,7 @@ void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx) {
|
|
128
144
|
}
|
129
145
|
|
130
146
|
static void executor_thread(void *arg) {
|
131
|
-
thread_state *ts = arg;
|
147
|
+
thread_state *ts = (thread_state *)arg;
|
132
148
|
gpr_tls_set(&g_this_thread_state, (intptr_t)ts);
|
133
149
|
|
134
150
|
grpc_exec_ctx exec_ctx =
|
@@ -136,60 +152,150 @@ static void executor_thread(void *arg) {
|
|
136
152
|
|
137
153
|
size_t subtract_depth = 0;
|
138
154
|
for (;;) {
|
155
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
156
|
+
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")",
|
157
|
+
(int)(ts - g_thread_state), subtract_depth);
|
158
|
+
}
|
139
159
|
gpr_mu_lock(&ts->mu);
|
140
160
|
ts->depth -= subtract_depth;
|
141
161
|
while (grpc_closure_list_empty(ts->elems) && !ts->shutdown) {
|
162
|
+
ts->queued_long_job = false;
|
142
163
|
gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
|
143
164
|
}
|
144
165
|
if (ts->shutdown) {
|
166
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
167
|
+
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown",
|
168
|
+
(int)(ts - g_thread_state));
|
169
|
+
}
|
145
170
|
gpr_mu_unlock(&ts->mu);
|
146
171
|
break;
|
147
172
|
}
|
173
|
+
GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(&exec_ctx);
|
148
174
|
grpc_closure_list exec = ts->elems;
|
149
175
|
ts->elems = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT;
|
150
176
|
gpr_mu_unlock(&ts->mu);
|
177
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
178
|
+
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state));
|
179
|
+
}
|
151
180
|
|
152
181
|
subtract_depth = run_closures(&exec_ctx, exec);
|
153
|
-
grpc_exec_ctx_flush(&exec_ctx);
|
154
182
|
}
|
155
183
|
grpc_exec_ctx_finish(&exec_ctx);
|
156
184
|
}
|
157
185
|
|
158
186
|
static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
|
159
|
-
grpc_error *error) {
|
160
|
-
|
161
|
-
if (
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
thread_state *ts = (thread_state *)gpr_tls_get(&g_this_thread_state);
|
166
|
-
if (ts == NULL) {
|
167
|
-
ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)];
|
168
|
-
}
|
169
|
-
gpr_mu_lock(&ts->mu);
|
170
|
-
if (grpc_closure_list_empty(ts->elems)) {
|
171
|
-
gpr_cv_signal(&ts->cv);
|
187
|
+
grpc_error *error, bool is_short) {
|
188
|
+
bool retry_push;
|
189
|
+
if (is_short) {
|
190
|
+
GRPC_STATS_INC_EXECUTOR_SCHEDULED_SHORT_ITEMS(exec_ctx);
|
191
|
+
} else {
|
192
|
+
GRPC_STATS_INC_EXECUTOR_SCHEDULED_LONG_ITEMS(exec_ctx);
|
172
193
|
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
194
|
+
do {
|
195
|
+
retry_push = false;
|
196
|
+
size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads);
|
197
|
+
if (cur_thread_count == 0) {
|
198
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
199
|
+
#ifndef NDEBUG
|
200
|
+
gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p (created %s:%d) inline",
|
201
|
+
closure, closure->file_created, closure->line_created);
|
202
|
+
#else
|
203
|
+
gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p inline", closure);
|
204
|
+
#endif
|
205
|
+
}
|
206
|
+
grpc_closure_list_append(&exec_ctx->closure_list, closure, error);
|
207
|
+
return;
|
187
208
|
}
|
188
|
-
|
189
|
-
|
209
|
+
thread_state *ts = (thread_state *)gpr_tls_get(&g_this_thread_state);
|
210
|
+
if (ts == NULL) {
|
211
|
+
ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)];
|
212
|
+
} else {
|
213
|
+
GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx);
|
214
|
+
}
|
215
|
+
thread_state *orig_ts = ts;
|
216
|
+
|
217
|
+
bool try_new_thread;
|
218
|
+
for (;;) {
|
219
|
+
if (GRPC_TRACER_ON(executor_trace)) {
|
220
|
+
#ifndef NDEBUG
|
221
|
+
gpr_log(
|
222
|
+
GPR_DEBUG,
|
223
|
+
"EXECUTOR: try to schedule %p (%s) (created %s:%d) to thread %d",
|
224
|
+
closure, is_short ? "short" : "long", closure->file_created,
|
225
|
+
closure->line_created, (int)(ts - g_thread_state));
|
226
|
+
#else
|
227
|
+
gpr_log(GPR_DEBUG, "EXECUTOR: try to schedule %p (%s) to thread %d",
|
228
|
+
closure, is_short ? "short" : "long",
|
229
|
+
(int)(ts - g_thread_state));
|
230
|
+
#endif
|
231
|
+
}
|
232
|
+
gpr_mu_lock(&ts->mu);
|
233
|
+
if (ts->queued_long_job) {
|
234
|
+
// if there's a long job queued, we never queue anything else to this
|
235
|
+
// queue (since long jobs can take 'infinite' time and we need to
|
236
|
+
// guarantee no starvation)
|
237
|
+
// ... spin through queues and try again
|
238
|
+
gpr_mu_unlock(&ts->mu);
|
239
|
+
size_t idx = (size_t)(ts - g_thread_state);
|
240
|
+
ts = &g_thread_state[(idx + 1) % cur_thread_count];
|
241
|
+
if (ts == orig_ts) {
|
242
|
+
retry_push = true;
|
243
|
+
try_new_thread = true;
|
244
|
+
break;
|
245
|
+
}
|
246
|
+
continue;
|
247
|
+
}
|
248
|
+
if (grpc_closure_list_empty(ts->elems)) {
|
249
|
+
GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx);
|
250
|
+
gpr_cv_signal(&ts->cv);
|
251
|
+
}
|
252
|
+
grpc_closure_list_append(&ts->elems, closure, error);
|
253
|
+
ts->depth++;
|
254
|
+
try_new_thread = ts->depth > MAX_DEPTH &&
|
255
|
+
cur_thread_count < g_max_threads && !ts->shutdown;
|
256
|
+
if (!is_short) ts->queued_long_job = true;
|
257
|
+
gpr_mu_unlock(&ts->mu);
|
258
|
+
break;
|
259
|
+
}
|
260
|
+
if (try_new_thread && gpr_spinlock_trylock(&g_adding_thread_lock)) {
|
261
|
+
cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads);
|
262
|
+
if (cur_thread_count < g_max_threads) {
|
263
|
+
gpr_atm_no_barrier_store(&g_cur_threads, cur_thread_count + 1);
|
264
|
+
|
265
|
+
gpr_thd_options opt = gpr_thd_options_default();
|
266
|
+
gpr_thd_options_set_joinable(&opt);
|
267
|
+
gpr_thd_new(&g_thread_state[cur_thread_count].id, executor_thread,
|
268
|
+
&g_thread_state[cur_thread_count], &opt);
|
269
|
+
}
|
270
|
+
gpr_spinlock_unlock(&g_adding_thread_lock);
|
271
|
+
}
|
272
|
+
if (retry_push) {
|
273
|
+
GRPC_STATS_INC_EXECUTOR_PUSH_RETRIES(exec_ctx);
|
274
|
+
}
|
275
|
+
} while (retry_push);
|
190
276
|
}
|
191
277
|
|
192
|
-
static
|
193
|
-
|
194
|
-
|
195
|
-
|
278
|
+
static void executor_push_short(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
|
279
|
+
grpc_error *error) {
|
280
|
+
executor_push(exec_ctx, closure, error, true);
|
281
|
+
}
|
282
|
+
|
283
|
+
static void executor_push_long(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
|
284
|
+
grpc_error *error) {
|
285
|
+
executor_push(exec_ctx, closure, error, false);
|
286
|
+
}
|
287
|
+
|
288
|
+
static const grpc_closure_scheduler_vtable executor_vtable_short = {
|
289
|
+
executor_push_short, executor_push_short, "executor"};
|
290
|
+
static grpc_closure_scheduler executor_scheduler_short = {
|
291
|
+
&executor_vtable_short};
|
292
|
+
|
293
|
+
static const grpc_closure_scheduler_vtable executor_vtable_long = {
|
294
|
+
executor_push_long, executor_push_long, "executor"};
|
295
|
+
static grpc_closure_scheduler executor_scheduler_long = {&executor_vtable_long};
|
296
|
+
|
297
|
+
grpc_closure_scheduler *grpc_executor_scheduler(
|
298
|
+
grpc_executor_job_length length) {
|
299
|
+
return length == GRPC_EXECUTOR_SHORT ? &executor_scheduler_short
|
300
|
+
: &executor_scheduler_long;
|
301
|
+
}
|
@@ -21,6 +21,11 @@
|
|
21
21
|
|
22
22
|
#include "src/core/lib/iomgr/closure.h"
|
23
23
|
|
24
|
+
typedef enum {
|
25
|
+
GRPC_EXECUTOR_SHORT,
|
26
|
+
GRPC_EXECUTOR_LONG
|
27
|
+
} grpc_executor_job_length;
|
28
|
+
|
24
29
|
/** Initialize the global executor.
|
25
30
|
*
|
26
31
|
* This mechanism is meant to outsource work (grpc_closure instances) to a
|
@@ -28,7 +33,7 @@
|
|
28
33
|
* non-blocking solution available. */
|
29
34
|
void grpc_executor_init(grpc_exec_ctx *exec_ctx);
|
30
35
|
|
31
|
-
|
36
|
+
grpc_closure_scheduler *grpc_executor_scheduler(grpc_executor_job_length);
|
32
37
|
|
33
38
|
/** Shutdown the executor, running all pending work as part of the call */
|
34
39
|
void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx);
|
@@ -0,0 +1,88 @@
|
|
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
|
+
#ifdef GRPC_POSIX_FORK
|
22
|
+
|
23
|
+
#include <string.h>
|
24
|
+
|
25
|
+
#include <grpc/fork.h>
|
26
|
+
#include <grpc/support/log.h>
|
27
|
+
#include <grpc/support/thd.h>
|
28
|
+
#include <grpc/support/useful.h>
|
29
|
+
|
30
|
+
#include "src/core/lib/iomgr/ev_posix.h"
|
31
|
+
#include "src/core/lib/iomgr/executor.h"
|
32
|
+
#include "src/core/lib/iomgr/timer_manager.h"
|
33
|
+
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
|
34
|
+
#include "src/core/lib/support/env.h"
|
35
|
+
#include "src/core/lib/support/fork.h"
|
36
|
+
#include "src/core/lib/support/thd_internal.h"
|
37
|
+
#include "src/core/lib/surface/init.h"
|
38
|
+
|
39
|
+
/*
|
40
|
+
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
|
41
|
+
* AROUND VERY SPECIFIC USE CASES.
|
42
|
+
*/
|
43
|
+
|
44
|
+
void grpc_prefork() {
|
45
|
+
if (!grpc_fork_support_enabled()) {
|
46
|
+
gpr_log(GPR_ERROR,
|
47
|
+
"Fork support not enabled; try running with the "
|
48
|
+
"environment variable GRPC_ENABLE_FORK_SUPPORT=1");
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
if (grpc_is_initialized()) {
|
52
|
+
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
53
|
+
grpc_timer_manager_set_threading(false);
|
54
|
+
grpc_executor_set_threading(&exec_ctx, false);
|
55
|
+
grpc_exec_ctx_finish(&exec_ctx);
|
56
|
+
if (!gpr_await_threads(
|
57
|
+
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
|
58
|
+
gpr_time_from_seconds(3, GPR_TIMESPAN)))) {
|
59
|
+
gpr_log(GPR_ERROR, "gRPC thread still active! Cannot fork!");
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
void grpc_postfork_parent() {
|
65
|
+
if (grpc_is_initialized()) {
|
66
|
+
grpc_timer_manager_set_threading(true);
|
67
|
+
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
68
|
+
grpc_executor_set_threading(&exec_ctx, true);
|
69
|
+
grpc_exec_ctx_finish(&exec_ctx);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
void grpc_postfork_child() {
|
74
|
+
if (grpc_is_initialized()) {
|
75
|
+
grpc_timer_manager_set_threading(true);
|
76
|
+
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
77
|
+
grpc_executor_set_threading(&exec_ctx, true);
|
78
|
+
grpc_exec_ctx_finish(&exec_ctx);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
void grpc_fork_handlers_auto_register() {
|
83
|
+
if (grpc_fork_support_enabled()) {
|
84
|
+
pthread_atfork(grpc_prefork, grpc_postfork_parent, grpc_postfork_child);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
#endif // GRPC_POSIX_FORK
|
@@ -0,0 +1,39 @@
|
|
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
|
+
#ifndef GRPC_POSIX_FORK
|
22
|
+
|
23
|
+
#include <grpc/fork.h>
|
24
|
+
#include <grpc/support/log.h>
|
25
|
+
|
26
|
+
/*
|
27
|
+
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
|
28
|
+
* AROUND VERY SPECIFIC USE CASES.
|
29
|
+
*/
|
30
|
+
|
31
|
+
void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); }
|
32
|
+
|
33
|
+
void grpc_postfork_parent() {}
|
34
|
+
|
35
|
+
void grpc_postfork_child() {}
|
36
|
+
|
37
|
+
void grpc_fork_handlers_auto_register() {}
|
38
|
+
|
39
|
+
#endif // GRPC_POSIX_FORK
|