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
@@ -71,7 +71,7 @@ struct gpr_cmdline {
71
71
  static int normal_state(gpr_cmdline *cl, char *arg);
72
72
 
73
73
  gpr_cmdline *gpr_cmdline_create(const char *description) {
74
- gpr_cmdline *cl = gpr_zalloc(sizeof(gpr_cmdline));
74
+ gpr_cmdline *cl = (gpr_cmdline *)gpr_zalloc(sizeof(gpr_cmdline));
75
75
 
76
76
  cl->description = description;
77
77
  cl->state = normal_state;
@@ -100,7 +100,7 @@ static void add_arg(gpr_cmdline *cl, const char *name, const char *help,
100
100
  GPR_ASSERT(0 != strcmp(a->name, name));
101
101
  }
102
102
 
103
- a = gpr_zalloc(sizeof(arg));
103
+ a = (arg *)gpr_zalloc(sizeof(arg));
104
104
  a->name = name;
105
105
  a->help = help;
106
106
  a->type = type;
@@ -302,7 +302,7 @@ static int normal_state(gpr_cmdline *cl, char *str) {
302
302
  eq = strchr(str, '=');
303
303
  if (eq != NULL) {
304
304
  /* copy the string into a temp buffer and extract the name */
305
- tmp = arg_name = gpr_malloc((size_t)(eq - str + 1));
305
+ tmp = arg_name = (char *)gpr_malloc((size_t)(eq - str + 1));
306
306
  memcpy(arg_name, str, (size_t)(eq - str));
307
307
  arg_name[eq - str] = 0;
308
308
  } else {
@@ -88,7 +88,7 @@ static double bucket_start(gpr_histogram *h, double x) {
88
88
 
89
89
  gpr_histogram *gpr_histogram_create(double resolution,
90
90
  double max_bucket_start) {
91
- gpr_histogram *h = gpr_malloc(sizeof(gpr_histogram));
91
+ gpr_histogram *h = (gpr_histogram *)gpr_malloc(sizeof(gpr_histogram));
92
92
  GPR_ASSERT(resolution > 0.0);
93
93
  GPR_ASSERT(max_bucket_start > resolution);
94
94
  h->sum = 0.0;
@@ -102,7 +102,7 @@ gpr_histogram *gpr_histogram_create(double resolution,
102
102
  h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1;
103
103
  GPR_ASSERT(h->num_buckets > 1);
104
104
  GPR_ASSERT(h->num_buckets < 100000000);
105
- h->buckets = gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
105
+ h->buckets = (uint32_t *)gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
106
106
  return h;
107
107
  }
108
108
 
@@ -98,7 +98,7 @@ int gpr_split_host_port(const char *name, char **host, char **port) {
98
98
  }
99
99
 
100
100
  /* Allocate return values. */
101
- *host = gpr_malloc(host_len + 1);
101
+ *host = (char *)gpr_malloc(host_len + 1);
102
102
  memcpy(*host, host_start, host_len);
103
103
  (*host)[host_len] = '\0';
104
104
 
@@ -0,0 +1,74 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_CORE_LIB_SUPPORT_MEMORY_H
35
+ #define GRPC_CORE_LIB_SUPPORT_MEMORY_H
36
+
37
+ #include <grpc/support/alloc.h>
38
+
39
+ #include <memory>
40
+ #include <utility>
41
+
42
+ namespace grpc_core {
43
+
44
+ // Alternative to new, since we cannot use it (for fear of libstdc++)
45
+ template <typename T, typename... Args>
46
+ inline T* New(Args&&... args) {
47
+ void* p = gpr_malloc(sizeof(T));
48
+ return new (p) T(std::forward<Args>(args)...);
49
+ }
50
+
51
+ // Alternative to delete, since we cannot use it (for fear of libstdc++)
52
+ template <typename T>
53
+ inline void Delete(T* p) {
54
+ p->~T();
55
+ gpr_free(p);
56
+ }
57
+
58
+ template <typename T>
59
+ class DefaultDelete {
60
+ public:
61
+ void operator()(T* p) { Delete(p); }
62
+ };
63
+
64
+ template <typename T, typename Deleter = DefaultDelete<T>>
65
+ using UniquePtr = std::unique_ptr<T, Deleter>;
66
+
67
+ template <typename T, typename... Args>
68
+ inline UniquePtr<T> MakeUnique(Args&&... args) {
69
+ return UniquePtr<T>(New<T>(std::forward<Args>(args)...));
70
+ }
71
+
72
+ } // namespace grpc_core
73
+
74
+ #endif /* GRPC_CORE_LIB_SUPPORT_MEMORY_H */
@@ -46,29 +46,40 @@ void gpr_mpscq_destroy(gpr_mpscq *q) {
46
46
  GPR_ASSERT(q->tail == &q->stub);
47
47
  }
48
48
 
49
- void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n) {
49
+ bool gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n) {
50
50
  gpr_atm_no_barrier_store(&n->next, (gpr_atm)NULL);
51
51
  gpr_mpscq_node *prev =
52
52
  (gpr_mpscq_node *)gpr_atm_full_xchg(&q->head, (gpr_atm)n);
53
53
  gpr_atm_rel_store(&prev->next, (gpr_atm)n);
54
+ return prev == &q->stub;
54
55
  }
55
56
 
56
57
  gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) {
58
+ bool empty;
59
+ return gpr_mpscq_pop_and_check_end(q, &empty);
60
+ }
61
+
62
+ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty) {
57
63
  gpr_mpscq_node *tail = q->tail;
58
64
  gpr_mpscq_node *next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
59
65
  if (tail == &q->stub) {
60
66
  // indicates the list is actually (ephemerally) empty
61
- if (next == NULL) return NULL;
67
+ if (next == NULL) {
68
+ *empty = true;
69
+ return NULL;
70
+ }
62
71
  q->tail = next;
63
72
  tail = next;
64
73
  next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
65
74
  }
66
75
  if (next != NULL) {
76
+ *empty = false;
67
77
  q->tail = next;
68
78
  return tail;
69
79
  }
70
80
  gpr_mpscq_node *head = (gpr_mpscq_node *)gpr_atm_acq_load(&q->head);
71
81
  if (tail != head) {
82
+ *empty = false;
72
83
  // indicates a retry is in order: we're still adding
73
84
  return NULL;
74
85
  }
@@ -79,5 +90,28 @@ gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) {
79
90
  return tail;
80
91
  }
81
92
  // indicates a retry is in order: we're still adding
93
+ *empty = false;
94
+ return NULL;
95
+ }
96
+
97
+ void gpr_locked_mpscq_init(gpr_locked_mpscq *q) {
98
+ gpr_mpscq_init(&q->queue);
99
+ q->read_lock = GPR_SPINLOCK_INITIALIZER;
100
+ }
101
+
102
+ void gpr_locked_mpscq_destroy(gpr_locked_mpscq *q) {
103
+ gpr_mpscq_destroy(&q->queue);
104
+ }
105
+
106
+ bool gpr_locked_mpscq_push(gpr_locked_mpscq *q, gpr_mpscq_node *n) {
107
+ return gpr_mpscq_push(&q->queue, n);
108
+ }
109
+
110
+ gpr_mpscq_node *gpr_locked_mpscq_pop(gpr_locked_mpscq *q) {
111
+ if (gpr_spinlock_trylock(&q->read_lock)) {
112
+ gpr_mpscq_node *n = gpr_mpscq_pop(&q->queue);
113
+ gpr_spinlock_unlock(&q->read_lock);
114
+ return n;
115
+ }
82
116
  return NULL;
83
117
  }
@@ -35,7 +35,9 @@
35
35
  #define GRPC_CORE_LIB_SUPPORT_MPSCQ_H
36
36
 
37
37
  #include <grpc/support/atm.h>
38
+ #include <stdbool.h>
38
39
  #include <stddef.h>
40
+ #include "src/core/lib/support/spinlock.h"
39
41
 
40
42
  // Multiple-producer single-consumer lock free queue, based upon the
41
43
  // implementation from Dmitry Vyukov here:
@@ -57,9 +59,34 @@ typedef struct gpr_mpscq {
57
59
  void gpr_mpscq_init(gpr_mpscq *q);
58
60
  void gpr_mpscq_destroy(gpr_mpscq *q);
59
61
  // Push a node
60
- void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n);
62
+ // Thread safe - can be called from multiple threads concurrently
63
+ // Returns true if this was possibly the first node (may return true
64
+ // sporadically, will not return false sporadically)
65
+ bool gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n);
61
66
  // Pop a node (returns NULL if no node is ready - which doesn't indicate that
62
67
  // the queue is empty!!)
68
+ // Thread compatible - can only be called from one thread at a time
63
69
  gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q);
70
+ // Pop a node; sets *empty to true if the queue is empty, or false if it is not
71
+ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty);
72
+
73
+ // An mpscq with a spinlock: it's safe to pop from multiple threads, but doing
74
+ // only one thread will succeed concurrently
75
+ typedef struct gpr_locked_mpscq {
76
+ gpr_mpscq queue;
77
+ gpr_spinlock read_lock;
78
+ } gpr_locked_mpscq;
79
+
80
+ void gpr_locked_mpscq_init(gpr_locked_mpscq *q);
81
+ void gpr_locked_mpscq_destroy(gpr_locked_mpscq *q);
82
+ // Push a node
83
+ // Thread safe - can be called from multiple threads concurrently
84
+ // Returns true if this was possibly the first node (may return true
85
+ // sporadically, will not return false sporadically)
86
+ bool gpr_locked_mpscq_push(gpr_locked_mpscq *q, gpr_mpscq_node *n);
87
+ // Pop a node (returns NULL if no node is ready - which doesn't indicate that
88
+ // the queue is empty!!)
89
+ // Thread safe - can be called from multiple threads concurrently
90
+ gpr_mpscq_node *gpr_locked_mpscq_pop(gpr_locked_mpscq *q);
64
91
 
65
92
  #endif /* GRPC_CORE_LIB_SUPPORT_MPSCQ_H */
@@ -72,28 +72,20 @@ typedef union lockfree_node {
72
72
  struct gpr_stack_lockfree {
73
73
  lockfree_node *entries;
74
74
  lockfree_node head; /* An atomic entry describing curr head */
75
-
76
- #ifndef NDEBUG
77
- /* Bitmap of pushed entries to check for double-push or pop */
78
- gpr_atm pushed[(INVALID_ENTRY_INDEX + 1) / (8 * sizeof(gpr_atm))];
79
- #endif
80
75
  };
81
76
 
82
77
  gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries) {
83
78
  gpr_stack_lockfree *stack;
84
- stack = gpr_malloc(sizeof(*stack));
79
+ stack = (gpr_stack_lockfree *)gpr_malloc(sizeof(*stack));
85
80
  /* Since we only allocate 16 bits to represent an entry number,
86
81
  * make sure that we are within the desired range */
87
82
  /* Reserve the highest entry number as a dummy */
88
83
  GPR_ASSERT(entries < INVALID_ENTRY_INDEX);
89
- stack->entries = gpr_malloc_aligned(entries * sizeof(stack->entries[0]),
90
- ENTRY_ALIGNMENT_BITS);
84
+ stack->entries = (lockfree_node *)gpr_malloc_aligned(
85
+ entries * sizeof(stack->entries[0]), ENTRY_ALIGNMENT_BITS);
91
86
  /* Clear out all entries */
92
87
  memset(stack->entries, 0, entries * sizeof(stack->entries[0]));
93
88
  memset(&stack->head, 0, sizeof(stack->head));
94
- #ifndef NDEBUG
95
- memset(&stack->pushed, 0, sizeof(stack->pushed));
96
- #endif
97
89
 
98
90
  GPR_ASSERT(sizeof(stack->entries->atm) == sizeof(stack->entries->contents));
99
91
 
@@ -130,19 +122,6 @@ int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
130
122
  newhead.contents.aba_ctr = ++curent.contents.aba_ctr;
131
123
  gpr_atm_no_barrier_store(&stack->entries[entry].atm, curent.atm);
132
124
 
133
- #ifndef NDEBUG
134
- /* Check for double push */
135
- {
136
- int pushed_index = entry / (int)(8 * sizeof(gpr_atm));
137
- int pushed_bit = entry % (int)(8 * sizeof(gpr_atm));
138
- gpr_atm old_val;
139
-
140
- old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index],
141
- ((gpr_atm)1 << pushed_bit));
142
- GPR_ASSERT((old_val & (((gpr_atm)1) << pushed_bit)) == 0);
143
- }
144
- #endif
145
-
146
125
  do {
147
126
  /* Atomically get the existing head value for use */
148
127
  head.atm = gpr_atm_no_barrier_load(&(stack->head.atm));
@@ -168,18 +147,6 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) {
168
147
  gpr_atm_no_barrier_load(&(stack->entries[head.contents.index].atm));
169
148
 
170
149
  } while (!gpr_atm_no_barrier_cas(&(stack->head.atm), head.atm, newhead.atm));
171
- #ifndef NDEBUG
172
- /* Check for valid pop */
173
- {
174
- int pushed_index = head.contents.index / (8 * sizeof(gpr_atm));
175
- int pushed_bit = head.contents.index % (8 * sizeof(gpr_atm));
176
- gpr_atm old_val;
177
-
178
- old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index],
179
- -((gpr_atm)1 << pushed_bit));
180
- GPR_ASSERT((old_val & (((gpr_atm)1) << pushed_bit)) != 0);
181
- }
182
- #endif
183
150
 
184
151
  return head.contents.index;
185
152
  }
@@ -53,7 +53,7 @@ char *gpr_strdup(const char *src) {
53
53
  }
54
54
 
55
55
  len = strlen(src) + 1;
56
- dst = gpr_malloc(len);
56
+ dst = (char *)gpr_malloc(len);
57
57
 
58
58
  memcpy(dst, src, len);
59
59
 
@@ -74,13 +74,13 @@ static dump_out dump_out_create(void) {
74
74
  static void dump_out_append(dump_out *out, char c) {
75
75
  if (out->length == out->capacity) {
76
76
  out->capacity = GPR_MAX(8, 2 * out->capacity);
77
- out->data = gpr_realloc(out->data, out->capacity);
77
+ out->data = (char *)gpr_realloc(out->data, out->capacity);
78
78
  }
79
79
  out->data[out->length++] = c;
80
80
  }
81
81
 
82
82
  static void hexdump(dump_out *out, const char *buf, size_t len) {
83
- static const char hex[16] = "0123456789abcdef";
83
+ static const char *hex = "0123456789abcdef";
84
84
 
85
85
  const uint8_t *const beg = (const uint8_t *)buf;
86
86
  const uint8_t *const end = beg + len;
@@ -124,16 +124,16 @@ char *gpr_dump(const char *buf, size_t len, uint32_t flags) {
124
124
 
125
125
  int gpr_parse_bytes_to_uint32(const char *buf, size_t len, uint32_t *result) {
126
126
  uint32_t out = 0;
127
- uint32_t new;
127
+ uint32_t new_val;
128
128
  size_t i;
129
129
 
130
130
  if (len == 0) return 0; /* must have some bytes */
131
131
 
132
132
  for (i = 0; i < len; i++) {
133
133
  if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */
134
- new = 10 * out + (uint32_t)(buf[i] - '0');
135
- if (new < out) return 0; /* overflow */
136
- out = new;
134
+ new_val = 10 * out + (uint32_t)(buf[i] - '0');
135
+ if (new_val < out) return 0; /* overflow */
136
+ out = new_val;
137
137
  }
138
138
 
139
139
  *result = out;
@@ -201,7 +201,7 @@ int gpr_parse_nonnegative_int(const char *value) {
201
201
  char *gpr_leftpad(const char *str, char flag, size_t length) {
202
202
  const size_t str_length = strlen(str);
203
203
  const size_t out_length = str_length > length ? str_length : length;
204
- char *out = gpr_malloc(out_length + 1);
204
+ char *out = (char *)gpr_malloc(out_length + 1);
205
205
  memset(out, flag, out_length - str_length);
206
206
  memcpy(out + out_length - str_length, str, str_length);
207
207
  out[out_length] = 0;
@@ -225,7 +225,7 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
225
225
  if (nstrs > 0) {
226
226
  out_length += sep_len * (nstrs - 1); /* separators */
227
227
  }
228
- out = gpr_malloc(out_length);
228
+ out = (char *)gpr_malloc(out_length);
229
229
  out_length = 0;
230
230
  for (i = 0; i < nstrs; i++) {
231
231
  const size_t slen = strlen(strs[i]);
@@ -256,7 +256,7 @@ void gpr_strvec_destroy(gpr_strvec *sv) {
256
256
  void gpr_strvec_add(gpr_strvec *sv, char *str) {
257
257
  if (sv->count == sv->capacity) {
258
258
  sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2);
259
- sv->strs = gpr_realloc(sv->strs, sizeof(char *) * sv->capacity);
259
+ sv->strs = (char **)gpr_realloc(sv->strs, sizeof(char *) * sv->capacity);
260
260
  }
261
261
  sv->strs[sv->count++] = str;
262
262
  }
@@ -278,12 +278,12 @@ int gpr_stricmp(const char *a, const char *b) {
278
278
 
279
279
  static void add_string_to_split(const char *beg, const char *end, char ***strs,
280
280
  size_t *nstrs, size_t *capstrs) {
281
- char *out = gpr_malloc((size_t)(end - beg) + 1);
281
+ char *out = (char *)gpr_malloc((size_t)(end - beg) + 1);
282
282
  memcpy(out, beg, (size_t)(end - beg));
283
283
  out[end - beg] = 0;
284
284
  if (*nstrs == *capstrs) {
285
285
  *capstrs = GPR_MAX(8, 2 * *capstrs);
286
- *strs = gpr_realloc(*strs, sizeof(*strs) * *capstrs);
286
+ *strs = (char **)gpr_realloc(*strs, sizeof(*strs) * *capstrs);
287
287
  }
288
288
  (*strs)[*nstrs] = out;
289
289
  ++*nstrs;
@@ -58,7 +58,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
58
58
 
59
59
  /* Allocate a new buffer, with space for the NUL terminator. */
60
60
  strp_buflen = (size_t)ret + 1;
61
- if ((*strp = gpr_malloc(strp_buflen)) == NULL) {
61
+ if ((*strp = (char *)gpr_malloc(strp_buflen)) == NULL) {
62
62
  /* This shouldn't happen, because gpr_malloc() calls abort(). */
63
63
  return -1;
64
64
  }
@@ -67,7 +67,7 @@ gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
67
67
  if (pid == -1) {
68
68
  return NULL;
69
69
  } else if (pid == 0) {
70
- exec_args = gpr_malloc(((size_t)argc + 1) * sizeof(char *));
70
+ exec_args = (char **)gpr_malloc(((size_t)argc + 1) * sizeof(char *));
71
71
  memcpy(exec_args, argv, (size_t)argc * sizeof(char *));
72
72
  exec_args[argc] = NULL;
73
73
  execv(exec_args[0], exec_args);
@@ -76,7 +76,7 @@ gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
76
76
  _exit(1);
77
77
  return NULL;
78
78
  } else {
79
- r = gpr_zalloc(sizeof(gpr_subprocess));
79
+ r = (gpr_subprocess *)gpr_zalloc(sizeof(gpr_subprocess));
80
80
  r->pid = pid;
81
81
  return r;
82
82
  }
@@ -65,7 +65,7 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
65
65
  pthread_t p;
66
66
  /* don't use gpr_malloc as we may cause an infinite recursion with
67
67
  * the profiling code */
68
- struct thd_arg *a = malloc(sizeof(*a));
68
+ struct thd_arg *a = (struct thd_arg *)malloc(sizeof(*a));
69
69
  GPR_ASSERT(a != NULL);
70
70
  a->body = thd_body;
71
71
  a->arg = arg;
@@ -42,6 +42,7 @@
42
42
  #ifdef __linux__
43
43
  #include <sys/syscall.h>
44
44
  #endif
45
+ #include <grpc/support/atm.h>
45
46
  #include <grpc/support/log.h>
46
47
  #include <grpc/support/time.h>
47
48
  #include "src/core/lib/support/block_annotate.h"
@@ -144,7 +145,14 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
144
145
 
145
146
  gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
146
147
 
148
+ #ifdef GPR_LOW_LEVEL_COUNTERS
149
+ gpr_atm gpr_now_call_count;
150
+ #endif
151
+
147
152
  gpr_timespec gpr_now(gpr_clock_type clock_type) {
153
+ #ifdef GPR_LOW_LEVEL_COUNTERS
154
+ __atomic_fetch_add(&gpr_now_call_count, 1, __ATOMIC_RELAXED);
155
+ #endif
148
156
  return gpr_now_impl(clock_type);
149
157
  }
150
158