diff options
author | Chris Robinson <[email protected]> | 2011-08-29 00:50:55 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-29 00:50:55 -0700 |
commit | 58078e2c1eb2a3778462c1d0632b0a2c85fe82ec (patch) | |
tree | 434158738f276fd2ef6f1c855fa895044a348822 /OpenAL32/Include | |
parent | 01503f8a7bd99136445008eba5bed5af483a7aea (diff) |
Use atomic exchanges when checking for updates to objects' internal parameters
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r-- | OpenAL32/Include/alMain.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 641baf7c..fa11a3d8 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -249,6 +249,12 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return __sync_sub_and_fetch(ptr, 1); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + return __sync_lock_test_and_set(ptr, newval); \ +} + #elif defined(_WIN32) typedef LONG RefCount; @@ -257,6 +263,16 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return InterlockedDecrement(ptr); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + union { \ + volatile T *t; \ + volatile LONG *l; \ + } u = { ptr }; \ + return InterlockedExchange(u.l, newval); \ +} + #elif defined(__APPLE__) #include <libkern/OSAtomic.h> @@ -267,10 +283,29 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return OSAtomicDecrement32Barrier(ptr); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + union { \ + volatile T *t; \ + volatile int32_t *l; \ + } u = { ptr }; \ + /* Really? No regular old atomic swap? */ \ + T oldval; \ + do { \ + oldval = *u.i; \ + } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, u.i)); \ + return oldval; \ +} + #else #error "No atomic functions available on this platform!" #endif +DECL_TEMPLATE(ALenum) + +#undef DECL_TEMPLATE + #include "alListener.h" #include "alu.h" |