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