From b5da8485c2c01ec4039e0d15d03879dbc45f6b88 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 22 May 2023 05:18:44 -0700 Subject: Make the router API functions noexcept --- router/al.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'router/al.cpp') diff --git a/router/al.cpp b/router/al.cpp index 06c314eb..c7e01d51 100644 --- a/router/al.cpp +++ b/router/al.cpp @@ -9,31 +9,31 @@ std::atomic CurrentCtxDriver{nullptr}; -#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \ +#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ 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) \ +#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ 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) \ +#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ 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) \ +#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ 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) \ +#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) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \ @@ -44,7 +44,7 @@ std::atomic CurrentCtxDriver{nullptr}; /* Ugly hack for some apps calling alGetError without a current context, and * expecting it to be AL_NO_ERROR. */ -AL_API ALenum AL_APIENTRY alGetError(void) +AL_API ALenum AL_APIENTRY alGetError(void) noexcept { DriverIface *iface = GetThreadDriver(); if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); -- cgit v1.2.3 From 6722ad196145ef7334d7478bdd375308801e7096 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 11 Sep 2023 19:34:55 -0700 Subject: Make some global and static member variables inline This also seems to work around the problematic MinGW code generation, so the indirection to access it can be removed. --- alc/context.cpp | 8 -------- alc/context.h | 11 +---------- router/al.cpp | 2 -- router/router.cpp | 9 --------- router/router.h | 18 +++++------------- 5 files changed, 6 insertions(+), 42 deletions(-) (limited to 'router/al.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index bba74a59..3b1de7b9 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -102,7 +102,6 @@ std::vector getContextExtensions() noexcept std::atomic ALCcontext::sGlobalContextLock{false}; std::atomic ALCcontext::sGlobalContext{nullptr}; -thread_local ALCcontext *ALCcontext::sLocalContext{nullptr}; ALCcontext::ThreadCtx::~ThreadCtx() { if(ALCcontext *ctx{std::exchange(ALCcontext::sLocalContext, nullptr)}) @@ -117,13 +116,6 @@ thread_local ALCcontext::ThreadCtx ALCcontext::sThreadContext; ALeffect ALCcontext::sDefaultEffect; -#ifdef __MINGW32__ -ALCcontext *ALCcontext::getThreadContext() noexcept -{ return sLocalContext; } -void ALCcontext::setThreadContext(ALCcontext *context) noexcept -{ sThreadContext.set(context); } -#endif - ALCcontext::ALCcontext(al::intrusive_ptr device, ContextFlagBitset flags) : ContextBase{device.get()}, mALDevice{std::move(device)}, mContextFlags{flags} { diff --git a/alc/context.h b/alc/context.h index f936bbe8..201c8873 100644 --- a/alc/context.h +++ b/alc/context.h @@ -211,7 +211,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { private: /* Thread-local current context. */ - static thread_local ALCcontext *sLocalContext; + static inline thread_local ALCcontext *sLocalContext{}; /* Thread-local context handling. This handles attempting to release the * context which may have been left current when the thread is destroyed. @@ -224,17 +224,8 @@ private: static thread_local ThreadCtx sThreadContext; public: - /* HACK: MinGW generates bad code when accessing an extern thread_local - * object. Add a wrapper function for it that only accesses it where it's - * defined. - */ -#ifdef __MINGW32__ - static ALCcontext *getThreadContext() noexcept; - static void setThreadContext(ALCcontext *context) noexcept; -#else static ALCcontext *getThreadContext() noexcept { return sLocalContext; } static void setThreadContext(ALCcontext *context) noexcept { sThreadContext.set(context); } -#endif /* Default effect that applies to sources that don't have an effect on send 0. */ static ALeffect sDefaultEffect; diff --git a/router/al.cpp b/router/al.cpp index c7e01d51..6ed8a626 100644 --- a/router/al.cpp +++ b/router/al.cpp @@ -7,8 +7,6 @@ #include "router.h" -std::atomic CurrentCtxDriver{nullptr}; - #define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ diff --git a/router/router.cpp b/router/router.cpp index b2274c0b..e2ba91d1 100644 --- a/router/router.cpp +++ b/router/router.cpp @@ -17,18 +17,9 @@ #include "version.h" -std::vector DriverList; - -thread_local DriverIface *ThreadCtxDriver; - enum LogLevel LogLevel = LogLevel_Error; FILE *LogFile; -#ifdef __MINGW32__ -DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; } -void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; } -#endif - static void LoadDriverList(void); diff --git a/router/router.h b/router/router.h index 2a126d42..f5c7f455 100644 --- a/router/router.h +++ b/router/router.h @@ -173,21 +173,13 @@ struct DriverIface { }; using DriverIfacePtr = std::unique_ptr; -extern std::vector DriverList; - -extern thread_local DriverIface *ThreadCtxDriver; -extern std::atomic CurrentCtxDriver; - -/* HACK: MinGW generates bad code when accessing an extern thread_local object. - * Add a wrapper function for it that only accesses it where it's defined. - */ -#ifdef __MINGW32__ -DriverIface *GetThreadDriver() noexcept; -void SetThreadDriver(DriverIface *driver) noexcept; -#else +inline std::vector DriverList; + +inline thread_local DriverIface *ThreadCtxDriver{}; +inline std::atomic CurrentCtxDriver{}; + inline DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; } inline void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; } -#endif class PtrIntMap { -- cgit v1.2.3