From e42ba058838aa9c642792016760e728287bd580c Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Sun, 19 May 2024 00:49:22 +0200 Subject: [PATCH] Improve match2 ctx context start --- rpcs3/Emu/Cell/Modules/sceNp2.cpp | 11 +++++++++-- rpcs3/Emu/NP/np_contexts.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sceNp2.cpp b/rpcs3/Emu/Cell/Modules/sceNp2.cpp index d0b957f2e8..ca18b1e0cd 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp2.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp2.cpp @@ -571,6 +571,9 @@ error_code sceNpMatching2ContextStart(SceNpMatching2ContextId ctxId) if (!ctx) return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND; + if (!ctx->started.compare_and_swap_test(0, 1)) + return SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED; + if (ctx->context_callback) { sysutil_register_cb([=](ppu_thread& cb_ppu) -> s32 @@ -1095,6 +1098,9 @@ error_code sceNpMatching2ContextStartAsync(SceNpMatching2ContextId ctxId, u32 ti if (!ctx) return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND; + if (!ctx->started.compare_and_swap_test(0, 1)) + return SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED; + if (ctx->context_callback) { sysutil_register_cb([=](ppu_thread& cb_ppu) -> s32 @@ -1693,10 +1699,11 @@ error_code sceNpMatching2ContextStop(SceNpMatching2ContextId ctxId) const auto ctx = get_match2_context(ctxId); if (!ctx) - { return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID; - } + if (!ctx->started.compare_and_swap_test(1, 0)) + return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_STARTED; + if (ctx->context_callback) { sysutil_register_cb([=](ppu_thread& cb_ppu) -> s32 diff --git a/rpcs3/Emu/NP/np_contexts.h b/rpcs3/Emu/NP/np_contexts.h index edb4c1dc79..d7824daf76 100644 --- a/rpcs3/Emu/NP/np_contexts.h +++ b/rpcs3/Emu/NP/np_contexts.h @@ -191,6 +191,8 @@ struct match2_ctx static const u32 id_count = 255; // TODO: constant here? SAVESTATE_INIT_POS(27); + atomic_t started = 0; + shared_mutex mutex; SceNpCommunicationId communicationId{};