Skip to content

Commit

Permalink
Make sure we remove server from our list when SifRemoveRpc is called.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Aug 9, 2024
1 parent 2673683 commit 8d45806
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions Source/iop/Iop_SifCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ void CSifCmd::LoadState(Framework::CZipArchiveReader& archive)
const auto& moduleState(moduleStatePair.second);
uint32 serverDataAddress = moduleState.GetRegister32(STATE_MODULE_SERVER_DATA_ADDRESS);
auto serverData = reinterpret_cast<SIFRPCSERVERDATA*>(m_ram + serverDataAddress);
auto module = new CSifDynamic(*this, serverDataAddress);
m_servers.push_back(module);
m_sifMan.RegisterModule(serverData->serverId, module);
auto module = std::make_unique<CSifDynamic>(*this, serverDataAddress);
m_sifMan.RegisterModule(serverData->serverId, module.get());
m_servers.push_back(std::move(module));
}
}
}
Expand Down Expand Up @@ -339,7 +339,6 @@ void CSifCmd::ClearServers()
{
auto serverData = reinterpret_cast<SIFRPCSERVERDATA*>(m_ram + server->GetServerDataAddress());
m_sifMan.UnregisterModule(serverData->serverId);
delete server;
}
m_servers.clear();
}
Expand Down Expand Up @@ -940,9 +939,9 @@ void CSifCmd::SifRegisterRpc(CMIPS& context)
bool moduleRegistered = m_sifMan.IsModuleRegistered(serverId);
if(!moduleRegistered)
{
auto module = new CSifDynamic(*this, serverDataAddr);
m_servers.push_back(module);
m_sifMan.RegisterModule(serverId, module);
auto module = std::make_unique<CSifDynamic>(*this, serverDataAddr);
m_sifMan.RegisterModule(serverId, module.get());
m_servers.push_back(std::move(module));
}

if(serverDataAddr != 0)
Expand Down Expand Up @@ -1056,7 +1055,14 @@ uint32 CSifCmd::SifRemoveRpc(uint32 serverDataAddr, uint32 queueDataAddr)
return 0;
}

auto matchPredicate =
[serverDataAddr](const DynamicModulePtr& module) {
return module->GetServerDataAddress() == serverDataAddr;
};

m_sifMan.UnregisterModule(serverData->serverId);
assert(std::count_if(std::begin(m_servers), std::end(m_servers), matchPredicate) == 1);
m_servers.erase(std::remove_if(std::begin(m_servers), std::end(m_servers), matchPredicate), std::end(m_servers));

return 1;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/iop/Iop_SifCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace Iop
uint32 queueNext;
};

typedef std::list<CSifDynamic*> DynamicModuleList;
using DynamicModulePtr = std::unique_ptr<CSifDynamic>;
typedef std::list<DynamicModulePtr> DynamicModuleList;
typedef std::function<void(const SIFCMDHEADER*, CSifMan&)> CmdHandler;

CSifCmd(CIopBios&, CSifMan&, CSysmem&, uint8*);
Expand Down

0 comments on commit 8d45806

Please sign in to comment.