123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- #ifndef AO_ATOMIC_OPS_H
- #define AO_ATOMIC_OPS_H
- #include "atomic_ops/ao_version.h"
-
-
- #include <assert.h>
- #include <stddef.h>
- #define AO_t size_t
- #define AO_TS_INITIALIZER (AO_t)AO_TS_CLEAR
- #if (defined(__GNUC__) || defined(_MSC_VER) || defined(__INTEL_COMPILER) \
- || defined(__DMC__) || defined(__WATCOMC__)) && !defined(AO_NO_INLINE)
- # define AO_INLINE static __inline
- #elif defined(__sun) && !defined(AO_NO_INLINE)
- # define AO_INLINE static inline
- #else
- # define AO_INLINE static
- #endif
- #if __GNUC__ >= 3 && !defined(LINT2)
- # define AO_EXPECT_FALSE(expr) __builtin_expect(expr, 0)
-
- #else
- # define AO_EXPECT_FALSE(expr) (expr)
- #endif
- #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
- # define AO_compiler_barrier() __asm__ __volatile__("" : : : "memory")
- #elif defined(_MSC_VER) || defined(__DMC__) || defined(__BORLANDC__) \
- || defined(__WATCOMC__)
- # if defined(_AMD64_) || defined(_M_X64) || _MSC_VER >= 1400
- # if defined(_WIN32_WCE)
- # elif defined(_MSC_VER)
- # include <intrin.h>
- # endif
- # pragma intrinsic(_ReadWriteBarrier)
- # define AO_compiler_barrier() _ReadWriteBarrier()
-
-
- # else
- # define AO_compiler_barrier() __asm { }
-
-
- # endif
- #elif defined(__INTEL_COMPILER)
- # define AO_compiler_barrier() __memory_barrier()
-
- #elif defined(_HPUX_SOURCE)
- # if defined(__ia64)
- # include <machine/sys/inline.h>
- # define AO_compiler_barrier() _Asm_sched_fence()
- # else
-
-
- static volatile int AO_barrier_dummy;
- # define AO_compiler_barrier() (void)(AO_barrier_dummy = AO_barrier_dummy)
- # endif
- #else
-
-
- # define AO_compiler_barrier() asm("")
- #endif
- #if defined(AO_USE_PTHREAD_DEFS)
- # include "atomic_ops/sysdeps/generic_pthread.h"
- #endif
- #if (defined(__CC_ARM) || defined(__ARMCC__)) && !defined(__GNUC__) \
- && !defined(AO_USE_PTHREAD_DEFS)
- # include "atomic_ops/sysdeps/armcc/arm_v6.h"
- # define AO_GENERALIZE_TWICE
- #endif
- #if defined(__GNUC__) && !defined(AO_USE_PTHREAD_DEFS) \
- && !defined(__INTEL_COMPILER)
- # if defined(__i386__)
-
-
-
- # include "atomic_ops/sysdeps/gcc/x86.h"
- # endif
- # if defined(__x86_64__)
- # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) \
- && !defined(AO_USE_SYNC_CAS_BUILTIN)
-
- # define AO_USE_SYNC_CAS_BUILTIN
- # endif
- # include "atomic_ops/sysdeps/gcc/x86.h"
- # endif
- # if defined(__ia64__)
- # include "atomic_ops/sysdeps/gcc/ia64.h"
- # define AO_GENERALIZE_TWICE
- # endif
- # if defined(__hppa__)
- # include "atomic_ops/sysdeps/gcc/hppa.h"
- # define AO_CAN_EMUL_CAS
- # endif
- # if defined(__alpha__)
- # include "atomic_ops/sysdeps/gcc/alpha.h"
- # define AO_GENERALIZE_TWICE
- # endif
- # if defined(__s390__)
- # include "atomic_ops/sysdeps/gcc/s390.h"
- # endif
- # if defined(__sparc__)
- # include "atomic_ops/sysdeps/gcc/sparc.h"
- # define AO_CAN_EMUL_CAS
- # endif
- # if defined(__m68k__)
- # include "atomic_ops/sysdeps/gcc/m68k.h"
- # endif
- # if defined(__nios2__)
- # include "atomic_ops/sysdeps/gcc/nios2.h"
- # endif
- # if defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) \
- || defined(__powerpc64__) || defined(__ppc64__)
- # include "atomic_ops/sysdeps/gcc/powerpc.h"
- # endif
- # if defined(__aarch64__)
- # include "atomic_ops/sysdeps/gcc/aarch64.h"
- # define AO_CAN_EMUL_CAS
- # endif
- # if defined(__arm__)
- # include "atomic_ops/sysdeps/gcc/arm.h"
- # define AO_CAN_EMUL_CAS
- # endif
- # if defined(__cris__) || defined(CRIS)
- # include "atomic_ops/sysdeps/gcc/cris.h"
- # define AO_GENERALIZE_TWICE
- # endif
- # if defined(__mips__)
- # include "atomic_ops/sysdeps/gcc/mips.h"
- # endif
- # if defined(__sh__) || defined(SH4)
- # include "atomic_ops/sysdeps/gcc/sh.h"
- # define AO_CAN_EMUL_CAS
- # endif
- # if defined(__avr32__)
- # include "atomic_ops/sysdeps/gcc/avr32.h"
- # endif
- # if defined(__hexagon__)
- # include "atomic_ops/sysdeps/gcc/hexagon.h"
- # endif
- #endif
- #if (defined(__IBMC__) || defined(__IBMCPP__)) && !defined(__GNUC__) \
- && !defined(AO_USE_PTHREAD_DEFS)
- # if defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) \
- || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) \
- || defined(_ARCH_PWR)
- # include "atomic_ops/sysdeps/ibmc/powerpc.h"
- # define AO_GENERALIZE_TWICE
- # endif
- #endif
- #if defined(__INTEL_COMPILER) && !defined(AO_USE_PTHREAD_DEFS)
- # if defined(__ia64__)
- # include "atomic_ops/sysdeps/icc/ia64.h"
- # define AO_GENERALIZE_TWICE
- # endif
- # if defined(__GNUC__)
-
- # if defined(__i386__)
- # include "atomic_ops/sysdeps/gcc/x86.h"
- # endif
- # if defined(__x86_64__)
- # if (__INTEL_COMPILER > 1110) && !defined(AO_USE_SYNC_CAS_BUILTIN)
- # define AO_USE_SYNC_CAS_BUILTIN
- # endif
- # include "atomic_ops/sysdeps/gcc/x86.h"
- # endif
- # endif
- #endif
- #if defined(_HPUX_SOURCE) && !defined(__GNUC__) && !defined(AO_USE_PTHREAD_DEFS)
- # if defined(__ia64)
- # include "atomic_ops/sysdeps/hpc/ia64.h"
- # define AO_GENERALIZE_TWICE
- # else
- # include "atomic_ops/sysdeps/hpc/hppa.h"
- # define AO_CAN_EMUL_CAS
- # endif
- #endif
- #if defined(_MSC_VER) || defined(__DMC__) || defined(__BORLANDC__) \
- || (defined(__WATCOMC__) && defined(__NT__))
- # if defined(_AMD64_) || defined(_M_X64)
- # include "atomic_ops/sysdeps/msftc/x86_64.h"
- # elif defined(_M_IX86) || defined(x86)
- # include "atomic_ops/sysdeps/msftc/x86.h"
- # elif defined(_M_ARM) || defined(ARM) || defined(_ARM_)
- # include "atomic_ops/sysdeps/msftc/arm.h"
- # define AO_GENERALIZE_TWICE
- # endif
- #endif
- #if defined(__sun) && !defined(__GNUC__) && !defined(AO_USE_PTHREAD_DEFS)
-
- # if defined(__i386) || defined(__x86_64) || defined(__amd64)
- # include "atomic_ops/sysdeps/sunc/x86.h"
- # endif
- #endif
- #if !defined(__GNUC__) && (defined(sparc) || defined(__sparc)) \
- && !defined(AO_USE_PTHREAD_DEFS)
- # include "atomic_ops/sysdeps/sunc/sparc.h"
- # define AO_CAN_EMUL_CAS
- #endif
- #if defined(AO_REQUIRE_CAS) && !defined(AO_HAVE_compare_and_swap) \
- && !defined(AO_HAVE_fetch_compare_and_swap) \
- && !defined(AO_HAVE_compare_and_swap_full) \
- && !defined(AO_HAVE_fetch_compare_and_swap_full) \
- && !defined(AO_HAVE_compare_and_swap_acquire) \
- && !defined(AO_HAVE_fetch_compare_and_swap_acquire)
- # if defined(AO_CAN_EMUL_CAS)
- # include "atomic_ops/sysdeps/emul_cas.h"
- # else
- # error Cannot implement AO_compare_and_swap_full on this architecture.
- # endif
- #endif
- #if AO_AO_TS_T && !defined(AO_CLEAR)
- # define AO_CLEAR(addr) AO_store_release((AO_TS_t *)(addr), AO_TS_CLEAR)
- #endif
- #if AO_CHAR_TS_T && !defined(AO_CLEAR)
- # define AO_CLEAR(addr) AO_char_store_release((AO_TS_t *)(addr), AO_TS_CLEAR)
- #endif
- #if !defined(AO_GENERALIZE_TWICE) && defined(AO_CAN_EMUL_CAS) \
- && !defined(AO_HAVE_compare_and_swap_full) \
- && !defined(AO_HAVE_fetch_compare_and_swap_full)
- # define AO_GENERALIZE_TWICE
- #endif
- #include "atomic_ops/generalize.h"
- #if !defined(AO_GENERALIZE_TWICE) \
- && defined(AO_HAVE_compare_double_and_swap_double) \
- && (!defined(AO_HAVE_double_load) || !defined(AO_HAVE_double_store))
- # define AO_GENERALIZE_TWICE
- #endif
- #ifdef AO_T_IS_INT
-
- # include "atomic_ops/sysdeps/ao_t_is_int.h"
- # ifndef AO_GENERALIZE_TWICE
-
- # define AO_GENERALIZE_TWICE
- # endif
- #endif
- #ifdef AO_GENERALIZE_TWICE
- # include "atomic_ops/generalize.h"
- #endif
- #define AO_TS_T AO_TS_t
- #define AO_T AO_t
- #define AO_TS_VAL AO_TS_VAL_t
- #endif
|