mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-17 08:11:51 +00:00
Syscalls: minor fixes
This commit is contained in:
parent
e9653f1029
commit
0fb092f2a5
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Emu/SysCalls/Modules/cellSpurs.h"
|
||||
|
||||
class SPURSManagerEventFlag
|
||||
{
|
||||
public:
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "Emu/SysCalls/ErrorCodes.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_spu.h"
|
||||
#include "Emu/SysCalls/lv2/sys_event_flag.h"
|
||||
#include "Emu/SysCalls/lv2/sys_time.h"
|
||||
|
@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
#include "Utilities/SMutex.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "PPCThread.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_event.h"
|
||||
#include "Emu/Event.h"
|
||||
#include "MFC.h"
|
||||
|
||||
enum SPUchannels
|
||||
enum SPUchannels
|
||||
{
|
||||
SPU_RdEventStat = 0, //Read event status with mask applied
|
||||
SPU_WrEventMask = 1, //Write event mask
|
||||
@ -22,7 +25,7 @@ enum SPUchannels
|
||||
SPU_WrOutIntrMbox = 30, //Write outbound interrupt mailbox contents (interrupting PPU)
|
||||
};
|
||||
|
||||
enum MFCchannels
|
||||
enum MFCchannels
|
||||
{
|
||||
MFC_WrMSSyncReq = 9, //Write multisource synchronization request
|
||||
MFC_RdTagMask = 12, //Read tag mask
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "Emu/Memory/Memory.h"
|
||||
//#include "Emu/System.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_event.h"
|
||||
#include "Event.h"
|
||||
|
||||
void EventManager::Init()
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include "Emu/SysCalls/lv2/sys_event.h"
|
||||
#include <unordered_map>
|
||||
|
||||
struct EventQueue;
|
||||
|
||||
class EventManager
|
||||
{
|
||||
std::mutex m_lock;
|
||||
|
@ -2,11 +2,15 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/Modules.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "rpcs3/Ini.h"
|
||||
#include "Utilities/SQueue.h"
|
||||
#include "Emu/Event.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_time.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_event.h"
|
||||
#include "Emu/Event.h"
|
||||
#include "Emu/Audio/AudioManager.h"
|
||||
#include "Emu/Audio/AudioDumper.h"
|
||||
#include "Emu/Audio/cellAudio.h"
|
||||
|
@ -3,8 +3,12 @@
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/Modules.h"
|
||||
#include "Emu/SysCalls/CB_FUNC.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "Emu/Cell/SPUThread.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwcond.h"
|
||||
#include "Emu/SysCalls/lv2/sys_spu.h"
|
||||
#include "Emu/SysCalls/lv2/sys_ppu_thread.h"
|
||||
#include "Emu/SysCalls/lv2/sys_memory.h"
|
||||
#include "Emu/SysCalls/lv2/sys_process.h"
|
||||
|
@ -1,7 +1,4 @@
|
||||
#pragma once
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwcond.h"
|
||||
#include "Emu/SysCalls/lv2/sys_spu.h"
|
||||
|
||||
// Core return codes.
|
||||
enum
|
||||
|
@ -2,7 +2,12 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/Modules.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_lwcond.h"
|
||||
#include "Emu/SysCalls/lv2/sys_spu.h"
|
||||
#include "cellSpurs.h"
|
||||
#include "cellSpursJq.h"
|
||||
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/Modules.h"
|
||||
#include "Emu/SysCalls/CB_FUNC.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
|
||||
#include "Emu/SysCalls/lv2/sys_event.h"
|
||||
#include "Emu/SysCalls/lv2/sys_process.h"
|
||||
#include "Emu/Event.h"
|
||||
#include "cellSync.h"
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/Modules.h"
|
||||
#include "Emu/SysCalls/CB_FUNC.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/FS/vfsFile.h"
|
||||
#include "Emu/SysCalls/lv2/sys_spu.h"
|
||||
|
@ -5,8 +5,12 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "ModuleManager.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "lv2/lv2Fs.h"
|
||||
#include "lv2/sys_lwmutex.h"
|
||||
#include "lv2/sys_mutex.h"
|
||||
#include "lv2/sys_cond.h"
|
||||
#include "lv2/sys_event.h"
|
||||
#include "lv2/sys_event_flag.h"
|
||||
|
@ -2,9 +2,13 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
#include "sys_mutex.h"
|
||||
#include "sys_cond.h"
|
||||
|
||||
SysCallBase sys_cond("sys_cond");
|
||||
@ -28,11 +32,6 @@ s32 sys_cond_create(vm::ptr<u32> cond_id, u32 mutex_id, vm::ptr<sys_cond_attribu
|
||||
return CELL_ESRCH;
|
||||
}
|
||||
|
||||
if (mutex->is_recursive)
|
||||
{
|
||||
sys_cond.Warning("*** condition on recursive mutex(%d)", mutex_id);
|
||||
}
|
||||
|
||||
Cond* cond = new Cond(mutex, attr->name_u64);
|
||||
u32 id = sys_cond.GetNewId(cond, TYPE_COND);
|
||||
*cond_id = id;
|
||||
@ -175,10 +174,7 @@ s32 sys_cond_wait(u32 cond_id, u64 timeout)
|
||||
|
||||
cond->m_queue.push(tid);
|
||||
|
||||
if (mutex->recursive != 1)
|
||||
{
|
||||
sys_cond.Warning("sys_cond_wait(cond_id=%d): associated mutex had wrong recursive value (%d)", cond_id, mutex->recursive);
|
||||
}
|
||||
auto old_recursive = mutex->recursive;
|
||||
mutex->recursive = 0;
|
||||
mutex->m_mutex.unlock(tid, mutex->protocol == SYS_SYNC_PRIORITY ? mutex->m_queue.pop_prio() : mutex->m_queue.pop());
|
||||
|
||||
@ -207,7 +203,7 @@ s32 sys_cond_wait(u32 cond_id, u64 timeout)
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
mutex->recursive = 1;
|
||||
mutex->recursive = old_recursive;
|
||||
cond->signal.unlock(tid);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "sys_mutex.h"
|
||||
|
||||
struct sys_cond_attribute
|
||||
{
|
||||
|
@ -2,9 +2,12 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "Emu/Event.h"
|
||||
#include "sys_lwmutex.h"
|
||||
#include "sys_process.h"
|
||||
#include "sys_event.h"
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "sys_lwmutex.h"
|
||||
//#include "sys_lwmutex.h"
|
||||
//#include "Utilities/SMutex.h"
|
||||
|
||||
#define FIX_SPUQ(x) ((u64)x | 0x5350555100000000ULL)
|
||||
// arbitrary code to prevent "special" zero value in key argument
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
enum
|
||||
{
|
||||
SYS_SYNC_WAITER_SINGLE = 0x10000,
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
@ -161,9 +163,15 @@ s32 sys_lwcond_wait(vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
|
||||
be_t<u32> tid = be_t<u32>::make(tid_le);
|
||||
|
||||
SleepQueue* sq = nullptr;
|
||||
Emu.GetIdManager().GetIDData((u32)mutex->sleep_queue, sq);
|
||||
if (!Emu.GetIdManager().GetIDData((u32)mutex->sleep_queue, sq) && mutex->attribute.ToBE() != se32(SYS_SYNC_RETRY))
|
||||
{
|
||||
sys_lwcond.Warning("sys_lwcond_wait(id=%d): associated mutex had invalid sleep queue (%d)",
|
||||
(u32)lwcond->lwcond_queue, (u32)mutex->sleep_queue);
|
||||
return CELL_ESRCH;
|
||||
}
|
||||
|
||||
if (mutex->mutex.GetOwner() != tid)
|
||||
auto old_owner = mutex->mutex.read_sync();
|
||||
if (old_owner != tid)
|
||||
{
|
||||
sys_lwcond.Warning("sys_lwcond_wait(id=%d) failed (EPERM)", (u32)lwcond->lwcond_queue);
|
||||
return CELL_EPERM; // caller must own this lwmutex
|
||||
@ -171,25 +179,13 @@ s32 sys_lwcond_wait(vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
|
||||
|
||||
lw->m_queue.push(tid_le);
|
||||
|
||||
if (mutex->recursive_count.ToBE() != se32(1))
|
||||
{
|
||||
sys_lwcond.Warning("sys_lwcond_wait(id=%d): associated mutex had wrong recursive value (%d)",
|
||||
(u32)lwcond->lwcond_queue, (u32)mutex->recursive_count);
|
||||
}
|
||||
auto old_recursive = mutex->recursive_count;
|
||||
mutex->recursive_count = 0;
|
||||
|
||||
if (sq)
|
||||
be_t<u32> target = sq ? (be_t<u32>::make(mutex->attribute.ToBE() == se32(SYS_SYNC_PRIORITY) ? sq->pop_prio() : sq->pop())) : be_t<u32>::make(0);
|
||||
if (!mutex->mutex.compare_and_swap_test(tid, target))
|
||||
{
|
||||
mutex->mutex.unlock(tid, be_t<u32>::make(mutex->attribute.ToBE() == se32(SYS_SYNC_PRIORITY) ? sq->pop_prio() : sq->pop()));
|
||||
}
|
||||
else if (mutex->attribute.ToBE() == se32(SYS_SYNC_RETRY))
|
||||
{
|
||||
mutex->mutex.unlock(tid); // SYS_SYNC_RETRY
|
||||
}
|
||||
else
|
||||
{
|
||||
sys_lwcond.Warning("sys_lwcond_wait(id=%d): associated mutex had invalid sleep queue (%d)",
|
||||
(u32)lwcond->lwcond_queue, (u32)mutex->sleep_queue);
|
||||
assert(!"sys_lwcond_wait(): mutex unlocking failed");
|
||||
}
|
||||
|
||||
u64 counter = 0;
|
||||
@ -209,7 +205,7 @@ s32 sys_lwcond_wait(vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
|
||||
case static_cast<int>(CELL_EINVAL): goto abort;
|
||||
}
|
||||
|
||||
mutex->recursive_count = 1;
|
||||
mutex->recursive_count = old_recursive;
|
||||
lw->signal.unlock(tid);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_time.h"
|
||||
#include "sys_lwmutex.h"
|
||||
|
||||
SysCallBase sys_lwmutex("sys_lwmutex");
|
||||
@ -15,8 +17,8 @@ s32 lwmutex_create(sys_lwmutex_t& lwmutex, u32 protocol, u32 recursive, u64 name
|
||||
{
|
||||
LV2_LOCK(0);
|
||||
|
||||
lwmutex.waiter = ~0;
|
||||
lwmutex.mutex.initialize();
|
||||
lwmutex.mutex.write_relaxed(be_t<u32>::make(0));
|
||||
lwmutex.waiter.write_relaxed(be_t<u32>::make(~0));
|
||||
lwmutex.attribute = protocol | recursive;
|
||||
lwmutex.recursive_count = 0;
|
||||
u32 sq_id = sys_lwmutex.GetNewId(new SleepQueue(name_u64), TYPE_LWMUTEX);
|
||||
@ -63,7 +65,7 @@ s32 sys_lwmutex_destroy(vm::ptr<sys_lwmutex_t> lwmutex)
|
||||
if (!Emu.GetIdManager().CheckID(sq_id)) return CELL_ESRCH;
|
||||
|
||||
// try to make it unable to lock
|
||||
switch (int res = lwmutex->trylock(lwmutex->mutex.GetDeadValue()))
|
||||
switch (int res = lwmutex->trylock(be_t<u32>::make(~0)))
|
||||
{
|
||||
case CELL_OK:
|
||||
lwmutex->all_info() = 0;
|
||||
@ -79,10 +81,7 @@ s32 sys_lwmutex_lock(vm::ptr<sys_lwmutex_t> lwmutex, u64 timeout)
|
||||
{
|
||||
sys_lwmutex.Log("sys_lwmutex_lock(lwmutex_addr=0x%x, timeout=%lld)", lwmutex.addr(), timeout);
|
||||
|
||||
//ConLog.Write("*** lock mutex (addr=0x%x, attr=0x%x, Nrec=%d, owner=%d, waiter=%d)",
|
||||
//lwmutex.addr(), (u32)lwmutex->attribute, (u32)lwmutex->recursive_count, lwmutex->vars.parts.owner.GetOwner(), (u32)lwmutex->waiter);
|
||||
|
||||
return lwmutex->lock(be_t<u32>::make(GetCurrentPPUThread().GetId()), timeout ? ((timeout < 1000) ? 1 : (timeout / 1000)) : 0);
|
||||
return lwmutex->lock(be_t<u32>::make(GetCurrentPPUThread().GetId()), timeout);
|
||||
}
|
||||
|
||||
s32 sys_lwmutex_trylock(vm::ptr<sys_lwmutex_t> lwmutex)
|
||||
@ -96,9 +95,6 @@ s32 sys_lwmutex_unlock(vm::ptr<sys_lwmutex_t> lwmutex)
|
||||
{
|
||||
sys_lwmutex.Log("sys_lwmutex_unlock(lwmutex_addr=0x%x)", lwmutex.addr());
|
||||
|
||||
//ConLog.Write("*** unlocking mutex (addr=0x%x, attr=0x%x, Nrec=%d, owner=%d, waiter=%d)",
|
||||
//lwmutex.addr(), (u32)lwmutex->attribute, (u32)lwmutex->recursive_count, (u32)lwmutex->vars.parts.owner.GetOwner(), (u32)lwmutex->waiter);
|
||||
|
||||
return lwmutex->unlock(be_t<u32>::make(GetCurrentPPUThread().GetId()));
|
||||
}
|
||||
|
||||
@ -219,43 +215,11 @@ bool SleepQueue::finalize()
|
||||
return true;
|
||||
}
|
||||
|
||||
int sys_lwmutex_t::trylock(be_t<u32> tid)
|
||||
s32 sys_lwmutex_t::trylock(be_t<u32> tid)
|
||||
{
|
||||
if (attribute.ToBE() == se32(0xDEADBEEF)) return CELL_EINVAL;
|
||||
|
||||
be_t<u32> owner_tid = mutex.GetFreeValue();
|
||||
|
||||
if (mutex.unlock(owner_tid, owner_tid) != SMR_OK) // check free value
|
||||
{
|
||||
owner_tid = mutex.GetOwner();
|
||||
/*if (CPUThread* tt = Emu.GetCPU().GetThread(owner_tid))
|
||||
{
|
||||
if (!tt->IsAlive())
|
||||
{
|
||||
sc_lwmutex.Error("sys_lwmutex_t::(try)lock(%d): deadlock on invalid thread(%d)", (u32)sleep_queue, (u32)owner_tid);
|
||||
mutex.unlock(owner_tid, tid);
|
||||
recursive_count = 1;
|
||||
return CELL_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sc_lwmutex.Error("sys_lwmutex_t::(try)lock(%d): deadlock on invalid thread(%d)", (u32)sleep_queue, (u32)owner_tid);
|
||||
mutex.unlock(owner_tid, tid);
|
||||
recursive_count = 1;
|
||||
return CELL_OK;
|
||||
}*/
|
||||
}
|
||||
|
||||
/*while ((attribute.ToBE() & se32(SYS_SYNC_ATTR_RECURSIVE_MASK)) == 0)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
{
|
||||
LOG_WARNING(HLE, "(hack) sys_lwmutex_t::(try)lock aborted (waiting for recursive attribute, attr=0x%x)", (u32)attribute);
|
||||
return CELL_ESRCH;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}*/
|
||||
be_t<u32> owner_tid = mutex.read_sync();
|
||||
|
||||
if (tid == owner_tid)
|
||||
{
|
||||
@ -271,17 +235,18 @@ int sys_lwmutex_t::trylock(be_t<u32> tid)
|
||||
}
|
||||
}
|
||||
|
||||
switch (mutex.trylock(tid))
|
||||
if (!mutex.compare_and_swap_test(be_t<u32>::make(0), tid))
|
||||
{
|
||||
case SMR_OK: recursive_count = 1; return CELL_OK;
|
||||
case SMR_FAILED: return CELL_EBUSY;
|
||||
default: return CELL_EINVAL;
|
||||
return CELL_EBUSY;
|
||||
}
|
||||
|
||||
recursive_count = 1;
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
int sys_lwmutex_t::unlock(be_t<u32> tid)
|
||||
s32 sys_lwmutex_t::unlock(be_t<u32> tid)
|
||||
{
|
||||
if (mutex.unlock(tid, tid) != SMR_OK)
|
||||
if (mutex.read_sync() != tid)
|
||||
{
|
||||
return CELL_EPERM;
|
||||
}
|
||||
@ -292,6 +257,7 @@ int sys_lwmutex_t::unlock(be_t<u32> tid)
|
||||
sys_lwmutex.Error("sys_lwmutex_t::unlock(%d): wrong recursive value fixed (%d)", (u32)sleep_queue, (u32)recursive_count);
|
||||
recursive_count = 1;
|
||||
}
|
||||
|
||||
recursive_count -= 1;
|
||||
if (!recursive_count.ToBE())
|
||||
{
|
||||
@ -300,48 +266,79 @@ int sys_lwmutex_t::unlock(be_t<u32> tid)
|
||||
{
|
||||
case se32(SYS_SYNC_FIFO):
|
||||
case se32(SYS_SYNC_PRIORITY):
|
||||
{
|
||||
SleepQueue* sq;
|
||||
if (!Emu.GetIdManager().GetIDData(sleep_queue, sq)) return CELL_ESRCH;
|
||||
if (!Emu.GetIdManager().GetIDData(sleep_queue, sq))
|
||||
{
|
||||
return CELL_ESRCH;
|
||||
}
|
||||
|
||||
target = attribute & SYS_SYNC_FIFO ? sq->pop() : sq->pop_prio();
|
||||
case se32(SYS_SYNC_RETRY): break;
|
||||
}
|
||||
if (target) mutex.unlock(tid, target);
|
||||
else mutex.unlock(tid);
|
||||
}
|
||||
|
||||
if (!mutex.compare_and_swap_test(tid, target))
|
||||
{
|
||||
assert(!"sys_lwmutex_t::unlock() failed");
|
||||
}
|
||||
}
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int sys_lwmutex_t::lock(be_t<u32> tid, u64 timeout)
|
||||
s32 sys_lwmutex_t::lock(be_t<u32> tid, u64 timeout)
|
||||
{
|
||||
switch (int res = trylock(tid))
|
||||
switch (s32 res = trylock(tid))
|
||||
{
|
||||
case static_cast<int>(CELL_EBUSY): break;
|
||||
case static_cast<s32>(CELL_EBUSY): break;
|
||||
default: return res;
|
||||
}
|
||||
|
||||
SleepQueue* sq;
|
||||
if (!Emu.GetIdManager().GetIDData(sleep_queue, sq)) return CELL_ESRCH;
|
||||
if (!Emu.GetIdManager().GetIDData(sleep_queue, sq))
|
||||
{
|
||||
return CELL_ESRCH;
|
||||
}
|
||||
|
||||
switch (attribute.ToBE() & se32(SYS_SYNC_ATTR_PROTOCOL_MASK))
|
||||
{
|
||||
case se32(SYS_SYNC_PRIORITY):
|
||||
case se32(SYS_SYNC_FIFO):
|
||||
{
|
||||
sq->push(tid);
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (mutex.lock(tid, timeout))
|
||||
const u64 time_start = get_system_time();
|
||||
while (true)
|
||||
{
|
||||
case SMR_OK:
|
||||
sq->invalidate(tid);
|
||||
case SMR_SIGNAL:
|
||||
recursive_count = 1; return CELL_OK;
|
||||
case SMR_TIMEOUT:
|
||||
sq->invalidate(tid); return CELL_ETIMEDOUT;
|
||||
case SMR_ABORT:
|
||||
if (Emu.IsStopped()) sys_lwmutex.Warning("sys_lwmutex_t::lock(sq=%d) aborted", (u32)sleep_queue);
|
||||
default:
|
||||
sq->invalidate(tid); return CELL_EINVAL;
|
||||
auto old_owner = mutex.compare_and_swap(be_t<u32>::make(0), tid);
|
||||
if (!old_owner.ToBE())
|
||||
{
|
||||
sq->invalidate(tid);
|
||||
break;
|
||||
}
|
||||
if (old_owner == tid)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
|
||||
|
||||
if (timeout && get_system_time() - time_start > timeout)
|
||||
{
|
||||
sq->invalidate(tid);
|
||||
return CELL_ETIMEDOUT;
|
||||
}
|
||||
|
||||
if (Emu.IsStopped())
|
||||
{
|
||||
sys_lwmutex.Warning("sys_lwmutex_t::lock(sq=%d) aborted", (u32)sleep_queue);
|
||||
return CELL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
recursive_count = 1;
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <Utilities/SMutex.h>
|
||||
|
||||
// attr_protocol (waiting scheduling policy)
|
||||
enum
|
||||
@ -66,8 +65,8 @@ struct SleepQueue
|
||||
|
||||
struct sys_lwmutex_t
|
||||
{
|
||||
SMutexBase<be_t<u32>> mutex;
|
||||
be_t<u32> waiter; // currently not used
|
||||
atomic_t<u32> mutex;
|
||||
atomic_t<u32> waiter; // currently not used
|
||||
be_t<u32> attribute;
|
||||
be_t<u32> recursive_count;
|
||||
be_t<u32> sleep_queue;
|
||||
@ -78,9 +77,9 @@ struct sys_lwmutex_t
|
||||
return *(reinterpret_cast<u64*>(this));
|
||||
}
|
||||
|
||||
int trylock(be_t<u32> tid);
|
||||
int unlock(be_t<u32> tid);
|
||||
int lock(be_t<u32> tid, u64 timeout);
|
||||
s32 trylock(be_t<u32> tid);
|
||||
s32 unlock(be_t<u32> tid);
|
||||
s32 lock(be_t<u32> tid, u64 timeout);
|
||||
};
|
||||
|
||||
// Aux
|
||||
|
@ -2,9 +2,12 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
#include "Utilities/SMutex.h"
|
||||
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
#include "sys_mutex.h"
|
||||
|
||||
SysCallBase sys_mutex("sys_mutex");
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "sys_lwmutex.h"
|
||||
|
||||
struct sys_mutex_attribute
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
|
@ -2,9 +2,11 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "Emu/CPU/CPUThreadManager.h"
|
||||
#include "Emu/Cell/PPUThread.h"
|
||||
#include "sys_lwmutex.h"
|
||||
#include "sys_time.h"
|
||||
#include "sys_semaphore.h"
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "sys_lwmutex.h"
|
||||
|
||||
struct sys_semaphore_attribute
|
||||
{
|
||||
be_t<u32> protocol;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Emu/Memory/Memory.h"
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/SysCalls/SysCalls.h"
|
||||
#include "Emu/Memory/atomic_type.h"
|
||||
|
||||
#include "Emu/Event.h"
|
||||
#include "sys_timer.h"
|
||||
|
Loading…
Reference in New Issue
Block a user