- fix iteration on entirely filled uint64_t keyspace: we need to reserve
UINT64_MAX as end-of-iteration marker.
- fix linear lookups below/above or equal: should not re-read the
pointer.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
uint8_t nr_child;
uint8_t *values;
struct cds_ja_inode_flag **pointers;
uint8_t nr_child;
uint8_t *values;
struct cds_ja_inode_flag **pointers;
- struct cds_ja_inode_flag *ptr = NULL;
+ struct cds_ja_inode_flag *ptr, *match_ptr = NULL;
- int match_idx = -1, match_v;
assert(type->type_class == RCU_JA_LINEAR || type->type_class == RCU_JA_POOL);
assert(dir == JA_LEFT || dir == JA_RIGHT);
assert(type->type_class == RCU_JA_LINEAR || type->type_class == RCU_JA_POOL);
assert(dir == JA_LEFT || dir == JA_RIGHT);
if (dir == JA_LEFT) {
if ((int) v < n && (int) v > match_v) {
match_v = v;
if (dir == JA_LEFT) {
if ((int) v < n && (int) v > match_v) {
match_v = v;
}
} else {
if ((int) v > n && (int) v < match_v) {
match_v = v;
}
} else {
if ((int) v > n && (int) v < match_v) {
match_v = v;
return NULL;
}
assert(match_v >= 0 && match_v < JA_ENTRY_PER_NODE);
*result_key = (uint8_t) match_v;
return NULL;
}
assert(match_v >= 0 && match_v < JA_ENTRY_PER_NODE);
*result_key = (uint8_t) match_v;
- ptr = rcu_dereference(pointers[match_idx]);
- return ptr;
unsigned int tree_depth, i;
struct cds_ja_inode_flag *node_flag;
unsigned int tree_depth, i;
struct cds_ja_inode_flag *node_flag;
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return NULL;
tree_depth = ja->tree_depth;
node_flag = rcu_dereference(ja->root);
return NULL;
tree_depth = ja->tree_depth;
node_flag = rcu_dereference(ja->root);
switch (mode) {
case JA_LOOKUP_BE:
switch (mode) {
case JA_LOOKUP_BE:
- if (caa_unlikely(key > ja->key_max))
- return NULL;
- break;
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return NULL;
break;
default:
return NULL;
break;
default:
**node_flag_ptr;
int ret;
**node_flag_ptr;
int ret;
- if (caa_unlikely(key > ja->key_max)) {
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX)) {
return -EINVAL;
}
tree_depth = ja->tree_depth;
return -EINVAL;
}
tree_depth = ja->tree_depth;
int nr_snapshot;
int ret;
int nr_snapshot;
int ret;
- if (caa_unlikely(key > ja->key_max))
+ if (caa_unlikely(key > ja->key_max || key == UINT64_MAX))
return -EINVAL;
tree_depth = ja->tree_depth;
return -EINVAL;
tree_depth = ja->tree_depth;
+/*
+ * Note: key UINT64_MAX is reserved internally for iteration.
+ */
+
/*
* cds_ja_lookup - look up by key.
* @ja: the Judy array.
/*
* cds_ja_lookup - look up by key.
* @ja: the Judy array.
*/
#define cds_ja_for_each_key_rcu(ja, key, pos) \
for ((key) = 0; \
*/
#define cds_ja_for_each_key_rcu(ja, key, pos) \
for ((key) = 0; \
- ((pos) = cds_ja_lookup_above_equal(ja, key, &(key))); )
+ ((key) != UINT64_MAX ? \
+ ((pos) = cds_ja_lookup_above_equal(ja, key, &(key))) : 0); \
+ (key)++)
/*
* cds_ja_for_each_key_prev_rcu: Iterate over all keys in descending order.
/*
* cds_ja_for_each_key_prev_rcu: Iterate over all keys in descending order.
* Safe against node removal during iteration.
*/
#define cds_ja_for_each_key_prev_rcu(ja, key, pos) \
* Safe against node removal during iteration.
*/
#define cds_ja_for_each_key_prev_rcu(ja, key, pos) \
- for ((key) = UINT64_MAX; \
- ((pos) = cds_ja_lookup_below_equal(ja, key, &(key))); )
+ for ((key) = UINT64_MAX - 1; \
+ ((key) != UINT64_MAX ? \
+ ((pos) = cds_ja_lookup_below_equal(ja, key, &(key))) : 0); \
+ (key)--)