rculfhash: change order of node fields for locality
[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 unsigned long hash;
16 struct rcu_head head;
17};
18
19struct rcu_ht;
20
21/*
22 * Caution !
23 * Ensure reader and writer threads are registered as urcu readers.
24 */
25
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);
30
31static inline
32void ht_node_init(struct rcu_ht_node *node, void *key,
33 size_t key_len)
34{
35 node->key = key;
36 node->key_len = key_len;
37 node->dummy = 0;
38}
39
40/*
41 * init_size must be power of two.
42 */
43struct rcu_ht *ht_new(ht_hash_fct hash_fct,
44 ht_compare_fct compare_fct,
45 unsigned long hash_seed,
46 unsigned long init_size,
47 void (*ht_call_rcu)(struct rcu_head *head,
48 void (*func)(struct rcu_head *head)));
49
50int ht_destroy(struct rcu_ht *ht);
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);
55
56/* Call with rcu_read_lock held. */
57struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
58
59/* Call with rcu_read_lock held. */
60void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
61
62/* Call with rcu_read_lock held. */
63int ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
64
65/* Call with rcu_read_lock held. */
66int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
67
68void ht_resize(struct rcu_ht *ht, int growth);
69
70#endif /* _URCU_RCULFHASH_H */
This page took 0.022271 seconds and 4 git commands to generate.