Skip to content

Commit 1447f84

Browse files
committed
Fix error of __list_find
The node on the linked list should follow the ordering by its key. However, the function list_insert doesn't actually do this because of the wrong implementation of __list_find. There are three main fixes in this patch. First, once we should do synchronization, we have to iterate the list again but not return from the function. Second, the while loop should iterate until the last node but not the second last one. Finally, under the normal situation that the tail node with key UINTPTR_MAX should not be deleted (unless the end of the program), some codes are never executed which can be removed.
1 parent b34b773 commit 1447f84

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

hp_list/main.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,13 @@ 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 have to
236+
go backwards in the list until an unmarked element is found from which
237+
the search in increasing key order can be started. */
237238
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;
239+
goto try_again;
241240
if (atomic_load(prev) != get_unmarked(curr))
242241
goto try_again;
243242
if (get_unmarked_node(next) == next) {
@@ -259,11 +258,6 @@ static bool __list_find(list_t *list,
259258
curr = next;
260259
(void) list_hp_protect_release(list->hp, HP_CURR, get_unmarked(next));
261260
}
262-
*par_curr = curr;
263-
*par_prev = prev;
264-
*par_next = next;
265-
266-
return false;
267261
}
268262

269263
bool list_insert(list_t *list, list_key_t key)

0 commit comments

Comments
 (0)