Fix race condition.

This commit is contained in:
Relintai 2022-09-17 22:35:42 +02:00
parent 48d26e9400
commit 099b05380e

View File

@ -113,16 +113,17 @@ bool ThreadPool::is_working_no_lock() const {
} }
bool ThreadPool::has_job(const Ref<ThreadPoolJob> &job) { bool ThreadPool::has_job(const Ref<ThreadPoolJob> &job) {
_THREAD_SAFE_LOCK_
for (int i = 0; i < _threads.size(); ++i) { for (int i = 0; i < _threads.size(); ++i) {
ThreadPoolContext *context = _threads.get(i); ThreadPoolContext *context = _threads.get(i);
if (context->job == job) { if (context->job == job) {
_THREAD_SAFE_UNLOCK_
return true; return true;
} }
} }
_THREAD_SAFE_LOCK_
List<Ref<ThreadPoolJob>>::Element *E = _queue.find(job); List<Ref<ThreadPoolJob>>::Element *E = _queue.find(job);
_THREAD_SAFE_UNLOCK_ _THREAD_SAFE_UNLOCK_