aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/alBuffer.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-31 01:13:02 -0700
committerChris Robinson <[email protected]>2011-08-31 01:13:02 -0700
commit2fcf97e2077741a878cbe160e7d107e9da0626f2 (patch)
tree6f1bf2db33525a3dc5ee684150ec236403d2f8e9 /OpenAL32/alBuffer.c
parentf3ac3cd1e23f0330396da242303f318c8a4b0fbb (diff)
Avoid the context lock when generating and deleting buffers
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r--OpenAL32/alBuffer.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index d76fa677..455cf166 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -39,6 +39,7 @@ static ALboolean IsValidType(ALenum type);
static ALboolean IsValidChannels(ALenum channels);
#define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
+#define RemoveBuffer(m, k) ((ALbuffer*)PopUIntMapValue(&(m), (k)))
/*
@@ -141,7 +142,7 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
ALCcontext *Context;
ALsizei i=0;
- Context = GetLockedContext();
+ Context = GetContextRef();
if(!Context) return;
/* Check that we are actually generating some Buffers */
@@ -180,7 +181,7 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
}
}
- UnlockContext(Context);
+ ALCcontext_DecRef(Context);
}
/*
@@ -192,22 +193,18 @@ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
{
ALCcontext *Context;
ALCdevice *device;
- ALboolean Failed;
ALbuffer *ALBuf;
ALsizei i;
- Context = GetLockedContext();
+ Context = GetContextRef();
if(!Context) return;
- Failed = AL_TRUE;
device = Context->Device;
/* Check we are actually Deleting some Buffers */
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
- Failed = AL_FALSE;
-
/* Check that all the buffers are valid and can actually be deleted */
for(i = 0;i < n;i++)
{
@@ -218,41 +215,34 @@ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
if((ALBuf=LookupBuffer(device->BufferMap, buffers[i])) == NULL)
{
alSetError(Context, AL_INVALID_NAME);
- Failed = AL_TRUE;
+ n = 0;
break;
}
else if(ALBuf->ref != 0)
{
/* Buffer still in use, cannot be deleted */
alSetError(Context, AL_INVALID_OPERATION);
- Failed = AL_TRUE;
+ n = 0;
break;
}
}
- }
- /* If all the Buffers were valid (and have Reference Counts of 0), then we
- * can delete them */
- if(!Failed)
- {
for(i = 0;i < n;i++)
{
- if((ALBuf=LookupBuffer(device->BufferMap, buffers[i])) == NULL)
+ if((ALBuf=RemoveBuffer(device->BufferMap, buffers[i])) == NULL)
continue;
+ FreeThunkEntry(ALBuf->buffer);
/* Release the memory used to store audio data */
free(ALBuf->data);
/* Release buffer structure */
- RemoveUIntMapKey(&device->BufferMap, ALBuf->buffer);
- FreeThunkEntry(ALBuf->buffer);
-
memset(ALBuf, 0, sizeof(ALbuffer));
free(ALBuf);
}
}
- UnlockContext(Context);
+ ALCcontext_DecRef(Context);
}
/*