Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / deps / grpc / src / core / ext / filters / client_channel / global_subchannel_pool.h
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
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
25
26 namespace grpc_core {
27
28 // The global subchannel pool. It shares subchannels among channels. There
29 // should be only one instance of this class. Init() should be called once at
30 // the filter initialization time; Shutdown() should be called once at the
31 // filter shutdown time.
32 // TODO(juanlishen): Enable subchannel retention.
33 class GlobalSubchannelPool final : public SubchannelPoolInterface {
34  public:
35   // The ctor and dtor are not intended to use directly.
36   GlobalSubchannelPool();
37   ~GlobalSubchannelPool() override;
38
39   // Should be called exactly once at filter initialization time.
40   static void Init();
41   // Should be called exactly once at filter shutdown time.
42   static void Shutdown();
43
44   // Gets the singleton instance.
45   static RefCountedPtr<GlobalSubchannelPool> instance();
46
47   // Implements interface methods.
48   Subchannel* RegisterSubchannel(SubchannelKey* key,
49                                  Subchannel* constructed) override;
50   void UnregisterSubchannel(SubchannelKey* key) override;
51   Subchannel* FindSubchannel(SubchannelKey* key) override;
52
53  private:
54   // The singleton instance. (It's a pointer to RefCountedPtr so that this
55   // non-local static object can be trivially destructible.)
56   static RefCountedPtr<GlobalSubchannelPool>* instance_;
57
58   // The vtable for subchannel operations in an AVL tree.
59   static const grpc_avl_vtable subchannel_avl_vtable_;
60   // A map from subchannel key to subchannel.
61   grpc_avl subchannel_map_;
62   // To protect subchannel_map_.
63   gpr_mu mu_;
64 };
65
66 }  // namespace grpc_core
67
68 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H */