aboutsummaryrefslogtreecommitdiffstats
path: root/router/al.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-07-07 18:33:54 -0700
committerChris Robinson <[email protected]>2017-07-07 18:33:54 -0700
commit6be752a9b1a38379b8631c5dcb6c47e099af4f02 (patch)
treeb22d581ed2fd98fbd12526d2af005c6517f110c4 /router/al.c
parentfaefa1d55479a5d5a05ddb18f6b9051634adec3d (diff)
Add methods for thread-local contexts to the router
Diffstat (limited to 'router/al.c')
-rw-r--r--router/al.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/router/al.c b/router/al.c
index 7af7168a..3349ad13 100644
--- a/router/al.c
+++ b/router/al.c
@@ -9,16 +9,36 @@
ATOMIC(DriverIface*) CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
-#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
-{ return ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire)->n(a); }
+#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a); \
+}
#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
-{ return ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire)->n(a, b); }
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b); \
+}
#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
-{ return ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire)->n(a, b, c); }
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c); \
+}
#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
-{ return ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire)->n(a, b, c, d); }
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c, d); \
+}
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
-{ return ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire)->n(a, b, c, d, e); }
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c, d, e); \
+}
/* Ugly hack for some apps calling alGetError without a current context, and
@@ -26,9 +46,9 @@ ATOMIC(DriverIface*) CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
*/
AL_API ALenum AL_APIENTRY alGetError(void)
{
- DriverIface *iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);
- if(iface) return iface->alGetError();
- return AL_NO_ERROR;
+ DriverIface *iface = altss_get(ThreadCtxDriver);
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);
+ return iface ? iface->alGetError() : AL_NO_ERROR;
}