Support for native and emulated atomic operations has been added.
authorMike Gorchak <lestat@i.com.ua>
Sun, 19 Jul 2009 08:04:59 +0000
changeset 321726ce0b98f2fb
parent 3216 48a80f2a7ff2
child 3218 81773a1eac83
Support for native and emulated atomic operations has been added.
configure.in
src/atomic/qnx/SDL_atomic.c
     1.1 --- a/configure.in	Thu Jul 09 21:31:27 2009 +0000
     1.2 +++ b/configure.in	Sun Jul 19 08:04:59 2009 +0000
     1.3 @@ -2572,6 +2572,12 @@
     1.4              SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
     1.5              have_timers=yes
     1.6          fi
     1.7 +        # Setup files for the atomic operations
     1.8 +        if test x$enable_atomic = xyes; then
     1.9 +                AC_DEFINE(SDL_ATOMIC_QNX)
    1.10 +                SOURCES="$SOURCES $srcdir/src/atomic/qnx/*.c"
    1.11 +                have_atomic=yes
    1.12 +        fi
    1.13          # Set up dummy files for the joystick for now
    1.14          if test x$enable_joystick = xyes; then
    1.15              AC_DEFINE(SDL_JOYSTICK_DUMMY)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/atomic/qnx/SDL_atomic.c	Sun Jul 19 08:04:59 2009 +0000
     2.3 @@ -0,0 +1,882 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2009 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 +
    2.26 +#include "SDL_stdinc.h"
    2.27 +#include "SDL_atomic.h"
    2.28 +
    2.29 +#include <atomic.h>
    2.30 +
    2.31 +/*
    2.32 +  This file provides 8, 16, 32, and 64 bit atomic operations. If the
    2.33 +  operations are provided by the native hardware and operating system
    2.34 +  they are used. If they are not then the operations are emulated
    2.35 +  using the SDL mutex operations. 
    2.36 + */
    2.37 +
    2.38 +/* 
    2.39 +  First, detect whether the operations are supported and create
    2.40 +  #defines that indicate that they do exist. The goal is to have all
    2.41 +  the system dependent code in the top part of the file so that the
    2.42 +  bottom can be use unchanged across all platforms.
    2.43 +
    2.44 +  Second, #define all the operations in each size class that are
    2.45 +  supported. Doing this allows supported operations to be used along
    2.46 +  side of emulated operations.
    2.47 +*/
    2.48 +
    2.49 +/* 
    2.50 +   Emmulated version.
    2.51 +
    2.52 +   Assume there is no support for atomic operations. All such
    2.53 +   operations are implemented using SDL mutex operations.
    2.54 + */
    2.55 +
    2.56 +#ifdef EMULATED_ATOMIC_OPERATIONS
    2.57 +#undef EMULATED_ATOMIC_OPERATIONS
    2.58 +#endif
    2.59 +
    2.60 +#ifdef EMULATED_ATOMIC_OPERATIONS
    2.61 +#define HAVE_ALL_8_BIT_OPS
    2.62 +
    2.63 +#define nativeExchange8(ptr, value)			()
    2.64 +#define nativeCompareThenSet8(ptr, oldvalue, newvalue) 	()
    2.65 +#define nativeTestThenSet8(ptr)    	     		()
    2.66 +#define nativeClear8(ptr)				()
    2.67 +#define nativeFetchThenIncrement8(ptr)   		()
    2.68 +#define nativeFetchThenDecrement8(ptr) 			()
    2.69 +#define nativeFetchThenAdd8(ptr, value) 		()
    2.70 +#define nativeFetchThenSubtract8(ptr, value) 		()
    2.71 +#define nativeIncrementThenFetch8(ptr) 			()
    2.72 +#define nativeDecrementThenFetch8(ptr) 			()
    2.73 +#define nativeAddThenFetch8(ptr, value) 		()
    2.74 +#define nativeSubtractThenFetch8(ptr, value) 		()
    2.75 +#endif
    2.76 +
    2.77 +#ifdef EMULATED_ATOMIC_OPERATIONS
    2.78 +#define HAVE_ALL_16_BIT_OPS
    2.79 +
    2.80 +#define nativeExchange16(ptr, value)			()
    2.81 +#define nativeCompareThenSet16(ptr, oldvalue, newvalue) ()
    2.82 +#define nativeTestThenSet16(ptr)    	     		()
    2.83 +#define nativeClear16(ptr)				()
    2.84 +#define nativeFetchThenIncrement16(ptr)   		()
    2.85 +#define nativeFetchThenDecrement16(ptr) 		()
    2.86 +#define nativeFetchThenAdd16(ptr, value) 		()
    2.87 +#define nativeFetchThenSubtract16(ptr, value) 		()
    2.88 +#define nativeIncrementThenFetch16(ptr) 		()
    2.89 +#define nativeDecrementThenFetch16(ptr) 		()
    2.90 +#define nativeAddThenFetch16(ptr, value) 		()
    2.91 +#define nativeSubtractThenFetch16(ptr, value) 		()
    2.92 +#endif
    2.93 +
    2.94 +#ifdef EMULATED_ATOMIC_OPERATIONS
    2.95 +#define HAVE_ALL_64_BIT_OPS
    2.96 +
    2.97 +#define nativeExchange64(ptr, value)			()
    2.98 +#define nativeCompareThenSet64(ptr, oldvalue, newvalue) ()
    2.99 +#define nativeTestThenSet64(ptr)    	     		()
   2.100 +#define nativeClear64(ptr)				()
   2.101 +#define nativeFetchThenIncrement64(ptr)   		()
   2.102 +#define nativeFetchThenDecrement64(ptr) 		()
   2.103 +#define nativeFetchThenAdd64(ptr, value) 		()
   2.104 +#define nativeFetchThenSubtract64(ptr, value) 		()
   2.105 +#define nativeIncrementThenFetch64(ptr) 		()
   2.106 +#define nativeDecrementThenFetch64(ptr) 		()
   2.107 +#define nativeAddThenFetch64(ptr, value) 		()
   2.108 +#define nativeSubtractThenFetch64(ptr, value) 		()
   2.109 +#endif
   2.110 +
   2.111 +/*
   2.112 +If any of the operations are not provided then we must emulate some of
   2.113 +them.
   2.114 + */
   2.115 +
   2.116 +#if !defined(HAVE_ALL_8_BIT_OPS) || !defined(HAVE_ALL_16_BIT_OPS) || !defined(HAVE_ALL_64_BIT_OPS)
   2.117 +
   2.118 +#include "SDL_mutex.h"
   2.119 +#include "SDL_error.h"
   2.120 +
   2.121 +static SDL_mutex * lock = NULL;
   2.122 +
   2.123 +static __inline__ void
   2.124 +privateWaitLock()
   2.125 +{
   2.126 +   if(NULL == lock)
   2.127 +   {
   2.128 +      lock = SDL_CreateMutex();
   2.129 +      if (NULL == lock)
   2.130 +      {
   2.131 +	 SDL_SetError("SDL_atomic.c: can't create a mutex");
   2.132 +	 return;
   2.133 +      }
   2.134 +   }
   2.135 +
   2.136 +   if (-1 == SDL_LockMutex(lock))
   2.137 +   {
   2.138 +      SDL_SetError("SDL_atomic.c: can't lock mutex");
   2.139 +   }
   2.140 +}
   2.141 +
   2.142 +static __inline__ void
   2.143 +privateUnlock()
   2.144 +{
   2.145 +   if (-1 == SDL_UnlockMutex(lock))
   2.146 +   {
   2.147 +      SDL_SetError("SDL_atomic.c: can't unlock mutex");
   2.148 +   }
   2.149 +}
   2.150 +
   2.151 +#endif
   2.152 +
   2.153 +/* 8 bit atomic operations */
   2.154 +
   2.155 +Uint8
   2.156 +SDL_AtomicExchange8(volatile Uint8 * ptr, Uint8 value)
   2.157 +{
   2.158 +#ifdef nativeExchange8
   2.159 +   return nativeExchange8(ptr, value);
   2.160 +#else
   2.161 +   Uint8 tmp = 0;
   2.162 +
   2.163 +   privateWaitLock();
   2.164 +   tmp = *ptr;
   2.165 +   *ptr = value;
   2.166 +   privateUnlock();
   2.167 +
   2.168 +   return tmp;
   2.169 +#endif
   2.170 +}
   2.171 +
   2.172 +SDL_bool
   2.173 +SDL_AtomicCompareThenSet8(volatile Uint8 * ptr, Uint8 oldvalue, Uint8 newvalue)
   2.174 +{
   2.175 +#ifdef nativeCompareThenSet8
   2.176 +   return (SDL_bool)nativeCompareThenSet8(ptr, oldvalue, newvalue);
   2.177 +#else
   2.178 +   SDL_bool result = SDL_FALSE;
   2.179 +
   2.180 +   privateWaitLock();
   2.181 +   result = (*ptr == oldvalue);
   2.182 +   if (result)
   2.183 +   {
   2.184 +      *ptr = newvalue;
   2.185 +   }
   2.186 +   privateUnlock();
   2.187 +
   2.188 +   return result;
   2.189 +#endif
   2.190 +}
   2.191 +
   2.192 +SDL_bool
   2.193 +SDL_AtomicTestThenSet8(volatile Uint8 * ptr)
   2.194 +{
   2.195 +#ifdef nativeTestThenSet8
   2.196 +   return (SDL_bool)nativeTestThenSet8(ptr);
   2.197 +#else
   2.198 +   SDL_bool result = SDL_FALSE;
   2.199 +
   2.200 +   privateWaitLock();
   2.201 +   result = (*ptr == 0);
   2.202 +   if (result)
   2.203 +   {
   2.204 +      *ptr = 1;
   2.205 +   }
   2.206 +   privateUnlock();
   2.207 +
   2.208 +   return result;
   2.209 +#endif
   2.210 +}
   2.211 +
   2.212 +void
   2.213 +SDL_AtomicClear8(volatile Uint8 * ptr)
   2.214 +{
   2.215 +#ifdef nativeClear8
   2.216 +   nativeClear8(ptr);
   2.217 +#else
   2.218 +   privateWaitLock();
   2.219 +   *ptr = 0;
   2.220 +   privateUnlock();
   2.221 +
   2.222 +   return;
   2.223 +#endif
   2.224 +}
   2.225 +
   2.226 +Uint8
   2.227 +SDL_AtomicFetchThenIncrement8(volatile Uint8 * ptr)
   2.228 +{
   2.229 +#ifdef nativeFetchThenIncrement8
   2.230 +   return nativeFetchThenIncrement8(ptr);
   2.231 +#else
   2.232 +   Uint8 tmp = 0;
   2.233 +
   2.234 +   privateWaitLock();
   2.235 +   tmp = *ptr;
   2.236 +   (*ptr)+= 1;
   2.237 +   privateUnlock();
   2.238 +
   2.239 +   return tmp;
   2.240 +#endif
   2.241 +}
   2.242 +
   2.243 +Uint8
   2.244 +SDL_AtomicFetchThenDecrement8(volatile Uint8 * ptr)
   2.245 +{
   2.246 +#ifdef nativeFetchThenDecrement8
   2.247 +   return nativeFetchThenDecrement8(ptr);
   2.248 +#else
   2.249 +   Uint8 tmp = 0;
   2.250 +
   2.251 +   privateWaitLock();
   2.252 +   tmp = *ptr;
   2.253 +   (*ptr) -= 1;
   2.254 +   privateUnlock();
   2.255 +
   2.256 +   return tmp;
   2.257 +#endif
   2.258 +}
   2.259 +
   2.260 +Uint8
   2.261 +SDL_AtomicFetchThenAdd8(volatile Uint8 * ptr, Uint8 value)
   2.262 +{
   2.263 +#ifdef nativeFetchThenAdd8
   2.264 +   return nativeFetchThenAdd8(ptr, value);
   2.265 +#else
   2.266 +   Uint8 tmp = 0;
   2.267 +
   2.268 +   privateWaitLock();
   2.269 +   tmp = *ptr;
   2.270 +   (*ptr)+= value;
   2.271 +   privateUnlock();
   2.272 +
   2.273 +   return tmp;
   2.274 +#endif
   2.275 +}
   2.276 +
   2.277 +Uint8
   2.278 +SDL_AtomicFetchThenSubtract8(volatile Uint8 * ptr, Uint8 value)
   2.279 +{
   2.280 +#ifdef nativeFetchThenSubtract8
   2.281 +   return nativeFetchThenSubtract8(ptr, value);
   2.282 +#else
   2.283 +   Uint8 tmp = 0;
   2.284 +
   2.285 +   privateWaitLock();
   2.286 +   tmp = *ptr;
   2.287 +   (*ptr)-= value;
   2.288 +   privateUnlock();
   2.289 +
   2.290 +   return tmp;
   2.291 +#endif
   2.292 +}
   2.293 +
   2.294 +Uint8
   2.295 +SDL_AtomicIncrementThenFetch8(volatile Uint8 * ptr)
   2.296 +{
   2.297 +#ifdef nativeIncrementThenFetch8
   2.298 +   return nativeIncrementThenFetch8(ptr);
   2.299 +#else
   2.300 +   Uint8 tmp = 0;
   2.301 +
   2.302 +   privateWaitLock();
   2.303 +   (*ptr)+= 1;
   2.304 +   tmp = *ptr;
   2.305 +   privateUnlock();
   2.306 +
   2.307 +   return tmp;
   2.308 +#endif
   2.309 +}
   2.310 +
   2.311 +Uint8
   2.312 +SDL_AtomicDecrementThenFetch8(volatile Uint8 * ptr)
   2.313 +{
   2.314 +#ifdef nativeDecrementThenFetch8
   2.315 +   return nativeDecrementThenFetch8(ptr);
   2.316 +#else
   2.317 +   Uint8 tmp = 0;
   2.318 +
   2.319 +   privateWaitLock();
   2.320 +   (*ptr)-= 1;
   2.321 +   tmp = *ptr;
   2.322 +   privateUnlock();
   2.323 +
   2.324 +   return tmp;
   2.325 +#endif
   2.326 +}
   2.327 +
   2.328 +Uint8
   2.329 +SDL_AtomicAddThenFetch8(volatile Uint8 * ptr, Uint8 value)
   2.330 +{
   2.331 +#ifdef nativeAddThenFetch8
   2.332 +   return nativeAddThenFetch8(ptr, value);
   2.333 +#else
   2.334 +   Uint8 tmp = 0;
   2.335 +
   2.336 +   privateWaitLock();
   2.337 +   (*ptr)+= value;
   2.338 +   tmp = *ptr;
   2.339 +   privateUnlock();
   2.340 +
   2.341 +   return tmp;
   2.342 +#endif
   2.343 +}
   2.344 +
   2.345 +Uint8
   2.346 +SDL_AtomicSubtractThenFetch8(volatile Uint8 * ptr, Uint8 value)
   2.347 +{
   2.348 +#ifdef nativeSubtractThenFetch8
   2.349 +   return nativeSubtractThenFetch8(ptr, value);
   2.350 +#else
   2.351 +   Uint8 tmp = 0;
   2.352 +
   2.353 +   privateWaitLock();
   2.354 +   (*ptr)-= value;
   2.355 +   tmp = *ptr;
   2.356 +   privateUnlock();
   2.357 +
   2.358 +   return tmp;
   2.359 +#endif
   2.360 +}
   2.361 +
   2.362 +/* 16 bit atomic operations */
   2.363 +
   2.364 +Uint16
   2.365 +SDL_AtomicExchange16(volatile Uint16 * ptr, Uint16 value)
   2.366 +{
   2.367 +#ifdef nativeExchange16
   2.368 +   return nativeExchange16(ptr, value);
   2.369 +#else
   2.370 +   Uint16 tmp = 0;
   2.371 +
   2.372 +   privateWaitLock();
   2.373 +   tmp = *ptr;
   2.374 +   *ptr = value;
   2.375 +   privateUnlock();
   2.376 +
   2.377 +   return tmp;
   2.378 +#endif
   2.379 +}
   2.380 +
   2.381 +SDL_bool
   2.382 +SDL_AtomicCompareThenSet16(volatile Uint16 * ptr, Uint16 oldvalue, Uint16 newvalue)
   2.383 +{
   2.384 +#ifdef nativeCompareThenSet16
   2.385 +   return (SDL_bool)nativeCompareThenSet16(ptr, oldvalue, newvalue);
   2.386 +#else
   2.387 +   SDL_bool result = SDL_FALSE;
   2.388 +
   2.389 +   privateWaitLock();
   2.390 +   result = (*ptr == oldvalue);
   2.391 +   if (result)
   2.392 +   {
   2.393 +      *ptr = newvalue;
   2.394 +   }
   2.395 +   privateUnlock();
   2.396 +
   2.397 +   return result;
   2.398 +#endif
   2.399 +}
   2.400 +
   2.401 +SDL_bool
   2.402 +SDL_AtomicTestThenSet16(volatile Uint16 * ptr)
   2.403 +{
   2.404 +#ifdef nativeTestThenSet16
   2.405 +   return (SDL_bool)nativeTestThenSet16(ptr);
   2.406 +#else
   2.407 +   SDL_bool result = SDL_FALSE;
   2.408 +
   2.409 +   privateWaitLock();
   2.410 +   result = (*ptr == 0);
   2.411 +   if (result)
   2.412 +   {
   2.413 +      *ptr = 1;
   2.414 +   }
   2.415 +   privateUnlock();
   2.416 +
   2.417 +   return result;
   2.418 +#endif
   2.419 +}
   2.420 +
   2.421 +void
   2.422 +SDL_AtomicClear16(volatile Uint16 * ptr)
   2.423 +{
   2.424 +#ifdef nativeClear16
   2.425 +   nativeClear16(ptr);
   2.426 +#else
   2.427 +   privateWaitLock();
   2.428 +   *ptr = 0;
   2.429 +   privateUnlock();
   2.430 +
   2.431 +   return;
   2.432 +#endif
   2.433 +}
   2.434 +
   2.435 +Uint16
   2.436 +SDL_AtomicFetchThenIncrement16(volatile Uint16 * ptr)
   2.437 +{
   2.438 +#ifdef nativeFetchThenIncrement16
   2.439 +   return nativeFetchThenIncrement16(ptr);
   2.440 +#else
   2.441 +   Uint16 tmp = 0;
   2.442 +
   2.443 +   privateWaitLock();
   2.444 +   tmp = *ptr;
   2.445 +   (*ptr)+= 1;
   2.446 +   privateUnlock();
   2.447 +
   2.448 +   return tmp;
   2.449 +#endif
   2.450 +}
   2.451 +
   2.452 +Uint16
   2.453 +SDL_AtomicFetchThenDecrement16(volatile Uint16 * ptr)
   2.454 +{
   2.455 +#ifdef nativeFetchThenDecrement16
   2.456 +   return nativeFetchThenDecrement16(ptr);
   2.457 +#else
   2.458 +   Uint16 tmp = 0;
   2.459 +
   2.460 +   privateWaitLock();
   2.461 +   tmp = *ptr;
   2.462 +   (*ptr) -= 1;
   2.463 +   privateUnlock();
   2.464 +
   2.465 +   return tmp;
   2.466 +#endif
   2.467 +}
   2.468 +
   2.469 +Uint16
   2.470 +SDL_AtomicFetchThenAdd16(volatile Uint16 * ptr, Uint16 value)
   2.471 +{
   2.472 +#ifdef nativeFetchThenAdd16
   2.473 +   return nativeFetchThenAdd16(ptr, value);
   2.474 +#else
   2.475 +   Uint16 tmp = 0;
   2.476 +
   2.477 +   privateWaitLock();
   2.478 +   tmp = *ptr;
   2.479 +   (*ptr)+= value;
   2.480 +   privateUnlock();
   2.481 +
   2.482 +   return tmp;
   2.483 +#endif
   2.484 +}
   2.485 +
   2.486 +Uint16
   2.487 +SDL_AtomicFetchThenSubtract16(volatile Uint16 * ptr, Uint16 value)
   2.488 +{
   2.489 +#ifdef nativeFetchThenSubtract16
   2.490 +   return nativeFetchThenSubtract16(ptr, value);
   2.491 +#else
   2.492 +   Uint16 tmp = 0;
   2.493 +
   2.494 +   privateWaitLock();
   2.495 +   tmp = *ptr;
   2.496 +   (*ptr)-= value;
   2.497 +   privateUnlock();
   2.498 +
   2.499 +   return tmp;
   2.500 +#endif
   2.501 +}
   2.502 +
   2.503 +Uint16
   2.504 +SDL_AtomicIncrementThenFetch16(volatile Uint16 * ptr)
   2.505 +{
   2.506 +#ifdef nativeIncrementThenFetch16
   2.507 +   return nativeIncrementThenFetch16(ptr);
   2.508 +#else
   2.509 +   Uint16 tmp = 0;
   2.510 +
   2.511 +   privateWaitLock();
   2.512 +   (*ptr)+= 1;
   2.513 +   tmp = *ptr;
   2.514 +   privateUnlock();
   2.515 +
   2.516 +   return tmp;
   2.517 +#endif
   2.518 +}
   2.519 +
   2.520 +Uint16
   2.521 +SDL_AtomicDecrementThenFetch16(volatile Uint16 * ptr)
   2.522 +{
   2.523 +#ifdef nativeDecrementThenFetch16
   2.524 +   return nativeDecrementThenFetch16(ptr);
   2.525 +#else
   2.526 +   Uint16 tmp = 0;
   2.527 +
   2.528 +   privateWaitLock();
   2.529 +   (*ptr)-= 1;
   2.530 +   tmp = *ptr;
   2.531 +   privateUnlock();
   2.532 +
   2.533 +   return tmp;
   2.534 +#endif
   2.535 +}
   2.536 +
   2.537 +Uint16
   2.538 +SDL_AtomicAddThenFetch16(volatile Uint16 * ptr, Uint16 value)
   2.539 +{
   2.540 +#ifdef nativeAddThenFetch16
   2.541 +   return nativeAddThenFetch16(ptr, value);
   2.542 +#else
   2.543 +   Uint16 tmp = 0;
   2.544 +
   2.545 +   privateWaitLock();
   2.546 +   (*ptr)+= value;
   2.547 +   tmp = *ptr;
   2.548 +   privateUnlock();
   2.549 +
   2.550 +   return tmp;
   2.551 +#endif
   2.552 +}
   2.553 +
   2.554 +Uint16
   2.555 +SDL_AtomicSubtractThenFetch16(volatile Uint16 * ptr, Uint16 value)
   2.556 +{
   2.557 +#ifdef nativeSubtractThenFetch16
   2.558 +   return nativeSubtractThenFetch16(ptr, value);
   2.559 +#else
   2.560 +   Uint16 tmp = 0;
   2.561 +
   2.562 +   privateWaitLock();
   2.563 +   (*ptr)-= value;
   2.564 +   tmp = *ptr;
   2.565 +   privateUnlock();
   2.566 +
   2.567 +   return tmp;
   2.568 +#endif
   2.569 +}
   2.570 +
   2.571 +/* 64 bit atomic operations */
   2.572 +#ifdef SDL_HAS_64BIT_TYPE
   2.573 +
   2.574 +Uint64
   2.575 +SDL_AtomicExchange64(volatile Uint64 * ptr, Uint64 value)
   2.576 +{
   2.577 +#ifdef nativeExchange64
   2.578 +   return nativeExchange64(ptr, value);
   2.579 +#else
   2.580 +   Uint64 tmp = 0;
   2.581 +
   2.582 +   privateWaitLock();
   2.583 +   tmp = *ptr;
   2.584 +   *ptr = value;
   2.585 +   privateUnlock();
   2.586 +
   2.587 +   return tmp;
   2.588 +#endif
   2.589 +}
   2.590 +
   2.591 +SDL_bool
   2.592 +SDL_AtomicCompareThenSet64(volatile Uint64 * ptr, Uint64 oldvalue, Uint64 newvalue)
   2.593 +{
   2.594 +#ifdef nativeCompareThenSet64
   2.595 +   return (SDL_bool)nativeCompareThenSet64(ptr, oldvalue, newvalue);
   2.596 +#else
   2.597 +   SDL_bool result = SDL_FALSE;
   2.598 +
   2.599 +   privateWaitLock();
   2.600 +   result = (*ptr == oldvalue);
   2.601 +   if (result)
   2.602 +   {
   2.603 +      *ptr = newvalue;
   2.604 +   }
   2.605 +   privateUnlock();
   2.606 +
   2.607 +   return result;
   2.608 +#endif
   2.609 +}
   2.610 +
   2.611 +SDL_bool
   2.612 +SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
   2.613 +{
   2.614 +#ifdef nativeTestThenSet64
   2.615 +   return (SDL_bool)nativeTestThenSet64(ptr);
   2.616 +#else
   2.617 +   SDL_bool result = SDL_FALSE;
   2.618 +
   2.619 +   privateWaitLock();
   2.620 +   result = (*ptr == 0);
   2.621 +   if (result)
   2.622 +   {
   2.623 +      *ptr = 1;
   2.624 +   }
   2.625 +   privateUnlock();
   2.626 +
   2.627 +   return result;
   2.628 +#endif
   2.629 +}
   2.630 +
   2.631 +void
   2.632 +SDL_AtomicClear64(volatile Uint64 * ptr)
   2.633 +{
   2.634 +#ifdef nativeClear64
   2.635 +   nativeClear64(ptr);
   2.636 +#else
   2.637 +   privateWaitLock();
   2.638 +   *ptr = 0;
   2.639 +   privateUnlock();
   2.640 +
   2.641 +   return;
   2.642 +#endif
   2.643 +}
   2.644 +
   2.645 +Uint64
   2.646 +SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
   2.647 +{
   2.648 +#ifdef nativeFetchThenIncrement64
   2.649 +   return nativeFetchThenIncrement64(ptr);
   2.650 +#else
   2.651 +   Uint64 tmp = 0;
   2.652 +
   2.653 +   privateWaitLock();
   2.654 +   tmp = *ptr;
   2.655 +   (*ptr)+= 1;
   2.656 +   privateUnlock();
   2.657 +
   2.658 +   return tmp;
   2.659 +#endif
   2.660 +}
   2.661 +
   2.662 +Uint64
   2.663 +SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
   2.664 +{
   2.665 +#ifdef nativeFetchThenDecrement64
   2.666 +   return nativeFetchThenDecrement64(ptr);
   2.667 +#else
   2.668 +   Uint64 tmp = 0;
   2.669 +
   2.670 +   privateWaitLock();
   2.671 +   tmp = *ptr;
   2.672 +   (*ptr) -= 1;
   2.673 +   privateUnlock();
   2.674 +
   2.675 +   return tmp;
   2.676 +#endif
   2.677 +}
   2.678 +
   2.679 +Uint64
   2.680 +SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
   2.681 +{
   2.682 +#ifdef nativeFetchThenAdd64
   2.683 +   return nativeFetchThenAdd64(ptr, value);
   2.684 +#else
   2.685 +   Uint64 tmp = 0;
   2.686 +
   2.687 +   privateWaitLock();
   2.688 +   tmp = *ptr;
   2.689 +   (*ptr)+= value;
   2.690 +   privateUnlock();
   2.691 +
   2.692 +   return tmp;
   2.693 +#endif
   2.694 +}
   2.695 +
   2.696 +Uint64
   2.697 +SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
   2.698 +{
   2.699 +#ifdef nativeFetchThenSubtract64
   2.700 +   return nativeFetchThenSubtract64(ptr, value);
   2.701 +#else
   2.702 +   Uint64 tmp = 0;
   2.703 +
   2.704 +   privateWaitLock();
   2.705 +   tmp = *ptr;
   2.706 +   (*ptr)-= value;
   2.707 +   privateUnlock();
   2.708 +
   2.709 +   return tmp;
   2.710 +#endif
   2.711 +}
   2.712 +
   2.713 +Uint64
   2.714 +SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
   2.715 +{
   2.716 +#ifdef nativeIncrementThenFetch64
   2.717 +   return nativeIncrementThenFetch64(ptr);
   2.718 +#else
   2.719 +   Uint64 tmp = 0;
   2.720 +
   2.721 +   privateWaitLock();
   2.722 +   (*ptr)+= 1;
   2.723 +   tmp = *ptr;
   2.724 +   privateUnlock();
   2.725 +
   2.726 +   return tmp;
   2.727 +#endif
   2.728 +}
   2.729 +
   2.730 +Uint64
   2.731 +SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
   2.732 +{
   2.733 +#ifdef nativeDecrementThenFetch64
   2.734 +   return nativeDecrementThenFetch64(ptr);
   2.735 +#else
   2.736 +   Uint64 tmp = 0;
   2.737 +
   2.738 +   privateWaitLock();
   2.739 +   (*ptr)-= 1;
   2.740 +   tmp = *ptr;
   2.741 +   privateUnlock();
   2.742 +
   2.743 +   return tmp;
   2.744 +#endif
   2.745 +}
   2.746 +
   2.747 +Uint64
   2.748 +SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
   2.749 +{
   2.750 +#ifdef nativeAddThenFetch64
   2.751 +   return nativeAddThenFetch64(ptr, value);
   2.752 +#else
   2.753 +   Uint64 tmp = 0;
   2.754 +
   2.755 +   privateWaitLock();
   2.756 +   (*ptr)+= value;
   2.757 +   tmp = *ptr;
   2.758 +   privateUnlock();
   2.759 +
   2.760 +   return tmp;
   2.761 +#endif
   2.762 +}
   2.763 +
   2.764 +Uint64
   2.765 +SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
   2.766 +{
   2.767 +#ifdef nativeSubtractThenFetch64
   2.768 +   return nativeSubtractThenFetch64(ptr, value);
   2.769 +#else
   2.770 +   Uint64 tmp = 0;
   2.771 +
   2.772 +   privateWaitLock();
   2.773 +   (*ptr)-= value;
   2.774 +   tmp = *ptr;
   2.775 +   privateUnlock();
   2.776 +
   2.777 +   return tmp;
   2.778 +#endif
   2.779 +}
   2.780 +#endif
   2.781 +
   2.782 +/* QNX native 32 bit atomic operations */
   2.783 +
   2.784 +Uint32
   2.785 +SDL_AtomicExchange32(volatile Uint32 * ptr, Uint32 value)
   2.786 +{
   2.787 +   Uint32 tmp = 0;
   2.788 +
   2.789 +   privateWaitLock();
   2.790 +   tmp = *ptr;
   2.791 +   *ptr = value;
   2.792 +   privateUnlock();
   2.793 +
   2.794 +   return tmp;
   2.795 +}
   2.796 +
   2.797 +SDL_bool
   2.798 +SDL_AtomicCompareThenSet32(volatile Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue)
   2.799 +{
   2.800 +   SDL_bool result = SDL_FALSE;
   2.801 +
   2.802 +   privateWaitLock();
   2.803 +   result = (*ptr == oldvalue);
   2.804 +   if (result)
   2.805 +   {
   2.806 +      *ptr = newvalue;
   2.807 +   }
   2.808 +   privateUnlock();
   2.809 +
   2.810 +   return result;
   2.811 +}
   2.812 +
   2.813 +SDL_bool
   2.814 +SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
   2.815 +{
   2.816 +   SDL_bool result = SDL_FALSE;
   2.817 +
   2.818 +   privateWaitLock();
   2.819 +   result = (*ptr == 0);
   2.820 +   if (result)
   2.821 +   {
   2.822 +      *ptr = 1;
   2.823 +   }
   2.824 +   privateUnlock();
   2.825 +
   2.826 +   return result;
   2.827 +}
   2.828 +
   2.829 +void
   2.830 +SDL_AtomicClear32(volatile Uint32 * ptr)
   2.831 +{
   2.832 +   atomic_clr(ptr, 0xFFFFFFFF);
   2.833 +}
   2.834 +
   2.835 +Uint32
   2.836 +SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
   2.837 +{
   2.838 +   return atomic_add_value(ptr, 0x00000001);
   2.839 +}
   2.840 +
   2.841 +Uint32
   2.842 +SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
   2.843 +{
   2.844 +   return atomic_sub_value(ptr, 0x00000001);
   2.845 +}
   2.846 +
   2.847 +Uint32
   2.848 +SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
   2.849 +{
   2.850 +   return atomic_add_value(ptr, value);
   2.851 +}
   2.852 +
   2.853 +Uint32
   2.854 +SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
   2.855 +{
   2.856 +   return atomic_sub_value(ptr, value);
   2.857 +}
   2.858 +
   2.859 +Uint32
   2.860 +SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
   2.861 +{
   2.862 +   atomic_add(ptr, 0x00000001);
   2.863 +   return atomic_add_value(ptr, 0x00000000);
   2.864 +}
   2.865 +
   2.866 +Uint32
   2.867 +SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
   2.868 +{
   2.869 +   atomic_sub(ptr, 0x00000001);
   2.870 +   return atomic_sub_value(ptr, 0x00000000);
   2.871 +}
   2.872 +
   2.873 +Uint32
   2.874 +SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
   2.875 +{
   2.876 +   atomic_add(ptr, value);
   2.877 +   return atomic_add_value(ptr, 0x00000000);
   2.878 +}
   2.879 +
   2.880 +Uint32
   2.881 +SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
   2.882 +{
   2.883 +   atomic_sub(ptr, value);
   2.884 +   return atomic_sub_value(ptr, 0x00000000);
   2.885 +}