src/atomic/linux/SDL_atomic.c
changeset 3200 ef2c029a3a9d
parent 3199 3e1bf2b8bd81
child 3201 c297230efc75
     1.1 --- a/src/atomic/linux/SDL_atomic.c	Wed Jun 24 20:04:08 2009 +0000
     1.2 +++ b/src/atomic/linux/SDL_atomic.c	Wed Jun 24 20:20:57 2009 +0000
     1.3 @@ -29,148 +29,147 @@
     1.4  Uint32
     1.5  SDL_AtomicExchange32(Uint32 * ptr, Uint32 value)
     1.6  {
     1.7 -   return 0;
     1.8 +   return __sync_lock_test_and_set(ptr, value);
     1.9  }
    1.10  
    1.11  SDL_bool
    1.12  SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue)
    1.13  {
    1.14 -   return SDL_false;
    1.15 +   return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue);
    1.16  }
    1.17  
    1.18  SDL_bool
    1.19  SDL_AtomicTestThenSet32(Uint32 * ptr)
    1.20  {
    1.21 -   return SDL_false;
    1.22 +   return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1));
    1.23  }
    1.24  
    1.25  void
    1.26  SDL_AtomicClear32(Uint32 * ptr)
    1.27  {
    1.28 +   __sync_lock_release(ptr);
    1.29  }
    1.30  
    1.31  Uint32
    1.32  SDL_AtomicFetchThenIncrement32(Uint32 * ptr)
    1.33  {
    1.34 -   return 0;
    1.35 +   return __sync_fetch_and_add(ptr, 1);
    1.36  }
    1.37  
    1.38  Uint32
    1.39  SDL_AtomicFetchThenDecrement32(Uint32 * ptr)
    1.40  {
    1.41 -   return 0;
    1.42 +   return __sync_fetch_and_sub(ptr, 1);
    1.43  }
    1.44  
    1.45  Uint32
    1.46  SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value)
    1.47  {
    1.48 -   return 0;
    1.49 +   return __sync_fetch_and_add(ptr, value);
    1.50  }
    1.51  
    1.52  Uint32
    1.53  SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value)
    1.54  {
    1.55 -   return 0;
    1.56 +   return __sync_fetch_and_sub(ptr, value);
    1.57  }
    1.58  
    1.59  Uint32
    1.60  SDL_AtomicIncrementThenFetch32(Uint32 * ptr)
    1.61  {
    1.62 -   return 0;
    1.63 +   return __sync_add_and_fetch(ptr, 1);
    1.64  }
    1.65  
    1.66  Uint32
    1.67  SDL_AtomicDecrementThenFetch32(Uint32 * ptr)
    1.68  {
    1.69 -   return 0;
    1.70 +   return __sync_sub_and_fetch(ptr, 1);
    1.71  }
    1.72  
    1.73  Uint32
    1.74  SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value)
    1.75  {
    1.76 -   return 0;
    1.77 +   return __sync_add_and_fetch(ptr, value);
    1.78  }
    1.79  
    1.80  Uint32
    1.81  SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value)
    1.82  {
    1.83 -   return 0;
    1.84 +   return __sync_sub_and_fetch(ptr, value);
    1.85  }
    1.86  
    1.87 -
    1.88  #ifdef SDL_HAS_64BIT_TYPE
    1.89  
    1.90  Uint64
    1.91  SDL_AtomicExchange64(Uint64 * ptr, Uint64 value)
    1.92  {
    1.93 -   return 0;
    1.94 +   return __sync_lock_test_and_set(ptr, value);
    1.95  }
    1.96  
    1.97  SDL_bool
    1.98 -SDL_AtomicCompareThenSet64(Uint64 * ptr,
    1.99 -Uint64 oldvalue, Uint64 newvalue)
   1.100 +SDL_AtomicCompareThenSet64(Uint64 * ptr, Uint64 oldvalue, Uint64 newvalue)
   1.101  {
   1.102 -   return SDL_false;
   1.103 +   return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue);
   1.104  }
   1.105  
   1.106  SDL_bool
   1.107  SDL_AtomicTestThenSet64(Uint64 * ptr)
   1.108  {
   1.109 -   return SDL_false;
   1.110 +   return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1));
   1.111  }
   1.112  
   1.113  void
   1.114  SDL_AtomicClear64(Uint64 * ptr)
   1.115  {
   1.116 +   __sync_lock_release(ptr);
   1.117  }
   1.118  
   1.119  Uint64
   1.120  SDL_AtomicFetchThenIncrement64(Uint64 * ptr)
   1.121  {
   1.122 -   return 0;
   1.123 +   return __sync_fetch_and_add(ptr, 1);
   1.124  }
   1.125  
   1.126  Uint64
   1.127  SDL_AtomicFetchThenDecrement64(Uint64 * ptr)
   1.128  {
   1.129 -   return 0;
   1.130 +   return __sync_fetch_and_sub(ptr, 1);
   1.131  }
   1.132  
   1.133  Uint64
   1.134  SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value)
   1.135  {
   1.136 -   return 0;
   1.137 +   return __sync_fetch_and_add(ptr, value);
   1.138  }
   1.139  
   1.140  Uint64
   1.141  SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value)
   1.142  {
   1.143 -   return 0;
   1.144 +   return __sync_fetch_and_sub(ptr, value);
   1.145  }
   1.146  
   1.147  Uint64
   1.148  SDL_AtomicIncrementThenFetch64(Uint64 * ptr)
   1.149  {
   1.150 -   return 0;
   1.151 +   return __sync_add_and_fetch(ptr, 1);
   1.152  }
   1.153  
   1.154  Uint64
   1.155  SDL_AtomicDecrementThenFetch64(Uint64 * ptr)
   1.156  {
   1.157 -   return 0;
   1.158 +   return __sync_sub_and_fetch(ptr, 1);
   1.159  }
   1.160  
   1.161  Uint64
   1.162  SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value)
   1.163  {
   1.164 -   return 0;
   1.165 +   return __sync_add_and_fetch(ptr, value);
   1.166  }
   1.167  
   1.168  Uint64
   1.169  SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value)
   1.170  {
   1.171 -   return 0;
   1.172 +   return __sync_sub_and_fetch(ptr, value);
   1.173  }
   1.174 -
   1.175  #endif
   1.176  #endif