Skip to content

Commit 2e5b105

Browse files
committed
SL-18721 Shutdown fixes #4
1 parent 71d0e6f commit 2e5b105

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

indra/llcommon/threadpool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ namespace LL
8787

8888
protected:
8989
std::unique_ptr<WorkQueueBase> mQueue;
90+
std::vector<std::pair<std::string, std::thread>> mThreads;
9091
bool mAutomaticShutdown;
9192

9293
private:
9394
void run(const std::string& name);
9495

9596
std::string mName;
9697
size_t mThreadCount;
97-
std::vector<std::pair<std::string, std::thread>> mThreads;
9898
};
9999

100100
/**

indra/llwindow/llwindowwin32.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ struct LLWindowWin32::LLWindowWin32Thread : public LL::ThreadPool
352352

353353
void run() override;
354354

355+
// closes queue, wakes thread, waits until thread closes
356+
void wakeAndClose();
357+
355358
void glReady()
356359
{
357360
mGLReady = true;
@@ -1022,12 +1025,8 @@ void LLWindowWin32::close()
10221025

10231026
mhDC = NULL;
10241027
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();
10291028

1030-
mWindowThread->close();
1029+
mWindowThread->wakeAndClose();
10311030
}
10321031

10331032
BOOL LLWindowWin32::isValid()
@@ -4940,6 +4939,39 @@ void LLWindowWin32::LLWindowWin32Thread::run()
49404939

49414940
}
49424941

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+
49434975
void LLWindowWin32::post(const std::function<void()>& func)
49444976
{
49454977
mFunctionQueue.pushFront(func);

0 commit comments

Comments
 (0)