global_subchannel_pool.cc
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2018 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
20 
22 
23 #include <utility>
24 
26 
27 namespace grpc_core {
28 
31  return p->Ref();
32 }
33 
35  const SubchannelKey& key, RefCountedPtr<Subchannel> constructed) {
36  MutexLock lock(&mu_);
37  auto it = subchannel_map_.find(key);
38  if (it != subchannel_map_.end()) {
39  RefCountedPtr<Subchannel> existing = it->second->RefIfNonZero();
40  if (existing != nullptr) return existing;
41  }
42  subchannel_map_[key] = constructed.get();
43  return constructed;
44 }
45 
48  MutexLock lock(&mu_);
49  auto it = subchannel_map_.find(key);
50  // delete only if key hasn't been re-registered to a different subchannel
51  // between strong-unreffing and unregistration of subchannel.
52  if (it != subchannel_map_.end() && it->second == subchannel) {
53  subchannel_map_.erase(it);
54  }
55 }
56 
58  const SubchannelKey& key) {
59  MutexLock lock(&mu_);
60  auto it = subchannel_map_.find(key);
61  if (it == subchannel_map_.end()) return nullptr;
62  return it->second->RefIfNonZero();
63 }
64 
65 } // namespace grpc_core
regen-readme.it
it
Definition: regen-readme.py:15
grpc_core::GlobalSubchannelPool::RegisterSubchannel
RefCountedPtr< Subchannel > RegisterSubchannel(const SubchannelKey &key, RefCountedPtr< Subchannel > constructed) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:34
grpc_core::GlobalSubchannelPool::UnregisterSubchannel
void UnregisterSubchannel(const SubchannelKey &key, Subchannel *subchannel) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:46
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
grpc_core::GlobalSubchannelPool::GlobalSubchannelPool
GlobalSubchannelPool()
Definition: global_subchannel_pool.h:52
subchannel.h
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
subchannel
RingHashSubchannelData * subchannel
Definition: ring_hash.cc:285
global_subchannel_pool.h
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::GlobalSubchannelPool
Definition: global_subchannel_pool.h:36
grpc_core::GlobalSubchannelPool::instance
static RefCountedPtr< GlobalSubchannelPool > instance()
Definition: global_subchannel_pool.cc:29
grpc_core::GlobalSubchannelPool::FindSubchannel
RefCountedPtr< Subchannel > FindSubchannel(const SubchannelKey &key) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:57
grpc_core::SubchannelKey
Definition: subchannel_pool_interface.h:40
grpc_core::Subchannel
Definition: subchannel.h:166
key
const char * key
Definition: hpack_parser_table.cc:164
grpc_core::GlobalSubchannelPool::mu_
Mutex mu_
Definition: global_subchannel_pool.h:58
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:28