rculfhash: merge node gc into add loop
[urcu.git] / urcu / rculfhash.h
... / ...
CommitLineData
1#ifndef _URCU_RCULFHASH_H
2#define _URCU_RCULFHASH_H
3
4#include <stdint.h>
5#include <urcu-call-rcu.h>
6
7struct 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 struct rcu_head head;
15};
16
17struct rcu_ht;
18
19/*
20 * Caution !
21 * Ensure reader and writer threads are registered as urcu readers.
22 */
23
24typedef unsigned long (*ht_hash_fct)(void *key, size_t length,
25 unsigned long seed);
26typedef unsigned long (*ht_compare_fct)(void *key1, size_t key1_len,
27 void *key2, size_t key2_len);
28
29static inline
30void ht_node_init(struct rcu_ht_node *node, void *key,
31 size_t key_len)
32{
33 node->key = key;
34 node->key_len = key_len;
35 node->dummy = 0;
36}
37
38/*
39 * init_size must be power of two.
40 */
41struct rcu_ht *ht_new(ht_hash_fct hash_fct,
42 ht_compare_fct compare_fct,
43 unsigned long hash_seed,
44 unsigned long init_size,
45 void (*ht_call_rcu)(struct rcu_head *head,
46 void (*func)(struct rcu_head *head)));
47
48int ht_destroy(struct rcu_ht *ht);
49/* Count the number of nodes in the hash table. Call with rcu_read_lock held. */
50void ht_count_nodes(struct rcu_ht *ht,
51 unsigned long *count,
52 unsigned long *removed);
53
54/* Call with rcu_read_lock held. */
55struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
56
57/* Call with rcu_read_lock held. */
58void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
59
60/* Call with rcu_read_lock held. */
61int ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
62
63/* Call with rcu_read_lock held. */
64int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
65
66void ht_resize(struct rcu_ht *ht, int growth);
67
68#endif /* _URCU_RCULFHASH_H */
This page took 0.02966 seconds and 4 git commands to generate.