From e75e0a342ecb78a47bebe0b7f5124dfb83c56f32 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Oct 2018 07:30:46 -0700 Subject: Use C++ atomics and mutexes in the router --- router/al.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'router/al.cpp') diff --git a/router/al.cpp b/router/al.cpp index 1b4f413f..4c8b0006 100644 --- a/router/al.cpp +++ b/router/al.cpp @@ -7,36 +7,36 @@ #include "router.h" -atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL); +std::atomic CurrentCtxDriver{nullptr}; #define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \ { \ - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver));\ - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\ + DriverIface *iface = ThreadCtxDriver; \ + if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \ return iface->n(a); \ } #define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \ { \ - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver));\ - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\ + DriverIface *iface = ThreadCtxDriver; \ + if(!iface) iface = CurrentCtxDriver.load(std::memory_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) \ { \ - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver));\ - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\ + DriverIface *iface = ThreadCtxDriver; \ + if(!iface) iface = CurrentCtxDriver.load(std::memory_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) \ { \ - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver));\ - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\ + DriverIface *iface = ThreadCtxDriver; \ + if(!iface) iface = CurrentCtxDriver.load(std::memory_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) \ { \ - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver));\ - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\ + DriverIface *iface = ThreadCtxDriver; \ + if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \ return iface->n(a, b, c, d, e); \ } @@ -46,8 +46,8 @@ atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL); */ AL_API ALenum AL_APIENTRY alGetError(void) { - DriverIface *iface = reinterpret_cast(altss_get(ThreadCtxDriver)); - if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire); + DriverIface *iface = ThreadCtxDriver; + if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); return iface ? iface->alGetError() : AL_NO_ERROR; } -- cgit v1.2.3