diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 248edfe5d3..dea1ff1974 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -122,22 +122,24 @@ error_code sys_event_queue_create(vm::ptr equeue_id, vm::ptr(protocol, type, attr->name_u64, event_queue_key, size); + CellError error = CELL_EAGAIN; + if (event_queue_key == SYS_EVENT_QUEUE_LOCAL) { // Not an IPC queue - if (const u32 _id = idm::import_existing(std::move(queue))) + if (const u32 _id = idm::import([&]() { if ((error = queue->on_id_create())) queue.reset(); return std::move(queue); } )) { *equeue_id = _id; return CELL_OK; } - return CELL_EAGAIN; + return error; } // Create IPC queue if (!ipc_manager::add(event_queue_key, [&]() -> std::shared_ptr { - if (const u32 _id = idm::import_existing(queue)) + if (const u32 _id = idm::import([&]() { if ((error = queue->on_id_create())) return decltype(queue){}; return queue; } )) { *equeue_id = _id; return std::move(queue); @@ -151,7 +153,7 @@ error_code sys_event_queue_create(vm::ptr equeue_id, vm::ptr exists = true; // Existence validation (workaround for shared-ptr ref-counting) + atomic_t exists = 0; // Existence validation (workaround for shared-ptr ref-counting) shared_mutex mutex; std::deque events; std::deque sq; @@ -112,6 +112,12 @@ struct lv2_event_queue final : public lv2_obj // Check queue ptr validity (use 'exists' member) static bool check(const std::weak_ptr&); static bool check(const std::shared_ptr&); + + CellError on_id_create() + { + exists++; + return {}; + } }; struct lv2_event_port final : lv2_obj