Commit | Line | Data |
---|---|---|
a42cc659 MD |
1 | #ifndef _URCU_RCULFHASH_H |
2 | #define _URCU_RCULFHASH_H | |
ab7d5fc6 | 3 | |
f0c29ed7 MD |
4 | /* |
5 | * urcu/rculfhash.h | |
6 | * | |
7 | * Userspace RCU library - Lock-Free RCU Hash Table | |
8 | * | |
9 | * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
0dcf4847 | 10 | * Copyright 2011 - Lai Jiangshan <laijs@cn.fujitsu.com> |
f0c29ed7 MD |
11 | * |
12 | * This library is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License as published by the Free Software Foundation; either | |
15 | * version 2.1 of the License, or (at your option) any later version. | |
16 | * | |
17 | * This library is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * Lesser General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
cf77d1fa MD |
25 | * |
26 | * Include this file _after_ including your URCU flavor. | |
f0c29ed7 MD |
27 | */ |
28 | ||
674f7a69 | 29 | #include <stdint.h> |
6d320126 | 30 | #include <urcu/compiler.h> |
abc490a1 | 31 | #include <urcu-call-rcu.h> |
7b17c13e | 32 | #include <urcu-flavor.h> |
abc490a1 | 33 | |
01389791 MD |
34 | #ifdef __cplusplus |
35 | extern "C" { | |
36 | #endif | |
37 | ||
7f52427b | 38 | /* |
04db56f8 | 39 | * cds_lfht_node: Contains the next pointers and reverse-hash |
7f52427b | 40 | * value required for lookup and traversal of the hash table. |
04db56f8 | 41 | * |
db00ccc3 | 42 | * struct cds_lfht_node should be aligned on 8-bytes boundaries because |
13f656f9 MD |
43 | * the three lower bits are used as flags. It is worth noting that the |
44 | * information contained within these three bits could be represented on | |
45 | * two bits by re-using the same bit for REMOVAL_OWNER_FLAG and | |
46 | * BUCKET_FLAG. This can be done if we ensure that no iterator nor | |
47 | * updater check the BUCKET_FLAG after it detects that the REMOVED_FLAG | |
48 | * is set. Given the minimum size of struct cds_lfht_node is 8 bytes on | |
49 | * 32-bit architectures, we choose to go for simplicity and reserve | |
50 | * three bits. | |
7f52427b | 51 | * |
ae62aa6a MD |
52 | * struct cds_lfht_node can be embedded into a structure (as a field). |
53 | * caa_container_of() can be used to get the structure from the struct | |
54 | * cds_lfht_node after a lookup. | |
04db56f8 LJ |
55 | * |
56 | * The structure which embeds it typically holds the key (or key-value | |
57 | * pair) of the object. The caller code is responsible for calculation | |
58 | * of the hash value for cds_lfht APIs. | |
ae62aa6a | 59 | */ |
14044b37 | 60 | struct cds_lfht_node { |
3f2f3714 | 61 | struct cds_lfht_node *next; /* ptr | REMOVAL_OWNER_FLAG | BUCKET_FLAG | REMOVED_FLAG */ |
04db56f8 | 62 | unsigned long reverse_hash; |
db00ccc3 | 63 | } __attribute__((aligned(8))); |
abc490a1 | 64 | |
7f52427b | 65 | /* cds_lfht_iter: Used to track state while traversing a hash chain. */ |
adc0de68 MD |
66 | struct cds_lfht_iter { |
67 | struct cds_lfht_node *node, *next; | |
68 | }; | |
69 | ||
70 | static inline | |
71 | struct cds_lfht_node *cds_lfht_iter_get_node(struct cds_lfht_iter *iter) | |
72 | { | |
73 | return iter->node; | |
74 | } | |
75 | ||
14044b37 | 76 | struct cds_lfht; |
ab7d5fc6 | 77 | |
5e28c532 MD |
78 | /* |
79 | * Caution ! | |
abc490a1 | 80 | * Ensure reader and writer threads are registered as urcu readers. |
5e28c532 MD |
81 | */ |
82 | ||
996ff57c | 83 | typedef int (*cds_lfht_match_fct)(struct cds_lfht_node *node, const void *key); |
abc490a1 | 84 | |
f0c29ed7 | 85 | /* |
14044b37 | 86 | * cds_lfht_node_init - initialize a hash table node |
0422d92c | 87 | * @node: the node to initialize. |
04db56f8 LJ |
88 | * |
89 | * This function is kept to be eventually used for debugging purposes | |
90 | * (detection of memory corruption). | |
f0c29ed7 | 91 | */ |
abc490a1 | 92 | static inline |
04db56f8 | 93 | void cds_lfht_node_init(struct cds_lfht_node *node) |
abc490a1 | 94 | { |
abc490a1 | 95 | } |
674f7a69 | 96 | |
b8af5011 MD |
97 | /* |
98 | * Hash table creation flags. | |
99 | */ | |
100 | enum { | |
101 | CDS_LFHT_AUTO_RESIZE = (1U << 0), | |
5afadd12 | 102 | CDS_LFHT_ACCOUNTING = (1U << 1), |
b8af5011 MD |
103 | }; |
104 | ||
0b6aa001 LJ |
105 | struct cds_lfht_mm_type { |
106 | struct cds_lfht *(*alloc_cds_lfht)(unsigned long min_nr_alloc_buckets, | |
107 | unsigned long max_nr_buckets); | |
108 | void (*alloc_bucket_table)(struct cds_lfht *ht, unsigned long order); | |
109 | void (*free_bucket_table)(struct cds_lfht *ht, unsigned long order); | |
110 | struct cds_lfht_node *(*bucket_at)(struct cds_lfht *ht, | |
111 | unsigned long index); | |
112 | }; | |
113 | ||
114 | extern const struct cds_lfht_mm_type cds_lfht_mm_order; | |
308d1cb3 | 115 | extern const struct cds_lfht_mm_type cds_lfht_mm_chunk; |
b0b55251 | 116 | extern const struct cds_lfht_mm_type cds_lfht_mm_mmap; |
0b6aa001 | 117 | |
674f7a69 | 118 | /* |
7a9dcf9b | 119 | * _cds_lfht_new - API used by cds_lfht_new wrapper. Do not use directly. |
674f7a69 | 120 | */ |
b9c27904 | 121 | extern |
0422d92c | 122 | struct cds_lfht *_cds_lfht_new(unsigned long init_size, |
0722081a | 123 | unsigned long min_nr_alloc_buckets, |
747d725c | 124 | unsigned long max_nr_buckets, |
b8af5011 | 125 | int flags, |
0b6aa001 | 126 | const struct cds_lfht_mm_type *mm, |
7b17c13e | 127 | const struct rcu_flavor_struct *flavor, |
b7d619b0 | 128 | pthread_attr_t *attr); |
ab7d5fc6 | 129 | |
7a9dcf9b MD |
130 | /* |
131 | * cds_lfht_new - allocate a hash table. | |
747d725c LJ |
132 | * @init_size: number of buckets to allocate initially. Must be power of two. |
133 | * @min_nr_alloc_buckets: the minimum number of allocated buckets. | |
134 | * (must be power of two) | |
135 | * @max_nr_buckets: the maximum number of hash table buckets allowed. | |
28d5c1b5 MD |
136 | * (must be power of two, 0 is accepted, means |
137 | * "infinite") | |
f22dd01d MD |
138 | * @flags: hash table creation flags (can be combined with bitwise or: '|'). |
139 | * 0: no flags. | |
140 | * CDS_LFHT_AUTO_RESIZE: automatically resize hash table. | |
44bbe7fa LJ |
141 | * CDS_LFHT_ACCOUNTING: count the number of node addition |
142 | * and removal in the table | |
b7d619b0 | 143 | * @attr: optional resize worker thread attributes. NULL for default. |
7a9dcf9b | 144 | * |
7a9dcf9b MD |
145 | * Return NULL on error. |
146 | * Note: the RCU flavor must be already included before the hash table header. | |
b7d619b0 MD |
147 | * |
148 | * The programmer is responsible for ensuring that resize operation has a | |
149 | * priority equal to hash table updater threads. It should be performed by | |
150 | * specifying the appropriate priority in the pthread "attr" argument, and, | |
151 | * for CDS_LFHT_AUTO_RESIZE, by ensuring that call_rcu worker threads also have | |
152 | * this priority level. Having lower priority for call_rcu and resize threads | |
153 | * does not pose any correctness issue, but the resize operations could be | |
154 | * starved by updates, thus leading to long hash table bucket chains. | |
3a9c66db MD |
155 | * Threads calling cds_lfht_new are NOT required to be registered RCU |
156 | * read-side threads. It can be called very early. (e.g. before RCU is | |
157 | * initialized) | |
7a9dcf9b MD |
158 | */ |
159 | static inline | |
0422d92c | 160 | struct cds_lfht *cds_lfht_new(unsigned long init_size, |
0722081a | 161 | unsigned long min_nr_alloc_buckets, |
747d725c | 162 | unsigned long max_nr_buckets, |
b7d619b0 MD |
163 | int flags, |
164 | pthread_attr_t *attr) | |
7a9dcf9b | 165 | { |
7b17c13e | 166 | return _cds_lfht_new(init_size, min_nr_alloc_buckets, max_nr_buckets, |
c1888f3a | 167 | flags, NULL, &rcu_flavor, attr); |
7a9dcf9b MD |
168 | } |
169 | ||
f0c29ed7 | 170 | /* |
14044b37 | 171 | * cds_lfht_destroy - destroy a hash table. |
b7d619b0 MD |
172 | * @ht: the hash table to destroy. |
173 | * @attr: (output) resize worker thread attributes, as received by cds_lfht_new. | |
174 | * The caller will typically want to free this pointer if dynamically | |
7f52427b MD |
175 | * allocated. The attr point can be NULL if the caller does not |
176 | * need to be informed of the value passed to cds_lfht_new(). | |
6878c72b MD |
177 | * |
178 | * Return 0 on success, negative error value on error. | |
3df0c49c | 179 | * Threads calling this API need to be registered RCU read-side threads. |
96914388 | 180 | * cds_lfht_destroy should *not* be called from a RCU read-side critical |
a22bf98b MD |
181 | * section. It should *not* be called from a call_rcu thread context |
182 | * neither. | |
f0c29ed7 | 183 | */ |
b9c27904 | 184 | extern |
b7d619b0 | 185 | int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr); |
f0c29ed7 MD |
186 | |
187 | /* | |
14044b37 | 188 | * cds_lfht_count_nodes - count the number of nodes in the hash table. |
7f52427b | 189 | * @ht: the hash table. |
3a9c66db MD |
190 | * @split_count_before: sample the node count split-counter before traversal. |
191 | * @count: traverse the hash table, count the number of nodes observed. | |
192 | * @split_count_after: sample the node count split-counter after traversal. | |
0422d92c | 193 | * |
f0c29ed7 | 194 | * Call with rcu_read_lock held. |
3df0c49c | 195 | * Threads calling this API need to be registered RCU read-side threads. |
f0c29ed7 | 196 | */ |
b9c27904 | 197 | extern |
14044b37 | 198 | void cds_lfht_count_nodes(struct cds_lfht *ht, |
7f52427b | 199 | long *split_count_before, |
adc0de68 | 200 | unsigned long *count, |
7f52427b | 201 | long *split_count_after); |
ab7d5fc6 | 202 | |
f0c29ed7 | 203 | /* |
14044b37 | 204 | * cds_lfht_lookup - lookup a node by key. |
0422d92c | 205 | * @ht: the hash table. |
0422d92c | 206 | * @hash: the key hash. |
6f554439 LJ |
207 | * @match: the key match function. |
208 | * @key: the current node key. | |
3a9c66db | 209 | * @iter: node, if found (output). *iter->node set to NULL if not found. |
f0c29ed7 | 210 | * |
f0c29ed7 | 211 | * Call with rcu_read_lock held. |
3df0c49c | 212 | * Threads calling this API need to be registered RCU read-side threads. |
7b783f81 | 213 | * This function acts as a rcu_dereference() to read the node pointer. |
f0c29ed7 | 214 | */ |
b9c27904 | 215 | extern |
6f554439 | 216 | void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash, |
996ff57c | 217 | cds_lfht_match_fct match, const void *key, |
6f554439 | 218 | struct cds_lfht_iter *iter); |
ab7d5fc6 | 219 | |
f0c29ed7 | 220 | /* |
3a9c66db | 221 | * cds_lfht_next_duplicate - get the next item with same key, after iterator. |
0422d92c MD |
222 | * @ht: the hash table. |
223 | * @match: the key match function. | |
04db56f8 | 224 | * @key: the current node key. |
3a9c66db MD |
225 | * @iter: input: current iterator. |
226 | * output: node, if found. *iter->node set to NULL if not found. | |
f0c29ed7 | 227 | * |
3a9c66db MD |
228 | * Uses an iterator initialized by a lookup or traversal. Important: the |
229 | * iterator _needs_ to be initialized before calling | |
230 | * cds_lfht_next_duplicate. | |
adc0de68 MD |
231 | * Sets *iter-node to the following node with same key. |
232 | * Sets *iter->node to NULL if no following node exists with same key. | |
233 | * RCU read-side lock must be held across cds_lfht_lookup and | |
234 | * cds_lfht_next calls, and also between cds_lfht_next calls using the | |
235 | * node returned by a previous cds_lfht_next. | |
236 | * Call with rcu_read_lock held. | |
3df0c49c | 237 | * Threads calling this API need to be registered RCU read-side threads. |
7b783f81 | 238 | * This function acts as a rcu_dereference() to read the node pointer. |
f0c29ed7 | 239 | */ |
b9c27904 | 240 | extern |
0422d92c | 241 | void cds_lfht_next_duplicate(struct cds_lfht *ht, |
996ff57c | 242 | cds_lfht_match_fct match, const void *key, |
04db56f8 | 243 | struct cds_lfht_iter *iter); |
4e9b9fbf MD |
244 | |
245 | /* | |
246 | * cds_lfht_first - get the first node in the table. | |
0422d92c MD |
247 | * @ht: the hash table. |
248 | * @iter: First node, if exists (output). *iter->node set to NULL if not found. | |
4e9b9fbf MD |
249 | * |
250 | * Output in "*iter". *iter->node set to NULL if table is empty. | |
251 | * Call with rcu_read_lock held. | |
3df0c49c | 252 | * Threads calling this API need to be registered RCU read-side threads. |
7b783f81 | 253 | * This function acts as a rcu_dereference() to read the node pointer. |
4e9b9fbf | 254 | */ |
b9c27904 | 255 | extern |
4e9b9fbf MD |
256 | void cds_lfht_first(struct cds_lfht *ht, struct cds_lfht_iter *iter); |
257 | ||
258 | /* | |
259 | * cds_lfht_next - get the next node in the table. | |
0422d92c | 260 | * @ht: the hash table. |
3a9c66db MD |
261 | * @iter: input: current iterator. |
262 | * output: next node, if exists. *iter->node set to NULL if not found. | |
4e9b9fbf MD |
263 | * |
264 | * Input/Output in "*iter". *iter->node set to NULL if *iter was | |
265 | * pointing to the last table node. | |
266 | * Call with rcu_read_lock held. | |
3df0c49c | 267 | * Threads calling this API need to be registered RCU read-side threads. |
7b783f81 | 268 | * This function acts as a rcu_dereference() to read the node pointer. |
4e9b9fbf | 269 | */ |
b9c27904 | 270 | extern |
4e9b9fbf | 271 | void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter); |
ab7d5fc6 | 272 | |
18117871 | 273 | /* |
14044b37 | 274 | * cds_lfht_add - add a node to the hash table. |
0422d92c MD |
275 | * @ht: the hash table. |
276 | * @hash: the key hash. | |
277 | * @node: the node to add. | |
f0c29ed7 | 278 | * |
48ed1c18 | 279 | * This function supports adding redundant keys into the table. |
3df0c49c MD |
280 | * Call with rcu_read_lock held. |
281 | * Threads calling this API need to be registered RCU read-side threads. | |
7b783f81 MD |
282 | * This function issues a full memory barrier before and after its |
283 | * atomic commit. | |
f0c29ed7 | 284 | */ |
b9c27904 | 285 | extern |
0422d92c MD |
286 | void cds_lfht_add(struct cds_lfht *ht, unsigned long hash, |
287 | struct cds_lfht_node *node); | |
f0c29ed7 MD |
288 | |
289 | /* | |
14044b37 | 290 | * cds_lfht_add_unique - add a node to hash table, if key is not present. |
0422d92c | 291 | * @ht: the hash table. |
6f554439 | 292 | * @hash: the node's hash. |
0422d92c | 293 | * @match: the key match function. |
04db56f8 | 294 | * @key: the node's key. |
0422d92c | 295 | * @node: the node to try adding. |
f0c29ed7 | 296 | * |
6878c72b | 297 | * Return the node added upon success. |
860d07e8 MD |
298 | * Return the unique node already present upon failure. If |
299 | * cds_lfht_add_unique fails, the node passed as parameter should be | |
3a9c66db | 300 | * freed by the caller. In this case, the caller does NOT need to wait |
50024344 | 301 | * for a grace period before freeing or re-using the node. |
f0c29ed7 | 302 | * Call with rcu_read_lock held. |
3df0c49c | 303 | * Threads calling this API need to be registered RCU read-side threads. |
48ed1c18 MD |
304 | * |
305 | * The semantic of this function is that if only this function is used | |
306 | * to add keys into the table, no duplicated keys should ever be | |
307 | * observable in the table. The same guarantee apply for combination of | |
9357c415 | 308 | * add_unique and add_replace (see below). |
7b783f81 MD |
309 | * |
310 | * Upon success, this function issues a full memory barrier before and | |
311 | * after its atomic commit. Upon failure, this function acts like a | |
312 | * simple lookup operation: it acts as a rcu_dereference() to read the | |
313 | * node pointer. The failure case does not guarantee any other memory | |
314 | * barrier. | |
18117871 | 315 | */ |
b9c27904 | 316 | extern |
adc0de68 | 317 | struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht, |
6f554439 | 318 | unsigned long hash, |
0422d92c | 319 | cds_lfht_match_fct match, |
996ff57c | 320 | const void *key, |
adc0de68 | 321 | struct cds_lfht_node *node); |
3eca1b8c | 322 | |
48ed1c18 | 323 | /* |
9357c415 | 324 | * cds_lfht_add_replace - replace or add a node within hash table. |
0422d92c | 325 | * @ht: the hash table. |
6f554439 | 326 | * @hash: the node's hash. |
0422d92c | 327 | * @match: the key match function. |
04db56f8 | 328 | * @key: the node's key. |
0422d92c | 329 | * @node: the node to add. |
48ed1c18 MD |
330 | * |
331 | * Return the node replaced upon success. If no node matching the key | |
332 | * was present, return NULL, which also means the operation succeeded. | |
333 | * This replacement operation should never fail. | |
334 | * Call with rcu_read_lock held. | |
3df0c49c | 335 | * Threads calling this API need to be registered RCU read-side threads. |
48ed1c18 | 336 | * After successful replacement, a grace period must be waited for before |
50024344 | 337 | * freeing or re-using the memory reserved for the returned node. |
48ed1c18 | 338 | * |
3a9c66db MD |
339 | * The semantic of replacement vs lookups and traversals is the |
340 | * following: if lookups and traversals are performed between a key | |
341 | * unique insertion and its removal, we guarantee that the lookups and | |
342 | * traversals will always find exactly one instance of the key if it is | |
343 | * replaced concurrently with the lookups. | |
48ed1c18 MD |
344 | * |
345 | * Providing this semantic allows us to ensure that replacement-only | |
346 | * schemes will never generate duplicated keys. It also allows us to | |
9357c415 | 347 | * guarantee that a combination of add_replace and add_unique updates |
48ed1c18 | 348 | * will never generate duplicated keys. |
7b783f81 MD |
349 | * |
350 | * This function issues a full memory barrier before and after its | |
351 | * atomic commit. | |
48ed1c18 | 352 | */ |
b9c27904 | 353 | extern |
9357c415 | 354 | struct cds_lfht_node *cds_lfht_add_replace(struct cds_lfht *ht, |
6f554439 | 355 | unsigned long hash, |
0422d92c | 356 | cds_lfht_match_fct match, |
996ff57c | 357 | const void *key, |
adc0de68 | 358 | struct cds_lfht_node *node); |
48ed1c18 | 359 | |
f0c29ed7 | 360 | /* |
929ad508 | 361 | * cds_lfht_replace - replace a node pointed to by iter within hash table. |
0422d92c MD |
362 | * @ht: the hash table. |
363 | * @old_iter: the iterator position of the node to replace. | |
2e79c445 MD |
364 | * @hash: the node's hash. |
365 | * @match: the key match function. | |
366 | * @key: the node's key. | |
367 | * @new_node: the new node to use as replacement. | |
f0c29ed7 | 368 | * |
9357c415 | 369 | * Return 0 if replacement is successful, negative value otherwise. |
2e79c445 MD |
370 | * Replacing a NULL old node or an already removed node will fail with |
371 | * -ENOENT. | |
372 | * If the hash or value of the node to replace and the new node differ, | |
373 | * this function returns -EINVAL without proceeding to the replacement. | |
9357c415 MD |
374 | * Old node can be looked up with cds_lfht_lookup and cds_lfht_next. |
375 | * RCU read-side lock must be held between lookup and replacement. | |
376 | * Call with rcu_read_lock held. | |
3df0c49c | 377 | * Threads calling this API need to be registered RCU read-side threads. |
9357c415 | 378 | * After successful replacement, a grace period must be waited for before |
50024344 MD |
379 | * freeing or re-using the memory reserved for the old node (which can |
380 | * be accessed with cds_lfht_iter_get_node). | |
9357c415 | 381 | * |
3a9c66db MD |
382 | * The semantic of replacement vs lookups is the same as |
383 | * cds_lfht_add_replace(). | |
7b783f81 MD |
384 | * |
385 | * Upon success, this function issues a full memory barrier before and | |
386 | * after its atomic commit. Upon failure, this function does not issue | |
387 | * any memory barrier. | |
9357c415 | 388 | */ |
b9c27904 | 389 | extern |
2e79c445 MD |
390 | int cds_lfht_replace(struct cds_lfht *ht, |
391 | struct cds_lfht_iter *old_iter, | |
392 | unsigned long hash, | |
393 | cds_lfht_match_fct match, | |
394 | const void *key, | |
9357c415 MD |
395 | struct cds_lfht_node *new_node); |
396 | ||
397 | /* | |
398 | * cds_lfht_del - remove node pointed to by iterator from hash table. | |
0422d92c | 399 | * @ht: the hash table. |
bc8c3c74 | 400 | * @node: the node to delete. |
9357c415 MD |
401 | * |
402 | * Return 0 if the node is successfully removed, negative value | |
403 | * otherwise. | |
bc8c3c74 | 404 | * Deleting a NULL node or an already removed node will fail with a |
9357c415 | 405 | * negative value. |
bc8c3c74 MD |
406 | * Node can be looked up with cds_lfht_lookup and cds_lfht_next, |
407 | * followed by use of cds_lfht_iter_get_node. | |
9357c415 | 408 | * RCU read-side lock must be held between lookup and removal. |
f0c29ed7 | 409 | * Call with rcu_read_lock held. |
3df0c49c | 410 | * Threads calling this API need to be registered RCU read-side threads. |
48ed1c18 | 411 | * After successful removal, a grace period must be waited for before |
50024344 MD |
412 | * freeing or re-using the memory reserved for old node (which can be |
413 | * accessed with cds_lfht_iter_get_node). | |
7b783f81 MD |
414 | * Upon success, this function issues a full memory barrier before and |
415 | * after its atomic commit. Upon failure, this function does not issue | |
416 | * any memory barrier. | |
f0c29ed7 | 417 | */ |
b9c27904 | 418 | extern |
bc8c3c74 | 419 | int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_node *node); |
ab7d5fc6 | 420 | |
df55172a | 421 | /* |
3a9c66db | 422 | * cds_lfht_is_node_deleted - query whether a node is removed from hash table. |
df55172a MD |
423 | * |
424 | * Return non-zero if the node is deleted from the hash table, 0 | |
425 | * otherwise. | |
426 | * Node can be looked up with cds_lfht_lookup and cds_lfht_next, | |
427 | * followed by use of cds_lfht_iter_get_node. | |
428 | * RCU read-side lock must be held between lookup and call to this | |
429 | * function. | |
430 | * Call with rcu_read_lock held. | |
431 | * Threads calling this API need to be registered RCU read-side threads. | |
7b783f81 | 432 | * This function does not issue any memory barrier. |
df55172a | 433 | */ |
b9c27904 | 434 | extern |
df55172a MD |
435 | int cds_lfht_is_node_deleted(struct cds_lfht_node *node); |
436 | ||
f0c29ed7 | 437 | /* |
14044b37 | 438 | * cds_lfht_resize - Force a hash table resize |
0422d92c | 439 | * @ht: the hash table. |
1475579c | 440 | * @new_size: update to this hash table size. |
3df0c49c MD |
441 | * |
442 | * Threads calling this API need to be registered RCU read-side threads. | |
7b783f81 | 443 | * This function does not (necessarily) issue memory barriers. |
43387742 MD |
444 | * cds_lfht_resize should *not* be called from a RCU read-side critical |
445 | * section. | |
f0c29ed7 | 446 | */ |
b9c27904 | 447 | extern |
1475579c | 448 | void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size); |
464a1ec9 | 449 | |
6d320126 | 450 | /* |
3a9c66db MD |
451 | * Note: it is safe to perform element removal (del), replacement, or |
452 | * any hash table update operation during any of the following hash | |
453 | * table traversals. | |
7b783f81 | 454 | * These functions act as rcu_dereference() to read the node pointers. |
6d320126 MD |
455 | */ |
456 | #define cds_lfht_for_each(ht, iter, node) \ | |
457 | for (cds_lfht_first(ht, iter), \ | |
458 | node = cds_lfht_iter_get_node(iter); \ | |
459 | node != NULL; \ | |
460 | cds_lfht_next(ht, iter), \ | |
461 | node = cds_lfht_iter_get_node(iter)) | |
462 | ||
6f554439 LJ |
463 | #define cds_lfht_for_each_duplicate(ht, hash, match, key, iter, node) \ |
464 | for (cds_lfht_lookup(ht, hash, match, key, iter), \ | |
6d320126 MD |
465 | node = cds_lfht_iter_get_node(iter); \ |
466 | node != NULL; \ | |
467 | cds_lfht_next_duplicate(ht, match, key, iter), \ | |
468 | node = cds_lfht_iter_get_node(iter)) | |
469 | ||
470 | #define cds_lfht_for_each_entry(ht, iter, pos, member) \ | |
471 | for (cds_lfht_first(ht, iter), \ | |
472 | pos = caa_container_of(cds_lfht_iter_get_node(iter), \ | |
bdffa73a | 473 | __typeof__(*(pos)), member); \ |
92af1a30 | 474 | cds_lfht_iter_get_node(iter) != NULL; \ |
6d320126 MD |
475 | cds_lfht_next(ht, iter), \ |
476 | pos = caa_container_of(cds_lfht_iter_get_node(iter), \ | |
bdffa73a | 477 | __typeof__(*(pos)), member)) |
6d320126 | 478 | |
6f554439 | 479 | #define cds_lfht_for_each_entry_duplicate(ht, hash, match, key, \ |
6d320126 | 480 | iter, pos, member) \ |
6f554439 | 481 | for (cds_lfht_lookup(ht, hash, match, key, iter), \ |
6d320126 | 482 | pos = caa_container_of(cds_lfht_iter_get_node(iter), \ |
bdffa73a | 483 | __typeof__(*(pos)), member); \ |
92af1a30 | 484 | cds_lfht_iter_get_node(iter) != NULL; \ |
6d320126 MD |
485 | cds_lfht_next_duplicate(ht, match, key, iter), \ |
486 | pos = caa_container_of(cds_lfht_iter_get_node(iter), \ | |
bdffa73a | 487 | __typeof__(*(pos)), member)) |
6d320126 | 488 | |
01389791 MD |
489 | #ifdef __cplusplus |
490 | } | |
491 | #endif | |
492 | ||
a42cc659 | 493 | #endif /* _URCU_RCULFHASH_H */ |