GUI: Fixed some GUI related start/stop crashes

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4223 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson
2009-09-07 12:40:43 +00:00
parent 49601e0af2
commit 7e115dcb00
27 changed files with 424 additions and 190 deletions

View File

@ -17,9 +17,11 @@
#include "Common.h"
#include "MemoryUtil.h"
#include "StringUtil.h"
#ifdef _WIN32
#include <windows.h>
#include <psapi.h>
#elif __GNUC__
#include <sys/mman.h>
#include <errno.h>
@ -132,3 +134,28 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
#endif
}
std::string MemUsage()
{
#ifdef _WIN32
DWORD processID = GetCurrentProcessId();
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
std::string Ret;
// Print information about the memory usage of the process.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
if (NULL == hProcess) return "MemUsage Error";
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
Ret = StringFromFormat("%s K", ThS(pmc.WorkingSetSize / 1024, true, 7).c_str());
CloseHandle(hProcess);
return Ret;
#else
return "";
#endif
}

View File

@ -18,11 +18,14 @@
#ifndef _MEMORYUTIL_H
#define _MEMORYUTIL_H
#include <iostream>
void* AllocateExecutableMemory(size_t size, bool low = true);
void* AllocateMemoryPages(size_t size);
void FreeMemoryPages(void* ptr, size_t size);
void WriteProtectMemory(void* ptr, size_t size, bool executable = false);
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false);
std::string MemUsage();
inline int GetPageSize() { return 4096; }

View File

@ -452,7 +452,7 @@ std::string ThS(int Integer, bool Unsigned, int Spaces)
// Spaces
std::string Spc = "";
for (int i = 0; i < (Spaces - Sbuf.length()); i++) Spc += " ";
for (int i = 0; i < (int)(Spaces - Sbuf.length()); i++) Spc += " ";
return Spc + Sbuf;
}

View File

@ -26,6 +26,15 @@
namespace Common
{
int Thread::CurrentId()
{
#ifdef _WIN32
return GetCurrentThreadId();
#else
return 0;
#endif
}
#ifdef _WIN32
void InitThreading()
@ -81,14 +90,16 @@ Thread::~Thread()
WaitForDeath();
}
void Thread::WaitForDeath(const int _Wait)
DWORD Thread::WaitForDeath(const int iWait)
{
if (m_hThread)
{
WaitForSingleObject(m_hThread, _Wait);
DWORD Wait = WaitForSingleObject(m_hThread, iWait);
CloseHandle(m_hThread);
m_hThread = NULL;
return Wait;
}
return NULL;
}
void Thread::SetAffinity(int mask)

View File

@ -105,9 +105,10 @@ public:
void SetAffinity(int mask);
static void SetCurrentThreadAffinity(int mask);
#ifdef _WIN32
static int CurrentId();
#ifdef _WIN32
void SetPriority(int priority);
void WaitForDeath(const int _Wait = INFINITE);
DWORD WaitForDeath(const int iWait = INFINITE);
#else
void WaitForDeath();
#endif