Skip to content

Commit 1fb932d

Browse files
committed
use atomics in critnib find_*
1 parent 02ccc4c commit 1fb932d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/critnib/critnib.c

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

535-
n = n->child[nib];
537+
utils_atomic_load_acquire_ptr((void **)&n->child[nib], (void **)&n);
536538
if (is_leaf(n)) {
537539
return to_leaf(n);
538540
}
@@ -636,7 +638,9 @@ static struct critnib_leaf *find_successor(struct critnib_node *__restrict n) {
636638
while (1) {
637639
unsigned nib;
638640
for (nib = 0; nib <= NIB; nib++) {
639-
if (n->child[nib]) {
641+
struct critnib_node *m;
642+
utils_atomic_load_acquire_ptr((void **)&n->child[nib], (void **)&m);
643+
if (m) {
640644
break;
641645
}
642646
}
@@ -645,7 +649,7 @@ static struct critnib_leaf *find_successor(struct critnib_node *__restrict n) {
645649
return NULL;
646650
}
647651

648-
n = n->child[nib];
652+
utils_atomic_load_acquire_ptr((void **)&n->child[nib], (void **)&n);
649653
if (is_leaf(n)) {
650654
return to_leaf(n);
651655
}

0 commit comments

Comments
 (0)