summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-29 20:52:13 -0700
committerChris Robinson <[email protected]>2011-08-29 20:52:13 -0700
commitda081b81c425805eef5b3d4a07c7a213490e04b7 (patch)
tree0d122e52f4a5bfb0898940e0b077f60a53c4aeb1
parent500ad776ea5bba13240cde84b2aa7c1caca77753 (diff)
Do a compare-exchange to set the context error
This allows for unlocked context access when getting the error
-rw-r--r--OpenAL32/Include/alMain.h20
-rw-r--r--OpenAL32/alError.c7
2 files changed, 23 insertions, 4 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 9a7c1cc4..a0c83254 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -235,6 +235,10 @@ static __inline RefCount DecrementRef(volatile RefCount *ptr)
static __inline T Exchange_##T(volatile T *ptr, T newval) \
{ \
return __sync_lock_test_and_set(ptr, newval); \
+} \
+static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\
+{ \
+ return __sync_bool_compare_and_swap(ptr, oldval, newval); \
}
#elif defined(_WIN32)
@@ -253,6 +257,14 @@ static __inline T Exchange_##T(volatile T *ptr, T newval) \
volatile LONG *l; \
} u = { ptr }; \
return InterlockedExchange(u.l, newval); \
+} \
+static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\
+{ \
+ union { \
+ volatile T *t; \
+ volatile LONG *l; \
+ } u = { ptr }; \
+ return InterlockedCompareExchange(u.l, newval, oldval) == oldval; \
}
#elif defined(__APPLE__)
@@ -278,6 +290,14 @@ static __inline T Exchange_##T(volatile T *ptr, T newval) \
oldval = *u.i; \
} while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, u.i)); \
return oldval; \
+} \
+static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\
+{ \
+ union { \
+ volatile T *t; \
+ volatile int32_t *i; \
+ } u = { ptr }; \
+ return OSAtomicCompareAndSwap32Barrier(oldval, newval, u.i); \
}
#else
diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c
index b30755d9..edca01f2 100644
--- a/OpenAL32/alError.c
+++ b/OpenAL32/alError.c
@@ -29,18 +29,17 @@ AL_API ALenum AL_APIENTRY alGetError(ALvoid)
ALCcontext *Context;
ALenum errorCode;
- Context = GetLockedContext();
+ Context = GetReffedContext();
if(!Context) return AL_INVALID_OPERATION;
errorCode = Exchange_ALenum(&Context->LastError, AL_NO_ERROR);
- UnlockContext(Context);
+ ALCcontext_DecRef(Context);
return errorCode;
}
ALvoid alSetError(ALCcontext *Context, ALenum errorCode)
{
- if(Context->LastError == AL_NO_ERROR)
- Context->LastError = errorCode;
+ CompExchange_ALenum(&Context->LastError, AL_NO_ERROR, errorCode);
}