diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index 76b97e96d9..e13cc2460b 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -42,6 +42,12 @@ public: /* Re-exec the game. If this is implemented, it doesn't return. */ virtual void RestartProgram() { } + /* Call this to temporarily enter a high-priority or realtime scheduling (depending + * on the implementation) mode. This is used to improve timestamp accuracy. Do as + * little as possible in this mode; hanging in it might hang the system entirely. */ + virtual void EnterTimeCriticalSection() { } + virtual void ExitTimeCriticalSection() { } + protected: virtual void MessageBoxErrorPrivate( CString sMessage, CString ID ) { printf("Error: %s\n", sMessage.c_str()); } virtual void MessageBoxOKPrivate( CString sMessage, CString ID ) {} diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index e85e07433f..6e8e4eeb67 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -12,9 +12,16 @@ #include "archutils/win32/RestartProgram.h" #include "ProductInfo.h" +#include "RageThreads.h" ArchHooks_Win32::ArchHooks_Win32() { SetUnhandledExceptionFilter(CrashHandler); + TimeCritMutex = new RageMutex; +} + +ArchHooks_Win32::~ArchHooks_Win32() +{ + delete TimeCritMutex; } void ArchHooks_Win32::DumpDebugInfo() @@ -180,9 +187,24 @@ void ArchHooks_Win32::RestartProgram() Win32RestartProgram(); } +void ArchHooks_Win32::EnterTimeCriticalSection() +{ + TimeCritMutex->Lock(); + + OldThreadPriority = GetThreadPriority( GetCurrentThread() ); + SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL ); +} + +void ArchHooks_Win32::ExitTimeCriticalSection() +{ + SetThreadPriority( GetCurrentThread(), OldThreadPriority ); + OldThreadPriority = 0; + TimeCritMutex->Unlock(); +} + /* - * Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. + * Copyright (c) 2002-2004 by the person(s) listed below. All rights reserved. * * Glenn Maynard * Chris Danford diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index 6ffc814ee8..9fa927b4a1 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -2,16 +2,24 @@ #define ARCH_HOOKS_WIN32_H #include "ArchHooks.h" +class RageMutex; + class ArchHooks_Win32: public ArchHooks { public: ArchHooks_Win32(); + ~ArchHooks_Win32(); void DumpDebugInfo(); void MessageBoxOKPrivate( CString sMessage, CString ID ); void MessageBoxErrorPrivate( CString error, CString ID ); MessageBoxResult MessageBoxAbortRetryIgnorePrivate( CString sMessage, CString ID ); MessageBoxResult MessageBoxRetryCancelPrivate( CString sMessage, CString ID ); void RestartProgram(); + + int OldThreadPriority; + RageMutex *TimeCritMutex; + void EnterTimeCriticalSection(); + void ExitTimeCriticalSection(); }; #undef ARCH_HOOKS