grpc 1.3.4 → 1.4.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.

Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +581 -450
  3. data/include/grpc/census.h +49 -49
  4. data/include/grpc/grpc.h +16 -70
  5. data/include/grpc/grpc_security.h +59 -59
  6. data/include/grpc/grpc_security_constants.h +9 -9
  7. data/include/grpc/impl/codegen/atm.h +1 -1
  8. data/include/grpc/impl/codegen/atm_windows.h +4 -4
  9. data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
  10. data/include/grpc/impl/codegen/compression_types.h +4 -5
  11. data/include/grpc/impl/codegen/gpr_slice.h +5 -5
  12. data/include/grpc/impl/codegen/gpr_types.h +6 -7
  13. data/include/grpc/impl/codegen/grpc_types.h +128 -59
  14. data/include/grpc/impl/codegen/port_platform.h +6 -0
  15. data/include/grpc/impl/codegen/propagation_bits.h +2 -2
  16. data/include/grpc/impl/codegen/slice.h +13 -12
  17. data/include/grpc/impl/codegen/status.h +23 -18
  18. data/include/grpc/impl/codegen/sync.h +1 -1
  19. data/include/grpc/load_reporting.h +6 -6
  20. data/include/grpc/slice.h +47 -25
  21. data/include/grpc/slice_buffer.h +18 -14
  22. data/include/grpc/support/alloc.h +7 -7
  23. data/include/grpc/support/cmdline.h +10 -10
  24. data/include/grpc/support/cpu.h +3 -3
  25. data/include/grpc/support/histogram.h +1 -1
  26. data/include/grpc/support/host_port.h +2 -2
  27. data/include/grpc/support/log.h +9 -9
  28. data/include/grpc/support/log_windows.h +1 -1
  29. data/include/grpc/support/string_util.h +3 -3
  30. data/include/grpc/support/subprocess.h +3 -3
  31. data/include/grpc/support/sync.h +31 -31
  32. data/include/grpc/support/thd.h +11 -11
  33. data/include/grpc/support/time.h +12 -12
  34. data/include/grpc/support/tls.h +1 -1
  35. data/include/grpc/support/tls_gcc.h +2 -2
  36. data/include/grpc/support/tls_msvc.h +1 -1
  37. data/include/grpc/support/tls_pthread.h +1 -1
  38. data/include/grpc/support/useful.h +2 -2
  39. data/include/grpc/support/workaround_list.h +46 -0
  40. data/src/core/ext/census/context.c +1 -1
  41. data/src/core/ext/census/intrusive_hash_map.c +319 -0
  42. data/src/core/ext/census/intrusive_hash_map.h +167 -0
  43. data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
  44. data/src/core/ext/census/resource.c +3 -1
  45. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  46. data/src/core/ext/filters/client_channel/client_channel.c +173 -103
  47. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  48. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  49. data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
  50. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  51. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  52. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
  53. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  54. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  55. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
  56. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
  57. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  58. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  59. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  60. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
  61. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  62. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  63. data/src/core/ext/filters/client_channel/parse_address.c +90 -59
  64. data/src/core/ext/filters/client_channel/parse_address.h +17 -8
  65. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
  66. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
  67. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
  68. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  69. data/src/core/ext/filters/client_channel/subchannel.c +20 -17
  70. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  71. data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
  72. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  73. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  74. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  75. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  76. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  77. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  78. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  79. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  80. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  81. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  82. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  83. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  84. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  85. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  86. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  87. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  88. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
  89. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
  90. data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
  91. data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
  92. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
  94. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  95. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  96. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
  97. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  98. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  99. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  100. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  101. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  102. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  103. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  104. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  105. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  107. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  108. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  109. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  110. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  111. data/src/core/lib/channel/channel_args.c +30 -9
  112. data/src/core/lib/channel/channel_args.h +5 -1
  113. data/src/core/lib/channel/channel_stack.c +1 -1
  114. data/src/core/lib/channel/channel_stack.h +2 -2
  115. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  116. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  117. data/src/core/lib/channel/connected_channel.c +3 -1
  118. data/src/core/lib/channel/context.h +2 -2
  119. data/src/core/lib/compression/message_compress.c +2 -2
  120. data/src/core/lib/debug/trace.c +13 -6
  121. data/src/core/lib/debug/trace.h +27 -1
  122. data/src/core/lib/http/httpcli.c +1 -1
  123. data/src/core/lib/http/httpcli_security_connector.c +9 -11
  124. data/src/core/lib/http/parser.c +2 -2
  125. data/src/core/lib/http/parser.h +2 -1
  126. data/src/core/lib/iomgr/combiner.c +6 -6
  127. data/src/core/lib/iomgr/combiner.h +2 -1
  128. data/src/core/lib/iomgr/error.c +12 -5
  129. data/src/core/lib/iomgr/error.h +13 -13
  130. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  131. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  132. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  133. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  134. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  135. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  136. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  137. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  138. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
  139. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  140. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  141. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  142. data/src/core/lib/iomgr/ev_posix.c +22 -8
  143. data/src/core/lib/iomgr/ev_posix.h +4 -3
  144. data/src/core/lib/iomgr/ev_windows.c +43 -0
  145. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  146. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  147. data/src/core/lib/iomgr/iomgr.c +4 -0
  148. data/src/core/lib/iomgr/iomgr.h +3 -0
  149. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  150. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  151. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  152. data/src/core/lib/iomgr/pollset.h +2 -5
  153. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  154. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  155. data/src/core/lib/iomgr/resource_quota.c +9 -8
  156. data/src/core/lib/iomgr/resource_quota.h +2 -1
  157. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  158. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  159. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  160. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  161. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  162. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  163. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  164. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  165. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  166. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  167. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  168. data/src/core/lib/iomgr/timer_generic.c +24 -25
  169. data/src/core/lib/iomgr/timer_manager.c +276 -0
  170. data/src/core/lib/iomgr/timer_manager.h +52 -0
  171. data/src/core/lib/iomgr/timer_uv.c +6 -0
  172. data/src/core/lib/iomgr/udp_server.c +42 -9
  173. data/src/core/lib/iomgr/udp_server.h +3 -1
  174. data/src/core/lib/security/credentials/credentials.c +0 -1
  175. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  176. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  177. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  178. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  179. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  180. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  181. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  182. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  183. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  184. data/src/core/lib/security/transport/security_connector.c +45 -57
  185. data/src/core/lib/security/transport/security_connector.h +10 -14
  186. data/src/core/lib/security/transport/security_handshaker.c +123 -97
  187. data/src/core/lib/slice/b64.c +1 -1
  188. data/src/core/lib/slice/percent_encoding.c +3 -3
  189. data/src/core/lib/slice/slice.c +66 -33
  190. data/src/core/lib/slice/slice_buffer.c +25 -6
  191. data/src/core/lib/slice/slice_hash_table.c +33 -35
  192. data/src/core/lib/slice/slice_hash_table.h +7 -12
  193. data/src/core/lib/support/atomic.h +45 -0
  194. data/src/core/lib/support/atomic_with_atm.h +70 -0
  195. data/src/core/lib/support/atomic_with_std.h +48 -0
  196. data/src/core/lib/support/avl.c +14 -14
  197. data/src/core/lib/support/cmdline.c +3 -3
  198. data/src/core/lib/support/histogram.c +2 -2
  199. data/src/core/lib/support/host_port.c +1 -1
  200. data/src/core/lib/support/memory.h +74 -0
  201. data/src/core/lib/support/mpscq.c +36 -2
  202. data/src/core/lib/support/mpscq.h +28 -1
  203. data/src/core/lib/support/stack_lockfree.c +3 -36
  204. data/src/core/lib/support/string.c +12 -12
  205. data/src/core/lib/support/string_posix.c +1 -1
  206. data/src/core/lib/support/subprocess_posix.c +2 -2
  207. data/src/core/lib/support/thd_posix.c +1 -1
  208. data/src/core/lib/support/time_posix.c +8 -0
  209. data/src/core/lib/support/tmpfile_posix.c +10 -10
  210. data/src/core/lib/surface/alarm.c +3 -1
  211. data/src/core/lib/surface/api_trace.c +2 -1
  212. data/src/core/lib/surface/api_trace.h +2 -2
  213. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  214. data/src/core/lib/surface/call.c +65 -22
  215. data/src/core/lib/surface/call.h +4 -2
  216. data/src/core/lib/surface/channel_init.c +2 -19
  217. data/src/core/lib/surface/channel_stack_type.c +18 -0
  218. data/src/core/lib/surface/channel_stack_type.h +2 -0
  219. data/src/core/lib/surface/completion_queue.c +694 -247
  220. data/src/core/lib/surface/completion_queue.h +30 -13
  221. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  222. data/src/core/lib/surface/init.c +1 -52
  223. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  224. data/src/core/lib/surface/server.c +79 -110
  225. data/src/core/lib/surface/server.h +2 -1
  226. data/src/core/lib/surface/version.c +2 -2
  227. data/src/core/lib/transport/bdp_estimator.c +25 -9
  228. data/src/core/lib/transport/bdp_estimator.h +7 -1
  229. data/src/core/lib/transport/byte_stream.c +23 -9
  230. data/src/core/lib/transport/byte_stream.h +15 -6
  231. data/src/core/lib/transport/connectivity_state.c +6 -6
  232. data/src/core/lib/transport/connectivity_state.h +2 -1
  233. data/src/core/lib/transport/service_config.c +6 -13
  234. data/src/core/lib/transport/service_config.h +2 -2
  235. data/src/core/lib/transport/static_metadata.c +403 -389
  236. data/src/core/lib/transport/static_metadata.h +127 -114
  237. data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
  238. data/src/core/tsi/fake_transport_security.c +5 -4
  239. data/src/core/tsi/ssl_transport_security.c +71 -82
  240. data/src/core/tsi/ssl_transport_security.h +39 -61
  241. data/src/core/tsi/transport_security.c +83 -2
  242. data/src/core/tsi/transport_security.h +27 -2
  243. data/src/core/tsi/transport_security_adapter.c +236 -0
  244. data/src/core/tsi/transport_security_adapter.h +62 -0
  245. data/src/core/tsi/transport_security_interface.h +179 -66
  246. data/src/ruby/ext/grpc/extconf.rb +2 -1
  247. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  248. data/src/ruby/ext/grpc/rb_call.c +56 -48
  249. data/src/ruby/ext/grpc/rb_call.h +3 -4
  250. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  251. data/src/ruby/ext/grpc/rb_channel.c +2 -3
  252. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  253. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  254. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  255. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  256. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  257. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  258. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  259. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  260. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
  261. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
  262. data/src/ruby/ext/grpc/rb_server.c +26 -28
  263. data/src/ruby/lib/grpc/grpc.rb +1 -1
  264. data/src/ruby/lib/grpc/version.rb +1 -1
  265. data/third_party/cares/config_linux/ares_config.h +36 -2
  266. data/third_party/zlib/adler32.c +14 -7
  267. data/third_party/zlib/compress.c +24 -18
  268. data/third_party/zlib/crc32.c +29 -12
  269. data/third_party/zlib/deflate.c +499 -303
  270. data/third_party/zlib/deflate.h +19 -16
  271. data/third_party/zlib/gzguts.h +16 -7
  272. data/third_party/zlib/gzlib.c +17 -14
  273. data/third_party/zlib/gzread.c +108 -48
  274. data/third_party/zlib/gzwrite.c +210 -122
  275. data/third_party/zlib/infback.c +2 -2
  276. data/third_party/zlib/inffast.c +34 -51
  277. data/third_party/zlib/inflate.c +86 -37
  278. data/third_party/zlib/inflate.h +7 -4
  279. data/third_party/zlib/inftrees.c +12 -14
  280. data/third_party/zlib/trees.c +38 -61
  281. data/third_party/zlib/uncompr.c +66 -32
  282. data/third_party/zlib/zconf.h +32 -9
  283. data/third_party/zlib/zlib.h +298 -154
  284. data/third_party/zlib/zutil.c +25 -24
  285. data/third_party/zlib/zutil.h +35 -17
  286. metadata +63 -30
@@ -37,18 +37,25 @@
37
37
  /* Internal API for completion queues */
38
38
 
39
39
  #include <grpc/grpc.h>
40
+ #include "src/core/lib/debug/trace.h"
40
41
  #include "src/core/lib/iomgr/pollset.h"
41
42
 
42
43
  /* These trace flags default to 1. The corresponding lines are only traced
43
44
  if grpc_api_trace is also truthy */
44
- extern int grpc_cq_pluck_trace;
45
- extern int grpc_cq_event_timeout_trace;
46
- extern int grpc_trace_operation_failures;
45
+ extern grpc_tracer_flag grpc_cq_pluck_trace;
46
+ extern grpc_tracer_flag grpc_cq_event_timeout_trace;
47
+ extern grpc_tracer_flag grpc_trace_operation_failures;
47
48
  #ifndef NDEBUG
48
- extern int grpc_trace_pending_tags;
49
+ extern grpc_tracer_flag grpc_trace_pending_tags;
50
+ #endif
51
+
52
+ #ifdef __cplusplus
53
+ extern "C" {
49
54
  #endif
50
55
 
51
56
  typedef struct grpc_cq_completion {
57
+ gpr_mpscq_node node;
58
+
52
59
  /** user supplied tag */
53
60
  void *tag;
54
61
  /** done callback - called when this queue element is no longer
@@ -65,17 +72,17 @@ typedef struct grpc_cq_completion {
65
72
  #ifdef GRPC_CQ_REF_COUNT_DEBUG
66
73
  void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
67
74
  const char *file, int line);
68
- void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason,
69
- const char *file, int line);
75
+ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc,
76
+ const char *reason, const char *file, int line);
70
77
  #define GRPC_CQ_INTERNAL_REF(cc, reason) \
71
78
  grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__)
72
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) \
73
- grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__)
79
+ #define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) \
80
+ grpc_cq_internal_unref(ec, cc, reason, __FILE__, __LINE__)
74
81
  #else
75
82
  void grpc_cq_internal_ref(grpc_completion_queue *cc);
76
- void grpc_cq_internal_unref(grpc_completion_queue *cc);
83
+ void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc);
77
84
  #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc)
78
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc)
85
+ #define GRPC_CQ_INTERNAL_UNREF(ec, cc, reason) grpc_cq_internal_unref(ec, cc)
79
86
  #endif
80
87
 
81
88
  /* Flag that an operation is beginning: the completion channel will not finish
@@ -94,9 +101,19 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc,
94
101
  grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc);
95
102
  grpc_completion_queue *grpc_cq_from_pollset(grpc_pollset *ps);
96
103
 
97
- void grpc_cq_mark_non_listening_server_cq(grpc_completion_queue *cc);
98
- bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc);
99
104
  void grpc_cq_mark_server_cq(grpc_completion_queue *cc);
100
- int grpc_cq_is_server_cq(grpc_completion_queue *cc);
105
+ bool grpc_cq_is_server_cq(grpc_completion_queue *cc);
106
+ bool grpc_cq_can_listen(grpc_completion_queue *cc);
107
+
108
+ grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cc);
109
+
110
+ int grpc_get_cq_poll_num(grpc_completion_queue *cc);
111
+
112
+ grpc_completion_queue *grpc_completion_queue_create_internal(
113
+ grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type);
114
+
115
+ #ifdef __cplusplus
116
+ }
117
+ #endif
101
118
 
102
119
  #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */
@@ -36,12 +36,15 @@
36
36
 
37
37
  #include <grpc/support/log.h>
38
38
 
39
- /* TODO (sreek) - Currently this does not use the attributes arg. This will be
40
- added in a future PR */
39
+ /*
40
+ * == Default completion queue factory implementation ==
41
+ */
42
+
41
43
  static grpc_completion_queue* default_create(
42
44
  const grpc_completion_queue_factory* factory,
43
- const grpc_completion_queue_attributes* attributes) {
44
- return grpc_completion_queue_create(NULL);
45
+ const grpc_completion_queue_attributes* attr) {
46
+ return grpc_completion_queue_create_internal(attr->cq_completion_type,
47
+ attr->cq_polling_type);
45
48
  }
46
49
 
47
50
  static grpc_completion_queue_factory_vtable default_vtable = {default_create};
@@ -49,19 +52,24 @@ static grpc_completion_queue_factory_vtable default_vtable = {default_create};
49
52
  static const grpc_completion_queue_factory g_default_cq_factory = {
50
53
  "Default Factory", NULL, &default_vtable};
51
54
 
55
+ /*
56
+ * == Completion queue factory APIs
57
+ */
58
+
52
59
  const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup(
53
60
  const grpc_completion_queue_attributes* attributes) {
54
- /* As we add more fields to grpc_completion_queue_attributes, we may have to
55
- change this assert to:
56
- GPR_ASSERT (attributes->version >= 1 &&
57
- attributes->version <= GRPC_CQ_CURRENT_VERSION) */
58
- GPR_ASSERT(attributes->version == 1);
61
+ GPR_ASSERT(attributes->version >= 1 &&
62
+ attributes->version <= GRPC_CQ_CURRENT_VERSION);
59
63
 
60
64
  /* The default factory can handle version 1 of the attributes structure. We
61
65
  may have to change this as more fields are added to the structure */
62
66
  return &g_default_cq_factory;
63
67
  }
64
68
 
69
+ /*
70
+ * == Completion queue creation APIs ==
71
+ */
72
+
65
73
  grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) {
66
74
  GPR_ASSERT(!reserved);
67
75
  grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT,
@@ -75,3 +83,10 @@ grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) {
75
83
  GRPC_CQ_DEFAULT_POLLING};
76
84
  return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr);
77
85
  }
86
+
87
+ grpc_completion_queue* grpc_completion_queue_create(
88
+ const grpc_completion_queue_factory* factory,
89
+ const grpc_completion_queue_attributes* attr, void* reserved) {
90
+ GPR_ASSERT(!reserved);
91
+ return factory->vtable->create(factory, attr);
92
+ }
@@ -41,13 +41,8 @@
41
41
  #include <grpc/support/log.h>
42
42
  #include <grpc/support/time.h>
43
43
  #include "src/core/lib/channel/channel_stack.h"
44
- #include "src/core/lib/channel/compress_filter.h"
45
44
  #include "src/core/lib/channel/connected_channel.h"
46
- #include "src/core/lib/channel/deadline_filter.h"
47
45
  #include "src/core/lib/channel/handshaker_registry.h"
48
- #include "src/core/lib/channel/http_client_filter.h"
49
- #include "src/core/lib/channel/http_server_filter.h"
50
- #include "src/core/lib/channel/message_size_filter.h"
51
46
  #include "src/core/lib/debug/trace.h"
52
47
  #include "src/core/lib/http/parser.h"
53
48
  #include "src/core/lib/iomgr/combiner.h"
@@ -95,57 +90,13 @@ static bool prepend_filter(grpc_exec_ctx *exec_ctx,
95
90
  builder, (const grpc_channel_filter *)arg, NULL, NULL);
96
91
  }
97
92
 
98
- static bool maybe_add_http_filter(grpc_exec_ctx *exec_ctx,
99
- grpc_channel_stack_builder *builder,
100
- void *arg) {
101
- grpc_transport *t = grpc_channel_stack_builder_get_transport(builder);
102
- if (t && strstr(t->vtable->name, "http")) {
103
- return grpc_channel_stack_builder_prepend_filter(
104
- builder, (const grpc_channel_filter *)arg, NULL, NULL);
105
- }
106
- return true;
107
- }
108
-
109
93
  static void register_builtin_channel_init() {
110
- grpc_channel_init_register_stage(
111
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
112
- prepend_filter, (void *)&grpc_client_deadline_filter);
113
- grpc_channel_init_register_stage(
114
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
115
- (void *)&grpc_server_deadline_filter);
116
- grpc_channel_init_register_stage(
117
- GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
118
- prepend_filter, (void *)&grpc_message_size_filter);
119
- grpc_channel_init_register_stage(
120
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
121
- prepend_filter, (void *)&grpc_message_size_filter);
122
- grpc_channel_init_register_stage(
123
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
124
- (void *)&grpc_message_size_filter);
125
- grpc_channel_init_register_stage(
126
- GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
127
- (void *)&grpc_compress_filter);
128
- grpc_channel_init_register_stage(
129
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
130
- prepend_filter, (void *)&grpc_compress_filter);
131
- grpc_channel_init_register_stage(
132
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
133
- (void *)&grpc_compress_filter);
134
- grpc_channel_init_register_stage(
135
- GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
136
- maybe_add_http_filter, (void *)&grpc_http_client_filter);
137
94
  grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
138
95
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
139
96
  grpc_add_connected_filter, NULL);
140
- grpc_channel_init_register_stage(
141
- GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
142
- maybe_add_http_filter, (void *)&grpc_http_client_filter);
143
97
  grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
144
98
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
145
99
  grpc_add_connected_filter, NULL);
146
- grpc_channel_init_register_stage(
147
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
148
- maybe_add_http_filter, (void *)&grpc_http_server_filter);
149
100
  grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
150
101
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
151
102
  grpc_add_connected_filter, NULL);
@@ -189,16 +140,13 @@ void grpc_init(void) {
189
140
  grpc_register_tracer("channel_stack_builder",
190
141
  &grpc_trace_channel_stack_builder);
191
142
  grpc_register_tracer("http1", &grpc_http1_trace);
192
- grpc_register_tracer("compression", &grpc_compression_trace);
193
143
  grpc_register_tracer("queue_pluck", &grpc_cq_pluck_trace);
194
144
  grpc_register_tracer("combiner", &grpc_combiner_trace);
195
145
  grpc_register_tracer("server_channel", &grpc_server_channel_trace);
196
146
  grpc_register_tracer("bdp_estimator", &grpc_bdp_estimator_trace);
197
147
  // Default pluck trace to 1
198
- grpc_cq_pluck_trace = 1;
199
148
  grpc_register_tracer("queue_timeout", &grpc_cq_event_timeout_trace);
200
149
  // Default timeout trace to 1
201
- grpc_cq_event_timeout_trace = 1;
202
150
  grpc_register_tracer("op_failure", &grpc_trace_operation_failures);
203
151
  grpc_register_tracer("resource_quota", &grpc_resource_quota_trace);
204
152
  grpc_register_tracer("call_error", &grpc_call_error_trace);
@@ -223,6 +171,7 @@ void grpc_init(void) {
223
171
  grpc_tracer_init("GRPC_TRACE");
224
172
  /* no more changes to channel init pipelines */
225
173
  grpc_channel_init_finalize();
174
+ grpc_iomgr_start();
226
175
  }
227
176
  gpr_mu_unlock(&g_init_mu);
228
177
  GRPC_API_TRACE("grpc_init(void)", 0, ());
@@ -31,39 +31,50 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/lib/surface/lame_client.h"
35
-
36
34
  #include <grpc/grpc.h>
37
35
 
38
36
  #include <string.h>
39
37
 
40
38
  #include <grpc/support/alloc.h>
41
39
  #include <grpc/support/log.h>
40
+
41
+ #include "src/core/lib/support/atomic.h"
42
+
43
+ extern "C" {
42
44
  #include "src/core/lib/channel/channel_stack.h"
43
45
  #include "src/core/lib/support/string.h"
44
46
  #include "src/core/lib/surface/api_trace.h"
45
47
  #include "src/core/lib/surface/call.h"
46
48
  #include "src/core/lib/surface/channel.h"
49
+ #include "src/core/lib/surface/lame_client.h"
47
50
  #include "src/core/lib/transport/static_metadata.h"
51
+ }
48
52
 
49
- typedef struct {
53
+ namespace grpc_core {
54
+
55
+ namespace {
56
+
57
+ struct CallData {
50
58
  grpc_linked_mdelem status;
51
59
  grpc_linked_mdelem details;
52
- gpr_atm filled_metadata;
53
- } call_data;
60
+ grpc_core::atomic<bool> filled_metadata;
61
+ };
54
62
 
55
- typedef struct {
63
+ struct ChannelData {
56
64
  grpc_status_code error_code;
57
65
  const char *error_message;
58
- } channel_data;
66
+ };
59
67
 
60
68
  static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
61
69
  grpc_metadata_batch *mdb) {
62
- call_data *calld = elem->call_data;
63
- if (!gpr_atm_no_barrier_cas(&calld->filled_metadata, 0, 1)) {
70
+ CallData *calld = static_cast<CallData *>(elem->call_data);
71
+ bool expected = false;
72
+ if (!calld->filled_metadata.compare_exchange_strong(
73
+ expected, true, grpc_core::memory_order_relaxed,
74
+ grpc_core::memory_order_relaxed)) {
64
75
  return;
65
76
  }
66
- channel_data *chand = elem->channel_data;
77
+ ChannelData *chand = static_cast<ChannelData *>(elem->channel_data);
67
78
  char tmp[GPR_LTOA_MIN_BUFSIZE];
68
79
  gpr_ltoa(chand->error_code, tmp);
69
80
  calld->status.md = grpc_mdelem_from_slices(
@@ -83,7 +94,6 @@ static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
83
94
  static void lame_start_transport_stream_op_batch(
84
95
  grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
85
96
  grpc_transport_stream_op_batch *op) {
86
- GRPC_CALL_LOG_OP(GPR_INFO, elem, op);
87
97
  if (op->recv_initial_metadata) {
88
98
  fill_metadata(exec_ctx, elem,
89
99
  op->payload->recv_initial_metadata.recv_initial_metadata);
@@ -127,8 +137,6 @@ static void lame_start_transport_op(grpc_exec_ctx *exec_ctx,
127
137
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
128
138
  grpc_call_element *elem,
129
139
  const grpc_call_element_args *args) {
130
- call_data *calld = elem->call_data;
131
- gpr_atm_no_barrier_store(&calld->filled_metadata, 0);
132
140
  return GRPC_ERROR_NONE;
133
141
  }
134
142
 
@@ -149,18 +157,22 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
149
157
  static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
150
158
  grpc_channel_element *elem) {}
151
159
 
152
- const grpc_channel_filter grpc_lame_filter = {
153
- lame_start_transport_stream_op_batch,
154
- lame_start_transport_op,
155
- sizeof(call_data),
156
- init_call_elem,
160
+ } // namespace
161
+
162
+ } // namespace grpc_core
163
+
164
+ extern "C" const grpc_channel_filter grpc_lame_filter = {
165
+ grpc_core::lame_start_transport_stream_op_batch,
166
+ grpc_core::lame_start_transport_op,
167
+ sizeof(grpc_core::CallData),
168
+ grpc_core::init_call_elem,
157
169
  grpc_call_stack_ignore_set_pollset_or_pollset_set,
158
- destroy_call_elem,
159
- sizeof(channel_data),
160
- init_channel_elem,
161
- destroy_channel_elem,
162
- lame_get_peer,
163
- lame_get_channel_info,
170
+ grpc_core::destroy_call_elem,
171
+ sizeof(grpc_core::ChannelData),
172
+ grpc_core::init_channel_elem,
173
+ grpc_core::destroy_channel_elem,
174
+ grpc_core::lame_get_peer,
175
+ grpc_core::lame_get_channel_info,
164
176
  "lame-client",
165
177
  };
166
178
 
@@ -171,7 +183,6 @@ grpc_channel *grpc_lame_client_channel_create(const char *target,
171
183
  const char *error_message) {
172
184
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
173
185
  grpc_channel_element *elem;
174
- channel_data *chand;
175
186
  grpc_channel *channel = grpc_channel_create(&exec_ctx, target, NULL,
176
187
  GRPC_CLIENT_LAME_CHANNEL, NULL);
177
188
  elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
@@ -180,7 +191,7 @@ grpc_channel *grpc_lame_client_channel_create(const char *target,
180
191
  "error_message=%s)",
181
192
  3, (target, (int)error_code, error_message));
182
193
  GPR_ASSERT(elem->filter == &grpc_lame_filter);
183
- chand = (channel_data *)elem->channel_data;
194
+ auto chand = static_cast<grpc_core::ChannelData *>(elem->channel_data);
184
195
  chand->error_code = error_code;
185
196
  chand->error_message = error_message;
186
197
  grpc_exec_ctx_finish(&exec_ctx);
@@ -44,9 +44,11 @@
44
44
 
45
45
  #include "src/core/lib/channel/channel_args.h"
46
46
  #include "src/core/lib/channel/connected_channel.h"
47
+ #include "src/core/lib/iomgr/executor.h"
47
48
  #include "src/core/lib/iomgr/iomgr.h"
48
49
  #include "src/core/lib/slice/slice_internal.h"
49
- #include "src/core/lib/support/stack_lockfree.h"
50
+ #include "src/core/lib/support/mpscq.h"
51
+ #include "src/core/lib/support/spinlock.h"
50
52
  #include "src/core/lib/support/string.h"
51
53
  #include "src/core/lib/surface/api_trace.h"
52
54
  #include "src/core/lib/surface/call.h"
@@ -72,9 +74,10 @@ typedef struct registered_method registered_method;
72
74
 
73
75
  typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type;
74
76
 
75
- int grpc_server_channel_trace = 0;
77
+ grpc_tracer_flag grpc_server_channel_trace = GRPC_TRACER_INITIALIZER(false);
76
78
 
77
79
  typedef struct requested_call {
80
+ gpr_mpscq_node request_link; /* must be first */
78
81
  requested_call_type type;
79
82
  size_t cq_idx;
80
83
  void *tag;
@@ -174,7 +177,7 @@ struct request_matcher {
174
177
  grpc_server *server;
175
178
  call_data *pending_head;
176
179
  call_data *pending_tail;
177
- gpr_stack_lockfree **requests_per_cq;
180
+ gpr_locked_mpscq *requests_per_cq;
178
181
  };
179
182
 
180
183
  struct registered_method {
@@ -211,14 +214,14 @@ struct grpc_server {
211
214
  gpr_mu mu_global; /* mutex for server and channel state */
212
215
  gpr_mu mu_call; /* mutex for call-specific state */
213
216
 
217
+ /* startup synchronization: flag is protected by mu_global, signals whether
218
+ we are doing the listener start routine or not */
219
+ bool starting;
220
+ gpr_cv starting_cv;
221
+
214
222
  registered_method *registered_methods;
215
223
  /** one request matcher for unregistered methods */
216
224
  request_matcher unregistered_request_matcher;
217
- /** free list of available requested_calls_per_cq indices */
218
- gpr_stack_lockfree **request_freelist_per_cq;
219
- /** requested call backing data */
220
- requested_call **requested_calls_per_cq;
221
- int max_requested_calls_per_cq;
222
225
 
223
226
  gpr_atm shutdown_flag;
224
227
  uint8_t shutdown_published;
@@ -318,28 +321,27 @@ static void channel_broadcaster_shutdown(grpc_exec_ctx *exec_ctx,
318
321
  * request_matcher
319
322
  */
320
323
 
321
- static void request_matcher_init(request_matcher *rm, size_t entries,
322
- grpc_server *server) {
324
+ static void request_matcher_init(request_matcher *rm, grpc_server *server) {
323
325
  memset(rm, 0, sizeof(*rm));
324
326
  rm->server = server;
325
327
  rm->requests_per_cq =
326
328
  gpr_malloc(sizeof(*rm->requests_per_cq) * server->cq_count);
327
329
  for (size_t i = 0; i < server->cq_count; i++) {
328
- rm->requests_per_cq[i] = gpr_stack_lockfree_create(entries);
330
+ gpr_locked_mpscq_init(&rm->requests_per_cq[i]);
329
331
  }
330
332
  }
331
333
 
332
334
  static void request_matcher_destroy(request_matcher *rm) {
333
335
  for (size_t i = 0; i < rm->server->cq_count; i++) {
334
- GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests_per_cq[i]) == -1);
335
- gpr_stack_lockfree_destroy(rm->requests_per_cq[i]);
336
+ GPR_ASSERT(gpr_locked_mpscq_pop(&rm->requests_per_cq[i]) == NULL);
337
+ gpr_locked_mpscq_destroy(&rm->requests_per_cq[i]);
336
338
  }
337
339
  gpr_free(rm->requests_per_cq);
338
340
  }
339
341
 
340
342
  static void kill_zombie(grpc_exec_ctx *exec_ctx, void *elem,
341
343
  grpc_error *error) {
342
- grpc_call_destroy(grpc_call_from_top_element(elem));
344
+ grpc_call_unref(grpc_call_from_top_element(elem));
343
345
  }
344
346
 
345
347
  static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx,
@@ -362,13 +364,17 @@ static void request_matcher_kill_requests(grpc_exec_ctx *exec_ctx,
362
364
  grpc_server *server,
363
365
  request_matcher *rm,
364
366
  grpc_error *error) {
365
- int request_id;
367
+ requested_call *rc;
366
368
  for (size_t i = 0; i < server->cq_count; i++) {
367
- while ((request_id = gpr_stack_lockfree_pop(rm->requests_per_cq[i])) !=
368
- -1) {
369
- fail_call(exec_ctx, server, i,
370
- &server->requested_calls_per_cq[i][request_id],
371
- GRPC_ERROR_REF(error));
369
+ /* Here we know:
370
+ 1. no requests are being added (since the server is shut down)
371
+ 2. no other threads are pulling (since the shut down process is single
372
+ threaded)
373
+ So, we can ignore the queue lock and just pop, with the guarantee that a
374
+ NULL returned here truly means that the queue is empty */
375
+ while ((rc = (requested_call *)gpr_mpscq_pop(
376
+ &rm->requests_per_cq[i].queue)) != NULL) {
377
+ fail_call(exec_ctx, server, i, rc, GRPC_ERROR_REF(error));
372
378
  }
373
379
  }
374
380
  GRPC_ERROR_UNREF(error);
@@ -388,6 +394,7 @@ static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) {
388
394
  grpc_channel_args_destroy(exec_ctx, server->channel_args);
389
395
  gpr_mu_destroy(&server->mu_global);
390
396
  gpr_mu_destroy(&server->mu_call);
397
+ gpr_cv_destroy(&server->starting_cv);
391
398
  while ((rm = server->registered_methods) != NULL) {
392
399
  server->registered_methods = rm->next;
393
400
  if (server->started) {
@@ -401,14 +408,8 @@ static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) {
401
408
  request_matcher_destroy(&server->unregistered_request_matcher);
402
409
  }
403
410
  for (i = 0; i < server->cq_count; i++) {
404
- GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server");
405
- if (server->started) {
406
- gpr_stack_lockfree_destroy(server->request_freelist_per_cq[i]);
407
- gpr_free(server->requested_calls_per_cq[i]);
408
- }
411
+ GRPC_CQ_INTERNAL_UNREF(exec_ctx, server->cqs[i], "server");
409
412
  }
410
- gpr_free(server->request_freelist_per_cq);
411
- gpr_free(server->requested_calls_per_cq);
412
413
  gpr_free(server->cqs);
413
414
  gpr_free(server->pollsets);
414
415
  gpr_free(server->shutdown_tags);
@@ -449,7 +450,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
449
450
  grpc_closure_init(&chand->finish_destroy_channel_closure,
450
451
  finish_destroy_channel, chand, grpc_schedule_on_exec_ctx);
451
452
 
452
- if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) {
453
+ if (GRPC_TRACER_ON(grpc_server_channel_trace) && error != GRPC_ERROR_NONE) {
453
454
  const char *msg = grpc_error_string(error);
454
455
  gpr_log(GPR_INFO, "Disconnected client: %s", msg);
455
456
  }
@@ -466,21 +467,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
466
467
 
467
468
  static void done_request_event(grpc_exec_ctx *exec_ctx, void *req,
468
469
  grpc_cq_completion *c) {
469
- requested_call *rc = req;
470
- grpc_server *server = rc->server;
471
-
472
- if (rc >= server->requested_calls_per_cq[rc->cq_idx] &&
473
- rc < server->requested_calls_per_cq[rc->cq_idx] +
474
- server->max_requested_calls_per_cq) {
475
- GPR_ASSERT(rc - server->requested_calls_per_cq[rc->cq_idx] <= INT_MAX);
476
- gpr_stack_lockfree_push(
477
- server->request_freelist_per_cq[rc->cq_idx],
478
- (int)(rc - server->requested_calls_per_cq[rc->cq_idx]));
479
- } else {
480
- gpr_free(req);
481
- }
482
-
483
- server_unref(exec_ctx, server);
470
+ gpr_free(req);
484
471
  }
485
472
 
486
473
  static void publish_call(grpc_exec_ctx *exec_ctx, grpc_server *server,
@@ -509,10 +496,6 @@ static void publish_call(grpc_exec_ctx *exec_ctx, grpc_server *server,
509
496
  GPR_UNREACHABLE_CODE(return );
510
497
  }
511
498
 
512
- grpc_call_element *elem =
513
- grpc_call_stack_element(grpc_call_get_call_stack(call), 0);
514
- channel_data *chand = elem->channel_data;
515
- server_ref(chand->server);
516
499
  grpc_cq_end_op(exec_ctx, calld->cq_new, rc->tag, GRPC_ERROR_NONE,
517
500
  done_request_event, rc, &rc->completion);
518
501
  }
@@ -540,15 +523,15 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg,
540
523
 
541
524
  for (size_t i = 0; i < server->cq_count; i++) {
542
525
  size_t cq_idx = (chand->cq_idx + i) % server->cq_count;
543
- int request_id = gpr_stack_lockfree_pop(rm->requests_per_cq[cq_idx]);
544
- if (request_id == -1) {
526
+ requested_call *rc =
527
+ (requested_call *)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]);
528
+ if (rc == NULL) {
545
529
  continue;
546
530
  } else {
547
531
  gpr_mu_lock(&calld->mu_state);
548
532
  calld->state = ACTIVATED;
549
533
  gpr_mu_unlock(&calld->mu_state);
550
- publish_call(exec_ctx, server, calld, cq_idx,
551
- &server->requested_calls_per_cq[cq_idx][request_id]);
534
+ publish_call(exec_ctx, server, calld, cq_idx, rc);
552
535
  return; /* early out */
553
536
  }
554
537
  }
@@ -974,7 +957,7 @@ const grpc_channel_filter grpc_server_top_filter = {
974
957
 
975
958
  static void register_completion_queue(grpc_server *server,
976
959
  grpc_completion_queue *cq,
977
- bool is_non_listening, void *reserved) {
960
+ void *reserved) {
978
961
  size_t i, n;
979
962
  GPR_ASSERT(!reserved);
980
963
  for (i = 0; i < server->cq_count; i++) {
@@ -983,10 +966,6 @@ static void register_completion_queue(grpc_server *server,
983
966
 
984
967
  grpc_cq_mark_server_cq(cq);
985
968
 
986
- if (is_non_listening) {
987
- grpc_cq_mark_non_listening_server_cq(cq);
988
- }
989
-
990
969
  GRPC_CQ_INTERNAL_REF(cq, "server");
991
970
  n = server->cq_count++;
992
971
  server->cqs = gpr_realloc(server->cqs,
@@ -1000,16 +979,16 @@ void grpc_server_register_completion_queue(grpc_server *server,
1000
979
  GRPC_API_TRACE(
1001
980
  "grpc_server_register_completion_queue(server=%p, cq=%p, reserved=%p)", 3,
1002
981
  (server, cq, reserved));
1003
- register_completion_queue(server, cq, false, reserved);
1004
- }
1005
982
 
1006
- void grpc_server_register_non_listening_completion_queue(
1007
- grpc_server *server, grpc_completion_queue *cq, void *reserved) {
1008
- GRPC_API_TRACE(
1009
- "grpc_server_register_non_listening_completion_queue(server=%p, cq=%p, "
1010
- "reserved=%p)",
1011
- 3, (server, cq, reserved));
1012
- register_completion_queue(server, cq, true, reserved);
983
+ if (grpc_get_cq_completion_type(cq) != GRPC_CQ_NEXT) {
984
+ gpr_log(GPR_INFO,
985
+ "Completion queue which is not of type GRPC_CQ_NEXT is being "
986
+ "registered as a server-completion-queue");
987
+ /* Ideally we should log an error and abort but ruby-wrapped-language API
988
+ calls grpc_completion_queue_pluck() on server completion queues */
989
+ }
990
+
991
+ register_completion_queue(server, cq, reserved);
1013
992
  }
1014
993
 
1015
994
  grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
@@ -1017,18 +996,15 @@ grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
1017
996
 
1018
997
  grpc_server *server = gpr_zalloc(sizeof(grpc_server));
1019
998
 
1020
- GPR_ASSERT(grpc_is_initialized() && "call grpc_init()");
1021
-
1022
999
  gpr_mu_init(&server->mu_global);
1023
1000
  gpr_mu_init(&server->mu_call);
1001
+ gpr_cv_init(&server->starting_cv);
1024
1002
 
1025
1003
  /* decremented by grpc_server_destroy */
1026
1004
  gpr_ref_init(&server->internal_refcount, 1);
1027
1005
  server->root_channel_data.next = server->root_channel_data.prev =
1028
1006
  &server->root_channel_data;
1029
1007
 
1030
- /* TODO(ctiller): expose a channel_arg for this */
1031
- server->max_requested_calls_per_cq = 32768;
1032
1008
  server->channel_args = grpc_channel_args_copy(args);
1033
1009
 
1034
1010
  return server;
@@ -1077,8 +1053,22 @@ void *grpc_server_register_method(
1077
1053
  return m;
1078
1054
  }
1079
1055
 
1056
+ static void start_listeners(grpc_exec_ctx *exec_ctx, void *s,
1057
+ grpc_error *error) {
1058
+ grpc_server *server = s;
1059
+ for (listener *l = server->listeners; l; l = l->next) {
1060
+ l->start(exec_ctx, server, l->arg, server->pollsets, server->pollset_count);
1061
+ }
1062
+
1063
+ gpr_mu_lock(&server->mu_global);
1064
+ server->starting = false;
1065
+ gpr_cv_signal(&server->starting_cv);
1066
+ gpr_mu_unlock(&server->mu_global);
1067
+
1068
+ server_unref(exec_ctx, server);
1069
+ }
1070
+
1080
1071
  void grpc_server_start(grpc_server *server) {
1081
- listener *l;
1082
1072
  size_t i;
1083
1073
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
1084
1074
 
@@ -1087,35 +1077,22 @@ void grpc_server_start(grpc_server *server) {
1087
1077
  server->started = true;
1088
1078
  server->pollset_count = 0;
1089
1079
  server->pollsets = gpr_malloc(sizeof(grpc_pollset *) * server->cq_count);
1090
- server->request_freelist_per_cq =
1091
- gpr_malloc(sizeof(*server->request_freelist_per_cq) * server->cq_count);
1092
- server->requested_calls_per_cq =
1093
- gpr_malloc(sizeof(*server->requested_calls_per_cq) * server->cq_count);
1094
1080
  for (i = 0; i < server->cq_count; i++) {
1095
- if (!grpc_cq_is_non_listening_server_cq(server->cqs[i])) {
1081
+ if (grpc_cq_can_listen(server->cqs[i])) {
1096
1082
  server->pollsets[server->pollset_count++] =
1097
1083
  grpc_cq_pollset(server->cqs[i]);
1098
1084
  }
1099
- server->request_freelist_per_cq[i] =
1100
- gpr_stack_lockfree_create((size_t)server->max_requested_calls_per_cq);
1101
- for (int j = 0; j < server->max_requested_calls_per_cq; j++) {
1102
- gpr_stack_lockfree_push(server->request_freelist_per_cq[i], j);
1103
- }
1104
- server->requested_calls_per_cq[i] =
1105
- gpr_malloc((size_t)server->max_requested_calls_per_cq *
1106
- sizeof(*server->requested_calls_per_cq[i]));
1107
1085
  }
1108
- request_matcher_init(&server->unregistered_request_matcher,
1109
- (size_t)server->max_requested_calls_per_cq, server);
1086
+ request_matcher_init(&server->unregistered_request_matcher, server);
1110
1087
  for (registered_method *rm = server->registered_methods; rm; rm = rm->next) {
1111
- request_matcher_init(&rm->request_matcher,
1112
- (size_t)server->max_requested_calls_per_cq, server);
1088
+ request_matcher_init(&rm->request_matcher, server);
1113
1089
  }
1114
1090
 
1115
- for (l = server->listeners; l; l = l->next) {
1116
- l->start(&exec_ctx, server, l->arg, server->pollsets,
1117
- server->pollset_count);
1118
- }
1091
+ server_ref(server);
1092
+ server->starting = true;
1093
+ grpc_closure_sched(&exec_ctx, grpc_closure_create(start_listeners, server,
1094
+ grpc_executor_scheduler),
1095
+ GRPC_ERROR_NONE);
1119
1096
 
1120
1097
  grpc_exec_ctx_finish(&exec_ctx);
1121
1098
  }
@@ -1249,8 +1226,14 @@ void grpc_server_shutdown_and_notify(grpc_server *server,
1249
1226
  GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
1250
1227
  (server, cq, tag));
1251
1228
 
1252
- /* lock, and gather up some stuff to do */
1229
+ /* wait for startup to be finished: locks mu_global */
1253
1230
  gpr_mu_lock(&server->mu_global);
1231
+ while (server->starting) {
1232
+ gpr_cv_wait(&server->starting_cv, &server->mu_global,
1233
+ gpr_inf_future(GPR_CLOCK_REALTIME));
1234
+ }
1235
+
1236
+ /* stay locked, and gather up some stuff to do */
1254
1237
  grpc_cq_begin_op(cq, tag);
1255
1238
  if (server->shutdown_published) {
1256
1239
  grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown,
@@ -1356,21 +1339,11 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx,
1356
1339
  requested_call *rc) {
1357
1340
  call_data *calld = NULL;
1358
1341
  request_matcher *rm = NULL;
1359
- int request_id;
1360
1342
  if (gpr_atm_acq_load(&server->shutdown_flag)) {
1361
1343
  fail_call(exec_ctx, server, cq_idx, rc,
1362
1344
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1363
1345
  return GRPC_CALL_OK;
1364
1346
  }
1365
- request_id = gpr_stack_lockfree_pop(server->request_freelist_per_cq[cq_idx]);
1366
- if (request_id == -1) {
1367
- /* out of request ids: just fail this one */
1368
- fail_call(exec_ctx, server, cq_idx, rc,
1369
- grpc_error_set_int(
1370
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Out of request ids"),
1371
- GRPC_ERROR_INT_LIMIT, server->max_requested_calls_per_cq));
1372
- return GRPC_CALL_OK;
1373
- }
1374
1347
  switch (rc->type) {
1375
1348
  case BATCH_CALL:
1376
1349
  rm = &server->unregistered_request_matcher;
@@ -1379,15 +1352,13 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx,
1379
1352
  rm = &rc->data.registered.registered_method->request_matcher;
1380
1353
  break;
1381
1354
  }
1382
- server->requested_calls_per_cq[cq_idx][request_id] = *rc;
1383
- gpr_free(rc);
1384
- if (gpr_stack_lockfree_push(rm->requests_per_cq[cq_idx], request_id)) {
1355
+ if (gpr_locked_mpscq_push(&rm->requests_per_cq[cq_idx], &rc->request_link)) {
1385
1356
  /* this was the first queued request: we need to lock and start
1386
1357
  matching calls */
1387
1358
  gpr_mu_lock(&server->mu_call);
1388
1359
  while ((calld = rm->pending_head) != NULL) {
1389
- request_id = gpr_stack_lockfree_pop(rm->requests_per_cq[cq_idx]);
1390
- if (request_id == -1) break;
1360
+ rc = (requested_call *)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]);
1361
+ if (rc == NULL) break;
1391
1362
  rm->pending_head = calld->pending_next;
1392
1363
  gpr_mu_unlock(&server->mu_call);
1393
1364
  gpr_mu_lock(&calld->mu_state);
@@ -1403,8 +1374,7 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx,
1403
1374
  GPR_ASSERT(calld->state == PENDING);
1404
1375
  calld->state = ACTIVATED;
1405
1376
  gpr_mu_unlock(&calld->mu_state);
1406
- publish_call(exec_ctx, server, calld, cq_idx,
1407
- &server->requested_calls_per_cq[cq_idx][request_id]);
1377
+ publish_call(exec_ctx, server, calld, cq_idx, rc);
1408
1378
  }
1409
1379
  gpr_mu_lock(&server->mu_call);
1410
1380
  }
@@ -1511,7 +1481,6 @@ static void fail_call(grpc_exec_ctx *exec_ctx, grpc_server *server,
1511
1481
  rc->initial_metadata->count = 0;
1512
1482
  GPR_ASSERT(error != GRPC_ERROR_NONE);
1513
1483
 
1514
- server_ref(server);
1515
1484
  grpc_cq_end_op(exec_ctx, server->cqs[cq_idx], rc->tag, error,
1516
1485
  done_request_event, rc, &rc->completion);
1517
1486
  }