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