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 DG |
23 | |
24 | #include "rculfhash.h" | |
25 | #include "rculfhash-internal.h" | |
d604af56 | 26 | #include <common/macros.h> |
bec39940 | 27 | |
b6314938 DG |
28 | extern unsigned long lttng_ht_seed; |
29 | ||
bec39940 DG |
30 | typedef unsigned long (*hash_fct)(void *_key, unsigned long seed); |
31 | typedef cds_lfht_match_fct hash_match_fct; | |
32 | ||
33 | enum lttng_ht_type { | |
34 | LTTNG_HT_TYPE_STRING, | |
35 | LTTNG_HT_TYPE_ULONG, | |
d88aee68 | 36 | LTTNG_HT_TYPE_U64, |
3c4599b9 | 37 | LTTNG_HT_TYPE_TWO_U64, |
bec39940 DG |
38 | }; |
39 | ||
40 | struct lttng_ht { | |
41 | struct cds_lfht *ht; | |
42 | cds_lfht_match_fct match_fct; | |
43 | hash_fct hash_fct; | |
44 | }; | |
45 | ||
46 | struct lttng_ht_iter { | |
47 | struct cds_lfht_iter iter; | |
48 | }; | |
49 | ||
50 | struct lttng_ht_node_str { | |
51 | char *key; | |
52 | struct cds_lfht_node node; | |
53 | struct rcu_head head; | |
54 | }; | |
55 | ||
56 | struct lttng_ht_node_ulong { | |
57 | unsigned long key; | |
58 | struct cds_lfht_node node; | |
59 | struct rcu_head head; | |
60 | }; | |
61 | ||
d88aee68 DG |
62 | struct lttng_ht_node_u64 { |
63 | uint64_t key; | |
64 | struct cds_lfht_node node; | |
65 | struct rcu_head head; | |
66 | }; | |
67 | ||
3c4599b9 JD |
68 | struct lttng_ht_two_u64 { |
69 | uint64_t key1; | |
70 | uint64_t key2; | |
71 | }; | |
72 | ||
73 | struct lttng_ht_node_two_u64 { | |
74 | struct lttng_ht_two_u64 key; | |
75 | struct cds_lfht_node node; | |
76 | struct rcu_head head; | |
77 | }; | |
78 | ||
bec39940 | 79 | /* Hashtable new and destroy */ |
d604af56 JG |
80 | LTTNG_HIDDEN |
81 | struct lttng_ht *lttng_ht_new(unsigned long size, int type); | |
82 | LTTNG_HIDDEN | |
83 | void lttng_ht_destroy(struct lttng_ht *ht); | |
bec39940 DG |
84 | |
85 | /* Specialized node init and free functions */ | |
d604af56 JG |
86 | LTTNG_HIDDEN |
87 | void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); | |
88 | LTTNG_HIDDEN | |
89 | void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, | |
bec39940 | 90 | unsigned long key); |
d604af56 JG |
91 | LTTNG_HIDDEN |
92 | void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, | |
d88aee68 | 93 | uint64_t key); |
d604af56 JG |
94 | LTTNG_HIDDEN |
95 | void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, | |
3c4599b9 | 96 | uint64_t key1, uint64_t key2); |
d604af56 JG |
97 | LTTNG_HIDDEN |
98 | void lttng_ht_node_free_str(struct lttng_ht_node_str *node); | |
99 | LTTNG_HIDDEN | |
100 | void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); | |
101 | LTTNG_HIDDEN | |
102 | void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node); | |
103 | LTTNG_HIDDEN | |
104 | void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node); | |
105 | ||
106 | LTTNG_HIDDEN | |
107 | void lttng_ht_lookup(struct lttng_ht *ht, void *key, | |
bec39940 DG |
108 | struct lttng_ht_iter *iter); |
109 | ||
110 | /* Specialized add unique functions */ | |
d604af56 JG |
111 | LTTNG_HIDDEN |
112 | void lttng_ht_add_unique_str(struct lttng_ht *ht, | |
bec39940 | 113 | struct lttng_ht_node_str *node); |
d604af56 JG |
114 | LTTNG_HIDDEN |
115 | void lttng_ht_add_unique_ulong(struct lttng_ht *ht, | |
bec39940 | 116 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
117 | LTTNG_HIDDEN |
118 | void lttng_ht_add_unique_u64(struct lttng_ht *ht, | |
d88aee68 | 119 | struct lttng_ht_node_u64 *node); |
d604af56 JG |
120 | LTTNG_HIDDEN |
121 | void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, | |
3c4599b9 | 122 | struct lttng_ht_node_two_u64 *node); |
d604af56 JG |
123 | LTTNG_HIDDEN |
124 | struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong( | |
852d0037 | 125 | struct lttng_ht *ht, struct lttng_ht_node_ulong *node); |
d604af56 JG |
126 | LTTNG_HIDDEN |
127 | struct lttng_ht_node_u64 *lttng_ht_add_replace_u64( | |
d88aee68 | 128 | struct lttng_ht *ht, struct lttng_ht_node_u64 *node); |
d604af56 JG |
129 | LTTNG_HIDDEN |
130 | void lttng_ht_add_str(struct lttng_ht *ht, | |
efa116c6 | 131 | struct lttng_ht_node_str *node); |
d604af56 JG |
132 | LTTNG_HIDDEN |
133 | void lttng_ht_add_ulong(struct lttng_ht *ht, | |
aefea3b7 | 134 | struct lttng_ht_node_ulong *node); |
d604af56 JG |
135 | LTTNG_HIDDEN |
136 | void lttng_ht_add_u64(struct lttng_ht *ht, | |
d88aee68 | 137 | struct lttng_ht_node_u64 *node); |
bec39940 | 138 | |
d604af56 JG |
139 | LTTNG_HIDDEN |
140 | int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 141 | |
d604af56 JG |
142 | LTTNG_HIDDEN |
143 | void lttng_ht_get_first(struct lttng_ht *ht, | |
bec39940 | 144 | struct lttng_ht_iter *iter); |
d604af56 JG |
145 | LTTNG_HIDDEN |
146 | void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); | |
bec39940 | 147 | |
d604af56 JG |
148 | LTTNG_HIDDEN |
149 | unsigned long lttng_ht_get_count(struct lttng_ht *ht); | |
bec39940 | 150 | |
d604af56 JG |
151 | LTTNG_HIDDEN |
152 | struct lttng_ht_node_str *lttng_ht_iter_get_node_str( | |
bec39940 | 153 | struct lttng_ht_iter *iter); |
d604af56 JG |
154 | LTTNG_HIDDEN |
155 | struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( | |
bec39940 | 156 | struct lttng_ht_iter *iter); |
d604af56 JG |
157 | LTTNG_HIDDEN |
158 | struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( | |
d88aee68 | 159 | struct lttng_ht_iter *iter); |
d604af56 JG |
160 | LTTNG_HIDDEN |
161 | struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( | |
3c4599b9 | 162 | struct lttng_ht_iter *iter); |
bec39940 DG |
163 | |
164 | #endif /* _LTT_HT_H */ |