From 0b9c784570fe3660b238b537fa7ba7e5de8783aa Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Mon, 1 Jan 2024 18:55:14 -0500 Subject: refactor ThreadRun for better pointer safety --- src/thread_pool.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/thread_pool.cpp') diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 41aaf7d..050db20 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -29,9 +29,13 @@ void ThreadRun(ThreadPool *tp) { { std::unique_lock lck(tp->mutex); tp->condition.wait(lck, [tp] { - return tp->jobQueue->Count() != 0 || !tp->isRunning || tp->isPaused; + if (!tp->isRunning) return true; + if (tp->isPaused) return true; + if (tp->jobQueue == nullptr) return true; + if (tp->jobQueue == CAFE_BABE(DynArray *>)) return true; + return tp->jobQueue->Count() != 0; }); - if (!tp->isRunning || tp->isPaused) { + if (!tp->isRunning || tp->isPaused || tp->jobQueue == nullptr || tp->jobQueue == CAFE_BABE(DynArray *>)) { return; } if (tp->jobQueue->Count() == 0) { -- cgit v1.2.3