From 1be39cb50516b7a48833e0ba263d15ab7f7e56c6 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Sat, 1 May 2021 15:44:53 +0700 Subject: [PATCH] [K/N] Replace thread_local with THREAD_LOCAL_VARIABLE For some reason using C++'s thread_local modifier causes crashes during TLS access on runtime initialization Kotlin dlls on Windows. This patch replaces the thread_local modifier with __thread which doesn't have this problem --- kotlin-native/runtime/src/main/cpp/AllocTest.cpp | 4 ++-- kotlin-native/runtime/src/mm/cpp/ThreadRegistry.cpp | 2 +- kotlin-native/runtime/src/mm/cpp/ThreadRegistry.hpp | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kotlin-native/runtime/src/main/cpp/AllocTest.cpp b/kotlin-native/runtime/src/main/cpp/AllocTest.cpp index 94ea54ec668..4b61017925a 100644 --- a/kotlin-native/runtime/src/main/cpp/AllocTest.cpp +++ b/kotlin-native/runtime/src/main/cpp/AllocTest.cpp @@ -18,7 +18,7 @@ class A : public KonanAllocatorAware { public: using DestructorHook = testing::StrictMock>; - static thread_local DestructorHook* destructorHook; + static THREAD_LOCAL_VARIABLE DestructorHook* destructorHook; explicit A(int value = -1) : value_(value) {} @@ -33,7 +33,7 @@ private: }; // static -thread_local A::DestructorHook* A::destructorHook = nullptr; +THREAD_LOCAL_VARIABLE A::DestructorHook* A::destructorHook = nullptr; struct B { explicit B(int value) : a(value) {} diff --git a/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.cpp b/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.cpp index 17e361c4a71..a344bb833d8 100644 --- a/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.cpp +++ b/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.cpp @@ -40,4 +40,4 @@ mm::ThreadRegistry::ThreadRegistry() = default; mm::ThreadRegistry::~ThreadRegistry() = default; // static -thread_local mm::ThreadRegistry::Node* mm::ThreadRegistry::currentThreadDataNode_ = nullptr; +THREAD_LOCAL_VARIABLE mm::ThreadRegistry::Node* mm::ThreadRegistry::currentThreadDataNode_ = nullptr; diff --git a/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.hpp b/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.hpp index 92462033101..00e2204d7e1 100644 --- a/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.hpp +++ b/kotlin-native/runtime/src/mm/cpp/ThreadRegistry.hpp @@ -8,6 +8,7 @@ #include +#include "Common.h" #include "SingleLockList.hpp" #include "Utils.hpp" @@ -48,7 +49,7 @@ private: ThreadRegistry(); ~ThreadRegistry(); - static thread_local Node* currentThreadDataNode_; + static THREAD_LOCAL_VARIABLE Node* currentThreadDataNode_; SingleLockList list_; };