The load-acquire of list->len on pop function is redundant.
Only the CAS success needs to be load-acquire.
It synchronizes with the store release in push, to ensure that the
updated head is visible when the new length is visible.
Without this, one thread in pop could see the increased length but the
old list, which doesn't have enough items yet for pop to succeed.
Signed-off-by: Steven Lariau <steven.lariau@arm.com>
Reviewed-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Acked-by: Gage Eads <gage.eads@intel.com>
int success;
/* Reserve num elements, if available */
- len = __atomic_load_n(&list->len, __ATOMIC_ACQUIRE);
+ len = __atomic_load_n(&list->len, __ATOMIC_RELAXED);
while (1) {
/* Does the list contain enough elements? */
if (__atomic_compare_exchange_n(&list->len,
&len, len - num,
1, __ATOMIC_ACQUIRE,
- __ATOMIC_ACQUIRE))
+ __ATOMIC_RELAXED))
break;
}