diff options
| author | John Peterson <jpeterson57@gmail.com> | 2009-09-07 12:40:43 +0000 |
|---|---|---|
| committer | John Peterson <jpeterson57@gmail.com> | 2009-09-07 12:40:43 +0000 |
| commit | 7e115dcb00c5cabef0bcb920c7a0415dc731ec84 (patch) | |
| tree | 665545a388585ed0cbe92b994892e544c6f87d34 /Source/Core/Common | |
| parent | 49601e0af2104eb0daca32d54840bc60bfea377f (diff) | |
GUI: Fixed some GUI related start/stop crashes
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4223 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Common.vcproj | 12 | ||||
| -rw-r--r-- | Source/Core/Common/Src/MemoryUtil.cpp | 27 | ||||
| -rw-r--r-- | Source/Core/Common/Src/MemoryUtil.h | 3 | ||||
| -rw-r--r-- | Source/Core/Common/Src/StringUtil.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Common/Src/Thread.cpp | 15 | ||||
| -rw-r--r-- | Source/Core/Common/Src/Thread.h | 5 |
6 files changed, 53 insertions, 11 deletions
diff --git a/Source/Core/Common/Common.vcproj b/Source/Core/Common/Common.vcproj index 4ee10ca9ee..93958f9d86 100644 --- a/Source/Core/Common/Common.vcproj +++ b/Source/Core/Common/Common.vcproj @@ -69,7 +69,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="wsock32.lib"
+ AdditionalDependencies="wsock32.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
@@ -142,7 +142,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="wsock32.lib winmm.lib"
+ AdditionalDependencies="wsock32.lib winmm.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
@@ -215,7 +215,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="wsock32.lib"
+ AdditionalDependencies="wsock32.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
@@ -289,7 +289,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="winmm.lib"
+ AdditionalDependencies="winmm.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
@@ -359,7 +359,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="wsock32.lib"
+ AdditionalDependencies="wsock32.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
@@ -429,7 +429,7 @@ />
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="wsock32.lib"
+ AdditionalDependencies="wsock32.lib psapi.lib"
OutputFile="$(OutDir)/Common.lib"
/>
<Tool
diff --git a/Source/Core/Common/Src/MemoryUtil.cpp b/Source/Core/Common/Src/MemoryUtil.cpp index acbdaabcbe..478b31248a 100644 --- a/Source/Core/Common/Src/MemoryUtil.cpp +++ b/Source/Core/Common/Src/MemoryUtil.cpp @@ -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 +}
\ No newline at end of file diff --git a/Source/Core/Common/Src/MemoryUtil.h b/Source/Core/Common/Src/MemoryUtil.h index 6cd9b075a9..0488fdef1c 100644 --- a/Source/Core/Common/Src/MemoryUtil.h +++ b/Source/Core/Common/Src/MemoryUtil.h @@ -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; } diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 1ab10a2f0c..6eb3580e92 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -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; } diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index 0cd237e2f8..05a930b9f3 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -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) diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index c829aded9f..ec1c3884bc 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -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 |
