Merge branch 'master' into urcu/ht
[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
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/*
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.
14 */
15
16struct _rcu_ht_node {
17 struct rcu_ht_node *next; /* ptr | DUMMY_FLAG | REMOVED_FLAG */
18 unsigned long reverse_hash;
19};
20
21struct rcu_ht_node {
22 /* cache-hot for iteration */
23 struct _rcu_ht_node p; /* needs to be first field */
24 void *key;
25 unsigned int key_len;
26 /* cache-cold for iteration */
27 struct rcu_head head;
28};
29
30struct rcu_ht;
31
32/*
33 * Caution !
34 * Ensure reader and writer threads are registered as urcu readers.
35 */
36
37typedef unsigned long (*ht_hash_fct)(void *key, size_t length,
38 unsigned long seed);
39typedef unsigned long (*ht_compare_fct)(void *key1, size_t key1_len,
40 void *key2, size_t key2_len);
41
42static inline
43void ht_node_init(struct rcu_ht_node *node, void *key,
44 size_t key_len)
45{
46 node->key = key;
47 node->key_len = key_len;
48}
49
50/*
51 * init_size must be power of two.
52 */
53struct 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)));
59
60int ht_destroy(struct rcu_ht *ht);
61/* Count the number of nodes in the hash table. Call with rcu_read_lock held. */
62void ht_count_nodes(struct rcu_ht *ht,
63 unsigned long *count,
64 unsigned long *removed);
65
66/* Call with rcu_read_lock held. */
67struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
68
69/* Call with rcu_read_lock held. */
70void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
71
72/*
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.
77 */
78struct rcu_ht_node *ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
79
80/* Call with rcu_read_lock held. */
81int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
82
83void ht_resize(struct rcu_ht *ht, int growth);
84
85#ifdef __cplusplus
86}
87#endif
88
89#endif /* _URCU_RCULFHASH_H */
This page took 0.022242 seconds and 4 git commands to generate.