diff options
author | Chris Robinson <[email protected]> | 2011-08-28 15:44:03 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-28 15:44:03 -0700 |
commit | 82244f298ced5fd96dec5ee64c8a5b957b7dfdb4 (patch) | |
tree | b6aa61052cbc1aef2091f41edfc4a6e27034ffbd /OpenAL32 | |
parent | 3ab20d4ccbdcaded207cd31ff63c4f9782ba402b (diff) |
Add reference counting to the ALC contexts
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMain.h | 32 |
1 files changed, 32 insertions, 0 deletions
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 <libkern/OSAtomic.h> + +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; |