diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-20 13:09:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-23 13:35:25 +0100 |
commit | 70894bcdb3912dbe87031da0af9ae5d591275e2a (patch) | |
tree | ca424232691a12bfca34293b093a7d9bd21525e9 /vcl | |
parent | 0c8b936734285ee7f373c41ecbad5a65953789dc (diff) |
improve function local statics
simplify the initialisaion and make them thread-safe i.e. initialise
them using the runtime's local static locking.
Thanks to mike kaganski for pointing out the nice lambda approach that
makes this feasible.
Change-Id: I76391189a6d0a3d7eed2d0d88d28dfa6541eaff7
Reviewed-on: https://gerrit.libreoffice.org/63645
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/opengl/win/WinDeviceInfo.cxx | 9 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/gtk/gtksys.cxx | 4 |
3 files changed, 6 insertions, 12 deletions
diff --git a/vcl/opengl/win/WinDeviceInfo.cxx b/vcl/opengl/win/WinDeviceInfo.cxx index 9c48651918a5..2ebccf9ee6f4 100644 --- a/vcl/opengl/win/WinDeviceInfo.cxx +++ b/vcl/opengl/win/WinDeviceInfo.cxx @@ -190,9 +190,7 @@ wgl::OperatingSystem WindowsVersionToOperatingSystem(int32_t aWindowsVersion) int32_t WindowsOSVersion() { - static int32_t winVersion = kWindowsUnknown; - - if (winVersion == kWindowsUnknown) + static int32_t winVersion = [&]() { // GetVersion(Ex) and VersionHelpers (based on VerifyVersionInfo) API are // subject to manifest-based behavior since Windows 8.1, so give wrong results. @@ -219,13 +217,14 @@ int32_t WindowsOSVersion() if (VerQueryValueW(ver.get(), L"\\", &pBlock, &dwBlockSz) != FALSE && dwBlockSz >= sizeof(VS_FIXEDFILEINFO)) { VS_FIXEDFILEINFO *vinfo = static_cast<VS_FIXEDFILEINFO *>(pBlock); - winVersion = int32_t(vinfo->dwProductVersionMS); + return int32_t(vinfo->dwProductVersionMS); } } } } } - } + return int32_t(kWindowsUnknown); + }(); return winVersion; } diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 9212e55bef1a..e1d97513172d 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -3167,10 +3167,7 @@ LOKWindowsMap& GetLOKWindowsMap() assert(comphelper::LibreOfficeKit::isActive()); // Map to remember the LOKWindowId <-> Window binding. - static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap; - - if (!s_pLOKWindowsMap) - s_pLOKWindowsMap.reset(new LOKWindowsMap); + static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap(new LOKWindowsMap); return *s_pLOKWindowsMap; } diff --git a/vcl/unx/gtk/gtksys.cxx b/vcl/unx/gtk/gtksys.cxx index d99d294301a0..bad2285576d5 100644 --- a/vcl/unx/gtk/gtksys.cxx +++ b/vcl/unx/gtk/gtksys.cxx @@ -25,9 +25,7 @@ GtkSalSystem *GtkSalSystem::GetSingleton() { - static GtkSalSystem *pSingleton = nullptr; - if (!pSingleton) - pSingleton = new GtkSalSystem(); + static GtkSalSystem *pSingleton = new GtkSalSystem(); return pSingleton; } |