wearefair-grpc 1.3.1.pre.c → 1.4.0.fair

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +418 -126
  3. data/include/grpc/grpc.h +15 -69
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/compression_types.h +3 -4
  6. data/include/grpc/impl/codegen/gpr_types.h +0 -1
  7. data/include/grpc/impl/codegen/grpc_types.h +69 -3
  8. data/include/grpc/impl/codegen/port_platform.h +6 -0
  9. data/include/grpc/impl/codegen/slice.h +2 -1
  10. data/include/grpc/load_reporting.h +6 -6
  11. data/include/grpc/slice.h +25 -3
  12. data/include/grpc/slice_buffer.h +4 -0
  13. data/src/core/ext/census/context.c +1 -1
  14. data/src/core/ext/census/resource.c +3 -1
  15. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  16. data/src/core/ext/filters/client_channel/client_channel.c +158 -100
  17. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  18. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  19. data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  29. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  33. data/src/core/ext/filters/client_channel/parse_address.c +37 -7
  34. data/src/core/ext/filters/client_channel/parse_address.h +11 -8
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  36. data/src/core/ext/filters/client_channel/subchannel.c +19 -16
  37. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  38. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  39. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  40. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  41. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  42. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  43. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  44. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  45. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  46. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  47. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  48. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  49. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  50. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  51. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  52. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  53. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  54. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  57. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  58. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
  59. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  60. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  61. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  62. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  63. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  66. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  69. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  70. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  71. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  72. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  73. data/src/core/lib/channel/channel_args.c +28 -9
  74. data/src/core/lib/channel/channel_args.h +5 -1
  75. data/src/core/lib/channel/channel_stack.c +1 -1
  76. data/src/core/lib/channel/channel_stack.h +2 -2
  77. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  78. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  79. data/src/core/lib/channel/connected_channel.c +3 -1
  80. data/src/core/lib/channel/context.h +2 -2
  81. data/src/core/lib/compression/message_compress.c +2 -2
  82. data/src/core/lib/debug/trace.c +13 -6
  83. data/src/core/lib/debug/trace.h +27 -1
  84. data/src/core/lib/http/httpcli.c +1 -1
  85. data/src/core/lib/http/httpcli_security_connector.c +6 -10
  86. data/src/core/lib/http/parser.c +2 -2
  87. data/src/core/lib/http/parser.h +2 -1
  88. data/src/core/lib/iomgr/combiner.c +6 -6
  89. data/src/core/lib/iomgr/combiner.h +2 -1
  90. data/src/core/lib/iomgr/error.c +12 -5
  91. data/src/core/lib/iomgr/error.h +13 -13
  92. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  93. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  94. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  95. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  96. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  97. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  98. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  99. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  100. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
  101. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  102. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  103. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  104. data/src/core/lib/iomgr/ev_posix.c +22 -8
  105. data/src/core/lib/iomgr/ev_posix.h +4 -3
  106. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  107. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  108. data/src/core/lib/iomgr/iomgr.c +4 -0
  109. data/src/core/lib/iomgr/iomgr.h +3 -0
  110. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  111. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  112. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  113. data/src/core/lib/iomgr/pollset.h +2 -5
  114. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  115. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  116. data/src/core/lib/iomgr/resource_quota.c +9 -8
  117. data/src/core/lib/iomgr/resource_quota.h +2 -1
  118. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  119. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  120. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  121. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  122. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  123. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  124. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  125. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  126. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  127. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  128. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  129. data/src/core/lib/iomgr/timer_generic.c +24 -25
  130. data/src/core/lib/iomgr/timer_manager.c +276 -0
  131. data/src/core/lib/iomgr/timer_manager.h +52 -0
  132. data/src/core/lib/iomgr/timer_uv.c +6 -0
  133. data/src/core/lib/iomgr/udp_server.c +42 -9
  134. data/src/core/lib/iomgr/udp_server.h +3 -1
  135. data/src/core/lib/security/credentials/credentials.c +0 -1
  136. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  137. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  138. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  139. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  140. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  141. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  142. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  143. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  144. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  145. data/src/core/lib/security/transport/security_connector.c +32 -51
  146. data/src/core/lib/security/transport/security_connector.h +10 -14
  147. data/src/core/lib/slice/b64.c +1 -1
  148. data/src/core/lib/slice/percent_encoding.c +3 -3
  149. data/src/core/lib/slice/slice.c +66 -33
  150. data/src/core/lib/slice/slice_buffer.c +25 -6
  151. data/src/core/lib/slice/slice_hash_table.c +33 -35
  152. data/src/core/lib/slice/slice_hash_table.h +7 -12
  153. data/src/core/lib/support/atomic.h +45 -0
  154. data/src/core/lib/support/atomic_with_atm.h +70 -0
  155. data/src/core/lib/support/atomic_with_std.h +48 -0
  156. data/src/core/lib/support/avl.c +14 -14
  157. data/src/core/lib/support/memory.h +74 -0
  158. data/src/core/lib/support/mpscq.c +12 -1
  159. data/src/core/lib/support/mpscq.h +4 -0
  160. data/src/core/lib/support/stack_lockfree.c +3 -36
  161. data/src/core/lib/support/time_posix.c +8 -0
  162. data/src/core/lib/support/tmpfile_posix.c +10 -10
  163. data/src/core/lib/surface/alarm.c +3 -1
  164. data/src/core/lib/surface/api_trace.c +2 -1
  165. data/src/core/lib/surface/api_trace.h +2 -2
  166. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  167. data/src/core/lib/surface/call.c +65 -22
  168. data/src/core/lib/surface/call.h +4 -2
  169. data/src/core/lib/surface/channel_init.c +2 -19
  170. data/src/core/lib/surface/channel_stack_type.c +18 -0
  171. data/src/core/lib/surface/channel_stack_type.h +2 -0
  172. data/src/core/lib/surface/completion_queue.c +249 -83
  173. data/src/core/lib/surface/completion_queue.h +18 -13
  174. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  175. data/src/core/lib/surface/init.c +1 -52
  176. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  177. data/src/core/lib/surface/server.c +50 -27
  178. data/src/core/lib/surface/server.h +2 -1
  179. data/src/core/lib/surface/version.c +2 -2
  180. data/src/core/lib/transport/bdp_estimator.c +20 -9
  181. data/src/core/lib/transport/bdp_estimator.h +5 -1
  182. data/src/core/lib/transport/byte_stream.c +23 -9
  183. data/src/core/lib/transport/byte_stream.h +15 -6
  184. data/src/core/lib/transport/connectivity_state.c +6 -6
  185. data/src/core/lib/transport/connectivity_state.h +2 -1
  186. data/src/core/lib/transport/service_config.c +6 -13
  187. data/src/core/lib/transport/service_config.h +2 -2
  188. data/src/core/lib/transport/static_metadata.c +403 -389
  189. data/src/core/lib/transport/static_metadata.h +127 -114
  190. data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
  191. data/src/core/tsi/fake_transport_security.c +5 -4
  192. data/src/core/tsi/ssl_transport_security.c +71 -82
  193. data/src/core/tsi/ssl_transport_security.h +39 -61
  194. data/src/core/tsi/transport_security.c +83 -2
  195. data/src/core/tsi/transport_security.h +27 -2
  196. data/src/core/tsi/transport_security_adapter.c +236 -0
  197. data/src/core/tsi/transport_security_adapter.h +62 -0
  198. data/src/core/tsi/transport_security_interface.h +179 -66
  199. data/src/ruby/ext/grpc/extconf.rb +2 -1
  200. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  201. data/src/ruby/ext/grpc/rb_call.c +56 -48
  202. data/src/ruby/ext/grpc/rb_call.h +3 -4
  203. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  204. data/src/ruby/ext/grpc/rb_channel.c +45 -29
  205. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  206. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  207. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  208. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  209. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  210. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  211. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  212. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  213. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
  214. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
  215. data/src/ruby/ext/grpc/rb_server.c +26 -28
  216. data/src/ruby/lib/grpc/version.rb +1 -1
  217. metadata +40 -18
  218. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  219. data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -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 */
@@ -54,21 +54,31 @@ void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n) {
54
54
  }
55
55
 
56
56
  gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) {
57
+ bool empty;
58
+ return gpr_mpscq_pop_and_check_end(q, &empty);
59
+ }
60
+
61
+ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty) {
57
62
  gpr_mpscq_node *tail = q->tail;
58
63
  gpr_mpscq_node *next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
59
64
  if (tail == &q->stub) {
60
65
  // indicates the list is actually (ephemerally) empty
61
- if (next == NULL) return NULL;
66
+ if (next == NULL) {
67
+ *empty = true;
68
+ return NULL;
69
+ }
62
70
  q->tail = next;
63
71
  tail = next;
64
72
  next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
65
73
  }
66
74
  if (next != NULL) {
75
+ *empty = false;
67
76
  q->tail = next;
68
77
  return tail;
69
78
  }
70
79
  gpr_mpscq_node *head = (gpr_mpscq_node *)gpr_atm_acq_load(&q->head);
71
80
  if (tail != head) {
81
+ *empty = false;
72
82
  // indicates a retry is in order: we're still adding
73
83
  return NULL;
74
84
  }
@@ -79,5 +89,6 @@ gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) {
79
89
  return tail;
80
90
  }
81
91
  // indicates a retry is in order: we're still adding
92
+ *empty = false;
82
93
  return NULL;
83
94
  }
@@ -35,6 +35,7 @@
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>
39
40
 
40
41
  // Multiple-producer single-consumer lock free queue, based upon the
@@ -62,4 +63,7 @@ void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n);
62
63
  // the queue is empty!!)
63
64
  gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q);
64
65
 
66
+ // Pop a node; sets *empty to true if the queue is empty, or false if it is not
67
+ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty);
68
+
65
69
  #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
  }
@@ -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
 
@@ -50,34 +50,34 @@
50
50
 
51
51
  FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
52
52
  FILE *result = NULL;
53
- char *template;
53
+ char *filename_template;
54
54
  int fd;
55
55
 
56
56
  if (tmp_filename != NULL) *tmp_filename = NULL;
57
57
 
58
- gpr_asprintf(&template, "/tmp/%s_XXXXXX", prefix);
59
- GPR_ASSERT(template != NULL);
58
+ gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix);
59
+ GPR_ASSERT(filename_template != NULL);
60
60
 
61
- fd = mkstemp(template);
61
+ fd = mkstemp(filename_template);
62
62
  if (fd == -1) {
63
- gpr_log(GPR_ERROR, "mkstemp failed for template %s with error %s.",
64
- template, strerror(errno));
63
+ gpr_log(GPR_ERROR, "mkstemp failed for filename_template %s with error %s.",
64
+ filename_template, strerror(errno));
65
65
  goto end;
66
66
  }
67
67
  result = fdopen(fd, "w+");
68
68
  if (result == NULL) {
69
69
  gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).",
70
- template, fd, strerror(errno));
71
- unlink(template);
70
+ filename_template, fd, strerror(errno));
71
+ unlink(filename_template);
72
72
  close(fd);
73
73
  goto end;
74
74
  }
75
75
 
76
76
  end:
77
77
  if (result != NULL && tmp_filename != NULL) {
78
- *tmp_filename = template;
78
+ *tmp_filename = filename_template;
79
79
  } else {
80
- gpr_free(template);
80
+ gpr_free(filename_template);
81
81
  }
82
82
  return result;
83
83
  }
@@ -81,7 +81,9 @@ void grpc_alarm_cancel(grpc_alarm *alarm) {
81
81
  }
82
82
 
83
83
  void grpc_alarm_destroy(grpc_alarm *alarm) {
84
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
84
85
  grpc_alarm_cancel(alarm);
85
- GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm");
86
+ GRPC_CQ_INTERNAL_UNREF(&exec_ctx, alarm->cq, "alarm");
86
87
  gpr_free(alarm);
88
+ grpc_exec_ctx_finish(&exec_ctx);
87
89
  }
@@ -32,5 +32,6 @@
32
32
  */
33
33
 
34
34
  #include "src/core/lib/surface/api_trace.h"
35
+ #include "src/core/lib/debug/trace.h"
35
36
 
36
- int grpc_api_trace = 0;
37
+ grpc_tracer_flag grpc_api_trace = GRPC_TRACER_INITIALIZER(false);
@@ -37,7 +37,7 @@
37
37
  #include <grpc/support/log.h>
38
38
  #include "src/core/lib/debug/trace.h"
39
39
 
40
- extern int grpc_api_trace;
40
+ extern grpc_tracer_flag grpc_api_trace;
41
41
 
42
42
  /* Provide unwrapping macros because we're in C89 and variadic macros weren't
43
43
  introduced until C99... */
@@ -58,7 +58,7 @@ extern int grpc_api_trace;
58
58
  /* Due to the limitations of C89's preprocessor, the arity of the var-arg list
59
59
  'nargs' must be specified. */
60
60
  #define GRPC_API_TRACE(fmt, nargs, args) \
61
- if (grpc_api_trace) { \
61
+ if (GRPC_TRACER_ON(grpc_api_trace)) { \
62
62
  gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \
63
63
  }
64
64
 
@@ -124,7 +124,7 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader) {
124
124
  grpc_slice in_slice;
125
125
  size_t bytes_read = 0;
126
126
  const size_t input_size = grpc_byte_buffer_length(reader->buffer_out);
127
- grpc_slice out_slice = grpc_slice_malloc(input_size);
127
+ grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size);
128
128
  uint8_t *const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */
129
129
 
130
130
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -160,6 +160,7 @@ typedef struct {
160
160
  } child_call;
161
161
 
162
162
  struct grpc_call {
163
+ gpr_refcount ext_ref;
163
164
  gpr_arena *arena;
164
165
  grpc_completion_queue *cq;
165
166
  grpc_polling_entity pollent;
@@ -170,7 +171,7 @@ struct grpc_call {
170
171
 
171
172
  /* client or server call */
172
173
  bool is_client;
173
- /** has grpc_call_destroy been called */
174
+ /** has grpc_call_unref been called */
174
175
  bool destroy_called;
175
176
  /** flag indicating that cancellation is inherited */
176
177
  bool cancellation_is_inherited;
@@ -243,7 +244,8 @@ struct grpc_call {
243
244
  void *saved_receiving_stream_ready_bctlp;
244
245
  };
245
246
 
246
- int grpc_call_error_trace = 0;
247
+ grpc_tracer_flag grpc_call_error_trace = GRPC_TRACER_INITIALIZER(false);
248
+ grpc_tracer_flag grpc_compression_trace = GRPC_TRACER_INITIALIZER(false);
247
249
 
248
250
  #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1))
249
251
  #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1)
@@ -282,6 +284,10 @@ static void add_init_error(grpc_error **composite, grpc_error *new) {
282
284
  *composite = grpc_error_add_child(*composite, new);
283
285
  }
284
286
 
287
+ void *grpc_call_arena_alloc(grpc_call *call, size_t size) {
288
+ return gpr_arena_alloc(call->arena, size);
289
+ }
290
+
285
291
  static parent_call *get_or_create_parent_call(grpc_call *call) {
286
292
  parent_call *p = (parent_call *)gpr_atm_acq_load(&call->parent_call_atm);
287
293
  if (p == NULL) {
@@ -312,6 +318,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
312
318
  gpr_arena_create(grpc_channel_get_call_size_estimate(args->channel));
313
319
  call = gpr_arena_alloc(arena,
314
320
  sizeof(grpc_call) + channel_stack->call_stack_size);
321
+ gpr_ref_init(&call->ext_ref, 1);
315
322
  call->arena = arena;
316
323
  *out_call = call;
317
324
  call->channel = args->channel;
@@ -346,6 +353,8 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
346
353
  gpr_timespec send_deadline =
347
354
  gpr_convert_clock_type(args->send_deadline, GPR_CLOCK_MONOTONIC);
348
355
 
356
+ bool immediately_cancel = false;
357
+
349
358
  if (args->parent_call != NULL) {
350
359
  child_call *cc = call->child_call =
351
360
  gpr_arena_alloc(arena, sizeof(child_call));
@@ -386,8 +395,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
386
395
  if (args->propagation_mask & GRPC_PROPAGATE_CANCELLATION) {
387
396
  call->cancellation_is_inherited = 1;
388
397
  if (gpr_atm_acq_load(&args->parent_call->received_final_op_atm)) {
389
- cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE,
390
- GRPC_ERROR_CANCELLED);
398
+ immediately_cancel = true;
391
399
  }
392
400
  }
393
401
 
@@ -407,7 +415,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
407
415
  call->send_deadline = send_deadline;
408
416
 
409
417
  GRPC_CHANNEL_INTERNAL_REF(args->channel, "call");
410
- /* initial refcount dropped by grpc_call_destroy */
418
+ /* initial refcount dropped by grpc_call_unref */
411
419
  grpc_call_element_args call_args = {
412
420
  .call_stack = CALL_STACK_FROM_CALL(call),
413
421
  .server_transport_data = args->server_transport_data,
@@ -422,6 +430,10 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
422
430
  cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE,
423
431
  GRPC_ERROR_REF(error));
424
432
  }
433
+ if (immediately_cancel) {
434
+ cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE,
435
+ GRPC_ERROR_CANCELLED);
436
+ }
425
437
  if (args->cq != NULL) {
426
438
  GPR_ASSERT(
427
439
  args->pollset_set_alternative == NULL &&
@@ -509,7 +521,7 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call,
509
521
  }
510
522
  }
511
523
  if (c->cq) {
512
- GRPC_CQ_INTERNAL_UNREF(c->cq, "bind");
524
+ GRPC_CQ_INTERNAL_UNREF(exec_ctx, c->cq, "bind");
513
525
  }
514
526
 
515
527
  get_final_status(call, set_status_value_directly, &c->final_info.final_status,
@@ -528,12 +540,16 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call,
528
540
  GPR_TIMER_END("destroy_call", 0);
529
541
  }
530
542
 
531
- void grpc_call_destroy(grpc_call *c) {
543
+ void grpc_call_ref(grpc_call *c) { gpr_ref(&c->ext_ref); }
544
+
545
+ void grpc_call_unref(grpc_call *c) {
546
+ if (!gpr_unref(&c->ext_ref)) return;
547
+
532
548
  child_call *cc = c->child_call;
533
549
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
534
550
 
535
- GPR_TIMER_BEGIN("grpc_call_destroy", 0);
536
- GRPC_API_TRACE("grpc_call_destroy(c=%p)", 1, (c));
551
+ GPR_TIMER_BEGIN("grpc_call_unref", 0);
552
+ GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c));
537
553
 
538
554
  if (cc) {
539
555
  parent_call *pc = get_parent_call(cc->parent);
@@ -560,7 +576,7 @@ void grpc_call_destroy(grpc_call *c) {
560
576
  }
561
577
  GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy");
562
578
  grpc_exec_ctx_finish(&exec_ctx);
563
- GPR_TIMER_END("grpc_call_destroy", 0);
579
+ GPR_TIMER_END("grpc_call_unref", 0);
564
580
  }
565
581
 
566
582
  grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) {
@@ -686,7 +702,7 @@ static void get_final_status(grpc_call *call,
686
702
  for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
687
703
  status[i] = unpack_received_status(gpr_atm_acq_load(&call->status[i]));
688
704
  }
689
- if (grpc_call_error_trace) {
705
+ if (GRPC_TRACER_ON(grpc_call_error_trace)) {
690
706
  gpr_log(GPR_DEBUG, "get_final_status %s", call->is_client ? "CLI" : "SVR");
691
707
  for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
692
708
  if (status[i].is_set) {
@@ -1187,6 +1203,7 @@ static void finish_batch_step(grpc_exec_ctx *exec_ctx, batch_control *bctl) {
1187
1203
 
1188
1204
  static void continue_receiving_slices(grpc_exec_ctx *exec_ctx,
1189
1205
  batch_control *bctl) {
1206
+ grpc_error *error;
1190
1207
  grpc_call *call = bctl->call;
1191
1208
  for (;;) {
1192
1209
  size_t remaining = call->receiving_stream->length -
@@ -1198,11 +1215,22 @@ static void continue_receiving_slices(grpc_exec_ctx *exec_ctx,
1198
1215
  finish_batch_step(exec_ctx, bctl);
1199
1216
  return;
1200
1217
  }
1201
- if (grpc_byte_stream_next(exec_ctx, call->receiving_stream,
1202
- &call->receiving_slice, remaining,
1218
+ if (grpc_byte_stream_next(exec_ctx, call->receiving_stream, remaining,
1203
1219
  &call->receiving_slice_ready)) {
1204
- grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer,
1205
- call->receiving_slice);
1220
+ error = grpc_byte_stream_pull(exec_ctx, call->receiving_stream,
1221
+ &call->receiving_slice);
1222
+ if (error == GRPC_ERROR_NONE) {
1223
+ grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer,
1224
+ call->receiving_slice);
1225
+ } else {
1226
+ grpc_byte_stream_destroy(exec_ctx, call->receiving_stream);
1227
+ call->receiving_stream = NULL;
1228
+ grpc_byte_buffer_destroy(*call->receiving_buffer);
1229
+ *call->receiving_buffer = NULL;
1230
+ call->receiving_message = 0;
1231
+ finish_batch_step(exec_ctx, bctl);
1232
+ return;
1233
+ }
1206
1234
  } else {
1207
1235
  return;
1208
1236
  }
@@ -1213,20 +1241,36 @@ static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp,
1213
1241
  grpc_error *error) {
1214
1242
  batch_control *bctl = bctlp;
1215
1243
  grpc_call *call = bctl->call;
1244
+ grpc_byte_stream *bs = call->receiving_stream;
1245
+ bool release_error = false;
1216
1246
 
1217
1247
  if (error == GRPC_ERROR_NONE) {
1218
- grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer,
1219
- call->receiving_slice);
1220
- continue_receiving_slices(exec_ctx, bctl);
1221
- } else {
1222
- if (grpc_trace_operation_failures) {
1248
+ grpc_slice slice;
1249
+ error = grpc_byte_stream_pull(exec_ctx, bs, &slice);
1250
+ if (error == GRPC_ERROR_NONE) {
1251
+ grpc_slice_buffer_add(&(*call->receiving_buffer)->data.raw.slice_buffer,
1252
+ slice);
1253
+ continue_receiving_slices(exec_ctx, bctl);
1254
+ } else {
1255
+ /* Error returned by grpc_byte_stream_pull needs to be released manually
1256
+ */
1257
+ release_error = true;
1258
+ }
1259
+ }
1260
+
1261
+ if (error != GRPC_ERROR_NONE) {
1262
+ if (GRPC_TRACER_ON(grpc_trace_operation_failures)) {
1223
1263
  GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error));
1224
1264
  }
1225
1265
  grpc_byte_stream_destroy(exec_ctx, call->receiving_stream);
1226
1266
  call->receiving_stream = NULL;
1227
1267
  grpc_byte_buffer_destroy(*call->receiving_buffer);
1228
1268
  *call->receiving_buffer = NULL;
1269
+ call->receiving_message = 0;
1229
1270
  finish_batch_step(exec_ctx, bctl);
1271
+ if (release_error) {
1272
+ GRPC_ERROR_UNREF(error);
1273
+ }
1230
1274
  }
1231
1275
  }
1232
1276
 
@@ -1311,8 +1355,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx,
1311
1355
  GPR_ASSERT(call->encodings_accepted_by_peer != 0);
1312
1356
  if (!GPR_BITGET(call->encodings_accepted_by_peer,
1313
1357
  call->incoming_compression_algorithm)) {
1314
- extern int grpc_compression_trace;
1315
- if (grpc_compression_trace) {
1358
+ if (GRPC_TRACER_ON(grpc_compression_trace)) {
1316
1359
  char *algo_name = NULL;
1317
1360
  grpc_compression_algorithm_name(call->incoming_compression_algorithm,
1318
1361
  &algo_name);