From b388a7e250bafcee20477ccb75bc072d051b7793 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Thu, 7 Sep 2023 14:48:47 -0700 Subject: [PATCH] [Core Config] Use absl::Invocable instead of std::function (#34282) Splitting off from https://github.com/grpc/grpc/pull/34273 --- BUILD | 1 + src/core/BUILD | 1 + src/core/lib/config/core_configuration.cc | 3 ++- src/core/lib/config/core_configuration.h | 7 ++++--- src/core/lib/surface/channel_init.h | 5 +++-- test/core/config/core_configuration_test.cc | 1 + 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BUILD b/BUILD index 3519a137c70..bde7f174e6a 100644 --- a/BUILD +++ b/BUILD @@ -2469,6 +2469,7 @@ grpc_cc_library( srcs = [ "//src/core:lib/config/core_configuration.cc", ], + external_deps = ["absl/functional:any_invocable"], language = "c++", public_hdrs = [ "//src/core:lib/config/core_configuration.h", diff --git a/src/core/BUILD b/src/core/BUILD index b6a4c320dba..8e64a89e95a 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -2627,6 +2627,7 @@ grpc_cc_library( hdrs = [ "lib/surface/channel_init.h", ], + external_deps = ["absl/functional:any_invocable"], language = "c++", deps = [ "channel_stack_type", diff --git a/src/core/lib/config/core_configuration.cc b/src/core/lib/config/core_configuration.cc index 4469f9db00f..7ae1b099d52 100644 --- a/src/core/lib/config/core_configuration.cc +++ b/src/core/lib/config/core_configuration.cc @@ -49,7 +49,8 @@ CoreConfiguration::CoreConfiguration(Builder* builder) certificate_provider_registry_( builder->certificate_provider_registry_.Build()) {} -void CoreConfiguration::RegisterBuilder(std::function builder) { +void CoreConfiguration::RegisterBuilder( + absl::AnyInvocable builder) { GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr && "CoreConfiguration was already instantiated before builder " "registration was completed"); diff --git a/src/core/lib/config/core_configuration.h b/src/core/lib/config/core_configuration.h index a32ee768c75..740cc1fc8af 100644 --- a/src/core/lib/config/core_configuration.h +++ b/src/core/lib/config/core_configuration.h @@ -18,7 +18,8 @@ #include #include -#include + +#include "absl/functional/any_invocable.h" #include @@ -98,7 +99,7 @@ class CoreConfiguration { // Stores a builder for RegisterBuilder struct RegisteredBuilder { - std::function builder; + absl::AnyInvocable builder; RegisteredBuilder* next; }; @@ -154,7 +155,7 @@ class CoreConfiguration { // Attach a registration function globally. // Each registration function is called *in addition to* // BuildCoreConfiguration for the default core configuration. - static void RegisterBuilder(std::function builder); + static void RegisterBuilder(absl::AnyInvocable builder); // Drop the core configuration. Users must ensure no other threads are // accessing the configuration. diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index 777fabe3076..502f5533b02 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -21,10 +21,11 @@ #include -#include #include #include +#include "absl/functional/any_invocable.h" + #include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/surface/channel_stack_type.h" @@ -41,7 +42,7 @@ class ChannelInit { public: /// One stage of mutation: call functions against \a builder to influence the /// finally constructed channel stack - using Stage = std::function; + using Stage = absl::AnyInvocable; class Builder { public: diff --git a/test/core/config/core_configuration_test.cc b/test/core/config/core_configuration_test.cc index 90383a8bca2..7d39154c846 100644 --- a/test/core/config/core_configuration_test.cc +++ b/test/core/config/core_configuration_test.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include