aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/filters/client_channel/subchannel_index.h
blob: 429634bd54ca257dd8ce8fa965a8bdd28fed8864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *
 * Copyright 2016 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INDEX_H
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INDEX_H

#include <grpc/support/port_platform.h>

#include "src/core/ext/filters/client_channel/subchannel.h"

/** \file Provides an index of active subchannels so that they can be
    shared amongst channels */

/** Create a key that can be used to uniquely identify a subchannel */
grpc_subchannel_key* grpc_subchannel_key_create(const grpc_channel_args* args);

/** Destroy a subchannel key */
void grpc_subchannel_key_destroy(grpc_subchannel_key* key);

/** Given a subchannel key, find the subchannel registered for it.
    Returns NULL if no such channel exists.
    Thread-safe. */
grpc_subchannel* grpc_subchannel_index_find(grpc_subchannel_key* key);

/** Register a subchannel against a key.
    Takes ownership of \a constructed.
    Returns the registered subchannel. This may be different from
    \a constructed in the case of a registration race. */
grpc_subchannel* grpc_subchannel_index_register(grpc_subchannel_key* key,
                                                grpc_subchannel* constructed);

/** Remove \a constructed as the registered subchannel for \a key. */
void grpc_subchannel_index_unregister(grpc_subchannel_key* key,
                                      grpc_subchannel* constructed);

int grpc_subchannel_key_compare(const grpc_subchannel_key* a,
                                const grpc_subchannel_key* b);

/** Initialize the subchannel index (global) */
void grpc_subchannel_index_init(void);
/** Shutdown the subchannel index (global) */
void grpc_subchannel_index_shutdown(void);

/** Increment the refcount (non-zero) of subchannel index (global). */
void grpc_subchannel_index_ref(void);

/** Decrement the refcount of subchannel index (global). If the refcount drops
    to zero, unref the subchannel index and destroy its mutex. */
void grpc_subchannel_index_unref(void);

/** \em TEST ONLY.
 * If \a force_creation is true, all keys are regarded different, resulting in
 * new subchannels always being created. Otherwise, the keys will be compared as
 * usual.
 *
 * Tests using this function \em MUST run tests with and without \a
 * force_creation set. */
void grpc_subchannel_index_test_only_set_force_creation(bool force_creation);

#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INDEX_H */