include/SDL_atomic.h
changeset 3261 72b542f34739
parent 3237 916f396fe65d
child 3407 d3baf5ac4e37
     1.1 --- a/include/SDL_atomic.h	Mon Sep 07 16:04:44 2009 +0000
     1.2 +++ b/include/SDL_atomic.h	Thu Sep 17 20:35:12 2009 +0000
     1.3 @@ -18,6 +18,8 @@
     1.4  
     1.5      Sam Lantinga
     1.6      slouken@libsdl.org
     1.7 +
     1.8 +    Contributed by Bob Pendleton, bob@pendleton.com
     1.9   */
    1.10  
    1.11  /**
    1.12 @@ -46,48 +48,50 @@
    1.13   * processor specific atomic operations. When possible they are
    1.14   * implemented as true processor specific atomic operations. When that
    1.15   * is not possible the are implemented using locks that *do* use the
    1.16 - * available atomic operations. In rare cases they may be implemented
    1.17 - * using SDL's mutex fuctions.
    1.18 + * available atomic operations.
    1.19 + *
    1.20 + * At the very minimum spin locks must be implemented. Without spin
    1.21 + * locks it is not possible (AFAICT) to emulate the rest of the atomic
    1.22 + * operations.
    1.23   */
    1.24  
    1.25  /* Function prototypes */
    1.26  
    1.27 +/**
    1.28 + * SDL AtomicLock.
    1.29 + * 
    1.30 + * The spin lock functions and type are required and can not be
    1.31 + * emulated because they are used in the emulation code.
    1.32 + */
    1.33 +
    1.34 +typedef volatile Uint32 SDL_SpinLock;
    1.35 +
    1.36 +/**
    1.37 + * \fn  void SDL_AtomicLock(SDL_SpinLock *lock);
    1.38 + *
    1.39 + * \brief Lock a spin lock by setting it to a none zero value.
    1.40 + *
    1.41 + * \param lock points to the lock.
    1.42 + *
    1.43 + */
    1.44 +extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
    1.45 +
    1.46 +/**
    1.47 + * \fn  void SDL_AtomicUnlock(SDL_SpinLock *lock);
    1.48 + *
    1.49 + * \brief Unlock a spin lock by setting it to 0. Always returns immediately
    1.50 + *
    1.51 + * \param lock points to the lock.
    1.52 + *
    1.53 + */
    1.54 +extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
    1.55 +
    1.56  /* 32 bit atomic operations */
    1.57  
    1.58  /**
    1.59 - * \fn int SDL_AtomicExchange32(volatile Uint32 * ptr, Uint32 value)
    1.60 - *
    1.61 - * \brief Atomically exchange two 32 bit values.
    1.62 - *
    1.63 - * \return the value point to by ptr.
    1.64 - *
    1.65 - * \param ptr points to the value to be fetched from *ptr.  
    1.66 - * \param value is value to be stored at *ptr.
    1.67 - *
    1.68 - * The current value stored at *ptr is returned and it is replaced
    1.69 - * with value. This function can be used to implement SDL_TestThenSet.
    1.70 - *
    1.71 - */
    1.72 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicExchange32(volatile Uint32 * ptr, Uint32 value);
    1.73 -
    1.74 -/**
    1.75 - * \fn int SDL_AtomicCompareThenSet32(volatile Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue)
    1.76 - *
    1.77 - * \brief If *ptr == oldvalue then replace the contents of *ptr by new value. 
    1.78 - *
    1.79 - * \return true if the newvalue was stored.
    1.80 - *
    1.81 - * \param *ptr is the value to be compared and replaced.
    1.82 - * \param oldvalue is value to be compared to *ptr.
    1.83 - * \param newvalue is value to be stored at *ptr.
    1.84 - *
    1.85 - */
    1.86 -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet32(volatile Uint32 * ptr,
    1.87 -                                                            Uint32 oldvalue, Uint32 newvalue);
    1.88 -/**
    1.89   * \fn  SDL_bool SDL_AtomicTestThenSet32(volatile Uint32 * ptr);
    1.90   *
    1.91 - * \brief Check to see if *ptr == 0 and set it to non-zero.
    1.92 + * \brief Check to see if *ptr == 0 and set it to 1.
    1.93   *
    1.94   * \return SDL_True if the value pointed to by ptr was zero and
    1.95   * SDL_False if it was not zero
    1.96 @@ -211,9 +215,6 @@
    1.97  /* 64 bit atomic operations */
    1.98  #ifdef SDL_HAS_64BIT_TYPE
    1.99  
   1.100 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicExchange64(volatile Uint64 * ptr, Uint64 value);
   1.101 -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet64(volatile Uint64 * ptr,
   1.102 -                                                            Uint64 oldvalue, Uint64 newvalue);
   1.103  extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet64(volatile Uint64 * ptr);
   1.104  extern DECLSPEC void SDLCALL SDL_AtomicClear64(volatile Uint64 * ptr);
   1.105  extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr);