Fix plugin initializers

Previous code not threadsafe nor idiomatic
pull/22813/head
Mehrdad Afshari 5 years ago
parent de8aa7e9df
commit 99367a7f98
  1. 9
      src/cpp/ext/proto_server_reflection_plugin.cc
  2. 11
      src/cpp/server/channelz/channelz_service_plugin.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

@ -76,11 +76,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

Loading…
Cancel
Save