Don't use the thunk array for object lookups
This commit is contained in:
parent
858592832f
commit
c1f435cc18
@ -12,25 +12,22 @@ extern "C" {
|
||||
|
||||
void alThunkInit(void);
|
||||
void alThunkExit(void);
|
||||
ALenum alThunkAddEntry(ALvoid *ptr, ALuint *idx);
|
||||
ALenum alThunkNewEntry(ALuint *idx);
|
||||
void alThunkRemoveEntry(ALuint index);
|
||||
ALvoid *alThunkLookupEntry(ALuint index);
|
||||
|
||||
#if (SIZEOF_VOIDP > SIZEOF_UINT)
|
||||
|
||||
#define ALTHUNK_INIT() alThunkInit()
|
||||
#define ALTHUNK_EXIT() alThunkExit()
|
||||
#define ALTHUNK_ADDENTRY(p,i) alThunkAddEntry(p,i)
|
||||
#define ALTHUNK_NEWENTRY(p,i) alThunkNewEntry(i)
|
||||
#define ALTHUNK_REMOVEENTRY(i) alThunkRemoveEntry(i)
|
||||
#define ALTHUNK_LOOKUPENTRY(i) alThunkLookupEntry(i)
|
||||
|
||||
#else
|
||||
|
||||
#define ALTHUNK_INIT()
|
||||
#define ALTHUNK_EXIT()
|
||||
#define ALTHUNK_ADDENTRY(p,i) ((*(i) = (ALuint)p),AL_NO_ERROR)
|
||||
#define ALTHUNK_NEWENTRY(p,i) ((*(i) = (ALuint)p),AL_NO_ERROR)
|
||||
#define ALTHUNK_REMOVEENTRY(i) ((ALvoid)i)
|
||||
#define ALTHUNK_LOOKUPENTRY(i) ((ALvoid*)(i))
|
||||
|
||||
#endif // (SIZEOF_VOIDP > SIZEOF_INT)
|
||||
|
||||
|
@ -68,7 +68,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
|
||||
break;
|
||||
}
|
||||
|
||||
err = ALTHUNK_ADDENTRY(slot, &slot->effectslot);
|
||||
err = ALTHUNK_NEWENTRY(slot, &slot->effectslot);
|
||||
if(err == AL_NO_ERROR)
|
||||
err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->effectslot, slot);
|
||||
if(err != AL_NO_ERROR)
|
||||
|
@ -163,7 +163,7 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
|
||||
break;
|
||||
}
|
||||
|
||||
err = ALTHUNK_ADDENTRY(buffer, &buffer->buffer);
|
||||
err = ALTHUNK_NEWENTRY(buffer, &buffer->buffer);
|
||||
if(err == AL_NO_ERROR)
|
||||
err = InsertUIntMapEntry(&device->BufferMap, buffer->buffer, buffer);
|
||||
if(err != AL_NO_ERROR)
|
||||
|
@ -63,7 +63,7 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
|
||||
break;
|
||||
}
|
||||
|
||||
err = ALTHUNK_ADDENTRY(effect, &effect->effect);
|
||||
err = ALTHUNK_NEWENTRY(effect, &effect->effect);
|
||||
if(err == AL_NO_ERROR)
|
||||
err = InsertUIntMapEntry(&device->EffectMap, effect->effect, effect);
|
||||
if(err != AL_NO_ERROR)
|
||||
|
@ -59,7 +59,7 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
|
||||
break;
|
||||
}
|
||||
|
||||
err = ALTHUNK_ADDENTRY(filter, &filter->filter);
|
||||
err = ALTHUNK_NEWENTRY(filter, &filter->filter);
|
||||
if(err == AL_NO_ERROR)
|
||||
err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter);
|
||||
if(err != AL_NO_ERROR)
|
||||
|
@ -85,7 +85,7 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources)
|
||||
break;
|
||||
}
|
||||
|
||||
err = ALTHUNK_ADDENTRY(source, &source->source);
|
||||
err = ALTHUNK_NEWENTRY(source, &source->source);
|
||||
if(err == AL_NO_ERROR)
|
||||
err = InsertUIntMapEntry(&Context->SourceMap, source->source, source);
|
||||
if(err != AL_NO_ERROR)
|
||||
@ -1376,7 +1376,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
|
||||
|
||||
for(i = 0;i < n;i++)
|
||||
{
|
||||
Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]);
|
||||
Source = LookupSource(Context->SourceMap, sources[i]);
|
||||
if(Context->DeferUpdates) Source->new_state = AL_PLAYING;
|
||||
else SetSourceState(Source, Context, AL_PLAYING);
|
||||
}
|
||||
@ -1422,7 +1422,7 @@ AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources)
|
||||
|
||||
for(i = 0;i < n;i++)
|
||||
{
|
||||
Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]);
|
||||
Source = LookupSource(Context->SourceMap, sources[i]);
|
||||
if(Context->DeferUpdates) Source->new_state = AL_PAUSED;
|
||||
else SetSourceState(Source, Context, AL_PAUSED);
|
||||
}
|
||||
@ -1468,7 +1468,7 @@ AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources)
|
||||
|
||||
for(i = 0;i < n;i++)
|
||||
{
|
||||
Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]);
|
||||
Source = LookupSource(Context->SourceMap, sources[i]);
|
||||
if(Context->DeferUpdates) Source->new_state = AL_STOPPED;
|
||||
else SetSourceState(Source, Context, AL_STOPPED);
|
||||
}
|
||||
@ -1514,7 +1514,7 @@ AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources)
|
||||
|
||||
for(i = 0;i < n;i++)
|
||||
{
|
||||
Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]);
|
||||
Source = LookupSource(Context->SourceMap, sources[i]);
|
||||
if(Context->DeferUpdates) Source->new_state = AL_INITIAL;
|
||||
else SetSourceState(Source, Context, AL_INITIAL);
|
||||
}
|
||||
@ -1616,7 +1616,7 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei n, const A
|
||||
// Change Source Type
|
||||
Source->lSourceType = AL_STREAMING;
|
||||
|
||||
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[0]);
|
||||
buffer = LookupBuffer(device->BufferMap, buffers[0]);
|
||||
|
||||
// All buffers are valid - so add them to the list
|
||||
BufferListStart = malloc(sizeof(ALbufferlistitem));
|
||||
@ -1631,7 +1631,7 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei n, const A
|
||||
|
||||
for(i = 1;i < n;i++)
|
||||
{
|
||||
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[i]);
|
||||
buffer = LookupBuffer(device->BufferMap, buffers[i]);
|
||||
|
||||
BufferList->next = malloc(sizeof(ALbufferlistitem));
|
||||
BufferList->next->buffer = buffer;
|
||||
|
@ -25,12 +25,8 @@
|
||||
#include "alMain.h"
|
||||
#include "alThunk.h"
|
||||
|
||||
typedef struct {
|
||||
ALvoid *ptr;
|
||||
ALboolean InUse;
|
||||
} ThunkEntry;
|
||||
|
||||
static ThunkEntry *g_ThunkArray;
|
||||
static ALboolean *g_ThunkArray;
|
||||
static ALuint g_ThunkArraySize;
|
||||
|
||||
static CRITICAL_SECTION g_ThunkLock;
|
||||
@ -39,7 +35,7 @@ void alThunkInit(void)
|
||||
{
|
||||
InitializeCriticalSection(&g_ThunkLock);
|
||||
g_ThunkArraySize = 1;
|
||||
g_ThunkArray = calloc(1, g_ThunkArraySize * sizeof(ThunkEntry));
|
||||
g_ThunkArray = calloc(1, g_ThunkArraySize * sizeof(*g_ThunkArray));
|
||||
}
|
||||
|
||||
void alThunkExit(void)
|
||||
@ -50,7 +46,7 @@ void alThunkExit(void)
|
||||
DeleteCriticalSection(&g_ThunkLock);
|
||||
}
|
||||
|
||||
ALenum alThunkAddEntry(ALvoid *ptr, ALuint *idx)
|
||||
ALenum alThunkNewEntry(ALuint *idx)
|
||||
{
|
||||
ALuint index;
|
||||
|
||||
@ -58,28 +54,27 @@ ALenum alThunkAddEntry(ALvoid *ptr, ALuint *idx)
|
||||
|
||||
for(index = 0;index < g_ThunkArraySize;index++)
|
||||
{
|
||||
if(g_ThunkArray[index].InUse == AL_FALSE)
|
||||
if(g_ThunkArray[index] == AL_FALSE)
|
||||
break;
|
||||
}
|
||||
|
||||
if(index == g_ThunkArraySize)
|
||||
{
|
||||
ThunkEntry *NewList;
|
||||
ALboolean *NewList;
|
||||
|
||||
NewList = realloc(g_ThunkArray, g_ThunkArraySize*2 * sizeof(ThunkEntry));
|
||||
NewList = realloc(g_ThunkArray, g_ThunkArraySize*2 * sizeof(*g_ThunkArray));
|
||||
if(!NewList)
|
||||
{
|
||||
LeaveCriticalSection(&g_ThunkLock);
|
||||
ERR("Realloc failed to increase to %u enties!\n", g_ThunkArraySize*2);
|
||||
return AL_OUT_OF_MEMORY;
|
||||
}
|
||||
memset(&NewList[g_ThunkArraySize], 0, g_ThunkArraySize*sizeof(ThunkEntry));
|
||||
memset(&NewList[g_ThunkArraySize], 0, g_ThunkArraySize*sizeof(*g_ThunkArray));
|
||||
g_ThunkArraySize *= 2;
|
||||
g_ThunkArray = NewList;
|
||||
}
|
||||
|
||||
g_ThunkArray[index].ptr = ptr;
|
||||
g_ThunkArray[index].InUse = AL_TRUE;
|
||||
g_ThunkArray[index] = AL_TRUE;
|
||||
*idx = index+1;
|
||||
|
||||
LeaveCriticalSection(&g_ThunkLock);
|
||||
@ -92,21 +87,7 @@ void alThunkRemoveEntry(ALuint index)
|
||||
EnterCriticalSection(&g_ThunkLock);
|
||||
|
||||
if(index > 0 && index <= g_ThunkArraySize)
|
||||
g_ThunkArray[index-1].InUse = AL_FALSE;
|
||||
g_ThunkArray[index-1] = AL_FALSE;
|
||||
|
||||
LeaveCriticalSection(&g_ThunkLock);
|
||||
}
|
||||
|
||||
ALvoid *alThunkLookupEntry(ALuint index)
|
||||
{
|
||||
ALvoid *ptr = NULL;
|
||||
|
||||
EnterCriticalSection(&g_ThunkLock);
|
||||
|
||||
if(index > 0 && index <= g_ThunkArraySize)
|
||||
ptr = g_ThunkArray[index-1].ptr;
|
||||
|
||||
LeaveCriticalSection(&g_ThunkLock);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user