From 6be752a9b1a38379b8631c5dcb6c47e099af4f02 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 7 Jul 2017 18:33:54 -0700 Subject: Add methods for thread-local contexts to the router --- router/al.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'router/al.c') 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; } -- cgit v1.2.3