diff options
author | Chris Robinson <[email protected]> | 2014-09-03 15:49:31 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-09-03 15:49:31 -0700 |
commit | 7f5497b86385cbf7d1164b80f8f420e0657a6d38 (patch) | |
tree | cf1c4c6768493f923c7006d7463b8232d2846735 /OpenAL32/alThunk.c | |
parent | 5840f5e76f2b803589074de254f282a5844c77ee (diff) |
Use proper atomics for the thunk array
Diffstat (limited to 'OpenAL32/alThunk.c')
-rw-r--r-- | OpenAL32/alThunk.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/OpenAL32/alThunk.c b/OpenAL32/alThunk.c index 400b18e3..ed0aa83c 100644 --- a/OpenAL32/alThunk.c +++ b/OpenAL32/alThunk.c @@ -26,33 +26,33 @@ #include "alThunk.h" -static ALenum *ThunkArray; -static ALuint ThunkArraySize; -static RWLock ThunkLock; +static ATOMIC(ALenum) *ThunkArray; +static ALuint ThunkArraySize; +static RWLock ThunkLock; void ThunkInit(void) { RWLockInit(&ThunkLock); ThunkArraySize = 1; - ThunkArray = calloc(1, ThunkArraySize * sizeof(*ThunkArray)); + ThunkArray = al_calloc(16, ThunkArraySize * sizeof(*ThunkArray)); } void ThunkExit(void) { - free(ThunkArray); + al_free(ThunkArray); ThunkArray = NULL; ThunkArraySize = 0; } ALenum NewThunkEntry(ALuint *index) { - ALenum *NewList; + void *NewList; ALuint i; ReadLock(&ThunkLock); for(i = 0;i < ThunkArraySize;i++) { - if(ExchangeInt(&ThunkArray[i], AL_TRUE) == AL_FALSE) + if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE) == AL_FALSE) { ReadUnlock(&ThunkLock); *index = i+1; @@ -62,18 +62,19 @@ ALenum NewThunkEntry(ALuint *index) ReadUnlock(&ThunkLock); WriteLock(&ThunkLock); - NewList = realloc(ThunkArray, ThunkArraySize*2 * sizeof(*ThunkArray)); + NewList = al_calloc(16, ThunkArraySize*2 * sizeof(*ThunkArray)); if(!NewList) { WriteUnlock(&ThunkLock); ERR("Realloc failed to increase to %u entries!\n", ThunkArraySize*2); return AL_OUT_OF_MEMORY; } - memset(&NewList[ThunkArraySize], 0, ThunkArraySize*sizeof(*ThunkArray)); - ThunkArraySize *= 2; + memcpy(NewList, ThunkArray, ThunkArraySize*sizeof(*ThunkArray)); + al_free(ThunkArray); ThunkArray = NewList; + ThunkArraySize *= 2; - ThunkArray[i] = AL_TRUE; + ATOMIC_STORE(&ThunkArray[i], AL_TRUE); WriteUnlock(&ThunkLock); *index = i+1; @@ -84,6 +85,6 @@ void FreeThunkEntry(ALuint index) { ReadLock(&ThunkLock); if(index > 0 && index <= ThunkArraySize) - ExchangeInt(&ThunkArray[index-1], AL_FALSE); + ATOMIC_STORE(&ThunkArray[index-1], AL_FALSE); ReadUnlock(&ThunkLock); } |