ThreadManager: Check for exchange failure.

Even if expected stays null, since it's weak assume it can fail.
This commit is contained in:
Unknown W. Brackets 2021-12-07 18:24:01 -08:00
parent 5907897c36
commit 7c7340e338

View File

@ -264,11 +264,11 @@ void ThreadManager::EnqueueTaskOnThread(int threadNum, Task *task) {
// Try first atomically, as highest priority.
Task *expected = nullptr;
thread->private_single.compare_exchange_weak(expected, task);
bool queued = thread->private_single.compare_exchange_weak(expected, task);
// Whether we got that or will have to wait, increase the queue counter.
thread->queue_size++;
if (expected == nullptr) {
if (queued) {
std::unique_lock<std::mutex> lock(thread->mutex);
thread->cond.notify_one();
} else {