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