include/SDL_atomic.h
changeset 3202 3aa519a5c676
parent 3199 3e1bf2b8bd81
child 3216 48a80f2a7ff2
     1.1 --- a/include/SDL_atomic.h	Wed Jun 24 22:24:23 2009 +0000
     1.2 +++ b/include/SDL_atomic.h	Mon Jun 29 19:54:43 2009 +0000
     1.3 @@ -29,7 +29,6 @@
     1.4  #ifndef _SDL_atomic_h_
     1.5  #define _SDL_atomic_h_
     1.6  
     1.7 -
     1.8  #include "SDL_stdinc.h"
     1.9  #include "SDL_platform.h"
    1.10  
    1.11 @@ -42,72 +41,51 @@
    1.12  /* *INDENT-ON* */
    1.13  #endif
    1.14  
    1.15 -/* *INDENT-OFF* */
    1.16  /**
    1.17 - * \def SDL_AtomicBusyWait32 (ptr)
    1.18 - *
    1.19 - * \brief Implements a simple busy wait for use with
    1.20 - * SDL_AtomicTestThenSet and SDL_AtomicClear.
    1.21 - *
    1.22 - * Note: This can be an infinite loop.
    1.23 - *
    1.24 + * These operations may, or may not, actually be implemented using
    1.25 + * processor specific atomic operations. When possible they are
    1.26 + * implemented as true processor specific atomic operations. When that
    1.27 + * is not possible the are implemented using locks that *do* use the
    1.28 + * available atomic operations. In rare cases they may be implemented
    1.29 + * using SDL's mutex fuctions.
    1.30   */
    1.31 -#define SDL_AtomicBusyWait32(ptr)		\
    1.32 -   {						\
    1.33 -   while (!SDL_AtomicTestThenSet32(ptr)		\
    1.34 -      {						\
    1.35 -      };					\
    1.36 -   };
    1.37 -
    1.38 -/**
    1.39 - * \def SDL_AtomicWait32(ptr)
    1.40 - *
    1.41 - * \brief A safer way to wait for a test-then-set lock to be cleared.
    1.42 - *
    1.43 - * This assumes that the SDL_Sleep(0) call acts as a thread_yeild
    1.44 - * operation. 
    1.45 - *
    1.46 - */
    1.47 -#define SDL_AtomicWait32(ptr)			\
    1.48 -   {						\
    1.49 -   while (!SDL_AtomicTestThenSet32(ptr)		\
    1.50 -      {						\
    1.51 -	 SDL_Sleep(0);				\
    1.52 -      };                                        \
    1.53 -   };
    1.54 -
    1.55 -/**
    1.56 - * \def SDL_AtomicBusyWait64(ptr)
    1.57 - *
    1.58 - * \brief 64 bit version of busy wait
    1.59 - *
    1.60 - * \sa SDL_AtomicBusyWait32
    1.61 - */
    1.62 -#define SDL_AtomicBusyWait64(ptr)		\
    1.63 -   {						\
    1.64 -   while (!SDL_AtomicTestThenSet64(ptr)		\
    1.65 -      {						\
    1.66 -      };					\
    1.67 -   };
    1.68 -
    1.69 -/**
    1.70 - * \def SDL_AtomicWait64(ptr)
    1.71 - *
    1.72 - * \brief 64 bit version of SDL_AtomicWait32
    1.73 - *
    1.74 - * \sa SDL_AtomicWait32
    1.75 - */
    1.76 -#define SDL_AtomicWait64(ptr)			\
    1.77 -   {						\
    1.78 -   while (!SDL_AtomicTestThenSet64(ptr)		\
    1.79 -      {						\
    1.80 -	 SDL_Sleep(0);				\
    1.81 -      };                                        \
    1.82 -   };
    1.83 -/* *INDENT-ON* */
    1.84  
    1.85  /* Function prototypes */
    1.86  
    1.87 +/* 8 bit atomic operations */
    1.88 +
    1.89 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicExchange8(Uint8 * ptr, Uint8 value);
    1.90 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet8(Uint8 * ptr,
    1.91 +                                                            Uint8 oldvalue, Uint8 newvalue);
    1.92 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet8(Uint8 * ptr);
    1.93 +extern DECLSPEC void SDLCALL SDL_AtomicClear8(Uint8 * ptr);
    1.94 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenIncrement8(Uint8 * ptr);
    1.95 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenDecrement8(Uint8 * ptr);
    1.96 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenAdd8(Uint8 * ptr, Uint8 value);
    1.97 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenSubtract8(Uint8 * ptr, Uint8 value);
    1.98 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicIncrementThenFetch8(Uint8 * ptr);
    1.99 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicDecrementThenFetch8(Uint8 * ptr);
   1.100 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicAddThenFetch8(Uint8 * ptr, Uint8 value);
   1.101 +extern DECLSPEC Uint8 SDLCALL SDL_AtomicSubtractThenFetch8(Uint8 * ptr, Uint8 value);
   1.102 +
   1.103 +/* 16 bit atomic operations */
   1.104 +
   1.105 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicExchange16(Uint16 * ptr, Uint16 value);
   1.106 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet16(Uint16 * ptr,
   1.107 +                                                            Uint16 oldvalue, Uint16 newvalue);
   1.108 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet16(Uint16 * ptr);
   1.109 +extern DECLSPEC void SDLCALL SDL_AtomicClear16(Uint16 * ptr);
   1.110 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenIncrement16(Uint16 * ptr);
   1.111 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenDecrement16(Uint16 * ptr);
   1.112 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenAdd16(Uint16 * ptr, Uint16 value);
   1.113 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenSubtract16(Uint16 * ptr, Uint16 value);
   1.114 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicIncrementThenFetch16(Uint16 * ptr);
   1.115 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicDecrementThenFetch16(Uint16 * ptr);
   1.116 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicAddThenFetch16(Uint16 * ptr, Uint16 value);
   1.117 +extern DECLSPEC Uint16 SDLCALL SDL_AtomicSubtractThenFetch16(Uint16 * ptr, Uint16 value);
   1.118 +
   1.119 +/* 32 bit atomic operations */
   1.120 +
   1.121  /**
   1.122   * \fn int SDL_AtomicExchange32(Uint32 * ptr, Uint32 value)
   1.123   *
   1.124 @@ -252,6 +230,7 @@
   1.125   */
   1.126  extern DECLSPEC Uint32 SDLCALL SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value);
   1.127  
   1.128 +/* 64 bit atomic operations */
   1.129  #ifdef SDL_HAS_64BIT_TYPE
   1.130  
   1.131  extern DECLSPEC Uint64 SDLCALL SDL_AtomicExchange64(Uint64 * ptr, Uint64 value);
   1.132 @@ -267,7 +246,7 @@
   1.133  extern DECLSPEC Uint64 SDLCALL SDL_AtomicDecrementThenFetch64(Uint64 * ptr);
   1.134  extern DECLSPEC Uint64 SDLCALL SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value);
   1.135  extern DECLSPEC Uint64 SDLCALL SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value);
   1.136 -#endif
   1.137 +#endif /*  SDL_HAS_64BIT_TYPE */
   1.138  
   1.139  /* Ends C function definitions when using C++ */
   1.140  #ifdef __cplusplus