From 0b693175e4e70cead730a245cffa66304998196a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Sun, 7 Apr 2019 12:32:51 +0200 Subject: 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 --- src/corelib/kernel/qcoreapplication.cpp | 5 +++++ src/corelib/thread/qthread_p.h | 3 +++ src/corelib/thread/qthread_unix.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 69b2a9bf41..5c0bf93acc 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -119,6 +119,7 @@ #ifdef Q_OS_WASM #include +#include #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(); +#endif #endif // Store app name/version (so they're still available after QCoreApplication is destroyed) diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 7d9442ab79..57e6c995c5 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -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); diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index a13f8ca215..ea78b0a147 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -100,10 +100,6 @@ #include #endif -#if defined(Q_OS_WASM) -#include -#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(); + cores = QThreadPrivate::idealThreadCount; #else // the rest: Linux, Solaris, AIX, Tru64 cores = (int)sysconf(_SC_NPROCESSORS_ONLN); -- cgit v1.2.3 From 2ea3e133c369deefeae0605ad2f32aaea52c9e97 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Fri, 7 Jun 2019 14:47:31 +0200 Subject: Doc: Add Q_OS_WASM documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-76264 Change-Id: Ie167a64e0c84375012e8b1056eaae2243b09bf5d Reviewed-by: Topi Reiniƶ --- src/corelib/global/qglobal.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 7879109930..f7f04c9684 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1545,6 +1545,13 @@ bool qSharedBuild() Q_DECL_NOTHROW Defined on Any UNIX BSD/SYSV system. */ +/*! + \macro Q_OS_WASM + \relates + + Defined on Web Assembly. +*/ + /*! \macro Q_CC_SYM \relates -- cgit v1.2.3