diff options
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alc.cpp | 14 | ||||
-rw-r--r-- | alc/context.cpp | 7 | ||||
-rw-r--r-- | alc/context.h | 15 |
3 files changed, 29 insertions, 7 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index c6ac6508..b63f0f82 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2218,7 +2218,7 @@ ContextRef VerifyContext(ALCcontext *context) /** Returns a new reference to the currently active context for this thread. */ ContextRef GetContextRef(void) { - ALCcontext *context{ALCcontext::sLocalContext}; + ALCcontext *context{ALCcontext::getThreadContext()}; if(context) context->add_ref(); else @@ -3062,7 +3062,7 @@ END_API_FUNC ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void) START_API_FUNC { - ALCcontext *Context{ALCcontext::sLocalContext}; + ALCcontext *Context{ALCcontext::getThreadContext()}; if(!Context) Context = ALCcontext::sGlobalContext.load(); return Context; } @@ -3071,7 +3071,7 @@ END_API_FUNC /** Returns the currently active thread-local context. */ ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void) START_API_FUNC -{ return ALCcontext::sLocalContext; } +{ return ALCcontext::getThreadContext(); } END_API_FUNC ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) @@ -3098,8 +3098,8 @@ START_API_FUNC * thread-local context. Take ownership of the thread-local context * reference (if any), clearing the storage to null. */ - ctx = ContextRef{ALCcontext::sLocalContext}; - if(ctx) ALCcontext::sThreadContext.set(nullptr); + ctx = ContextRef{ALCcontext::getThreadContext()}; + if(ctx) ALCcontext::setThreadContext(nullptr); /* Reset (decrement) the previous thread-local reference. */ return ALC_TRUE; @@ -3122,8 +3122,8 @@ START_API_FUNC } } /* context's reference count is already incremented */ - ContextRef old{ALCcontext::sLocalContext}; - ALCcontext::sThreadContext.set(ctx.release()); + ContextRef old{ALCcontext::getThreadContext()}; + ALCcontext::setThreadContext(ctx.release()); return ALC_TRUE; } diff --git a/alc/context.cpp b/alc/context.cpp index 1dff00bc..c2d3e351 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -96,6 +96,13 @@ 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<ALCdevice> device) : ContextBase{device.get()}, mALDevice{std::move(device)} { diff --git a/alc/context.h b/alc/context.h index d0afbdd9..87754235 100644 --- a/alc/context.h +++ b/alc/context.h @@ -131,8 +131,10 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase { /* Process-wide current context */ static std::atomic<ALCcontext*> sGlobalContext; +private: /* Thread-local current context. */ static 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. */ @@ -143,6 +145,19 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase { }; 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; |