421e8388eb563112c894d6897b6e990d1e772911
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_lower_equal - look up first node with key <= @key.
75 * @ja: the Judy array.
76 * @key: key to look up.
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.
83 struct cds_ja_node
*cds_ja_lookup_lower_equal(struct cds_ja
*ja
,
87 * cds_ja_add - Add @node at @key, allowing duplicates.
88 * @ja: the Judy array.
89 * @key: key at which @node should be added.
92 * Returns 0 on success, negative error value on error.
93 * A RCU read-side lock should be held across call to this function.
95 int cds_ja_add(struct cds_ja
*ja
, uint64_t key
,
96 struct cds_ja_node
*node
);
99 * cds_ja_add_unique - Add @node at @key, without duplicates.
100 * @ja: the Judy array.
101 * @key: key at which @node should be added.
102 * @node: node to add.
104 * Returns @node if successfully added, else returns the already
105 * existing node (acts as a RCU lookup).
106 * A RCU read-side lock should be held across call to this function and
107 * use of its return value.
109 struct cds_ja_node
*cds_ja_add_unique(struct cds_ja
*ja
, uint64_t key
,
110 struct cds_ja_node
*node
);
113 * cds_ja_del - Remove @node at @key.
114 * @ja: the Judy array.
115 * @key: key at which @node is expected.
116 * @node: node to remove.
118 * Returns 0 on success, negative error value on error.
119 * A RCU read-side lock should be held across call to this function.
121 int cds_ja_del(struct cds_ja
*ja
, uint64_t key
,
122 struct cds_ja_node
*node
);
124 struct cds_ja
*_cds_ja_new(unsigned int key_bits
,
125 const struct rcu_flavor_struct
*flavor
);
128 * cds_ja_new - Create a Judy array.
129 * @key_bits: Number of bits for key.
131 * Returns non-NULL pointer on success, else NULL on error. @key_bits
132 * needs to be multiple of 8, either: 8, 16, 24, 32, 40, 48, 56, or 64.
135 struct cds_ja
*cds_ja_new(unsigned int key_bits
)
137 return _cds_ja_new(key_bits
, &rcu_flavor
);
141 * cds_ja_destroy - Destroy a Judy array.
142 * @ja: the Judy array.
143 * @rcu_free_node_cb: callback performing memory free of leftover nodes.
145 * Returns 0 on success, negative error value on error.
146 * There should be no more concurrent add, delete, nor look-up performed
147 * on the Judy array while it is being destroyed (ensured by the caller).
148 * There is no need for the @rcu_free_node_cb callback to wait for grace
149 * periods, since there are no more concurrent users of the Judy array.
151 int cds_ja_destroy(struct cds_ja
*ja
,
152 void (*free_node_cb
)(struct cds_ja_node
*node
));
155 * Iterate through duplicates returned by cds_ja_lookup*()
156 * This must be done while rcu_read_lock() is held.
157 * Receives a struct cds_ja_node * as parameter, which is used as start
158 * of duplicate list and loop cursor.
160 #define cds_ja_for_each_duplicate_rcu(pos) \
161 for (; (pos) != NULL; (pos) = rcu_dereference((pos)->next))
167 #endif /* _URCU_RCUJA_H */
This page took 0.050259 seconds and 4 git commands to generate.