Merge pull request #22813 from mehrdada/fix-static-initialization-crap

Fix channelz plugin initializer
pull/22951/head^2
Esun Kim 5 years ago committed by GitHub
commit 8d0e703393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/cpp/ext/proto_server_reflection_plugin.cc
  2. 11
      src/cpp/server/channelz/channelz_service_plugin.cc
  3. 13
      test/cpp/end2end/server_builder_plugin_test.cc

@ -64,10 +64,11 @@ static std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateProtoReflection() {
}
void InitProtoReflectionServerBuilderPlugin() {
static bool already_here = false;
if (already_here) return;
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
static struct Initialize {
Initialize() {
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
}
} initializer;
}
// Force InitProtoReflectionServerBuilderPlugin() to be called at static

@ -75,11 +75,12 @@ namespace channelz {
namespace experimental {
void InitChannelzService() {
static bool already_here = false;
if (already_here) return;
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(
&grpc::channelz::experimental::CreateChannelzServicePlugin);
static struct Initializer {
Initializer() {
::grpc::ServerBuilder::InternalAddPluginFactory(
&grpc::channelz::experimental::CreateChannelzServicePlugin);
}
} initialize;
}
} // namespace experimental

@ -121,17 +121,12 @@ std::unique_ptr<ServerBuilderPlugin> CreateTestServerBuilderPlugin() {
return std::unique_ptr<ServerBuilderPlugin>(new TestServerBuilderPlugin());
}
void AddTestServerBuilderPlugin() {
static bool already_here = false;
if (already_here) return;
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(
&CreateTestServerBuilderPlugin);
}
// Force AddServerBuilderPlugin() to be called at static initialization time.
struct StaticTestPluginInitializer {
StaticTestPluginInitializer() { AddTestServerBuilderPlugin(); }
StaticTestPluginInitializer() {
::grpc::ServerBuilder::InternalAddPluginFactory(
&CreateTestServerBuilderPlugin);
}
} static_plugin_initializer_test_;
// When the param boolean is true, the ServerBuilder plugin will be added at the

Loading…
Cancel
Save