Skip to content
Snippets Groups Projects
Commit 0cfee92c authored by Martin Doerr's avatar Martin Doerr
Browse files

8294699: Launcher causes lingering busy cursor

Backport-of: d3df3eb5d7f5537ade917db7a36caba028f94111
parent f4da0e7a
Branches
Tags
No related merge requests found
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -134,6 +134,82 @@ tstring getJvmLibPath(const Jvm& jvm) {
}
class RunExecutorWithMsgLoop {
public:
static DWORD apply(const Executor& exec) {
RunExecutorWithMsgLoop instance(exec);
UniqueHandle threadHandle = UniqueHandle(CreateThread(NULL, 0, worker,
static_cast<LPVOID>(&instance), 0, NULL));
if (threadHandle.get() == NULL) {
JP_THROW(SysError("CreateThread() failed", CreateThread));
}
MSG msg;
BOOL bRet;
while((bRet = GetMessage(&msg, instance.hwnd, 0, 0 )) != 0) {
if (bRet == -1) {
JP_THROW(SysError("GetMessage() failed", GetMessage));
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Wait for worker thread to terminate to guarantee it will not linger
// around after the thread running a message loop terminates.
const DWORD res = ::WaitForSingleObject(threadHandle.get(), INFINITE);
if (WAIT_FAILED == res) {
JP_THROW(SysError("WaitForSingleObject() failed",
WaitForSingleObject));
}
LOG_TRACE(tstrings::any()
<< "Executor worker thread terminated. Exit code="
<< instance.exitCode);
return instance.exitCode;
}
private:
RunExecutorWithMsgLoop(const Executor& v): exec(v) {
exitCode = 1;
// Message-only window.
hwnd = CreateWindowEx(0, _T("STATIC"), _T(""), 0, 0, 0, 0, 0,
HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
if (!hwnd) {
JP_THROW(SysError("CreateWindowEx() failed", CreateWindowEx));
}
}
static DWORD WINAPI worker(LPVOID param) {
static_cast<RunExecutorWithMsgLoop*>(param)->run();
return 0;
}
void run() {
JP_TRY;
exitCode = static_cast<DWORD>(exec.execAndWaitForExit());
JP_CATCH_ALL;
JP_TRY;
if (!PostMessage(hwnd, WM_QUIT, 0, 0)) {
JP_THROW(SysError("PostMessage(WM_QUIT) failed", PostMessage));
}
return;
JP_CATCH_ALL;
// All went wrong, PostMessage() failed. Just terminate with error code.
exit(1);
}
private:
const Executor& exec;
DWORD exitCode;
HWND hwnd;
};
void launchApp() {
// [RT-31061] otherwise UI can be left in back of other windows.
::AllowSetForegroundWindow(ASFW_ANY);
......@@ -180,7 +256,7 @@ void launchApp() {
exec.arg(arg);
});
DWORD exitCode = static_cast<DWORD>(exec.execAndWaitForExit());
DWORD exitCode = RunExecutorWithMsgLoop::apply(exec);
exit(exitCode);
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment