aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/alThunk.c
diff options
context:
space:
mode:
Diffstat (limited to 'OpenAL32/alThunk.c')
-rw-r--r--OpenAL32/alThunk.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/OpenAL32/alThunk.c b/OpenAL32/alThunk.c
index d3892c97..0d90760a 100644
--- a/OpenAL32/alThunk.c
+++ b/OpenAL32/alThunk.c
@@ -28,8 +28,8 @@
#include "almalloc.h"
-static ATOMIC(ALenum) *ThunkArray;
-static ALuint ThunkArraySize;
+static ATOMIC_FLAG *ThunkArray;
+static ALsizei ThunkArraySize;
static RWLock ThunkLock;
void ThunkInit(void)
@@ -49,12 +49,12 @@ void ThunkExit(void)
ALenum NewThunkEntry(ALuint *index)
{
void *NewList;
- ALuint i;
+ ALsizei i;
ReadLock(&ThunkLock);
for(i = 0;i < ThunkArraySize;i++)
{
- if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE, almemory_order_acq_rel) == AL_FALSE)
+ if(!ATOMIC_FLAG_TEST_AND_SET(&ThunkArray[i], almemory_order_acq_rel))
{
ReadUnlock(&ThunkLock);
*index = i+1;
@@ -69,7 +69,7 @@ ALenum NewThunkEntry(ALuint *index)
*/
for(;i < ThunkArraySize;i++)
{
- if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE, almemory_order_acq_rel) == AL_FALSE)
+ if(!ATOMIC_FLAG_TEST_AND_SET(&ThunkArray[i], almemory_order_acq_rel))
{
WriteUnlock(&ThunkLock);
*index = i+1;
@@ -89,17 +89,20 @@ ALenum NewThunkEntry(ALuint *index)
ThunkArray = NewList;
ThunkArraySize *= 2;
- ATOMIC_STORE_SEQ(&ThunkArray[i], AL_TRUE);
+ ATOMIC_FLAG_TEST_AND_SET(&ThunkArray[i], almemory_order_seq_cst);
+ *index = ++i;
+
+ for(;i < ThunkArraySize;i++)
+ ATOMIC_FLAG_CLEAR(&ThunkArray[i], almemory_order_relaxed);
WriteUnlock(&ThunkLock);
- *index = i+1;
return AL_NO_ERROR;
}
void FreeThunkEntry(ALuint index)
{
ReadLock(&ThunkLock);
- if(index > 0 && index <= ThunkArraySize)
- ATOMIC_STORE_SEQ(&ThunkArray[index-1], AL_FALSE);
+ if(index > 0 && (ALsizei)index <= ThunkArraySize)
+ ATOMIC_FLAG_CLEAR(&ThunkArray[index-1], almemory_order_release);
ReadUnlock(&ThunkLock);
}