rpcsx/rpcs3/Emu/CPU/CPUThreadManager.h
Peter Tissen 13d2f8fa59 re-enable threadlist in GUI
This used to crash so it was removed. However I think this is a cruicial feature.
This is the only way to observe the stack-frames, registers and disasm around the PC
in a user friendly way.

The reason this caused crashes was that we got a reference to a std::vector and iterated
over it in one thread while another thread could modify it (and thereby invalidating the
iterators). The way I "fixed" it is to just copy the `std::vector<std::shared_ptr<...>>`
and iterate over the copy. This obviously has some overhead (locking the shared_ptr
counters and incrementing them). It also allows entities other than the Thread manager
to keep the Thread objects frome being deleted but that should not be a problem.
2015-02-02 11:33:49 +01:00

30 lines
652 B
C++

#pragma once
class CPUThread;
class RawSPUThread;
enum CPUThreadType : unsigned char;
class CPUThreadManager
{
std::vector<std::shared_ptr<CPUThread>> m_threads;
std::mutex m_mtx_thread;
public:
CPUThreadManager();
~CPUThreadManager();
void Close();
CPUThread& AddThread(CPUThreadType type);
void RemoveThread(const u32 id);
std::vector<std::shared_ptr<CPUThread>> GetThreads() { return m_threads; }
s32 GetThreadNumById(CPUThreadType type, u32 id);
std::shared_ptr<CPUThread> GetThread(u32 id);
std::shared_ptr<CPUThread> GetThread(u32 id, CPUThreadType type);
RawSPUThread* GetRawSPUThread(u32 num);
void Exec();
void Task();
};