Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts: import more hash table macros

Add more macros used for removing hash table entries.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+119
+50
scripts/include/hashtable.h
··· 15 15 16 16 #define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)]) 17 17 18 + static inline void __hash_init(struct hlist_head *ht, unsigned int sz) 19 + { 20 + unsigned int i; 21 + 22 + for (i = 0; i < sz; i++) 23 + INIT_HLIST_HEAD(&ht[i]); 24 + } 25 + 26 + /** 27 + * hash_init - initialize a hash table 28 + * @table: hashtable to be initialized 29 + * 30 + * This has to be a macro since HASH_SIZE() will not work on pointers since 31 + * it calculates the size during preprocessing. 32 + */ 33 + #define hash_init(table) __hash_init(table, HASH_SIZE(table)) 34 + 18 35 /** 19 36 * hash_add - add an object to a hashtable 20 37 * @table: hashtable to add to ··· 40 23 */ 41 24 #define hash_add(table, node, key) \ 42 25 hlist_add_head(node, hash_head(table, key)) 26 + 27 + /** 28 + * hash_del - remove an object from a hashtable 29 + * @node: &struct hlist_node of the object to remove 30 + */ 31 + static inline void hash_del(struct hlist_node *node) 32 + { 33 + hlist_del_init(node); 34 + } 43 35 44 36 /** 45 37 * hash_for_each - iterate over a hashtable ··· 61 35 hlist_for_each_entry(obj, &table[_bkt], member) 62 36 63 37 /** 38 + * hash_for_each_safe - iterate over a hashtable safe against removal of 39 + * hash entry 40 + * @table: hashtable to iterate 41 + * @obj: the type * to use as a loop cursor for each entry 42 + * @tmp: a &struct hlist_node used for temporary storage 43 + * @member: the name of the hlist_node within the struct 44 + */ 45 + #define hash_for_each_safe(table, obj, tmp, member) \ 46 + for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \ 47 + hlist_for_each_entry_safe(obj, tmp, &table[_bkt], member) 48 + 49 + /** 64 50 * hash_for_each_possible - iterate over all possible objects hashing to the 65 51 * same bucket 66 52 * @table: hashtable to iterate ··· 82 44 */ 83 45 #define hash_for_each_possible(table, obj, member, key) \ 84 46 hlist_for_each_entry(obj, hash_head(table, key), member) 47 + 48 + /** 49 + * hash_for_each_possible_safe - iterate over all possible objects hashing to the 50 + * same bucket safe against removals 51 + * @table: hashtable to iterate 52 + * @obj: the type * to use as a loop cursor for each entry 53 + * @tmp: a &struct hlist_node used for temporary storage 54 + * @member: the name of the hlist_node within the struct 55 + * @key: the key of the objects to iterate over 56 + */ 57 + #define hash_for_each_possible_safe(table, obj, tmp, member, key) \ 58 + hlist_for_each_entry_safe(obj, tmp, hash_head(table, key), member) 85 59 86 60 #endif /* HASHTABLE_H */
+69
scripts/include/list.h
··· 268 268 */ 269 269 270 270 #define HLIST_HEAD_INIT { .first = NULL } 271 + #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) 272 + static inline void INIT_HLIST_NODE(struct hlist_node *h) 273 + { 274 + h->next = NULL; 275 + h->pprev = NULL; 276 + } 277 + 278 + /** 279 + * hlist_unhashed - Has node been removed from list and reinitialized? 280 + * @h: Node to be checked 281 + * 282 + * Not that not all removal functions will leave a node in unhashed 283 + * state. For example, hlist_nulls_del_init_rcu() does leave the 284 + * node in unhashed state, but hlist_nulls_del() does not. 285 + */ 286 + static inline int hlist_unhashed(const struct hlist_node *h) 287 + { 288 + return !h->pprev; 289 + } 290 + 291 + static inline void __hlist_del(struct hlist_node *n) 292 + { 293 + struct hlist_node *next = n->next; 294 + struct hlist_node **pprev = n->pprev; 295 + 296 + *pprev = next; 297 + if (next) 298 + next->pprev = pprev; 299 + } 300 + 301 + /** 302 + * hlist_del - Delete the specified hlist_node from its list 303 + * @n: Node to delete. 304 + * 305 + * Note that this function leaves the node in hashed state. Use 306 + * hlist_del_init() or similar instead to unhash @n. 307 + */ 308 + static inline void hlist_del(struct hlist_node *n) 309 + { 310 + __hlist_del(n); 311 + n->next = LIST_POISON1; 312 + n->pprev = LIST_POISON2; 313 + } 314 + 315 + /** 316 + * hlist_del_init - Delete the specified hlist_node from its list and initialize 317 + * @n: Node to delete. 318 + * 319 + * Note that this function leaves the node in unhashed state. 320 + */ 321 + static inline void hlist_del_init(struct hlist_node *n) 322 + { 323 + if (!hlist_unhashed(n)) { 324 + __hlist_del(n); 325 + INIT_HLIST_NODE(n); 326 + } 327 + } 271 328 272 329 /** 273 330 * hlist_add_head - add a new entry at the beginning of the hlist ··· 362 305 for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ 363 306 pos; \ 364 307 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) 308 + 309 + /** 310 + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry 311 + * @pos: the type * to use as a loop cursor. 312 + * @n: a &struct hlist_node to use as temporary storage 313 + * @head: the head for your list. 314 + * @member: the name of the hlist_node within the struct. 315 + */ 316 + #define hlist_for_each_entry_safe(pos, n, head, member) \ 317 + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ 318 + pos && ({ n = pos->member.next; 1; }); \ 319 + pos = hlist_entry_safe(n, typeof(*pos), member)) 365 320 366 321 #endif /* LIST_H */