7 * Userspace RCU library - RCU Judy Array
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
25 * Include this file _after_ including your URCU flavor.
29 #include <urcu/compiler.h>
30 #include <urcu-call-rcu.h>
31 #include <urcu-flavor.h>
33 #include <urcu/rcuhlist.h>
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.
44 struct cds_ja_node
*next
;
50 * cds_ja_node_init - initialize a judy array node
51 * @node: the node to initialize.
53 * This function is kept to be eventually used for debugging purposes
54 * (detection of memory corruption).
57 void cds_ja_node_init(struct cds_ja_node
*node
)
62 * cds_ja_lookup - look up by key.
63 * @ja: the Judy array.
64 * @key: key to look up.
66 * Returns the first node of a duplicate chain if a match is found, else
68 * A RCU read-side lock should be held across call to this function and
69 * use of its return value.
71 struct cds_ja_node
*cds_ja_lookup(struct cds_ja
*ja
, uint64_t key
);
74 * cds_ja_lookup_below_equal - look up first node with key <= @key.
75 * @ja: the Judy array.
76 * @key: key to look up.
77 * @result_key: key found.
79 * Returns the first node of a duplicate chain if a node is present in
80 * the tree which has a key below or equal to @key, else returns NULL.
81 * A RCU read-side lock should be held across call to this function and
82 * use of its return value.
84 struct cds_ja_node
*cds_ja_lookup_below_equal(struct cds_ja
*ja
,
85 uint64_t key
, uint64_t *result_key
);
88 * cds_ja_lookup_above_equal - look up first node with key >= @key.
89 * @ja: the Judy array.
90 * @key: key to look up.
91 * @result_key: key found.
93 * Returns the first node of a duplicate chain if a node is present in
94 * the tree which has a key above or equal to @key, else returns NULL.
95 * A RCU read-side lock should be held across call to this function and
96 * use of its return value.
98 struct cds_ja_node
*cds_ja_lookup_above_equal(struct cds_ja
*ja
,
99 uint64_t key
, uint64_t *result_key
);
102 * cds_ja_add - Add @node at @key, allowing duplicates.
103 * @ja: the Judy array.
104 * @key: key at which @node should be added.
105 * @node: node to add.
107 * Returns 0 on success, negative error value on error.
108 * A RCU read-side lock should be held across call to this function.
110 int cds_ja_add(struct cds_ja
*ja
, uint64_t key
,
111 struct cds_ja_node
*node
);
114 * cds_ja_add_unique - Add @node at @key, without duplicates.
115 * @ja: the Judy array.
116 * @key: key at which @node should be added.
117 * @node: node to add.
119 * Returns @node if successfully added, else returns the already
120 * existing node (acts as a RCU lookup).
121 * A RCU read-side lock should be held across call to this function and
122 * use of its return value.
124 struct cds_ja_node
*cds_ja_add_unique(struct cds_ja
*ja
, uint64_t key
,
125 struct cds_ja_node
*node
);
128 * cds_ja_del - Remove @node at @key.
129 * @ja: the Judy array.
130 * @key: key at which @node is expected.
131 * @node: node to remove.
133 * Returns 0 on success, negative error value on error.
134 * A RCU read-side lock should be held across call to this function.
136 int cds_ja_del(struct cds_ja
*ja
, uint64_t key
,
137 struct cds_ja_node
*node
);
139 struct cds_ja
*_cds_ja_new(unsigned int key_bits
,
140 const struct rcu_flavor_struct
*flavor
);
143 * cds_ja_new - Create a Judy array.
144 * @key_bits: Number of bits for key.
146 * Returns non-NULL pointer on success, else NULL on error. @key_bits
147 * needs to be multiple of 8, either: 8, 16, 24, 32, 40, 48, 56, or 64.
150 struct cds_ja
*cds_ja_new(unsigned int key_bits
)
152 return _cds_ja_new(key_bits
, &rcu_flavor
);
156 * cds_ja_destroy - Destroy a Judy array.
157 * @ja: the Judy array.
158 * @rcu_free_node_cb: callback performing memory free of leftover nodes.
160 * Returns 0 on success, negative error value on error.
161 * There should be no more concurrent add, delete, nor look-up performed
162 * on the Judy array while it is being destroyed (ensured by the caller).
163 * There is no need for the @rcu_free_node_cb callback to wait for grace
164 * periods, since there are no more concurrent users of the Judy array.
165 * RCU read-side lock should _not_ be held when calling this function,
166 * however, QSBR threads need to be online.
168 int cds_ja_destroy(struct cds_ja
*ja
,
169 void (*free_node_cb
)(struct cds_ja_node
*node
));
172 * Iterate through duplicates returned by cds_ja_lookup*()
173 * This must be done while rcu_read_lock() is held.
174 * Receives a struct cds_ja_node * as parameter, which is used as start
175 * of duplicate list and loop cursor.
177 #define cds_ja_for_each_duplicate_rcu(pos) \
178 for (; (pos) != NULL; (pos) = rcu_dereference((pos)->next))
184 #endif /* _URCU_RCUJA_H */
This page took 0.032995 seconds and 4 git commands to generate.