Common/Threading: Replace TLS macros with standard thread_local

This commit is contained in:
Connor McLaughlin 2022-05-09 20:37:53 +10:00 committed by refractionpcsx2
parent f8dcff9fc4
commit d2347d9972
8 changed files with 13 additions and 61 deletions

View File

@ -20,10 +20,10 @@
using namespace Threading;
// thread-local console indentation setting.
static DeclareTls(int) conlog_Indent(0);
static thread_local int conlog_Indent(0);
// thread-local console color storage.
static DeclareTls(ConsoleColors) conlog_Color(DefaultConsoleColor);
static thread_local ConsoleColors conlog_Color(DefaultConsoleColor);
#ifdef __POSIX__
#include <unistd.h>

View File

@ -26,24 +26,6 @@
#include <atomic>
// --------------------------------------------------------------------------------------
// PCSX2_THREAD_LOCAL - Defines platform/operating system support for Thread Local Storage
// --------------------------------------------------------------------------------------
//
// TLS is enabled by default. It will be disabled at compile time for Linux plugin.
// If you link SPU2X/ZZOGL with a TLS library, you will consume a DVT slots. Slots
// are rather limited and it ends up to "impossible to dlopen the library"
// None of the above plugin uses TLS variable in a multithread context
#ifndef PCSX2_THREAD_LOCAL
#define PCSX2_THREAD_LOCAL 1
#endif
#if PCSX2_THREAD_LOCAL
#define DeclareTls(x) thread_local x
#else
#define DeclareTls(x) x
#endif
namespace Threading
{
// --------------------------------------------------------------------------------------

View File

@ -60,8 +60,8 @@
//
__tls_emit u8* x86Ptr;
__tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM] = {XMMT_INT};
thread_local u8* x86Ptr;
thread_local XMMSSEType g_xmmtypes[iREGCNT_XMM] = {XMMT_INT};
namespace x86Emitter
{

View File

@ -29,38 +29,8 @@ enum XMMSSEType
//XMMT_FPD = 3, // double
};
// --------------------------------------------------------------------------------------
// __tls_emit / x86EMIT_MULTITHREADED
// --------------------------------------------------------------------------------------
// Multithreaded support for the x86 emitter. (defaults to 0)
// To enable the multithreaded emitter, either set the below define to 1, or set the define
// as a project option. The multithreaded emitter relies on native compiler support for
// TLS -- Macs are crap out of luck there (for now).
#ifndef x86EMIT_MULTITHREADED
#if PCSX2_THREAD_LOCAL
#define x86EMIT_MULTITHREADED 1
#else
// No TLS support? Force-clear the MT flag:
#pragma message("x86emitter: TLS not available, multithreaded emitter disabled.")
#undef x86EMIT_MULTITHREADED
#define x86EMIT_MULTITHREADED 0
#endif
#endif
#ifndef __tls_emit
#if x86EMIT_MULTITHREADED
#define __tls_emit thread_local
#else
// Using TlsVariable is sub-optimal and could result in huge executables, so we
// force-disable TLS entirely, and disallow running multithreaded recompilation
// components within PCSX2 manually.
#define __tls_emit
#endif
#endif
extern __tls_emit u8* x86Ptr;
extern __tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM];
extern thread_local u8* x86Ptr;
extern thread_local XMMSSEType g_xmmtypes[iREGCNT_XMM];
namespace x86Emitter
{

View File

@ -105,7 +105,7 @@ static wxString pxGetStackTrace( const FnChar_t* calledFrom )
void Pcsx2App::OnAssertFailure( const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg )
{
// Re-entrant assertions are bad mojo -- trap immediately.
static DeclareTls(int) _reentrant_lock( 0 );
static thread_local int _reentrant_lock( 0 );
RecursionGuard guard( _reentrant_lock );
if( guard.IsReentrant() ) pxTrap();

View File

@ -686,8 +686,8 @@ void SysExecEvent_CoreThreadPause::InvokeEvent()
// ScopedCoreThreadClose / ScopedCoreThreadPause
// --------------------------------------------------------------------------------------
static DeclareTls(bool) ScopedCore_IsPaused = false;
static DeclareTls(bool) ScopedCore_IsFullyClosed = false;
static thread_local bool ScopedCore_IsPaused = false;
static thread_local bool ScopedCore_IsFullyClosed = false;
BaseScopedCoreThread::BaseScopedCoreThread()
{

View File

@ -24,8 +24,8 @@
using namespace x86Emitter;
__tls_emit u8* j8Ptr[32];
__tls_emit u32* j32Ptr[32];
thread_local u8* j8Ptr[32];
thread_local u32* j32Ptr[32];
u16 g_x86AllocCounter = 0;
u16 g_xmmAllocCounter = 0;

View File

@ -256,8 +256,8 @@ extern u32 g_recWriteback; // used for jumps (VUrec mess!)
extern _xmmregs xmmregs[iREGCNT_XMM], s_saveXMMregs[iREGCNT_XMM];
extern __tls_emit u8* j8Ptr[32]; // depreciated item. use local u8* vars instead.
extern __tls_emit u32* j32Ptr[32]; // depreciated item. use local u32* vars instead.
extern thread_local u8* j8Ptr[32]; // depreciated item. use local u8* vars instead.
extern thread_local u32* j32Ptr[32]; // depreciated item. use local u32* vars instead.
extern u16 g_x86AllocCounter;
extern u16 g_xmmAllocCounter;