Skip to content

Commit

Permalink
Lock scope optimization for sys_mutex_unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Feb 2, 2019
1 parent 195693f commit 5d0f1c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_cond.cpp
Expand Up @@ -221,11 +221,11 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout)
}
else
{
cond->sleep(ppu, timeout);
std::lock_guard lock(cond->mutex->mutex);

// Register waiter
cond->sq.emplace_back(&ppu);
cond->sleep(ppu, timeout);

// Unlock the mutex
cond->mutex->lock_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwcond.cpp
Expand Up @@ -265,12 +265,12 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
return nullptr;
}

cond.sleep(ppu, timeout);
std::lock_guard lock(cond.mutex);

// Add a waiter
cond.waiters++;
cond.sq.emplace_back(&ppu);
cond.sleep(ppu, timeout);

std::lock_guard lock2(mutex->mutex);

Expand Down
8 changes: 6 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_mutex.cpp
Expand Up @@ -231,9 +231,13 @@ error_code sys_mutex_unlock(ppu_thread& ppu, u32 mutex_id)

if (mutex.ret == CELL_EBUSY)
{
std::lock_guard lock(mutex->mutex);
cpu_thread* cpu;
{
std::lock_guard lock(mutex->mutex);
cpu = mutex->reown<ppu_thread>();
}

if (auto cpu = mutex->reown<ppu_thread>())
if (cpu)
{
mutex->awake(*cpu);
}
Expand Down

0 comments on commit 5d0f1c0

Please sign in to comment.