Put lv2_obj::awake calls under mutex

This commit is contained in:
Nekotekina 2019-08-28 01:22:31 +03:00
parent 04c808b8ab
commit b3f5d6d85b
3 changed files with 35 additions and 58 deletions

View File

@ -77,7 +77,7 @@ error_code sys_cond_signal(ppu_thread& ppu, u32 cond_id)
sys_cond.trace("sys_cond_signal(cond_id=0x%x)", cond_id);
const auto cond = idm::check<lv2_obj, lv2_cond>(cond_id, [](lv2_cond& cond) -> cpu_thread*
const auto cond = idm::check<lv2_obj, lv2_cond>(cond_id, [](lv2_cond& cond)
{
if (cond.waiters)
{
@ -85,11 +85,9 @@ error_code sys_cond_signal(ppu_thread& ppu, u32 cond_id)
if (const auto cpu = cond.schedule<ppu_thread>(cond.sq, cond.mutex->protocol))
{
return cpu;
cond.awake(cpu);
}
}
return nullptr;
});
if (!cond)
@ -97,11 +95,6 @@ error_code sys_cond_signal(ppu_thread& ppu, u32 cond_id)
return CELL_ESRCH;
}
if (cond.ret)
{
cond->awake(cond.ret);
}
return CELL_OK;
}
@ -124,9 +117,12 @@ error_code sys_cond_signal_all(ppu_thread& ppu, u32 cond_id)
lv2_obj::append(cpu);
count++;
}
}
return count;
if (count)
{
lv2_obj::awake_all();
}
}
});
if (!cond)
@ -134,11 +130,6 @@ error_code sys_cond_signal_all(ppu_thread& ppu, u32 cond_id)
return CELL_ESRCH;
}
if (cond.ret)
{
lv2_obj::awake_all();
}
return CELL_OK;
}
@ -148,11 +139,11 @@ error_code sys_cond_signal_to(ppu_thread& ppu, u32 cond_id, u32 thread_id)
sys_cond.trace("sys_cond_signal_to(cond_id=0x%x, thread_id=0x%x)", cond_id, thread_id);
const auto cond = idm::check<lv2_obj, lv2_cond>(cond_id, [&](lv2_cond& cond) -> cpu_thread*
const auto cond = idm::check<lv2_obj, lv2_cond>(cond_id, [&](lv2_cond& cond) -> int
{
if (!idm::check_unlocked<named_thread<ppu_thread>>(thread_id))
{
return (cpu_thread*)(1);
return -1;
}
if (cond.waiters)
@ -164,24 +155,21 @@ error_code sys_cond_signal_to(ppu_thread& ppu, u32 cond_id, u32 thread_id)
if (cpu->id == thread_id)
{
verify(HERE), cond.unqueue(cond.sq, cpu);
return cpu;
cond.awake(cpu);
return 1;
}
}
}
return nullptr;
return 0;
});
if (!cond || cond.ret == (cpu_thread*)(1))
if (!cond || cond.ret == -1)
{
return CELL_ESRCH;
}
if (cond.ret)
{
cond->awake(cond.ret);
}
else if (!cond.ret)
if (!cond.ret)
{
return not_an_error(CELL_EPERM);
}

View File

@ -86,11 +86,11 @@ error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u3
fmt::throw_exception("Unknown mode (%d)" HERE, mode);
}
const auto cond = idm::check<lv2_obj, lv2_lwcond>(lwcond_id, [&](lv2_lwcond& cond) -> cpu_thread*
const auto cond = idm::check<lv2_obj, lv2_lwcond>(lwcond_id, [&](lv2_lwcond& cond) -> int
{
if (ppu_thread_id != -1 && !idm::check_unlocked<named_thread<ppu_thread>>(ppu_thread_id))
{
return (cpu_thread*)(1);
return -1;
}
lv2_lwmutex* mutex;
@ -101,7 +101,7 @@ error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u3
if (!mutex)
{
return (cpu_thread*)(1);
return -1;
}
}
@ -143,15 +143,19 @@ error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u3
std::lock_guard lock(mutex->mutex);
mutex->sq.emplace_back(result);
}
else
{
cond.awake(result);
}
return result;
return 1;
}
}
return nullptr;
return 0;
});
if (!cond || cond.ret == (cpu_thread*)(1))
if (!cond || cond.ret == -1)
{
return CELL_ESRCH;
}
@ -173,11 +177,6 @@ error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u3
return not_an_error(CELL_EPERM);
}
if (mode != 1)
{
cond->awake(cond.ret);
}
return CELL_OK;
}
@ -241,6 +240,11 @@ error_code _sys_lwcond_signal_all(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
result++;
}
if (need_awake)
{
lv2_obj::awake_all();
}
return result;
}
@ -252,11 +256,6 @@ error_code _sys_lwcond_signal_all(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id
return CELL_ESRCH;
}
if (need_awake)
{
lv2_obj::awake_all();
}
if (mode == 1)
{
// Mode 1: return the amount of threads (TODO)

View File

@ -192,17 +192,17 @@ error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id)
sys_lwmutex.trace("_sys_lwmutex_unlock(lwmutex_id=0x%x)", lwmutex_id);
const auto mutex = idm::check<lv2_obj, lv2_lwmutex>(lwmutex_id, [&](lv2_lwmutex& mutex) -> cpu_thread*
const auto mutex = idm::check<lv2_obj, lv2_lwmutex>(lwmutex_id, [&](lv2_lwmutex& mutex)
{
std::lock_guard lock(mutex.mutex);
if (const auto cpu = mutex.schedule<ppu_thread>(mutex.sq, mutex.protocol))
{
return cpu;
mutex.awake(cpu);
return;
}
mutex.signaled |= 1;
return nullptr;
});
if (!mutex)
@ -210,11 +210,6 @@ error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id)
return CELL_ESRCH;
}
if (mutex.ret)
{
mutex->awake(mutex.ret);
}
return CELL_OK;
}
@ -224,18 +219,18 @@ error_code _sys_lwmutex_unlock2(ppu_thread& ppu, u32 lwmutex_id)
sys_lwmutex.warning("_sys_lwmutex_unlock2(lwmutex_id=0x%x)", lwmutex_id);
const auto mutex = idm::check<lv2_obj, lv2_lwmutex>(lwmutex_id, [&](lv2_lwmutex& mutex) -> cpu_thread*
const auto mutex = idm::check<lv2_obj, lv2_lwmutex>(lwmutex_id, [&](lv2_lwmutex& mutex)
{
std::lock_guard lock(mutex.mutex);
if (const auto cpu = mutex.schedule<ppu_thread>(mutex.sq, mutex.protocol))
{
static_cast<ppu_thread*>(cpu)->gpr[3] = CELL_EBUSY;
return cpu;
mutex.awake(cpu);
return;
}
mutex.signaled |= 1 << 31;
return nullptr;
});
if (!mutex)
@ -243,10 +238,5 @@ error_code _sys_lwmutex_unlock2(ppu_thread& ppu, u32 lwmutex_id)
return CELL_ESRCH;
}
if (mutex.ret)
{
mutex->awake(mutex.ret);
}
return CELL_OK;
}