mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Some cleanup
This commit is contained in:
parent
f6ba1eaebd
commit
a74e07dc40
15 changed files with 74 additions and 196 deletions
|
@ -1,7 +1,4 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Utilities/Log.h"
|
|
||||||
#include "Emu/Memory/Memory.h"
|
|
||||||
|
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
|
|
||||||
thread_local NamedThreadBase* g_tls_this_thread = nullptr;
|
thread_local NamedThreadBase* g_tls_this_thread = nullptr;
|
||||||
|
@ -27,6 +24,17 @@ void NamedThreadBase::SetThreadName(const std::string& name)
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NamedThreadBase::WaitForAnySignal() // wait 1 ms for something
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m_signal_mtx);
|
||||||
|
m_signal_cv.wait_for(lock, std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NamedThreadBase::Notify() // wake up waiting thread or nothing
|
||||||
|
{
|
||||||
|
m_signal_cv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
ThreadBase::ThreadBase(const std::string& name)
|
ThreadBase::ThreadBase(const std::string& name)
|
||||||
: NamedThreadBase(name)
|
: NamedThreadBase(name)
|
||||||
, m_executor(nullptr)
|
, m_executor(nullptr)
|
||||||
|
@ -40,7 +48,8 @@ ThreadBase::~ThreadBase()
|
||||||
if(IsAlive())
|
if(IsAlive())
|
||||||
Stop(false);
|
Stop(false);
|
||||||
|
|
||||||
safe_delete(m_executor);
|
delete m_executor;
|
||||||
|
m_executor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadBase::Start()
|
void ThreadBase::Start()
|
||||||
|
@ -57,18 +66,7 @@ void ThreadBase::Start()
|
||||||
SetCurrentNamedThread(this);
|
SetCurrentNamedThread(this);
|
||||||
g_thread_count++;
|
g_thread_count++;
|
||||||
|
|
||||||
try
|
Task();
|
||||||
{
|
|
||||||
Task();
|
|
||||||
}
|
|
||||||
catch (const std::string& e)
|
|
||||||
{
|
|
||||||
LOG_ERROR(GENERAL, "Exception: %s", e.c_str());
|
|
||||||
}
|
|
||||||
catch (const char* e)
|
|
||||||
{
|
|
||||||
LOG_ERROR(GENERAL, "Exception: %s", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_alive = false;
|
m_alive = false;
|
||||||
g_thread_count--;
|
g_thread_count--;
|
||||||
|
@ -144,15 +142,7 @@ void thread::start(std::function<void()> func)
|
||||||
SetCurrentNamedThread(&info);
|
SetCurrentNamedThread(&info);
|
||||||
g_thread_count++;
|
g_thread_count++;
|
||||||
|
|
||||||
try
|
func();
|
||||||
{
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
LOG_ERROR(HLE, "Crash :(");
|
|
||||||
//std::terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_thread_count--;
|
g_thread_count--;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
//#include <Utilities/SSemaphore.h>
|
|
||||||
|
|
||||||
static std::thread::id main_thread;
|
static std::thread::id main_thread;
|
||||||
|
|
||||||
|
@ -35,16 +33,9 @@ public:
|
||||||
virtual std::string GetThreadName() const;
|
virtual std::string GetThreadName() const;
|
||||||
virtual void SetThreadName(const std::string& name);
|
virtual void SetThreadName(const std::string& name);
|
||||||
|
|
||||||
void WaitForAnySignal() // wait 1 ms for something
|
void WaitForAnySignal();
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(m_signal_mtx);
|
|
||||||
m_signal_cv.wait_for(lock, std::chrono::milliseconds(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Notify() // wake up waiting thread or nothing
|
void Notify();
|
||||||
{
|
|
||||||
m_signal_cv.notify_one();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NamedThreadBase* GetCurrentNamedThread();
|
NamedThreadBase* GetCurrentNamedThread();
|
||||||
|
@ -89,132 +80,4 @@ public:
|
||||||
void detach();
|
void detach();
|
||||||
void join();
|
void join();
|
||||||
bool joinable() const;
|
bool joinable() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> class MTPacketBuffer
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
volatile bool m_busy;
|
|
||||||
volatile u32 m_put, m_get;
|
|
||||||
std::vector<u8> m_buffer;
|
|
||||||
u32 m_max_buffer_size;
|
|
||||||
mutable std::recursive_mutex m_cs_main;
|
|
||||||
|
|
||||||
void CheckBusy()
|
|
||||||
{
|
|
||||||
m_busy = m_put >= m_max_buffer_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
MTPacketBuffer(u32 max_buffer_size)
|
|
||||||
: m_max_buffer_size(max_buffer_size)
|
|
||||||
{
|
|
||||||
Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
~MTPacketBuffer()
|
|
||||||
{
|
|
||||||
Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Flush()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
|
||||||
m_put = m_get = 0;
|
|
||||||
m_buffer.clear();
|
|
||||||
m_busy = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void _push(const T& v) = 0;
|
|
||||||
virtual T _pop() = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Push(const T& v)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
|
||||||
_push(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
T Pop()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
|
||||||
return _pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasNewPacket() const { std::lock_guard<std::recursive_mutex> lock(m_cs_main); return m_put != m_get; }
|
|
||||||
bool IsBusy() const { return m_busy; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
class StepThread : public ThreadBase
|
|
||||||
{
|
|
||||||
wxSemaphore m_main_sem;
|
|
||||||
wxSemaphore m_destroy_sem;
|
|
||||||
volatile bool m_exit;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
StepThread(const std::string& name = "Unknown StepThread")
|
|
||||||
: ThreadBase(true, name)
|
|
||||||
, m_exit(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~StepThread() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void Task()
|
|
||||||
{
|
|
||||||
m_exit = false;
|
|
||||||
|
|
||||||
while(!TestDestroy())
|
|
||||||
{
|
|
||||||
m_main_sem.Wait();
|
|
||||||
|
|
||||||
if(TestDestroy() || m_exit) break;
|
|
||||||
|
|
||||||
Step();
|
|
||||||
}
|
|
||||||
|
|
||||||
while(!TestDestroy()) std::this_thread::sleep_for(std::chrono::milliseconds(0));
|
|
||||||
if(m_destroy_sem.TryWait() != wxSEMA_NO_ERROR) m_destroy_sem.Post();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Step()=0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void DoStep()
|
|
||||||
{
|
|
||||||
if(IsRunning()) m_main_sem.Post();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaitForExit()
|
|
||||||
{
|
|
||||||
if(TestDestroy()) m_destroy_sem.Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaitForNextStep()
|
|
||||||
{
|
|
||||||
if(!IsRunning()) return;
|
|
||||||
|
|
||||||
while(m_main_sem.TryWait() != wxSEMA_NO_ERROR) std::this_thread::sleep_for(std::chrono::milliseconds(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Exit(bool wait = false)
|
|
||||||
{
|
|
||||||
if(!IsAlive()) return;
|
|
||||||
|
|
||||||
if(m_main_sem.TryWait() != wxSEMA_NO_ERROR)
|
|
||||||
{
|
|
||||||
m_exit = true;
|
|
||||||
m_main_sem.Post();
|
|
||||||
}
|
|
||||||
|
|
||||||
Delete();
|
|
||||||
|
|
||||||
if(wait) WaitForExit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
|
@ -324,40 +324,51 @@ void CPUThread::Task()
|
||||||
// TODO: linux version
|
// TODO: linux version
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (true)
|
try
|
||||||
{
|
{
|
||||||
int status = ThreadStatus();
|
while (true)
|
||||||
|
|
||||||
if (status == CPUThread_Stopped || status == CPUThread_Break)
|
|
||||||
{
|
{
|
||||||
break;
|
int status = ThreadStatus();
|
||||||
}
|
|
||||||
|
|
||||||
if (status == CPUThread_Sleeping)
|
if (status == CPUThread_Stopped || status == CPUThread_Break)
|
||||||
{
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Step();
|
|
||||||
//if (PC - 0x13ED4 < 0x288) trace.push_back(PC);
|
|
||||||
NextPc(m_dec->DecodeMemory(PC + m_offset));
|
|
||||||
|
|
||||||
if (status == CPUThread_Step)
|
|
||||||
{
|
|
||||||
m_is_step = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint i = 0; i < bp.size(); ++i)
|
|
||||||
{
|
|
||||||
if (bp[i] == PC)
|
|
||||||
{
|
{
|
||||||
Emu.Pause();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status == CPUThread_Sleeping)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Step();
|
||||||
|
//if (PC - 0x13ED4 < 0x288) trace.push_back(PC);
|
||||||
|
NextPc(m_dec->DecodeMemory(PC + m_offset));
|
||||||
|
|
||||||
|
if (status == CPUThread_Step)
|
||||||
|
{
|
||||||
|
m_is_step = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint i = 0; i < bp.size(); ++i)
|
||||||
|
{
|
||||||
|
if (bp[i] == PC)
|
||||||
|
{
|
||||||
|
Emu.Pause();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const std::string& e)
|
||||||
|
{
|
||||||
|
LOG_ERROR(GENERAL, "Exception: %s", e.c_str());
|
||||||
|
}
|
||||||
|
catch (const char* e)
|
||||||
|
{
|
||||||
|
LOG_ERROR(GENERAL, "Exception: %s", e);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& v : trace) LOG_NOTICE(PPU, "PC = 0x%llx", v);
|
for (auto& v : trace) LOG_NOTICE(PPU, "PC = 0x%llx", v);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "VFS.h"
|
#include "VFS.h"
|
||||||
|
#include "vfsDirBase.h"
|
||||||
#include "Emu/HDD/HDD.h"
|
#include "Emu/HDD/HDD.h"
|
||||||
#include "vfsDeviceLocalFile.h"
|
#include "vfsDeviceLocalFile.h"
|
||||||
#include "Ini.h"
|
#include "Ini.h"
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "vfsDevice.h"
|
class vfsDevice;
|
||||||
|
struct vfsFileBase;
|
||||||
|
class vfsDirBase;
|
||||||
|
enum vfsOpenMode;
|
||||||
|
|
||||||
enum vfsDeviceType
|
enum vfsDeviceType
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "vfsFileBase.h"
|
|
||||||
#include "vfsDirBase.h"
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
struct vfsFileBase;
|
||||||
|
class vfsDirBase;
|
||||||
|
|
||||||
class vfsDevice
|
class vfsDevice
|
||||||
{
|
{
|
||||||
std::string m_ps3_path;
|
std::string m_ps3_path;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#include "vfsDirBase.h"
|
#include "vfsDirBase.h"
|
||||||
|
|
||||||
class vfsDir : public vfsDirBase
|
class vfsDir : public vfsDirBase
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "vfsDevice.h"
|
|
||||||
#include "vfsDirBase.h"
|
|
||||||
#include "Utilities/rFile.h"
|
#include "Utilities/rFile.h"
|
||||||
|
#include "vfsDirBase.h"
|
||||||
|
|
||||||
vfsDirBase::vfsDirBase(vfsDevice* device)
|
vfsDirBase::vfsDirBase(vfsDevice* device)
|
||||||
: m_pos(0)
|
: m_pos(0)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
class vfsDevice;
|
||||||
|
|
||||||
enum DirEntryFlags
|
enum DirEntryFlags
|
||||||
{
|
{
|
||||||
DirEntry_TypeDir = 0x1,
|
DirEntry_TypeDir = 0x1,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Emu/SysCalls/Modules.h"
|
#include "Emu/SysCalls/Modules.h"
|
||||||
|
|
||||||
|
#include "Emu/FS/vfsFileBase.h"
|
||||||
#include "cellUserInfo.h"
|
#include "cellUserInfo.h"
|
||||||
|
|
||||||
//void cellUserInfo_init();
|
//void cellUserInfo_init();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "Loader/TRP.h"
|
#include "Loader/TRP.h"
|
||||||
#include "Loader/TROPUSR.h"
|
#include "Loader/TROPUSR.h"
|
||||||
#include "Emu/FS/vfsDir.h"
|
#include "Emu/FS/vfsDir.h"
|
||||||
|
#include "Emu/FS/vfsFileBase.h"
|
||||||
#include "Emu/SysCalls/lv2/sys_time.h"
|
#include "Emu/SysCalls/lv2/sys_time.h"
|
||||||
#include "sceNp.h"
|
#include "sceNp.h"
|
||||||
#include "sceNpTrophy.h"
|
#include "sceNpTrophy.h"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Emu/SysCalls/Modules.h"
|
#include "Emu/SysCalls/Modules.h"
|
||||||
|
|
||||||
|
#include "Emu/FS/vfsFileBase.h"
|
||||||
#include "Emu/SysCalls/lv2/lv2Fs.h"
|
#include "Emu/SysCalls/lv2/lv2Fs.h"
|
||||||
|
|
||||||
Module *sys_fs = nullptr;
|
Module *sys_fs = nullptr;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Utilities/Log.h"
|
#include "Utilities/Log.h"
|
||||||
#include "Utilities/rFile.h"
|
#include "Utilities/rFile.h"
|
||||||
|
#include "Emu/FS/vfsStream.h"
|
||||||
#include "Emu/Memory/Memory.h"
|
#include "Emu/Memory/Memory.h"
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Emu/SysCalls/SysCalls.h"
|
#include "Emu/SysCalls/SysCalls.h"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Utilities/Log.h"
|
#include "Utilities/Log.h"
|
||||||
#include "Utilities/rXml.h"
|
#include "Utilities/rXml.h"
|
||||||
|
#include "Emu/FS/vfsFileBase.h"
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "TROPUSR.h"
|
#include "TROPUSR.h"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
struct vfsStream;
|
||||||
|
|
||||||
struct TROPUSRHeader
|
struct TROPUSRHeader
|
||||||
{
|
{
|
||||||
be_t<u32> magic; // 81 8F 54 AD
|
be_t<u32> magic; // 81 8F 54 AD
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue