mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-25 20:22:30 +01:00
d136adc73f
BUGFIX: Add break after NV4097_SET_TEXTURE_BORDER_COLOR in RSXThread.cpp BUGFIX: Fix parameters passed to RSXTexture::SetControl3 (they were being passed in reverse order) BUGFIX: Remove invalid, non-sensical call to glPixelStorei in GLGSRender.h BUGFIX: Fix signed/unsigned comparison compiler warnings in GLGSRender.h CHANGE: Make GLFragmentProgram::Decompiler synchronous by default CHANGE: Update wxWidgets submodule to latest commit BUGFIX: Fix several memory leaks ADDED: Created a new MSVC debug configuration to output locations of allocations that end up leaking after the program is closed. BUGFIX: Fix the stupid PadHandler crash due to the lack of a virtual d'tor
156 lines
2.1 KiB
C++
156 lines
2.1 KiB
C++
#include "stdafx.h"
|
|
#include "Thread.h"
|
|
|
|
#ifdef _WIN32
|
|
__declspec(thread)
|
|
#else
|
|
thread_local
|
|
#endif
|
|
NamedThreadBase* g_tls_this_thread = nullptr;
|
|
|
|
NamedThreadBase* GetCurrentNamedThread()
|
|
{
|
|
return g_tls_this_thread;
|
|
}
|
|
|
|
std::string NamedThreadBase::GetThreadName() const
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
void NamedThreadBase::SetThreadName(const std::string& name)
|
|
{
|
|
m_name = name;
|
|
}
|
|
|
|
ThreadBase::ThreadBase(const std::string& name)
|
|
: NamedThreadBase(name)
|
|
, m_executor(nullptr)
|
|
, m_destroy(false)
|
|
, m_alive(false)
|
|
{
|
|
}
|
|
|
|
ThreadBase::~ThreadBase()
|
|
{
|
|
if(IsAlive())
|
|
Stop(false);
|
|
|
|
safe_delete(m_executor);
|
|
}
|
|
|
|
void ThreadBase::Start()
|
|
{
|
|
if(m_executor) Stop();
|
|
|
|
std::lock_guard<std::mutex> lock(m_main_mutex);
|
|
|
|
m_destroy = false;
|
|
m_alive = true;
|
|
|
|
m_executor = new std::thread(
|
|
[this]()
|
|
{
|
|
g_tls_this_thread = this;
|
|
|
|
Task();
|
|
|
|
m_alive = false;
|
|
});
|
|
}
|
|
|
|
void ThreadBase::Stop(bool wait, bool send_destroy)
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_main_mutex);
|
|
|
|
if (send_destroy)
|
|
m_destroy = true;
|
|
|
|
if(!m_executor)
|
|
return;
|
|
|
|
if(wait && m_executor->joinable() && m_alive)
|
|
{
|
|
m_executor->join();
|
|
}
|
|
else
|
|
{
|
|
m_executor->detach();
|
|
}
|
|
|
|
delete m_executor;
|
|
m_executor = nullptr;
|
|
}
|
|
|
|
bool ThreadBase::Join() const
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_main_mutex);
|
|
if(m_executor->joinable() && m_alive && m_executor != nullptr)
|
|
{
|
|
m_executor->join();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool ThreadBase::IsAlive() const
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_main_mutex);
|
|
return m_alive;
|
|
}
|
|
|
|
bool ThreadBase::TestDestroy() const
|
|
{
|
|
return m_destroy;
|
|
}
|
|
|
|
thread::thread(const std::string& name, std::function<void()> func) : m_name(name)
|
|
{
|
|
start(func);
|
|
}
|
|
|
|
thread::thread(const std::string& name) : m_name(name)
|
|
{
|
|
}
|
|
|
|
thread::thread()
|
|
{
|
|
}
|
|
|
|
void thread::start(std::function<void()> func)
|
|
{
|
|
std::string name = m_name;
|
|
|
|
m_thr = std::thread([func, name]()
|
|
{
|
|
NamedThreadBase info(name);
|
|
g_tls_this_thread = &info;
|
|
|
|
try
|
|
{
|
|
func();
|
|
}
|
|
catch(...)
|
|
{
|
|
ConLog.Error("Crash :(");
|
|
//std::terminate();
|
|
}
|
|
});
|
|
}
|
|
|
|
void thread::detach()
|
|
{
|
|
m_thr.detach();
|
|
}
|
|
|
|
void thread::join()
|
|
{
|
|
m_thr.join();
|
|
}
|
|
|
|
bool thread::joinable() const
|
|
{
|
|
return m_thr.joinable();
|
|
}
|