Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Resizable, Scalable, Concurrent Hash Table |
| 3 | * |
| 4 | * Copyright (c) 2014 Thomas Graf <tgraf@suug.ch> |
| 5 | * Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net> |
| 6 | * |
| 7 | * Based on the following paper by Josh Triplett, Paul E. McKenney |
| 8 | * and Jonathan Walpole: |
| 9 | * https://www.usenix.org/legacy/event/atc11/tech/final_files/Triplett.pdf |
| 10 | * |
| 11 | * Code partially derived from nft_hash |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | |
| 18 | #ifndef _LINUX_RHASHTABLE_H |
| 19 | #define _LINUX_RHASHTABLE_H |
| 20 | |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 21 | #include <linux/list_nulls.h> |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 22 | #include <linux/workqueue.h> |
Ying Xue | 86b35b6 | 2015-01-04 15:25:09 +0800 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 24 | |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 25 | /* |
| 26 | * The end of the chain is marked with a special nulls marks which has |
| 27 | * the following format: |
| 28 | * |
| 29 | * +-------+-----------------------------------------------------+-+ |
| 30 | * | Base | Hash |1| |
| 31 | * +-------+-----------------------------------------------------+-+ |
| 32 | * |
| 33 | * Base (4 bits) : Reserved to distinguish between multiple tables. |
| 34 | * Specified via &struct rhashtable_params.nulls_base. |
| 35 | * Hash (27 bits): Full hash (unmasked) of first element added to bucket |
| 36 | * 1 (1 bit) : Nulls marker (always set) |
| 37 | * |
| 38 | * The remaining bits of the next pointer remain unused for now. |
| 39 | */ |
| 40 | #define RHT_BASE_BITS 4 |
| 41 | #define RHT_HASH_BITS 27 |
| 42 | #define RHT_BASE_SHIFT RHT_HASH_BITS |
| 43 | |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 44 | struct rhash_head { |
Thomas Graf | 5300fdc | 2014-08-13 16:38:29 +0200 | [diff] [blame] | 45 | struct rhash_head __rcu *next; |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 46 | }; |
| 47 | |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 48 | /** |
| 49 | * struct bucket_table - Table of hash buckets |
| 50 | * @size: Number of hash buckets |
| 51 | * @locks_mask: Mask to apply before accessing locks[] |
| 52 | * @locks: Array of spinlocks protecting individual buckets |
| 53 | * @buckets: size * hash buckets |
| 54 | */ |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 55 | struct bucket_table { |
| 56 | size_t size; |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 57 | unsigned int locks_mask; |
| 58 | spinlock_t *locks; |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 59 | struct rhash_head __rcu *buckets[]; |
| 60 | }; |
| 61 | |
| 62 | typedef u32 (*rht_hashfn_t)(const void *data, u32 len, u32 seed); |
| 63 | typedef u32 (*rht_obj_hashfn_t)(const void *data, u32 seed); |
| 64 | |
| 65 | struct rhashtable; |
| 66 | |
| 67 | /** |
| 68 | * struct rhashtable_params - Hash table construction parameters |
| 69 | * @nelem_hint: Hint on number of elements, should be 75% of desired size |
| 70 | * @key_len: Length of key |
| 71 | * @key_offset: Offset of key in struct to be hashed |
| 72 | * @head_offset: Offset of rhash_head in struct to be hashed |
| 73 | * @hash_rnd: Seed to use while hashing |
| 74 | * @max_shift: Maximum number of shifts while expanding |
Ying Xue | 9400017 | 2014-09-03 09:22:36 +0800 | [diff] [blame] | 75 | * @min_shift: Minimum number of shifts while shrinking |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 76 | * @nulls_base: Base value to generate nulls marker |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 77 | * @locks_mul: Number of bucket locks to allocate per cpu (default: 128) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 78 | * @hashfn: Function to hash key |
| 79 | * @obj_hashfn: Function to hash object |
| 80 | * @grow_decision: If defined, may return true if table should expand |
| 81 | * @shrink_decision: If defined, may return true if table should shrink |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 82 | */ |
| 83 | struct rhashtable_params { |
| 84 | size_t nelem_hint; |
| 85 | size_t key_len; |
| 86 | size_t key_offset; |
| 87 | size_t head_offset; |
| 88 | u32 hash_rnd; |
| 89 | size_t max_shift; |
Ying Xue | 9400017 | 2014-09-03 09:22:36 +0800 | [diff] [blame] | 90 | size_t min_shift; |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 91 | u32 nulls_base; |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 92 | size_t locks_mul; |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 93 | rht_hashfn_t hashfn; |
| 94 | rht_obj_hashfn_t obj_hashfn; |
| 95 | bool (*grow_decision)(const struct rhashtable *ht, |
| 96 | size_t new_size); |
| 97 | bool (*shrink_decision)(const struct rhashtable *ht, |
| 98 | size_t new_size); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * struct rhashtable - Hash table handle |
| 103 | * @tbl: Bucket table |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 104 | * @future_tbl: Table under construction during expansion/shrinking |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 105 | * @nelems: Number of elements in table |
| 106 | * @shift: Current size (1 << shift) |
| 107 | * @p: Configuration parameters |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 108 | * @run_work: Deferred worker to expand/shrink asynchronously |
| 109 | * @mutex: Mutex to protect current/future table swapping |
| 110 | * @being_destroyed: True if table is set up for destruction |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 111 | */ |
| 112 | struct rhashtable { |
| 113 | struct bucket_table __rcu *tbl; |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 114 | struct bucket_table __rcu *future_tbl; |
| 115 | atomic_t nelems; |
Ying Xue | c0c09bf | 2015-01-07 13:41:56 +0800 | [diff] [blame^] | 116 | atomic_t shift; |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 117 | struct rhashtable_params p; |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 118 | struct delayed_work run_work; |
| 119 | struct mutex mutex; |
| 120 | bool being_destroyed; |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 123 | static inline unsigned long rht_marker(const struct rhashtable *ht, u32 hash) |
| 124 | { |
| 125 | return NULLS_MARKER(ht->p.nulls_base + hash); |
| 126 | } |
| 127 | |
| 128 | #define INIT_RHT_NULLS_HEAD(ptr, ht, hash) \ |
| 129 | ((ptr) = (typeof(ptr)) rht_marker(ht, hash)) |
| 130 | |
| 131 | static inline bool rht_is_a_nulls(const struct rhash_head *ptr) |
| 132 | { |
| 133 | return ((unsigned long) ptr & 1); |
| 134 | } |
| 135 | |
| 136 | static inline unsigned long rht_get_nulls_value(const struct rhash_head *ptr) |
| 137 | { |
| 138 | return ((unsigned long) ptr) >> 1; |
| 139 | } |
| 140 | |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 141 | #ifdef CONFIG_PROVE_LOCKING |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 142 | int lockdep_rht_mutex_is_held(struct rhashtable *ht); |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 143 | int lockdep_rht_bucket_is_held(const struct bucket_table *tbl, u32 hash); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 144 | #else |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 145 | static inline int lockdep_rht_mutex_is_held(struct rhashtable *ht) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 146 | { |
| 147 | return 1; |
| 148 | } |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 149 | |
| 150 | static inline int lockdep_rht_bucket_is_held(const struct bucket_table *tbl, |
| 151 | u32 hash) |
| 152 | { |
| 153 | return 1; |
| 154 | } |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 155 | #endif /* CONFIG_PROVE_LOCKING */ |
| 156 | |
| 157 | int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params); |
| 158 | |
Thomas Graf | 6eba822 | 2014-11-13 13:45:46 +0100 | [diff] [blame] | 159 | void rhashtable_insert(struct rhashtable *ht, struct rhash_head *node); |
| 160 | bool rhashtable_remove(struct rhashtable *ht, struct rhash_head *node); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 161 | |
| 162 | bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size); |
| 163 | bool rht_shrink_below_30(const struct rhashtable *ht, size_t new_size); |
| 164 | |
Thomas Graf | 6eba822 | 2014-11-13 13:45:46 +0100 | [diff] [blame] | 165 | int rhashtable_expand(struct rhashtable *ht); |
| 166 | int rhashtable_shrink(struct rhashtable *ht); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 167 | |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 168 | void *rhashtable_lookup(struct rhashtable *ht, const void *key); |
| 169 | void *rhashtable_lookup_compare(struct rhashtable *ht, const void *key, |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 170 | bool (*compare)(void *, void *), void *arg); |
Ying Xue | db30485 | 2015-01-07 13:41:54 +0800 | [diff] [blame] | 171 | bool rhashtable_lookup_insert(struct rhashtable *ht, struct rhash_head *obj); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 172 | |
Thomas Graf | 97defe1 | 2015-01-02 23:00:20 +0100 | [diff] [blame] | 173 | void rhashtable_destroy(struct rhashtable *ht); |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 174 | |
| 175 | #define rht_dereference(p, ht) \ |
| 176 | rcu_dereference_protected(p, lockdep_rht_mutex_is_held(ht)) |
| 177 | |
| 178 | #define rht_dereference_rcu(p, ht) \ |
| 179 | rcu_dereference_check(p, lockdep_rht_mutex_is_held(ht)) |
| 180 | |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 181 | #define rht_dereference_bucket(p, tbl, hash) \ |
| 182 | rcu_dereference_protected(p, lockdep_rht_bucket_is_held(tbl, hash)) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 183 | |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 184 | #define rht_dereference_bucket_rcu(p, tbl, hash) \ |
| 185 | rcu_dereference_check(p, lockdep_rht_bucket_is_held(tbl, hash)) |
| 186 | |
| 187 | #define rht_entry(tpos, pos, member) \ |
| 188 | ({ tpos = container_of(pos, typeof(*tpos), member); 1; }) |
| 189 | |
| 190 | /** |
| 191 | * rht_for_each_continue - continue iterating over hash chain |
| 192 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 193 | * @head: the previous &struct rhash_head to continue from |
| 194 | * @tbl: the &struct bucket_table |
| 195 | * @hash: the hash value / bucket index |
| 196 | */ |
| 197 | #define rht_for_each_continue(pos, head, tbl, hash) \ |
| 198 | for (pos = rht_dereference_bucket(head, tbl, hash); \ |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 199 | !rht_is_a_nulls(pos); \ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 200 | pos = rht_dereference_bucket((pos)->next, tbl, hash)) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * rht_for_each - iterate over hash chain |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 204 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 205 | * @tbl: the &struct bucket_table |
| 206 | * @hash: the hash value / bucket index |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 207 | */ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 208 | #define rht_for_each(pos, tbl, hash) \ |
| 209 | rht_for_each_continue(pos, (tbl)->buckets[hash], tbl, hash) |
| 210 | |
| 211 | /** |
| 212 | * rht_for_each_entry_continue - continue iterating over hash chain |
| 213 | * @tpos: the type * to use as a loop cursor. |
| 214 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 215 | * @head: the previous &struct rhash_head to continue from |
| 216 | * @tbl: the &struct bucket_table |
| 217 | * @hash: the hash value / bucket index |
| 218 | * @member: name of the &struct rhash_head within the hashable struct. |
| 219 | */ |
| 220 | #define rht_for_each_entry_continue(tpos, pos, head, tbl, hash, member) \ |
| 221 | for (pos = rht_dereference_bucket(head, tbl, hash); \ |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 222 | (!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 223 | pos = rht_dereference_bucket((pos)->next, tbl, hash)) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * rht_for_each_entry - iterate over hash chain of given type |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 227 | * @tpos: the type * to use as a loop cursor. |
| 228 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 229 | * @tbl: the &struct bucket_table |
| 230 | * @hash: the hash value / bucket index |
| 231 | * @member: name of the &struct rhash_head within the hashable struct. |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 232 | */ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 233 | #define rht_for_each_entry(tpos, pos, tbl, hash, member) \ |
| 234 | rht_for_each_entry_continue(tpos, pos, (tbl)->buckets[hash], \ |
| 235 | tbl, hash, member) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * rht_for_each_entry_safe - safely iterate over hash chain of given type |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 239 | * @tpos: the type * to use as a loop cursor. |
| 240 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 241 | * @next: the &struct rhash_head to use as next in loop cursor. |
| 242 | * @tbl: the &struct bucket_table |
| 243 | * @hash: the hash value / bucket index |
| 244 | * @member: name of the &struct rhash_head within the hashable struct. |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 245 | * |
| 246 | * This hash chain list-traversal primitive allows for the looped code to |
| 247 | * remove the loop cursor from the list. |
| 248 | */ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 249 | #define rht_for_each_entry_safe(tpos, pos, next, tbl, hash, member) \ |
| 250 | for (pos = rht_dereference_bucket((tbl)->buckets[hash], tbl, hash), \ |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 251 | next = !rht_is_a_nulls(pos) ? \ |
| 252 | rht_dereference_bucket(pos->next, tbl, hash) : NULL; \ |
| 253 | (!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 254 | pos = next) |
| 255 | |
| 256 | /** |
| 257 | * rht_for_each_rcu_continue - continue iterating over rcu hash chain |
| 258 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 259 | * @head: the previous &struct rhash_head to continue from |
| 260 | * @tbl: the &struct bucket_table |
| 261 | * @hash: the hash value / bucket index |
| 262 | * |
| 263 | * This hash chain list-traversal primitive may safely run concurrently with |
| 264 | * the _rcu mutation primitives such as rhashtable_insert() as long as the |
| 265 | * traversal is guarded by rcu_read_lock(). |
| 266 | */ |
| 267 | #define rht_for_each_rcu_continue(pos, head, tbl, hash) \ |
| 268 | for (({barrier(); }), \ |
| 269 | pos = rht_dereference_bucket_rcu(head, tbl, hash); \ |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 270 | !rht_is_a_nulls(pos); \ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 271 | pos = rcu_dereference_raw(pos->next)) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * rht_for_each_rcu - iterate over rcu hash chain |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 275 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 276 | * @tbl: the &struct bucket_table |
| 277 | * @hash: the hash value / bucket index |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 278 | * |
| 279 | * This hash chain list-traversal primitive may safely run concurrently with |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 280 | * the _rcu mutation primitives such as rhashtable_insert() as long as the |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 281 | * traversal is guarded by rcu_read_lock(). |
| 282 | */ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 283 | #define rht_for_each_rcu(pos, tbl, hash) \ |
| 284 | rht_for_each_rcu_continue(pos, (tbl)->buckets[hash], tbl, hash) |
| 285 | |
| 286 | /** |
| 287 | * rht_for_each_entry_rcu_continue - continue iterating over rcu hash chain |
| 288 | * @tpos: the type * to use as a loop cursor. |
| 289 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 290 | * @head: the previous &struct rhash_head to continue from |
| 291 | * @tbl: the &struct bucket_table |
| 292 | * @hash: the hash value / bucket index |
| 293 | * @member: name of the &struct rhash_head within the hashable struct. |
| 294 | * |
| 295 | * This hash chain list-traversal primitive may safely run concurrently with |
| 296 | * the _rcu mutation primitives such as rhashtable_insert() as long as the |
| 297 | * traversal is guarded by rcu_read_lock(). |
| 298 | */ |
| 299 | #define rht_for_each_entry_rcu_continue(tpos, pos, head, tbl, hash, member) \ |
| 300 | for (({barrier(); }), \ |
| 301 | pos = rht_dereference_bucket_rcu(head, tbl, hash); \ |
Thomas Graf | f89bd6f | 2015-01-02 23:00:21 +0100 | [diff] [blame] | 302 | (!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 303 | pos = rht_dereference_bucket_rcu(pos->next, tbl, hash)) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * rht_for_each_entry_rcu - iterate over rcu hash chain of given type |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 307 | * @tpos: the type * to use as a loop cursor. |
| 308 | * @pos: the &struct rhash_head to use as a loop cursor. |
| 309 | * @tbl: the &struct bucket_table |
| 310 | * @hash: the hash value / bucket index |
| 311 | * @member: name of the &struct rhash_head within the hashable struct. |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 312 | * |
| 313 | * This hash chain list-traversal primitive may safely run concurrently with |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 314 | * the _rcu mutation primitives such as rhashtable_insert() as long as the |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 315 | * traversal is guarded by rcu_read_lock(). |
| 316 | */ |
Thomas Graf | 88d6ed1 | 2015-01-02 23:00:16 +0100 | [diff] [blame] | 317 | #define rht_for_each_entry_rcu(tpos, pos, tbl, hash, member) \ |
| 318 | rht_for_each_entry_rcu_continue(tpos, pos, (tbl)->buckets[hash],\ |
| 319 | tbl, hash, member) |
Thomas Graf | 7e1e776 | 2014-08-02 11:47:44 +0200 | [diff] [blame] | 320 | |
| 321 | #endif /* _LINUX_RHASHTABLE_H */ |