summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-22 08:52:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-22 12:07:54 +0100
commit85acc270fc670443cd700c471d9b495e12d4e6dc (patch)
tree59172f6ee9a51d92548dc64735946b4fcd2a3f7d /sal/osl
parenteea439b4b1305449616e8d0d368f3ccff1a7eca9 (diff)
improve function-local statics in sal
Change-Id: I0853cf13162bae44cf8a5c44a4546a73f05772d9 Reviewed-on: https://gerrit.libreoffice.org/63780 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/unx/profile.cxx14
-rw-r--r--sal/osl/w32/module.cxx5
-rw-r--r--sal/osl/w32/time.cxx12
3 files changed, 6 insertions, 25 deletions
diff --git a/sal/osl/unx/profile.cxx b/sal/osl/unx/profile.cxx
index a986dfd0d41f..589662b9b62a 100644
--- a/sal/osl/unx/profile.cxx
+++ b/sal/osl/unx/profile.cxx
@@ -879,19 +879,7 @@ static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile)
static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
{
struct flock lock;
- /* boring hack, but initializers for static vars must be constant */
- static bool bIsInitialized = false;
- static bool bLockingDisabled;
-
- if ( !bIsInitialized )
- {
- sal_Char* pEnvValue;
- pEnvValue = getenv( "STAR_PROFILE_LOCKING_DISABLED" );
-
- bLockingDisabled = pEnvValue != nullptr;
-
- bIsInitialized = true;
- }
+ static bool const bLockingDisabled = getenv( "STAR_PROFILE_LOCKING_DISABLED" ) != nullptr;
if (pFile->m_Handle < 0)
{
diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx
index de9ce4db421b..8de791a7a8e1 100644
--- a/sal/osl/w32/module.cxx
+++ b/sal/osl/w32/module.cxx
@@ -327,10 +327,7 @@ typedef BOOL (WINAPI *GetModuleInformation_PROC)(
static bool osl_addressGetModuleURL_NT_( void *pv, rtl_uString **pustrURL )
{
bool bSuccess = false; /* Assume failure */
- static HMODULE hModPsapi = nullptr;
-
- if ( !hModPsapi )
- hModPsapi = LoadLibraryW( L"PSAPI.DLL" );
+ static HMODULE hModPsapi = LoadLibraryW( L"PSAPI.DLL" );
if ( hModPsapi )
{
diff --git a/sal/osl/w32/time.cxx b/sal/osl/w32/time.cxx
index d1284b663fae..135aab368fc8 100644
--- a/sal/osl/w32/time.cxx
+++ b/sal/osl/w32/time.cxx
@@ -35,18 +35,14 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal)
typedef VOID (WINAPI *GetSystemTimePreciseAsFileTime_PROC)(LPFILETIME);
- static HMODULE hModule = nullptr;
- static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = nullptr;
-
OSL_ASSERT(pTimeVal != nullptr);
- if ( !hModule )
+ static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = [&]()
{
- hModule = GetModuleHandleW( L"Kernel32.dll" );
- if ( hModule )
- pGetSystemTimePreciseAsFileTime = reinterpret_cast<GetSystemTimePreciseAsFileTime_PROC>(
+ HMODULE hModule = GetModuleHandleW( L"Kernel32.dll" );
+ return reinterpret_cast<GetSystemTimePreciseAsFileTime_PROC>(
GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime"));
- }
+ }();
// use ~1 microsecond resolution if available
if (pGetSystemTimePreciseAsFileTime)