sys_mutex/lwmutex: Regression fixes after #12378
This commit is contained in:
@@ -318,6 +318,9 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout)
|
|||||||
return static_cast<u32>(syscall_state >> 32);
|
return static_cast<u32>(syscall_state >> 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register waiter
|
||||||
|
lv2_obj::emplace(cond.sq, &ppu);
|
||||||
|
|
||||||
// Unlock the mutex
|
// Unlock the mutex
|
||||||
const u32 count = cond.mutex->lock_count.exchange(0);
|
const u32 count = cond.mutex->lock_count.exchange(0);
|
||||||
|
|
||||||
@@ -325,6 +328,7 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout)
|
|||||||
{
|
{
|
||||||
if (cpu->state & cpu_flag::again)
|
if (cpu->state & cpu_flag::again)
|
||||||
{
|
{
|
||||||
|
ensure(cond.unqueue(cond.sq, &ppu));
|
||||||
ppu.state += cpu_flag::again;
|
ppu.state += cpu_flag::again;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -332,9 +336,6 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout)
|
|||||||
cond.mutex->append(cpu);
|
cond.mutex->append(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register waiter
|
|
||||||
lv2_obj::emplace(cond.sq, &ppu);
|
|
||||||
|
|
||||||
// Sleep current thread and schedule mutex waiter
|
// Sleep current thread and schedule mutex waiter
|
||||||
cond.sleep(ppu, timeout);
|
cond.sleep(ppu, timeout);
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,11 @@ struct lv2_lwmutex final : lv2_obj
|
|||||||
lwcond_waiters.notify_all();
|
lwcond_waiters.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signal)
|
||||||
|
{
|
||||||
|
cpu->next_cpu = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return signal;
|
return signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,8 +163,9 @@ struct lv2_lwmutex final : lv2_obj
|
|||||||
res = nullptr;
|
res = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto sq = data.sq)
|
if (auto sq = static_cast<T*>(data.sq))
|
||||||
{
|
{
|
||||||
|
restore_next = sq->next_cpu;
|
||||||
res = schedule<T>(data.sq, protocol);
|
res = schedule<T>(data.sq, protocol);
|
||||||
|
|
||||||
if (sq == data.sq)
|
if (sq == data.sq)
|
||||||
@@ -167,7 +173,6 @@ struct lv2_lwmutex final : lv2_obj
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_next = res->next_cpu;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ struct lv2_mutex final : lv2_obj
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool try_own(T& cpu)
|
bool try_own(T& cpu)
|
||||||
{
|
{
|
||||||
return control.atomic_op([&](control_data_t& data)
|
if (control.atomic_op([&](control_data_t& data)
|
||||||
{
|
{
|
||||||
if (data.owner)
|
if (data.owner)
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,13 @@ struct lv2_mutex final : lv2_obj
|
|||||||
data.owner = cpu.id;
|
data.owner = cpu.id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
}))
|
||||||
|
{
|
||||||
|
cpu.next_cpu = nullptr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -161,8 +167,9 @@ struct lv2_mutex final : lv2_obj
|
|||||||
res = nullptr;
|
res = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto sq = data.sq)
|
if (auto sq = static_cast<T*>(data.sq))
|
||||||
{
|
{
|
||||||
|
restore_next = sq->next_cpu;
|
||||||
res = schedule<T>(data.sq, protocol);
|
res = schedule<T>(data.sq, protocol);
|
||||||
|
|
||||||
if (sq == data.sq)
|
if (sq == data.sq)
|
||||||
@@ -171,7 +178,6 @@ struct lv2_mutex final : lv2_obj
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_next = res->next_cpu;
|
|
||||||
data.owner = res->id;
|
data.owner = res->id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user