mirror of
https://github.com/RPCSX/rpcsx.git
synced 2025-12-06 07:12:14 +01:00
move module initialization into a module manager, still has some issues like stopping not working and debug crashing add #idef 0 to modules that aren't in the windows project don't double initialize and don't de-initialize for now, since many modules don't expect it and it leads to many errors remove duplicate module lists for empty modules and implemented ones, make Module non-copyable but movable add secondary project, no real use for it now add some memleak config to the emucore and add asmjit path to rpcs3 small rebase error fixed to get it to compile again add filters for emucore re-add the module manager and static file WIP commit, linker errors abound some more abstraction layer stuff fix the remaining linker errors, re-enable platform specific mouse, pad and keyboard handlers rebasing fix memset undefined and re() usage of se_t before declaration Add wxGUI define by default for cmake builds fix copy constructors of Datetime header fix copy constructors of other wx interface classes remove static declarations of global variables make wxGLCanvas constructor non-ambiguous even with wx2.8. compat mode, fix wrong std::exception constructor calls remove duplicate definition for FromUTF8 and ToUTF8 temp changes
120 lines
2.4 KiB
C++
120 lines
2.4 KiB
C++
#include "stdafx.h"
|
|
#include "Emu/ConLog.h"
|
|
#include "Emu/Memory/Memory.h"
|
|
#include "Emu/System.h"
|
|
|
|
#include "CPUThreadManager.h"
|
|
#include "Emu/Cell/PPUThread.h"
|
|
#include "Emu/Cell/SPUThread.h"
|
|
#include "Emu/Cell/RawSPUThread.h"
|
|
#include "Emu/ARMv7/ARMv7Thread.h"
|
|
|
|
CPUThreadManager::CPUThreadManager()
|
|
: m_raw_spu_num(0)
|
|
{
|
|
}
|
|
|
|
CPUThreadManager::~CPUThreadManager()
|
|
{
|
|
Close();
|
|
}
|
|
|
|
void CPUThreadManager::Close()
|
|
{
|
|
m_raw_spu_num = 0;
|
|
while(m_threads.size()) RemoveThread(m_threads[0]->GetId());
|
|
}
|
|
|
|
CPUThread& CPUThreadManager::AddThread(CPUThreadType type)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
CPUThread* new_thread;
|
|
|
|
switch(type)
|
|
{
|
|
case CPU_THREAD_PPU: new_thread = new PPUThread(); break;
|
|
case CPU_THREAD_SPU: new_thread = new SPUThread(); break;
|
|
case CPU_THREAD_RAW_SPU: new_thread = new RawSPUThread(m_raw_spu_num++); break;
|
|
case CPU_THREAD_ARMv7: new_thread = new ARMv7Thread(); break;
|
|
default: assert(0);
|
|
}
|
|
|
|
new_thread->SetId(Emu.GetIdManager().GetNewID(fmt::Format("%s Thread", new_thread->GetTypeString().c_str()), new_thread));
|
|
|
|
m_threads.push_back(new_thread);
|
|
SendDbgCommand(DID_CREATE_THREAD, new_thread);
|
|
|
|
return *new_thread;
|
|
}
|
|
|
|
void CPUThreadManager::RemoveThread(const u32 id)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
CPUThread* thr = nullptr;
|
|
u32 thread_index = 0;
|
|
|
|
for (u32 i = 0; i < m_threads.size(); ++i)
|
|
{
|
|
if (m_threads[i]->m_wait_thread_id == id)
|
|
{
|
|
m_threads[i]->Wait(false);
|
|
m_threads[i]->m_wait_thread_id = -1;
|
|
}
|
|
|
|
if (m_threads[i]->GetId() != id) continue;
|
|
|
|
thr = m_threads[i];
|
|
thread_index = i;
|
|
}
|
|
|
|
if (thr)
|
|
{
|
|
SendDbgCommand(DID_REMOVE_THREAD, thr);
|
|
thr->Close();
|
|
|
|
m_threads.erase(m_threads.begin() + thread_index);
|
|
}
|
|
|
|
// Removing the ID should trigger the actual deletion of the thread
|
|
Emu.GetIdManager().RemoveID(id);
|
|
Emu.CheckStatus();
|
|
}
|
|
|
|
s32 CPUThreadManager::GetThreadNumById(CPUThreadType type, u32 id)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
s32 num = 0;
|
|
|
|
for(u32 i=0; i<m_threads.size(); ++i)
|
|
{
|
|
if(m_threads[i]->GetId() == id) return num;
|
|
if(m_threads[i]->GetType() == type) num++;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
CPUThread* CPUThreadManager::GetThread(u32 id)
|
|
{
|
|
CPUThread* res;
|
|
|
|
if (!id) return nullptr;
|
|
|
|
if (!Emu.GetIdManager().GetIDData(id, res)) return nullptr;
|
|
|
|
return res;
|
|
}
|
|
|
|
void CPUThreadManager::Exec()
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
for(u32 i=0; i<m_threads.size(); ++i)
|
|
{
|
|
m_threads[i]->Exec();
|
|
}
|
|
}
|