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