rculfhash: change order of node fields for locality
[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
7struct rcu_ht_node {
9b35f1e4 8 /* cache-hot for iteration */
abc490a1 9 struct rcu_ht_node *next;
abc490a1 10 unsigned long reverse_hash;
9b35f1e4
MD
11 void *key;
12 unsigned int key_len;
abc490a1 13 unsigned int dummy;
9b35f1e4
MD
14 /* cache-cold for iteration */
15 unsigned long hash;
abc490a1
MD
16 struct rcu_head head;
17};
18
19struct rcu_ht;
ab7d5fc6 20
5e28c532
MD
21/*
22 * Caution !
abc490a1 23 * Ensure reader and writer threads are registered as urcu readers.
5e28c532
MD
24 */
25
732ad076
MD
26typedef unsigned long (*ht_hash_fct)(void *key, size_t length,
27 unsigned long seed);
28typedef unsigned long (*ht_compare_fct)(void *key1, size_t key1_len,
29 void *key2, size_t key2_len);
abc490a1
MD
30
31static inline
732ad076 32void ht_node_init(struct rcu_ht_node *node, void *key,
cb233752 33 size_t key_len)
abc490a1
MD
34{
35 node->key = key;
732ad076 36 node->key_len = key_len;
abc490a1
MD
37 node->dummy = 0;
38}
674f7a69
MD
39
40/*
41 * init_size must be power of two.
42 */
abc490a1 43struct rcu_ht *ht_new(ht_hash_fct hash_fct,
732ad076
MD
44 ht_compare_fct compare_fct,
45 unsigned long hash_seed,
abc490a1
MD
46 unsigned long init_size,
47 void (*ht_call_rcu)(struct rcu_head *head,
48 void (*func)(struct rcu_head *head)));
ab7d5fc6 49
5e28c532 50int ht_destroy(struct rcu_ht *ht);
273399de
MD
51/* Count the number of nodes in the hash table. Call with rcu_read_lock held. */
52void ht_count_nodes(struct rcu_ht *ht,
53 unsigned long *count,
54 unsigned long *removed);
ab7d5fc6 55
abc490a1 56/* Call with rcu_read_lock held. */
732ad076 57struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
ab7d5fc6 58
abc490a1 59/* Call with rcu_read_lock held. */
f000907d 60void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
ab7d5fc6 61
3eca1b8c
MD
62/* Call with rcu_read_lock held. */
63int ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
64
abc490a1
MD
65/* Call with rcu_read_lock held. */
66int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
ab7d5fc6 67
464a1ec9
MD
68void ht_resize(struct rcu_ht *ht, int growth);
69
a42cc659 70#endif /* _URCU_RCULFHASH_H */
This page took 0.025325 seconds and 4 git commands to generate.