[Project64] Move thread code to Emulation Thread.cpp

This commit is contained in:
zilmar 2015-11-15 20:51:44 +11:00
parent 3024d7c524
commit 3a80cd7138
6 changed files with 106 additions and 75 deletions

View File

@ -0,0 +1,96 @@
/****************************************************************************
* *
* Project64 - A Nintendo 64 emulator. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2012 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#include "stdafx.h"
#include <Project64\N64 System\N64 Class.h>
#include <common/Util.h>
#include <Windows.h>
#include <Objbase.h>
void CN64System::StartEmulationThead()
{
ThreadInfo * Info = new ThreadInfo;
HANDLE * hThread = new HANDLE;
*hThread = NULL;
//create the needed info into a structure to pass as one parameter
//for creating a thread
Info->ThreadHandle = hThread;
*hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, (LPDWORD)&Info->ThreadID);
}
void CN64System::StartEmulationThread(ThreadInfo * Info)
{
if (g_Settings->LoadBool(Setting_CN64TimeCritical))
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
}
CoInitialize(NULL);
EmulationStarting(Info->ThreadHandle, Info->ThreadID);
delete ((HANDLE *)Info->ThreadHandle);
delete Info;
CoUninitialize();
}
void CN64System::CloseCpu()
{
if (m_CPU_Handle == NULL)
{
return;
}
m_EndEmulation = true;
if (g_Settings->LoadBool(GameRunning_CPU_Paused))
{
m_hPauseEvent.Trigger();
}
if (GetCurrentThreadId() == m_CPU_ThreadID)
{
ExternalEvent(SysEvent_CloseCPU);
return;
}
HANDLE hThread = m_CPU_Handle;
m_CPU_Handle = NULL;
for (int count = 0; count < 200; count++)
{
pjutil::Sleep(100);
if (g_Notify->ProcessGuiMessages())
{
return;
}
DWORD ExitCode;
if (GetExitCodeThread(hThread, &ExitCode))
{
if (ExitCode != STILL_ACTIVE)
{
break;
}
}
}
if (hThread)
{
DWORD ExitCode;
GetExitCodeThread(hThread, &ExitCode);
if (ExitCode == STILL_ACTIVE)
{
TerminateThread(hThread, 0);
}
}
CloseHandle(hThread);
CpuStopped();
}

View File

@ -325,15 +325,7 @@ void CN64System::StartEmulation2(bool NewThread)
}
else
{
ThreadInfo * Info = new ThreadInfo;
HANDLE * hThread = new HANDLE;
*hThread = NULL;
//create the needed info into a structure to pass as one parameter
//for creating a thread
Info->ThreadHandle = hThread;
*hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, (LPDWORD)&Info->ThreadID);
StartEmulationThead();
}
}
else
@ -359,72 +351,6 @@ void CN64System::StartEmulation(bool NewThread)
}
}
void CN64System::StartEmulationThread(ThreadInfo * Info)
{
if (g_Settings->LoadBool(Setting_CN64TimeCritical))
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
}
CoInitialize(NULL);
EmulationStarting(Info->ThreadHandle, Info->ThreadID);
delete Info->ThreadHandle;
delete Info;
CoUninitialize();
}
void CN64System::CloseCpu()
{
if (m_CPU_Handle == NULL)
{
return;
}
m_EndEmulation = true;
if (g_Settings->LoadBool(GameRunning_CPU_Paused))
{
m_hPauseEvent.Trigger();
}
if (GetCurrentThreadId() == m_CPU_ThreadID)
{
ExternalEvent(SysEvent_CloseCPU);
return;
}
HANDLE hThread = m_CPU_Handle;
for (int count = 0; count < 200; count++)
{
Sleep(100);
if (Notify().ProcessGuiMessages())
{
return;
}
DWORD ExitCode;
if (GetExitCodeThread(hThread, &ExitCode))
{
if (ExitCode != STILL_ACTIVE)
{
break;
}
}
}
if (hThread)
{
DWORD ExitCode;
GetExitCodeThread(hThread, &ExitCode);
if (ExitCode == STILL_ACTIVE)
{
TerminateThread(hThread, 0);
}
}
CpuStopped();
}
void CN64System::DisplayRomInfo(HWND hParent)
{
if (!g_Rom) { return; }

View File

@ -97,6 +97,7 @@ private:
static void StartEmulationThread(ThreadInfo * Info);
static bool EmulationStarting(void * hThread, uint32_t ThreadId);
static void StartEmulationThead();
void ExecuteCPU();
void RefreshScreen();

View File

@ -440,6 +440,10 @@
RelativePath="N64 System\Cheat Class.cpp"
>
</File>
<File
RelativePath=".\N64 System\Emulation Thread.cpp"
>
</File>
<File
RelativePath="N64 System\N64 Class.cpp"
>

View File

@ -48,6 +48,7 @@
<ClCompile Include="logging.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Multilanguage\LanguageSelector.cpp" />
<ClCompile Include="N64 System\Emulation Thread.cpp" />
<ClCompile Include="N64 System\Mips\Rumblepak.cpp" />
<ClCompile Include="Plugins\Plugin Base.cpp" />
<ClCompile Include="Settings\Logging Settings.cpp" />

View File

@ -429,6 +429,9 @@
<ClCompile Include="AppInit.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="N64 System\Emulation Thread.cpp">
<Filter>Source Files\N64 System Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="User Interface\Icons\left.ico">