inline GetThreadI() (except on Windows, no dllexport for thread_local variables supported)

This commit is contained in:
Matthias Hochsteger 2021-06-11 09:51:23 +02:00
parent 6c73222f20
commit a11294baf0
2 changed files with 13 additions and 12 deletions

View File

@ -35,11 +35,7 @@ namespace ngcore
int TaskManager :: num_threads = 1; int TaskManager :: num_threads = 1;
// #ifndef __clang__
thread_local int TaskManager :: thread_id = 0; thread_local int TaskManager :: thread_id = 0;
// #else
// __thread int TaskManager :: thread_id;
// #endif
const function<void(TaskInfo&)> * TaskManager::func; const function<void(TaskInfo&)> * TaskManager::func;
const function<void()> * TaskManager::startup_function = nullptr; const function<void()> * TaskManager::startup_function = nullptr;
@ -174,10 +170,12 @@ namespace ngcore
num_threads = 1; num_threads = 1;
} }
#ifdef WIN32
int TaskManager :: GetThreadId() int TaskManager :: GetThreadId()
{ {
return thread_id; return thread_id;
} }
#endif
void TaskManager :: StartWorkers() void TaskManager :: StartWorkers()
{ {

View File

@ -78,12 +78,11 @@ namespace ngcore
// #ifndef __clang__ #ifdef WIN32 // no exported thread_local in dlls on Windows
static thread_local int thread_id; static thread_local int thread_id;
// #else #else
// static __thread int thread_id; NGCORE_API static thread_local int thread_id;
// #endif #endif
NGCORE_API static bool use_paje_trace; NGCORE_API static bool use_paje_trace;
public: public:
@ -102,11 +101,15 @@ namespace ngcore
void ResumeWorkers() { sleep = false; } void ResumeWorkers() { sleep = false; }
NGCORE_API static void SetNumThreads(int amax_threads); NGCORE_API static void SetNumThreads(int amax_threads);
NGCORE_API static int GetMaxThreads() { return max_threads; } static int GetMaxThreads() { return max_threads; }
// static int GetNumThreads() { return task_manager ? task_manager->num_threads : 1; } // static int GetNumThreads() { return task_manager ? task_manager->num_threads : 1; }
NGCORE_API static int GetNumThreads() { return num_threads; } static int GetNumThreads() { return num_threads; }
#ifdef WIN32
NGCORE_API static int GetThreadId(); NGCORE_API static int GetThreadId();
NGCORE_API int GetNumNodes() const { return num_nodes; } #else
static int GetThreadId() { return thread_id; }
#endif
int GetNumNodes() const { return num_nodes; }
static void SetPajeTrace (bool use) { use_paje_trace = use; } static void SetPajeTrace (bool use) { use_paje_trace = use; }