Skip to content

Commit e13354b

Browse files
committed
use atomic loads in critnib find_pre/succ
1 parent 62eb8c6 commit e13354b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/critnib/critnib.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ static struct critnib_leaf *
523523
find_predecessor(struct critnib_node *__restrict n) {
524524
while (1) {
525525
int nib;
526+
struct critnib_node *m;
526527
for (nib = NIB; nib >= 0; nib--) {
527-
if (n->child[nib]) {
528+
utils_atomic_load_acquire_ptr((void **)&n->child[nib], (void **)&m);
529+
if (m) {
528530
break;
529531
}
530532
}
@@ -533,9 +535,8 @@ find_predecessor(struct critnib_node *__restrict n) {
533535
return NULL;
534536
}
535537

536-
n = n->child[nib];
537-
if (is_leaf(n)) {
538-
return to_leaf(n);
538+
if (is_leaf(m)) {
539+
return to_leaf(m);
539540
}
540541
}
541542
}
@@ -636,6 +637,8 @@ void *critnib_find_le(struct critnib *c, word key) {
636637
static struct critnib_leaf *find_successor(struct critnib_node *__restrict n) {
637638
while (1) {
638639
unsigned nib;
640+
struct critnib_node *m;
641+
utils_atomic_load_acquire_ptr((void **)&n->child[nib], (void **)&m);
639642
for (nib = 0; nib <= NIB; nib++) {
640643
if (n->child[nib]) {
641644
break;
@@ -646,9 +649,8 @@ static struct critnib_leaf *find_successor(struct critnib_node *__restrict n) {
646649
return NULL;
647650
}
648651

649-
n = n->child[nib];
650-
if (is_leaf(n)) {
651-
return to_leaf(n);
652+
if (is_leaf(m)) {
653+
return to_leaf(m);
652654
}
653655
}
654656
}

0 commit comments

Comments
 (0)