src/atomic/SDL_spinlock.c
changeset 8979 1e283b7a1580
parent 8583 fb2933ca805f
child 8991 13b0df1793e8
equal deleted inserted replaced
8978:7753e4fd3d1d 8979:1e283b7a1580
    26 
    26 
    27 #include "SDL_atomic.h"
    27 #include "SDL_atomic.h"
    28 #include "SDL_mutex.h"
    28 #include "SDL_mutex.h"
    29 #include "SDL_timer.h"
    29 #include "SDL_timer.h"
    30 
    30 
       
    31 #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
       
    32 #include <atomic.h>
       
    33 #endif
    31 
    34 
    32 /* This function is where all the magic happens... */
    35 /* This function is where all the magic happens... */
    33 SDL_bool
    36 SDL_bool
    34 SDL_AtomicTryLock(SDL_SpinLock *lock)
    37 SDL_AtomicTryLock(SDL_SpinLock *lock)
    35 {
    38 {
    88 
    91 
    89 #elif HAVE_PTHREAD_SPINLOCK
    92 #elif HAVE_PTHREAD_SPINLOCK
    90     /* pthread instructions */
    93     /* pthread instructions */
    91     return (pthread_spin_trylock(lock) == 0);
    94     return (pthread_spin_trylock(lock) == 0);
    92 
    95 
       
    96 #elif defined(__SOLARIS__) && defined(_LP64)
       
    97     /* Used for Solaris with non-gcc compilers. */
       
    98     return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0);
       
    99 
       
   100 #elif defined(__SOLARIS__) && !defined(_LP64)
       
   101     /* Used for Solaris with non-gcc compilers. */
       
   102     return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0);
       
   103 
    93 #else
   104 #else
    94 #error Please implement for your platform.
   105 #error Please implement for your platform.
    95     return SDL_FALSE;
   106     return SDL_FALSE;
    96 #endif
   107 #endif
    97 }
   108 }
   116     __sync_lock_release(lock);
   127     __sync_lock_release(lock);
   117 
   128 
   118 #elif HAVE_PTHREAD_SPINLOCK
   129 #elif HAVE_PTHREAD_SPINLOCK
   119     pthread_spin_unlock(lock);
   130     pthread_spin_unlock(lock);
   120 
   131 
       
   132 #elif defined(__SOLARIS__)
       
   133     /* Used for Solaris when not using gcc. */
       
   134     *lock = 0;
       
   135     membar_producer();
       
   136 
   121 #else
   137 #else
   122     *lock = 0;
   138     *lock = 0;
   123 #endif
   139 #endif
   124 }
   140 }
   125 
   141