grpc 1.26.0 → 1.27.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,250 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // Each active thread has an ThreadIdentity that may represent the thread in
16
+ // various level interfaces. ThreadIdentity objects are never deallocated.
17
+ // When a thread terminates, its ThreadIdentity object may be reused for a
18
+ // thread created later.
19
+
20
+ #ifndef ABSL_BASE_INTERNAL_THREAD_IDENTITY_H_
21
+ #define ABSL_BASE_INTERNAL_THREAD_IDENTITY_H_
22
+
23
+ #ifndef _WIN32
24
+ #include <pthread.h>
25
+ // Defines __GOOGLE_GRTE_VERSION__ (via glibc-specific features.h) when
26
+ // supported.
27
+ #include <unistd.h>
28
+ #endif
29
+
30
+ #include <atomic>
31
+ #include <cstdint>
32
+
33
+ #include "absl/base/internal/per_thread_tls.h"
34
+
35
+ namespace absl {
36
+ ABSL_NAMESPACE_BEGIN
37
+
38
+ struct SynchLocksHeld;
39
+ struct SynchWaitParams;
40
+
41
+ namespace base_internal {
42
+
43
+ class SpinLock;
44
+ struct ThreadIdentity;
45
+
46
+ // Used by the implementation of absl::Mutex and absl::CondVar.
47
+ struct PerThreadSynch {
48
+ // The internal representation of absl::Mutex and absl::CondVar rely
49
+ // on the alignment of PerThreadSynch. Both store the address of the
50
+ // PerThreadSynch in the high-order bits of their internal state,
51
+ // which means the low kLowZeroBits of the address of PerThreadSynch
52
+ // must be zero.
53
+ static constexpr int kLowZeroBits = 8;
54
+ static constexpr int kAlignment = 1 << kLowZeroBits;
55
+
56
+ // Returns the associated ThreadIdentity.
57
+ // This can be implemented as a cast because we guarantee
58
+ // PerThreadSynch is the first element of ThreadIdentity.
59
+ ThreadIdentity* thread_identity() {
60
+ return reinterpret_cast<ThreadIdentity*>(this);
61
+ }
62
+
63
+ PerThreadSynch *next; // Circular waiter queue; initialized to 0.
64
+ PerThreadSynch *skip; // If non-zero, all entries in Mutex queue
65
+ // up to and including "skip" have same
66
+ // condition as this, and will be woken later
67
+ bool may_skip; // if false while on mutex queue, a mutex unlocker
68
+ // is using this PerThreadSynch as a terminator. Its
69
+ // skip field must not be filled in because the loop
70
+ // might then skip over the terminator.
71
+
72
+ // The wait parameters of the current wait. waitp is null if the
73
+ // thread is not waiting. Transitions from null to non-null must
74
+ // occur before the enqueue commit point (state = kQueued in
75
+ // Enqueue() and CondVarEnqueue()). Transitions from non-null to
76
+ // null must occur after the wait is finished (state = kAvailable in
77
+ // Mutex::Block() and CondVar::WaitCommon()). This field may be
78
+ // changed only by the thread that describes this PerThreadSynch. A
79
+ // special case is Fer(), which calls Enqueue() on another thread,
80
+ // but with an identical SynchWaitParams pointer, thus leaving the
81
+ // pointer unchanged.
82
+ SynchWaitParams *waitp;
83
+
84
+ bool suppress_fatal_errors; // If true, try to proceed even in the face of
85
+ // broken invariants. This is used within fatal
86
+ // signal handlers to improve the chances of
87
+ // debug logging information being output
88
+ // successfully.
89
+
90
+ intptr_t readers; // Number of readers in mutex.
91
+ int priority; // Priority of thread (updated every so often).
92
+
93
+ // When priority will next be read (cycles).
94
+ int64_t next_priority_read_cycles;
95
+
96
+ // State values:
97
+ // kAvailable: This PerThreadSynch is available.
98
+ // kQueued: This PerThreadSynch is unavailable, it's currently queued on a
99
+ // Mutex or CondVar waistlist.
100
+ //
101
+ // Transitions from kQueued to kAvailable require a release
102
+ // barrier. This is needed as a waiter may use "state" to
103
+ // independently observe that it's no longer queued.
104
+ //
105
+ // Transitions from kAvailable to kQueued require no barrier, they
106
+ // are externally ordered by the Mutex.
107
+ enum State {
108
+ kAvailable,
109
+ kQueued
110
+ };
111
+ std::atomic<State> state;
112
+
113
+ bool maybe_unlocking; // Valid at head of Mutex waiter queue;
114
+ // true if UnlockSlow could be searching
115
+ // for a waiter to wake. Used for an optimization
116
+ // in Enqueue(). true is always a valid value.
117
+ // Can be reset to false when the unlocker or any
118
+ // writer releases the lock, or a reader fully releases
119
+ // the lock. It may not be set to false by a reader
120
+ // that decrements the count to non-zero.
121
+ // protected by mutex spinlock
122
+
123
+ bool wake; // This thread is to be woken from a Mutex.
124
+
125
+ // If "x" is on a waiter list for a mutex, "x->cond_waiter" is true iff the
126
+ // waiter is waiting on the mutex as part of a CV Wait or Mutex Await.
127
+ //
128
+ // The value of "x->cond_waiter" is meaningless if "x" is not on a
129
+ // Mutex waiter list.
130
+ bool cond_waiter;
131
+
132
+ // Locks held; used during deadlock detection.
133
+ // Allocated in Synch_GetAllLocks() and freed in ReclaimThreadIdentity().
134
+ SynchLocksHeld *all_locks;
135
+ };
136
+
137
+ struct ThreadIdentity {
138
+ // Must be the first member. The Mutex implementation requires that
139
+ // the PerThreadSynch object associated with each thread is
140
+ // PerThreadSynch::kAlignment aligned. We provide this alignment on
141
+ // ThreadIdentity itself.
142
+ PerThreadSynch per_thread_synch;
143
+
144
+ // Private: Reserved for absl::synchronization_internal::Waiter.
145
+ struct WaiterState {
146
+ char data[128];
147
+ } waiter_state;
148
+
149
+ // Used by PerThreadSem::{Get,Set}ThreadBlockedCounter().
150
+ std::atomic<int>* blocked_count_ptr;
151
+
152
+ // The following variables are mostly read/written just by the
153
+ // thread itself. The only exception is that these are read by
154
+ // a ticker thread as a hint.
155
+ std::atomic<int> ticker; // Tick counter, incremented once per second.
156
+ std::atomic<int> wait_start; // Ticker value when thread started waiting.
157
+ std::atomic<bool> is_idle; // Has thread become idle yet?
158
+
159
+ ThreadIdentity* next;
160
+ };
161
+
162
+ // Returns the ThreadIdentity object representing the calling thread; guaranteed
163
+ // to be unique for its lifetime. The returned object will remain valid for the
164
+ // program's lifetime; although it may be re-assigned to a subsequent thread.
165
+ // If one does not exist, return nullptr instead.
166
+ //
167
+ // Does not malloc(*), and is async-signal safe.
168
+ // [*] Technically pthread_setspecific() does malloc on first use; however this
169
+ // is handled internally within tcmalloc's initialization already.
170
+ //
171
+ // New ThreadIdentity objects can be constructed and associated with a thread
172
+ // by calling GetOrCreateCurrentThreadIdentity() in per-thread-sem.h.
173
+ ThreadIdentity* CurrentThreadIdentityIfPresent();
174
+
175
+ using ThreadIdentityReclaimerFunction = void (*)(void*);
176
+
177
+ // Sets the current thread identity to the given value. 'reclaimer' is a
178
+ // pointer to the global function for cleaning up instances on thread
179
+ // destruction.
180
+ void SetCurrentThreadIdentity(ThreadIdentity* identity,
181
+ ThreadIdentityReclaimerFunction reclaimer);
182
+
183
+ // Removes the currently associated ThreadIdentity from the running thread.
184
+ // This must be called from inside the ThreadIdentityReclaimerFunction, and only
185
+ // from that function.
186
+ void ClearCurrentThreadIdentity();
187
+
188
+ // May be chosen at compile time via: -DABSL_FORCE_THREAD_IDENTITY_MODE=<mode
189
+ // index>
190
+ #ifdef ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
191
+ #error ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC cannot be direcly set
192
+ #else
193
+ #define ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC 0
194
+ #endif
195
+
196
+ #ifdef ABSL_THREAD_IDENTITY_MODE_USE_TLS
197
+ #error ABSL_THREAD_IDENTITY_MODE_USE_TLS cannot be direcly set
198
+ #else
199
+ #define ABSL_THREAD_IDENTITY_MODE_USE_TLS 1
200
+ #endif
201
+
202
+ #ifdef ABSL_THREAD_IDENTITY_MODE_USE_CPP11
203
+ #error ABSL_THREAD_IDENTITY_MODE_USE_CPP11 cannot be direcly set
204
+ #else
205
+ #define ABSL_THREAD_IDENTITY_MODE_USE_CPP11 2
206
+ #endif
207
+
208
+ #ifdef ABSL_THREAD_IDENTITY_MODE
209
+ #error ABSL_THREAD_IDENTITY_MODE cannot be direcly set
210
+ #elif defined(ABSL_FORCE_THREAD_IDENTITY_MODE)
211
+ #define ABSL_THREAD_IDENTITY_MODE ABSL_FORCE_THREAD_IDENTITY_MODE
212
+ #elif defined(_WIN32) && !defined(__MINGW32__)
213
+ #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11
214
+ #elif ABSL_PER_THREAD_TLS && defined(__GOOGLE_GRTE_VERSION__) && \
215
+ (__GOOGLE_GRTE_VERSION__ >= 20140228L)
216
+ // Support for async-safe TLS was specifically added in GRTEv4. It's not
217
+ // present in the upstream eglibc.
218
+ // Note: Current default for production systems.
219
+ #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_TLS
220
+ #else
221
+ #define ABSL_THREAD_IDENTITY_MODE \
222
+ ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
223
+ #endif
224
+
225
+ #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \
226
+ ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
227
+
228
+ #if ABSL_PER_THREAD_TLS
229
+ ABSL_CONST_INIT extern ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity*
230
+ thread_identity_ptr;
231
+ #elif defined(ABSL_HAVE_THREAD_LOCAL)
232
+ ABSL_CONST_INIT extern thread_local ThreadIdentity* thread_identity_ptr;
233
+ #else
234
+ #error Thread-local storage not detected on this platform
235
+ #endif
236
+
237
+ inline ThreadIdentity* CurrentThreadIdentityIfPresent() {
238
+ return thread_identity_ptr;
239
+ }
240
+
241
+ #elif ABSL_THREAD_IDENTITY_MODE != \
242
+ ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
243
+ #error Unknown ABSL_THREAD_IDENTITY_MODE
244
+ #endif
245
+
246
+ } // namespace base_internal
247
+ ABSL_NAMESPACE_END
248
+ } // namespace absl
249
+
250
+ #endif // ABSL_BASE_INTERNAL_THREAD_IDENTITY_H_
@@ -0,0 +1,108 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "absl/base/internal/throw_delegate.h"
16
+
17
+ #include <cstdlib>
18
+ #include <functional>
19
+ #include <new>
20
+ #include <stdexcept>
21
+ #include "absl/base/config.h"
22
+ #include "absl/base/internal/raw_logging.h"
23
+
24
+ namespace absl {
25
+ ABSL_NAMESPACE_BEGIN
26
+ namespace base_internal {
27
+
28
+ namespace {
29
+ template <typename T>
30
+ [[noreturn]] void Throw(const T& error) {
31
+ #ifdef ABSL_HAVE_EXCEPTIONS
32
+ throw error;
33
+ #else
34
+ ABSL_RAW_LOG(FATAL, "%s", error.what());
35
+ std::abort();
36
+ #endif
37
+ }
38
+ } // namespace
39
+
40
+ void ThrowStdLogicError(const std::string& what_arg) {
41
+ Throw(std::logic_error(what_arg));
42
+ }
43
+ void ThrowStdLogicError(const char* what_arg) {
44
+ Throw(std::logic_error(what_arg));
45
+ }
46
+ void ThrowStdInvalidArgument(const std::string& what_arg) {
47
+ Throw(std::invalid_argument(what_arg));
48
+ }
49
+ void ThrowStdInvalidArgument(const char* what_arg) {
50
+ Throw(std::invalid_argument(what_arg));
51
+ }
52
+
53
+ void ThrowStdDomainError(const std::string& what_arg) {
54
+ Throw(std::domain_error(what_arg));
55
+ }
56
+ void ThrowStdDomainError(const char* what_arg) {
57
+ Throw(std::domain_error(what_arg));
58
+ }
59
+
60
+ void ThrowStdLengthError(const std::string& what_arg) {
61
+ Throw(std::length_error(what_arg));
62
+ }
63
+ void ThrowStdLengthError(const char* what_arg) {
64
+ Throw(std::length_error(what_arg));
65
+ }
66
+
67
+ void ThrowStdOutOfRange(const std::string& what_arg) {
68
+ Throw(std::out_of_range(what_arg));
69
+ }
70
+ void ThrowStdOutOfRange(const char* what_arg) {
71
+ Throw(std::out_of_range(what_arg));
72
+ }
73
+
74
+ void ThrowStdRuntimeError(const std::string& what_arg) {
75
+ Throw(std::runtime_error(what_arg));
76
+ }
77
+ void ThrowStdRuntimeError(const char* what_arg) {
78
+ Throw(std::runtime_error(what_arg));
79
+ }
80
+
81
+ void ThrowStdRangeError(const std::string& what_arg) {
82
+ Throw(std::range_error(what_arg));
83
+ }
84
+ void ThrowStdRangeError(const char* what_arg) {
85
+ Throw(std::range_error(what_arg));
86
+ }
87
+
88
+ void ThrowStdOverflowError(const std::string& what_arg) {
89
+ Throw(std::overflow_error(what_arg));
90
+ }
91
+ void ThrowStdOverflowError(const char* what_arg) {
92
+ Throw(std::overflow_error(what_arg));
93
+ }
94
+
95
+ void ThrowStdUnderflowError(const std::string& what_arg) {
96
+ Throw(std::underflow_error(what_arg));
97
+ }
98
+ void ThrowStdUnderflowError(const char* what_arg) {
99
+ Throw(std::underflow_error(what_arg));
100
+ }
101
+
102
+ void ThrowStdBadFunctionCall() { Throw(std::bad_function_call()); }
103
+
104
+ void ThrowStdBadAlloc() { Throw(std::bad_alloc()); }
105
+
106
+ } // namespace base_internal
107
+ ABSL_NAMESPACE_END
108
+ } // namespace absl
@@ -0,0 +1,75 @@
1
+ //
2
+ // Copyright 2017 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+
17
+ #ifndef ABSL_BASE_INTERNAL_THROW_DELEGATE_H_
18
+ #define ABSL_BASE_INTERNAL_THROW_DELEGATE_H_
19
+
20
+ #include <string>
21
+
22
+ #include "absl/base/config.h"
23
+
24
+ namespace absl {
25
+ ABSL_NAMESPACE_BEGIN
26
+ namespace base_internal {
27
+
28
+ // Helper functions that allow throwing exceptions consistently from anywhere.
29
+ // The main use case is for header-based libraries (eg templates), as they will
30
+ // be built by many different targets with their own compiler options.
31
+ // In particular, this will allow a safe way to throw exceptions even if the
32
+ // caller is compiled with -fno-exceptions. This is intended for implementing
33
+ // things like map<>::at(), which the standard documents as throwing an
34
+ // exception on error.
35
+ //
36
+ // Using other techniques like #if tricks could lead to ODR violations.
37
+ //
38
+ // You shouldn't use it unless you're writing code that you know will be built
39
+ // both with and without exceptions and you need to conform to an interface
40
+ // that uses exceptions.
41
+
42
+ [[noreturn]] void ThrowStdLogicError(const std::string& what_arg);
43
+ [[noreturn]] void ThrowStdLogicError(const char* what_arg);
44
+ [[noreturn]] void ThrowStdInvalidArgument(const std::string& what_arg);
45
+ [[noreturn]] void ThrowStdInvalidArgument(const char* what_arg);
46
+ [[noreturn]] void ThrowStdDomainError(const std::string& what_arg);
47
+ [[noreturn]] void ThrowStdDomainError(const char* what_arg);
48
+ [[noreturn]] void ThrowStdLengthError(const std::string& what_arg);
49
+ [[noreturn]] void ThrowStdLengthError(const char* what_arg);
50
+ [[noreturn]] void ThrowStdOutOfRange(const std::string& what_arg);
51
+ [[noreturn]] void ThrowStdOutOfRange(const char* what_arg);
52
+ [[noreturn]] void ThrowStdRuntimeError(const std::string& what_arg);
53
+ [[noreturn]] void ThrowStdRuntimeError(const char* what_arg);
54
+ [[noreturn]] void ThrowStdRangeError(const std::string& what_arg);
55
+ [[noreturn]] void ThrowStdRangeError(const char* what_arg);
56
+ [[noreturn]] void ThrowStdOverflowError(const std::string& what_arg);
57
+ [[noreturn]] void ThrowStdOverflowError(const char* what_arg);
58
+ [[noreturn]] void ThrowStdUnderflowError(const std::string& what_arg);
59
+ [[noreturn]] void ThrowStdUnderflowError(const char* what_arg);
60
+
61
+ [[noreturn]] void ThrowStdBadFunctionCall();
62
+ [[noreturn]] void ThrowStdBadAlloc();
63
+
64
+ // ThrowStdBadArrayNewLength() cannot be consistently supported because
65
+ // std::bad_array_new_length is missing in libstdc++ until 4.9.0.
66
+ // https://gcc.gnu.org/onlinedocs/gcc-4.8.3/libstdc++/api/a01379_source.html
67
+ // https://gcc.gnu.org/onlinedocs/gcc-4.9.0/libstdc++/api/a01327_source.html
68
+ // libcxx (as of 3.2) and msvc (as of 2015) both have it.
69
+ // [[noreturn]] void ThrowStdBadArrayNewLength();
70
+
71
+ } // namespace base_internal
72
+ ABSL_NAMESPACE_END
73
+ } // namespace absl
74
+
75
+ #endif // ABSL_BASE_INTERNAL_THROW_DELEGATE_H_
@@ -0,0 +1,66 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // This file is intended solely for spinlock.h.
16
+ // It provides ThreadSanitizer annotations for custom mutexes.
17
+ // See <sanitizer/tsan_interface.h> for meaning of these annotations.
18
+
19
+ #ifndef ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
20
+ #define ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
21
+
22
+ // ABSL_INTERNAL_HAVE_TSAN_INTERFACE
23
+ // Macro intended only for internal use.
24
+ //
25
+ // Checks whether LLVM Thread Sanitizer interfaces are available.
26
+ // First made available in LLVM 5.0 (Sep 2017).
27
+ #ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
28
+ #error "ABSL_INTERNAL_HAVE_TSAN_INTERFACE cannot be directly set."
29
+ #endif
30
+
31
+ #if defined(THREAD_SANITIZER) && defined(__has_include)
32
+ #if __has_include(<sanitizer/tsan_interface.h>)
33
+ #define ABSL_INTERNAL_HAVE_TSAN_INTERFACE 1
34
+ #endif
35
+ #endif
36
+
37
+ #ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
38
+ #include <sanitizer/tsan_interface.h>
39
+
40
+ #define ABSL_TSAN_MUTEX_CREATE __tsan_mutex_create
41
+ #define ABSL_TSAN_MUTEX_DESTROY __tsan_mutex_destroy
42
+ #define ABSL_TSAN_MUTEX_PRE_LOCK __tsan_mutex_pre_lock
43
+ #define ABSL_TSAN_MUTEX_POST_LOCK __tsan_mutex_post_lock
44
+ #define ABSL_TSAN_MUTEX_PRE_UNLOCK __tsan_mutex_pre_unlock
45
+ #define ABSL_TSAN_MUTEX_POST_UNLOCK __tsan_mutex_post_unlock
46
+ #define ABSL_TSAN_MUTEX_PRE_SIGNAL __tsan_mutex_pre_signal
47
+ #define ABSL_TSAN_MUTEX_POST_SIGNAL __tsan_mutex_post_signal
48
+ #define ABSL_TSAN_MUTEX_PRE_DIVERT __tsan_mutex_pre_divert
49
+ #define ABSL_TSAN_MUTEX_POST_DIVERT __tsan_mutex_post_divert
50
+
51
+ #else
52
+
53
+ #define ABSL_TSAN_MUTEX_CREATE(...)
54
+ #define ABSL_TSAN_MUTEX_DESTROY(...)
55
+ #define ABSL_TSAN_MUTEX_PRE_LOCK(...)
56
+ #define ABSL_TSAN_MUTEX_POST_LOCK(...)
57
+ #define ABSL_TSAN_MUTEX_PRE_UNLOCK(...)
58
+ #define ABSL_TSAN_MUTEX_POST_UNLOCK(...)
59
+ #define ABSL_TSAN_MUTEX_PRE_SIGNAL(...)
60
+ #define ABSL_TSAN_MUTEX_POST_SIGNAL(...)
61
+ #define ABSL_TSAN_MUTEX_PRE_DIVERT(...)
62
+ #define ABSL_TSAN_MUTEX_POST_DIVERT(...)
63
+
64
+ #endif
65
+
66
+ #endif // ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_