Set timer resolution to 0.5ms on Windows

This commit is contained in:
Adam Honse 2020-07-25 01:20:49 -05:00
parent 8b5717470a
commit 1555dae1c8

View file

@ -38,6 +38,33 @@ enum
RET_FLAG_START_MINIMIZED = 8,
};
/******************************************************************************************\
* *
* InitializeTimerResolution (Win32) *
* *
* On Windows, the default timer resolution is 15.6ms. For higher accuracy delays, *
* the timer resolution should be set to a shorter interval. The shortest interval *
* that can be set is 0.5ms. *
* *
\******************************************************************************************/
#ifdef _WIN32
typedef unsigned int NTSTATUS;
typedef NTSTATUS (*NTSETTIMERRESOLUTION)(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
void InitializeTimerResolution()
{
NTSETTIMERRESOLUTION NtSetTimerResolution;
HMODULE NtDllHandle;
ULONG CurrentResolution;
NtDllHandle = LoadLibrary("ntdll.dll");
NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(NtDllHandle, "NtSetTimerResolution");
NtSetTimerResolution(5000, TRUE, &CurrentResolution);
}
#endif
/******************************************************************************************\
* *
* AttemptLocalConnection *
@ -90,6 +117,10 @@ bool AttemptLocalConnection()
int main(int argc, char* argv[])
{
#ifdef _WIN32
//InitializeTimerResolution();
#endif
ProfileManager profile_manager(rgb_controllers);
NetworkServer server(rgb_controllers);