@@ -352,6 +352,9 @@ struct LLWindowWin32::LLWindowWin32Thread : public LL::ThreadPool
352
352
353
353
void run () override ;
354
354
355
+ // closes queue, wakes thread, waits until thread closes
356
+ void wakeAndClose ();
357
+
355
358
void glReady ()
356
359
{
357
360
mGLReady = true ;
@@ -1022,12 +1025,8 @@ void LLWindowWin32::close()
1022
1025
1023
1026
mhDC = NULL ;
1024
1027
mWindowHandle = NULL ;
1025
-
1026
- // Window thread might be waiting for a getMessage(), give it
1027
- // a push to enshure it will process destroy_window_handler
1028
- kickWindowThread ();
1029
1028
1030
- mWindowThread ->close ();
1029
+ mWindowThread ->wakeAndClose ();
1031
1030
}
1032
1031
1033
1032
BOOL LLWindowWin32::isValid ()
@@ -4940,6 +4939,39 @@ void LLWindowWin32::LLWindowWin32Thread::run()
4940
4939
4941
4940
}
4942
4941
4942
+ void LLWindowWin32::LLWindowWin32Thread::wakeAndClose ()
4943
+ {
4944
+ if (!mQueue ->isClosed ())
4945
+ {
4946
+ LL_DEBUGS (" Window" ) << " closing pool queue" << LL_ENDL;
4947
+ mQueue ->close ();
4948
+
4949
+ // Post a nonsense user message to wake up the thred in
4950
+ // case it is waiting for a getMessage()
4951
+ //
4952
+ // Note that mWindowHandleThrd can change at any moment and isn't thread safe
4953
+ // but since we aren't writing it, should be safe to use even if value is obsolete
4954
+ // worst case dead handle gets reused and some new window ignores the message
4955
+ HWND old_handle = mWindowHandleThrd ;
4956
+ if (old_handle)
4957
+ {
4958
+ WPARAM wparam{ 0xB0B0 };
4959
+ LL_DEBUGS (" Window" ) << " PostMessage(" << std::hex << old_handle
4960
+ << " , " << WM_DUMMY_
4961
+ << " , " << wparam << " )" << std::dec << LL_ENDL;
4962
+ PostMessage (old_handle, WM_DUMMY_, wparam, 0x1337 );
4963
+ }
4964
+
4965
+ // now wait for our one thread to die.
4966
+ for (auto & pair : mThreads )
4967
+ {
4968
+ LL_DEBUGS (" Window" ) << " waiting on pool's thread " << pair.first << LL_ENDL;
4969
+ pair.second .join ();
4970
+ }
4971
+ LL_DEBUGS (" Window" ) << " thread pool shutdown complete" << LL_ENDL;
4972
+ }
4973
+ }
4974
+
4943
4975
void LLWindowWin32::post (const std::function<void ()>& func)
4944
4976
{
4945
4977
mFunctionQueue .pushFront (func);
0 commit comments