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