include/SDL_atomic.h
changeset 8979 1e283b7a1580
parent 8149 681eb46b8ac4
child 9278 8900afb78a19
equal deleted inserted replaced
8978:7753e4fd3d1d 8979:1e283b7a1580
   120  */
   120  */
   121 #if defined(_MSC_VER) && (_MSC_VER > 1200)
   121 #if defined(_MSC_VER) && (_MSC_VER > 1200)
   122 void _ReadWriteBarrier(void);
   122 void _ReadWriteBarrier(void);
   123 #pragma intrinsic(_ReadWriteBarrier)
   123 #pragma intrinsic(_ReadWriteBarrier)
   124 #define SDL_CompilerBarrier()   _ReadWriteBarrier()
   124 #define SDL_CompilerBarrier()   _ReadWriteBarrier()
   125 #elif defined(__GNUC__)
   125 #elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
       
   126 /* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
   126 #define SDL_CompilerBarrier()   __asm__ __volatile__ ("" : : : "memory")
   127 #define SDL_CompilerBarrier()   __asm__ __volatile__ ("" : : : "memory")
   127 #else
   128 #else
   128 #define SDL_CompilerBarrier()   \
   129 #define SDL_CompilerBarrier()   \
   129 { SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
   130 { SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
   130 #endif
   131 #endif
   167 #else
   168 #else
   168 #define SDL_MemoryBarrierRelease()   __asm__ __volatile__ ("" : : : "memory")
   169 #define SDL_MemoryBarrierRelease()   __asm__ __volatile__ ("" : : : "memory")
   169 #define SDL_MemoryBarrierAcquire()   __asm__ __volatile__ ("" : : : "memory")
   170 #define SDL_MemoryBarrierAcquire()   __asm__ __volatile__ ("" : : : "memory")
   170 #endif /* __GNUC__ && __arm__ */
   171 #endif /* __GNUC__ && __arm__ */
   171 #else
   172 #else
       
   173 #if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
       
   174 /* This is correct for all CPUs on Solaris when using Solaris Studio 12.1+. */
       
   175 #include <mbarrier.h>
       
   176 #define SDL_MemoryBarrierRelease()  __machine_rel_barrier()
       
   177 #define SDL_MemoryBarrierAcquire()  __machine_acq_barrier()
       
   178 #else
   172 /* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
   179 /* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
   173 #define SDL_MemoryBarrierRelease()  SDL_CompilerBarrier()
   180 #define SDL_MemoryBarrierRelease()  SDL_CompilerBarrier()
   174 #define SDL_MemoryBarrierAcquire()  SDL_CompilerBarrier()
   181 #define SDL_MemoryBarrierAcquire()  SDL_CompilerBarrier()
   175 #endif
   182 #endif
       
   183 #endif
   176 
   184 
   177 /**
   185 /**
   178  * \brief A type representing an atomic integer value.  It is a struct
   186  * \brief A type representing an atomic integer value.  It is a struct
   179  *        so people don't accidentally use numeric operations on it.
   187  *        so people don't accidentally use numeric operations on it.
   180  */
   188  */