src/atomic/SDL_atomic.c
changeset 8979 1e283b7a1580
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
     1.1 --- a/src/atomic/SDL_atomic.c	Mon Jul 07 10:33:32 2014 -0700
     1.2 +++ b/src/atomic/SDL_atomic.c	Sat Jul 05 16:11:23 2014 -0700
     1.3 @@ -31,6 +31,10 @@
     1.4  #include <libkern/OSAtomic.h>
     1.5  #endif
     1.6  
     1.7 +#if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
     1.8 +#include <atomic.h>
     1.9 +#endif
    1.10 +
    1.11  /*
    1.12    If any of the operations are not provided then we must emulate some
    1.13    of them. That means we need a nice implementation of spin locks
    1.14 @@ -54,7 +58,7 @@
    1.15    Contributed by Bob Pendleton, bob@pendleton.com
    1.16  */
    1.17  
    1.18 -#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(__MACOSX__)
    1.19 +#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(__MACOSX__) && !defined(__SOLARIS__)
    1.20  #define EMULATE_CAS 1
    1.21  #endif
    1.22  
    1.23 @@ -88,6 +92,10 @@
    1.24      return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
    1.25  #elif defined(HAVE_GCC_ATOMICS)
    1.26      return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
    1.27 +#elif defined(__SOLARIS__) && defined(_LP64)
    1.28 +    return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)&a->value, (uint64_t)oldval, (uint64_t)newval) == oldval);
    1.29 +#elif defined(__SOLARIS__) && !defined(_LP64)
    1.30 +    return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)&a->value, (uint32_t)oldval, (uint32_t)newval) == oldval);
    1.31  #elif EMULATE_CAS
    1.32      SDL_bool retval = SDL_FALSE;
    1.33  
    1.34 @@ -117,6 +125,8 @@
    1.35      return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
    1.36  #elif defined(HAVE_GCC_ATOMICS)
    1.37      return __sync_bool_compare_and_swap(a, oldval, newval);
    1.38 +#elif defined(__SOLARIS__)
    1.39 +    return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval);
    1.40  #elif EMULATE_CAS
    1.41      SDL_bool retval = SDL_FALSE;
    1.42  
    1.43 @@ -140,6 +150,10 @@
    1.44      return _InterlockedExchange((long*)&a->value, v);
    1.45  #elif defined(HAVE_GCC_ATOMICS)
    1.46      return __sync_lock_test_and_set(&a->value, v);
    1.47 +#elif defined(__SOLARIS__) && defined(_LP64)
    1.48 +    return (int) atomic_swap_64((volatile uint64_t*)&a->value, (uint64_t)v);
    1.49 +#elif defined(__SOLARIS__) && !defined(_LP64)
    1.50 +    return (int) atomic_swap_32((volatile uint32_t*)&a->value, (uint32_t)v);
    1.51  #else
    1.52      int value;
    1.53      do {
    1.54 @@ -158,6 +172,8 @@
    1.55      return _InterlockedExchangePointer(a, v);
    1.56  #elif defined(HAVE_GCC_ATOMICS)
    1.57      return __sync_lock_test_and_set(a, v);
    1.58 +#elif defined(__SOLARIS__)
    1.59 +    return atomic_swap_ptr(a, v);
    1.60  #else
    1.61      void *value;
    1.62      do {
    1.63 @@ -174,6 +190,15 @@
    1.64      return _InterlockedExchangeAdd((long*)&a->value, v);
    1.65  #elif defined(HAVE_GCC_ATOMICS)
    1.66      return __sync_fetch_and_add(&a->value, v);
    1.67 +#elif defined(__SOLARIS__)
    1.68 +    int pv = a->value;
    1.69 +    membar_consumer();
    1.70 +#if defined(_LP64)
    1.71 +    atomic_add_64((volatile uint64_t*)&a->value, v);
    1.72 +#elif !defined(_LP64)
    1.73 +    atomic_add_32((volatile uint32_t*)&a->value, v);
    1.74 +#endif
    1.75 +    return pv;
    1.76  #else
    1.77      int value;
    1.78      do {