Commit | Line | Data |
---|---|---|
bec39940 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
bec39940 DG |
7 | * |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
d14d33bf | 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
bec39940 DG |
11 | * more details. |
12 | * | |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
bec39940 DG |
16 | */ |
17 | ||
18 | #ifndef _LTT_HT_H | |
19 | #define _LTT_HT_H | |
20 | ||
21 | #include <urcu.h> | |
d88aee68 | 22 | #include <stdint.h> |
10a8a223 | 23 | |
d604af56 | 24 | #include <common/macros.h> |
8684af09 | 25 | #include <urcu/rculfhash.h> |
bec39940 | 26 | |
b6314938 DG |
27 | extern unsigned long lttng_ht_seed; |
28 | ||
bec39940 DG |
29 | typedef unsigned long (*hash_fct)(void *_key, unsigned long seed); |
30 | typedef cds_lfht_match_fct hash_match_fct; | |
31 | ||
32 | enum lttng_ht_type { | |
33 | LTTNG_HT_TYPE_STRING, | |
34 | LTTNG_HT_TYPE_ULONG, | |
d88aee68 | 35 | LTTNG_HT_TYPE_U64, |
3c4599b9 | 36 | LTTNG_HT_TYPE_TWO_U64, |
bec39940 DG |
37 | }; |
38 | ||
39 | struct lttng_ht { | |
40 | struct cds_lfht *ht; | |
41 | cds_lfht_match_fct match_fct; | |
42 | hash_fct hash_fct; | |
43 | }; | |
44 | ||
45 | struct lttng_ht_iter { | |
46 | struct cds_lfht_iter iter; | |
47 | }; | |
48 | ||
49 | struct lttng_ht_node_str { | |
50 | char *key; | |
51 | struct cds_lfht_node node; | |
52 | struct rcu_head head; | |
53 | }; | |
54 | ||
55 | struct lttng_ht_node_ulong { | |
56 | unsigned long key; | |
57 | struct cds_lfht_node node; | |
58 | struct rcu_head head; | |
59 | }; | |
60 | ||
d88aee68 DG |
61 | struct lttng_ht_node_u64 { |
62 | uint64_t key; | |
63 | struct cds_lfht_node node; | |
64 | struct rcu_head head; | |
65 | }; | |
66 | ||
3c4599b9 JD |
67 | struct lttng_ht_two_u64 { |
68 | uint64_t key1; | |
69 | uint64_t key2; | |
70 | }; | |
71 | ||
72 | struct lttng_ht_node_two_u64 { | |
73 | struct lttng_ht_two_u64 key; | |
74 | struct cds_lfht_node node; | |
75 | struct rcu_head head; | |
76 | }; | |
77 | ||
bec39940 | 78 | /* Hashtable new and destroy */ |
d604af56 JG |
79 | LTTNG_HIDDEN |
80 | struct lttng_ht *lttng_ht_new(unsigned long size, int type); | |
81 | LTTNG_HIDDEN | |
82 | void lttng_ht_destroy(struct lttng_ht *ht); | |
bec39940 DG |
83 | |
84 | /* Specialized node init and free functions */ | |
d604af56 JG |
85 | LTTNG_HIDDEN |
86 | void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); | |
87 | LTTNG_HIDDEN | |
88 | void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, | |
bec39940 | 89 | unsigned long key); |
d604af56 JG |
90 | LTTNG_HIDDEN |
91 | void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, | |
d88aee68 | 92 | uint64_t key); |
d604af56 JG |
93 | LTTNG_HIDDEN |
94 | void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, | |
3c4599b9 | 95 | uint64_t key1, uint64_t key2); |
d604af56 JG |
96 | LTTNG_HIDDEN |
97 | void lttng_ht_node_free_str(struct lttng_ht_node_str *node); | |
98 | LTTNG_HIDDEN | |
99 | void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); | |
100 | LTTNG_HIDDEN | |
101 | void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node); | |
102 | LTTNG_HIDDEN | |
103 | void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node); | |
104 | ||
105 | LTTNG_HIDDEN | |
106 | void lttng_ht_lookup(struct lttng_ht *ht, void *key, | |
bec39940 DG |
107 | struct lttng_ht_iter *iter); |
108 | ||
109 | /* Specialized add unique functions */ | |
d604af56 JG |
110 | LTTNG_HIDDEN |
111 | void lttng_ht_add_unique_str(struct lttng_ht *ht, | |
bec39940 | 112 | struct lttng_ht_node_str *node); |
d604af56 JG |
113 | LTTNG_HIDDEN |
114 | void lttng_ht_add_unique_ulong(struct lttng_ht *ht, | |
bec39940 | 115 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
116 | LTTNG_HIDDEN |
117 | void lttng_ht_add_unique_u64(struct lttng_ht *ht, | |
d88aee68 | 118 | struct lttng_ht_node_u64 *node); |
d604af56 JG |
119 | LTTNG_HIDDEN |
120 | void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, | |
3c4599b9 | 121 | struct lttng_ht_node_two_u64 *node); |
d604af56 JG |
122 | LTTNG_HIDDEN |
123 | struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong( | |
852d0037 | 124 | struct lttng_ht *ht, struct lttng_ht_node_ulong *node); |
d604af56 JG |
125 | LTTNG_HIDDEN |
126 | struct lttng_ht_node_u64 *lttng_ht_add_replace_u64( | |
d88aee68 | 127 | struct lttng_ht *ht, struct lttng_ht_node_u64 *node); |
d604af56 JG |
128 | LTTNG_HIDDEN |
129 | void lttng_ht_add_str(struct lttng_ht *ht, | |
efa116c6 | 130 | struct lttng_ht_node_str *node); |
d604af56 JG |
131 | LTTNG_HIDDEN |
132 | void lttng_ht_add_ulong(struct lttng_ht *ht, | |
aefea3b7 | 133 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
134 | LTTNG_HIDDEN |
135 | void lttng_ht_add_u64(struct lttng_ht *ht, | |
d88aee68 | 136 | struct lttng_ht_node_u64 *node); |
bec39940 | 137 | |
d604af56 JG |
138 | LTTNG_HIDDEN |
139 | int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 140 | |
d604af56 JG |
141 | LTTNG_HIDDEN |
142 | void lttng_ht_get_first(struct lttng_ht *ht, | |
bec39940 | 143 | struct lttng_ht_iter *iter); |
d604af56 JG |
144 | LTTNG_HIDDEN |
145 | void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 146 | |
d604af56 JG |
147 | LTTNG_HIDDEN |
148 | unsigned long lttng_ht_get_count(struct lttng_ht *ht); | |
bec39940 | 149 | |
d604af56 JG |
150 | LTTNG_HIDDEN |
151 | struct lttng_ht_node_str *lttng_ht_iter_get_node_str( | |
bec39940 | 152 | struct lttng_ht_iter *iter); |
d604af56 JG |
153 | LTTNG_HIDDEN |
154 | struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( | |
bec39940 | 155 | struct lttng_ht_iter *iter); |
d604af56 JG |
156 | LTTNG_HIDDEN |
157 | struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( | |
d88aee68 | 158 | struct lttng_ht_iter *iter); |
d604af56 JG |
159 | LTTNG_HIDDEN |
160 | struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( | |
3c4599b9 | 161 | struct lttng_ht_iter *iter); |
bec39940 DG |
162 | |
163 | #endif /* _LTT_HT_H */ |