Removed the atomic file for the old API
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Feb 2011 11:43:22 -0800
changeset 527173f8030f0c72
parent 5270 7aba0406c273
child 5272 3c94c559f5c2
Removed the atomic file for the old API
Makefile.ds
src/atomic/nds/SDL_atomic.c
     1.1 --- a/Makefile.ds	Sat Feb 12 11:36:56 2011 -0800
     1.2 +++ b/Makefile.ds	Sat Feb 12 11:43:22 2011 -0800
     1.3 @@ -39,7 +39,6 @@
     1.4  src/SDL_fatal.c \
     1.5  src/SDL_hints.c \
     1.6  src/SDL_log.c \
     1.7 -src/atomic/nds/SDL_atomic.c \
     1.8  src/atomic/SDL_atomic.c \
     1.9  src/audio/SDL_audio.c \
    1.10  src/audio/SDL_audiocvt.c \
     2.1 --- a/src/atomic/nds/SDL_atomic.c	Sat Feb 12 11:36:56 2011 -0800
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,469 +0,0 @@
     2.4 -/*
     2.5 -  SDL - Simple DirectMedia Layer
     2.6 -  Copyright (C) 1997-2010 Sam Lantinga
     2.7 -
     2.8 -  This library is free software; you can redistribute it and/or
     2.9 -  modify it under the terms of the GNU Lesser General Public
    2.10 -  License as published by the Free Software Foundation; either
    2.11 -  version 2.1 of the License, or (at your option) any later version.
    2.12 -
    2.13 -  This library is distributed in the hope that it will be useful,
    2.14 -  but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 -  Lesser General Public License for more details.
    2.17 -
    2.18 -  You should have received a copy of the GNU Lesser General Public
    2.19 -  License along with this library; if not, write to the Free Software
    2.20 -  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 -
    2.22 -  Sam Lantinga
    2.23 -  slouken@libsdl.org
    2.24 -
    2.25 -  Contributed by Bob Pendleton, bob@pendleton.com
    2.26 -*/
    2.27 -
    2.28 -#include "SDL_stdinc.h"
    2.29 -#include "SDL_atomic.h"
    2.30 -
    2.31 -#include "SDL_error.h"
    2.32 -
    2.33 -/*
    2.34 -  This file provides 32, and 64 bit atomic operations. If the
    2.35 -  operations are provided by the native hardware and operating system
    2.36 -  they are used. If they are not then the operations are emulated
    2.37 -  using the SDL spin lock operations. If spin lock can not be
    2.38 -  implemented then these functions must fail.
    2.39 -*/
    2.40 -
    2.41 -/* 
    2.42 -  DUMMY VERSION.
    2.43 -
    2.44 -  This version of the code assumes there is no support for atomic
    2.45 -  operations. Therefore, every function sets the SDL error
    2.46 -  message. Oddly enough, if you only have one thread then this
    2.47 -  version actuallys works.
    2.48 -*/
    2.49 -
    2.50 -/*
    2.51 -  Native spinlock routines. Because this is the dummy implementation
    2.52 -  these will always call SDL_SetError() and do nothing.
    2.53 -*/
    2.54 -
    2.55 -void 
    2.56 -SDL_AtomicLock(SDL_SpinLock *lock)
    2.57 -{
    2.58 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
    2.59 -}
    2.60 -
    2.61 -void 
    2.62 -SDL_AtomicUnlock(SDL_SpinLock *lock)
    2.63 -{
    2.64 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
    2.65 -}
    2.66 -
    2.67 -/*
    2.68 -  Note that platform specific versions can be built from this version
    2.69 -  by changing the #undefs to #defines and adding platform specific
    2.70 -  code.
    2.71 -*/
    2.72 -
    2.73 -#undef  nativeTestThenSet32
    2.74 -#undef  nativeClear32
    2.75 -#undef  nativeFetchThenIncrement32
    2.76 -#undef  nativeFetchThenDecrement32
    2.77 -#undef  nativeFetchThenAdd32
    2.78 -#undef  nativeFetchThenSubtract32
    2.79 -#undef  nativeIncrementThenFetch32
    2.80 -#undef  nativeDecrementThenFetch32
    2.81 -#undef  nativeAddThenFetch32
    2.82 -#undef  nativeSubtractThenFetch32
    2.83 -
    2.84 -#undef  nativeTestThenSet64
    2.85 -#undef  nativeClear64
    2.86 -#undef  nativeFetchThenIncrement64
    2.87 -#undef  nativeFetchThenDecrement64
    2.88 -#undef  nativeFetchThenAdd64
    2.89 -#undef  nativeFetchThenSubtract64
    2.90 -#undef  nativeIncrementThenFetch64
    2.91 -#undef  nativeDecrementThenFetch64
    2.92 -#undef  nativeAddThenFetch64
    2.93 -#undef  nativeSubtractThenFetch64
    2.94 -
    2.95 -/* 
    2.96 -  If any of the operations are not provided then we must emulate some
    2.97 -  of them. That means we need a nice implementation of spin locks
    2.98 -  that avoids the "one big lock" problem. We use a vector of spin
    2.99 -  locks and pick which one to use based on the address of the operand
   2.100 -  of the function.
   2.101 -
   2.102 -  To generate the index of the lock we first shift by 3 bits to get
   2.103 -  rid on the zero bits that result from 32 and 64 bit allignment of
   2.104 -  data. We then mask off all but 5 bits and use those 5 bits as an
   2.105 -  index into the table. 
   2.106 -
   2.107 -  Picking the lock this way insures that accesses to the same data at
   2.108 -  the same time will go to the same lock. OTOH, accesses to different
   2.109 -  data have only a 1/32 chance of hitting the same lock. That should
   2.110 -  pretty much eliminate the chances of several atomic operations on
   2.111 -  different data from waiting on the same "big lock". If it isn't
   2.112 -  then the table of locks can be expanded to a new size so long as
   2.113 -  the new size is a power of two.
   2.114 -*/
   2.115 -
   2.116 -static SDL_SpinLock locks[32] = {
   2.117 -   0, 0, 0, 0, 0, 0, 0, 0,
   2.118 -   0, 0, 0, 0, 0, 0, 0, 0,
   2.119 -   0, 0, 0, 0, 0, 0, 0, 0,
   2.120 -   0, 0, 0, 0, 0, 0, 0, 0,
   2.121 -};
   2.122 -
   2.123 -static __inline__ void
   2.124 -privateWaitLock(volatile void *ptr)
   2.125 -{
   2.126 -#if SIZEOF_VOIDP == 4
   2.127 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
   2.128 -#elif SIZEOF_VOIDP == 8
   2.129 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
   2.130 -#endif
   2.131 -
   2.132 -   SDL_AtomicLock(&locks[index]);
   2.133 -}
   2.134 -
   2.135 -static __inline__ void
   2.136 -privateUnlock(volatile void *ptr)
   2.137 -{
   2.138 -#if SIZEOF_VOIDP == 4
   2.139 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
   2.140 -#elif SIZEOF_VOIDP == 8
   2.141 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
   2.142 -#endif
   2.143 -
   2.144 -   SDL_AtomicUnlock(&locks[index]);
   2.145 -}
   2.146 -
   2.147 -/* 32 bit atomic operations */
   2.148 -
   2.149 -SDL_bool
   2.150 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
   2.151 -{
   2.152 -#ifdef nativeTestThenSet32
   2.153 -#else
   2.154 -   SDL_bool result = SDL_FALSE;
   2.155 -
   2.156 -   privateWaitLock(ptr);
   2.157 -   result = (*ptr == 0);
   2.158 -   if (result)
   2.159 -   {
   2.160 -      *ptr = 1;
   2.161 -   }
   2.162 -   privateUnlock(ptr);
   2.163 -
   2.164 -   return result;
   2.165 -#endif
   2.166 -}
   2.167 -
   2.168 -void
   2.169 -SDL_AtomicClear32(volatile Uint32 * ptr)
   2.170 -{
   2.171 -#ifdef nativeClear32
   2.172 -#else
   2.173 -   privateWaitLock(ptr);
   2.174 -   *ptr = 0;
   2.175 -   privateUnlock(ptr);
   2.176 -
   2.177 -   return;
   2.178 -#endif
   2.179 -}
   2.180 -
   2.181 -Uint32
   2.182 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
   2.183 -{
   2.184 -#ifdef nativeFetchThenIncrement32
   2.185 -#else
   2.186 -   Uint32 tmp = 0;
   2.187 -
   2.188 -   privateWaitLock(ptr);
   2.189 -   tmp = *ptr;
   2.190 -   (*ptr)+= 1;
   2.191 -   privateUnlock(ptr);
   2.192 -
   2.193 -   return tmp;
   2.194 -#endif
   2.195 -}
   2.196 -
   2.197 -Uint32
   2.198 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
   2.199 -{
   2.200 -#ifdef nativeFetchThenDecrement32
   2.201 -#else
   2.202 -   Uint32 tmp = 0;
   2.203 -
   2.204 -   privateWaitLock(ptr);
   2.205 -   tmp = *ptr;
   2.206 -   (*ptr) -= 1;
   2.207 -   privateUnlock(ptr);
   2.208 -
   2.209 -   return tmp;
   2.210 -#endif
   2.211 -}
   2.212 -
   2.213 -Uint32
   2.214 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
   2.215 -{
   2.216 -#ifdef nativeFetchThenAdd32
   2.217 -#else
   2.218 -   Uint32 tmp = 0;
   2.219 -
   2.220 -   privateWaitLock(ptr);
   2.221 -   tmp = *ptr;
   2.222 -   (*ptr)+= value;
   2.223 -   privateUnlock(ptr);
   2.224 -
   2.225 -   return tmp;
   2.226 -#endif
   2.227 -}
   2.228 -
   2.229 -Uint32
   2.230 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
   2.231 -{
   2.232 -#ifdef nativeFetchThenSubtract32
   2.233 -#else
   2.234 -   Uint32 tmp = 0;
   2.235 -
   2.236 -   privateWaitLock(ptr);
   2.237 -   tmp = *ptr;
   2.238 -   (*ptr)-= value;
   2.239 -   privateUnlock(ptr);
   2.240 -
   2.241 -   return tmp;
   2.242 -#endif
   2.243 -}
   2.244 -
   2.245 -Uint32
   2.246 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
   2.247 -{
   2.248 -#ifdef nativeIncrementThenFetch32
   2.249 -#else
   2.250 -   Uint32 tmp = 0;
   2.251 -
   2.252 -   privateWaitLock(ptr);
   2.253 -   (*ptr)+= 1;
   2.254 -   tmp = *ptr;
   2.255 -   privateUnlock(ptr);
   2.256 -
   2.257 -   return tmp;
   2.258 -#endif
   2.259 -}
   2.260 -
   2.261 -Uint32
   2.262 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
   2.263 -{
   2.264 -#ifdef nativeDecrementThenFetch32
   2.265 -#else
   2.266 -   Uint32 tmp = 0;
   2.267 -
   2.268 -   privateWaitLock(ptr);
   2.269 -   (*ptr)-= 1;
   2.270 -   tmp = *ptr;
   2.271 -   privateUnlock(ptr);
   2.272 -
   2.273 -   return tmp;
   2.274 -#endif
   2.275 -}
   2.276 -
   2.277 -Uint32
   2.278 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
   2.279 -{
   2.280 -#ifdef nativeAddThenFetch32
   2.281 -#else
   2.282 -   Uint32 tmp = 0;
   2.283 -
   2.284 -   privateWaitLock(ptr);
   2.285 -   (*ptr)+= value;
   2.286 -   tmp = *ptr;
   2.287 -   privateUnlock(ptr);
   2.288 -
   2.289 -   return tmp;
   2.290 -#endif
   2.291 -}
   2.292 -
   2.293 -Uint32
   2.294 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
   2.295 -{
   2.296 -#ifdef nativeSubtractThenFetch32
   2.297 -#else
   2.298 -   Uint32 tmp = 0;
   2.299 -
   2.300 -   privateWaitLock(ptr);
   2.301 -   (*ptr)-= value;
   2.302 -   tmp = *ptr;
   2.303 -   privateUnlock(ptr);
   2.304 -
   2.305 -   return tmp;
   2.306 -#endif
   2.307 -}
   2.308 -
   2.309 -/* 64 bit atomic operations */
   2.310 -#ifdef SDL_HAS_64BIT_TYPE
   2.311 -
   2.312 -SDL_bool
   2.313 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
   2.314 -{
   2.315 -#ifdef nativeTestThenSet64
   2.316 -#else
   2.317 -   SDL_bool result = SDL_FALSE;
   2.318 -
   2.319 -   privateWaitLock(ptr);
   2.320 -   result = (*ptr == 0);
   2.321 -   if (result)
   2.322 -   {
   2.323 -      *ptr = 1;
   2.324 -   }
   2.325 -   privateUnlock(ptr);
   2.326 -
   2.327 -   return result;
   2.328 -#endif
   2.329 -}
   2.330 -
   2.331 -void
   2.332 -SDL_AtomicClear64(volatile Uint64 * ptr)
   2.333 -{
   2.334 -#ifdef nativeClear64
   2.335 -#else
   2.336 -   privateWaitLock(ptr);
   2.337 -   *ptr = 0;
   2.338 -   privateUnlock(ptr);
   2.339 -
   2.340 -   return;
   2.341 -#endif
   2.342 -}
   2.343 -
   2.344 -Uint64
   2.345 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
   2.346 -{
   2.347 -#ifdef nativeFetchThenIncrement64
   2.348 -#else
   2.349 -   Uint64 tmp = 0;
   2.350 -
   2.351 -   privateWaitLock(ptr);
   2.352 -   tmp = *ptr;
   2.353 -   (*ptr)+= 1;
   2.354 -   privateUnlock(ptr);
   2.355 -
   2.356 -   return tmp;
   2.357 -#endif
   2.358 -}
   2.359 -
   2.360 -Uint64
   2.361 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
   2.362 -{
   2.363 -#ifdef nativeFetchThenDecrement64
   2.364 -#else
   2.365 -   Uint64 tmp = 0;
   2.366 -
   2.367 -   privateWaitLock(ptr);
   2.368 -   tmp = *ptr;
   2.369 -   (*ptr) -= 1;
   2.370 -   privateUnlock(ptr);
   2.371 -
   2.372 -   return tmp;
   2.373 -#endif
   2.374 -}
   2.375 -
   2.376 -Uint64
   2.377 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
   2.378 -{
   2.379 -#ifdef nativeFetchThenAdd64
   2.380 -#else
   2.381 -   Uint64 tmp = 0;
   2.382 -
   2.383 -   privateWaitLock(ptr);
   2.384 -   tmp = *ptr;
   2.385 -   (*ptr)+= value;
   2.386 -   privateUnlock(ptr);
   2.387 -
   2.388 -   return tmp;
   2.389 -#endif
   2.390 -}
   2.391 -
   2.392 -Uint64
   2.393 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
   2.394 -{
   2.395 -#ifdef nativeFetchThenSubtract64
   2.396 -#else
   2.397 -   Uint64 tmp = 0;
   2.398 -
   2.399 -   privateWaitLock(ptr);
   2.400 -   tmp = *ptr;
   2.401 -   (*ptr)-= value;
   2.402 -   privateUnlock(ptr);
   2.403 -
   2.404 -   return tmp;
   2.405 -#endif
   2.406 -}
   2.407 -
   2.408 -Uint64
   2.409 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
   2.410 -{
   2.411 -#ifdef nativeIncrementThenFetch64
   2.412 -#else
   2.413 -   Uint64 tmp = 0;
   2.414 -
   2.415 -   privateWaitLock(ptr);
   2.416 -   (*ptr)+= 1;
   2.417 -   tmp = *ptr;
   2.418 -   privateUnlock(ptr);
   2.419 -
   2.420 -   return tmp;
   2.421 -#endif
   2.422 -}
   2.423 -
   2.424 -Uint64
   2.425 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
   2.426 -{
   2.427 -#ifdef nativeDecrementThenFetch64
   2.428 -#else
   2.429 -   Uint64 tmp = 0;
   2.430 -
   2.431 -   privateWaitLock(ptr);
   2.432 -   (*ptr)-= 1;
   2.433 -   tmp = *ptr;
   2.434 -   privateUnlock(ptr);
   2.435 -
   2.436 -   return tmp;
   2.437 -#endif
   2.438 -}
   2.439 -
   2.440 -Uint64
   2.441 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
   2.442 -{
   2.443 -#ifdef nativeAddThenFetch64
   2.444 -#else
   2.445 -   Uint64 tmp = 0;
   2.446 -
   2.447 -   privateWaitLock(ptr);
   2.448 -   (*ptr)+= value;
   2.449 -   tmp = *ptr;
   2.450 -   privateUnlock(ptr);
   2.451 -
   2.452 -   return tmp;
   2.453 -#endif
   2.454 -}
   2.455 -
   2.456 -Uint64
   2.457 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
   2.458 -{
   2.459 -#ifdef nativeSubtractThenFetch64
   2.460 -#else
   2.461 -   Uint64 tmp = 0;
   2.462 -
   2.463 -   privateWaitLock(ptr);
   2.464 -   (*ptr)-= value;
   2.465 -   tmp = *ptr;
   2.466 -   privateUnlock(ptr);
   2.467 -
   2.468 -   return tmp;
   2.469 -#endif
   2.470 -}
   2.471 -#endif
   2.472 -