From 633c332deee0500b85927906be1084606a286ac9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 20 Dec 2021 10:27:39 -0800 Subject: Work around a MinGW thread_local bug MinGW-w64 generates bad code when accessing extern thread_local objects. Wrapper functions are used to ensure it only accesses them from the same place they're defined. This unfortunately adds a bit of overhead for what should be a relatively simple thing. These functions are inlined for non-MinGW targets, avoiding the overhead on non-affected targets. --- router/router.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'router/router.cpp') diff --git a/router/router.cpp b/router/router.cpp index 731db063..7eb0bddc 100644 --- a/router/router.cpp +++ b/router/router.cpp @@ -24,6 +24,11 @@ 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); -- cgit v1.2.3