mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
sys_lwmutex/mutex: Fix race on lock timeout
This commit is contained in:
parent
f57c8c1c35
commit
b844aecb9e
5 changed files with 95 additions and 29 deletions
|
|
@ -245,12 +245,38 @@ error_code sys_mutex_lock(ppu_thread& ppu, u32 mutex_id, u64 timeout)
|
|||
|
||||
std::lock_guard lock(mutex->mutex);
|
||||
|
||||
if (!mutex->unqueue(mutex->control.raw().sq, &ppu))
|
||||
bool success = false;
|
||||
|
||||
mutex->control.fetch_op([&](lv2_mutex::control_data_t& data)
|
||||
{
|
||||
break;
|
||||
success = false;
|
||||
|
||||
ppu_thread* sq = static_cast<ppu_thread*>(data.sq);
|
||||
|
||||
const bool retval = &ppu == sq;
|
||||
|
||||
if (!mutex->unqueue<false>(sq, &ppu))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
success = true;
|
||||
|
||||
if (!retval)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
data.sq = sq;
|
||||
return true;
|
||||
});
|
||||
|
||||
if (success)
|
||||
{
|
||||
ppu.next_cpu = nullptr;
|
||||
ppu.gpr[3] = CELL_ETIMEDOUT;
|
||||
}
|
||||
|
||||
ppu.gpr[3] = CELL_ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue