summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-11-04 15:28:37 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-11-04 14:46:01 +0100
commite128f7806961b391cfb265a1ce009b2e036622ca (patch)
treeeda1097987f07ac6e2f507f898b71ddf929e0635 /sal
parenta2058e7516a01167c2d20ed157500b38db967c64 (diff)
replace double-checked locking patterns with thread safe local statics
Change-Id: I1bf67196e97411aeecc13ed4f91d1088a315e323 Reviewed-on: https://gerrit.libreoffice.org/62839 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/bootstrap.cxx32
-rw-r--r--sal/rtl/uuid.cxx17
2 files changed, 19 insertions, 30 deletions
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index 5e0769c99630..897de890d890 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -227,10 +227,7 @@ static void getExecutableDirectory_Impl(rtl_uString ** ppDirURL)
static OUString & getIniFileName_Impl()
{
- osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
- static OUString *pStaticName = nullptr;
- if (!pStaticName)
- {
+ static OUString aStaticName = []() {
OUString fileName;
#if defined IOS
@@ -284,14 +281,10 @@ static OUString & getIniFileName_Impl()
}
#endif
- static OUString theFileName;
- if (fileName.getLength())
- theFileName = fileName;
-
- pStaticName = &theFileName;
- }
+ return fileName;
+ }();
- return *pStaticName;
+ return aStaticName;
}
// ensure the given file url has no final slash
@@ -395,20 +388,17 @@ namespace {
Bootstrap_Impl * get_static_bootstrap_handle()
{
- osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
- static Bootstrap_Impl * s_handle = nullptr;
- if (!s_handle)
- {
+ static Bootstrap_Impl* s_handle = []() {
OUString iniName(getIniFileName_Impl());
- s_handle = static_cast< Bootstrap_Impl * >(
- rtl_bootstrap_args_open(iniName.pData));
- if (!s_handle)
+ Bootstrap_Impl* that = static_cast<Bootstrap_Impl*>(rtl_bootstrap_args_open(iniName.pData));
+ if (!that)
{
- Bootstrap_Impl * that = new Bootstrap_Impl( iniName );
+ that = new Bootstrap_Impl(iniName);
++that->_nRefCount;
- s_handle = that;
}
- }
+ return that;
+ }();
+
return s_handle;
}
diff --git a/sal/rtl/uuid.cxx b/sal/rtl/uuid.cxx
index 632b842f6391..bb9490ef8b99 100644
--- a/sal/rtl/uuid.cxx
+++ b/sal/rtl/uuid.cxx
@@ -93,19 +93,18 @@ extern "C" void SAL_CALL rtl_createUuid(sal_uInt8 *pTargetUUID ,
SAL_UNUSED_PARAMETER sal_Bool)
{
{
- osl::MutexGuard g(osl::Mutex::getGlobalMutex());
- static rtlRandomPool pool = nullptr;
- if (!pool)
- {
- pool = rtl_random_createPool();
- if (!pool)
+ static rtlRandomPool pool = []() {
+ rtlRandomPool aPool = rtl_random_createPool();
+ if (!aPool)
{
abort();
- // only possible way to signal failure here (rtl_createUuid
- // being part of a fixed C API)
+ // only possible way to signal failure here (rtl_createUuid
+ // being part of a fixed C API)
}
- }
+ return aPool;
+ }();
+ osl::MutexGuard g(osl::Mutex::getGlobalMutex());
if (rtl_random_getBytes(pool, pTargetUUID, 16) != rtl_Random_E_None)
{
abort();