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.
- checksums.yaml +4 -4
- data/Makefile +1654 -1519
- data/etc/roots.pem +44 -0
- data/include/grpc/grpc_security.h +37 -15
- data/include/grpc/grpc_security_constants.h +27 -0
- data/include/grpc/impl/codegen/grpc_types.h +14 -0
- data/include/grpc/impl/codegen/port_platform.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
- data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +3 -10
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
- data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
- data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
- data/src/core/lib/channel/channelz.h +11 -1
- data/src/core/lib/gpr/time_precise.cc +1 -1
- data/src/core/lib/gprpp/optional.h +26 -0
- data/src/core/lib/gprpp/string_view.h +14 -10
- data/src/core/lib/iomgr/executor.cc +1 -1
- data/src/core/lib/iomgr/fork_posix.cc +4 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
- data/src/core/lib/iomgr/tcp_custom.h +3 -0
- data/src/core/lib/iomgr/tcp_posix.cc +607 -56
- data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
- data/src/core/lib/json/json.h +11 -1
- data/src/core/lib/json/json_reader.cc +206 -28
- data/src/core/lib/json/json_writer.cc +111 -24
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
- data/src/core/lib/security/credentials/credentials.h +10 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
- data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
- data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
- data/src/core/lib/surface/completion_queue.cc +22 -1
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +7 -3
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl_transport_security.cc +144 -8
- data/src/core/tsi/ssl_transport_security.h +15 -1
- data/src/core/tsi/transport_security.cc +13 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -2
- data/src/core/tsi/transport_security_grpc.h +2 -2
- data/src/core/tsi/transport_security_interface.h +12 -0
- data/src/ruby/bin/math_pb.rb +5 -5
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
- data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
- data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
- data/third_party/abseil-cpp/absl/base/casts.h +184 -0
- data/third_party/abseil-cpp/absl/base/config.h +622 -0
- data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
- data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
- data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
- data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
- data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
- data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
- data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
- data/third_party/abseil-cpp/absl/base/macros.h +220 -0
- data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
- data/third_party/abseil-cpp/absl/base/options.h +214 -0
- data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
- data/third_party/abseil-cpp/absl/base/port.h +26 -0
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
- data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
- data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
- data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
- data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
- data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
- data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
- data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
- data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
- data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
- data/third_party/abseil-cpp/absl/strings/match.h +90 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
- data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
- data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
- data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
- data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
- data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
- data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
- data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
- data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
- data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
- data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
- data/third_party/abseil-cpp/absl/types/optional.h +776 -0
- data/third_party/abseil-cpp/absl/types/span.h +713 -0
- data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
- data/third_party/upb/upb/decode.c +4 -0
- data/third_party/upb/upb/port.c +0 -1
- data/third_party/upb/upb/port_def.inc +1 -3
- data/third_party/upb/upb/table.c +2 -1
- metadata +147 -43
- data/src/core/lib/json/json_common.h +0 -34
- data/src/core/lib/json/json_reader.h +0 -146
- data/src/core/lib/json/json_string.cc +0 -367
- data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,179 @@
|
|
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
|
+
#ifndef ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
|
16
|
+
#define ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
|
17
|
+
|
18
|
+
#include <atomic>
|
19
|
+
#include <cassert>
|
20
|
+
#include <cstdint>
|
21
|
+
#include <utility>
|
22
|
+
|
23
|
+
#include "absl/base/config.h"
|
24
|
+
|
25
|
+
#ifdef _MSC_FULL_VER
|
26
|
+
#define ABSL_HAVE_WORKING_ATOMIC_POINTER 0
|
27
|
+
#define ABSL_HAVE_WORKING_CONSTEXPR_STATIC_INIT 0
|
28
|
+
#else
|
29
|
+
#define ABSL_HAVE_WORKING_ATOMIC_POINTER 1
|
30
|
+
#define ABSL_HAVE_WORKING_CONSTEXPR_STATIC_INIT 1
|
31
|
+
#endif
|
32
|
+
|
33
|
+
namespace absl {
|
34
|
+
ABSL_NAMESPACE_BEGIN
|
35
|
+
namespace base_internal {
|
36
|
+
|
37
|
+
template <typename T>
|
38
|
+
class AtomicHook;
|
39
|
+
|
40
|
+
// `AtomicHook` is a helper class, templatized on a raw function pointer type,
|
41
|
+
// for implementing Abseil customization hooks. It is a callable object that
|
42
|
+
// dispatches to the registered hook. Objects of type `AtomicHook` must have
|
43
|
+
// static or thread storage duration.
|
44
|
+
//
|
45
|
+
// A default constructed object performs a no-op (and returns a default
|
46
|
+
// constructed object) if no hook has been registered.
|
47
|
+
//
|
48
|
+
// Hooks can be pre-registered via constant initialization, for example,
|
49
|
+
// `ABSL_CONST_INIT static AtomicHook<void(*)()> my_hook(DefaultAction);`
|
50
|
+
// and then changed at runtime via a call to `Store()`.
|
51
|
+
//
|
52
|
+
// Reads and writes guarantee memory_order_acquire/memory_order_release
|
53
|
+
// semantics.
|
54
|
+
template <typename ReturnType, typename... Args>
|
55
|
+
class AtomicHook<ReturnType (*)(Args...)> {
|
56
|
+
public:
|
57
|
+
using FnPtr = ReturnType (*)(Args...);
|
58
|
+
|
59
|
+
// Constructs an object that by default performs a no-op (and
|
60
|
+
// returns a default constructed object) when no hook as been registered.
|
61
|
+
constexpr AtomicHook() : AtomicHook(DummyFunction) {}
|
62
|
+
|
63
|
+
// Constructs an object that by default dispatches to/returns the
|
64
|
+
// pre-registered default_fn when no hook has been registered at runtime.
|
65
|
+
#if ABSL_HAVE_WORKING_ATOMIC_POINTER && ABSL_HAVE_WORKING_CONSTEXPR_STATIC_INIT
|
66
|
+
explicit constexpr AtomicHook(FnPtr default_fn)
|
67
|
+
: hook_(default_fn), default_fn_(default_fn) {}
|
68
|
+
#else
|
69
|
+
// On MSVC, this function sometimes executes after dynamic initialization =(.
|
70
|
+
// If a non-zero `hook_` has been installed by a dynamic initializer, we want
|
71
|
+
// to preserve it. If not, `hook_` will be zero initialized and we have no
|
72
|
+
// need to set it to `kUninitialized`.
|
73
|
+
// https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html
|
74
|
+
explicit constexpr AtomicHook(FnPtr default_fn)
|
75
|
+
: /* hook_(deliberately omitted), */ default_fn_(default_fn) {
|
76
|
+
static_assert(kUninitialized == 0, "here we rely on zero-initialization");
|
77
|
+
}
|
78
|
+
#endif
|
79
|
+
|
80
|
+
// Stores the provided function pointer as the value for this hook.
|
81
|
+
//
|
82
|
+
// This is intended to be called once. Multiple calls are legal only if the
|
83
|
+
// same function pointer is provided for each call. The store is implemented
|
84
|
+
// as a memory_order_release operation, and read accesses are implemented as
|
85
|
+
// memory_order_acquire.
|
86
|
+
void Store(FnPtr fn) {
|
87
|
+
bool success = DoStore(fn);
|
88
|
+
static_cast<void>(success);
|
89
|
+
assert(success);
|
90
|
+
}
|
91
|
+
|
92
|
+
// Invokes the registered callback. If no callback has yet been registered, a
|
93
|
+
// default-constructed object of the appropriate type is returned instead.
|
94
|
+
template <typename... CallArgs>
|
95
|
+
ReturnType operator()(CallArgs&&... args) const {
|
96
|
+
return DoLoad()(std::forward<CallArgs>(args)...);
|
97
|
+
}
|
98
|
+
|
99
|
+
// Returns the registered callback, or nullptr if none has been registered.
|
100
|
+
// Useful if client code needs to conditionalize behavior based on whether a
|
101
|
+
// callback was registered.
|
102
|
+
//
|
103
|
+
// Note that atomic_hook.Load()() and atomic_hook() have different semantics:
|
104
|
+
// operator()() will perform a no-op if no callback was registered, while
|
105
|
+
// Load()() will dereference a null function pointer. Prefer operator()() to
|
106
|
+
// Load()() unless you must conditionalize behavior on whether a hook was
|
107
|
+
// registered.
|
108
|
+
FnPtr Load() const {
|
109
|
+
FnPtr ptr = DoLoad();
|
110
|
+
return (ptr == DummyFunction) ? nullptr : ptr;
|
111
|
+
}
|
112
|
+
|
113
|
+
private:
|
114
|
+
static ReturnType DummyFunction(Args...) {
|
115
|
+
return ReturnType();
|
116
|
+
}
|
117
|
+
|
118
|
+
// Current versions of MSVC (as of September 2017) have a broken
|
119
|
+
// implementation of std::atomic<T*>: Its constructor attempts to do the
|
120
|
+
// equivalent of a reinterpret_cast in a constexpr context, which is not
|
121
|
+
// allowed.
|
122
|
+
//
|
123
|
+
// This causes an issue when building with LLVM under Windows. To avoid this,
|
124
|
+
// we use a less-efficient, intptr_t-based implementation on Windows.
|
125
|
+
#if ABSL_HAVE_WORKING_ATOMIC_POINTER
|
126
|
+
// Return the stored value, or DummyFunction if no value has been stored.
|
127
|
+
FnPtr DoLoad() const { return hook_.load(std::memory_order_acquire); }
|
128
|
+
|
129
|
+
// Store the given value. Returns false if a different value was already
|
130
|
+
// stored to this object.
|
131
|
+
bool DoStore(FnPtr fn) {
|
132
|
+
assert(fn);
|
133
|
+
FnPtr expected = default_fn_;
|
134
|
+
const bool store_succeeded = hook_.compare_exchange_strong(
|
135
|
+
expected, fn, std::memory_order_acq_rel, std::memory_order_acquire);
|
136
|
+
const bool same_value_already_stored = (expected == fn);
|
137
|
+
return store_succeeded || same_value_already_stored;
|
138
|
+
}
|
139
|
+
|
140
|
+
std::atomic<FnPtr> hook_;
|
141
|
+
#else // !ABSL_HAVE_WORKING_ATOMIC_POINTER
|
142
|
+
// Use a sentinel value unlikely to be the address of an actual function.
|
143
|
+
static constexpr intptr_t kUninitialized = 0;
|
144
|
+
|
145
|
+
static_assert(sizeof(intptr_t) >= sizeof(FnPtr),
|
146
|
+
"intptr_t can't contain a function pointer");
|
147
|
+
|
148
|
+
FnPtr DoLoad() const {
|
149
|
+
const intptr_t value = hook_.load(std::memory_order_acquire);
|
150
|
+
if (value == kUninitialized) {
|
151
|
+
return default_fn_;
|
152
|
+
}
|
153
|
+
return reinterpret_cast<FnPtr>(value);
|
154
|
+
}
|
155
|
+
|
156
|
+
bool DoStore(FnPtr fn) {
|
157
|
+
assert(fn);
|
158
|
+
const auto value = reinterpret_cast<intptr_t>(fn);
|
159
|
+
intptr_t expected = kUninitialized;
|
160
|
+
const bool store_succeeded = hook_.compare_exchange_strong(
|
161
|
+
expected, value, std::memory_order_acq_rel, std::memory_order_acquire);
|
162
|
+
const bool same_value_already_stored = (expected == value);
|
163
|
+
return store_succeeded || same_value_already_stored;
|
164
|
+
}
|
165
|
+
|
166
|
+
std::atomic<intptr_t> hook_;
|
167
|
+
#endif
|
168
|
+
|
169
|
+
const FnPtr default_fn_;
|
170
|
+
};
|
171
|
+
|
172
|
+
#undef ABSL_HAVE_WORKING_ATOMIC_POINTER
|
173
|
+
#undef ABSL_HAVE_WORKING_CONSTEXPR_STATIC_INIT
|
174
|
+
|
175
|
+
} // namespace base_internal
|
176
|
+
ABSL_NAMESPACE_END
|
177
|
+
} // namespace absl
|
178
|
+
|
179
|
+
#endif // ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
|
@@ -0,0 +1,218 @@
|
|
1
|
+
// Copyright 2018 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
|
+
#ifndef ABSL_BASE_INTERNAL_BITS_H_
|
16
|
+
#define ABSL_BASE_INTERNAL_BITS_H_
|
17
|
+
|
18
|
+
// This file contains bitwise ops which are implementation details of various
|
19
|
+
// absl libraries.
|
20
|
+
|
21
|
+
#include <cstdint>
|
22
|
+
|
23
|
+
#include "absl/base/config.h"
|
24
|
+
|
25
|
+
// Clang on Windows has __builtin_clzll; otherwise we need to use the
|
26
|
+
// windows intrinsic functions.
|
27
|
+
#if defined(_MSC_VER)
|
28
|
+
#include <intrin.h>
|
29
|
+
#if defined(_M_X64)
|
30
|
+
#pragma intrinsic(_BitScanReverse64)
|
31
|
+
#pragma intrinsic(_BitScanForward64)
|
32
|
+
#endif
|
33
|
+
#pragma intrinsic(_BitScanReverse)
|
34
|
+
#pragma intrinsic(_BitScanForward)
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#include "absl/base/attributes.h"
|
38
|
+
|
39
|
+
#if defined(_MSC_VER)
|
40
|
+
// We can achieve something similar to attribute((always_inline)) with MSVC by
|
41
|
+
// using the __forceinline keyword, however this is not perfect. MSVC is
|
42
|
+
// much less aggressive about inlining, and even with the __forceinline keyword.
|
43
|
+
#define ABSL_BASE_INTERNAL_FORCEINLINE __forceinline
|
44
|
+
#else
|
45
|
+
// Use default attribute inline.
|
46
|
+
#define ABSL_BASE_INTERNAL_FORCEINLINE inline ABSL_ATTRIBUTE_ALWAYS_INLINE
|
47
|
+
#endif
|
48
|
+
|
49
|
+
|
50
|
+
namespace absl {
|
51
|
+
ABSL_NAMESPACE_BEGIN
|
52
|
+
namespace base_internal {
|
53
|
+
|
54
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64Slow(uint64_t n) {
|
55
|
+
int zeroes = 60;
|
56
|
+
if (n >> 32) {
|
57
|
+
zeroes -= 32;
|
58
|
+
n >>= 32;
|
59
|
+
}
|
60
|
+
if (n >> 16) {
|
61
|
+
zeroes -= 16;
|
62
|
+
n >>= 16;
|
63
|
+
}
|
64
|
+
if (n >> 8) {
|
65
|
+
zeroes -= 8;
|
66
|
+
n >>= 8;
|
67
|
+
}
|
68
|
+
if (n >> 4) {
|
69
|
+
zeroes -= 4;
|
70
|
+
n >>= 4;
|
71
|
+
}
|
72
|
+
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
73
|
+
}
|
74
|
+
|
75
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64(uint64_t n) {
|
76
|
+
#if defined(_MSC_VER) && defined(_M_X64)
|
77
|
+
// MSVC does not have __buitin_clzll. Use _BitScanReverse64.
|
78
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
79
|
+
if (_BitScanReverse64(&result, n)) {
|
80
|
+
return 63 - result;
|
81
|
+
}
|
82
|
+
return 64;
|
83
|
+
#elif defined(_MSC_VER)
|
84
|
+
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
|
85
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
86
|
+
if ((n >> 32) && _BitScanReverse(&result, n >> 32)) {
|
87
|
+
return 31 - result;
|
88
|
+
}
|
89
|
+
if (_BitScanReverse(&result, n)) {
|
90
|
+
return 63 - result;
|
91
|
+
}
|
92
|
+
return 64;
|
93
|
+
#elif defined(__GNUC__)
|
94
|
+
// Use __builtin_clzll, which uses the following instructions:
|
95
|
+
// x86: bsr
|
96
|
+
// ARM64: clz
|
97
|
+
// PPC: cntlzd
|
98
|
+
static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int)
|
99
|
+
"__builtin_clzll does not take 64-bit arg");
|
100
|
+
|
101
|
+
// Handle 0 as a special case because __builtin_clzll(0) is undefined.
|
102
|
+
if (n == 0) {
|
103
|
+
return 64;
|
104
|
+
}
|
105
|
+
return __builtin_clzll(n);
|
106
|
+
#else
|
107
|
+
return CountLeadingZeros64Slow(n);
|
108
|
+
#endif
|
109
|
+
}
|
110
|
+
|
111
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32Slow(uint64_t n) {
|
112
|
+
int zeroes = 28;
|
113
|
+
if (n >> 16) {
|
114
|
+
zeroes -= 16;
|
115
|
+
n >>= 16;
|
116
|
+
}
|
117
|
+
if (n >> 8) {
|
118
|
+
zeroes -= 8;
|
119
|
+
n >>= 8;
|
120
|
+
}
|
121
|
+
if (n >> 4) {
|
122
|
+
zeroes -= 4;
|
123
|
+
n >>= 4;
|
124
|
+
}
|
125
|
+
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
126
|
+
}
|
127
|
+
|
128
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32(uint32_t n) {
|
129
|
+
#if defined(_MSC_VER)
|
130
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
131
|
+
if (_BitScanReverse(&result, n)) {
|
132
|
+
return 31 - result;
|
133
|
+
}
|
134
|
+
return 32;
|
135
|
+
#elif defined(__GNUC__)
|
136
|
+
// Use __builtin_clz, which uses the following instructions:
|
137
|
+
// x86: bsr
|
138
|
+
// ARM64: clz
|
139
|
+
// PPC: cntlzd
|
140
|
+
static_assert(sizeof(int) == sizeof(n),
|
141
|
+
"__builtin_clz does not take 32-bit arg");
|
142
|
+
|
143
|
+
// Handle 0 as a special case because __builtin_clz(0) is undefined.
|
144
|
+
if (n == 0) {
|
145
|
+
return 32;
|
146
|
+
}
|
147
|
+
return __builtin_clz(n);
|
148
|
+
#else
|
149
|
+
return CountLeadingZeros32Slow(n);
|
150
|
+
#endif
|
151
|
+
}
|
152
|
+
|
153
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64Slow(uint64_t n) {
|
154
|
+
int c = 63;
|
155
|
+
n &= ~n + 1;
|
156
|
+
if (n & 0x00000000FFFFFFFF) c -= 32;
|
157
|
+
if (n & 0x0000FFFF0000FFFF) c -= 16;
|
158
|
+
if (n & 0x00FF00FF00FF00FF) c -= 8;
|
159
|
+
if (n & 0x0F0F0F0F0F0F0F0F) c -= 4;
|
160
|
+
if (n & 0x3333333333333333) c -= 2;
|
161
|
+
if (n & 0x5555555555555555) c -= 1;
|
162
|
+
return c;
|
163
|
+
}
|
164
|
+
|
165
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64(uint64_t n) {
|
166
|
+
#if defined(_MSC_VER) && defined(_M_X64)
|
167
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
168
|
+
_BitScanForward64(&result, n);
|
169
|
+
return result;
|
170
|
+
#elif defined(_MSC_VER)
|
171
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
172
|
+
if (static_cast<uint32_t>(n) == 0) {
|
173
|
+
_BitScanForward(&result, n >> 32);
|
174
|
+
return result + 32;
|
175
|
+
}
|
176
|
+
_BitScanForward(&result, n);
|
177
|
+
return result;
|
178
|
+
#elif defined(__GNUC__)
|
179
|
+
static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int)
|
180
|
+
"__builtin_ctzll does not take 64-bit arg");
|
181
|
+
return __builtin_ctzll(n);
|
182
|
+
#else
|
183
|
+
return CountTrailingZerosNonZero64Slow(n);
|
184
|
+
#endif
|
185
|
+
}
|
186
|
+
|
187
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32Slow(uint32_t n) {
|
188
|
+
int c = 31;
|
189
|
+
n &= ~n + 1;
|
190
|
+
if (n & 0x0000FFFF) c -= 16;
|
191
|
+
if (n & 0x00FF00FF) c -= 8;
|
192
|
+
if (n & 0x0F0F0F0F) c -= 4;
|
193
|
+
if (n & 0x33333333) c -= 2;
|
194
|
+
if (n & 0x55555555) c -= 1;
|
195
|
+
return c;
|
196
|
+
}
|
197
|
+
|
198
|
+
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32(uint32_t n) {
|
199
|
+
#if defined(_MSC_VER)
|
200
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
201
|
+
_BitScanForward(&result, n);
|
202
|
+
return result;
|
203
|
+
#elif defined(__GNUC__)
|
204
|
+
static_assert(sizeof(int) == sizeof(n),
|
205
|
+
"__builtin_ctz does not take 32-bit arg");
|
206
|
+
return __builtin_ctz(n);
|
207
|
+
#else
|
208
|
+
return CountTrailingZerosNonZero32Slow(n);
|
209
|
+
#endif
|
210
|
+
}
|
211
|
+
|
212
|
+
#undef ABSL_BASE_INTERNAL_FORCEINLINE
|
213
|
+
|
214
|
+
} // namespace base_internal
|
215
|
+
ABSL_NAMESPACE_END
|
216
|
+
} // namespace absl
|
217
|
+
|
218
|
+
#endif // ABSL_BASE_INTERNAL_BITS_H_
|
@@ -0,0 +1,107 @@
|
|
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
|
+
// The implementation of CycleClock::Frequency.
|
16
|
+
//
|
17
|
+
// NOTE: only i386 and x86_64 have been well tested.
|
18
|
+
// PPC, sparc, alpha, and ia64 are based on
|
19
|
+
// http://peter.kuscsik.com/wordpress/?p=14
|
20
|
+
// with modifications by m3b. See also
|
21
|
+
// https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
|
22
|
+
|
23
|
+
#include "absl/base/internal/cycleclock.h"
|
24
|
+
|
25
|
+
#include <atomic>
|
26
|
+
#include <chrono> // NOLINT(build/c++11)
|
27
|
+
|
28
|
+
#include "absl/base/internal/unscaledcycleclock.h"
|
29
|
+
|
30
|
+
namespace absl {
|
31
|
+
ABSL_NAMESPACE_BEGIN
|
32
|
+
namespace base_internal {
|
33
|
+
|
34
|
+
#if ABSL_USE_UNSCALED_CYCLECLOCK
|
35
|
+
|
36
|
+
namespace {
|
37
|
+
|
38
|
+
#ifdef NDEBUG
|
39
|
+
#ifdef ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY
|
40
|
+
// Not debug mode and the UnscaledCycleClock frequency is the CPU
|
41
|
+
// frequency. Scale the CycleClock to prevent overflow if someone
|
42
|
+
// tries to represent the time as cycles since the Unix epoch.
|
43
|
+
static constexpr int32_t kShift = 1;
|
44
|
+
#else
|
45
|
+
// Not debug mode and the UnscaledCycleClock isn't operating at the
|
46
|
+
// raw CPU frequency. There is no need to do any scaling, so don't
|
47
|
+
// needlessly sacrifice precision.
|
48
|
+
static constexpr int32_t kShift = 0;
|
49
|
+
#endif
|
50
|
+
#else
|
51
|
+
// In debug mode use a different shift to discourage depending on a
|
52
|
+
// particular shift value.
|
53
|
+
static constexpr int32_t kShift = 2;
|
54
|
+
#endif
|
55
|
+
|
56
|
+
static constexpr double kFrequencyScale = 1.0 / (1 << kShift);
|
57
|
+
static std::atomic<CycleClockSourceFunc> cycle_clock_source;
|
58
|
+
|
59
|
+
CycleClockSourceFunc LoadCycleClockSource() {
|
60
|
+
// Optimize for the common case (no callback) by first doing a relaxed load;
|
61
|
+
// this is significantly faster on non-x86 platforms.
|
62
|
+
if (cycle_clock_source.load(std::memory_order_relaxed) == nullptr) {
|
63
|
+
return nullptr;
|
64
|
+
}
|
65
|
+
// This corresponds to the store(std::memory_order_release) in
|
66
|
+
// CycleClockSource::Register, and makes sure that any updates made prior to
|
67
|
+
// registering the callback are visible to this thread before the callback is
|
68
|
+
// invoked.
|
69
|
+
return cycle_clock_source.load(std::memory_order_acquire);
|
70
|
+
}
|
71
|
+
|
72
|
+
} // namespace
|
73
|
+
|
74
|
+
int64_t CycleClock::Now() {
|
75
|
+
auto fn = LoadCycleClockSource();
|
76
|
+
if (fn == nullptr) {
|
77
|
+
return base_internal::UnscaledCycleClock::Now() >> kShift;
|
78
|
+
}
|
79
|
+
return fn() >> kShift;
|
80
|
+
}
|
81
|
+
|
82
|
+
double CycleClock::Frequency() {
|
83
|
+
return kFrequencyScale * base_internal::UnscaledCycleClock::Frequency();
|
84
|
+
}
|
85
|
+
|
86
|
+
void CycleClockSource::Register(CycleClockSourceFunc source) {
|
87
|
+
// Corresponds to the load(std::memory_order_acquire) in LoadCycleClockSource.
|
88
|
+
cycle_clock_source.store(source, std::memory_order_release);
|
89
|
+
}
|
90
|
+
|
91
|
+
#else
|
92
|
+
|
93
|
+
int64_t CycleClock::Now() {
|
94
|
+
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
95
|
+
std::chrono::steady_clock::now().time_since_epoch())
|
96
|
+
.count();
|
97
|
+
}
|
98
|
+
|
99
|
+
double CycleClock::Frequency() {
|
100
|
+
return 1e9;
|
101
|
+
}
|
102
|
+
|
103
|
+
#endif
|
104
|
+
|
105
|
+
} // namespace base_internal
|
106
|
+
ABSL_NAMESPACE_END
|
107
|
+
} // namespace absl
|