(root)/
glibc-2.38/
sysdeps/
sparc/
atomic-machine.h
       1  /* Atomic operations.  Sparc version.
       2     Copyright (C) 2019-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #ifndef _ATOMIC_MACHINE_H
      20  #define _ATOMIC_MACHINE_H	1
      21  
      22  #ifdef __arch64__
      23  # define __HAVE_64B_ATOMICS          1
      24  #else
      25  # define __HAVE_64B_ATOMICS          0
      26  #endif
      27  #define USE_ATOMIC_COMPILER_BUILTINS 1
      28  
      29  /* XXX Is this actually correct?  */
      30  #define ATOMIC_EXCHANGE_USES_CAS     __HAVE_64B_ATOMICS
      31  
      32  /* Compare and exchange.
      33     For all "bool" routines, we return FALSE if exchange successful.  */
      34  
      35  #define __arch_compare_and_exchange_val_int(mem, newval, oldval, model) \
      36    ({									\
      37      typeof (*mem) __oldval = (oldval);					\
      38      __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\
      39  				 model, __ATOMIC_RELAXED);		\
      40      __oldval;								\
      41    })
      42  
      43  #define atomic_compare_and_exchange_val_acq(mem, new, old)		      \
      44    ({									      \
      45      __typeof ((__typeof (*(mem))) *(mem)) __result;			      \
      46      if (sizeof (*mem) == 4						      \
      47          || (__HAVE_64B_ATOMICS && sizeof (*mem) == 8))			      \
      48        __result = __arch_compare_and_exchange_val_int (mem, new, old,	      \
      49  							 __ATOMIC_ACQUIRE);   \
      50      else								      \
      51        abort ();								      \
      52      __result;								      \
      53    })
      54  
      55  #ifdef __sparc_v9__
      56  # define atomic_full_barrier() \
      57    __asm __volatile ("membar #LoadLoad | #LoadStore"			      \
      58  		    " | #StoreLoad | #StoreStore" : : : "memory")
      59  # define atomic_read_barrier() \
      60    __asm __volatile ("membar #LoadLoad | #LoadStore" : : : "memory")
      61  # define atomic_write_barrier() \
      62    __asm __volatile ("membar #LoadStore | #StoreStore" : : : "memory")
      63  
      64  extern void __cpu_relax (void);
      65  # define atomic_spin_nop() __cpu_relax ()
      66  #endif
      67  
      68  #endif /* _ATOMIC_MACHINE_H  */