Hi Aaron,

On Mon, 2026-08-31 at 18:46 -0400, Aaron Merey wrote:
> Use __atomic_{load, store}_n when USE_LOCKS is defined.  Fall back to
> non-atomic load/store when USE_LOCKS is not defined.

This looks sane. The code already uses __atomic_load_n calls. Do we
also need a wrapper for __atomic_compare_exchange_n?

Maybe add the comment from libdw.h here?

  /* __atomic_* compiler builtin functions are used instead of <stdatomic.h>
     because the builtins can operate on non-_Atomic types.
     Dwarf_Die.abbrev cannot be made _Atomic without possibly breaking ABI
     compatibility.  */

Because my first question was, why not use the stdatomic ones. Then I
remembered I asked that question before, but didn't remember the
answer.

Cheers,

Mark

> Signed-off-by: Aaron Merey <[email protected]>
> ---
>  lib/locks.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lib/locks.h b/lib/locks.h
> index 9c17eca7..ef0e9cac 100644
> --- a/lib/locks.h
> +++ b/lib/locks.h
> @@ -56,6 +56,10 @@
>  # define mutex_fini(lock)            MUTEX_CALL (destroy (&lock))
>  # define once(once_control, init_routine)  \
>    ONCE_CALL (once (&once_control, init_routine))
> +# define atomic_load_acquire(ptr) \
> +  __atomic_load_n ((ptr), __ATOMIC_ACQUIRE)
> +# define atomic_store_release(ptr, val) \
> +  __atomic_store_n ((ptr), (val), __ATOMIC_RELEASE)
>  #else
>  /* Eventually we will allow multi-threaded applications to use the
>     libraries.  Therefore we will add the necessary locking although
> @@ -73,6 +77,8 @@
>  # define mutex_fini(lock) ((void) (lock))
>  # define once_define(class,name)
>  # define once(once_control, init_routine)       init_routine()
> +# define atomic_load_acquire(ptr) (*(ptr))
> +# define atomic_store_release(ptr, val) ((void) (*(ptr) = (val)))
>  #endif  /* USE_LOCKS */
>  
>  #endif  /* locks.h */

Reply via email to