diff --git a/uppsrc/Core/CoWork.cpp b/uppsrc/Core/CoWork.cpp index 628f0eaa6..46e49dc15 100644 --- a/uppsrc/Core/CoWork.cpp +++ b/uppsrc/Core/CoWork.cpp @@ -12,7 +12,7 @@ namespace Upp { #ifdef COMPILER_MINGW FastMingwTls CoWork::Pool::finlock; -FastMingwTls CoWork::worker_index; +FastMingwTls CoWork::worker_index = -1; FastMingwTls CoWork::current; #else thread_local bool CoWork::Pool::finlock; @@ -359,6 +359,11 @@ void CoWork::Reset() canceled = false; } +bool CoWork::IsCanceled() +{ + return current && current->canceled; +} + int CoWork::GetWorkerIndex() { return worker_index; diff --git a/uppsrc/Core/CoWork.h b/uppsrc/Core/CoWork.h index 596aee56e..e0214fc8f 100644 --- a/uppsrc/Core/CoWork.h +++ b/uppsrc/Core/CoWork.h @@ -30,7 +30,7 @@ public: Pool(); ~Pool(); - + #ifdef COMPILER_MINGW static FastMingwTls finlock; #else @@ -99,7 +99,7 @@ public: static void FinLock(); void Cancel(); - static bool IsCanceled() { return current && current->canceled; } + static bool IsCanceled(); void Finish(); @@ -107,7 +107,7 @@ public: void Reset(); - static bool IsWorker() { return worker_index >= 0; } + static bool IsWorker() { return GetWorkerIndex() >= 0; } static int GetWorkerIndex(); static int GetPoolSize(); static void SetPoolSize(int n); diff --git a/uppsrc/Core/Ops.h b/uppsrc/Core/Ops.h index 0f2b03a3f..f9476fdd4 100644 --- a/uppsrc/Core/Ops.h +++ b/uppsrc/Core/Ops.h @@ -303,10 +303,10 @@ int SignificantBits(dword x) #ifdef COMPILER_MINGW // This is hopefully a temporary fix for abysmal MINGW thread_local implementation -// IMPORTANT: There are some mingw/lld issues that prevent TLS stuff to be used in inlines +// ALSO IMPORTANT: There are some mingw/lld issues that prevent TLS stuff to be used in inlines template -class FastMingwTls { +struct FastMingwTls { int ndx = -1; struct TEB_ { @@ -333,12 +333,13 @@ class FastMingwTls { } public: - void operator=(T x) { Slot() = (PVOID)(uintptr_t)x; } - T operator->() { return (T)(uintptr_t)Slot(); } - const T operator->() const { return (T)(uintptr_t)Slot(); } - operator T() const { return (T)(uintptr_t)Slot(); } + void operator=(T x) { Slot() = (PVOID)(uintptr_t)x; } + T operator->() { return (T)(uintptr_t)Slot(); } + const T operator->() const { return (T)(uintptr_t)Slot(); } + operator T() const { return (T)(uintptr_t)Slot(); } - FastMingwTls() { ndx = TlsAlloc(); ASSERT(ndx < 60); } + FastMingwTls() { ndx = TlsAlloc(); ASSERT(ndx < 60); } + FastMingwTls(T x) : FastMingwTls() { operator=(x); } }; #endif \ No newline at end of file