diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2020-06-05 09:24:37 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2020-06-06 20:25:49 +0200 |
commit | 45b0f1be686cfba8dcecb9be5c875cae59c69276 (patch) | |
tree | 363dfd46575d147206267d854ce14747157f432e /src/corelib/thread/qthread_win.cpp | |
parent | aa81b90738ce9faee5e433617c8bd243cb238729 (diff) |
Remove winrt
Macros and the await helper function from qfunctions_winrt(_p).h are
needed in other Qt modules which use UWP APIs on desktop windows.
Task-number: QTBUG-84434
Change-Id: Ice09c11436ad151c17bdccd2c7defadd08c13925
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/thread/qthread_win.cpp')
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 121 |
1 files changed, 9 insertions, 112 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 00d67b3a00..78c4d8d672 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -46,49 +46,19 @@ #include <qpointer.h> #include <private/qcoreapplication_p.h> -#ifndef Q_OS_WINRT #include <private/qeventdispatcher_win_p.h> -#else -#include <private/qeventdispatcher_winrt_p.h> -#endif #include <qt_windows.h> -#ifndef Q_OS_WINRT -# ifndef _MT -# define _MT -# endif // _MT -# include <process.h> -#endif // Q_OS_WINRT +#ifndef _MT +# define _MT +#endif // _MT +#include <process.h> QT_BEGIN_NAMESPACE #if QT_CONFIG(thread) -#ifdef Q_OS_WINRT -inline DWORD qWinRTTlsAlloc() { - return FlsAlloc(0); -} - -inline bool qWinRTTlsFree(DWORD dwTlsIndex) { - return FlsFree(dwTlsIndex); -} - -inline LPVOID qWinRTTlsGetValue(DWORD dwTlsIndex) { - return FlsGetValue(dwTlsIndex); -} - -inline bool qWinRTTlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) { - return FlsSetValue(dwTlsIndex, lpTlsValue); -} - -#define TlsAlloc qWinRTTlsAlloc -#define TlsFree qWinRTTlsFree -#define TlsSetValue qWinRTTlsSetValue -#define TlsGetValue qWinRTTlsGetValue - -#endif // Q_OS_WINRT - void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread); DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID); @@ -142,15 +112,9 @@ QThreadData *QThreadData::current(bool createIfNecessary) threadData->isAdopted = true; threadData->threadId.storeRelaxed(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId()))); -#ifndef Q_OS_WINRT if (!QCoreApplicationPrivate::theMainThread) { QCoreApplicationPrivate::theMainThread = threadData->thread.loadRelaxed(); } else { -#else - // for winrt the main thread is set explicitly in QCoreApplication's constructor as the - // native main thread (Xaml thread) is not Qt's main thread. - { -#endif HANDLE realHandle = INVALID_HANDLE_VALUE; DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), @@ -165,33 +129,6 @@ QThreadData *QThreadData::current(bool createIfNecessary) return threadData; } -#ifdef Q_OS_WINRT -void QThreadData::setMainThread() -{ - Q_ASSERT(!QCoreApplicationPrivate::theMainThread); - qt_create_tls(); - QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index)); - if (!threadData) { - threadData = new QThreadData; - // This needs to be called prior to new AdoptedThread() to - // avoid recursion. - TlsSetValue(qt_current_thread_data_tls_index, threadData); - QT_TRY { - threadData->thread = new QAdoptedThread(threadData); - } QT_CATCH(...) { - TlsSetValue(qt_current_thread_data_tls_index, 0); - threadData->deref(); - threadData = 0; - QT_RETHROW; - } - threadData->deref(); - threadData->isAdopted = true; - threadData->threadId.storeRelaxed(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId()))); - } - QCoreApplicationPrivate::theMainThread = threadData->thread.loadRelaxed(); -} -#endif - void QAdoptedThread::init() { d_func()->handle = GetCurrentThread(); @@ -225,11 +162,7 @@ void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread) // Start watcher thread if it is not already running. if (qt_adopted_thread_watcher_id == 0) { if (qt_adopted_thread_wakeup == 0) { -#ifndef Q_OS_WINRT qt_adopted_thread_wakeup = CreateEvent(0, false, false, 0); -#else - qt_adopted_thread_wakeup = CreateEventEx(0, NULL, 0, EVENT_ALL_ACCESS); -#endif qt_adopted_thread_handles.prepend(qt_adopted_thread_wakeup); } @@ -268,21 +201,13 @@ DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID) // no need to loop, no timeout offset = 0; count = handlesCopy.count(); -#ifndef Q_OS_WINRT ret = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE); -#else - ret = WaitForMultipleObjectsEx(handlesCopy.count(), handlesCopy.constData(), false, INFINITE, false); -#endif } else { int loop = 0; do { offset = loop * MAXIMUM_WAIT_OBJECTS; count = qMin(handlesCopy.count() - offset, MAXIMUM_WAIT_OBJECTS); -#ifndef Q_OS_WINRT ret = WaitForMultipleObjects(count, handlesCopy.constData() + offset, false, 100); -#else - ret = WaitForMultipleObjectsEx(count, handlesCopy.constData() + offset, false, 100, false); -#endif loop = (loop + 1) % loops; } while (ret == WAIT_TIMEOUT); } @@ -323,7 +248,7 @@ DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID) return 0; } -#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT) +#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) #ifndef Q_OS_WIN64 # define ULONG_PTR DWORD @@ -354,7 +279,7 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName) { } } -#endif // !QT_NO_DEBUG && Q_CC_MSVC && !Q_OS_WINRT +#endif // !QT_NO_DEBUG && Q_CC_MSVC /************************************************************************** ** QThreadPrivate @@ -365,11 +290,7 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName) QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *data) { Q_UNUSED(data); -#ifndef Q_OS_WINRT return new QEventDispatcherWin32; -#else - return new QEventDispatcherWinRT; -#endif } #if QT_CONFIG(thread) @@ -392,7 +313,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi data->ensureEventDispatcher(); -#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT) +#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) // sets the name of the current thread. QByteArray objectName = thr->objectName().toLocal8Bit(); qt_set_thread_name(HANDLE(-1), @@ -457,11 +378,7 @@ Qt::HANDLE QThread::currentThreadIdImpl() noexcept int QThread::idealThreadCount() noexcept { SYSTEM_INFO sysinfo; -#ifndef Q_OS_WINRT GetSystemInfo(&sysinfo); -#else - GetNativeSystemInfo(&sysinfo); -#endif return sysinfo.dwNumberOfProcessors; } @@ -519,16 +436,7 @@ void QThread::start(Priority priority) less than NormalPriority), but the newly created thread preempts its 'parent' and runs at normal priority. */ -#if defined(Q_CC_MSVC) && !defined(_DLL) // && !defined(Q_OS_WINRT) -# ifdef Q_OS_WINRT - // If you wish to accept the memory leaks, uncomment the part above. - // See: - // https://support.microsoft.com/en-us/kb/104641 - // https://msdn.microsoft.com/en-us/library/kdzttdcb.aspx -# error "Microsoft documentation says this combination leaks memory every time a thread is started. " \ - "Please change your build back to -MD/-MDd or, if you understand this issue and want to continue, " \ - "edit this source file." -# endif +#if defined(Q_CC_MSVC) && !defined(_DLL) // MSVC -MT or -MTd build d->handle = (Qt::HANDLE) _beginthreadex(NULL, d->stackSize, QThreadPrivate::start, this, CREATE_SUSPENDED, &(d->id)); @@ -537,7 +445,7 @@ void QThread::start(Priority priority) d->handle = CreateThread(nullptr, d->stackSize, reinterpret_cast<LPTHREAD_START_ROUTINE>(QThreadPrivate::start), this, CREATE_SUSPENDED, reinterpret_cast<LPDWORD>(&d->id)); -#endif // Q_OS_WINRT +#endif if (!d->handle) { qErrnoWarning("QThread::start: Failed to create thread"); @@ -603,10 +511,7 @@ void QThread::terminate() return; } - // Calling ExitThread() in setTerminationEnabled is all we can do on WinRT -#ifndef Q_OS_WINRT TerminateThread(d->handle, 0); -#endif QThreadPrivate::finish(this, false); } @@ -626,11 +531,7 @@ bool QThread::wait(QDeadlineTimer deadline) locker.mutex()->unlock(); bool ret = false; -#ifndef Q_OS_WINRT switch (WaitForSingleObject(d->handle, deadline.remainingTime())) { -#else - switch (WaitForSingleObjectEx(d->handle, deadline.remainingTime(), false)) { -#endif case WAIT_OBJECT_0: ret = true; break; @@ -671,11 +572,7 @@ void QThread::setTerminationEnabled(bool enabled) if (enabled && d->terminatePending) { QThreadPrivate::finish(thr, false); locker.unlock(); // don't leave the mutex locked! -#ifndef Q_OS_WINRT _endthreadex(0); -#else - ExitThread(0); -#endif } } |