Commit | Line | Data |
---|---|---|
bec39940 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca> |
bec39940 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
bec39940 | 5 | * |
bec39940 DG |
6 | */ |
7 | ||
8 | #ifndef _LTT_HT_H | |
9 | #define _LTT_HT_H | |
10 | ||
11 | #include <urcu.h> | |
d88aee68 | 12 | #include <stdint.h> |
10a8a223 | 13 | |
d604af56 | 14 | #include <common/macros.h> |
8684af09 | 15 | #include <urcu/rculfhash.h> |
bec39940 | 16 | |
b6314938 DG |
17 | extern unsigned long lttng_ht_seed; |
18 | ||
bcd52dd9 | 19 | typedef unsigned long (*hash_fct)(const void *_key, unsigned long seed); |
bec39940 DG |
20 | typedef cds_lfht_match_fct hash_match_fct; |
21 | ||
22 | enum lttng_ht_type { | |
23 | LTTNG_HT_TYPE_STRING, | |
24 | LTTNG_HT_TYPE_ULONG, | |
d88aee68 | 25 | LTTNG_HT_TYPE_U64, |
3c4599b9 | 26 | LTTNG_HT_TYPE_TWO_U64, |
bec39940 DG |
27 | }; |
28 | ||
29 | struct lttng_ht { | |
30 | struct cds_lfht *ht; | |
31 | cds_lfht_match_fct match_fct; | |
32 | hash_fct hash_fct; | |
33 | }; | |
34 | ||
35 | struct lttng_ht_iter { | |
36 | struct cds_lfht_iter iter; | |
37 | }; | |
38 | ||
39 | struct lttng_ht_node_str { | |
40 | char *key; | |
41 | struct cds_lfht_node node; | |
42 | struct rcu_head head; | |
43 | }; | |
44 | ||
45 | struct lttng_ht_node_ulong { | |
46 | unsigned long key; | |
47 | struct cds_lfht_node node; | |
48 | struct rcu_head head; | |
49 | }; | |
50 | ||
d88aee68 DG |
51 | struct lttng_ht_node_u64 { |
52 | uint64_t key; | |
53 | struct cds_lfht_node node; | |
54 | struct rcu_head head; | |
55 | }; | |
56 | ||
3c4599b9 JD |
57 | struct lttng_ht_two_u64 { |
58 | uint64_t key1; | |
59 | uint64_t key2; | |
60 | }; | |
61 | ||
62 | struct lttng_ht_node_two_u64 { | |
63 | struct lttng_ht_two_u64 key; | |
64 | struct cds_lfht_node node; | |
65 | struct rcu_head head; | |
66 | }; | |
67 | ||
bec39940 | 68 | /* Hashtable new and destroy */ |
d604af56 JG |
69 | LTTNG_HIDDEN |
70 | struct lttng_ht *lttng_ht_new(unsigned long size, int type); | |
71 | LTTNG_HIDDEN | |
72 | void lttng_ht_destroy(struct lttng_ht *ht); | |
bec39940 DG |
73 | |
74 | /* Specialized node init and free functions */ | |
d604af56 JG |
75 | LTTNG_HIDDEN |
76 | void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); | |
77 | LTTNG_HIDDEN | |
78 | void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, | |
bec39940 | 79 | unsigned long key); |
d604af56 JG |
80 | LTTNG_HIDDEN |
81 | void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, | |
d88aee68 | 82 | uint64_t key); |
d604af56 JG |
83 | LTTNG_HIDDEN |
84 | void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, | |
3c4599b9 | 85 | uint64_t key1, uint64_t key2); |
d604af56 JG |
86 | LTTNG_HIDDEN |
87 | void lttng_ht_node_free_str(struct lttng_ht_node_str *node); | |
88 | LTTNG_HIDDEN | |
89 | void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); | |
90 | LTTNG_HIDDEN | |
91 | void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node); | |
92 | LTTNG_HIDDEN | |
93 | void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node); | |
94 | ||
95 | LTTNG_HIDDEN | |
fb9a95c4 | 96 | void lttng_ht_lookup(struct lttng_ht *ht, const void *key, |
bec39940 DG |
97 | struct lttng_ht_iter *iter); |
98 | ||
99 | /* Specialized add unique functions */ | |
d604af56 JG |
100 | LTTNG_HIDDEN |
101 | void lttng_ht_add_unique_str(struct lttng_ht *ht, | |
bec39940 | 102 | struct lttng_ht_node_str *node); |
d604af56 JG |
103 | LTTNG_HIDDEN |
104 | void lttng_ht_add_unique_ulong(struct lttng_ht *ht, | |
bec39940 | 105 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
106 | LTTNG_HIDDEN |
107 | void lttng_ht_add_unique_u64(struct lttng_ht *ht, | |
d88aee68 | 108 | struct lttng_ht_node_u64 *node); |
d604af56 JG |
109 | LTTNG_HIDDEN |
110 | void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, | |
3c4599b9 | 111 | struct lttng_ht_node_two_u64 *node); |
d604af56 JG |
112 | LTTNG_HIDDEN |
113 | struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong( | |
852d0037 | 114 | struct lttng_ht *ht, struct lttng_ht_node_ulong *node); |
d604af56 JG |
115 | LTTNG_HIDDEN |
116 | struct lttng_ht_node_u64 *lttng_ht_add_replace_u64( | |
d88aee68 | 117 | struct lttng_ht *ht, struct lttng_ht_node_u64 *node); |
d604af56 JG |
118 | LTTNG_HIDDEN |
119 | void lttng_ht_add_str(struct lttng_ht *ht, | |
efa116c6 | 120 | struct lttng_ht_node_str *node); |
d604af56 JG |
121 | LTTNG_HIDDEN |
122 | void lttng_ht_add_ulong(struct lttng_ht *ht, | |
aefea3b7 | 123 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
124 | LTTNG_HIDDEN |
125 | void lttng_ht_add_u64(struct lttng_ht *ht, | |
d88aee68 | 126 | struct lttng_ht_node_u64 *node); |
bec39940 | 127 | |
d604af56 JG |
128 | LTTNG_HIDDEN |
129 | int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 130 | |
d604af56 JG |
131 | LTTNG_HIDDEN |
132 | void lttng_ht_get_first(struct lttng_ht *ht, | |
bec39940 | 133 | struct lttng_ht_iter *iter); |
d604af56 JG |
134 | LTTNG_HIDDEN |
135 | void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 136 | |
d604af56 JG |
137 | LTTNG_HIDDEN |
138 | unsigned long lttng_ht_get_count(struct lttng_ht *ht); | |
bec39940 | 139 | |
d604af56 JG |
140 | LTTNG_HIDDEN |
141 | struct lttng_ht_node_str *lttng_ht_iter_get_node_str( | |
bec39940 | 142 | struct lttng_ht_iter *iter); |
d604af56 JG |
143 | LTTNG_HIDDEN |
144 | struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( | |
bec39940 | 145 | struct lttng_ht_iter *iter); |
d604af56 JG |
146 | LTTNG_HIDDEN |
147 | struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( | |
d88aee68 | 148 | struct lttng_ht_iter *iter); |
d604af56 JG |
149 | LTTNG_HIDDEN |
150 | struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( | |
3c4599b9 | 151 | struct lttng_ht_iter *iter); |
bec39940 DG |
152 | |
153 | #endif /* _LTT_HT_H */ |