Skip to content

Commit

Permalink
Improve match2 ctx context start
Browse files Browse the repository at this point in the history
  • Loading branch information
RipleyTom authored and Megamouse committed May 19, 2024
1 parent b83f1e7 commit e42ba05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rpcs3/Emu/Cell/Modules/sceNp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/NP/np_contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down

0 comments on commit e42ba05

Please sign in to comment.