summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-05-24 09:18:10 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2020-05-24 10:28:59 +0200
commit1126515226b60630b3a0fd72c45258b230dfe8fd (patch)
treefbc7eedbd9cf2d15db850df27fcfb7217f53d990 /sal
parente3ca594d63daa7e59cee1f9745015f582ab4e773 (diff)
Try to blind-solve cppunittester hangs on Windows
... calling OleInitialize early in sal_main to initialize COM and concurrency. Seeing intermittent hangs in main thread in CAPNDataObject::GetData calling m_rIDataObjectOrg->GetData, and the inner stack waiting objects in the code doing apartment switching (I forgot to save a stack to paste unfortunately), I suspect that being related to incorrect concurrency model. OleInitialize docs [1] mention: Applications that use the following functionality must call OleInitialize before calling any other function in the COM library: * Clipboard * Drag and Drop * Object linking and embedding (OLE) * In-place activation ... Because OLE operations are not thread-safe, OleInitialize specifies the concurrency model as single-thread apartment. CoInitializeEx sets COINIT_MULTITHREADED by default, so possibly that might get called somewhere before clipboard/OLE code is called. I hope that this change would fix those hangs. [1] https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleinitialize Change-Id: I7213c9d6cb4bd0691a3ce355995157797d7db93f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94675 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/Executable_cppunittester.mk4
-rw-r--r--sal/cppunittester/cppunittester.cxx10
2 files changed, 10 insertions, 4 deletions
diff --git a/sal/Executable_cppunittester.mk b/sal/Executable_cppunittester.mk
index 3b9016783b80..65426e722240 100644
--- a/sal/Executable_cppunittester.mk
+++ b/sal/Executable_cppunittester.mk
@@ -28,6 +28,10 @@ $(eval $(call gb_Executable_add_exception_objects,cppunittester,\
sal/cppunittester/cppunittester \
))
+$(eval $(call gb_Executable_use_system_win32_libs,cppunittester,\
+ ole32 \
+))
+
ifeq ($(COM),MSC)
$(eval $(call gb_Executable_add_ldflags,cppunittester,\
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index a760ecf8ff41..1b3c518c4b21 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -18,10 +18,9 @@
*/
#ifdef _WIN32
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
+#include <prewin.h>
+#include <ole2.h>
+#include <postwin.h>
#endif
#ifdef UNX
@@ -389,6 +388,9 @@ SAL_IMPLEMENT_MAIN()
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG|_CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
#endif
+
+ // Tests may use e.g. OLE or clipboard; initialize COM and appropriate concurrency early
+ OleInitialize(nullptr);
#endif
std::vector<CppUnit::Protector *> protectors;