tdf#120703 PVS: V547 Get rid of mutexes to initialize function-local statics

Also fix an infinite recursion when VCLXHatchWindow::getTypes() called
VCLXHatchWindow::getTypes() when initializing its static.

Change-Id: I19b8b1e1b367ddf636f905fb141c7690e21f67f8
Reviewed-on: https://gerrit.libreoffice.org/62825
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sfx2/source/dialog/backingcomp.cxx b/sfx2/source/dialog/backingcomp.cxx
index d6e36f7..015ce31 100644
--- a/sfx2/source/dialog/backingcomp.cxx
+++ b/sfx2/source/dialog/backingcomp.cxx
@@ -235,38 +235,25 @@

css::uno::Sequence< css::uno::Type > SAL_CALL BackingComp::getTypes()
{
    static ::cppu::OTypeCollection* pTypeCollection = nullptr;
    if (!pTypeCollection)
    {
        /* GLOBAL SAFE { */
        ::osl::MutexGuard aGlobalLock(m_aTypeProviderMutex);
        // Control these pointer again ... it can be, that another instance will be faster then this one!
        if (!pTypeCollection)
        {
            /* LOCAL SAFE { */
            SolarMutexGuard aGuard;
            css::uno::Reference< css::lang::XTypeProvider > xProvider(m_xWindow, css::uno::UNO_QUERY);
    static cppu::OTypeCollection aTypeCollection = [this]() {
        SolarMutexGuard aGuard;
        css::uno::Reference<css::lang::XTypeProvider> xProvider(m_xWindow, css::uno::UNO_QUERY);

            css::uno::Sequence< css::uno::Type > lWindowTypes;
            if (xProvider.is())
                lWindowTypes = xProvider->getTypes();
        css::uno::Sequence<css::uno::Type> lWindowTypes;
        if (xProvider.is())
            lWindowTypes = xProvider->getTypes();

            static ::cppu::OTypeCollection aTypeCollection(
                    cppu::UnoType<css::lang::XInitialization>::get(),
                    cppu::UnoType<css::lang::XTypeProvider>::get(),
                    cppu::UnoType<css::lang::XServiceInfo>::get(),
                    cppu::UnoType<css::frame::XController>::get(),
                    cppu::UnoType<css::lang::XComponent>::get(),
                    cppu::UnoType<css::frame::XDispatchProvider>::get(),
                    cppu::UnoType<css::frame::XDispatch>::get(),
                    lWindowTypes);
        return cppu::OTypeCollection(
            cppu::UnoType<css::lang::XInitialization>::get(),
            cppu::UnoType<css::lang::XTypeProvider>::get(),
            cppu::UnoType<css::lang::XServiceInfo>::get(),
            cppu::UnoType<css::frame::XController>::get(),
            cppu::UnoType<css::lang::XComponent>::get(),
            cppu::UnoType<css::frame::XDispatchProvider>::get(),
            cppu::UnoType<css::frame::XDispatch>::get(), lWindowTypes);
    }();

            pTypeCollection = &aTypeCollection;
            /* } LOCAL SAFE */
        }
        /* } GLOBAL SAFE */
    }
    return pTypeCollection->getTypes();
    return aTypeCollection.getTypes();
}


diff --git a/svtools/source/hatchwindow/hatchwindow.cxx b/svtools/source/hatchwindow/hatchwindow.cxx
index 0e8b4b9..02a0c8a 100644
--- a/svtools/source/hatchwindow/hatchwindow.cxx
+++ b/svtools/source/hatchwindow/hatchwindow.cxx
@@ -139,23 +139,10 @@

uno::Sequence< uno::Type > SAL_CALL VCLXHatchWindow::getTypes()
{
    static ::cppu::OTypeCollection* pTypeCollection = nullptr ;
    static cppu::OTypeCollection aTypeCollection(cppu::UnoType<embed::XHatchWindow>::get(),
                                                 VCLXWindow::getTypes());

    if ( pTypeCollection == nullptr )
    {
        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;

        if ( pTypeCollection == nullptr )
        {
            static ::cppu::OTypeCollection aTypeCollection(
                    cppu::UnoType<embed::XHatchWindow>::get(),
                    VCLXHatchWindow::getTypes() );

            pTypeCollection = &aTypeCollection ;
        }
    }

    return pTypeCollection->getTypes() ;
    return aTypeCollection.getTypes();
}

uno::Sequence< sal_Int8 > SAL_CALL VCLXHatchWindow::getImplementationId()