aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-11-22 03:00:16 -0800
committerChris Robinson <[email protected]>2016-11-22 03:00:16 -0800
commitc6189717580453b03cc70f0647a215f3f5f886fe (patch)
treeceda65d18733e34c59d74c6fe430e2d78d9ff8a8 /Alc
parent01babb69d25fd23bde0fdf5ed525bb82934ce6fd (diff)
Remove the non-atomic COMPARE_EXCHANGE macro
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 8c855157..9d3467f7 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -2402,7 +2402,6 @@ static void FreeContext(ALCcontext *context)
*/
static void ReleaseContext(ALCcontext *context, ALCdevice *device)
{
- ALCcontext *nextctx;
ALCcontext *origctx;
if(altss_get(LocalContext) == context)
@@ -2418,14 +2417,18 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device)
ALCdevice_Lock(device);
origctx = context;
- nextctx = context->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCcontext*, &device->ContextList, &origctx, nextctx))
+ if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCcontext*, &device->ContextList, &origctx, context->next))
{
- ALCcontext *list;
- do {
- list = origctx;
- origctx = context;
- } while(!COMPARE_EXCHANGE(&list->next, &origctx, nextctx));
+ ALCcontext *volatile*list = &origctx->next;
+ while(*list)
+ {
+ if(*list == context)
+ {
+ *list = (*list)->next;
+ break;
+ }
+ list = &(*list)->next;
+ }
}
ALCdevice_Unlock(device);
@@ -3618,31 +3621,36 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
*/
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
{
- ALCdevice *list, *origdev, *nextdev;
+ ALCdevice *iter, *origdev;
ALCcontext *ctx;
LockLists();
- list = ATOMIC_LOAD(&DeviceList);
+ iter = ATOMIC_LOAD(&DeviceList);
do {
- if(list == device)
+ if(iter == device)
break;
- } while((list=list->next) != NULL);
- if(!list || list->Type == Capture)
+ } while((iter=iter->next) != NULL);
+ if(!iter || iter->Type == Capture)
{
- alcSetError(list, ALC_INVALID_DEVICE);
+ alcSetError(iter, ALC_INVALID_DEVICE);
UnlockLists();
return ALC_FALSE;
}
almtx_lock(&device->BackendLock);
origdev = device;
- nextdev = device->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &origdev, nextdev))
+ if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &origdev, device->next))
{
- do {
- list = origdev;
- origdev = device;
- } while(!COMPARE_EXCHANGE(&list->next, &origdev, nextdev));
+ ALCdevice *volatile*list = &origdev->next;
+ while(*list)
+ {
+ if(*list == device)
+ {
+ *list = (*list)->next;
+ break;
+ }
+ list = &(*list)->next;
+ }
}
UnlockLists();
@@ -3769,29 +3777,34 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
{
- ALCdevice *list, *next, *nextdev;
+ ALCdevice *iter, *origdev;
LockLists();
- list = ATOMIC_LOAD(&DeviceList);
+ iter = ATOMIC_LOAD(&DeviceList);
do {
- if(list == device)
+ if(iter == device)
break;
- } while((list=list->next) != NULL);
- if(!list || list->Type != Capture)
+ } while((iter=iter->next) != NULL);
+ if(!iter || iter->Type != Capture)
{
- alcSetError(list, ALC_INVALID_DEVICE);
+ alcSetError(iter, ALC_INVALID_DEVICE);
UnlockLists();
return ALC_FALSE;
}
- next = device;
- nextdev = device->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &next, nextdev))
+ origdev = device;
+ if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &origdev, device->next))
{
- do {
- list = next;
- next = device;
- } while(!COMPARE_EXCHANGE(&list->next, &next, nextdev));
+ ALCdevice *volatile*list = &origdev->next;
+ while(*list)
+ {
+ if(*list == device)
+ {
+ *list = (*list)->next;
+ break;
+ }
+ list = &(*list)->next;
+ }
}
UnlockLists();