aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-09-10 07:18:29 -0700
committerChris Robinson <[email protected]>2011-09-10 07:18:29 -0700
commit419294cddd7a437eb8d4bc5c0ffa6861d794d99b (patch)
tree0536691ef5ba70d257e29df96dad08e9d3c6631f /Alc/ALc.c
parentb9448a476e7e4f7e3077265fd894190f6c836c59 (diff)
Avoid locking the device when adding and removing contexts
Also, don't keep track of the number of contexts per device
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r--Alc/ALc.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 57db46fe..a5296ced 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -2225,7 +2225,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
}
if(!ALContext || !ALContext->ActiveSources)
{
- if(device->NumContexts == 0)
+ if(!device->ContextList)
{
ALCdevice_StopPlayback(device);
device->Flags &= ~DEVICE_RUNNING;
@@ -2243,11 +2243,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ALContext->Device = device;
InitContext(ALContext);
- LockDevice(device);
- device->NumContexts++;
ALContext->next = device->ContextList;
device->ContextList = ALContext;
- UnlockDevice(device);
UnlockLists();
ALCdevice_DecRef(device);
@@ -2263,7 +2260,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
{
ALCdevice *Device;
- ALCcontext **tmp_ctx;
+ ALCcontext *volatile*tmp_ctx;
LockLists();
Device = alcGetContextsDevice(context);
@@ -2273,18 +2270,21 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
return;
}
- LockDevice(Device);
tmp_ctx = &Device->ContextList;
while(*tmp_ctx)
{
if(*tmp_ctx == context)
{
- *tmp_ctx = (*tmp_ctx)->next;
- Device->NumContexts--;
+ *tmp_ctx = context->next;
break;
}
tmp_ctx = &(*tmp_ctx)->next;
}
+
+ LockDevice(Device);
+ /* Lock the device to make sure the mixer is not using the contexts in the
+ * list before we go about deleting this one. There should be a more
+ * efficient way of doing this. */
UnlockDevice(Device);
if(pthread_getspecific(LocalContext) == context)
@@ -2300,7 +2300,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALCcontext_DecRef(context);
}
- if(Device->NumContexts == 0)
+ if(!Device->ContextList)
{
ALCdevice_StopPlayback(Device);
Device->Flags &= ~DEVICE_RUNNING;
@@ -2517,7 +2517,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->szDeviceName = NULL;
device->ContextList = NULL;
- device->NumContexts = 0;
InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0);
@@ -2590,6 +2589,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
{
ALCdevice **list;
+ ALCcontext *ctx;
LockLists();
list = &g_pDeviceList;
@@ -2608,11 +2608,10 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
UnlockLists();
- if(pDevice->NumContexts > 0)
+ while((ctx=pDevice->ContextList) != NULL)
{
- WARN("Destroying %u Context(s)\n", pDevice->NumContexts);
- while(pDevice->ContextList)
- alcDestroyContext(pDevice->ContextList);
+ WARN("Destroying context %p\n", ctx);
+ alcDestroyContext(ctx);
}
ALCdevice_ClosePlayback(pDevice);
@@ -2649,7 +2648,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
device->szDeviceName = NULL;
device->ContextList = NULL;
- device->NumContexts = 0;
InitUIntMap(&device->BufferMap, ~0);
InitUIntMap(&device->EffectMap, ~0);