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,226 @@
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
+ // -----------------------------------------------------------------------------
16
+ // File: call_once.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file provides an Abseil version of `std::call_once` for invoking
20
+ // a given function at most once, across all threads. This Abseil version is
21
+ // faster than the C++11 version and incorporates the C++17 argument-passing
22
+ // fix, so that (for example) non-const references may be passed to the invoked
23
+ // function.
24
+
25
+ #ifndef ABSL_BASE_CALL_ONCE_H_
26
+ #define ABSL_BASE_CALL_ONCE_H_
27
+
28
+ #include <algorithm>
29
+ #include <atomic>
30
+ #include <cstdint>
31
+ #include <type_traits>
32
+ #include <utility>
33
+
34
+ #include "absl/base/internal/invoke.h"
35
+ #include "absl/base/internal/low_level_scheduling.h"
36
+ #include "absl/base/internal/raw_logging.h"
37
+ #include "absl/base/internal/scheduling_mode.h"
38
+ #include "absl/base/internal/spinlock_wait.h"
39
+ #include "absl/base/macros.h"
40
+ #include "absl/base/optimization.h"
41
+ #include "absl/base/port.h"
42
+
43
+ namespace absl {
44
+ ABSL_NAMESPACE_BEGIN
45
+
46
+ class once_flag;
47
+
48
+ namespace base_internal {
49
+ std::atomic<uint32_t>* ControlWord(absl::once_flag* flag);
50
+ } // namespace base_internal
51
+
52
+ // call_once()
53
+ //
54
+ // For all invocations using a given `once_flag`, invokes a given `fn` exactly
55
+ // once across all threads. The first call to `call_once()` with a particular
56
+ // `once_flag` argument (that does not throw an exception) will run the
57
+ // specified function with the provided `args`; other calls with the same
58
+ // `once_flag` argument will not run the function, but will wait
59
+ // for the provided function to finish running (if it is still running).
60
+ //
61
+ // This mechanism provides a safe, simple, and fast mechanism for one-time
62
+ // initialization in a multi-threaded process.
63
+ //
64
+ // Example:
65
+ //
66
+ // class MyInitClass {
67
+ // public:
68
+ // ...
69
+ // mutable absl::once_flag once_;
70
+ //
71
+ // MyInitClass* init() const {
72
+ // absl::call_once(once_, &MyInitClass::Init, this);
73
+ // return ptr_;
74
+ // }
75
+ //
76
+ template <typename Callable, typename... Args>
77
+ void call_once(absl::once_flag& flag, Callable&& fn, Args&&... args);
78
+
79
+ // once_flag
80
+ //
81
+ // Objects of this type are used to distinguish calls to `call_once()` and
82
+ // ensure the provided function is only invoked once across all threads. This
83
+ // type is not copyable or movable. However, it has a `constexpr`
84
+ // constructor, and is safe to use as a namespace-scoped global variable.
85
+ class once_flag {
86
+ public:
87
+ constexpr once_flag() : control_(0) {}
88
+ once_flag(const once_flag&) = delete;
89
+ once_flag& operator=(const once_flag&) = delete;
90
+
91
+ private:
92
+ friend std::atomic<uint32_t>* base_internal::ControlWord(once_flag* flag);
93
+ std::atomic<uint32_t> control_;
94
+ };
95
+
96
+ //------------------------------------------------------------------------------
97
+ // End of public interfaces.
98
+ // Implementation details follow.
99
+ //------------------------------------------------------------------------------
100
+
101
+ namespace base_internal {
102
+
103
+ // Like call_once, but uses KERNEL_ONLY scheduling. Intended to be used to
104
+ // initialize entities used by the scheduler implementation.
105
+ template <typename Callable, typename... Args>
106
+ void LowLevelCallOnce(absl::once_flag* flag, Callable&& fn, Args&&... args);
107
+
108
+ // Disables scheduling while on stack when scheduling mode is non-cooperative.
109
+ // No effect for cooperative scheduling modes.
110
+ class SchedulingHelper {
111
+ public:
112
+ explicit SchedulingHelper(base_internal::SchedulingMode mode) : mode_(mode) {
113
+ if (mode_ == base_internal::SCHEDULE_KERNEL_ONLY) {
114
+ guard_result_ = base_internal::SchedulingGuard::DisableRescheduling();
115
+ }
116
+ }
117
+
118
+ ~SchedulingHelper() {
119
+ if (mode_ == base_internal::SCHEDULE_KERNEL_ONLY) {
120
+ base_internal::SchedulingGuard::EnableRescheduling(guard_result_);
121
+ }
122
+ }
123
+
124
+ private:
125
+ base_internal::SchedulingMode mode_;
126
+ bool guard_result_;
127
+ };
128
+
129
+ // Bit patterns for call_once state machine values. Internal implementation
130
+ // detail, not for use by clients.
131
+ //
132
+ // The bit patterns are arbitrarily chosen from unlikely values, to aid in
133
+ // debugging. However, kOnceInit must be 0, so that a zero-initialized
134
+ // once_flag will be valid for immediate use.
135
+ enum {
136
+ kOnceInit = 0,
137
+ kOnceRunning = 0x65C2937B,
138
+ kOnceWaiter = 0x05A308D2,
139
+ // A very small constant is chosen for kOnceDone so that it fit in a single
140
+ // compare with immediate instruction for most common ISAs. This is verified
141
+ // for x86, POWER and ARM.
142
+ kOnceDone = 221, // Random Number
143
+ };
144
+
145
+ template <typename Callable, typename... Args>
146
+ ABSL_ATTRIBUTE_NOINLINE
147
+ void CallOnceImpl(std::atomic<uint32_t>* control,
148
+ base_internal::SchedulingMode scheduling_mode, Callable&& fn,
149
+ Args&&... args) {
150
+ #ifndef NDEBUG
151
+ {
152
+ uint32_t old_control = control->load(std::memory_order_relaxed);
153
+ if (old_control != kOnceInit &&
154
+ old_control != kOnceRunning &&
155
+ old_control != kOnceWaiter &&
156
+ old_control != kOnceDone) {
157
+ ABSL_RAW_LOG(FATAL, "Unexpected value for control word: 0x%lx",
158
+ static_cast<unsigned long>(old_control)); // NOLINT
159
+ }
160
+ }
161
+ #endif // NDEBUG
162
+ static const base_internal::SpinLockWaitTransition trans[] = {
163
+ {kOnceInit, kOnceRunning, true},
164
+ {kOnceRunning, kOnceWaiter, false},
165
+ {kOnceDone, kOnceDone, true}};
166
+
167
+ // Must do this before potentially modifying control word's state.
168
+ base_internal::SchedulingHelper maybe_disable_scheduling(scheduling_mode);
169
+ // Short circuit the simplest case to avoid procedure call overhead.
170
+ // The base_internal::SpinLockWait() call returns either kOnceInit or
171
+ // kOnceDone. If it returns kOnceDone, it must have loaded the control word
172
+ // with std::memory_order_acquire and seen a value of kOnceDone.
173
+ uint32_t old_control = kOnceInit;
174
+ if (control->compare_exchange_strong(old_control, kOnceRunning,
175
+ std::memory_order_relaxed) ||
176
+ base_internal::SpinLockWait(control, ABSL_ARRAYSIZE(trans), trans,
177
+ scheduling_mode) == kOnceInit) {
178
+ base_internal::Invoke(std::forward<Callable>(fn),
179
+ std::forward<Args>(args)...);
180
+ // The call to SpinLockWake below is an optimization, because the waiter
181
+ // in SpinLockWait is waiting with a short timeout. The atomic load/store
182
+ // sequence is slightly faster than an atomic exchange:
183
+ // old_control = control->exchange(base_internal::kOnceDone,
184
+ // std::memory_order_release);
185
+ // We opt for a slightly faster case when there are no waiters, in spite
186
+ // of longer tail latency when there are waiters.
187
+ old_control = control->load(std::memory_order_relaxed);
188
+ control->store(base_internal::kOnceDone, std::memory_order_release);
189
+ if (old_control == base_internal::kOnceWaiter) {
190
+ base_internal::SpinLockWake(control, true);
191
+ }
192
+ } // else *control is already kOnceDone
193
+ }
194
+
195
+ inline std::atomic<uint32_t>* ControlWord(once_flag* flag) {
196
+ return &flag->control_;
197
+ }
198
+
199
+ template <typename Callable, typename... Args>
200
+ void LowLevelCallOnce(absl::once_flag* flag, Callable&& fn, Args&&... args) {
201
+ std::atomic<uint32_t>* once = base_internal::ControlWord(flag);
202
+ uint32_t s = once->load(std::memory_order_acquire);
203
+ if (ABSL_PREDICT_FALSE(s != base_internal::kOnceDone)) {
204
+ base_internal::CallOnceImpl(once, base_internal::SCHEDULE_KERNEL_ONLY,
205
+ std::forward<Callable>(fn),
206
+ std::forward<Args>(args)...);
207
+ }
208
+ }
209
+
210
+ } // namespace base_internal
211
+
212
+ template <typename Callable, typename... Args>
213
+ void call_once(absl::once_flag& flag, Callable&& fn, Args&&... args) {
214
+ std::atomic<uint32_t>* once = base_internal::ControlWord(&flag);
215
+ uint32_t s = once->load(std::memory_order_acquire);
216
+ if (ABSL_PREDICT_FALSE(s != base_internal::kOnceDone)) {
217
+ base_internal::CallOnceImpl(
218
+ once, base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL,
219
+ std::forward<Callable>(fn), std::forward<Args>(args)...);
220
+ }
221
+ }
222
+
223
+ ABSL_NAMESPACE_END
224
+ } // namespace absl
225
+
226
+ #endif // ABSL_BASE_CALL_ONCE_H_
@@ -0,0 +1,184 @@
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
+ // File: casts.h
18
+ // -----------------------------------------------------------------------------
19
+ //
20
+ // This header file defines casting templates to fit use cases not covered by
21
+ // the standard casts provided in the C++ standard. As with all cast operations,
22
+ // use these with caution and only if alternatives do not exist.
23
+
24
+ #ifndef ABSL_BASE_CASTS_H_
25
+ #define ABSL_BASE_CASTS_H_
26
+
27
+ #include <cstring>
28
+ #include <memory>
29
+ #include <type_traits>
30
+ #include <utility>
31
+
32
+ #include "absl/base/internal/identity.h"
33
+ #include "absl/base/macros.h"
34
+ #include "absl/meta/type_traits.h"
35
+
36
+ namespace absl {
37
+ ABSL_NAMESPACE_BEGIN
38
+
39
+ namespace internal_casts {
40
+
41
+ template <class Dest, class Source>
42
+ struct is_bitcastable
43
+ : std::integral_constant<
44
+ bool,
45
+ sizeof(Dest) == sizeof(Source) &&
46
+ type_traits_internal::is_trivially_copyable<Source>::value &&
47
+ type_traits_internal::is_trivially_copyable<Dest>::value &&
48
+ std::is_default_constructible<Dest>::value> {};
49
+
50
+ } // namespace internal_casts
51
+
52
+ // implicit_cast()
53
+ //
54
+ // Performs an implicit conversion between types following the language
55
+ // rules for implicit conversion; if an implicit conversion is otherwise
56
+ // allowed by the language in the given context, this function performs such an
57
+ // implicit conversion.
58
+ //
59
+ // Example:
60
+ //
61
+ // // If the context allows implicit conversion:
62
+ // From from;
63
+ // To to = from;
64
+ //
65
+ // // Such code can be replaced by:
66
+ // implicit_cast<To>(from);
67
+ //
68
+ // An `implicit_cast()` may also be used to annotate numeric type conversions
69
+ // that, although safe, may produce compiler warnings (such as `long` to `int`).
70
+ // Additionally, an `implicit_cast()` is also useful within return statements to
71
+ // indicate a specific implicit conversion is being undertaken.
72
+ //
73
+ // Example:
74
+ //
75
+ // return implicit_cast<double>(size_in_bytes) / capacity_;
76
+ //
77
+ // Annotating code with `implicit_cast()` allows you to explicitly select
78
+ // particular overloads and template instantiations, while providing a safer
79
+ // cast than `reinterpret_cast()` or `static_cast()`.
80
+ //
81
+ // Additionally, an `implicit_cast()` can be used to allow upcasting within a
82
+ // type hierarchy where incorrect use of `static_cast()` could accidentally
83
+ // allow downcasting.
84
+ //
85
+ // Finally, an `implicit_cast()` can be used to perform implicit conversions
86
+ // from unrelated types that otherwise couldn't be implicitly cast directly;
87
+ // C++ will normally only implicitly cast "one step" in such conversions.
88
+ //
89
+ // That is, if C is a type which can be implicitly converted to B, with B being
90
+ // a type that can be implicitly converted to A, an `implicit_cast()` can be
91
+ // used to convert C to B (which the compiler can then implicitly convert to A
92
+ // using language rules).
93
+ //
94
+ // Example:
95
+ //
96
+ // // Assume an object C is convertible to B, which is implicitly convertible
97
+ // // to A
98
+ // A a = implicit_cast<B>(C);
99
+ //
100
+ // Such implicit cast chaining may be useful within template logic.
101
+ template <typename To>
102
+ constexpr To implicit_cast(typename absl::internal::identity_t<To> to) {
103
+ return to;
104
+ }
105
+
106
+ // bit_cast()
107
+ //
108
+ // Performs a bitwise cast on a type without changing the underlying bit
109
+ // representation of that type's value. The two types must be of the same size
110
+ // and both types must be trivially copyable. As with most casts, use with
111
+ // caution. A `bit_cast()` might be needed when you need to temporarily treat a
112
+ // type as some other type, such as in the following cases:
113
+ //
114
+ // * Serialization (casting temporarily to `char *` for those purposes is
115
+ // always allowed by the C++ standard)
116
+ // * Managing the individual bits of a type within mathematical operations
117
+ // that are not normally accessible through that type
118
+ // * Casting non-pointer types to pointer types (casting the other way is
119
+ // allowed by `reinterpret_cast()` but round-trips cannot occur the other
120
+ // way).
121
+ //
122
+ // Example:
123
+ //
124
+ // float f = 3.14159265358979;
125
+ // int i = bit_cast<int32_t>(f);
126
+ // // i = 0x40490fdb
127
+ //
128
+ // Casting non-pointer types to pointer types and then dereferencing them
129
+ // traditionally produces undefined behavior.
130
+ //
131
+ // Example:
132
+ //
133
+ // // WRONG
134
+ // float f = 3.14159265358979; // WRONG
135
+ // int i = * reinterpret_cast<int*>(&f); // WRONG
136
+ //
137
+ // The address-casting method produces undefined behavior according to the ISO
138
+ // C++ specification section [basic.lval]. Roughly, this section says: if an
139
+ // object in memory has one type, and a program accesses it with a different
140
+ // type, the result is undefined behavior for most values of "different type".
141
+ //
142
+ // Such casting results in type punning: holding an object in memory of one type
143
+ // and reading its bits back using a different type. A `bit_cast()` avoids this
144
+ // issue by implementing its casts using `memcpy()`, which avoids introducing
145
+ // this undefined behavior.
146
+ //
147
+ // NOTE: The requirements here are more strict than the bit_cast of standard
148
+ // proposal p0476 due to the need for workarounds and lack of intrinsics.
149
+ // Specifically, this implementation also requires `Dest` to be
150
+ // default-constructible.
151
+ template <
152
+ typename Dest, typename Source,
153
+ typename std::enable_if<internal_casts::is_bitcastable<Dest, Source>::value,
154
+ int>::type = 0>
155
+ inline Dest bit_cast(const Source& source) {
156
+ Dest dest;
157
+ memcpy(static_cast<void*>(std::addressof(dest)),
158
+ static_cast<const void*>(std::addressof(source)), sizeof(dest));
159
+ return dest;
160
+ }
161
+
162
+ // NOTE: This overload is only picked if the requirements of bit_cast are not
163
+ // met. It is therefore UB, but is provided temporarily as previous versions of
164
+ // this function template were unchecked. Do not use this in new code.
165
+ template <
166
+ typename Dest, typename Source,
167
+ typename std::enable_if<
168
+ !internal_casts::is_bitcastable<Dest, Source>::value, int>::type = 0>
169
+ ABSL_DEPRECATED(
170
+ "absl::bit_cast type requirements were violated. Update the types being "
171
+ "used such that they are the same size and are both TriviallyCopyable.")
172
+ inline Dest bit_cast(const Source& source) {
173
+ static_assert(sizeof(Dest) == sizeof(Source),
174
+ "Source and destination types should have equal sizes.");
175
+
176
+ Dest dest;
177
+ memcpy(&dest, &source, sizeof(dest));
178
+ return dest;
179
+ }
180
+
181
+ ABSL_NAMESPACE_END
182
+ } // namespace absl
183
+
184
+ #endif // ABSL_BASE_CASTS_H_
@@ -0,0 +1,622 @@
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
+ // File: config.h
18
+ // -----------------------------------------------------------------------------
19
+ //
20
+ // This header file defines a set of macros for checking the presence of
21
+ // important compiler and platform features. Such macros can be used to
22
+ // produce portable code by parameterizing compilation based on the presence or
23
+ // lack of a given feature.
24
+ //
25
+ // We define a "feature" as some interface we wish to program to: for example,
26
+ // a library function or system call. A value of `1` indicates support for
27
+ // that feature; any other value indicates the feature support is undefined.
28
+ //
29
+ // Example:
30
+ //
31
+ // Suppose a programmer wants to write a program that uses the 'mmap()' system
32
+ // call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
33
+ // selectively include the `mmap.h` header and bracket code using that feature
34
+ // in the macro:
35
+ //
36
+ // #include "absl/base/config.h"
37
+ //
38
+ // #ifdef ABSL_HAVE_MMAP
39
+ // #include "sys/mman.h"
40
+ // #endif //ABSL_HAVE_MMAP
41
+ //
42
+ // ...
43
+ // #ifdef ABSL_HAVE_MMAP
44
+ // void *ptr = mmap(...);
45
+ // ...
46
+ // #endif // ABSL_HAVE_MMAP
47
+
48
+ #ifndef ABSL_BASE_CONFIG_H_
49
+ #define ABSL_BASE_CONFIG_H_
50
+
51
+ // Included for the __GLIBC__ macro (or similar macros on other systems).
52
+ #include <limits.h>
53
+
54
+ #ifdef __cplusplus
55
+ // Included for __GLIBCXX__, _LIBCPP_VERSION
56
+ #include <cstddef>
57
+ #endif // __cplusplus
58
+
59
+ #if defined(__APPLE__)
60
+ // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
61
+ // __IPHONE_8_0.
62
+ #include <Availability.h>
63
+ #include <TargetConditionals.h>
64
+ #endif
65
+
66
+ #include "absl/base/options.h"
67
+ #include "absl/base/policy_checks.h"
68
+
69
+ // -----------------------------------------------------------------------------
70
+ // Abseil namespace annotations
71
+ // -----------------------------------------------------------------------------
72
+
73
+ // ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END
74
+ //
75
+ // An annotation placed at the beginning/end of each `namespace absl` scope.
76
+ // This is used to inject an inline namespace.
77
+ //
78
+ // The proper way to write Abseil code in the `absl` namespace is:
79
+ //
80
+ // namespace absl {
81
+ // ABSL_NAMESPACE_BEGIN
82
+ //
83
+ // void Foo(); // absl::Foo().
84
+ //
85
+ // ABSL_NAMESPACE_END
86
+ // } // namespace absl
87
+ //
88
+ // Users of Abseil should not use these macros, because users of Abseil should
89
+ // not write `namespace absl {` in their own code for any reason. (Abseil does
90
+ // not support forward declarations of its own types, nor does it support
91
+ // user-provided specialization of Abseil templates. Code that violates these
92
+ // rules may be broken without warning.)
93
+ #if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \
94
+ !defined(ABSL_OPTION_INLINE_NAMESPACE_NAME)
95
+ #error options.h is misconfigured.
96
+ #endif
97
+
98
+ // Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
99
+ #if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1
100
+
101
+ #define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
102
+ #define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x)
103
+ #define ABSL_INTERNAL_INLINE_NAMESPACE_STR \
104
+ ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME)
105
+
106
+ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
107
+ "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
108
+ "not be empty.");
109
+ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
110
+ ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
111
+ ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
112
+ ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
113
+ ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
114
+ "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must "
115
+ "be changed to a new, unique identifier name.");
116
+
117
+ #endif
118
+
119
+ #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
120
+ #define ABSL_NAMESPACE_BEGIN
121
+ #define ABSL_NAMESPACE_END
122
+ #elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
123
+ #define ABSL_NAMESPACE_BEGIN \
124
+ inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
125
+ #define ABSL_NAMESPACE_END }
126
+ #else
127
+ #error options.h is misconfigured.
128
+ #endif
129
+
130
+ // -----------------------------------------------------------------------------
131
+ // Compiler Feature Checks
132
+ // -----------------------------------------------------------------------------
133
+
134
+ // ABSL_HAVE_BUILTIN()
135
+ //
136
+ // Checks whether the compiler supports a Clang Feature Checking Macro, and if
137
+ // so, checks whether it supports the provided builtin function "x" where x
138
+ // is one of the functions noted in
139
+ // https://clang.llvm.org/docs/LanguageExtensions.html
140
+ //
141
+ // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
142
+ // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
143
+ #ifdef __has_builtin
144
+ #define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
145
+ #else
146
+ #define ABSL_HAVE_BUILTIN(x) 0
147
+ #endif
148
+
149
+ #if defined(__is_identifier)
150
+ #define ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
151
+ #else
152
+ #define ABSL_INTERNAL_HAS_KEYWORD(x) 0
153
+ #endif
154
+
155
+ // ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
156
+ // We assume __thread is supported on Linux when compiled with Clang or compiled
157
+ // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
158
+ #ifdef ABSL_HAVE_TLS
159
+ #error ABSL_HAVE_TLS cannot be directly set
160
+ #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
161
+ #define ABSL_HAVE_TLS 1
162
+ #endif
163
+
164
+ // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
165
+ //
166
+ // Checks whether `std::is_trivially_destructible<T>` is supported.
167
+ //
168
+ // Notes: All supported compilers using libc++ support this feature, as does
169
+ // gcc >= 4.8.1 using libstdc++, and Visual Studio.
170
+ #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
171
+ #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
172
+ #elif defined(_LIBCPP_VERSION) || \
173
+ (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
174
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
175
+ defined(_MSC_VER)
176
+ #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
177
+ #endif
178
+
179
+ // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
180
+ //
181
+ // Checks whether `std::is_trivially_default_constructible<T>` and
182
+ // `std::is_trivially_copy_constructible<T>` are supported.
183
+
184
+ // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
185
+ //
186
+ // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
187
+
188
+ // Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
189
+ // either libc++ or libstdc++, and Visual Studio (but not NVCC).
190
+ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
191
+ #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
192
+ #elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
193
+ #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
194
+ #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
195
+ (!defined(__clang__) && defined(__GNUC__) && \
196
+ (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \
197
+ (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
198
+ (defined(_MSC_VER) && !defined(__NVCC__))
199
+ #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
200
+ #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
201
+ #endif
202
+
203
+ // ABSL_HAVE_SOURCE_LOCATION_CURRENT
204
+ //
205
+ // Indicates whether `absl::SourceLocation::current()` will return useful
206
+ // information in some contexts.
207
+ #ifndef ABSL_HAVE_SOURCE_LOCATION_CURRENT
208
+ #if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
209
+ ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
210
+ #define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
211
+ #endif
212
+ #endif
213
+
214
+ // ABSL_HAVE_THREAD_LOCAL
215
+ //
216
+ // Checks whether C++11's `thread_local` storage duration specifier is
217
+ // supported.
218
+ #ifdef ABSL_HAVE_THREAD_LOCAL
219
+ #error ABSL_HAVE_THREAD_LOCAL cannot be directly set
220
+ #elif defined(__APPLE__)
221
+ // Notes:
222
+ // * Xcode's clang did not support `thread_local` until version 8, and
223
+ // even then not for all iOS < 9.0.
224
+ // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
225
+ // targeting iOS 9.x.
226
+ // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
227
+ // making __has_feature unreliable there.
228
+ //
229
+ // Otherwise, `__has_feature` is only supported by Clang so it has be inside
230
+ // `defined(__APPLE__)` check.
231
+ #if __has_feature(cxx_thread_local) && \
232
+ !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
233
+ #define ABSL_HAVE_THREAD_LOCAL 1
234
+ #endif
235
+ #else // !defined(__APPLE__)
236
+ #define ABSL_HAVE_THREAD_LOCAL 1
237
+ #endif
238
+
239
+ // There are platforms for which TLS should not be used even though the compiler
240
+ // makes it seem like it's supported (Android NDK < r12b for example).
241
+ // This is primarily because of linker problems and toolchain misconfiguration:
242
+ // Abseil does not intend to support this indefinitely. Currently, the newest
243
+ // toolchain that we intend to support that requires this behavior is the
244
+ // r11 NDK - allowing for a 5 year support window on that means this option
245
+ // is likely to be removed around June of 2021.
246
+ // TLS isn't supported until NDK r12b per
247
+ // https://developer.android.com/ndk/downloads/revision_history.html
248
+ // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
249
+ // <android/ndk-version.h>. For NDK < r16, users should define these macros,
250
+ // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
251
+ #if defined(__ANDROID__) && defined(__clang__)
252
+ #if __has_include(<android/ndk-version.h>)
253
+ #include <android/ndk-version.h>
254
+ #endif // __has_include(<android/ndk-version.h>)
255
+ #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
256
+ defined(__NDK_MINOR__) && \
257
+ ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
258
+ #undef ABSL_HAVE_TLS
259
+ #undef ABSL_HAVE_THREAD_LOCAL
260
+ #endif
261
+ #endif // defined(__ANDROID__) && defined(__clang__)
262
+
263
+ // Emscripten doesn't yet support `thread_local` or `__thread`.
264
+ // https://github.com/emscripten-core/emscripten/issues/3502
265
+ #if defined(__EMSCRIPTEN__)
266
+ #undef ABSL_HAVE_TLS
267
+ #undef ABSL_HAVE_THREAD_LOCAL
268
+ #endif // defined(__EMSCRIPTEN__)
269
+
270
+ // ABSL_HAVE_INTRINSIC_INT128
271
+ //
272
+ // Checks whether the __int128 compiler extension for a 128-bit integral type is
273
+ // supported.
274
+ //
275
+ // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
276
+ // supported, but we avoid using it in certain cases:
277
+ // * On Clang:
278
+ // * Building using Clang for Windows, where the Clang runtime library has
279
+ // 128-bit support only on LP64 architectures, but Windows is LLP64.
280
+ // * On Nvidia's nvcc:
281
+ // * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
282
+ // actually support __int128.
283
+ #ifdef ABSL_HAVE_INTRINSIC_INT128
284
+ #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
285
+ #elif defined(__SIZEOF_INT128__)
286
+ #if (defined(__clang__) && !defined(_WIN32)) || \
287
+ (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
288
+ (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
289
+ #define ABSL_HAVE_INTRINSIC_INT128 1
290
+ #elif defined(__CUDACC__)
291
+ // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
292
+ // string explaining that it has been removed starting with CUDA 9. We use
293
+ // nested #ifs because there is no short-circuiting in the preprocessor.
294
+ // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
295
+ #if __CUDACC_VER__ >= 70000
296
+ #define ABSL_HAVE_INTRINSIC_INT128 1
297
+ #endif // __CUDACC_VER__ >= 70000
298
+ #endif // defined(__CUDACC__)
299
+ #endif // ABSL_HAVE_INTRINSIC_INT128
300
+
301
+ // ABSL_HAVE_EXCEPTIONS
302
+ //
303
+ // Checks whether the compiler both supports and enables exceptions. Many
304
+ // compilers support a "no exceptions" mode that disables exceptions.
305
+ //
306
+ // Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
307
+ //
308
+ // * Code using `throw` and `try` may not compile.
309
+ // * The `noexcept` specifier will still compile and behave as normal.
310
+ // * The `noexcept` operator may still return `false`.
311
+ //
312
+ // For further details, consult the compiler's documentation.
313
+ #ifdef ABSL_HAVE_EXCEPTIONS
314
+ #error ABSL_HAVE_EXCEPTIONS cannot be directly set.
315
+
316
+ #elif defined(__clang__)
317
+ // TODO(calabrese)
318
+ // Switch to using __cpp_exceptions when we no longer support versions < 3.6.
319
+ // For details on this check, see:
320
+ // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
321
+ #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
322
+ #define ABSL_HAVE_EXCEPTIONS 1
323
+ #endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
324
+
325
+ // Handle remaining special cases and default to exceptions being supported.
326
+ #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
327
+ !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
328
+ !(defined(_MSC_VER) && !defined(_CPPUNWIND))
329
+ #define ABSL_HAVE_EXCEPTIONS 1
330
+ #endif
331
+
332
+ // -----------------------------------------------------------------------------
333
+ // Platform Feature Checks
334
+ // -----------------------------------------------------------------------------
335
+
336
+ // Currently supported operating systems and associated preprocessor
337
+ // symbols:
338
+ //
339
+ // Linux and Linux-derived __linux__
340
+ // Android __ANDROID__ (implies __linux__)
341
+ // Linux (non-Android) __linux__ && !__ANDROID__
342
+ // Darwin (macOS and iOS) __APPLE__
343
+ // Akaros (http://akaros.org) __ros__
344
+ // Windows _WIN32
345
+ // NaCL __native_client__
346
+ // AsmJS __asmjs__
347
+ // WebAssembly __wasm__
348
+ // Fuchsia __Fuchsia__
349
+ //
350
+ // Note that since Android defines both __ANDROID__ and __linux__, one
351
+ // may probe for either Linux or Android by simply testing for __linux__.
352
+
353
+ // ABSL_HAVE_MMAP
354
+ //
355
+ // Checks whether the platform has an mmap(2) implementation as defined in
356
+ // POSIX.1-2001.
357
+ #ifdef ABSL_HAVE_MMAP
358
+ #error ABSL_HAVE_MMAP cannot be directly set
359
+ #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
360
+ defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
361
+ defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
362
+ defined(__ASYLO__)
363
+ #define ABSL_HAVE_MMAP 1
364
+ #endif
365
+
366
+ // ABSL_HAVE_PTHREAD_GETSCHEDPARAM
367
+ //
368
+ // Checks whether the platform implements the pthread_(get|set)schedparam(3)
369
+ // functions as defined in POSIX.1-2001.
370
+ #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
371
+ #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
372
+ #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
373
+ defined(__ros__)
374
+ #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
375
+ #endif
376
+
377
+ // ABSL_HAVE_SCHED_YIELD
378
+ //
379
+ // Checks whether the platform implements sched_yield(2) as defined in
380
+ // POSIX.1-2001.
381
+ #ifdef ABSL_HAVE_SCHED_YIELD
382
+ #error ABSL_HAVE_SCHED_YIELD cannot be directly set
383
+ #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
384
+ #define ABSL_HAVE_SCHED_YIELD 1
385
+ #endif
386
+
387
+ // ABSL_HAVE_SEMAPHORE_H
388
+ //
389
+ // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
390
+ // family of functions as standardized in POSIX.1-2001.
391
+ //
392
+ // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
393
+ // explicitly deprecated and will cause build failures if enabled for those
394
+ // platforms. We side-step the issue by not defining it here for Apple
395
+ // platforms.
396
+ #ifdef ABSL_HAVE_SEMAPHORE_H
397
+ #error ABSL_HAVE_SEMAPHORE_H cannot be directly set
398
+ #elif defined(__linux__) || defined(__ros__)
399
+ #define ABSL_HAVE_SEMAPHORE_H 1
400
+ #endif
401
+
402
+ // ABSL_HAVE_ALARM
403
+ //
404
+ // Checks whether the platform supports the <signal.h> header and alarm(2)
405
+ // function as standardized in POSIX.1-2001.
406
+ #ifdef ABSL_HAVE_ALARM
407
+ #error ABSL_HAVE_ALARM cannot be directly set
408
+ #elif defined(__GOOGLE_GRTE_VERSION__)
409
+ // feature tests for Google's GRTE
410
+ #define ABSL_HAVE_ALARM 1
411
+ #elif defined(__GLIBC__)
412
+ // feature test for glibc
413
+ #define ABSL_HAVE_ALARM 1
414
+ #elif defined(_MSC_VER)
415
+ // feature tests for Microsoft's library
416
+ #elif defined(__MINGW32__)
417
+ // mingw32 doesn't provide alarm(2):
418
+ // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
419
+ // mingw-w64 provides a no-op implementation:
420
+ // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
421
+ #elif defined(__EMSCRIPTEN__)
422
+ // emscripten doesn't support signals
423
+ #elif defined(__Fuchsia__)
424
+ // Signals don't exist on fuchsia.
425
+ #elif defined(__native_client__)
426
+ #else
427
+ // other standard libraries
428
+ #define ABSL_HAVE_ALARM 1
429
+ #endif
430
+
431
+ // ABSL_IS_LITTLE_ENDIAN
432
+ // ABSL_IS_BIG_ENDIAN
433
+ //
434
+ // Checks the endianness of the platform.
435
+ //
436
+ // Notes: uses the built in endian macros provided by GCC (since 4.6) and
437
+ // Clang (since 3.2); see
438
+ // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
439
+ // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
440
+ #if defined(ABSL_IS_BIG_ENDIAN)
441
+ #error "ABSL_IS_BIG_ENDIAN cannot be directly set."
442
+ #endif
443
+ #if defined(ABSL_IS_LITTLE_ENDIAN)
444
+ #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
445
+ #endif
446
+
447
+ #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
448
+ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
449
+ #define ABSL_IS_LITTLE_ENDIAN 1
450
+ #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
451
+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
452
+ #define ABSL_IS_BIG_ENDIAN 1
453
+ #elif defined(_WIN32)
454
+ #define ABSL_IS_LITTLE_ENDIAN 1
455
+ #else
456
+ #error "absl endian detection needs to be set up for your compiler"
457
+ #endif
458
+
459
+ // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
460
+ // even though the headers exist and are publicly noted to work. See
461
+ // https://github.com/abseil/abseil-cpp/issues/207 and
462
+ // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
463
+ // libc++ spells out the availability requirements in the file
464
+ // llvm-project/libcxx/include/__config via the #define
465
+ // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
466
+ #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
467
+ ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
468
+ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
469
+ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
470
+ __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
471
+ (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
472
+ __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 120000) || \
473
+ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
474
+ __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 50000))
475
+ #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
476
+ #else
477
+ #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
478
+ #endif
479
+
480
+ // ABSL_HAVE_STD_ANY
481
+ //
482
+ // Checks whether C++17 std::any is available by checking whether <any> exists.
483
+ #ifdef ABSL_HAVE_STD_ANY
484
+ #error "ABSL_HAVE_STD_ANY cannot be directly set."
485
+ #endif
486
+
487
+ #ifdef __has_include
488
+ #if __has_include(<any>) && __cplusplus >= 201703L && \
489
+ !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
490
+ #define ABSL_HAVE_STD_ANY 1
491
+ #endif
492
+ #endif
493
+
494
+ // ABSL_HAVE_STD_OPTIONAL
495
+ //
496
+ // Checks whether C++17 std::optional is available.
497
+ #ifdef ABSL_HAVE_STD_OPTIONAL
498
+ #error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
499
+ #endif
500
+
501
+ #ifdef __has_include
502
+ #if __has_include(<optional>) && __cplusplus >= 201703L && \
503
+ !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
504
+ #define ABSL_HAVE_STD_OPTIONAL 1
505
+ #endif
506
+ #endif
507
+
508
+ // ABSL_HAVE_STD_VARIANT
509
+ //
510
+ // Checks whether C++17 std::variant is available.
511
+ #ifdef ABSL_HAVE_STD_VARIANT
512
+ #error "ABSL_HAVE_STD_VARIANT cannot be directly set."
513
+ #endif
514
+
515
+ #ifdef __has_include
516
+ #if __has_include(<variant>) && __cplusplus >= 201703L && \
517
+ !ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
518
+ #define ABSL_HAVE_STD_VARIANT 1
519
+ #endif
520
+ #endif
521
+
522
+ // ABSL_HAVE_STD_STRING_VIEW
523
+ //
524
+ // Checks whether C++17 std::string_view is available.
525
+ #ifdef ABSL_HAVE_STD_STRING_VIEW
526
+ #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
527
+ #endif
528
+
529
+ #ifdef __has_include
530
+ #if __has_include(<string_view>) && __cplusplus >= 201703L
531
+ #define ABSL_HAVE_STD_STRING_VIEW 1
532
+ #endif
533
+ #endif
534
+
535
+ // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
536
+ // the support for <optional>, <any>, <string_view>, <variant>. So we use
537
+ // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
538
+ // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
539
+ // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
540
+ // version.
541
+ // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
542
+ #if defined(_MSC_VER) && _MSC_VER >= 1910 && \
543
+ ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
544
+ // #define ABSL_HAVE_STD_ANY 1
545
+ #define ABSL_HAVE_STD_OPTIONAL 1
546
+ #define ABSL_HAVE_STD_VARIANT 1
547
+ #define ABSL_HAVE_STD_STRING_VIEW 1
548
+ #endif
549
+
550
+ // ABSL_USES_STD_ANY
551
+ //
552
+ // Indicates whether absl::any is an alias for std::any.
553
+ #if !defined(ABSL_OPTION_USE_STD_ANY)
554
+ #error options.h is misconfigured.
555
+ #elif ABSL_OPTION_USE_STD_ANY == 0 || \
556
+ (ABSL_OPTION_USE_STD_ANY == 2 && !defined(ABSL_HAVE_STD_ANY))
557
+ #undef ABSL_USES_STD_ANY
558
+ #elif ABSL_OPTION_USE_STD_ANY == 1 || \
559
+ (ABSL_OPTION_USE_STD_ANY == 2 && defined(ABSL_HAVE_STD_ANY))
560
+ #define ABSL_USES_STD_ANY 1
561
+ #else
562
+ #error options.h is misconfigured.
563
+ #endif
564
+
565
+ // ABSL_USES_STD_OPTIONAL
566
+ //
567
+ // Indicates whether absl::optional is an alias for std::optional.
568
+ #if !defined(ABSL_OPTION_USE_STD_OPTIONAL)
569
+ #error options.h is misconfigured.
570
+ #elif ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
571
+ (ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(ABSL_HAVE_STD_OPTIONAL))
572
+ #undef ABSL_USES_STD_OPTIONAL
573
+ #elif ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
574
+ (ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(ABSL_HAVE_STD_OPTIONAL))
575
+ #define ABSL_USES_STD_OPTIONAL 1
576
+ #else
577
+ #error options.h is misconfigured.
578
+ #endif
579
+
580
+ // ABSL_USES_STD_VARIANT
581
+ //
582
+ // Indicates whether absl::variant is an alias for std::variant.
583
+ #if !defined(ABSL_OPTION_USE_STD_VARIANT)
584
+ #error options.h is misconfigured.
585
+ #elif ABSL_OPTION_USE_STD_VARIANT == 0 || \
586
+ (ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(ABSL_HAVE_STD_VARIANT))
587
+ #undef ABSL_USES_STD_VARIANT
588
+ #elif ABSL_OPTION_USE_STD_VARIANT == 1 || \
589
+ (ABSL_OPTION_USE_STD_VARIANT == 2 && defined(ABSL_HAVE_STD_VARIANT))
590
+ #define ABSL_USES_STD_VARIANT 1
591
+ #else
592
+ #error options.h is misconfigured.
593
+ #endif
594
+
595
+ // ABSL_USES_STD_STRING_VIEW
596
+ //
597
+ // Indicates whether absl::string_view is an alias for std::string_view.
598
+ #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW)
599
+ #error options.h is misconfigured.
600
+ #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
601
+ (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
602
+ !defined(ABSL_HAVE_STD_STRING_VIEW))
603
+ #undef ABSL_USES_STD_STRING_VIEW
604
+ #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
605
+ (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
606
+ defined(ABSL_HAVE_STD_STRING_VIEW))
607
+ #define ABSL_USES_STD_STRING_VIEW 1
608
+ #else
609
+ #error options.h is misconfigured.
610
+ #endif
611
+
612
+ // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
613
+ // SEH exception from emplace for variant<SomeStruct> when constructing the
614
+ // struct can throw. This defeats some of variant_test and
615
+ // variant_exception_safety_test.
616
+ #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
617
+ #define ABSL_INTERNAL_MSVC_2017_DBG_MODE
618
+ #endif
619
+
620
+ #undef ABSL_INTERNAL_HAS_KEYWORD
621
+
622
+ #endif // ABSL_BASE_CONFIG_H_