wasm: make idealThreadCount() work on all threads
navigator.hardwareConcurrency can be accessed from the main thread only. Read and cache the value on QCoreApplication initialization. Change-Id: I731f7f356ce106c7107977783d4b763326af06b6 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
parent
c996d13126
commit
0b693175e4
|
|
@ -119,6 +119,7 @@
|
|||
|
||||
#ifdef Q_OS_WASM
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/val.h>
|
||||
#endif
|
||||
|
||||
#ifdef QT_BOOTSTRAPPED
|
||||
|
|
@ -800,6 +801,10 @@ void QCoreApplicationPrivate::init()
|
|||
Module.print(err);
|
||||
});
|
||||
);
|
||||
|
||||
#if QT_CONFIG(thread)
|
||||
QThreadPrivate::idealThreadCount = emscripten::val::global("navigator")["hardwareConcurrency"].as<int>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Store app name/version (so they're still available after QCoreApplication is destroyed)
|
||||
|
|
|
|||
|
|
@ -195,6 +195,9 @@ public:
|
|||
int waiters;
|
||||
bool terminationEnabled, terminatePending;
|
||||
#endif // Q_OS_WIN
|
||||
#ifdef Q_OS_WASM
|
||||
static int idealThreadCount;
|
||||
#endif
|
||||
QThreadData *data;
|
||||
|
||||
static QAbstractEventDispatcher *createEventDispatcher(QThreadData *data);
|
||||
|
|
|
|||
|
|
@ -100,10 +100,6 @@
|
|||
#include <sys/neutrino.h>
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WASM)
|
||||
#include <emscripten/val.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if QT_CONFIG(thread)
|
||||
|
|
@ -454,6 +450,10 @@ Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW
|
|||
# define _SC_NPROCESSORS_ONLN 84
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WASM
|
||||
int QThreadPrivate::idealThreadCount = 1;
|
||||
#endif
|
||||
|
||||
int QThread::idealThreadCount() Q_DECL_NOTHROW
|
||||
{
|
||||
int cores = 1;
|
||||
|
|
@ -503,7 +503,7 @@ int QThread::idealThreadCount() Q_DECL_NOTHROW
|
|||
cores = 1;
|
||||
# endif
|
||||
#elif defined(Q_OS_WASM)
|
||||
cores = emscripten::val::global("navigator")["hardwareConcurrency"].as<int>();
|
||||
cores = QThreadPrivate::idealThreadCount;
|
||||
#else
|
||||
// the rest: Linux, Solaris, AIX, Tru64
|
||||
cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
|
|
|||
Loading…
Reference in New Issue