aboutsummaryrefslogtreecommitdiffstats
path: root/router/router.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-12-20 10:27:39 -0800
committerChris Robinson <[email protected]>2021-12-20 10:27:39 -0800
commit633c332deee0500b85927906be1084606a286ac9 (patch)
tree31d178782d6ed65163c4f9f945ccace31a1c0ad1 /router/router.h
parenta88803f21e1b44633de1aa5e068df8e9f371c2c2 (diff)
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.
Diffstat (limited to 'router/router.h')
-rw-r--r--router/router.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/router/router.h b/router/router.h
index 253494de..f9ebd4a4 100644
--- a/router/router.h
+++ b/router/router.h
@@ -172,6 +172,17 @@ extern std::vector<DriverIface> DriverList;
extern thread_local DriverIface *ThreadCtxDriver;
extern std::atomic<DriverIface*> 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 DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; }
+inline void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; }
+#endif
+
class PtrIntMap {
void **mKeys{nullptr};