summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2016-05-02 22:01:38 -0700
committerJake Petroules <jake.petroules@qt.io>2016-06-02 22:16:47 +0000
commit3ec57107cedb154f256e3ad001ea5475cc64fa94 (patch)
tree1ef002d247ae853b89cdfc790f4c7d42ab21e767 /src/dbus
parent49e49bdbe16734c24407d10f86eece3d9317cc51 (diff)
Windows: stop using _beginthreadex on regular builds
This commit also reverts fecaa6aae83a3ffa8f1fd41c5aa8275a1bfa7c9b. The Microsoft documentation says _beginthreadex and _endthreadex are used to initialize the C/C++ runtime and are necessary when linking to libcmt(d).lib (that is, when using the -MT or -MTd options). For regular builds linking against the .dll runtime, there should be no impact. Inspection of the CRT source code which gets installed with Visual Studio or Windows SDK proves that. It's preferable to use CreateThread directly as _endthreadex will try to call FreeLibraryAndExitThread, which can cause a deadlock if we try to wait for the thread to exit from a global destructor. For -MT builds, since there can be no DLLs, it's not a problem to continue to use _beginthreadex and follow Microsoft's recommendation. Task-number: QTBUG-53031 Change-Id: Id5480807d25e49e78b79ffff144af62c3c59dfe0 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusconnection.cpp35
1 files changed, 0 insertions, 35 deletions
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