summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-08-03 20:40:26 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-04 08:40:47 +0200
commit1082943bd8ab8174f0256f41b0d417950060e240 (patch)
tree1d52a020d4e0cb0c84e066eb5c9f8362c8dbd229 /toolkit
parentfba874c162bcb78f2979f4da57ccd4c384c71d72 (diff)
osl::Mutex->std::mutex in getDefaultFormats
Change-Id: I884416cae7d968f1869fb949eb81ab378573a4dd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119950 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/source/controls/formattedcontrol.cxx46
1 files changed, 17 insertions, 29 deletions
diff --git a/toolkit/source/controls/formattedcontrol.cxx b/toolkit/source/controls/formattedcontrol.cxx
index d2acd9c2e17d..2a24c23c53b7 100644
--- a/toolkit/source/controls/formattedcontrol.cxx
+++ b/toolkit/source/controls/formattedcontrol.cxx
@@ -31,6 +31,7 @@
#include <osl/diagnose.h>
#include <helper/unopropertyarrayhelper.hxx>
+#include <mutex>
namespace toolkit
{
@@ -46,61 +47,48 @@ namespace toolkit
namespace
{
- ::osl::Mutex& getDefaultFormatsMutex()
+ std::mutex& getDefaultFormatsMutex()
{
- static ::osl::Mutex s_aDefaultFormatsMutex;
+ static std::mutex s_aDefaultFormatsMutex;
return s_aDefaultFormatsMutex;
}
-
- Reference< XNumberFormatsSupplier >& lcl_getDefaultFormatsAccess_nothrow()
- {
- static Reference< XNumberFormatsSupplier > s_xDefaultFormats;
- return s_xDefaultFormats;
- }
-
-
+ Reference< XNumberFormatsSupplier > s_xDefaultFormats;
bool s_bTriedCreation = false;
+ oslInterlockedCount s_refCount(0);
const Reference< XNumberFormatsSupplier >& lcl_getDefaultFormats_throw()
{
- ::osl::MutexGuard aGuard( getDefaultFormatsMutex() );
+ std::scoped_lock aGuard( getDefaultFormatsMutex() );
- Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() );
- if ( !rDefaultFormats.is() && !s_bTriedCreation )
+ if ( !s_xDefaultFormats.is() && !s_bTriedCreation )
{
s_bTriedCreation = true;
- rDefaultFormats = NumberFormatsSupplier::createWithDefaultLocale( ::comphelper::getProcessComponentContext() );
+ s_xDefaultFormats = NumberFormatsSupplier::createWithDefaultLocale( ::comphelper::getProcessComponentContext() );
}
- if ( !rDefaultFormats.is() )
+ if ( !s_xDefaultFormats.is() )
throw RuntimeException();
- return rDefaultFormats;
+ return s_xDefaultFormats;
}
-
- oslInterlockedCount s_refCount(0);
-
-
void lcl_registerDefaultFormatsClient()
{
osl_atomic_increment( &s_refCount );
}
-
void lcl_revokeDefaultFormatsClient()
{
- ::osl::ClearableMutexGuard aGuard( getDefaultFormatsMutex() );
- if ( 0 == osl_atomic_decrement( &s_refCount ) )
+ Reference< XNumberFormatsSupplier > xReleasePotentialLastReference;
{
- Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() );
- Reference< XNumberFormatsSupplier > xReleasePotentialLastReference( rDefaultFormats );
- rDefaultFormats.clear();
- s_bTriedCreation = false;
+ std::scoped_lock aGuard( getDefaultFormatsMutex() );
+ if ( 0 != osl_atomic_decrement( &s_refCount ) )
+ return;
- aGuard.clear();
- xReleasePotentialLastReference.clear();
+ xReleasePotentialLastReference = std::move(s_xDefaultFormats);
+ s_bTriedCreation = false;
}
+ xReleasePotentialLastReference.clear();
}
}