From a2058e7516a01167c2d20ed157500b38db967c64 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 4 Nov 2018 12:48:59 +0300 Subject: replace double-checked locking patterns with thread safe local statics Change-Id: Ie1aae7ecbd065a88b371d8c0deb586f54f7eff65 Reviewed-on: https://gerrit.libreoffice.org/62835 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- avmedia/source/framework/soundhandler.cxx | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'avmedia') diff --git a/avmedia/source/framework/soundhandler.cxx b/avmedia/source/framework/soundhandler.cxx index 70ed2f53c2dc..b004f7b52403 100644 --- a/avmedia/source/framework/soundhandler.cxx +++ b/avmedia/source/framework/soundhandler.cxx @@ -76,33 +76,14 @@ css::uno::Sequence< sal_Int8 > SAL_CALL SoundHandler::getImplementationId() css::uno::Sequence< css::uno::Type > SAL_CALL SoundHandler::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 ::cppu::OTypeCollection* pTypeCollection = nullptr ; - if ( pTypeCollection == nullptr ) - { - /* Ready for multithreading; get global mutex for first call of this method only! see before */ - ::osl::MutexGuard aGuard( ::osl::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 ::cppu::OTypeCollection aTypeCollection - ( - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get() - ); - /* ... and set his address to static pointer! */ - pTypeCollection = &aTypeCollection ; - } - } - return pTypeCollection->getTypes(); + static ::cppu::OTypeCollection aTypeCollection( + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get()); + + return aTypeCollection.getTypes(); } #define IMPLEMENTATIONNAME_SOUNDHANDLER OUString("com.sun.star.comp.framework.SoundHandler") -- cgit