local_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 
25 #include <grpc/support/log.h>
26 
28 
29 namespace grpc_core {
30 
32  const SubchannelKey& key, RefCountedPtr<Subchannel> constructed) {
33  auto it = subchannel_map_.find(key);
34  // Because this pool is only accessed under the client channel's work
35  // serializer, and because FindSubchannel is checked before invoking
36  // RegisterSubchannel, no such subchannel should exist in the map.
37  GPR_ASSERT(it == subchannel_map_.end());
38  subchannel_map_[key] = constructed.get();
39  return constructed;
40 }
41 
44  auto it = subchannel_map_.find(key);
45  // Because this subchannel pool is accessed only under the client
46  // channel's work serializer, any subchannel created by RegisterSubchannel
47  // will be deleted from the map in UnregisterSubchannel.
48  GPR_ASSERT(it != subchannel_map_.end());
49  GPR_ASSERT(it->second == subchannel);
50  subchannel_map_.erase(it);
51 }
52 
54  const SubchannelKey& key) {
55  auto it = subchannel_map_.find(key);
56  if (it == subchannel_map_.end()) return nullptr;
57  return it->second->Ref();
58 }
59 
60 } // namespace grpc_core
regen-readme.it
it
Definition: regen-readme.py:15
log.h
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
subchannel.h
grpc_core
Definition: call_metric_recorder.h:31
subchannel
RingHashSubchannelData * subchannel
Definition: ring_hash.cc:285
grpc_core::LocalSubchannelPool::RegisterSubchannel
RefCountedPtr< Subchannel > RegisterSubchannel(const SubchannelKey &key, RefCountedPtr< Subchannel > constructed) override
Definition: local_subchannel_pool.cc:31
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
local_subchannel_pool.h
grpc_core::LocalSubchannelPool::FindSubchannel
RefCountedPtr< Subchannel > FindSubchannel(const SubchannelKey &key) override
Definition: local_subchannel_pool.cc:53
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::LocalSubchannelPool::UnregisterSubchannel
void UnregisterSubchannel(const SubchannelKey &key, Subchannel *subchannel) override
Definition: local_subchannel_pool.cc:42
grpc_core::LocalSubchannelPool::subchannel_map_
std::map< SubchannelKey, Subchannel * > subchannel_map_
Definition: local_subchannel_pool.h:54
port_platform.h


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