diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 8a32e3bf0c1..4b53c20fd8b 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -42,12 +42,10 @@ void grpc_client_channel_init(void) { grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry(); grpc_core::ProxyMapperRegistry::Init(); grpc_core::RegisterHttpProxyMapper(); - grpc_core::GlobalSubchannelPool::Init(); grpc_client_channel_global_init_backup_polling(); } void grpc_client_channel_shutdown(void) { - grpc_core::GlobalSubchannelPool::Shutdown(); grpc_core::ProxyMapperRegistry::Shutdown(); grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry(); } diff --git a/src/core/ext/filters/client_channel/global_subchannel_pool.cc b/src/core/ext/filters/client_channel/global_subchannel_pool.cc index 72593a6f4a2..4fc5ff9ccbe 100644 --- a/src/core/ext/filters/client_channel/global_subchannel_pool.cc +++ b/src/core/ext/filters/client_channel/global_subchannel_pool.cc @@ -24,27 +24,9 @@ namespace grpc_core { -#define GRPC_REGISTER_SUBCHANNEL_CALM_DOWN_AFTER_ATTEMPTS 100 -#define GRPC_REGISTER_SUBCHANNEL_CALM_DOWN_MICROS 10 - -void GlobalSubchannelPool::Init() { - instance_ = new RefCountedPtr( - MakeRefCounted()); -} - -void GlobalSubchannelPool::Shutdown() { - // To ensure Init() was called before. - GPR_ASSERT(instance_ != nullptr); - // To ensure Shutdown() was not called before. - GPR_ASSERT(*instance_ != nullptr); - instance_->reset(); - delete instance_; -} - RefCountedPtr GlobalSubchannelPool::instance() { - GPR_ASSERT(instance_ != nullptr); - GPR_ASSERT(*instance_ != nullptr); - return *instance_; + static GlobalSubchannelPool* p = new GlobalSubchannelPool(); + return p->Ref(); } RefCountedPtr GlobalSubchannelPool::RegisterSubchannel( @@ -59,8 +41,6 @@ RefCountedPtr GlobalSubchannelPool::RegisterSubchannel( return constructed; } -RefCountedPtr* GlobalSubchannelPool::instance_ = nullptr; - void GlobalSubchannelPool::UnregisterSubchannel(const SubchannelKey& key, Subchannel* subchannel) { MutexLock lock(&mu_); diff --git a/src/core/ext/filters/client_channel/global_subchannel_pool.h b/src/core/ext/filters/client_channel/global_subchannel_pool.h index 5b29a89a39d..cb380918b68 100644 --- a/src/core/ext/filters/client_channel/global_subchannel_pool.h +++ b/src/core/ext/filters/client_channel/global_subchannel_pool.h @@ -29,20 +29,9 @@ namespace grpc_core { // The global subchannel pool. It shares subchannels among channels. There -// should be only one instance of this class. Init() should be called once at -// the filter initialization time; Shutdown() should be called once at the -// filter shutdown time. +// should be only one instance of this class. class GlobalSubchannelPool final : public SubchannelPoolInterface { public: - // The ctor and dtor are not intended to use directly. - GlobalSubchannelPool() {} - ~GlobalSubchannelPool() override {} - - // Should be called exactly once at filter initialization time. - static void Init(); - // Should be called exactly once at filter shutdown time. - static void Shutdown(); - // Gets the singleton instance. static RefCountedPtr instance(); @@ -57,9 +46,8 @@ class GlobalSubchannelPool final : public SubchannelPoolInterface { ABSL_LOCKS_EXCLUDED(mu_); private: - // The singleton instance. (It's a pointer to RefCountedPtr so that this - // non-local static object can be trivially destructible.) - static RefCountedPtr* instance_; + GlobalSubchannelPool() {} + ~GlobalSubchannelPool() override {} // A map from subchannel key to subchannel. std::map subchannel_map_ ABSL_GUARDED_BY(mu_);