Defined thread_local for MSVC

Updated asmjit project
Tried to fix crash on exit
Fixed hypothetical issue when pausing already stopped emulator
This commit is contained in:
Nekotekina 2014-06-19 17:50:18 +04:00
parent bf6507e9be
commit ccfaabd1d7
12 changed files with 62 additions and 33 deletions

2
.gitignore vendored
View file

@ -62,3 +62,5 @@ rpcs3/git-version.h
# Ignore other system generated files # Ignore other system generated files
bin/dev_hdd0/log.txt bin/dev_hdd0/log.txt
x64/Debug/emucore.lib
x64/Release/emucore.lib

View file

@ -1,5 +1,11 @@
#pragma once #pragma once
#ifdef _WIN32
#define thread_local __declspec(thread)
#elif __APPLE__
#define thread_local __thread
#endif
#if defined(__GNUG__) #if defined(__GNUG__)
#include <cmath> #include <cmath>
#include <stdlib.h> #include <stdlib.h>

View file

@ -11,14 +11,7 @@ __forceinline void SM_Sleep()
Sleep(1); Sleep(1);
} }
#ifdef _WIN32 thread_local size_t g_this_thread_id = 0;
__declspec(thread)
#elif __APPLE__
__thread
#else
thread_local
#endif
size_t g_this_thread_id = 0;
__forceinline size_t SM_GetCurrentThreadId() __forceinline size_t SM_GetCurrentThreadId()
{ {

View file

@ -3,14 +3,8 @@
#include "Thread.h" #include "Thread.h"
#ifdef _WIN32 thread_local NamedThreadBase* g_tls_this_thread = nullptr;
__declspec(thread) std::atomic<u32> g_thread_count = 0;
#elif __APPLE__
__thread
#else
thread_local
#endif
NamedThreadBase* g_tls_this_thread = nullptr;
NamedThreadBase* GetCurrentNamedThread() NamedThreadBase* GetCurrentNamedThread()
{ {
@ -56,10 +50,12 @@ void ThreadBase::Start()
[this]() [this]()
{ {
g_tls_this_thread = this; g_tls_this_thread = this;
g_thread_count++;
Task(); Task();
m_alive = false; m_alive = false;
g_thread_count--;
}); });
} }
@ -130,6 +126,7 @@ void thread::start(std::function<void()> func)
{ {
NamedThreadBase info(name); NamedThreadBase info(name);
g_tls_this_thread = &info; g_tls_this_thread = &info;
g_thread_count++;
try try
{ {
@ -140,6 +137,8 @@ void thread::start(std::function<void()> func)
ConLog.Error("Crash :("); ConLog.Error("Crash :(");
//std::terminate(); //std::terminate();
} }
g_thread_count--;
}); });
} }

2
asmjit

@ -1 +1 @@
Subproject commit b76922fde96232030be302b3bdd9673e9bcec568 Subproject commit a66efd54609aab7dd98e34c069937f34aa7c8f95

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@ -26,12 +26,10 @@
<ClCompile Include="..\asmjit\src\asmjit\base\context.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\context.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\cpuinfo.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\cpuinfo.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\cputicks.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\cputicks.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\defs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\error.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\error.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\func.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\globals.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\globals.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\logger.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\logger.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\memorymanager.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\operand.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\podvector.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\podvector.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\runtime.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\runtime.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\string.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\string.cpp" />
@ -42,8 +40,11 @@
<ClCompile Include="..\asmjit\src\asmjit\x86\x86compiler.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86compiler.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86context.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86context.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86cpuinfo.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86cpuinfo.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86defs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86func.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86func.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86inst.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86operand.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86regs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86util.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\asmjit\src\asmjit\base\constpool.h" /> <ClInclude Include="..\asmjit\src\asmjit\base\constpool.h" />

View file

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClCompile Include="..\asmjit\src\asmjit\x86\x86assembler.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86assembler.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86compiler.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86compiler.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86context.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86context.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86cpuinfo.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86cpuinfo.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86defs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86func.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\x86\x86func.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\contrib\winremoteruntime.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\contrib\winremoteruntime.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\assembler.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\assembler.cpp" />
@ -14,18 +13,20 @@
<ClCompile Include="..\asmjit\src\asmjit\base\context.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\context.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\cpuinfo.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\cpuinfo.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\cputicks.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\cputicks.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\defs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\error.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\error.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\func.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\globals.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\globals.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\logger.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\logger.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\memorymanager.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\podvector.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\podvector.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\runtime.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\runtime.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\string.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\string.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\vmem.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\vmem.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\zone.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\zone.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\constpool.cpp" /> <ClCompile Include="..\asmjit\src\asmjit\base\constpool.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\base\operand.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86inst.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86operand.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86regs.cpp" />
<ClCompile Include="..\asmjit\src\asmjit\x86\x86util.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\asmjit\src\asmjit\base\constpool.h" /> <ClInclude Include="..\asmjit\src\asmjit\base\constpool.h" />

View file

@ -1844,6 +1844,11 @@ void RSXThread::Task()
while(!TestDestroy()) while(!TestDestroy())
{ {
if (Emu.IsStopped())
{
ConLog.Warning("RSX thread aborted");
return;
}
rCriticalSectionLocker lock(m_cs_main); rCriticalSectionLocker lock(m_cs_main);
inc=1; inc=1;

View file

@ -471,7 +471,7 @@ int cellGcmSetPrepareFlip(mem_ptr_t<CellGcmContextData> ctxt, u32 id)
return CELL_GCM_ERROR_FAILURE; return CELL_GCM_ERROR_FAILURE;
} }
GSLockCurrent gslock(GS_LOCK_WAIT_FLUSH); // could stall on exit GSLockCurrent gslock(GS_LOCK_WAIT_FLUSH); // could freeze on exit
u32 current = ctxt->current; u32 current = ctxt->current;
u32 end = ctxt->end; u32 end = ctxt->end;

View file

@ -13,7 +13,7 @@ extern gcmInfo gcm_info;
int cellGcmCallback(u32 context_addr, u32 count) int cellGcmCallback(u32 context_addr, u32 count)
{ {
GSLockCurrent gslock(GS_LOCK_WAIT_FLUSH); // could stall on exit GSLockCurrent gslock(GS_LOCK_WAIT_FLUSH); // could freeze on exit
CellGcmContextData& ctx = (CellGcmContextData&)Memory[context_addr]; CellGcmContextData& ctx = (CellGcmContextData&)Memory[context_addr];
CellGcmControl& ctrl = (CellGcmControl&)Memory[gcm_info.control_addr]; CellGcmControl& ctrl = (CellGcmControl&)Memory[gcm_info.control_addr];

View file

@ -83,7 +83,7 @@ void sys_ppu_thread_get_join_state(u32 isjoinable_addr)
int sys_ppu_thread_set_priority(u32 thread_id, int prio) int sys_ppu_thread_set_priority(u32 thread_id, int prio)
{ {
sysPrxForUser->Warning("sys_ppu_thread_set_priority(thread_id=%d, prio=%d)", thread_id, prio); sysPrxForUser->Log("sys_ppu_thread_set_priority(thread_id=%d, prio=%d)", thread_id, prio);
CPUThread* thr = Emu.GetCPU().GetThread(thread_id); CPUThread* thr = Emu.GetCPU().GetThread(thread_id);
if(!thr) return CELL_ESRCH; if(!thr) return CELL_ESRCH;

View file

@ -21,6 +21,7 @@ using namespace PPU_instr;
static const std::string& BreakPointsDBName = "BreakPoints.dat"; static const std::string& BreakPointsDBName = "BreakPoints.dat";
static const u16 bpdb_version = 0x1000; static const u16 bpdb_version = 0x1000;
extern std::atomic<u32> g_thread_count;
ModuleInitializer::ModuleInitializer() ModuleInitializer::ModuleInitializer()
{ {
@ -345,8 +346,10 @@ void Emulator::Pause()
//ConLog.Write("pause..."); //ConLog.Write("pause...");
SendDbgCommand(DID_PAUSE_EMU); SendDbgCommand(DID_PAUSE_EMU);
m_status = Paused; if (InterlockedCompareExchange((volatile unsigned long*)&m_status, Paused, Running) == Running)
SendDbgCommand(DID_PAUSED_EMU); {
SendDbgCommand(DID_PAUSED_EMU);
}
} }
void Emulator::Resume() void Emulator::Resume()
@ -370,8 +373,27 @@ void Emulator::Stop()
SendDbgCommand(DID_STOP_EMU); SendDbgCommand(DID_STOP_EMU);
m_status = Stopped; m_status = Stopped;
u32 uncounted = 0 + (u32)(bool)m_dbg_console;
u32 counter = 0;
while (true)
{
if (g_thread_count <= uncounted)
{
ConLog.Write("All threads stopped...");
break;
}
Sleep(1);
if (counter++ > 3000)
{
ConLog.Error("%d threads not stopped (timeout)", (u32)(g_thread_count - uncounted));
break;
}
}
m_rsx_callback = 0; m_rsx_callback = 0;
// TODO: check finalization order
SavePoints(BreakPointsDBName); SavePoints(BreakPointsDBName);
m_break_points.clear(); m_break_points.clear();
m_marked_points.clear(); m_marked_points.clear();
@ -388,7 +410,7 @@ void Emulator::Stop()
GetKeyboardManager().Close(); GetKeyboardManager().Close();
GetMouseManager().Close(); GetMouseManager().Close();
GetCallbackManager().Clear(); GetCallbackManager().Clear();
//not all modules unload cleanly, so we're not unloading them for now // TODO: not all modules unload cleanly, so we're not unloading them for now
//GetModuleManager().UnloadModules(); //GetModuleManager().UnloadModules();
CurGameInfo.Reset(); CurGameInfo.Reset();