Merge branch 'master' into urcu/ht
[urcu.git] / urcu / rculfhash.h
CommitLineData
a42cc659
MD
1#ifndef _URCU_RCULFHASH_H
2#define _URCU_RCULFHASH_H
ab7d5fc6 3
674f7a69 4#include <stdint.h>
abc490a1
MD
5#include <urcu-call-rcu.h>
6
01389791
MD
7#ifdef __cplusplus
8extern "C" {
9#endif
10
7f61a77f
MD
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
cc4fcb10 16struct _rcu_ht_node {
d95bd160 17 struct rcu_ht_node *next; /* ptr | DUMMY_FLAG | REMOVED_FLAG */
abc490a1 18 unsigned long reverse_hash;
cc4fcb10
MD
19};
20
21struct rcu_ht_node {
22 /* cache-hot for iteration */
23 struct _rcu_ht_node p; /* needs to be first field */
9b35f1e4
MD
24 void *key;
25 unsigned int key_len;
9b35f1e4 26 /* cache-cold for iteration */
abc490a1
MD
27 struct rcu_head head;
28};
29
30struct rcu_ht;
ab7d5fc6 31
5e28c532
MD
32/*
33 * Caution !
abc490a1 34 * Ensure reader and writer threads are registered as urcu readers.
5e28c532
MD
35 */
36
732ad076
MD
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);
abc490a1
MD
41
42static inline
732ad076 43void ht_node_init(struct rcu_ht_node *node, void *key,
cb233752 44 size_t key_len)
abc490a1
MD
45{
46 node->key = key;
732ad076 47 node->key_len = key_len;
abc490a1 48}
674f7a69
MD
49
50/*
51 * init_size must be power of two.
52 */
abc490a1 53struct rcu_ht *ht_new(ht_hash_fct hash_fct,
732ad076
MD
54 ht_compare_fct compare_fct,
55 unsigned long hash_seed,
abc490a1
MD
56 unsigned long init_size,
57 void (*ht_call_rcu)(struct rcu_head *head,
58 void (*func)(struct rcu_head *head)));
ab7d5fc6 59
5e28c532 60int ht_destroy(struct rcu_ht *ht);
273399de
MD
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);
ab7d5fc6 65
abc490a1 66/* Call with rcu_read_lock held. */
732ad076 67struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
ab7d5fc6 68
abc490a1 69/* Call with rcu_read_lock held. */
f000907d 70void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
ab7d5fc6 71
18117871
MD
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);
3eca1b8c 79
abc490a1
MD
80/* Call with rcu_read_lock held. */
81int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
ab7d5fc6 82
464a1ec9
MD
83void ht_resize(struct rcu_ht *ht, int growth);
84
01389791
MD
85#ifdef __cplusplus
86}
87#endif
88
a42cc659 89#endif /* _URCU_RCULFHASH_H */
This page took 0.026406 seconds and 4 git commands to generate.