From e78d128e3b7bf45990d1f7b27123ccd616665f93 Mon Sep 17 00:00:00 2001 From: Jochen Nitschke Date: Thu, 8 Jun 2017 21:29:23 +0200 Subject: 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 Tested-by: Noel Grandin --- UnoControls/source/base/basecontainercontrol.cxx | 28 +++++------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'UnoControls/source/base/basecontainercontrol.cxx') 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::get(), + cppu::UnoType::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::get(), - cppu::UnoType::get(), - BaseControl::getTypes() - ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection; - } - } - - return pTypeCollection->getTypes(); + return ourTypeCollection.getTypes(); } // XAggregation -- cgit