Commit | Line | Data |
---|---|---|
a42cc659 MD |
1 | #ifndef _URCU_RCULFHASH_H |
2 | #define _URCU_RCULFHASH_H | |
ab7d5fc6 | 3 | |
674f7a69 | 4 | #include <stdint.h> |
abc490a1 MD |
5 | #include <urcu-call-rcu.h> |
6 | ||
7 | struct rcu_ht_node { | |
9b35f1e4 | 8 | /* cache-hot for iteration */ |
abc490a1 | 9 | struct rcu_ht_node *next; |
abc490a1 | 10 | unsigned long reverse_hash; |
9b35f1e4 MD |
11 | void *key; |
12 | unsigned int key_len; | |
abc490a1 | 13 | unsigned int dummy; |
9b35f1e4 | 14 | /* cache-cold for iteration */ |
abc490a1 MD |
15 | struct rcu_head head; |
16 | }; | |
17 | ||
18 | struct rcu_ht; | |
ab7d5fc6 | 19 | |
5e28c532 MD |
20 | /* |
21 | * Caution ! | |
abc490a1 | 22 | * Ensure reader and writer threads are registered as urcu readers. |
5e28c532 MD |
23 | */ |
24 | ||
732ad076 MD |
25 | typedef unsigned long (*ht_hash_fct)(void *key, size_t length, |
26 | unsigned long seed); | |
27 | typedef unsigned long (*ht_compare_fct)(void *key1, size_t key1_len, | |
28 | void *key2, size_t key2_len); | |
abc490a1 MD |
29 | |
30 | static inline | |
732ad076 | 31 | void ht_node_init(struct rcu_ht_node *node, void *key, |
cb233752 | 32 | size_t key_len) |
abc490a1 MD |
33 | { |
34 | node->key = key; | |
732ad076 | 35 | node->key_len = key_len; |
abc490a1 MD |
36 | node->dummy = 0; |
37 | } | |
674f7a69 MD |
38 | |
39 | /* | |
40 | * init_size must be power of two. | |
41 | */ | |
abc490a1 | 42 | struct rcu_ht *ht_new(ht_hash_fct hash_fct, |
732ad076 MD |
43 | ht_compare_fct compare_fct, |
44 | unsigned long hash_seed, | |
abc490a1 MD |
45 | unsigned long init_size, |
46 | void (*ht_call_rcu)(struct rcu_head *head, | |
47 | void (*func)(struct rcu_head *head))); | |
ab7d5fc6 | 48 | |
5e28c532 | 49 | int ht_destroy(struct rcu_ht *ht); |
273399de MD |
50 | /* Count the number of nodes in the hash table. Call with rcu_read_lock held. */ |
51 | void ht_count_nodes(struct rcu_ht *ht, | |
52 | unsigned long *count, | |
53 | unsigned long *removed); | |
ab7d5fc6 | 54 | |
abc490a1 | 55 | /* Call with rcu_read_lock held. */ |
732ad076 | 56 | struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len); |
ab7d5fc6 | 57 | |
abc490a1 | 58 | /* Call with rcu_read_lock held. */ |
f000907d | 59 | void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node); |
ab7d5fc6 | 60 | |
18117871 MD |
61 | /* |
62 | * Call with rcu_read_lock held. | |
63 | * Returns the node added upon success. | |
64 | * Returns the unique node already present upon failure. If ht_add_unique fails, | |
65 | * the node passed as parameter should be freed by the caller. | |
66 | */ | |
67 | struct rcu_ht_node *ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node); | |
3eca1b8c | 68 | |
abc490a1 MD |
69 | /* Call with rcu_read_lock held. */ |
70 | int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node); | |
ab7d5fc6 | 71 | |
464a1ec9 MD |
72 | void ht_resize(struct rcu_ht *ht, int growth); |
73 | ||
a42cc659 | 74 | #endif /* _URCU_RCULFHASH_H */ |