aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-04-14 15:29:30 -0700
committerChris Robinson <[email protected]>2017-04-14 16:14:05 -0700
commit9e60eea93b029f1c2d2e394e2352b86cd7c65d12 (patch)
tree1d3b715c1b4316636a0cd7664231d4fd90965294 /OpenAL32
parent6476f3277ae94d034f8bf21fba66473b71bcf3a2 (diff)
Use atomic flags for the thunk array
Diffstat (limited to 'OpenAL32')
-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);
}