Core: CoWork Mingw fixes

git-svn-id: svn://ultimatepp.org/upp/trunk@13387 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-06-13 07:48:06 +00:00
parent 3139ae930c
commit cbc7989b91
3 changed files with 17 additions and 11 deletions

View file

@ -12,7 +12,7 @@ namespace Upp {
#ifdef COMPILER_MINGW
FastMingwTls<bool> CoWork::Pool::finlock;
FastMingwTls<int> CoWork::worker_index;
FastMingwTls<int> CoWork::worker_index = -1;
FastMingwTls<CoWork *> 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;

View file

@ -30,7 +30,7 @@ public:
Pool();
~Pool();
#ifdef COMPILER_MINGW
static FastMingwTls<bool> 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);

View file

@ -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 T>
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