Merge pull request #20350 from veblush/cpp-now

Activate the C++ standard library
pull/20435/head
Esun Kim 6 years ago committed by GitHub
commit 7eb9262936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      BUILD
  2. 2
      BUILD.gn
  3. 42
      CMakeLists.txt
  4. 48
      Makefile
  5. 3
      bazel/grpc_build_system.bzl
  6. 15
      build.yaml
  7. 1
      gRPC-C++.podspec
  8. 2
      gRPC-Core.podspec
  9. 1
      grpc.gemspec
  10. 8
      include/grpc/impl/codegen/port_platform.h
  11. 1
      package.xml
  12. 4
      src/core/ext/filters/client_channel/backend_metric.cc
  13. 12
      src/core/ext/filters/client_channel/client_channel.cc
  14. 6
      src/core/ext/filters/client_channel/client_channel_factory.h
  15. 56
      src/core/ext/filters/client_channel/lb_policy.h
  16. 7
      src/core/ext/filters/client_channel/lb_policy/subchannel_list.h
  17. 4
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  18. 4
      src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc
  19. 14
      src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h
  20. 8
      src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc
  21. 2
      src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h
  22. 9
      src/core/ext/filters/client_channel/lb_policy_factory.h
  23. 13
      src/core/ext/filters/client_channel/resolver.h
  24. 23
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h
  25. 10
      src/core/ext/filters/client_channel/resolver_factory.h
  26. 4
      src/core/ext/filters/client_channel/service_config.h
  27. 12
      src/core/ext/filters/client_channel/subchannel.h
  28. 22
      src/core/ext/filters/client_channel/subchannel_interface.h
  29. 9
      src/core/ext/filters/client_channel/subchannel_pool_interface.h
  30. 5
      src/core/ext/transport/chttp2/transport/flow_control.h
  31. 10
      src/core/lib/channel/channelz.h
  32. 2
      src/core/lib/channel/channelz_registry.h
  33. 7
      src/core/lib/channel/handshaker.h
  34. 4
      src/core/lib/channel/handshaker_factory.h
  35. 47
      src/core/lib/gprpp/abstract.h
  36. 500
      src/core/lib/gprpp/map.h
  37. 7
      src/core/lib/gprpp/orphanable.h
  38. 9
      src/core/lib/gprpp/ref_counted.h
  39. 6
      src/core/lib/gprpp/thd.h
  40. 9
      src/core/lib/iomgr/executor/mpmcqueue.h
  41. 13
      src/core/lib/iomgr/executor/threadpool.h
  42. 5
      src/core/lib/iomgr/tcp_server.h
  43. 16
      src/core/lib/iomgr/udp_server.h
  44. 12
      src/core/lib/security/credentials/credentials.cc
  45. 30
      src/core/lib/security/credentials/credentials.h
  46. 4
      src/core/lib/security/credentials/oauth2/oauth2_credentials.h
  47. 26
      src/core/lib/security/security_connector/security_connector.h
  48. 1
      src/core/lib/surface/completion_queue.h
  49. 10
      src/core/lib/transport/byte_stream.h
  50. 11
      src/core/lib/transport/connectivity_state.h
  51. 4
      src/core/tsi/ssl/session_cache/ssl_session.h
  52. 14
      test/core/gprpp/BUILD
  53. 2
      test/core/gprpp/manual_constructor_test.cc
  54. 514
      test/core/gprpp/map_test.cc
  55. 1
      test/cpp/qps/interarrival.h
  56. 1
      tools/doxygen/Doxyfile.c++.internal
  57. 1
      tools/doxygen/Doxyfile.core.internal
  58. 1
      tools/internal_ci/linux/grpc_bazel_build_in_docker.sh
  59. 24
      tools/run_tests/generated/tests.json

@ -69,11 +69,6 @@ config_setting(
values = {"cpu": "darwin"},
)
config_setting(
name = "grpc_use_cpp_std_lib",
values = {"define": "GRPC_USE_CPP_STD_LIB=1"},
)
python_config_settings()
# This should be updated along with build.yaml
@ -514,7 +509,6 @@ grpc_cc_library(
"src/core/lib/gpr/tls_pthread.h",
"src/core/lib/gpr/tmpfile.h",
"src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/fork.h",

@ -132,7 +132,6 @@ config("grpc_config") {
"src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/useful.h",
"src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/arena.cc",
"src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h",
@ -1237,7 +1236,6 @@ config("grpc_config") {
"src/core/lib/gpr/tls_pthread.h",
"src/core/lib/gpr/tmpfile.h",
"src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/debug_location.h",

@ -631,7 +631,6 @@ add_dependencies(buildtests_cxx golden_file_test)
add_dependencies(buildtests_cxx gprpp_mpscq_test)
add_dependencies(buildtests_cxx grpc_alts_credentials_options_test)
add_dependencies(buildtests_cxx grpc_cli)
add_dependencies(buildtests_cxx grpc_core_map_test)
add_dependencies(buildtests_cxx grpc_fetch_oauth2)
add_dependencies(buildtests_cxx grpc_linux_system_roots_test)
add_dependencies(buildtests_cxx grpc_spiffe_security_connector_test)
@ -13408,47 +13407,6 @@ target_link_libraries(grpc_cli
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(grpc_core_map_test
test/core/gprpp/map_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(grpc_core_map_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_UPB_GENERATED_DIR}
PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR}
PRIVATE ${_gRPC_UPB_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(grpc_core_map_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc++
grpc
gpr
${_gRPC_GFLAGS_LIBRARIES}
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_CODEGEN)

@ -1220,7 +1220,6 @@ golden_file_test: $(BINDIR)/$(CONFIG)/golden_file_test
gprpp_mpscq_test: $(BINDIR)/$(CONFIG)/gprpp_mpscq_test
grpc_alts_credentials_options_test: $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test
grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli
grpc_core_map_test: $(BINDIR)/$(CONFIG)/grpc_core_map_test
grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin
grpc_csharp_plugin: $(BINDIR)/$(CONFIG)/grpc_csharp_plugin
grpc_fetch_oauth2: $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2
@ -1699,7 +1698,6 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/gprpp_mpscq_test \
$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \
$(BINDIR)/$(CONFIG)/grpc_cli \
$(BINDIR)/$(CONFIG)/grpc_core_map_test \
$(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 \
$(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \
$(BINDIR)/$(CONFIG)/grpc_spiffe_security_connector_test \
@ -1870,7 +1868,6 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/gprpp_mpscq_test \
$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \
$(BINDIR)/$(CONFIG)/grpc_cli \
$(BINDIR)/$(CONFIG)/grpc_core_map_test \
$(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 \
$(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \
$(BINDIR)/$(CONFIG)/grpc_spiffe_security_connector_test \
@ -2378,8 +2375,6 @@ test_cxx: buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/gprpp_mpscq_test || ( echo test gprpp_mpscq_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_alts_credentials_options_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test || ( echo test grpc_alts_credentials_options_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_core_map_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_core_map_test || ( echo test grpc_core_map_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_linux_system_roots_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test || ( echo test grpc_linux_system_roots_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_spiffe_security_connector_test"
@ -16803,49 +16798,6 @@ endif
endif
GRPC_CORE_MAP_TEST_SRC = \
test/core/gprpp/map_test.cc \
GRPC_CORE_MAP_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CORE_MAP_TEST_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/grpc_core_map_test: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
$(BINDIR)/$(CONFIG)/grpc_core_map_test: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/grpc_core_map_test: $(PROTOBUF_DEP) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/grpc_core_map_test
endif
endif
$(OBJDIR)/$(CONFIG)/test/core/gprpp/map_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_grpc_core_map_test: $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep)
endif
endif
GRPC_CPP_PLUGIN_SRC = \
src/compiler/cpp_plugin.cc \

@ -98,9 +98,6 @@ def grpc_cc_library(
"//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"],
"//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"],
"//conditions:default": [],
}) + select({
"//:grpc_use_cpp_std_lib": ["GRPC_USE_CPP_STD_LIB=1"],
"//conditions:default": [],
}),
hdrs = hdrs + public_hdrs,
deps = deps + _get_external_deps(external_deps),

@ -279,7 +279,6 @@ filegroups:
- src/core/lib/gpr/tls_pthread.h
- src/core/lib/gpr/tmpfile.h
- src/core/lib/gpr/useful.h
- src/core/lib/gprpp/abstract.h
- src/core/lib/gprpp/arena.h
- src/core/lib/gprpp/atomic.h
- src/core/lib/gprpp/fork.h
@ -5016,20 +5015,6 @@ targets:
- grpc
- gpr
- grpc++_test_config
- name: grpc_core_map_test
gtest: true
build: test
language: c++
headers:
- test/core/gprpp/map_tester.h
src:
- test/core/gprpp/map_test.cc
deps:
- grpc_test_util
- grpc++
- grpc
- gpr
uses_polling: false
- name: grpc_cpp_plugin
build: protoc
language: c++

@ -299,7 +299,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/tls_pthread.h',
'src/core/lib/gpr/tmpfile.h',
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/abstract.h',
'src/core/lib/gprpp/arena.h',
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',

@ -202,7 +202,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/tls_pthread.h',
'src/core/lib/gpr/tmpfile.h',
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/abstract.h',
'src/core/lib/gprpp/arena.h',
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',
@ -978,7 +977,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/tls_pthread.h',
'src/core/lib/gpr/tmpfile.h',
'src/core/lib/gpr/useful.h',
'src/core/lib/gprpp/abstract.h',
'src/core/lib/gprpp/arena.h',
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',

@ -96,7 +96,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/tls_pthread.h )
s.files += %w( src/core/lib/gpr/tmpfile.h )
s.files += %w( src/core/lib/gpr/useful.h )
s.files += %w( src/core/lib/gprpp/abstract.h )
s.files += %w( src/core/lib/gprpp/arena.h )
s.files += %w( src/core/lib/gprpp/atomic.h )
s.files += %w( src/core/lib/gprpp/fork.h )

@ -27,14 +27,6 @@
* - some syscalls to be made directly
*/
/*
* Defines GRPC_USE_CPP_STD_LIB to use standard C++ library instead of
* in-house library if possible. (e.g. std::map)
*/
#ifndef GRPC_USE_CPP_STD_LIB
#define GRPC_USE_CPP_STD_LIB 1
#endif
/* Get windows.h included everywhere (we need it) */
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
#ifndef WIN32_LEAN_AND_MEAN

@ -101,7 +101,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/tls_pthread.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/tmpfile.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/useful.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/abstract.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/arena.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.h" role="src" />

@ -26,12 +26,12 @@ namespace grpc_core {
namespace {
template <typename EntryType>
Map<StringView, double, StringLess> ParseMap(
std::map<StringView, double, StringLess> ParseMap(
udpa_data_orca_v1_OrcaLoadReport* msg,
EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*),
upb_strview (*key_func)(const EntryType*),
double (*value_func)(const EntryType*), Arena* arena) {
Map<StringView, double, StringLess> result;
std::map<StringView, double, StringLess> result;
size_t size;
const auto* const* entries = entry_func(msg, &size);
for (size_t i = 0; i < size; ++i) {

@ -282,18 +282,18 @@ class ChannelData {
RefCountedPtr<ServiceConfig> saved_service_config_;
bool received_first_resolver_result_ = false;
// The number of SubchannelWrapper instances referencing a given Subchannel.
Map<Subchannel*, int> subchannel_refcount_map_;
std::map<Subchannel*, int> subchannel_refcount_map_;
// The set of SubchannelWrappers that currently exist.
// No need to hold a ref, since the map is updated in the control-plane
// combiner when the SubchannelWrappers are created and destroyed.
// TODO(roth): We really want to use a set here, not a map. Since we don't
// currently have a set implementation, we use a map and ignore the value.
Map<SubchannelWrapper*, bool> subchannel_wrappers_;
std::map<SubchannelWrapper*, bool> subchannel_wrappers_;
// Pending ConnectedSubchannel updates for each SubchannelWrapper.
// Updates are queued here in the control plane combiner and then applied
// in the data plane mutex when the picker is updated.
Map<RefCountedPtr<SubchannelWrapper>, RefCountedPtr<ConnectedSubchannel>,
RefCountedPtrLess<SubchannelWrapper>>
std::map<RefCountedPtr<SubchannelWrapper>, RefCountedPtr<ConnectedSubchannel>,
RefCountedPtrLess<SubchannelWrapper>>
pending_subchannel_updates_;
//
@ -314,7 +314,7 @@ class ChannelData {
// synchronously via grpc_channel_num_external_connectivity_watchers().
//
mutable Mutex external_watchers_mu_;
Map<grpc_closure*, ExternalConnectivityWatcher*> external_watchers_;
std::map<grpc_closure*, ExternalConnectivityWatcher*> external_watchers_;
};
//
@ -1107,7 +1107,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
// subchannel. This is needed so that when the LB policy calls
// CancelConnectivityStateWatch() with its watcher, we know the
// corresponding WrapperWatcher to cancel on the underlying subchannel.
Map<ConnectivityStateWatcherInterface*, WatcherWrapper*> watcher_map_;
std::map<ConnectivityStateWatcherInterface*, WatcherWrapper*> watcher_map_;
// To be accessed only in the control plane combiner.
RefCountedPtr<ConnectedSubchannel> connected_subchannel_;
// To be accessed only in the data plane mutex.

@ -24,7 +24,6 @@
#include <grpc/impl/codegen/grpc_types.h>
#include "src/core/ext/filters/client_channel/subchannel.h"
#include "src/core/lib/gprpp/abstract.h"
namespace grpc_core {
@ -33,8 +32,7 @@ class ClientChannelFactory {
virtual ~ClientChannelFactory() = default;
// Creates a subchannel with the specified args.
virtual Subchannel* CreateSubchannel(const grpc_channel_args* args)
GRPC_ABSTRACT;
virtual Subchannel* CreateSubchannel(const grpc_channel_args* args) = 0;
// Returns a channel arg containing the specified factory.
static grpc_arg CreateChannelArg(ClientChannelFactory* factory);
@ -42,8 +40,6 @@ class ClientChannelFactory {
// Returns the factory from args, or null if not found.
static ClientChannelFactory* GetFromChannelArgs(
const grpc_channel_args* args);
GRPC_ABSTRACT_BASE_CLASS
};
} // namespace grpc_core

@ -24,7 +24,6 @@
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/filters/client_channel/service_config.h"
#include "src/core/ext/filters/client_channel/subchannel_interface.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
@ -91,11 +90,11 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// Application-specific requests cost metrics. Metric names are
/// determined by the application. Each value is an absolute cost
/// (e.g. 3487 bytes of storage) associated with the request.
Map<StringView, double, StringLess> request_cost;
std::map<StringView, double, StringLess> request_cost;
/// Application-specific resource utilization metrics. Metric names
/// are determined by the application. Each value is expressed as a
/// fraction of total resources available.
Map<StringView, double, StringLess> utilization;
std::map<StringView, double, StringLess> utilization;
};
/// Interface for accessing per-call state.
@ -109,13 +108,11 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// automatically freed when the call is complete.
/// It is more efficient to use this than to allocate memory directly
/// for allocations that need to be made on a per-call basis.
virtual void* Alloc(size_t size) GRPC_ABSTRACT;
virtual void* Alloc(size_t size) = 0;
/// Returns the backend metric data returned by the server for the call,
/// or null if no backend metric data was returned.
virtual const BackendMetricData* GetBackendMetricData() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual const BackendMetricData* GetBackendMetricData() = 0;
};
/// Interface for accessing metadata.
@ -134,20 +131,18 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// Implementations must ensure that the key and value remain alive
/// until the call ends. If desired, they may be allocated via
/// CallState::Alloc().
virtual void Add(StringView key, StringView value) GRPC_ABSTRACT;
virtual void Add(StringView key, StringView value) = 0;
/// Iteration interface.
virtual Iterator Begin() const GRPC_ABSTRACT;
virtual bool IsEnd(Iterator it) const GRPC_ABSTRACT;
virtual void Next(Iterator* it) const GRPC_ABSTRACT;
virtual StringView Key(Iterator it) const GRPC_ABSTRACT;
virtual StringView Value(Iterator it) const GRPC_ABSTRACT;
virtual Iterator Begin() const = 0;
virtual bool IsEnd(Iterator it) const = 0;
virtual void Next(Iterator* it) const = 0;
virtual StringView Key(Iterator it) const = 0;
virtual StringView Value(Iterator it) const = 0;
/// Removes the element pointed to by \a it, which is modified to
/// point to the next element.
virtual void Erase(Iterator* it) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual void Erase(Iterator* it) = 0;
};
/// Arguments used when picking a subchannel for a call.
@ -229,9 +224,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
SubchannelPicker() = default;
virtual ~SubchannelPicker() = default;
virtual PickResult Pick(PickArgs args) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual PickResult Pick(PickArgs args) = 0;
};
/// A proxy object implemented by the client channel and used by the
@ -246,22 +239,19 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
/// Creates a new subchannel with the specified channel args.
virtual RefCountedPtr<SubchannelInterface> CreateSubchannel(
const grpc_channel_args& args) GRPC_ABSTRACT;
const grpc_channel_args& args) = 0;
/// Sets the connectivity state and returns a new picker to be used
/// by the client channel.
virtual void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker>) GRPC_ABSTRACT;
UniquePtr<SubchannelPicker>) = 0;
/// Requests that the resolver re-resolve.
virtual void RequestReresolution() GRPC_ABSTRACT;
virtual void RequestReresolution() = 0;
/// Adds a trace message associated with the channel.
enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR };
virtual void AddTraceEvent(TraceSeverity severity,
StringView message) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual void AddTraceEvent(TraceSeverity severity, StringView message) = 0;
};
/// Interface for configuration data used by an LB policy implementation.
@ -272,9 +262,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
virtual ~Config() = default;
// Returns the load balancing policy name
virtual const char* name() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual const char* name() const = 0;
};
/// Data passed to the UpdateLocked() method when new addresses and
@ -319,12 +307,12 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
LoadBalancingPolicy& operator=(const LoadBalancingPolicy&) = delete;
/// Returns the name of the LB policy.
virtual const char* name() const GRPC_ABSTRACT;
virtual const char* name() const = 0;
/// Updates the policy with new data from the resolver. Will be invoked
/// immediately after LB policy is constructed, and then again whenever
/// the resolver returns a new result.
virtual void UpdateLocked(UpdateArgs) GRPC_ABSTRACT; // NOLINT
virtual void UpdateLocked(UpdateArgs) = 0; // NOLINT
/// Tries to enter a READY connectivity state.
/// This is a no-op by default, since most LB policies never go into
@ -332,7 +320,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
virtual void ExitIdleLocked() {}
/// Resets connection backoff.
virtual void ResetBackoffLocked() GRPC_ABSTRACT;
virtual void ResetBackoffLocked() = 0;
grpc_pollset_set* interested_parties() const { return interested_parties_; }
@ -370,8 +358,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
grpc_error* error_;
};
GRPC_ABSTRACT_BASE_CLASS
protected:
grpc_combiner* combiner() const { return combiner_; }
@ -382,7 +368,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
}
/// Shuts down the policy.
virtual void ShutdownLocked() GRPC_ABSTRACT;
virtual void ShutdownLocked() = 0;
private:
/// Combiner under which LB policy actions take place.

@ -33,7 +33,6 @@
#include "src/core/ext/filters/client_channel/subchannel_interface.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted.h"
@ -117,8 +116,6 @@ class SubchannelData {
// Cancels any pending connectivity watch and unrefs the subchannel.
void ShutdownLocked();
GRPC_ABSTRACT_BASE_CLASS
protected:
SubchannelData(
SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
@ -131,7 +128,7 @@ class SubchannelData {
// invoked whenever the subchannel's connectivity state changes.
// To stop watching, use CancelConnectivityWatchLocked().
virtual void ProcessConnectivityChangeLocked(
grpc_connectivity_state connectivity_state) GRPC_ABSTRACT;
grpc_connectivity_state connectivity_state) = 0;
private:
// Watcher for subchannel connectivity state.
@ -200,8 +197,6 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
InternallyRefCounted<SubchannelListType>::Unref(DEBUG_LOCATION, "shutdown");
}
GRPC_ABSTRACT_BASE_CLASS
protected:
SubchannelList(LoadBalancingPolicy* policy, TraceFlag* tracer,
const ServerAddressList& addresses,

@ -576,8 +576,8 @@ class XdsLb : public LoadBalancingPolicy {
RefCountedPtr<XdsLb> xds_policy_;
Map<RefCountedPtr<XdsLocalityName>, OrphanablePtr<Locality>,
XdsLocalityName::Less>
std::map<RefCountedPtr<XdsLocalityName>, OrphanablePtr<Locality>,
XdsLocalityName::Less>
localities_;
const uint32_t priority_;
grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE;

@ -143,15 +143,11 @@ XdsClientStats::Snapshot XdsClientStats::GetSnapshotAndReset() {
}
{
MutexLock lock(&dropped_requests_mu_);
#if GRPC_USE_CPP_STD_LIB
// This is a workaround for the case where some compilers cannot build
// move-assignment of map with non-copyable but movable key.
// https://stackoverflow.com/questions/36475497
std::swap(snapshot.dropped_requests, dropped_requests_);
dropped_requests_.clear();
#else
snapshot.dropped_requests = std::move(dropped_requests_);
#endif
}
return snapshot;
}

@ -111,9 +111,9 @@ class XdsClientStats {
double total_metric_value_{0};
};
using LoadMetricMap = Map<UniquePtr<char>, LoadMetric, StringLess>;
using LoadMetricMap = std::map<UniquePtr<char>, LoadMetric, StringLess>;
using LoadMetricSnapshotMap =
Map<UniquePtr<char>, LoadMetric::Snapshot, StringLess>;
std::map<UniquePtr<char>, LoadMetric::Snapshot, StringLess>;
struct Snapshot {
// TODO(juanlishen): Change this to const method when const_iterator is
@ -180,12 +180,12 @@ class XdsClientStats {
// UniquePtr<>. We should remove this wrapper if the value type of Map<>
// doesn't have to be movable.
using LocalityStatsMap =
Map<RefCountedPtr<XdsLocalityName>, RefCountedPtr<LocalityStats>,
XdsLocalityName::Less>;
std::map<RefCountedPtr<XdsLocalityName>, RefCountedPtr<LocalityStats>,
XdsLocalityName::Less>;
using LocalityStatsSnapshotMap =
Map<RefCountedPtr<XdsLocalityName>, LocalityStats::Snapshot,
XdsLocalityName::Less>;
using DroppedRequestsMap = Map<UniquePtr<char>, uint64_t, StringLess>;
std::map<RefCountedPtr<XdsLocalityName>, LocalityStats::Snapshot,
XdsLocalityName::Less>;
using DroppedRequestsMap = std::map<UniquePtr<char>, uint64_t, StringLess>;
using DroppedRequestsSnapshotMap = DroppedRequestsMap;
struct Snapshot {

@ -346,15 +346,7 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) {
namespace {
void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output,
#if GRPC_USE_CPP_STD_LIB
// TODO(veblush): Clean up this
// This is to address the difference between
// std::map and Map. #else block will be gone
// once using stdlib is enabled by default.
Pair<const RefCountedPtr<XdsLocalityName>,
#else
Pair<RefCountedPtr<XdsLocalityName>,
#endif
XdsClientStats::LocalityStats::Snapshot>& input,
upb_arena* arena) {
// Set sub_zone.

@ -57,7 +57,7 @@ class XdsPriorityListUpdate {
size_t size() const { return localities.size(); }
Map<RefCountedPtr<XdsLocalityName>, Locality, XdsLocalityName::Less>
std::map<RefCountedPtr<XdsLocalityName>, Locality, XdsLocalityName::Less>
localities;
};

@ -22,7 +22,6 @@
#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/lb_policy.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/orphanable.h"
namespace grpc_core {
@ -31,18 +30,16 @@ class LoadBalancingPolicyFactory {
public:
/// Returns a new LB policy instance.
virtual OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
LoadBalancingPolicy::Args) const GRPC_ABSTRACT;
LoadBalancingPolicy::Args) const = 0;
/// Returns the LB policy name that this factory provides.
/// Caller does NOT take ownership of result.
virtual const char* name() const GRPC_ABSTRACT;
virtual const char* name() const = 0;
virtual RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
const grpc_json* json, grpc_error** error) const GRPC_ABSTRACT;
const grpc_json* json, grpc_error** error) const = 0;
virtual ~LoadBalancingPolicyFactory() {}
GRPC_ABSTRACT_BASE_CLASS;
};
} // namespace grpc_core

@ -25,7 +25,6 @@
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/filters/client_channel/service_config.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/combiner.h"
@ -74,17 +73,15 @@ class Resolver : public InternallyRefCounted<Resolver> {
/// Returns a result to the channel.
/// Takes ownership of \a result.args.
virtual void ReturnResult(Result result) GRPC_ABSTRACT; // NOLINT
virtual void ReturnResult(Result result) = 0; // NOLINT
/// Returns a transient error to the channel.
/// If the resolver does not set the GRPC_ERROR_INT_GRPC_STATUS
/// attribute on the error, calls will be failed with status UNKNOWN.
virtual void ReturnError(grpc_error* error) GRPC_ABSTRACT;
virtual void ReturnError(grpc_error* error) = 0;
// TODO(yashkt): As part of the service config error handling
// changes, add a method to parse the service config JSON string.
GRPC_ABSTRACT_BASE_CLASS
};
// Not copyable nor movable.
@ -92,7 +89,7 @@ class Resolver : public InternallyRefCounted<Resolver> {
Resolver& operator=(const Resolver&) = delete;
/// Starts resolving.
virtual void StartLocked() GRPC_ABSTRACT;
virtual void StartLocked() = 0;
/// Asks the resolver to obtain an updated resolver result, if
/// applicable.
@ -123,8 +120,6 @@ class Resolver : public InternallyRefCounted<Resolver> {
Unref();
}
GRPC_ABSTRACT_BASE_CLASS
protected:
GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
@ -138,7 +133,7 @@ class Resolver : public InternallyRefCounted<Resolver> {
virtual ~Resolver();
/// Shuts down the resolver.
virtual void ShutdownLocked() GRPC_ABSTRACT;
virtual void ShutdownLocked() = 0;
grpc_combiner* combiner() const { return combiner_; }

@ -23,7 +23,6 @@
#include <ares.h>
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/iomgr/pollset_set.h"
typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;
@ -67,22 +66,18 @@ class GrpcPolledFd {
public:
virtual ~GrpcPolledFd() {}
/* Called when c-ares library is interested and there's no pending callback */
virtual void RegisterForOnReadableLocked(grpc_closure* read_closure)
GRPC_ABSTRACT;
virtual void RegisterForOnReadableLocked(grpc_closure* read_closure) = 0;
/* Called when c-ares library is interested and there's no pending callback */
virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure)
GRPC_ABSTRACT;
virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure) = 0;
/* Indicates if there is data left even after just being read from */
virtual bool IsFdStillReadableLocked() GRPC_ABSTRACT;
virtual bool IsFdStillReadableLocked() = 0;
/* Called once and only once. Must cause cancellation of any pending
* read/write callbacks. */
virtual void ShutdownLocked(grpc_error* error) GRPC_ABSTRACT;
virtual void ShutdownLocked(grpc_error* error) = 0;
/* Get the underlying ares_socket_t that this was created from */
virtual ares_socket_t GetWrappedAresSocketLocked() GRPC_ABSTRACT;
virtual ares_socket_t GetWrappedAresSocketLocked() = 0;
/* A unique name, for logging */
virtual const char* GetName() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual const char* GetName() = 0;
};
/* A GrpcPolledFdFactory is 1-to-1 with and owned by the
@ -95,11 +90,9 @@ class GrpcPolledFdFactory {
/* Creates a new wrapped fd for the current platform */
virtual GrpcPolledFd* NewGrpcPolledFdLocked(
ares_socket_t as, grpc_pollset_set* driver_pollset_set,
grpc_combiner* combiner) GRPC_ABSTRACT;
grpc_combiner* combiner) = 0;
/* Optionally configures the ares channel after creation */
virtual void ConfigureAresChannelLocked(ares_channel channel) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual void ConfigureAresChannelLocked(ares_channel channel) = 0;
};
UniquePtr<GrpcPolledFdFactory> NewGrpcPolledFdFactory(grpc_combiner* combiner);

@ -24,7 +24,6 @@
#include <grpc/support/string_util.h>
#include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/iomgr/pollset_set.h"
@ -49,11 +48,10 @@ class ResolverFactory {
public:
/// Returns a bool indicating whether the input uri is valid to create a
/// resolver.
virtual bool IsValidUri(const grpc_uri* uri) const GRPC_ABSTRACT;
virtual bool IsValidUri(const grpc_uri* uri) const = 0;
/// Returns a new resolver instance.
virtual OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const
GRPC_ABSTRACT;
virtual OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const = 0;
/// Returns a string representing the default authority to use for this
/// scheme.
@ -65,11 +63,9 @@ class ResolverFactory {
/// Returns the URI scheme that this factory implements.
/// Caller does NOT take ownership of result.
virtual const char* scheme() const GRPC_ABSTRACT;
virtual const char* scheme() const = 0;
virtual ~ResolverFactory() {}
GRPC_ABSTRACT_BASE_CLASS
};
} // namespace grpc_core

@ -62,8 +62,6 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
class ParsedConfig {
public:
virtual ~ParsedConfig() = default;
GRPC_ABSTRACT_BASE_CLASS;
};
/// This is the base class that all service config parsers should derive from.
@ -82,8 +80,6 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
GPR_DEBUG_ASSERT(error != nullptr);
return nullptr;
}
GRPC_ABSTRACT_BASE_CLASS;
};
static constexpr int kNumPreallocatedParsers = 4;

@ -192,11 +192,9 @@ class Subchannel {
virtual void OnConnectivityStateChange(
grpc_connectivity_state new_state,
RefCountedPtr<ConnectedSubchannel> connected_subchannel) // NOLINT
GRPC_ABSTRACT;
= 0;
virtual grpc_pollset_set* interested_parties() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual grpc_pollset_set* interested_parties() = 0;
};
// The ctor and dtor are not intended to use directly.
@ -296,8 +294,8 @@ class Subchannel {
private:
// TODO(roth): This could be a set instead of a map if we had a set
// implementation.
Map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_;
};
@ -330,7 +328,7 @@ class Subchannel {
private:
class HealthWatcher;
Map<const char*, OrphanablePtr<HealthWatcher>, StringLess> map_;
std::map<const char*, OrphanablePtr<HealthWatcher>, StringLess> map_;
};
class ConnectedSubchannelStateWatcher;

@ -36,14 +36,12 @@ class SubchannelInterface : public RefCounted<SubchannelInterface> {
// Will be invoked whenever the subchannel's connectivity state
// changes. There will be only one invocation of this method on a
// given watcher instance at any given time.
virtual void OnConnectivityStateChange(grpc_connectivity_state new_state)
GRPC_ABSTRACT;
virtual void OnConnectivityStateChange(
grpc_connectivity_state new_state) = 0;
// TODO(roth): Remove this as soon as we move to EventManager-based
// polling.
virtual grpc_pollset_set* interested_parties() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual grpc_pollset_set* interested_parties() = 0;
};
template <typename TraceFlagT = TraceFlag>
@ -53,7 +51,7 @@ class SubchannelInterface : public RefCounted<SubchannelInterface> {
virtual ~SubchannelInterface() = default;
// Returns the current connectivity state of the subchannel.
virtual grpc_connectivity_state CheckConnectivityState() GRPC_ABSTRACT;
virtual grpc_connectivity_state CheckConnectivityState() = 0;
// Starts watching the subchannel's connectivity state.
// The first callback to the watcher will be delivered when the
@ -68,29 +66,27 @@ class SubchannelInterface : public RefCounted<SubchannelInterface> {
// the previous watcher using CancelConnectivityStateWatch().
virtual void WatchConnectivityState(
grpc_connectivity_state initial_state,
UniquePtr<ConnectivityStateWatcherInterface> watcher) GRPC_ABSTRACT;
UniquePtr<ConnectivityStateWatcherInterface> watcher) = 0;
// Cancels a connectivity state watch.
// If the watcher has already been destroyed, this is a no-op.
virtual void CancelConnectivityStateWatch(
ConnectivityStateWatcherInterface* watcher) GRPC_ABSTRACT;
ConnectivityStateWatcherInterface* watcher) = 0;
// Attempt to connect to the backend. Has no effect if already connected.
// If the subchannel is currently in backoff delay due to a previously
// failed attempt, the new connection attempt will not start until the
// backoff delay has elapsed.
virtual void AttemptToConnect() GRPC_ABSTRACT;
virtual void AttemptToConnect() = 0;
// Resets the subchannel's connection backoff state. If AttemptToConnect()
// has been called since the subchannel entered TRANSIENT_FAILURE state,
// starts a new connection attempt immediately; otherwise, a new connection
// attempt will be started as soon as AttemptToConnect() is called.
virtual void ResetBackoff() GRPC_ABSTRACT;
virtual void ResetBackoff() = 0;
// TODO(roth): Need a better non-grpc-specific abstraction here.
virtual const grpc_channel_args* channel_args() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual const grpc_channel_args* channel_args() = 0;
};
} // namespace grpc_core

@ -23,7 +23,6 @@
#include "src/core/lib/avl/avl.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/ref_counted.h"
namespace grpc_core {
@ -70,14 +69,14 @@ class SubchannelPoolInterface : public RefCounted<SubchannelPoolInterface> {
// with \a key, which may be different from \a constructed because we reuse
// (instead of update) any existing subchannel already registered with \a key.
virtual Subchannel* RegisterSubchannel(SubchannelKey* key,
Subchannel* constructed) GRPC_ABSTRACT;
Subchannel* constructed) = 0;
// Removes the registered subchannel found by \a key.
virtual void UnregisterSubchannel(SubchannelKey* key) GRPC_ABSTRACT;
virtual void UnregisterSubchannel(SubchannelKey* key) = 0;
// Finds the subchannel registered for the given subchannel key. Returns NULL
// if no such channel exists. Thread-safe.
virtual Subchannel* FindSubchannel(SubchannelKey* key) GRPC_ABSTRACT;
virtual Subchannel* FindSubchannel(SubchannelKey* key) = 0;
// Creates a channel arg from \a subchannel pool.
static grpc_arg CreateChannelArg(SubchannelPoolInterface* subchannel_pool);
@ -85,8 +84,6 @@ class SubchannelPoolInterface : public RefCounted<SubchannelPoolInterface> {
// Gets the subchannel pool from the channel args.
static SubchannelPoolInterface* GetSubchannelPoolFromChannelArgs(
const grpc_channel_args* args);
GRPC_ABSTRACT_BASE_CLASS
};
} // namespace grpc_core

@ -25,7 +25,6 @@
#include "src/core/ext/transport/chttp2/transport/http2_settings.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/transport/bdp_estimator.h"
#include "src/core/lib/transport/pid_controller.h"
@ -189,8 +188,6 @@ class TransportFlowControlBase {
// factor
virtual void TestOnlyForceHugeWindow() {}
GRPC_ABSTRACT_BASE_CLASS
protected:
friend class ::grpc::testing::TrickledCHTTP2;
int64_t remote_window_ = kDefaultWindow;
@ -385,8 +382,6 @@ class StreamFlowControlBase {
int64_t local_window_delta() { return local_window_delta_; }
int64_t announced_window_delta() { return announced_window_delta_; }
GRPC_ABSTRACT_BASE_CLASS
protected:
friend class ::grpc::testing::TrickledCHTTP2;
int64_t remote_window_delta_ = 0;

@ -88,7 +88,7 @@ class BaseNode : public RefCounted<BaseNode> {
virtual ~BaseNode();
// All children must implement this function.
virtual grpc_json* RenderJson() GRPC_ABSTRACT;
virtual grpc_json* RenderJson() = 0;
// Renders the json and returns allocated string that must be freed by the
// caller.
@ -221,8 +221,8 @@ class ChannelNode : public BaseNode {
// TODO(roth): We don't actually use the values here, only the keys, so
// these should be sets instead of maps, but we don't currently have a set
// implementation. Change this if/when we have one.
Map<intptr_t, bool> child_channels_;
Map<intptr_t, bool> child_subchannels_;
std::map<intptr_t, bool> child_channels_;
std::map<intptr_t, bool> child_subchannels_;
};
// Handles channelz bookkeeping for servers
@ -262,8 +262,8 @@ class ServerNode : public BaseNode {
CallCountingHelper call_counter_;
ChannelTrace trace_;
Mutex child_mu_; // Guards child maps below.
Map<intptr_t, RefCountedPtr<SocketNode>> child_sockets_;
Map<intptr_t, RefCountedPtr<ListenSocketNode>> child_listen_sockets_;
std::map<intptr_t, RefCountedPtr<SocketNode>> child_sockets_;
std::map<intptr_t, RefCountedPtr<ListenSocketNode>> child_listen_sockets_;
};
// Handles channelz bookkeeping for sockets

@ -87,7 +87,7 @@ class ChannelzRegistry {
// protects members
Mutex mu_;
Map<intptr_t, BaseNode*> node_map_;
std::map<intptr_t, BaseNode*> node_map_;
intptr_t uuid_generator_ = 0;
};

@ -77,12 +77,11 @@ struct HandshakerArgs {
class Handshaker : public RefCounted<Handshaker> {
public:
virtual ~Handshaker() = default;
virtual void Shutdown(grpc_error* why) GRPC_ABSTRACT;
virtual void Shutdown(grpc_error* why) = 0;
virtual void DoHandshake(grpc_tcp_server_acceptor* acceptor,
grpc_closure* on_handshake_done,
HandshakerArgs* args) GRPC_ABSTRACT;
virtual const char* name() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
HandshakerArgs* args) = 0;
virtual const char* name() const = 0;
};
//

@ -33,10 +33,8 @@ class HandshakerFactory {
public:
virtual void AddHandshakers(const grpc_channel_args* args,
grpc_pollset_set* interested_parties,
HandshakeManager* handshake_mgr) GRPC_ABSTRACT;
HandshakeManager* handshake_mgr) = 0;
virtual ~HandshakerFactory() = default;
GRPC_ABSTRACT_BASE_CLASS
};
} // namespace grpc_core

@ -1,47 +0,0 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_ABSTRACT_H
#define GRPC_CORE_LIB_GPRPP_ABSTRACT_H
#if GRPC_USE_CPP_STD_LIB
#define GRPC_ABSTRACT_BASE_CLASS
#define GRPC_ABSTRACT = 0
#else
// This is needed to support abstract base classes in the c core. Since gRPC
// doesn't have a c++ runtime, it will hit a linker error on delete unless
// we define a virtual operator delete. See this blog for more info:
// https://eli.thegreenplace.net/2015/c-deleting-destructors-and-virtual-operator-delete/
#define GRPC_ABSTRACT_BASE_CLASS \
static void operator delete(void* p) { abort(); }
// gRPC currently can't depend on libstdc++, so we can't use "= 0" for
// pure virtual methods. Instead, we use this macro.
#define GRPC_ABSTRACT \
{ \
gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented"); \
GPR_ASSERT(false); \
}
#endif // GRPC_USE_CPP_STD_LIB
#endif /* GRPC_CORE_LIB_GPRPP_ABSTRACT_H */

@ -26,10 +26,7 @@
#include <algorithm>
#include <functional>
#include <iterator>
#if GRPC_USE_CPP_STD_LIB
#include <map>
#endif
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
@ -62,503 +59,6 @@ struct RefCountedPtrLess {
}
};
#if GRPC_USE_CPP_STD_LIB
template <class Key, class T, class Compare = std::less<Key>>
using Map = std::map<Key, T, Compare>;
#else // GRPC_USE_CPP_STD_LIB
namespace testing {
class MapTest;
}
// Alternative map implementation for grpc_core
template <class Key, class T, class Compare = std::less<Key>>
class Map {
public:
typedef Key key_type;
typedef T mapped_type;
typedef Pair<key_type, mapped_type> value_type;
typedef Compare key_compare;
class iterator;
class const_iterator;
Map() = default;
~Map() { clear(); }
// Movable.
Map(Map&& other) : root_(other.root_), size_(other.size_) {
other.root_ = nullptr;
other.size_ = 0;
}
Map& operator=(Map&& other) {
if (this != &other) {
clear();
root_ = other.root_;
size_ = other.size_;
other.root_ = nullptr;
other.size_ = 0;
}
return *this;
}
// Copyable.
Map(const Map& other) {
for (const auto& p : other) {
emplace(p);
}
}
Map& operator=(const Map& other) {
if (this != &other) {
clear();
for (const auto& p : other) {
emplace(p);
}
}
return *this;
}
T& operator[](key_type&& key);
T& operator[](const key_type& key);
iterator find(const key_type& k);
size_t erase(const key_type& key);
// Removes the current entry and points to the next one
iterator erase(iterator iter);
size_t size() const { return size_; }
template <class... Args>
Pair<iterator, bool> emplace(Args&&... args);
Pair<iterator, bool> insert(value_type&& pair) {
return emplace(std::move(pair));
}
Pair<iterator, bool> insert(const value_type& pair) { return emplace(pair); }
bool empty() const { return root_ == nullptr; }
void clear() {
auto iter = begin();
while (!empty()) {
iter = erase(iter);
}
}
iterator begin() {
Entry* curr = GetMinEntry(root_);
return iterator(this, curr);
}
iterator end() { return iterator(this, nullptr); }
const_iterator begin() const {
Entry* curr = GetMinEntry(root_);
return const_iterator(this, curr);
}
const_iterator end() const { return const_iterator(this, nullptr); }
iterator lower_bound(const Key& k) {
// This is a workaround for "const key_compare compare;"
// because some versions of compilers cannot build this by requiring
// a user-provided constructor. (ref: https://stackoverflow.com/q/7411515)
key_compare compare_tmp;
const key_compare& compare = compare_tmp;
return std::find_if(begin(), end(), [&k, &compare](const value_type& v) {
return !compare(v.first, k);
});
}
private:
friend class testing::MapTest;
struct Entry {
explicit Entry(value_type&& pair) : pair(std::move(pair)) {}
value_type pair;
Entry* left = nullptr;
Entry* right = nullptr;
int32_t height = 1;
};
static int32_t EntryHeight(const Entry* e) {
return e == nullptr ? 0 : e->height;
}
static Entry* GetMinEntry(Entry* e);
Entry* InOrderSuccessor(const Entry* e) const;
static Entry* RotateLeft(Entry* e);
static Entry* RotateRight(Entry* e);
static Entry* RebalanceTreeAfterInsertion(Entry* root, const key_type& k);
static Entry* RebalanceTreeAfterDeletion(Entry* root);
// Returns a pair with the first value being an iterator pointing to the
// inserted entry and the second value being the new root of the subtree
// after a rebalance
Pair<iterator, Entry*> InsertRecursive(Entry* root, value_type&& p);
// Returns a pair with the first value being an iterator pointing to the
// successor of the deleted entry and the second value being the new root of
// the subtree after a rebalance
Pair<iterator, Entry*> RemoveRecursive(Entry* root, const key_type& k);
// Return 0 if lhs = rhs
// 1 if lhs > rhs
// -1 if lhs < rhs
static int CompareKeys(const Key& lhs, const Key& rhs);
Entry* root_ = nullptr;
size_t size_ = 0;
};
template <class Key, class T, class Compare>
class Map<Key, T, Compare>::iterator
: public std::iterator<std::input_iterator_tag, Pair<Key, T>, int32_t,
Pair<Key, T>*, Pair<Key, T>&> {
public:
iterator(const iterator& iter) : curr_(iter.curr_), map_(iter.map_) {}
bool operator==(const iterator& rhs) const { return (curr_ == rhs.curr_); }
bool operator!=(const iterator& rhs) const { return (curr_ != rhs.curr_); }
iterator& operator++() {
curr_ = map_->InOrderSuccessor(curr_);
return *this;
}
iterator operator++(int) {
Entry* prev = curr_;
curr_ = map_->InOrderSuccessor(curr_);
return iterator(map_, prev);
}
iterator& operator=(const iterator& other) {
if (this != &other) {
this->curr_ = other.curr_;
this->map_ = other.map_;
}
return *this;
}
// operator*()
value_type& operator*() { return curr_->pair; }
const value_type& operator*() const { return curr_->pair; }
// operator->()
value_type* operator->() { return &curr_->pair; }
value_type const* operator->() const { return &curr_->pair; }
private:
friend class Map<key_type, mapped_type, key_compare>;
using GrpcMap = typename ::grpc_core::Map<Key, T, Compare>;
iterator(GrpcMap* map, Entry* curr) : curr_(curr), map_(map) {}
Entry* curr_;
GrpcMap* map_;
};
template <class Key, class T, class Compare>
class Map<Key, T, Compare>::const_iterator
: public std::iterator<std::input_iterator_tag, Pair<Key, T>, int32_t,
Pair<Key, T>*, Pair<Key, T>&> {
public:
const_iterator(const const_iterator& iter)
: curr_(iter.curr_), map_(iter.map_) {}
bool operator==(const const_iterator& rhs) const {
return (curr_ == rhs.curr_);
}
bool operator!=(const const_iterator& rhs) const {
return (curr_ != rhs.curr_);
}
const_iterator& operator++() {
curr_ = map_->InOrderSuccessor(curr_);
return *this;
}
const_iterator operator++(int) {
Entry* prev = curr_;
curr_ = map_->InOrderSuccessor(curr_);
return const_iterator(map_, prev);
}
const_iterator& operator=(const const_iterator& other) {
if (this != &other) {
this->curr_ = other.curr_;
this->map_ = other.map_;
}
return *this;
}
// operator*()
const value_type& operator*() const { return curr_->pair; }
// operator->()
const value_type* operator->() const { return &curr_->pair; }
private:
friend class Map<key_type, mapped_type, key_compare>;
using GrpcMap = typename ::grpc_core::Map<Key, T, Compare>;
const_iterator(const GrpcMap* map, Entry* curr) : curr_(curr), map_(map) {}
Entry* curr_;
const GrpcMap* map_;
};
template <class Key, class T, class Compare>
T& Map<Key, T, Compare>::operator[](key_type&& key) {
auto iter = find(key);
if (iter == end()) {
return emplace(std::move(key), T()).first->second;
}
return iter->second;
}
template <class Key, class T, class Compare>
T& Map<Key, T, Compare>::operator[](const key_type& key) {
auto iter = find(key);
if (iter == end()) {
return emplace(key, T()).first->second;
}
return iter->second;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::iterator Map<Key, T, Compare>::find(
const key_type& k) {
Entry* iter = root_;
while (iter != nullptr) {
int comp = CompareKeys(iter->pair.first, k);
if (comp == 0) {
return iterator(this, iter);
} else if (comp < 0) {
iter = iter->right;
} else {
iter = iter->left;
}
}
return end();
}
template <class Key, class T, class Compare>
template <class... Args>
typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator, bool>
Map<Key, T, Compare>::emplace(Args&&... args) {
Pair<key_type, mapped_type> pair(std::forward<Args>(args)...);
iterator ret = find(pair.first);
bool insertion = false;
if (ret == end()) {
Pair<iterator, Entry*> p = InsertRecursive(root_, std::move(pair));
root_ = p.second;
ret = p.first;
insertion = true;
size_++;
}
return MakePair(ret, insertion);
}
template <class Key, class T, class Compare>
size_t Map<Key, T, Compare>::erase(const key_type& key) {
iterator it = find(key);
if (it == end()) return 0;
erase(it);
return 1;
}
// TODO(mhaidry): Modify erase to use the iterator location
// to create an efficient erase method
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::iterator Map<Key, T, Compare>::erase(
iterator iter) {
if (iter == end()) return iter;
key_type& del_key = iter->first;
Pair<iterator, Entry*> ret = RemoveRecursive(root_, del_key);
root_ = ret.second;
size_--;
return ret.first;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::InOrderSuccessor(
const Entry* e) const {
if (e->right != nullptr) {
return GetMinEntry(e->right);
}
Entry* successor = nullptr;
Entry* iter = root_;
while (iter != nullptr) {
int comp = CompareKeys(iter->pair.first, e->pair.first);
if (comp > 0) {
successor = iter;
iter = iter->left;
} else if (comp < 0) {
iter = iter->right;
} else
break;
}
return successor;
}
// Returns a pair with the first value being an iterator pointing to the
// inserted entry and the second value being the new root of the subtree
// after a rebalance
template <class Key, class T, class Compare>
typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator,
typename Map<Key, T, Compare>::Entry*>
Map<Key, T, Compare>::InsertRecursive(Entry* root, value_type&& p) {
if (root == nullptr) {
Entry* e = New<Entry>(std::move(p));
return MakePair(iterator(this, e), e);
}
int comp = CompareKeys(root->pair.first, p.first);
if (comp > 0) {
Pair<iterator, Entry*> ret = InsertRecursive(root->left, std::move(p));
root->left = ret.second;
ret.second = RebalanceTreeAfterInsertion(root, ret.first->first);
return ret;
} else if (comp < 0) {
Pair<iterator, Entry*> ret = InsertRecursive(root->right, std::move(p));
root->right = ret.second;
ret.second = RebalanceTreeAfterInsertion(root, ret.first->first);
return ret;
} else {
root->pair = std::move(p);
return MakePair(iterator(this, root), root);
}
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::GetMinEntry(
Entry* e) {
if (e != nullptr) {
while (e->left != nullptr) {
e = e->left;
}
}
return e;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RotateLeft(
Entry* e) {
Entry* rightChild = e->right;
Entry* rightLeftChild = rightChild->left;
rightChild->left = e;
e->right = rightLeftChild;
e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right));
rightChild->height = 1 + GPR_MAX(EntryHeight(rightChild->left),
EntryHeight(rightChild->right));
return rightChild;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RotateRight(
Entry* e) {
Entry* leftChild = e->left;
Entry* leftRightChild = leftChild->right;
leftChild->right = e;
e->left = leftRightChild;
e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right));
leftChild->height =
1 + GPR_MAX(EntryHeight(leftChild->left), EntryHeight(leftChild->right));
return leftChild;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry*
Map<Key, T, Compare>::RebalanceTreeAfterInsertion(Entry* root,
const key_type& k) {
root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right));
int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right);
if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) > 0) {
return RotateRight(root);
}
if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) < 0) {
return RotateLeft(root);
}
if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) < 0) {
root->left = RotateLeft(root->left);
return RotateRight(root);
}
if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) > 0) {
root->right = RotateRight(root->right);
return RotateLeft(root);
}
return root;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry*
Map<Key, T, Compare>::RebalanceTreeAfterDeletion(Entry* root) {
root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right));
int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right);
if (heightDifference > 1) {
int leftHeightDifference =
EntryHeight(root->left->left) - EntryHeight(root->left->right);
if (leftHeightDifference < 0) {
root->left = RotateLeft(root->left);
}
return RotateRight(root);
}
if (heightDifference < -1) {
int rightHeightDifference =
EntryHeight(root->right->left) - EntryHeight(root->right->right);
if (rightHeightDifference > 0) {
root->right = RotateRight(root->right);
}
return RotateLeft(root);
}
return root;
}
template <class Key, class T, class Compare>
typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator,
typename Map<Key, T, Compare>::Entry*>
Map<Key, T, Compare>::RemoveRecursive(Entry* root, const key_type& k) {
Pair<iterator, Entry*> ret = MakePair(end(), root);
if (root == nullptr) return ret;
int comp = CompareKeys(root->pair.first, k);
if (comp > 0) {
ret = RemoveRecursive(root->left, k);
root->left = ret.second;
} else if (comp < 0) {
ret = RemoveRecursive(root->right, k);
root->right = ret.second;
} else {
Entry* entry;
Entry* successor = InOrderSuccessor(root);
if (root->left == nullptr) {
entry = root->right;
Delete(root);
return MakePair(iterator(this, successor), entry);
} else if (root->right == nullptr) {
entry = root->left;
Delete(root);
return MakePair(iterator(this, successor), entry);
} else {
entry = successor;
root->pair.swap(entry->pair);
ret = RemoveRecursive(root->right, entry->pair.first);
root->right = ret.second;
ret.first = iterator(this, root);
}
}
return MakePair(ret.first, RebalanceTreeAfterDeletion(root));
}
template <class Key, class T, class Compare>
int Map<Key, T, Compare>::CompareKeys(const key_type& lhs,
const key_type& rhs) {
// This is a workaround for "const key_compare compare;"
// because some versions of compilers cannot build this by requiring
// a user-provided constructor. (ref: https://stackoverflow.com/q/7411515)
key_compare compare_tmp;
const key_compare& compare = compare_tmp;
bool left_comparison = compare(lhs, rhs);
bool right_comparison = compare(rhs, lhs);
// Both values are equal
if (!left_comparison && !right_comparison) {
return 0;
}
return left_comparison ? -1 : 1;
}
#endif // GRPC_USE_CPP_STD_LIB
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_MAP_H */

@ -28,7 +28,6 @@
#include <memory>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/ref_counted.h"
@ -46,14 +45,12 @@ class Orphanable {
// Gives up ownership of the object. The implementation must arrange
// to eventually destroy the object without further interaction from the
// caller.
virtual void Orphan() GRPC_ABSTRACT;
virtual void Orphan() = 0;
// Not copyable or movable.
Orphanable(const Orphanable&) = delete;
Orphanable& operator=(const Orphanable&) = delete;
GRPC_ABSTRACT_BASE_CLASS
protected:
Orphanable() {}
virtual ~Orphanable() {}
@ -83,8 +80,6 @@ class InternallyRefCounted : public Orphanable {
InternallyRefCounted(const InternallyRefCounted&) = delete;
InternallyRefCounted& operator=(const InternallyRefCounted&) = delete;
GRPC_ABSTRACT_BASE_CLASS
protected:
GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE

@ -30,7 +30,6 @@
#include <cinttypes>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/memory.h"
@ -40,9 +39,6 @@ namespace grpc_core {
// PolymorphicRefCount enforces polymorphic destruction of RefCounted.
class PolymorphicRefCount {
public:
GRPC_ABSTRACT_BASE_CLASS
protected:
GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
@ -53,9 +49,6 @@ class PolymorphicRefCount {
// RefCounted. Please refer to grpc_core::RefCounted for more details, and
// when in doubt use PolymorphicRefCount.
class NonPolymorphicRefCount {
public:
GRPC_ABSTRACT_BASE_CLASS
protected:
GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
@ -272,8 +265,6 @@ class RefCounted : public Impl {
RefCounted(const RefCounted&) = delete;
RefCounted& operator=(const RefCounted&) = delete;
GRPC_ABSTRACT_BASE_CLASS
protected:
GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE

@ -28,7 +28,6 @@
#include <grpc/support/thd_id.h>
#include <grpc/support/time.h>
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/memory.h"
namespace grpc_core {
@ -38,9 +37,8 @@ namespace internal {
class ThreadInternalsInterface {
public:
virtual ~ThreadInternalsInterface() {}
virtual void Start() GRPC_ABSTRACT;
virtual void Join() GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual void Start() = 0;
virtual void Join() = 0;
};
} // namespace internal

@ -22,7 +22,6 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/sync.h"
@ -38,17 +37,15 @@ class MPMCQueueInterface {
// Puts elem into queue immediately at the end of queue.
// This might cause to block on full queue depending on implementation.
virtual void Put(void* elem) GRPC_ABSTRACT;
virtual void Put(void* elem) = 0;
// Removes the oldest element from the queue and return it.
// This might cause to block on empty queue depending on implementation.
// Optional argument for collecting stats purpose.
virtual void* Get(gpr_timespec* wait_time = nullptr) GRPC_ABSTRACT;
virtual void* Get(gpr_timespec* wait_time = nullptr) = 0;
// Returns number of elements in the queue currently
virtual int count() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual int count() const = 0;
};
class InfLenFIFOQueue : public MPMCQueueInterface {

@ -43,22 +43,19 @@ class ThreadPoolInterface {
// current thread to be blocked (in case of unable to schedule).
// Closure should contain a function pointer and arguments it will take, more
// details for closure struct at /grpc/include/grpc/impl/codegen/grpc_types.h
virtual void Add(grpc_experimental_completion_queue_functor* closure)
GRPC_ABSTRACT;
virtual void Add(grpc_experimental_completion_queue_functor* closure) = 0;
// Returns the current number of pending closures
virtual int num_pending_closures() const GRPC_ABSTRACT;
virtual int num_pending_closures() const = 0;
// Returns the capacity of pool (number of worker threads in pool)
virtual int pool_capacity() const GRPC_ABSTRACT;
virtual int pool_capacity() const = 0;
// Thread option accessor
virtual const Thread::Options& thread_options() const GRPC_ABSTRACT;
virtual const Thread::Options& thread_options() const = 0;
// Returns the thread name for threads in this ThreadPool.
virtual const char* thread_name() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual const char* thread_name() const = 0;
};
// Worker thread for threadpool. Executes closures in the queue, until getting a

@ -24,7 +24,6 @@
#include <grpc/grpc.h>
#include <grpc/impl/codegen/grpc_types.h>
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -57,9 +56,7 @@ class TcpServerFdHandler {
public:
virtual ~TcpServerFdHandler() = default;
virtual void Handle(int listener_fd, int fd,
grpc_byte_buffer* pending_read) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS;
grpc_byte_buffer* pending_read) = 0;
};
} // namespace grpc_core

@ -21,7 +21,6 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -47,18 +46,16 @@ class GrpcUdpHandler {
// Called when data is available to read from the socket. Returns true if
// there is more data to read after this call.
virtual bool Read() GRPC_ABSTRACT;
virtual bool Read() = 0;
// Called when socket becomes write unblocked. The given closure should be
// scheduled when the socket becomes blocked next time.
virtual void OnCanWrite(void* user_data,
grpc_closure* notify_on_write_closure) GRPC_ABSTRACT;
grpc_closure* notify_on_write_closure) = 0;
// Called before the gRPC FD is orphaned. Notify udp server to continue
// orphaning fd by scheduling the given closure, afterwards the associated fd
// will be closed.
virtual void OnFdAboutToOrphan(grpc_closure* orphan_fd_closure,
void* user_data) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
void* user_data) = 0;
};
class GrpcUdpHandlerFactory {
@ -67,11 +64,8 @@ class GrpcUdpHandlerFactory {
/* Called when start to listen on a socket.
* Return an instance of the implementation of GrpcUdpHandler interface which
* will process I/O events for this socket from now on. */
virtual GrpcUdpHandler* CreateUdpHandler(grpc_fd* emfd,
void* user_data) GRPC_ABSTRACT;
virtual void DestroyUdpHandler(GrpcUdpHandler* handler) GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual GrpcUdpHandler* CreateUdpHandler(grpc_fd* emfd, void* user_data) = 0;
virtual void DestroyUdpHandler(GrpcUdpHandler* handler) = 0;
};
/* Create a server, initially not bound to any ports */

@ -45,18 +45,18 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) {
if (creds) creds->Unref();
}
static grpc_core::Map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>* g_grpc_control_plane_creds;
static std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>* g_grpc_control_plane_creds;
static gpr_mu g_control_plane_creds_mu;
static void do_control_plane_creds_init() {
gpr_mu_init(&g_control_plane_creds_mu);
GPR_ASSERT(g_grpc_control_plane_creds == nullptr);
g_grpc_control_plane_creds = grpc_core::New<
grpc_core::Map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>>();
std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>>();
}
void grpc_control_plane_credentials_init() {

@ -110,17 +110,7 @@ struct grpc_channel_credentials
create_security_connector(
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
const char* target, const grpc_channel_args* args,
grpc_channel_args** new_args)
#if GRPC_USE_CPP_STD_LIB
= 0;
#else
{
// Tell clang-tidy that call_creds cannot be passed as const-ref.
call_creds.reset();
gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented");
GPR_ASSERT(false);
}
#endif
grpc_channel_args** new_args) = 0;
// Creates a version of the channel credentials without any attached call
// credentials. This can be used in order to open a channel to a non-trusted
@ -156,13 +146,11 @@ struct grpc_channel_credentials
const char* type() const { return type_; }
GRPC_ABSTRACT_BASE_CLASS
private:
const char* type_;
grpc_core::Map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>
std::map<grpc_core::UniquePtr<char>,
grpc_core::RefCountedPtr<grpc_channel_credentials>,
grpc_core::StringLess>
local_control_plane_creds_;
};
@ -248,18 +236,16 @@ struct grpc_call_credentials
grpc_auth_metadata_context context,
grpc_credentials_mdelem_array* md_array,
grpc_closure* on_request_metadata,
grpc_error** error) GRPC_ABSTRACT;
grpc_error** error) = 0;
// Cancels a pending asynchronous operation started by
// grpc_call_credentials_get_request_metadata() with the corresponding
// value of \a md_array.
virtual void cancel_get_request_metadata(
grpc_credentials_mdelem_array* md_array, grpc_error* error) GRPC_ABSTRACT;
grpc_credentials_mdelem_array* md_array, grpc_error* error) = 0;
const char* type() const { return type_; }
GRPC_ABSTRACT_BASE_CLASS
private:
const char* type_;
};
@ -282,7 +268,7 @@ struct grpc_server_credentials
virtual ~grpc_server_credentials() { DestroyProcessor(); }
virtual grpc_core::RefCountedPtr<grpc_server_security_connector>
create_security_connector() GRPC_ABSTRACT;
create_security_connector() = 0;
const char* type() const { return type_; }
@ -292,8 +278,6 @@ struct grpc_server_credentials
void set_auth_metadata_processor(
const grpc_auth_metadata_processor& processor);
GRPC_ABSTRACT_BASE_CLASS
private:
void DestroyProcessor() {
if (processor_.destroy != nullptr && processor_.state != nullptr) {

@ -85,13 +85,11 @@ class grpc_oauth2_token_fetcher_credentials : public grpc_call_credentials {
void on_http_response(grpc_credentials_metadata_request* r,
grpc_error* error);
GRPC_ABSTRACT_BASE_CLASS
protected:
virtual void fetch_oauth2(grpc_credentials_metadata_request* req,
grpc_httpcli_context* httpcli_context,
grpc_polling_entity* pollent, grpc_iomgr_cb_func cb,
grpc_millis deadline) GRPC_ABSTRACT;
grpc_millis deadline) = 0;
private:
gpr_mu mu_;

@ -58,15 +58,13 @@ class grpc_security_connector
virtual void check_peer(
tsi_peer peer, grpc_endpoint* ep,
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
grpc_closure* on_peer_checked) GRPC_ABSTRACT;
grpc_closure* on_peer_checked) = 0;
/* Compares two security connectors. */
virtual int cmp(const grpc_security_connector* other) const GRPC_ABSTRACT;
virtual int cmp(const grpc_security_connector* other) const = 0;
const char* url_scheme() const { return url_scheme_; }
GRPC_ABSTRACT_BASE_CLASS
private:
const char* url_scheme_;
};
@ -103,16 +101,16 @@ class grpc_channel_security_connector : public grpc_security_connector {
virtual bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) GRPC_ABSTRACT;
grpc_error** error) = 0;
/// Cancels a pending asynchronous call to
/// grpc_channel_security_connector_check_call_host() with
/// \a on_call_host_checked as its callback.
virtual void cancel_check_call_host(grpc_closure* on_call_host_checked,
grpc_error* error) GRPC_ABSTRACT;
grpc_error* error) = 0;
/// Registers handshakers with \a handshake_mgr.
virtual void add_handshakers(
const grpc_channel_args* args, grpc_pollset_set* interested_parties,
grpc_core::HandshakeManager* handshake_mgr) GRPC_ABSTRACT;
virtual void add_handshakers(const grpc_channel_args* args,
grpc_pollset_set* interested_parties,
grpc_core::HandshakeManager* handshake_mgr) = 0;
const grpc_channel_credentials* channel_creds() const {
return channel_creds_.get();
@ -127,8 +125,6 @@ class grpc_channel_security_connector : public grpc_security_connector {
return request_metadata_creds_.get();
}
GRPC_ABSTRACT_BASE_CLASS
protected:
// Helper methods to be used in subclasses.
int channel_security_connector_cmp(
@ -157,9 +153,9 @@ class grpc_server_security_connector : public grpc_security_connector {
grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
~grpc_server_security_connector() override = default;
virtual void add_handshakers(
const grpc_channel_args* args, grpc_pollset_set* interested_parties,
grpc_core::HandshakeManager* handshake_mgr) GRPC_ABSTRACT;
virtual void add_handshakers(const grpc_channel_args* args,
grpc_pollset_set* interested_parties,
grpc_core::HandshakeManager* handshake_mgr) = 0;
const grpc_server_credentials* server_creds() const {
return server_creds_.get();
@ -168,8 +164,6 @@ class grpc_server_security_connector : public grpc_security_connector {
return server_creds_.get();
}
GRPC_ABSTRACT_BASE_CLASS
protected:
// Helper methods to be used in subclasses.
int server_security_connector_cmp(

@ -26,7 +26,6 @@
#include <grpc/grpc.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/iomgr/pollset.h"

@ -22,7 +22,6 @@
#include <grpc/support/port_platform.h>
#include <grpc/slice_buffer.h>
#include "src/core/lib/gprpp/abstract.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/iomgr/closure.h"
@ -45,14 +44,13 @@ class ByteStream : public Orphanable {
//
// max_size_hint can be set as a hint as to the maximum number
// of bytes that would be acceptable to read.
virtual bool Next(size_t max_size_hint,
grpc_closure* on_complete) GRPC_ABSTRACT;
virtual bool Next(size_t max_size_hint, grpc_closure* on_complete) = 0;
// Returns the next slice in the byte stream when it is available, as
// indicated by Next().
//
// Once a slice is returned into *slice, it is owned by the caller.
virtual grpc_error* Pull(grpc_slice* slice) GRPC_ABSTRACT;
virtual grpc_error* Pull(grpc_slice* slice) = 0;
// Shuts down the byte stream.
//
@ -61,15 +59,13 @@ class ByteStream : public Orphanable {
//
// The next call to Pull() (if any) will return the error passed to
// Shutdown().
virtual void Shutdown(grpc_error* error) GRPC_ABSTRACT;
virtual void Shutdown(grpc_error* error) = 0;
uint32_t length() const { return length_; }
uint32_t flags() const { return flags_; }
void set_flags(uint32_t flags) { flags_ = flags; }
GRPC_ABSTRACT_BASE_CLASS
protected:
ByteStream(uint32_t length, uint32_t flags)
: length_(length), flags_(flags) {}

@ -47,11 +47,9 @@ class ConnectivityStateWatcherInterface
virtual ~ConnectivityStateWatcherInterface() = default;
// Notifies the watcher that the state has changed to new_state.
virtual void Notify(grpc_connectivity_state new_state) GRPC_ABSTRACT;
virtual void Notify(grpc_connectivity_state new_state) = 0;
void Orphan() override { Unref(); }
GRPC_ABSTRACT_BASE_CLASS
};
// An alternative watcher interface that performs notifications via an
@ -70,8 +68,7 @@ class AsyncConnectivityStateWatcherInterface
class Notifier;
// Invoked asynchronously when Notify() is called.
virtual void OnConnectivityStateChange(grpc_connectivity_state new_state)
GRPC_ABSTRACT;
virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) = 0;
};
// Tracks connectivity state. Maintains a list of watchers that are
@ -113,8 +110,8 @@ class ConnectivityStateTracker {
Atomic<grpc_connectivity_state> state_;
// TODO(roth): This could be a set instead of a map if we had a set
// implementation.
Map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_;
};

@ -62,9 +62,7 @@ class SslCachedSession {
virtual ~SslCachedSession() = default;
/// Returns a copy of previously cached session.
virtual SslSessionPtr CopySession() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual SslSessionPtr CopySession() const = 0;
protected:
SslCachedSession() = default;

@ -81,20 +81,6 @@ grpc_cc_test(
uses_polling = False,
)
grpc_cc_test(
name = "grpc_core_map_test",
srcs = ["map_test.cc"],
external_deps = [
"gtest",
],
language = "C++",
deps = [
"//:gpr_base",
"//test/core/util:grpc_test_util",
],
uses_polling = False,
)
grpc_cc_test(
name = "memory_test",
srcs = ["memory_test.cc"],

@ -26,7 +26,6 @@
#include <stdlib.h>
#include <cstring>
#include "src/core/lib/gprpp/abstract.h"
#include "test/core/util/test_config.h"
class A {
@ -35,7 +34,6 @@ class A {
virtual ~A() {}
virtual const char* foo() { return "A_foo"; }
virtual const char* bar() { return "A_bar"; }
GRPC_ABSTRACT_BASE_CLASS
};
class B : public A {

@ -1,514 +0,0 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "src/core/lib/gprpp/map.h"
#include <gtest/gtest.h>
#include "include/grpc/support/string_util.h"
#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "test/core/util/test_config.h"
namespace grpc_core {
namespace testing {
#if GRPC_USE_CPP_STD_LIB
TEST(MapTest, Nop) {}
#else
class Payload {
public:
Payload() : data_(-1) {}
explicit Payload(int data) : data_(data) {}
Payload(const Payload& other) : data_(other.data_) {}
Payload& operator=(const Payload& other) {
if (this != &other) {
data_ = other.data_;
}
return *this;
}
int data() { return data_; }
private:
int data_;
};
inline UniquePtr<char> CopyString(const char* string) {
return UniquePtr<char>(gpr_strdup(string));
}
static constexpr char kKeys[][4] = {"abc", "efg", "hij", "klm", "xyz"};
class MapTest : public ::testing::Test {
public:
template <class Key, class T, class Compare>
typename ::grpc_core::Map<Key, T, Compare>::Entry* Root(
typename ::grpc_core::Map<Key, T, Compare>* map) {
return map->root_;
}
};
// Test insertion of Payload
TEST_F(MapTest, EmplaceAndFind) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second.data());
}
}
// Test insertion of Payload Unique Ptrs
TEST_F(MapTest, EmplaceAndFindWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], MakeUnique<Payload>(i));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second->data());
}
}
// Test insertion of Unique Ptr kKeys and Payload
TEST_F(MapTest, EmplaceAndFindWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(CopyString(kKeys[i]), Payload(i));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data());
}
}
// Test insertion of Payload
TEST_F(MapTest, InsertAndFind) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.insert(MakePair(kKeys[i], Payload(i)));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second.data());
}
}
// Test insertion of Payload Unique Ptrs
TEST_F(MapTest, InsertAndFindWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.insert(MakePair(kKeys[i], MakeUnique<Payload>(i)));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second->data());
}
}
// Test insertion of Unique Ptr kKeys and Payload
TEST_F(MapTest, InsertAndFindWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.insert(MakePair(CopyString(kKeys[i]), Payload(i)));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data());
}
}
// Test bracket operators
TEST_F(MapTest, BracketOperator) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map[kKeys[i]] = Payload(i);
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map[kKeys[i]].data());
}
}
// Test bracket operators with unique pointer to payload
TEST_F(MapTest, BracketOperatorWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map[kKeys[i]] = MakeUnique<Payload>(i);
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map[kKeys[i]]->data());
}
}
// Test bracket operators with unique pointer to payload
TEST_F(MapTest, BracketOperatorWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map[CopyString(kKeys[i])] = Payload(i);
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map[CopyString(kKeys[i])].data());
}
}
// Test removal of a single value
TEST_F(MapTest, Erase) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
EXPECT_EQ(test_map.size(), 5UL);
EXPECT_EQ(test_map.erase(kKeys[3]), 1UL); // Remove "hij"
for (int i = 0; i < 5; i++) {
if (i == 3) { // "hij" should not be present
EXPECT_TRUE(test_map.find(kKeys[i]) == test_map.end());
} else {
EXPECT_EQ(i, test_map.find(kKeys[i])->second.data());
}
}
EXPECT_EQ(test_map.size(), 4UL);
}
// Test removal of a single value with unique ptr to payload
TEST_F(MapTest, EraseWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], MakeUnique<Payload>(i));
}
EXPECT_EQ(test_map.size(), 5UL);
test_map.erase(kKeys[3]); // Remove "hij"
for (int i = 0; i < 5; i++) {
if (i == 3) { // "hij" should not be present
EXPECT_TRUE(test_map.find(kKeys[i]) == test_map.end());
} else {
EXPECT_EQ(i, test_map.find(kKeys[i])->second->data());
}
}
EXPECT_EQ(test_map.size(), 4UL);
}
// Test removal of a single value
TEST_F(MapTest, EraseWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(CopyString(kKeys[i]), Payload(i));
}
EXPECT_EQ(test_map.size(), 5UL);
test_map.erase(CopyString(kKeys[3])); // Remove "hij"
for (int i = 0; i < 5; i++) {
if (i == 3) { // "hij" should not be present
EXPECT_TRUE(test_map.find(CopyString(kKeys[i])) == test_map.end());
} else {
EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data());
}
}
EXPECT_EQ(test_map.size(), 4UL);
}
// Test clear
TEST_F(MapTest, SizeAndClear) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
EXPECT_EQ(test_map.size(), 5UL);
EXPECT_FALSE(test_map.empty());
test_map.clear();
EXPECT_EQ(test_map.size(), 0UL);
EXPECT_TRUE(test_map.empty());
}
// Test clear with unique ptr payload
TEST_F(MapTest, SizeAndClearWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], MakeUnique<Payload>(i));
}
EXPECT_EQ(test_map.size(), 5UL);
EXPECT_FALSE(test_map.empty());
test_map.clear();
EXPECT_EQ(test_map.size(), 0UL);
EXPECT_TRUE(test_map.empty());
}
// Test clear with unique ptr char key
TEST_F(MapTest, SizeAndClearWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(CopyString(kKeys[i]), Payload(i));
}
EXPECT_EQ(test_map.size(), 5UL);
EXPECT_FALSE(test_map.empty());
test_map.clear();
EXPECT_EQ(test_map.size(), 0UL);
EXPECT_TRUE(test_map.empty());
}
// Test correction of Left-Left Tree imbalance
TEST_F(MapTest, MapLL) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 2; i >= 0; i--) {
test_map.emplace(kKeys[i], Payload(i));
}
EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0);
}
// Test correction of Left-Right tree imbalance
TEST_F(MapTest, MapLR) {
Map<const char*, Payload, StringLess> test_map;
int insertion_key_index[] = {2, 0, 1};
for (int i = 0; i < 3; i++) {
int key_index = insertion_key_index[i];
test_map.emplace(kKeys[key_index], Payload(key_index));
}
EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0);
}
// Test correction of Right-Left tree imbalance
TEST_F(MapTest, MapRL) {
Map<const char*, Payload, StringLess> test_map;
int insertion_key_index[] = {0, 2, 1};
for (int i = 0; i < 3; i++) {
int key_index = insertion_key_index[i];
test_map.emplace(kKeys[key_index], Payload(key_index));
}
EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0);
}
// Test correction of Right-Right tree imbalance
TEST_F(MapTest, MapRR) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[3]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->left->pair.first, kKeys[2]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->right->pair.first, kKeys[4]), 0);
}
// Test correction after random insertion
TEST_F(MapTest, MapRandomInsertions) {
Map<const char*, Payload, StringLess> test_map;
int insertion_key_index[] = {1, 4, 3, 0, 2};
for (int i = 0; i < 5; i++) {
int key_index = insertion_key_index[i];
test_map.emplace(kKeys[key_index], Payload(key_index));
}
EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[3]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[1]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[4]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->right->pair.first, kKeys[2]), 0);
EXPECT_EQ(strcmp(Root(&test_map)->left->left->pair.first, kKeys[0]), 0);
}
// Test Map iterator
TEST_F(MapTest, Iteration) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 4; i >= 0; --i) {
test_map.emplace(kKeys[i], Payload(i));
}
auto it = test_map.begin();
for (int i = 0; i < 5; ++i) {
ASSERT_NE(it, test_map.end());
EXPECT_STREQ(kKeys[i], it->first);
EXPECT_EQ(i, it->second.data());
++it;
}
EXPECT_EQ(it, test_map.end());
}
// Test Map iterator with unique ptr payload
TEST_F(MapTest, IterationWithUniquePtrValue) {
Map<const char*, UniquePtr<Payload>, StringLess> test_map;
for (int i = 4; i >= 0; --i) {
test_map.emplace(kKeys[i], MakeUnique<Payload>(i));
}
auto it = test_map.begin();
for (int i = 0; i < 5; ++i) {
ASSERT_NE(it, test_map.end());
EXPECT_STREQ(kKeys[i], it->first);
EXPECT_EQ(i, it->second->data());
++it;
}
EXPECT_EQ(it, test_map.end());
}
// Test Map iterator with unique ptr to char key
TEST_F(MapTest, IterationWithUniquePtrKey) {
Map<UniquePtr<char>, Payload, StringLess> test_map;
for (int i = 4; i >= 0; --i) {
test_map.emplace(CopyString(kKeys[i]), Payload(i));
}
auto it = test_map.begin();
for (int i = 0; i < 5; ++i) {
ASSERT_NE(it, test_map.end());
EXPECT_STREQ(kKeys[i], it->first.get());
EXPECT_EQ(i, it->second.data());
++it;
}
EXPECT_EQ(it, test_map.end());
}
// Test removing entries while iterating the map
TEST_F(MapTest, EraseUsingIterator) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
int count = 0;
for (auto iter = test_map.begin(); iter != test_map.end();) {
EXPECT_EQ(iter->second.data(), count);
if (count % 2 == 1) {
iter = test_map.erase(iter);
} else {
++iter;
}
++count;
}
EXPECT_EQ(count, 5);
auto it = test_map.begin();
for (int i = 0; i < 5; ++i) {
if (i % 2 == 0) {
EXPECT_STREQ(kKeys[i], it->first);
EXPECT_EQ(i, it->second.data());
++it;
}
}
EXPECT_EQ(it, test_map.end());
}
// Random ops on a Map with Integer key of Payload value,
// tests default comparator
TEST_F(MapTest, RandomOpsWithIntKey) {
Map<int, Payload> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(i, Payload(i));
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(i)->second.data());
}
for (int i = 0; i < 5; i++) {
test_map[i] = Payload(i + 10);
}
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i + 10, test_map[i].data());
}
EXPECT_EQ(test_map.erase(3), 1UL);
EXPECT_TRUE(test_map.find(3) == test_map.end());
EXPECT_FALSE(test_map.empty());
EXPECT_EQ(test_map.size(), 4UL);
test_map.clear();
EXPECT_EQ(test_map.size(), 0UL);
EXPECT_TRUE(test_map.empty());
}
// Tests lower_bound().
TEST_F(MapTest, LowerBound) {
Map<int, Payload> test_map;
for (int i = 0; i < 10; i += 2) {
test_map.emplace(i, Payload(i));
}
auto it = test_map.lower_bound(-1);
EXPECT_EQ(it, test_map.begin());
it = test_map.lower_bound(0);
EXPECT_EQ(it, test_map.begin());
it = test_map.lower_bound(2);
EXPECT_EQ(it->first, 2);
it = test_map.lower_bound(3);
EXPECT_EQ(it->first, 4);
it = test_map.lower_bound(9);
EXPECT_EQ(it, test_map.end());
}
// Test move ctor
TEST_F(MapTest, MoveCtor) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
Map<const char*, Payload, StringLess> test_map2 = std::move(test_map);
for (int i = 0; i < 5; i++) {
EXPECT_EQ(test_map.end(), test_map.find(kKeys[i]));
EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data());
}
}
// Test move assignment
TEST_F(MapTest, MoveAssignment) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
Map<const char*, Payload, StringLess> test_map2;
test_map2.emplace("xxx", Payload(123));
test_map2 = std::move(test_map);
for (int i = 0; i < 5; i++) {
EXPECT_EQ(test_map.end(), test_map.find(kKeys[i]));
EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data());
}
EXPECT_EQ(test_map2.end(), test_map2.find("xxx"));
}
// Test copy ctor
TEST_F(MapTest, CopyCtor) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
Map<const char*, Payload, StringLess> test_map2 = test_map;
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second.data());
EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data());
}
}
// Test copy assignment
TEST_F(MapTest, CopyAssignment) {
Map<const char*, Payload, StringLess> test_map;
for (int i = 0; i < 5; i++) {
test_map.emplace(kKeys[i], Payload(i));
}
Map<const char*, Payload, StringLess> test_map2;
test_map2.emplace("xxx", Payload(123));
test_map2 = test_map;
for (int i = 0; i < 5; i++) {
EXPECT_EQ(i, test_map.find(kKeys[i])->second.data());
EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data());
}
EXPECT_EQ(test_map2.end(), test_map2.find("xxx"));
}
#endif
} // namespace testing
} // namespace grpc_core
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -81,7 +81,6 @@ class InterarrivalTimer {
for (int i = 0; i < entries; i++) {
random_table_.push_back(
static_cast<int64_t>(1e9 * r.transform(rando(generator))));
;
}
// Now set up the thread positions
for (int i = 0; i < threads; i++) {

@ -1101,7 +1101,6 @@ src/core/lib/gpr/tls_msvc.h \
src/core/lib/gpr/tls_pthread.h \
src/core/lib/gpr/tmpfile.h \
src/core/lib/gpr/useful.h \
src/core/lib/gprpp/abstract.h \
src/core/lib/gprpp/arena.h \
src/core/lib/gprpp/atomic.h \
src/core/lib/gprpp/debug_location.h \

@ -1232,7 +1232,6 @@ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/useful.h \
src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/README.md \
src/core/lib/gprpp/abstract.h \
src/core/lib/gprpp/arena.cc \
src/core/lib/gprpp/arena.h \
src/core/lib/gprpp/atomic.h \

@ -25,4 +25,3 @@ git clone /var/local/jenkins/grpc /var/local/git/grpc
${name}')
cd /var/local/git/grpc
bazel build --spawn_strategy=standalone --genrule_strategy=standalone :all test/... examples/...
bazel build --spawn_strategy=standalone --genrule_strategy=standalone --define=GRPC_USE_CPP_STD_LIB=1 :grpc

@ -4739,30 +4739,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "grpc_core_map_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save