diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index c5cfc6fe21..6014c607bf 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -249,7 +249,7 @@ bool waiter_map_t::is_stopped(u64 signal_id) { if (Emu.IsStopped()) { - LOG_WARNING(Log::HLE, "%s.waiter_op() aborted (signal_id=0x%llx)", m_name.c_str(), signal_id); + LOG_WARNING(Log::HLE, "%s: waiter_op() aborted (signal_id=0x%llx)", m_name.c_str(), signal_id); return true; } return false; diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 57b12ba293..65f70c983b 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -169,8 +169,10 @@ class squeue_t atomic_le_t m_sync; - mutable std::mutex m_rcv_mutex, m_wcv_mutex; - mutable std::condition_variable m_rcv, m_wcv; + mutable std::mutex m_rcv_mutex; + mutable std::mutex m_wcv_mutex; + mutable std::condition_variable m_rcv; + mutable std::condition_variable m_wcv; T m_data[sq_size]; diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp index 4852d04dff..b44c8473dc 100644 --- a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp @@ -46,8 +46,6 @@ s32 cellFsOpen(vm::ptr path, s32 flags, vm::ptr> fd, vm::p const std::string _path = path.get_ptr(); - LV2_LOCK(0); - s32 _oflags = flags; if (flags & CELL_O_CREAT) { @@ -129,8 +127,6 @@ s32 cellFsRead(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr> nread) sys_fs->Log("cellFsRead(fd=%d, buf_addr=0x%x, nbytes=0x%llx, nread_addr=0x%x)", fd, buf.addr(), nbytes, nread.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -152,8 +148,6 @@ s32 cellFsWrite(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite sys_fs->Log("cellFsWrite(fd=%d, buf_addr=0x%x, nbytes=0x%llx, nwrite_addr=0x%x)", fd, buf.addr(), nbytes, nwrite.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -172,8 +166,6 @@ s32 cellFsClose(u32 fd) { sys_fs->Warning("cellFsClose(fd=%d)", fd); - LV2_LOCK(0); - if (!Emu.GetIdManager().RemoveID(fd)) return CELL_ESRCH; @@ -183,8 +175,6 @@ s32 cellFsClose(u32 fd) s32 cellFsOpendir(vm::ptr path, vm::ptr fd) { sys_fs->Warning("cellFsOpendir(path=\"%s\", fd_addr=0x%x)", path.get_ptr(), fd.addr()); - - LV2_LOCK(0); std::shared_ptr dir(Emu.GetVFS().OpenDir(path.get_ptr())); if (!dir || !dir->IsOpened()) @@ -200,8 +190,6 @@ s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread) { sys_fs->Warning("cellFsReaddir(fd=%d, dir_addr=0x%x, nread_addr=0x%x)", fd, dir.addr(), nread.addr()); - LV2_LOCK(0); - std::shared_ptr directory; if (!sys_fs->CheckId(fd, directory)) return CELL_ESRCH; @@ -226,8 +214,6 @@ s32 cellFsClosedir(u32 fd) { sys_fs->Warning("cellFsClosedir(fd=%d)", fd); - LV2_LOCK(0); - if (!Emu.GetIdManager().RemoveID(fd)) return CELL_ESRCH; @@ -238,8 +224,6 @@ s32 cellFsStat(vm::ptr path, vm::ptr sb) { sys_fs->Warning("cellFsStat(path=\"%s\", sb_addr=0x%x)", path.get_ptr(), sb.addr()); - LV2_LOCK(0); - const std::string _path = path.get_ptr(); u32 mode = 0; @@ -316,8 +300,6 @@ s32 cellFsFstat(u32 fd, vm::ptr sb) { sys_fs->Warning("cellFsFstat(fd=%d, sb_addr=0x%x)", fd, sb.addr()); - LV2_LOCK(0); - IDType type; std::shared_ptr file; if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) @@ -344,8 +326,6 @@ s32 cellFsMkdir(vm::ptr path, u32 mode) { sys_fs->Warning("cellFsMkdir(path=\"%s\", mode=0x%x)", path.get_ptr(), mode); - LV2_LOCK(0); - const std::string _path = path.get_ptr(); if (vfsDir().IsExists(_path)) @@ -361,8 +341,6 @@ s32 cellFsRename(vm::ptr from, vm::ptr to) { sys_fs->Warning("cellFsRename(from='%s', to='%s')", from.get_ptr(), to.get_ptr()); - LV2_LOCK(0); - std::string _from = from.get_ptr(); std::string _to = to.get_ptr(); @@ -395,8 +373,6 @@ s32 cellFsChmod(vm::ptr path, u32 mode) { sys_fs->Todo("cellFsChmod(path=\"%s\", mode=0x%x)", path.get_ptr(), mode); - LV2_LOCK(0); - // TODO: return CELL_OK; @@ -406,8 +382,6 @@ s32 cellFsFsync(u32 fd) { sys_fs->Todo("cellFsFsync(fd=0x%x)", fd); - LV2_LOCK(0); - // TODO: return CELL_OK; @@ -417,8 +391,6 @@ s32 cellFsRmdir(vm::ptr path) { sys_fs->Warning("cellFsRmdir(path=\"%s\")", path.get_ptr()); - LV2_LOCK(0); - std::string _path = path.get_ptr(); vfsDir d; @@ -435,8 +407,6 @@ s32 cellFsUnlink(vm::ptr path) { sys_fs->Warning("cellFsUnlink(path=\"%s\")", path.get_ptr()); - LV2_LOCK(0); - std::string _path = path.get_ptr(); if (vfsDir().IsExists(_path)) @@ -455,8 +425,6 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos) { sys_fs->Log("cellFsLseek(fd=%d, offset=0x%llx, whence=0x%x, pos_addr=0x%x)", fd, offset, whence, pos.addr()); - LV2_LOCK(0); - vfsSeekMode seek_mode; switch(whence) { @@ -480,8 +448,6 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos) s32 cellFsFtruncate(u32 fd, u64 size) { sys_fs->Warning("cellFsFtruncate(fd=%d, size=%lld)", fd, size); - - LV2_LOCK(0); IDType type; std::shared_ptr file; @@ -512,8 +478,6 @@ s32 cellFsTruncate(vm::ptr path, u64 size) { sys_fs->Warning("cellFsTruncate(path=\"%s\", size=%lld)", path.get_ptr(), size); - LV2_LOCK(0); - vfsFile f(path.get_ptr(), vfsReadWrite); if (!f.IsOpened()) { @@ -562,8 +526,6 @@ s32 cellFsGetBlockSize(vm::ptr path, vm::ptr sector_size, vm::p sys_fs->Warning("cellFsGetBlockSize(file='%s', sector_size_addr=0x%x, block_size_addr=0x%x)", path.get_ptr(), sector_size.addr(), block_size.addr()); - LV2_LOCK(0); - *sector_size = 4096; // ? *block_size = 4096; // ? @@ -575,8 +537,6 @@ s32 cellFsGetFreeSize(vm::ptr path, vm::ptr block_size, vm::ptr sys_fs->Warning("cellFsGetFreeSize(path=\"%s\", block_size_addr=0x%x, block_count_addr=0x%x)", path.get_ptr(), block_size.addr(), block_count.addr()); - LV2_LOCK(0); - // TODO: Get real values. Currently, it always returns 40 GB of free space divided in 4 KB blocks *block_size = 4096; // ? *block_count = 10 * 1024 * 1024; // ? @@ -589,8 +549,6 @@ s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 sys_fs->Warning("cellFsGetDirectoryEntries(fd=%d, entries_addr=0x%x, entries_size=0x%x, data_count_addr=0x%x)", fd, entries.addr(), entries_size, data_count.addr()); - LV2_LOCK(0); - std::shared_ptr directory; if (!sys_fs->CheckId(fd, directory)) return CELL_ESRCH; @@ -627,8 +585,6 @@ s32 cellFsStReadInit(u32 fd, vm::ptr ringbuf) { sys_fs->Warning("cellFsStReadInit(fd=%d, ringbuf_addr=0x%x)", fd, ringbuf.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -654,8 +610,6 @@ s32 cellFsStReadFinish(u32 fd) { sys_fs->Warning("cellFsStReadFinish(fd=%d)", fd); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -670,8 +624,6 @@ s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr ringbuf) { sys_fs->Warning("cellFsStReadGetRingBuf(fd=%d, ringbuf_addr=0x%x)", fd, ringbuf.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -687,8 +639,6 @@ s32 cellFsStReadGetStatus(u32 fd, vm::ptr status) { sys_fs->Warning("cellFsStReadGetRingBuf(fd=%d, status_addr=0x%x)", fd, status.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -702,8 +652,6 @@ s32 cellFsStReadGetRegid(u32 fd, vm::ptr regid) { sys_fs->Warning("cellFsStReadGetRingBuf(fd=%d, regid_addr=0x%x)", fd, regid.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -717,8 +665,6 @@ s32 cellFsStReadStart(u32 fd, u64 offset, u64 size) { sys_fs->Todo("cellFsStReadStart(fd=%d, offset=0x%llx, size=0x%llx)", fd, offset, size); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -733,8 +679,6 @@ s32 cellFsStReadStop(u32 fd) { sys_fs->Warning("cellFsStReadStop(fd=%d)", fd); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -747,8 +691,6 @@ s32 cellFsStReadStop(u32 fd) s32 cellFsStRead(u32 fd, u32 buf_addr, u64 size, vm::ptr rsize) { sys_fs->Warning("cellFsStRead(fd=%d, buf_addr=0x%x, size=0x%llx, rsize_addr=0x%x)", fd, buf_addr, size, rsize.addr()); - - LV2_LOCK(0); std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) @@ -769,8 +711,6 @@ s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr addr, vm::ptr size) { sys_fs->Todo("cellFsStReadGetCurrentAddr(fd=%d, addr_addr=0x%x, size_addr=0x%x)", fd, addr.addr(), size.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -781,8 +721,6 @@ s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr addr, vm::ptr size) s32 cellFsStReadPutCurrentAddr(u32 fd, u32 addr_addr, u64 size) { sys_fs->Todo("cellFsStReadPutCurrentAddr(fd=%d, addr_addr=0x%x, size=0x%llx)", fd, addr_addr, size); - - LV2_LOCK(0); std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) @@ -794,8 +732,6 @@ s32 cellFsStReadPutCurrentAddr(u32 fd, u32 addr_addr, u64 size) s32 cellFsStReadWait(u32 fd, u64 size) { sys_fs->Todo("cellFsStReadWait(fd=%d, size=0x%llx)", fd, size); - - LV2_LOCK(0); std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) @@ -808,8 +744,6 @@ s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptrTodo("cellFsStReadWaitCallback(fd=%d, size=0x%llx, func_addr=0x%x)", fd, size, func.addr()); - LV2_LOCK(0); - std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -971,8 +905,6 @@ void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptr orig_file; if (!sys_fs->CheckId(fd, orig_file)) { @@ -1018,8 +950,6 @@ int cellFsAioRead(vm::ptr aio, vm::ptr aio_id, vm::ptrWarning("cellFsAioRead(aio_addr=0x%x, id_addr=0x%x, func_addr=0x%x)", aio.addr(), aio_id.addr(), func.addr()); - LV2_LOCK(0); - if (!aio_init) { return CELL_ENXIO; @@ -1049,8 +979,6 @@ int cellFsAioWrite(vm::ptr aio, vm::ptr aio_id, vm::ptrTodo("cellFsAioWrite(aio_addr=0x%x, id_addr=0x%x, func_addr=0x%x)", aio.addr(), aio_id.addr(), func.addr()); - LV2_LOCK(0); - // TODO: return CELL_OK; @@ -1060,8 +988,6 @@ int cellFsAioInit(vm::ptr mount_point) { sys_fs->Warning("cellFsAioInit(mount_point_addr=0x%x (%s))", mount_point.addr(), mount_point.get_ptr()); - LV2_LOCK(0); - aio_init = true; return CELL_OK; } @@ -1070,8 +996,6 @@ int cellFsAioFinish(vm::ptr mount_point) { sys_fs->Warning("cellFsAioFinish(mount_point_addr=0x%x (%s))", mount_point.addr(), mount_point.get_ptr()); - LV2_LOCK(0); - aio_init = false; return CELL_OK; } @@ -1081,8 +1005,6 @@ int cellFsReadWithOffset(u32 fd, u64 offset, vm::ptr buf, u64 buffer_size, sys_fs->Warning("cellFsReadWithOffset(fd=%d, offset=0x%llx, buf_addr=0x%x, buffer_size=%lld nread=0x%llx)", fd, offset, buf.addr(), buffer_size, nread.addr()); - LV2_LOCK(0); - int ret; vm::var> oldPos, newPos; ret = cellFsLseek(fd, 0, CELL_SEEK_CUR, oldPos); // Save the current position diff --git a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp index 07b1d8fa84..6808222a3e 100644 --- a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp @@ -13,7 +13,7 @@ sleep_queue_t::~sleep_queue_t() { for (auto& tid : m_list) { - LOG_NOTICE(HLE, "~sleep_queue_t(): thread %d", tid); + LOG_NOTICE(HLE, "~sleep_queue_t('%s'): m_list[%lld]=%d", m_name.c_str(), &tid - m_list.data(), tid); } } diff --git a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.h b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.h index a05c818ccd..4fabf01e46 100644 --- a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.h +++ b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.h @@ -30,6 +30,7 @@ class sleep_queue_t { std::vector m_list; std::mutex m_mutex; + std::string m_name; public: const u64 name; @@ -41,6 +42,9 @@ public: ~sleep_queue_t(); + void set_full_name(const std::string& name) { m_name = name; } + const std::string& get_full_name() { return m_name; } + void push(u32 tid, u32 protocol); u32 pop(u32 protocol); bool invalidate(u32 tid); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp index c169f61775..5bbb2dc121 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp @@ -15,10 +15,7 @@ SysCallBase sys_cond("sys_cond"); s32 sys_cond_create(vm::ptr cond_id, u32 mutex_id, vm::ptr attr) { - sys_cond.Log("sys_cond_create(cond_id_addr=0x%x, mutex_id=%d, attr_addr=0x%x)", - cond_id.addr(), mutex_id, attr.addr()); - - LV2_LOCK(0); + sys_cond.Log("sys_cond_create(cond_id_addr=0x%x, mutex_id=%d, attr_addr=0x%x)", cond_id.addr(), mutex_id, attr.addr()); if (attr->pshared.ToBE() != se32(0x200)) { @@ -33,11 +30,13 @@ s32 sys_cond_create(vm::ptr cond_id, u32 mutex_id, vm::ptr cond(new Cond(mutex, attr->name_u64)); - const u32 id = sys_cond.GetNewId(cond, TYPE_COND); - *cond_id = id; - mutex->cond_count++; - sys_cond.Warning("*** condition created [%s] (mutex_id=%d): id = %d", std::string(attr->name, 8).c_str(), mutex_id, id); + const u32 id = sys_cond.GetNewId(cond, TYPE_COND); + cond->queue.set_full_name(fmt::Format("Cond(%d, mutex_id=%d)", id, mutex_id)); + *cond_id = id; + mutex->cond_count++; // TODO: check safety + + sys_cond.Warning("*** condition created [%s] (mutex_id=%d): id = %d", std::string(attr->name, 8).c_str(), mutex_id, id); return CELL_OK; } @@ -45,8 +44,6 @@ s32 sys_cond_destroy(u32 cond_id) { sys_cond.Warning("sys_cond_destroy(cond_id=%d)", cond_id); - LV2_LOCK(0); - std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { @@ -58,7 +55,7 @@ s32 sys_cond_destroy(u32 cond_id) return CELL_EBUSY; } - cond->mutex->cond_count--; + cond->mutex->cond_count--; // TODO: check safety Emu.GetIdManager().RemoveID(cond_id); return CELL_OK; } @@ -73,9 +70,7 @@ s32 sys_cond_signal(u32 cond_id) return CELL_ESRCH; } - std::shared_ptr mutex = cond->mutex; - - if (u32 target = cond->queue.pop(mutex->protocol)) + if (u32 target = cond->queue.pop(cond->mutex->protocol)) { cond->signal.push(target); @@ -98,7 +93,7 @@ s32 sys_cond_signal_all(u32 cond_id) return CELL_ESRCH; } - std::shared_ptr mutex = cond->mutex; + Mutex* mutex = cond->mutex.get(); while (u32 target = cond->queue.pop(mutex->protocol)) { @@ -134,8 +129,6 @@ s32 sys_cond_signal_to(u32 cond_id, u32 thread_id) return CELL_EPERM; } - std::shared_ptr mutex = cond->mutex; - u32 target = thread_id; { cond->signal.push(target); @@ -159,7 +152,7 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout) return CELL_ESRCH; } - std::shared_ptr mutex = cond->mutex; + Mutex* mutex = cond->mutex.get(); const u32 tid = CPU.GetId(); if (mutex->owner.read_sync() != tid) diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp index 16b0b9cc9e..32a9c1a3ec 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp @@ -21,7 +21,8 @@ u32 event_queue_create(u32 protocol, s32 type, u64 name_u64, u64 event_queue_key return 0; } - u32 id = sys_event.GetNewId(eq, TYPE_EVENT_QUEUE); + const u32 id = sys_event.GetNewId(eq, TYPE_EVENT_QUEUE); + eq->sq.set_full_name(fmt::Format("EventQueue(%d)", id)); sys_event.Warning("*** event_queue created [%s] (protocol=0x%x, type=0x%x, key=0x%llx, size=0x%x): id = %d", std::string((const char*)&name_u64, 8).c_str(), protocol, type, event_queue_key, size, id); return id; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp index 533ca617ba..d2e4cbfd1d 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp @@ -14,11 +14,11 @@ SysCallBase sys_lwcond("sys_lwcond"); s32 lwcond_create(sys_lwcond_t& lwcond, sys_lwmutex_t& lwmutex, u64 name_u64) { - LV2_LOCK(0); + std::shared_ptr lw(new Lwcond(name_u64, Memory.RealToVirtualAddr(&lwcond))); - std::shared_ptr lw(new Lwcond(name_u64)); - u32 id = sys_lwcond.GetNewId(lw, TYPE_LWCOND); - u32 addr = Memory.RealToVirtualAddr(&lwmutex); + const u32 id = sys_lwcond.GetNewId(lw, TYPE_LWCOND); + const u32 addr = Memory.RealToVirtualAddr(&lwmutex); + lw->queue.set_full_name(fmt::Format("Lwcond(%d, addr=0x%x)", id, lw->addr)); lwcond.lwmutex.set(addr); lwcond.lwcond_queue = id; @@ -38,8 +38,6 @@ s32 sys_lwcond_destroy(vm::ptr lwcond) { sys_lwcond.Warning("sys_lwcond_destroy(lwcond_addr=0x%x)", lwcond.addr()); - LV2_LOCK(0); - u32 id = lwcond->lwcond_queue; std::shared_ptr lw; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.h b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.h index 9e702ff5c5..451c1b3587 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.h @@ -22,8 +22,11 @@ struct Lwcond squeue_t signal; sleep_queue_t queue; - Lwcond(u64 name) + const u32 addr; + + Lwcond(u64 name, u32 addr) : queue(name) + , addr(addr) { } }; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index 3159e7c431..56c5bab163 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -14,8 +14,6 @@ SysCallBase sys_lwmutex("sys_lwmutex"); s32 lwmutex_create(sys_lwmutex_t& lwmutex, u32 protocol, u32 recursive, u64 name_u64) { - LV2_LOCK(0); - std::shared_ptr sq(new sleep_queue_t(name_u64)); lwmutex.owner.write_relaxed(be_t::make(0)); @@ -24,6 +22,7 @@ s32 lwmutex_create(sys_lwmutex_t& lwmutex, u32 protocol, u32 recursive, u64 name lwmutex.recursive_count.write_relaxed(be_t::make(0)); u32 sq_id = sys_lwmutex.GetNewId(sq, TYPE_LWMUTEX); lwmutex.sleep_queue = sq_id; + sq->set_full_name(fmt::Format("Lwmutex(%d, addr=0x%x)", sq_id, Memory.RealToVirtualAddr(&lwmutex))); sys_lwmutex.Notice("*** lwmutex created [%s] (attribute=0x%x): sq_id = %d", std::string((const char*)&name_u64, 8).c_str(), protocol | recursive, sq_id); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index e13b59888b..b7859b1530 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -29,8 +29,6 @@ s32 sys_mutex_create(PPUThread& CPU, vm::ptr mutex_id, vm::ptrprotocol.ToBE()) { case se32(SYS_SYNC_FIFO): break; @@ -55,12 +53,14 @@ s32 sys_mutex_create(PPUThread& CPU, vm::ptr mutex_id, vm::ptr mutex(new Mutex((u32)attr->protocol, is_recursive, attr->name_u64)); + const u32 id = sys_mutex.GetNewId(mutex, TYPE_MUTEX); mutex->id.exchange(id); *mutex_id = id; + mutex->queue.set_full_name(fmt::Format("Mutex(%d)", id)); + sys_mutex.Warning("*** mutex created [%s] (protocol=0x%x, recursive=%s): id = %d", std::string(attr->name, 8).c_str(), (u32) attr->protocol, (is_recursive ? "true" : "false"), id); - // TODO: unlock mutex when owner thread does exit return CELL_OK; } @@ -69,15 +69,14 @@ s32 sys_mutex_destroy(PPUThread& CPU, u32 mutex_id) { sys_mutex.Warning("sys_mutex_destroy(mutex_id=%d)", mutex_id); - LV2_LOCK(0); - std::shared_ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; } - if (mutex->cond_count) // check if associated condition variable exists + // check if associated condition variable exists + if (mutex->cond_count) // TODO: check safety { return CELL_EPERM; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.h b/rpcs3/Emu/SysCalls/lv2/sys_mutex.h index 0eee5a6650..2767dbe31c 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.h @@ -7,7 +7,7 @@ struct sys_mutex_attribute be_t pshared; // always 0x200 (not shared) be_t adaptive; be_t ipc_key; - be_t flags; + be_t flags; be_t pad; union { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index 2bdd56f774..fa97339ab7 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -14,10 +14,11 @@ SysCallBase sys_semaphore("sys_semaphore"); u32 semaphore_create(s32 initial_count, s32 max_count, u32 protocol, u64 name_u64) { - LV2_LOCK(0); - std::shared_ptr sem(new Semaphore(initial_count, max_count, protocol, name_u64)); + const u32 id = sys_semaphore.GetNewId(sem, TYPE_SEMAPHORE); + sem->queue.set_full_name(fmt::Format("Semaphore(%d)", id)); + sys_semaphore.Notice("*** semaphore created [%s] (protocol=0x%x): id = %d", std::string((const char*)&name_u64, 8).c_str(), protocol, id); return id; } @@ -27,15 +28,17 @@ s32 sys_semaphore_create(vm::ptr sem, vm::ptr attr sys_semaphore.Warning("sys_semaphore_create(sem_addr=0x%x, attr_addr=0x%x, initial_count=%d, max_count=%d)", sem.addr(), attr.addr(), initial_count, max_count); - if (sem.addr() == NULL) { - sys_semaphore.Error("sys_semaphore_create(): invalid memory access (sem_addr=0x%x)", sem.addr()); - return CELL_EFAULT; - } + if (!sem) + { + sys_semaphore.Error("sys_semaphore_create(): invalid memory access (sem_addr=0x%x)", sem.addr()); + return CELL_EFAULT; + } - if (attr.addr() == NULL) { - sys_semaphore.Error("sys_semaphore_create(): An invalid argument value is specified (attr_addr=0x%x)", attr.addr()); - return CELL_EFAULT; - } + if (!attr) + { + sys_semaphore.Error("sys_semaphore_create(): An invalid argument value is specified (attr_addr=0x%x)", attr.addr()); + return CELL_EFAULT; + } if (max_count <= 0 || initial_count > max_count || initial_count < 0) { @@ -66,8 +69,6 @@ s32 sys_semaphore_destroy(u32 sem_id) { sys_semaphore.Warning("sys_semaphore_destroy(sem_id=%d)", sem_id); - LV2_LOCK(0); - std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp index 885f0686bd..29cdb9bd39 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp @@ -442,18 +442,17 @@ s32 sys_spu_thread_group_terminate(u32 id, int value) std::shared_ptr spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container) { - LV2_LOCK(0); - if (type) { sys_spu.Todo("Unsupported SPU Thread Group type (0x%x)", type); } std::shared_ptr group(new SpuGroupInfo(name, num, prio, type, container)); + const u32 _id = sys_spu.GetNewId(group); group->m_id = _id; - sys_spu.Notice("*** SPU Thread Group created [%s] (num=%d, prio=%d, type=0x%x, container=%d): id=%d", - name.c_str(), num, prio, type, container, _id); + + sys_spu.Notice("*** SPU Thread Group created [%s] (num=%d, prio=%d, type=0x%x, container=%d): id=%d", name.c_str(), num, prio, type, container, _id); return group; }