rculfhash: add unique
[urcu.git] / urcu / rculfhash.h
1 #ifndef _URCU_RCULFHASH_H
2 #define _URCU_RCULFHASH_H
3
4 #include <stdint.h>
5 #include <urcu-call-rcu.h>
6
7 struct rcu_ht_node {
8 struct rcu_ht_node *next;
9 void *key;
10 size_t key_len;
11 unsigned long hash;
12 unsigned long reverse_hash;
13 unsigned int dummy;
14 void *value;
15 struct rcu_head head;
16 };
17
18 struct rcu_ht;
19
20 /*
21 * Caution !
22 * Ensure reader and writer threads are registered as urcu readers.
23 */
24
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);
29
30 static inline
31 void ht_node_init(struct rcu_ht_node *node, void *key,
32 size_t key_len, void *value)
33 {
34 node->key = key;
35 node->key_len = key_len;
36 node->value = value;
37 node->dummy = 0;
38 }
39
40 /*
41 * init_size must be power of two.
42 */
43 struct rcu_ht *ht_new(ht_hash_fct hash_fct,
44 ht_compare_fct compare_fct,
45 unsigned long hash_seed,
46 unsigned long init_size,
47 void (*ht_call_rcu)(struct rcu_head *head,
48 void (*func)(struct rcu_head *head)));
49
50 int ht_destroy(struct rcu_ht *ht);
51
52 /* Call with rcu_read_lock held. */
53 struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
54
55 /* Call with rcu_read_lock held. */
56 void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
57
58 /* Call with rcu_read_lock held. */
59 int ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
60
61 /* Call with rcu_read_lock held. */
62 int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
63
64 void ht_resize(struct rcu_ht *ht, int growth);
65
66 #endif /* _URCU_RCULFHASH_H */
This page took 0.039952 seconds and 4 git commands to generate.