Skip to content

Commit

Permalink
[Win] WTF::RunLoop: RegisterClass has to be called in the main thread…
Browse files Browse the repository at this point in the history
… before creating other threads

https://bugs.webkit.org/show_bug.cgi?id=255624

Reviewed by Don Olmstead.

CreateWindow was randomly failing in the GPU process for WebGL tests
for Windows port. This seems to be a theading issue of calling
CreateWindow in a different thread rather than one called
RegisterClass. RegisterClass has to be called in the main thread
before creating other threads. Reverted 228617@main.

* Source/WTF/wtf/win/MainThreadWin.cpp:
(WTF::initializeMainThreadPlatform):
* Source/WTF/wtf/win/RunLoopWin.cpp:
(WTF::RunLoop::registerRunLoopMessageWindowClass):
(WTF::RunLoop::RunLoop):

Canonical link: https://commits.webkit.org/263194@main
  • Loading branch information
fujii committed Apr 20, 2023
1 parent d01d573 commit a44713b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions Source/WTF/wtf/win/MainThreadWin.cpp
Expand Up @@ -43,6 +43,7 @@ void initializeMainThreadPlatform()
{
s_mainThread = Thread::currentID();
Thread::initializeCurrentThreadInternal("Main Thread");
RunLoop::registerRunLoopMessageWindowClass();
}

bool isMainThread()
Expand Down
16 changes: 6 additions & 10 deletions Source/WTF/wtf/win/RunLoopWin.cpp
Expand Up @@ -90,20 +90,16 @@ void RunLoop::stop()

void RunLoop::registerRunLoopMessageWindowClass()
{
static std::once_flag onceKey;
std::call_once(onceKey, [&] {
WNDCLASS windowClass = { };
windowClass.lpfnWndProc = RunLoop::RunLoopWndProc;
windowClass.cbWndExtra = sizeof(RunLoop*);
windowClass.lpszClassName = kRunLoopMessageWindowClassName;
bool result = ::RegisterClass(&windowClass);
RELEASE_ASSERT(result);
});
WNDCLASS windowClass = { };
windowClass.lpfnWndProc = RunLoop::RunLoopWndProc;
windowClass.cbWndExtra = sizeof(RunLoop*);
windowClass.lpszClassName = kRunLoopMessageWindowClassName;
bool result = ::RegisterClass(&windowClass);
RELEASE_ASSERT(result);
}

RunLoop::RunLoop()
{
registerRunLoopMessageWindowClass();
m_runLoopMessageWindow = ::CreateWindow(kRunLoopMessageWindowClassName, nullptr, 0,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, nullptr, nullptr, this);
RELEASE_ASSERT(::IsWindow(m_runLoopMessageWindow));
Expand Down

0 comments on commit a44713b

Please sign in to comment.