From 410ca734fb864fc3989e01d48e34b5f224ae1465 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sun, 20 Feb 2022 10:51:25 +0300 Subject: [PATCH] Repeat black list check on CAS fail in stack_push_explicit_aux_release (a cherry-pick of commit ae0f8e7e4 from 'release-7_4') Also, execute the first read in a loop with an acquire barrier, and place black list checking as close to CAS as possible. * src/atomic_ops_stack.c [AO_USE_ALMOST_LOCK_FREE] (AO_stack_push_explicit_aux_release): Use acquire barrier to read list value (stored to next local variable); read list value and store it to x element before iterating over AO_stack_bl (and, thus, retry iterating over AO_stack_bl if CAS failed). --- src/atomic_ops_stack.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/atomic_ops_stack.c b/src/atomic_ops_stack.c index d59fac9d..e0778c42 100644 --- a/src/atomic_ops_stack.c +++ b/src/atomic_ops_stack.c @@ -56,6 +56,9 @@ AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, /* No deletions of x can start here, since x is not currently in the */ /* list. */ retry: + do { + next = AO_load_acquire(list); + *x = next; # if AO_BL_SIZE == 2 { /* Start all loads as close to concurrently as possible. */ @@ -91,12 +94,7 @@ AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, } # endif /* x_bits is not currently being deleted */ - do - { - next = AO_load(list); - *x = next; - } - while (AO_EXPECT_FALSE(!AO_compare_and_swap_release(list, next, x_bits))); + } while (AO_EXPECT_FALSE(!AO_compare_and_swap_release(list, next, x_bits))); } /*