Skip to content

Commit

Permalink
fix: kill management thread on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Aug 26, 2024
1 parent 0b35483 commit 48e1897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,12 @@ namespace SIE
{
Clear();
StopFileWatcher();
if (!compilationPool.wait_for_tasks_duration(std::chrono::milliseconds(1000))) {
logger::info("Tasks still running despite request to stop; killing thread {}!", GetThreadId(managementThread));
WaitForSingleObject(managementThread, 1000);
TerminateThread(managementThread, 0);
CloseHandle(managementThread);
}
}

void ShaderCache::Clear()
Expand Down Expand Up @@ -2332,7 +2338,8 @@ namespace SIE

void ShaderCache::ManageCompilationSet(std::stop_token stoken)
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
managementThread = GetCurrentThread();
SetThreadPriority(managementThread, THREAD_PRIORITY_BELOW_NORMAL);
while (!stoken.stop_requested()) {
const auto& task = compilationSet.WaitTake(stoken);
if (!task.has_value())
Expand Down
1 change: 1 addition & 0 deletions src/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ namespace SIE
uint blockedKeyIndex = (uint)-1; // index in shaderMap; negative value indicates disabled
std::string blockedKey = "";
std::vector<uint32_t> blockedIDs; // more than one descriptor could be blocked based on shader hash
HANDLE managementThread = nullptr;

private:
ShaderCache();
Expand Down

0 comments on commit 48e1897

Please sign in to comment.