From 92e209c62a83f8b48c0ebdc0e6c63d05cd81c737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Thu, 14 Jul 2022 22:02:01 +0300 Subject: [PATCH] Simplify getIsHungAppWindow --- .../crashcatcher/windows_crashmonitor.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/components/crashcatcher/windows_crashmonitor.cpp b/components/crashcatcher/windows_crashmonitor.cpp index c91f57c6f9..d2e5737949 100644 --- a/components/crashcatcher/windows_crashmonitor.cpp +++ b/components/crashcatcher/windows_crashmonitor.cpp @@ -24,21 +24,14 @@ namespace Crash // See: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-ishungappwindow static IsHungAppWindowFn getIsHungAppWindow() noexcept { - static IsHungAppWindowFn isHungAppWindow = nullptr; - static bool isHungAppWindowInitialized = false; - - if (isHungAppWindowInitialized) - return isHungAppWindow; - auto user32Handle = LoadLibraryA("user32.dll"); if (user32Handle == nullptr) return nullptr; - isHungAppWindow = reinterpret_cast(GetProcAddress(user32Handle, "IsHungAppWindow")); - isHungAppWindowInitialized = true; - - return isHungAppWindow; + return reinterpret_cast(GetProcAddress(user32Handle, "IsHungAppWindow")); } + + static const IsHungAppWindowFn sIsHungAppWindow = getIsHungAppWindow(); CrashMonitor::CrashMonitor(HANDLE shmHandle) : mShmHandle(shmHandle) @@ -145,8 +138,8 @@ namespace Crash else return false; } - if (auto isHungAppWindow = getIsHungAppWindow(); isHungAppWindow != nullptr) - return isHungAppWindow(mAppWindowHandle); + if (sIsHungAppWindow != nullptr) + return sIsHungAppWindow(mAppWindowHandle); else { BOOL debuggerPresent;