Skip to content

Commit 9fa5bf8

Browse files
authored
Merge pull request #8 from RinHizakura/pr
Fix incorrect __list_find implementation
2 parents b34b773 + 83ef91e commit 9fa5bf8

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

hp_list/main.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ static bool __list_find(list_t *list,
230230
if (atomic_load(prev) != get_unmarked(curr))
231231
goto try_again;
232232
while (true) {
233-
if (!get_unmarked_node(curr))
234-
return false;
235233
next = (list_node_t *) atomic_load(&get_unmarked_node(curr)->next);
236234
(void) list_hp_protect_ptr(list->hp, HP_NEXT, get_unmarked(next));
235+
/* On a CAS failure, the search function, "__list_find," will simply
236+
* have to go backwards in the list until an unmarked element is found
237+
* from which the search in increasing key order can be started.
238+
*/
237239
if (atomic_load(&get_unmarked_node(curr)->next) != (uintptr_t) next)
238-
break;
239-
if (get_unmarked(next) == atomic_load((atomic_uintptr_t *) &list->tail))
240-
break;
240+
goto try_again;
241241
if (atomic_load(prev) != get_unmarked(curr))
242242
goto try_again;
243243
if (get_unmarked_node(next) == next) {
@@ -259,11 +259,6 @@ static bool __list_find(list_t *list,
259259
curr = next;
260260
(void) list_hp_protect_release(list->hp, HP_CURR, get_unmarked(next));
261261
}
262-
*par_curr = curr;
263-
*par_prev = prev;
264-
*par_next = next;
265-
266-
return false;
267262
}
268263

269264
bool list_insert(list_t *list, list_key_t key)

0 commit comments

Comments
 (0)