2012-11-15 00:39:56 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "PPCThreadManager.h"
|
|
|
|
|
#include "PPUThread.h"
|
|
|
|
|
#include "SPUThread.h"
|
2013-07-12 14:42:17 +02:00
|
|
|
#include "RawSPUThread.h"
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
PPCThreadManager::PPCThreadManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PPCThreadManager::~PPCThreadManager()
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PPCThreadManager::Close()
|
|
|
|
|
{
|
|
|
|
|
while(m_threads.GetCount()) RemoveThread(m_threads[0].GetId());
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 14:42:17 +02:00
|
|
|
PPCThread& PPCThreadManager::AddThread(PPCThreadType type)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-08-19 01:06:11 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
|
|
2013-07-12 14:42:17 +02:00
|
|
|
PPCThread* new_thread;
|
|
|
|
|
char* name;
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case PPC_THREAD_PPU: new_thread = new PPUThread(); name = "PPU"; break;
|
|
|
|
|
case PPC_THREAD_SPU: new_thread = new SPUThread(); name = "SPU"; break;
|
|
|
|
|
case PPC_THREAD_RAW_SPU: new_thread = new RawSPUThread(); name = "RawSPU"; break;
|
|
|
|
|
default: assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_thread->SetId(Emu.GetIdManager().GetNewID(wxString::Format("%s Thread", name), new_thread));
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
m_threads.Add(new_thread);
|
2013-06-30 10:46:29 +02:00
|
|
|
wxGetApp().SendDbgCommand(DID_CREATE_THREAD, new_thread);
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
return *new_thread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PPCThreadManager::RemoveThread(const u32 id)
|
|
|
|
|
{
|
2013-08-19 01:06:11 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_mtx_thread);
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
for(u32 i=0; i<m_threads.GetCount(); ++i)
|
|
|
|
|
{
|
2013-07-06 01:49:38 +02:00
|
|
|
if(m_threads[i].m_wait_thread_id == id)
|
|
|
|
|
{
|
|
|
|
|
m_threads[i].Wait(false);
|
|
|
|
|
m_threads[i].m_wait_thread_id = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
if(m_threads[i].GetId() != id) continue;
|
|
|
|
|
|
2013-08-17 18:23:03 +02:00
|
|
|
PPCThread* thr = &m_threads[i];
|
|
|
|
|
wxGetApp().SendDbgCommand(DID_REMOVE_THREAD, thr);
|
2013-08-19 01:06:11 +02:00
|
|
|
if(thr->IsAlive())
|
|
|
|
|
{
|
|
|
|
|
thr->Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
thr->Close();
|
|
|
|
|
delete thr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_threads.RemoveFAt(i);
|
2013-07-06 01:49:38 +02:00
|
|
|
i--;
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Emu.GetIdManager().RemoveID(id, false);
|
|
|
|
|
Emu.CheckStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-12 14:42:17 +02:00
|
|
|
s32 PPCThreadManager::GetThreadNumById(PPCThreadType type, u32 id)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
|
|
|
|
s32 num = 0;
|
|
|
|
|
|
|
|
|
|
for(u32 i=0; i<m_threads.GetCount(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(m_threads[i].GetId() == id) return num;
|
2013-07-12 14:42:17 +02:00
|
|
|
if(m_threads[i].GetType() == type) num++;
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
PPCThread* PPCThreadManager::GetThread(u32 id)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-06-30 10:46:29 +02:00
|
|
|
for(u32 i=0; i<m_threads.GetCount(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(m_threads[i].GetId() == id) return &m_threads[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
void PPCThreadManager::Exec()
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-06-30 10:46:29 +02:00
|
|
|
for(u32 i=0; i<m_threads.GetCount(); ++i)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-06-30 10:46:29 +02:00
|
|
|
m_threads[i].Exec();
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
}
|