Try to resolve another race condition. Improve an assert.

This commit is contained in:
Henrik Rydgård 2024-02-03 10:50:23 +01:00
parent 16d1d5566b
commit 3802d4ee16
3 changed files with 11 additions and 4 deletions

View File

@ -459,6 +459,7 @@ VulkanRenderManager::~VulkanRenderManager() {
void VulkanRenderManager::CompileThreadFunc() {
SetCurrentThreadName("ShaderCompile");
while (true) {
bool exitAfterCompile = false;
std::vector<CompileQueueEntry> toCompile;
{
std::unique_lock<std::mutex> lock(compileMutex_);
@ -467,6 +468,9 @@ void VulkanRenderManager::CompileThreadFunc() {
}
toCompile = std::move(compileQueue_);
compileQueue_.clear();
if (!runCompileThread_) {
exitAfterCompile = true;
}
}
int countToCompile = (int)toCompile.size();
@ -509,7 +513,7 @@ void VulkanRenderManager::CompileThreadFunc() {
g_threadManager.EnqueueTask(task);
}
if (!runCompileThread_) {
if (exitAfterCompile) {
break;
}

View File

@ -569,7 +569,8 @@ private:
int curHeight_ = -1;
bool insideFrame_ = false;
bool runCompileThread_ = false;
// probably doesn't need to be atomic.
std::atomic<bool> runCompileThread_;
bool useRenderThread_ = true;
bool measurePresentTime_ = false;

View File

@ -88,7 +88,8 @@ public:
// Returns T if the data is ready, nullptr if it's not.
// Obviously, can only be used if T is nullable, otherwise it won't compile.
T Poll() {
_assert_(sentinel_ == 0xffc0ffee);
uint32_t sentinel = sentinel_;
_assert_msg_(sentinel == 0xffc0ffee, "%08x", sentinel);
std::lock_guard<std::mutex> guard(readyMutex_);
if (ready_) {
return data_;
@ -105,7 +106,8 @@ public:
}
T BlockUntilReady() {
_assert_(sentinel_ == 0xffc0ffee);
uint32_t sentinel = sentinel_;
_assert_msg_(sentinel == 0xffc0ffee, "%08x", sentinel);
std::lock_guard<std::mutex> guard(readyMutex_);
if (ready_) {
return data_;