[Core Config] Use absl::Invocable instead of std::function (#34282)

Splitting off from https://github.com/grpc/grpc/pull/34273

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/34273/head
Yash Tibrewal 1 year ago committed by GitHub
parent aed2797cd2
commit b388a7e250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 1
      src/core/BUILD
  3. 3
      src/core/lib/config/core_configuration.cc
  4. 7
      src/core/lib/config/core_configuration.h
  5. 5
      src/core/lib/surface/channel_init.h
  6. 1
      test/core/config/core_configuration_test.cc

@ -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",

@ -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",

@ -49,7 +49,8 @@ CoreConfiguration::CoreConfiguration(Builder* builder)
certificate_provider_registry_(
builder->certificate_provider_registry_.Build()) {}
void CoreConfiguration::RegisterBuilder(std::function<void(Builder*)> builder) {
void CoreConfiguration::RegisterBuilder(
absl::AnyInvocable<void(Builder*)> builder) {
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
"CoreConfiguration was already instantiated before builder "
"registration was completed");

@ -18,7 +18,8 @@
#include <grpc/support/port_platform.h>
#include <atomic>
#include <functional>
#include "absl/functional/any_invocable.h"
#include <grpc/support/log.h>
@ -98,7 +99,7 @@ class CoreConfiguration {
// Stores a builder for RegisterBuilder
struct RegisteredBuilder {
std::function<void(Builder*)> builder;
absl::AnyInvocable<void(Builder*)> 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<void(Builder*)> builder);
static void RegisterBuilder(absl::AnyInvocable<void(Builder*)> builder);
// Drop the core configuration. Users must ensure no other threads are
// accessing the configuration.

@ -21,10 +21,11 @@
#include <grpc/support/port_platform.h>
#include <functional>
#include <utility>
#include <vector>
#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<bool(ChannelStackBuilder* builder)>;
using Stage = absl::AnyInvocable<bool(ChannelStackBuilder* builder) const>;
class Builder {
public:

@ -16,6 +16,7 @@
#include <algorithm>
#include <chrono>
#include <functional>
#include <thread>
#include <vector>

Loading…
Cancel
Save