rcuja: rename new_node to node in add functions
[userspace-rcu.git] / urcu / rcuja.h
CommitLineData
d553beef
MD
1#ifndef _URCU_RCUJA_H
2#define _URCU_RCUJA_H
3
4/*
5 * urcu/rcuja.h
6 *
7 * Userspace RCU library - RCU Judy Array
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Include this file _after_ including your URCU flavor.
26 */
27
28#include <stdint.h>
29#include <urcu/compiler.h>
30#include <urcu-call-rcu.h>
31#include <urcu-flavor.h>
32#include <stdint.h>
33#include <urcu/rcuhlist.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
03ec1aeb
MD
39/*
40 * Duplicate nodes with the same key are chained into a singly-linked
41 * list. The last item of this list has a NULL next pointer.
42 */
d553beef 43struct cds_ja_node {
03ec1aeb 44 struct cds_ja_node *next;
d553beef
MD
45};
46
47struct cds_ja;
48
49/*
50 * cds_ja_node_init - initialize a judy array node
51 * @node: the node to initialize.
52 *
53 * This function is kept to be eventually used for debugging purposes
54 * (detection of memory corruption).
55 */
56static inline
57void cds_ja_node_init(struct cds_ja_node *node)
58{
59}
60
b41da4d1
MD
61/*
62 * cds_ja_lookup - look up by key.
63 * @ja: the Judy array.
64 * @key: key to look up.
65 *
66 * Returns the first node of a duplicate chain if a match is found, else
67 * returns NULL.
68 * A RCU read-side lock should be held across call to this function and
69 * use of its return value.
70 */
03ec1aeb 71struct cds_ja_node *cds_ja_lookup(struct cds_ja *ja, uint64_t key);
b41da4d1
MD
72
73/*
74 * cds_ja_lookup_lower_equal - look up first node with key <= @key.
75 * @ja: the Judy array.
76 * @key: key to look up.
77 *
78 * Returns the first node of a duplicate chain if a node is present in
79 * the tree which has a key lower or equal to @key, else returns NULL.
80 * A RCU read-side lock should be held across call to this function and
81 * use of its return value.
82 */
03ec1aeb 83struct cds_ja_node *cds_ja_lookup_lower_equal(struct cds_ja *ja,
291b2543 84 uint64_t key);
d553beef
MD
85
86int cds_ja_add(struct cds_ja *ja, uint64_t key,
87 struct cds_ja_node *new_node);
88
75d573aa
MD
89struct cds_ja_node *cds_ja_add_unique(struct cds_ja *ja, uint64_t key,
90 struct cds_ja_node *new_node);
91
d553beef
MD
92int cds_ja_del(struct cds_ja *ja, uint64_t key,
93 struct cds_ja_node *node);
94
95struct cds_ja *_cds_ja_new(unsigned int key_bits,
96 const struct rcu_flavor_struct *flavor);
97
98static inline
99struct cds_ja *cds_ja_new(unsigned int key_bits)
100{
101 return _cds_ja_new(key_bits, &rcu_flavor);
102}
103
104int cds_ja_destroy(struct cds_ja *ja,
21ac4c56 105 void (*rcu_free_node_cb)(struct cds_ja_node *node));
d553beef 106
03ec1aeb
MD
107/*
108 * Iterate through duplicates returned by cds_ja_lookup*()
109 * This must be done while rcu_read_lock() is held.
110 * Receives a struct cds_ja_node * as parameter, which is used as start
111 * of duplicate list and loop cursor.
112 */
113#define cds_ja_for_each_duplicate_rcu(pos) \
114 for (; (pos) != NULL; (pos) = rcu_dereference((pos)->next))
115
d553beef
MD
116#ifdef __cplusplus
117}
118#endif
119
120#endif /* _URCU_RCUJA_H */
This page took 0.026158 seconds and 4 git commands to generate.