Kaydet (Commit) 41707751 authored tarafından Mike Kaganski's avatar Mike Kaganski

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/62825Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst a786fad5
......@@ -235,38 +235,25 @@ void SAL_CALL BackingComp::release()
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);
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);
pTypeCollection = &aTypeCollection;
/* } LOCAL SAFE */
}
/* } GLOBAL SAFE */
}
return pTypeCollection->getTypes();
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();
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);
}();
return aTypeCollection.getTypes();
}
......
......@@ -139,23 +139,10 @@ void SAL_CALL VCLXHatchWindow::release()
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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment