1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Threads.cpp: Fix infinite looping

This commit is contained in:
Eladash 2023-04-26 22:39:26 +03:00 committed by Ivan
parent 5d13978bbf
commit 3d8d9ef61c
2 changed files with 12 additions and 19 deletions

View File

@ -2647,26 +2647,24 @@ void thread_base::exec()
while (shared_ptr<thread_future> head = m_taskq.exchange(null_ptr)) while (shared_ptr<thread_future> head = m_taskq.exchange(null_ptr))
{ {
// TODO: check if adapting reverse algorithm is feasible here // TODO: check if adapting reverse algorithm is feasible here
shared_ptr<thread_future>* prev{}; thread_future* prev_head{head.get()};
for (auto ptr = head.get(); ptr; ptr = ptr->next.get()) for (thread_future* prev{};;)
{ {
utils::prefetch_exec(ptr->exec.load()); utils::prefetch_exec(prev_head->exec.load());
ptr->prev = prev; if (auto next = prev_head->next.get())
if (ptr->next)
{ {
prev = &ptr->next; prev = std::exchange(prev_head, next);
prev_head->prev = prev;
}
else
{
break;
} }
} }
if (!prev) for (auto ptr = prev_head; ptr; ptr = ptr->prev)
{
prev = &head;
}
for (auto ptr = prev->get(); ptr; ptr = ptr->prev->get())
{ {
if (auto task = ptr->exec.load()) [[likely]] if (auto task = ptr->exec.load()) [[likely]]
{ {
@ -2690,11 +2688,6 @@ void thread_base::exec()
// Partial cleanup // Partial cleanup
ptr->next.reset(); ptr->next.reset();
} }
if (!ptr->prev)
{
break;
}
} }
if (!m_taskq) [[likely]] if (!m_taskq) [[likely]]

View File

@ -95,7 +95,7 @@ class thread_future
shared_ptr<thread_future> next{}; shared_ptr<thread_future> next{};
shared_ptr<thread_future>* prev{}; thread_future* prev{};
protected: protected:
atomic_t<void(*)(thread_base*, thread_future*)> exec{}; atomic_t<void(*)(thread_base*, thread_future*)> exec{};