diff options
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 15 | ||||
-rw-r--r-- | src/dbus/qdbusconnection.cpp | 35 |
2 files changed, 13 insertions, 37 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 74e191f889..a14c193bad 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -482,7 +482,6 @@ void QThread::start(Priority priority) d->returnCode = 0; d->interruptionRequested = false; -#ifndef Q_OS_WINRT /* NOTE: we create the thread in the suspended state, set the priority and then resume the thread. @@ -493,9 +492,21 @@ 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 + // MSVC -MT or -MTd build d->handle = (Qt::HANDLE) _beginthreadex(NULL, d->stackSize, QThreadPrivate::start, this, CREATE_SUSPENDED, &(d->id)); -#else // !Q_OS_WINRT +#else + // MSVC -MD or -MDd or MinGW build d->handle = (Qt::HANDLE) CreateThread(NULL, d->stackSize, (LPTHREAD_START_ROUTINE)QThreadPrivate::start, this, CREATE_SUSPENDED, reinterpret_cast<LPDWORD>(&d->id)); #endif // Q_OS_WINRT diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index bd25d8a6bf..cddb7dfb95 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -69,10 +69,6 @@ QT_BEGIN_NAMESPACE -#ifdef Q_OS_WIN -static void preventDllUnload(); -#endif - Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager) // can be replaced with a lambda in Qt 5.7 @@ -161,10 +157,6 @@ QDBusConnectionManager::QDBusConnectionManager() this, &QDBusConnectionManager::createServer, Qt::BlockingQueuedConnection); moveToThread(this); // ugly, don't do this in other projects -#ifdef Q_OS_WIN - // prevent the library from being unloaded on Windows. See comments in the function. - preventDllUnload(); -#endif defaultBuses[0] = defaultBuses[1] = Q_NULLPTR; start(); } @@ -1290,31 +1282,4 @@ QT_END_NAMESPACE #include "qdbusconnection.moc" -#ifdef Q_OS_WIN -# include <qt_windows.h> - -QT_BEGIN_NAMESPACE -static void preventDllUnload() -{ - // Thread termination is really wacky on Windows. For some reason we don't - // understand, exiting from the thread may try to unload the DLL. Since the - // QDBusConnectionManager thread runs until the DLL is unloaded, we've got - // a deadlock: the main thread is waiting for the manager thread to exit, - // but the manager thread is attempting to acquire a lock to unload the DLL. - // - // We work around the issue by preventing the unload from happening in the - // first place. - // - // For this trick, see - // https://blogs.msdn.microsoft.com/oldnewthing/20131105-00/?p=2733 - - static HMODULE self; - GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | - GET_MODULE_HANDLE_EX_FLAG_PIN, - reinterpret_cast<const wchar_t *>(&self), // any address in this DLL - &self); -} -QT_END_NAMESPACE -#endif - #endif // QT_NO_DBUS |