1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22
23 #include <cassert>
24
25 #include <osl/file.hxx>
26 #include <osl/signal.h>
27
28 #include <desktop/exithelper.h>
29
30 #include <comphelper/processfactory.hxx>
31 #include <comphelper/asyncnotification.hxx>
32 #include <i18nlangtag/mslangid.hxx>
33 #include <unotools/syslocale.hxx>
34 #include <unotools/syslocaleoptions.hxx>
35 #include <vcl/QueueInfo.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/vclmain.hxx>
38 #include <vcl/wrkwin.hxx>
39 #include <vcl/cvtgrf.hxx>
40 #include <vcl/scheduler.hxx>
41 #include <vcl/image.hxx>
42 #include <vcl/ImageTree.hxx>
43 #include <vcl/settings.hxx>
44 #include <vcl/toolkit/unowrap.hxx>
45 #include <configsettings.hxx>
46 #include <vcl/lazydelete.hxx>
47 #include <vcl/embeddedfontshelper.hxx>
48 #include <vcl/toolkit/dialog.hxx>
49 #include <vcl/menu.hxx>
50 #include <vcl/virdev.hxx>
51 #include <vcl/print.hxx>
52 #include <debugevent.hxx>
53 #include <scrwnd.hxx>
54 #include <windowdev.hxx>
55 #include <saldatabasic.hxx>
56
57 #ifdef _WIN32
58 #include <svsys.h>
59 #include <process.h>
60 #include <ole2.h>
61 #else
62 #include <stdlib.h>
63 #endif
64
65 #ifdef ANDROID
66 #include <cppuhelper/bootstrap.hxx>
67 #include <jni.h>
68 #endif
69
70 #include <impfontcache.hxx>
71 #include <salinst.hxx>
72 #include <svdata.hxx>
73 #include <vcl/svmain.hxx>
74 #include <dbggui.hxx>
75 #include <accmgr.hxx>
76 #include <PhysicalFontCollection.hxx>
77 #include <print.h>
78 #include <salsys.hxx>
79 #include <saltimer.hxx>
80 #include <displayconnectiondispatch.hxx>
81
82 #include <config_features.h>
83 #include <config_feature_opencl.h>
84
85 #include <osl/process.h>
86 #include <com/sun/star/lang/XComponent.hpp>
87 #include <com/sun/star/frame/Desktop.hpp>
88
89 #ifdef _WIN32
90 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
91 #endif
92
93 #include <comphelper/lok.hxx>
94 #include <cppuhelper/implbase.hxx>
95 #include <uno/current_context.hxx>
96
97 #include <opencl/OpenCLZone.hxx>
98 #include <opengl/zone.hxx>
99 #include <skia/zone.hxx>
100 #include <watchdog.hxx>
101
102 #include <basegfx/utils/systemdependentdata.hxx>
103 #include <tools/diagnose_ex.h>
104
105 #if OSL_DEBUG_LEVEL > 0
106 #include <typeinfo>
107 #include <rtl/strbuf.hxx>
108 #endif
109
110 using namespace ::com::sun::star;
111
112 static bool g_bIsLeanException;
113
VCLExceptionSignal_impl(void *,oslSignalInfo * pInfo)114 static oslSignalAction VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo* pInfo)
115 {
116 static volatile bool bIn = false;
117
118 // if we crash again, bail out immediately
119 if ( bIn || g_bIsLeanException)
120 return osl_Signal_ActCallNextHdl;
121
122 ExceptionCategory nVCLException = ExceptionCategory::NONE;
123
124 // UAE
125 if ( (pInfo->Signal == osl_Signal_AccessViolation) ||
126 (pInfo->Signal == osl_Signal_IntegerDivideByZero) ||
127 (pInfo->Signal == osl_Signal_FloatDivideByZero) ||
128 (pInfo->Signal == osl_Signal_DebugBreak) )
129 {
130 nVCLException = ExceptionCategory::System;
131 #if HAVE_FEATURE_OPENGL
132 if (OpenGLZone::isInZone())
133 OpenGLZone::hardDisable();
134 #endif
135 #if HAVE_FEATURE_SKIA
136 if (SkiaZone::isInZone())
137 SkiaZone::hardDisable();
138 #endif
139 #if HAVE_FEATURE_OPENCL
140 if (OpenCLZone::isInZone())
141 {
142 OpenCLZone::hardDisable();
143 #ifdef _WIN32
144 if (OpenCLInitialZone::isInZone())
145 TerminateProcess(GetCurrentProcess(), EXITHELPER_NORMAL_RESTART);
146 #endif
147 }
148 #endif
149 }
150
151 // DISPLAY-Unix
152 if ((pInfo->Signal == osl_Signal_User) &&
153 (pInfo->UserSignal == OSL_SIGNAL_USER_X11SUBSYSTEMERROR) )
154 nVCLException = ExceptionCategory::UserInterface;
155
156 if ( nVCLException != ExceptionCategory::NONE )
157 {
158 bIn = true;
159
160 vcl::SolarMutexTryAndBuyGuard aLock;
161 if( aLock.isAcquired())
162 {
163 // do not stop timer because otherwise the UAE-Box will not be painted as well
164 ImplSVData* pSVData = ImplGetSVData();
165 if ( pSVData->mpApp )
166 {
167 SystemWindowFlags nOldMode = Application::GetSystemWindowMode();
168 Application::SetSystemWindowMode( nOldMode & ~SystemWindowFlags::NOAUTOMODE );
169 pSVData->mpApp->Exception( nVCLException );
170 Application::SetSystemWindowMode( nOldMode );
171 }
172 }
173 bIn = false;
174 }
175
176 return osl_Signal_ActCallNextHdl;
177
178 }
179
ImplSVMain()180 int ImplSVMain()
181 {
182 // The 'real' SVMain()
183 ImplSVData* pSVData = ImplGetSVData();
184
185 SAL_WARN_IF( !pSVData->mpApp, "vcl", "no instance of class Application" );
186
187 int nReturn = EXIT_FAILURE;
188
189 const bool bWasInitVCL = IsVCLInit();
190 const bool bInit = bWasInitVCL || InitVCL();
191 int nRet = 0;
192 if (!bWasInitVCL && bInit && pSVData->mpDefInst->SVMainHook(&nRet))
193 return nRet;
194
195 if( bInit )
196 {
197 // call application main
198 pSVData->maAppData.mbInAppMain = true;
199 nReturn = pSVData->mpApp->Main();
200 pSVData->maAppData.mbInAppMain = false;
201 }
202
203 if( pSVData->mxDisplayConnection.is() )
204 {
205 pSVData->mxDisplayConnection->terminate();
206 pSVData->mxDisplayConnection.clear();
207 }
208
209 // This is a hack to work around the problem of the asynchronous nature
210 // of bridging accessibility through Java: on shutdown there might still
211 // be some events in the AWT EventQueue, which need the SolarMutex which
212 // - on the other hand - is destroyed in DeInitVCL(). So empty the queue
213 // here ..
214 if( pSVData->mxAccessBridge.is() )
215 {
216 {
217 SolarMutexReleaser aReleaser;
218 pSVData->mxAccessBridge->dispose();
219 }
220 pSVData->mxAccessBridge.clear();
221 }
222
223 WatchdogThread::stop();
224 DeInitVCL();
225
226 return nReturn;
227 }
228
SVMain()229 int SVMain()
230 {
231 return ImplSVMain();
232 }
233
234 // This variable is set when no Application object has been instantiated
235 // before InitVCL is called
236 static Application * pOwnSvApp = nullptr;
237
238 // Exception handler. pExceptionHandler != NULL => VCL already inited
239 static oslSignalHandler pExceptionHandler = nullptr;
240
241 namespace {
242
243 class DesktopEnvironmentContext: public cppu::WeakImplHelper< css::uno::XCurrentContext >
244 {
245 public:
DesktopEnvironmentContext(const css::uno::Reference<css::uno::XCurrentContext> & ctx)246 explicit DesktopEnvironmentContext( const css::uno::Reference< css::uno::XCurrentContext > & ctx)
247 : m_xNextContext( ctx ) {}
248
249 // XCurrentContext
250 virtual css::uno::Any SAL_CALL getValueByName( const OUString& Name ) override;
251
252 private:
253 css::uno::Reference< css::uno::XCurrentContext > m_xNextContext;
254 };
255
256 }
257
getValueByName(const OUString & Name)258 uno::Any SAL_CALL DesktopEnvironmentContext::getValueByName( const OUString& Name)
259 {
260 uno::Any retVal;
261
262 if ( Name == "system.desktop-environment" )
263 {
264 retVal <<= Application::GetDesktopEnvironment();
265 }
266 else if( m_xNextContext.is() )
267 {
268 // Call next context in chain if found
269 retVal = m_xNextContext->getValueByName( Name );
270 }
271 return retVal;
272 }
273
IsVCLInit()274 bool IsVCLInit()
275 {
276 ImplSVData* pSVData = ImplGetSVData();
277 return pExceptionHandler != nullptr &&
278 pSVData->mpApp != nullptr &&
279 pSVData->mpDefInst != nullptr;
280 }
281
282 #ifdef DBG_UTIL
283 namespace vclmain
284 {
isAlive()285 bool isAlive()
286 {
287 return ImplGetSVData()->mpDefInst;
288 }
289 }
290 #endif
291
292
InitVCL()293 bool InitVCL()
294 {
295 if (IsVCLInit())
296 {
297 SAL_INFO("vcl.app", "Double initialization of vcl");
298 return true;
299 }
300
301 if( pExceptionHandler != nullptr )
302 return false;
303
304 EmbeddedFontsHelper::clearTemporaryFontFiles();
305
306 if( !ImplGetSVData()->mpApp )
307 {
308 pOwnSvApp = new Application();
309 }
310
311 ImplSVData* pSVData = ImplGetSVData();
312
313 // remember Main-Thread-Id
314 pSVData->mnMainThreadId = ::osl::Thread::getCurrentIdentifier();
315
316 // Initialize Sal
317 pSVData->mpDefInst = CreateSalInstance();
318 if ( !pSVData->mpDefInst )
319 return false;
320
321 // Desktop Environment context (to be able to get value of "system.desktop-environment" as soon as possible)
322 css::uno::setCurrentContext(
323 new DesktopEnvironmentContext( css::uno::getCurrentContext() ) );
324
325 // Initialize application instance (should be done after initialization of VCL SAL part)
326 if (pSVData->mpApp)
327 {
328 // call init to initialize application class
329 // soffice/sfx implementation creates the global service manager
330 pSVData->mpApp->Init();
331 }
332
333 try
334 {
335 //Now that uno has been bootstrapped we can ask the config what the UI language is so that we can
336 //force that in as $LANGUAGE. That way we can get gtk to render widgets RTL
337 //if we have a RTL UI in an otherwise LTR locale and get gettext using externals (e.g. python)
338 //to match their translations to our preferred UI language
339 OUString aLocaleString(SvtSysLocaleOptions().GetRealUILanguageTag().getGlibcLocaleString(u".UTF-8"));
340 if (!aLocaleString.isEmpty())
341 {
342 MsLangId::getSystemUILanguage(); //call this now to pin what the system UI really was
343 OUString envVar("LANGUAGE");
344 osl_setEnvironment(envVar.pData, aLocaleString.pData);
345 }
346 }
347 catch (const uno::Exception &)
348 {
349 TOOLS_INFO_EXCEPTION("vcl.app", "Unable to get ui language:");
350 }
351
352 pSVData->mpDefInst->AfterAppInit();
353
354 // Fetch AppFileName and make it absolute before the workdir changes...
355 OUString aExeFileName;
356 osl_getExecutableFile( &aExeFileName.pData );
357
358 // convert path to native file format
359 OUString aNativeFileName;
360 osl::FileBase::getSystemPathFromFileURL( aExeFileName, aNativeFileName );
361 pSVData->maAppData.mxAppFileName = aNativeFileName;
362
363 // Initialize global data
364 pSVData->maGDIData.mxScreenFontList = std::make_shared<PhysicalFontCollection>();
365 pSVData->maGDIData.mxScreenFontCache = std::make_shared<ImplFontCache>();
366 pSVData->maGDIData.mxGrfConverter.reset(new GraphicConverter);
367
368 g_bIsLeanException = getenv("LO_LEAN_EXCEPTION") != nullptr;
369 // Set exception handler
370 pExceptionHandler = osl_addSignalHandler(VCLExceptionSignal_impl, nullptr);
371
372 #ifndef NDEBUG
373 DbgGUIInitSolarMutexCheck();
374 #endif
375
376 #if OSL_DEBUG_LEVEL > 0
377 DebugEventInjector::getCreate();
378 #endif
379
380 #ifndef _WIN32
381 // Clear startup notification details for child processes
382 // See https://bugs.freedesktop.org/show_bug.cgi?id=11375 for discussion
383 unsetenv("DESKTOP_STARTUP_ID");
384 #endif
385
386 return true;
387 }
388
389 namespace
390 {
391
392 /** Serves for destroying the VCL UNO wrapper as late as possible. This avoids
393 crash at exit in some special cases when a11y is enabled (e.g., when
394 a bundled extension is registered/deregistered during startup, forcing exit
395 while the app is still in splash screen.)
396 */
397 class VCLUnoWrapperDeleter : public cppu::WeakImplHelper<css::lang::XEventListener>
398 {
399 virtual void SAL_CALL disposing(lang::EventObject const& rSource) override;
400 };
401
402 void
disposing(lang::EventObject const &)403 VCLUnoWrapperDeleter::disposing(lang::EventObject const& /* rSource */)
404 {
405 ImplSVData* const pSVData = ImplGetSVData();
406 if (pSVData && pSVData->mpUnoWrapper)
407 {
408 pSVData->mpUnoWrapper->Destroy();
409 pSVData->mpUnoWrapper = nullptr;
410 }
411 }
412
413 }
414
DeInitVCL()415 void DeInitVCL()
416 {
417 // The LOK Windows map container should be empty
418 assert(vcl::Window::IsLOKWindowsEmpty());
419
420 //rhbz#1444437, when using LibreOffice like a library you can't realistically
421 //tear everything down and recreate them on the next call, there's too many
422 //(c++) singletons that point to stuff that gets deleted during shutdown
423 //which won't be recreated on restart.
424 if (comphelper::LibreOfficeKit::isActive())
425 return;
426
427 {
428 SolarMutexReleaser r; // unblock threads blocked on that so we can join
429 ::comphelper::JoinAsyncEventNotifiers();
430 }
431 ImplSVData* pSVData = ImplGetSVData();
432
433 // lp#1560328: clear cache before disposing rest of VCL
434 if(pSVData->mpBlendFrameCache)
435 pSVData->mpBlendFrameCache->m_aLastResult.Clear();
436 pSVData->mbDeInit = true;
437
438 vcl::DeleteOnDeinitBase::ImplDeleteOnDeInit();
439
440 #if OSL_DEBUG_LEVEL > 0
441 OStringBuffer aBuf( 256 );
442 aBuf.append( "DeInitVCL: some top Windows are still alive\n" );
443 tools::Long nTopWindowCount = Application::GetTopWindowCount();
444 tools::Long nBadTopWindows = nTopWindowCount;
445 for( tools::Long i = 0; i < nTopWindowCount; i++ )
446 {
447 vcl::Window* pWin = Application::GetTopWindow( i );
448 // default window will be destroyed further down
449 // but may still be useful during deinit up to that point
450 if( pWin == pSVData->mpDefaultWin )
451 nBadTopWindows--;
452 else
453 {
454 aBuf.append( "text = \"" );
455 aBuf.append( OUStringToOString( pWin->GetText(), osl_getThreadTextEncoding() ) );
456 aBuf.append( "\" type = \"" );
457 aBuf.append( typeid(*pWin).name() );
458 aBuf.append( "\", ptr = 0x" );
459 aBuf.append( reinterpret_cast<sal_Int64>( pWin ), 16 );
460 aBuf.append( "\n" );
461 }
462 }
463 SAL_WARN_IF( nBadTopWindows!=0, "vcl", aBuf.getStr() );
464 #endif
465
466 ImageTree::get().shutdown();
467
468 osl_removeSignalHandler( pExceptionHandler);
469 pExceptionHandler = nullptr;
470
471 // free global data
472 pSVData->maGDIData.mxGrfConverter.reset();
473 pSVData->mpSettingsConfigItem.reset();
474
475 // prevent unnecessary painting during Scheduler shutdown
476 // as this processes all pending events in debug builds.
477 ImplGetSystemDependentDataManager().flushAll();
478
479 Scheduler::ImplDeInitScheduler();
480
481 pSVData->mpWinData->maMsgBoxImgList.clear();
482 pSVData->maCtrlData.maCheckImgList.clear();
483 pSVData->maCtrlData.maRadioImgList.clear();
484 pSVData->maCtrlData.mpDisclosurePlus.reset();
485 pSVData->maCtrlData.mpDisclosureMinus.reset();
486 pSVData->mpDefaultWin.disposeAndClear();
487
488 #if defined _WIN32
489 // See GetSystemClipboard (vcl/source/treelist/transfer2.cxx):
490 if (auto const comp = css::uno::Reference<css::lang::XComponent>(
491 pSVData->m_xSystemClipboard, css::uno::UNO_QUERY))
492 {
493 SolarMutexReleaser r; // unblock pending "clipboard content changed" notifications
494 comp->dispose(); // will use s_aClipboardSingletonMutex for CWinClipboard
495 }
496 pSVData->m_xSystemClipboard.clear();
497 #endif
498
499 #ifndef NDEBUG
500 DbgGUIDeInitSolarMutexCheck();
501 #endif
502
503 if ( pSVData->mpUnoWrapper )
504 {
505 try
506 {
507 uno::Reference<frame::XDesktop2> const xDesktop = frame::Desktop::create(
508 comphelper::getProcessComponentContext() );
509 xDesktop->addEventListener(new VCLUnoWrapperDeleter);
510 }
511 catch (uno::Exception const&)
512 {
513 // ignore
514 }
515 }
516
517 if( pSVData->mpApp || pSVData->maDeInitHook.IsSet() )
518 {
519 SolarMutexReleaser aReleaser;
520 // call deinit to deinitialize application class
521 // soffice/sfx implementation disposes the global service manager
522 // Warning: After this call you can't call uno services
523 if( pSVData->mpApp )
524 {
525 pSVData->mpApp->DeInit();
526 }
527 if( pSVData->maDeInitHook.IsSet() )
528 {
529 pSVData->maDeInitHook.Call(nullptr);
530 }
531 }
532
533 if ( pSVData->maAppData.mpSettings )
534 {
535 if ( pSVData->maAppData.mpCfgListener )
536 {
537 pSVData->maAppData.mpSettings->GetSysLocale().GetOptions().RemoveListener( pSVData->maAppData.mpCfgListener );
538 delete pSVData->maAppData.mpCfgListener;
539 }
540
541 pSVData->maAppData.mpSettings.reset();
542 }
543 if ( pSVData->maAppData.mpAccelMgr )
544 {
545 delete pSVData->maAppData.mpAccelMgr;
546 pSVData->maAppData.mpAccelMgr = nullptr;
547 }
548 pSVData->maAppData.maKeyListeners.clear();
549 pSVData->mpBlendFrameCache.reset();
550
551 ImplDeletePrnQueueList();
552
553 // destroy all Sal interfaces before destroying the instance
554 // and thereby unloading the plugin
555 pSVData->mpSalSystem.reset();
556 assert( !pSVData->maSchedCtx.mpSalTimer );
557 delete pSVData->maSchedCtx.mpSalTimer;
558 pSVData->maSchedCtx.mpSalTimer = nullptr;
559
560 pSVData->mpDefaultWin = nullptr;
561 pSVData->mpIntroWindow = nullptr;
562 pSVData->maAppData.mpActivePopupMenu = nullptr;
563 pSVData->maAppData.mpWheelWindow = nullptr;
564 pSVData->maGDIData.mpFirstWinGraphics = nullptr;
565 pSVData->maGDIData.mpLastWinGraphics = nullptr;
566 pSVData->maGDIData.mpFirstVirGraphics = nullptr;
567 pSVData->maGDIData.mpLastVirGraphics = nullptr;
568 pSVData->maGDIData.mpFirstPrnGraphics = nullptr;
569 pSVData->maGDIData.mpLastPrnGraphics = nullptr;
570 pSVData->maGDIData.mpFirstVirDev = nullptr;
571 pSVData->maGDIData.mpFirstPrinter = nullptr;
572 pSVData->maFrameData.mpFirstFrame = nullptr;
573 pSVData->maFrameData.mpAppWin = nullptr;
574 pSVData->maFrameData.mpActiveApplicationFrame = nullptr;
575 pSVData->mpWinData->mpCaptureWin = nullptr;
576 pSVData->mpWinData->mpLastDeacWin = nullptr;
577 pSVData->mpWinData->mpFirstFloat = nullptr;
578 pSVData->mpWinData->mpExecuteDialogs.clear();
579 pSVData->mpWinData->mpExtTextInputWin = nullptr;
580 pSVData->mpWinData->mpTrackWin = nullptr;
581 pSVData->mpWinData->mpAutoScrollWin = nullptr;
582 pSVData->mpWinData->mpLastWheelWindow = nullptr;
583
584 pSVData->maGDIData.mxScreenFontList.reset();
585 pSVData->maGDIData.mxScreenFontCache.reset();
586 pSVData->maGDIData.maScaleCache.remove_if([](const lru_scale_cache::key_value_pair_t&)
587 { return true; });
588
589 pSVData->maGDIData.maThemeDrawCommandsCache.clear();
590 pSVData->maGDIData.maThemeImageCache.clear();
591
592 // Deinit Sal
593 if (pSVData->mpDefInst)
594 {
595 DestroySalInstance( pSVData->mpDefInst );
596 pSVData->mpDefInst = nullptr;
597 }
598
599 // This only works on Linux. On Mac and Windows I get very
600 // weird segment violations.
601 #if defined LINUX
602 delete pSVData->mpSalData;
603 #endif
604
605 if( pOwnSvApp )
606 {
607 delete pOwnSvApp;
608 pOwnSvApp = nullptr;
609 }
610
611 EmbeddedFontsHelper::clearTemporaryFontFiles();
612 }
613
614 namespace {
615
616 // only one call is allowed
617 struct WorkerThreadData
618 {
619 oslWorkerFunction pWorker;
620 void * pThreadData;
WorkerThreadData__anon21f408000411::WorkerThreadData621 WorkerThreadData( oslWorkerFunction pWorker_, void * pThreadData_ )
622 : pWorker( pWorker_ )
623 , pThreadData( pThreadData_ )
624 {
625 }
626 };
627
628 }
629
630 #ifdef _WIN32
631 static HANDLE hThreadID = nullptr;
threadmain(void * pArgs)632 static unsigned __stdcall threadmain( void *pArgs )
633 {
634 OleInitialize( nullptr );
635 static_cast<WorkerThreadData*>(pArgs)->pWorker( static_cast<WorkerThreadData*>(pArgs)->pThreadData );
636 delete static_cast<WorkerThreadData*>(pArgs);
637 OleUninitialize();
638 hThreadID = nullptr;
639 return 0;
640 }
641 #else
642 static oslThread hThreadID = nullptr;
643 extern "C"
644 {
MainWorkerFunction(void * pArgs)645 static void MainWorkerFunction( void* pArgs )
646 {
647 static_cast<WorkerThreadData*>(pArgs)->pWorker( static_cast<WorkerThreadData*>(pArgs)->pThreadData );
648 delete static_cast<WorkerThreadData*>(pArgs);
649 hThreadID = nullptr;
650 }
651 } // extern "C"
652 #endif
653
CreateMainLoopThread(oslWorkerFunction pWorker,void * pThreadData)654 void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData )
655 {
656 #ifdef _WIN32
657 // sal thread always call CoInitializeEx, so a system dependent implementation is necessary
658
659 unsigned uThreadID;
660 hThreadID = reinterpret_cast<HANDLE>(_beginthreadex(
661 nullptr, // no security handle
662 0, // stacksize 0 means default
663 threadmain, // thread worker function
664 new WorkerThreadData( pWorker, pThreadData ), // arguments for worker function
665 0, // 0 means: create immediately otherwise use CREATE_SUSPENDED
666 &uThreadID )); // thread id to fill
667 #else
668 hThreadID = osl_createThread( MainWorkerFunction, new WorkerThreadData( pWorker, pThreadData ) );
669 #endif
670 }
671
JoinMainLoopThread()672 void JoinMainLoopThread()
673 {
674 if( hThreadID )
675 {
676 #ifdef _WIN32
677 WaitForSingleObject(hThreadID, INFINITE);
678 #else
679 osl_joinWithThread(hThreadID);
680 osl_destroyThread( hThreadID );
681 #endif
682 }
683 }
684
685 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
686