diff options
author | Jochen Nitschke <j.nitschke+logerrit@ok.de> | 2017-06-08 21:29:23 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-06-09 13:40:37 +0200 |
commit | e78d128e3b7bf45990d1f7b27123ccd616665f93 (patch) | |
tree | 3ed3a8ee792e52f6b0cb5df085428e7b9c526c1a /UnoControls/source | |
parent | 86338ee6aa90854a0e161857d760bbdba12bf06d (diff) |
UnoControls: replace double checked locking patterns
with thread safe local statics
Change-Id: I6ba88ffc3b3489bfe4dce17c4297312dd9765f2e
Reviewed-on: https://gerrit.libreoffice.org/38594
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'UnoControls/source')
-rw-r--r-- | UnoControls/source/base/basecontainercontrol.cxx | 28 | ||||
-rw-r--r-- | UnoControls/source/base/basecontrol.cxx | 39 | ||||
-rw-r--r-- | UnoControls/source/controls/framecontrol.cxx | 68 | ||||
-rw-r--r-- | UnoControls/source/controls/progressbar.cxx | 28 | ||||
-rw-r--r-- | UnoControls/source/controls/progressmonitor.cxx | 30 | ||||
-rw-r--r-- | UnoControls/source/controls/statusindicator.cxx | 28 |
6 files changed, 44 insertions, 177 deletions
diff --git a/UnoControls/source/base/basecontainercontrol.cxx b/UnoControls/source/base/basecontainercontrol.cxx index a6fb9b97447a..766b5fa75e6d 100644 --- a/UnoControls/source/base/basecontainercontrol.cxx +++ b/UnoControls/source/base/basecontainercontrol.cxx @@ -73,30 +73,12 @@ Any SAL_CALL BaseContainerControl::queryInterface( const Type& rType ) Sequence< Type > SAL_CALL BaseContainerControl::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XControlContainer>::get(), + BaseControl::getTypes() ); - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection ( cppu::UnoType<XControlModel>::get(), - cppu::UnoType<XControlContainer>::get(), - BaseControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation diff --git a/UnoControls/source/base/basecontrol.cxx b/UnoControls/source/base/basecontrol.cxx index 81a79a4da107..f488113a273b 100644 --- a/UnoControls/source/base/basecontrol.cxx +++ b/UnoControls/source/base/basecontrol.cxx @@ -114,35 +114,16 @@ void SAL_CALL BaseControl::release() throw() Sequence< Type > SAL_CALL BaseControl::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; - - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection( cppu::UnoType<XPaintListener>::get(), - cppu::UnoType<XWindowListener>::get(), - cppu::UnoType<XView>::get(), - cppu::UnoType<XWindow>::get(), - cppu::UnoType<XServiceInfo>::get(), - cppu::UnoType<XControl>::get(), - OComponentHelper::getTypes() - ); - - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + static OTypeCollection ourTypeCollection( + cppu::UnoType<XPaintListener>::get(), + cppu::UnoType<XWindowListener>::get(), + cppu::UnoType<XView>::get(), + cppu::UnoType<XWindow>::get(), + cppu::UnoType<XServiceInfo>::get(), + cppu::UnoType<XControl>::get(), + OComponentHelper::getTypes() ); + + return ourTypeCollection.getTypes(); } // XTypeProvider diff --git a/UnoControls/source/controls/framecontrol.cxx b/UnoControls/source/controls/framecontrol.cxx index ed9b15e2870a..e9fe0371840e 100644 --- a/UnoControls/source/controls/framecontrol.cxx +++ b/UnoControls/source/controls/framecontrol.cxx @@ -107,31 +107,13 @@ void SAL_CALL FrameControl::release() throw() Sequence< Type > SAL_CALL FrameControl::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XControlContainer>::get(), + cppu::UnoType<XConnectionPointContainer>::get(), + BaseControl::getTypes() ); - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection ( cppu::UnoType<XControlModel>::get(), - cppu::UnoType<XControlContainer>::get(), - cppu::UnoType<XConnectionPointContainer>::get(), - BaseControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation @@ -353,44 +335,20 @@ void FrameControl::getFastPropertyValue( Any& rRet , IPropertyArrayHelper& FrameControl::getInfoHelper() { // Create a table that map names to index values. - static OPropertyArrayHelper* pInfo; - - if (!pInfo) - { - // global method must be guarded - MutexGuard aGuard ( Mutex::getGlobalMutex() ); + static OPropertyArrayHelper ourPropertyInfo( impl_getStaticPropertyDescriptor(), true ); - if (!pInfo) - { - pInfo = new OPropertyArrayHelper( impl_getStaticPropertyDescriptor(), true ); - } - } - - return *pInfo; + return ourPropertyInfo; } // OPropertySetHelper Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pInfo is NULL - for the second call pInfo is different from NULL! - static Reference< XPropertySetInfo >* pInfo = nullptr; - if ( pInfo == nullptr ) - { - // Ready for multithreading - MutexGuard aGuard ( Mutex::getGlobalMutex () ); - // Control this pointer again, another instance can be faster then these! - if ( pInfo == nullptr ) - { - // Create structure of propertysetinfo for baseclass "OPropertySetHelper". - // (Use method "getInfoHelper()".) - static Reference< XPropertySetInfo > xInfo ( createPropertySetInfo ( getInfoHelper () ) ); - pInfo = &xInfo; - } - } - return ( *pInfo ); + // Create structure of propertysetinfo for baseclass "OPropertySetHelper". + // (Use method "getInfoHelper()".) + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + + return xInfo; } // BaseControl diff --git a/UnoControls/source/controls/progressbar.cxx b/UnoControls/source/controls/progressbar.cxx index ceebf816199b..3cc8372da483 100644 --- a/UnoControls/source/controls/progressbar.cxx +++ b/UnoControls/source/controls/progressbar.cxx @@ -106,30 +106,12 @@ void SAL_CALL ProgressBar::release() throw() Sequence< Type > SAL_CALL ProgressBar::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XProgressBar>::get(), + BaseControl::getTypes() ); - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection ( cppu::UnoType<XControlModel>::get(), - cppu::UnoType<XProgressBar>::get(), - BaseControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx index 3354e60131c1..cabdc1a15ddc 100644 --- a/UnoControls/source/controls/progressmonitor.cxx +++ b/UnoControls/source/controls/progressmonitor.cxx @@ -147,31 +147,13 @@ void SAL_CALL ProgressMonitor::release() throw() // XTypeProvider Sequence< Type > SAL_CALL ProgressMonitor::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XButton>::get(), + cppu::UnoType<XProgressMonitor>::get(), + BaseContainerControl::getTypes() ); - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection ( cppu::UnoType<XLayoutConstrains>::get(), - cppu::UnoType<XButton>::get(), - cppu::UnoType<XProgressMonitor>::get(), - BaseContainerControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation diff --git a/UnoControls/source/controls/statusindicator.cxx b/UnoControls/source/controls/statusindicator.cxx index 9d3f714bc2a9..e0c79a936ce7 100644 --- a/UnoControls/source/controls/statusindicator.cxx +++ b/UnoControls/source/controls/statusindicator.cxx @@ -115,30 +115,12 @@ void SAL_CALL StatusIndicator::release() throw() Sequence< Type > SAL_CALL StatusIndicator::getTypes() { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTypeCollection* pTypeCollection = nullptr; + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XStatusIndicator>::get(), + BaseContainerControl::getTypes() ); - if ( pTypeCollection == nullptr ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MutexGuard aGuard( Mutex::getGlobalMutex() ); - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == nullptr ) - { - // Create a static typecollection ... - static OTypeCollection aTypeCollection ( cppu::UnoType<XLayoutConstrains>::get(), - cppu::UnoType<XStatusIndicator>::get(), - BaseContainerControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation |