1 #ifndef _URCU_RCULFHASH_H
2 #define _URCU_RCULFHASH_H
5 #include <urcu-call-rcu.h>
12 * struct rcu_ht_node and struct _rcu_ht_node should be aligned on
13 * 4-bytes boundaries because the two lower bits are used as flags.
17 struct rcu_ht_node
*next
; /* ptr | DUMMY_FLAG | REMOVED_FLAG */
18 unsigned long reverse_hash
;
22 /* cache-hot for iteration */
23 struct _rcu_ht_node p
; /* needs to be first field */
26 /* cache-cold for iteration */
34 * Ensure reader and writer threads are registered as urcu readers.
37 typedef unsigned long (*ht_hash_fct
)(void *key
, size_t length
,
39 typedef unsigned long (*ht_compare_fct
)(void *key1
, size_t key1_len
,
40 void *key2
, size_t key2_len
);
43 void ht_node_init(struct rcu_ht_node
*node
, void *key
,
47 node
->key_len
= key_len
;
51 * init_size must be power of two.
53 struct rcu_ht
*ht_new(ht_hash_fct hash_fct
,
54 ht_compare_fct compare_fct
,
55 unsigned long hash_seed
,
56 unsigned long init_size
,
57 void (*ht_call_rcu
)(struct rcu_head
*head
,
58 void (*func
)(struct rcu_head
*head
)));
60 int ht_destroy(struct rcu_ht
*ht
);
61 /* Count the number of nodes in the hash table. Call with rcu_read_lock held. */
62 void ht_count_nodes(struct rcu_ht
*ht
,
64 unsigned long *removed
);
66 /* Call with rcu_read_lock held. */
67 struct rcu_ht_node
*ht_lookup(struct rcu_ht
*ht
, void *key
, size_t key_len
);
69 /* Call with rcu_read_lock held. */
70 void ht_add(struct rcu_ht
*ht
, struct rcu_ht_node
*node
);
73 * Call with rcu_read_lock held.
74 * Returns the node added upon success.
75 * Returns the unique node already present upon failure. If ht_add_unique fails,
76 * the node passed as parameter should be freed by the caller.
78 struct rcu_ht_node
*ht_add_unique(struct rcu_ht
*ht
, struct rcu_ht_node
*node
);
80 /* Call with rcu_read_lock held. */
81 int ht_remove(struct rcu_ht
*ht
, struct rcu_ht_node
*node
);
83 void ht_resize(struct rcu_ht
*ht
, int growth
);
89 #endif /* _URCU_RCULFHASH_H */