X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=rculfhash.c;h=72abe40f9ae7eb49dc8586c5cde4396e7f4aacba;hb=743f9143d0dce4b1385531577ebf702f119576ef;hp=b9c184fcc5f22e0e3043dd7f8b2c8a3ad2f6756f;hpb=83beee94416bdffdec505bc33cfd79859f6aa243;p=urcu.git diff --git a/rculfhash.c b/rculfhash.c index b9c184f..72abe40 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -748,6 +748,7 @@ void _cds_lfht_gc_bucket(struct cds_lfht_node *dummy, struct cds_lfht_node *node iter_prev = dummy; /* We can always skip the dummy node initially */ iter = rcu_dereference(iter_prev->p.next); + assert(!is_removed(iter)); assert(iter_prev->p.reverse_hash <= node->p.reverse_hash); /* * We should never be called with dummy (start of chain) @@ -772,8 +773,6 @@ void _cds_lfht_gc_bucket(struct cds_lfht_node *dummy, struct cds_lfht_node *node new_next = flag_dummy(clear_flag(next)); else new_next = clear_flag(next); - if (is_removed(iter)) - new_next = flag_removed(new_next); (void) uatomic_cmpxchg(&iter_prev->p.next, iter, new_next); } return; @@ -787,10 +786,9 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, { struct cds_lfht_node *dummy, *ret_next; struct _cds_lfht_node *lookup; - int flagged = 0; if (!old_node) /* Return -ENOENT if asked to replace NULL node */ - goto end; + return -ENOENT; assert(!is_removed(old_node)); assert(!is_dummy(old_node)); @@ -804,7 +802,7 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, * Too late, the old node has been removed under us * between lookup and replace. Fail. */ - goto end; + return -ENOENT; } assert(!is_dummy(old_next)); assert(new_node != clear_flag(old_next)); @@ -822,13 +820,10 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, ret_next = uatomic_cmpxchg(&old_node->p.next, old_next, flag_removed(new_node)); if (ret_next == old_next) - break; + break; /* We performed the replacement. */ old_next = ret_next; } - /* We performed the replacement. */ - flagged = 1; - /* * Ensure that the old node is not visible to readers anymore: * lookup for the node, and remove it (along with any other @@ -837,17 +832,9 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, lookup = lookup_bucket(ht, size, bit_reverse_ulong(old_node->p.reverse_hash)); dummy = (struct cds_lfht_node *) lookup; _cds_lfht_gc_bucket(dummy, new_node); -end: - /* - * Only the flagging action indicated that we (and no other) - * replaced the node from the hash table. - */ - if (flagged) { - assert(is_removed(rcu_dereference(old_node->p.next))); - return 0; - } else { - return -ENOENT; - } + + assert(is_removed(rcu_dereference(old_node->p.next))); + return 0; } /* @@ -958,10 +945,9 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, { struct cds_lfht_node *dummy, *next, *old; struct _cds_lfht_node *lookup; - int flagged = 0; if (!node) /* Return -ENOENT if asked to delete NULL node */ - goto end; + return -ENOENT; /* logically delete the node */ assert(!is_dummy(node)); @@ -972,7 +958,7 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, next = old; if (unlikely(is_removed(next))) - goto end; + return -ENOENT; if (dummy_removal) assert(is_dummy(next)); else @@ -980,9 +966,7 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, new_next = flag_removed(next); old = uatomic_cmpxchg(&node->p.next, next, new_next); } while (old != next); - /* We performed the (logical) deletion. */ - flagged = 1; /* * Ensure that the node is not visible to readers anymore: lookup for @@ -992,17 +976,9 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, lookup = lookup_bucket(ht, size, bit_reverse_ulong(node->p.reverse_hash)); dummy = (struct cds_lfht_node *) lookup; _cds_lfht_gc_bucket(dummy, node); -end: - /* - * Only the flagging action indicated that we (and no other) - * removed the node from the hash. - */ - if (flagged) { - assert(is_removed(rcu_dereference(node->p.next))); - return 0; - } else { - return -ENOENT; - } + + assert(is_removed(rcu_dereference(node->p.next))); + return 0; } static