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