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. 7
      src/cpp/ext/proto_server_reflection_plugin.cc
  2. 7
      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() { void InitProtoReflectionServerBuilderPlugin() {
static bool already_here = false; static struct Initialize {
if (already_here) return; Initialize() {
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection); ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
}
} initializer;
} }
// Force InitProtoReflectionServerBuilderPlugin() to be called at static // Force InitProtoReflectionServerBuilderPlugin() to be called at static

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

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

Loading…
Cancel
Save