Improve match2 ctx context start

This commit is contained in:
RipleyTom 2024-05-19 00:49:22 +02:00 committed by Megamouse
parent b83f1e7694
commit e42ba05883
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -191,6 +191,8 @@ struct match2_ctx
static const u32 id_count = 255; // TODO: constant here?
SAVESTATE_INIT_POS(27);
atomic_t<u32> started = 0;
shared_mutex mutex;
SceNpCommunicationId communicationId{};