X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=os_win32.cpp;h=f220ae5ec46dbbcd7368ca0204a36a669d26c835;hb=81bbbbc7f387d85dc53a41380a7cf0b98fce37ea;hp=e96cc93d63431f9a74b5f5057313b113422986af;hpb=c26194e92e4ac8f9672806afe29a9ef4636a24f2;p=apitrace diff --git a/os_win32.cpp b/os_win32.cpp index e96cc93..f220ae5 100644 --- a/os_win32.cpp +++ b/os_win32.cpp @@ -28,7 +28,6 @@ #include #include "os.hpp" -#include "log.hpp" namespace OS { @@ -46,14 +45,14 @@ CriticalSection = { void AcquireMutex(void) { - //EnterCriticalSection(&CriticalSection); + EnterCriticalSection(&CriticalSection); } void ReleaseMutex(void) { - //LeaveCriticalSection(&CriticalSection); + LeaveCriticalSection(&CriticalSection); } @@ -89,14 +88,39 @@ GetCurrentDir(char *str, size_t size) } void -DebugMessage(const char *message) +DebugMessage(const char *format, ...) { - OutputDebugStringA(message); - if (!IsDebuggerPresent()) { - fflush(stdout); - fputs(message, stderr); - fflush(stderr); - } + char buf[4096]; + + va_list ap; + va_start(ap, format); + fflush(stdout); + vsnprintf(buf, sizeof buf, format, ap); + va_end(ap); + + OutputDebugStringA(buf); + + /* + * Also write the message to stderr, when a debugger is not present (to + * avoid duplicate messages in command line debuggers). + */ +#if _WIN32_WINNT > 0x0400 + if (!IsDebuggerPresent()) { + fflush(stdout); + fputs(buf, stderr); + fflush(stderr); + } +#endif +} + +long long GetTime(void) +{ + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + if (!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return counter.QuadPart*1000000LL/frequency.QuadPart; } void @@ -109,25 +133,4 @@ Abort(void) #endif } - - } /* namespace OS */ - - -#if 0 -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - switch(fdwReason) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - return TRUE; - case DLL_THREAD_DETACH: - return TRUE; - case DLL_PROCESS_DETACH: - Log::Close(); - return TRUE; - } - (void)hinstDLL; - (void)lpvReserved; - return TRUE; -} -#endif