From 82244f298ced5fd96dec5ee64c8a5b957b7dfdb4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Aug 2011 15:44:03 -0700 Subject: Add reference counting to the ALC contexts --- OpenAL32/Include/alMain.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'OpenAL32') diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 2f30a953..0a006ee9 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -229,6 +229,36 @@ void *GetSymbol(void *handle, const char *name); #endif +#ifdef __GNUC__ +typedef ALuint RefCount; +static __inline RefCount IncrementRef(volatile RefCount *ptr) +{ return __sync_add_and_fetch(ptr, 1); } +static __inline RefCount DecrementRef(volatile RefCount *ptr) +{ return __sync_sub_and_fetch(ptr, 1); } + +#elif defined(_WIN32) + +typedef LONG RefCount; +static __inline RefCount IncrementRef(volatile RefCount *ptr) +{ return InterlockedInrement(ptr); } +static __inline RefCount DecrementRef(volatile RefCount *ptr) +{ return InterlockedDecrement(ptr); } + +#elif defined(__APPLE__) + +#include + +typedef int32_t RefCount; +static __inline RefCount IncrementRef(volatile RefCount *ptr) +{ return OSAtomicIncrement32Barrier(ptr); } +static __inline RefCount DecrementRef(volatile RefCount *ptr) +{ return OSAtomicDecrement32Barrier(ptr); } + +#else +#error "No atomic functions available on this platform!" +#endif + + #include "alListener.h" #include "alu.h" @@ -477,6 +507,8 @@ struct ALCdevice_struct struct ALCcontext_struct { + volatile RefCount ref; + ALlistener Listener; UIntMap SourceMap; -- cgit v1.2.3