diff options
author | Chris Robinson <[email protected]> | 2018-10-30 07:30:46 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-10-30 07:30:46 -0700 |
commit | e75e0a342ecb78a47bebe0b7f5124dfb83c56f32 (patch) | |
tree | de3139cef2abe1299f9b184f31e6b1ea52dadd98 /router/al.cpp | |
parent | a0d03e50e849d6f295d618cc4bde115af596e68a (diff) |
Use C++ atomics and mutexes in the router
Diffstat (limited to 'router/al.cpp')
-rw-r--r-- | router/al.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
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<DriverIface*> CurrentCtxDriver{nullptr}; #define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \ { \ - DriverIface *iface = reinterpret_cast<DriverIface*>(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<DriverIface*>(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<DriverIface*>(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<DriverIface*>(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<DriverIface*>(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<DriverIface*>(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; } |