From bb8ee18a597fc71ff78bec7226ba6b732643be3d Mon Sep 17 00:00:00 2001 From: ivan100sic Date: Tue, 27 Oct 2020 11:11:23 +0100 Subject: [PATCH] Thread-safe initialization --- .../fancyzones/lib/ZoneWindowDrawing.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp b/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp index 89ce1c24a6..73221ef727 100644 --- a/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp +++ b/src/modules/fancyzones/lib/ZoneWindowDrawing.cpp @@ -33,22 +33,22 @@ float ZoneWindowDrawing::GetAnimationAlpha() ID2D1Factory* ZoneWindowDrawing::GetD2DFactory() { - static ID2D1Factory* pD2DFactory = nullptr; - if (!pD2DFactory) - { - D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &pD2DFactory); - } + static auto pD2DFactory = [] { + ID2D1Factory* res = nullptr; + D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &res); + return res; + }(); return pD2DFactory; } IDWriteFactory* ZoneWindowDrawing::GetWriteFactory() { - static IUnknown* pDWriteFactory = nullptr; - if (!pDWriteFactory) - { - DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &pDWriteFactory); - } - return reinterpret_cast(pDWriteFactory); + static auto pDWriteFactory = [] { + IUnknown* res = nullptr; + DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &res); + return reinterpret_cast(res); + }(); + return pDWriteFactory; } D2D1_COLOR_F ZoneWindowDrawing::ConvertColor(COLORREF color)