mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-14 11:28:11 +00:00
[host/common] windows: provide delayExecution
via nsleep
This change moves this platform specific sleep to `common` as the OS agnostic `nsleep` function. Ref PR #661
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright (C) 2017-2021 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "windows/delay.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
NTSYSCALLAPI NTSTATUS NTAPI NtDelayExecution(
|
||||
_In_ BOOLEAN Alertable,
|
||||
_In_opt_ PLARGE_INTEGER DelayInterval
|
||||
);
|
||||
|
||||
NTSYSCALLAPI NTSTATUS NTAPI NtSetTimerResolution(
|
||||
_In_ ULONG DesiredTime,
|
||||
_In_ BOOLEAN SetResolution,
|
||||
_Out_ PULONG ActualTime
|
||||
);
|
||||
|
||||
void delayInit(void)
|
||||
{
|
||||
ULONG actualResolution;
|
||||
NtSetTimerResolution(1, true, &actualResolution);
|
||||
DEBUG_INFO("System timer resolution: %.1f μs", actualResolution / 10.0);
|
||||
}
|
||||
|
||||
void delayExecution(float ms)
|
||||
{
|
||||
LARGE_INTEGER interval = { .QuadPart = -1 * (LONGLONG)(ms * 10000.0f) };
|
||||
NtDelayExecution(FALSE, &interval);
|
||||
}
|
@@ -19,8 +19,8 @@
|
||||
*/
|
||||
|
||||
#include "windows/mousehook.h"
|
||||
#include "windows/delay.h"
|
||||
#include "common/windebug.h"
|
||||
#include "common/time.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <windows.h>
|
||||
@@ -105,7 +105,7 @@ static DWORD WINAPI updateThreadProc(LPVOID lParam)
|
||||
mouseHook.callback(mouseHook.x, mouseHook.y);
|
||||
|
||||
// limit this to 1000Hz, who has a mouse that updates faster anyway?
|
||||
delayExecution(1.0f);
|
||||
nsleep(1000000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "platform.h"
|
||||
#include "service.h"
|
||||
#include "windows/delay.h"
|
||||
#include "windows/mousehook.h"
|
||||
|
||||
#include <windows.h>
|
||||
@@ -38,6 +37,7 @@
|
||||
#include "common/option.h"
|
||||
#include "common/locking.h"
|
||||
#include "common/thread.h"
|
||||
#include "common/time.h"
|
||||
|
||||
#define ID_MENU_SHOW_LOG 3000
|
||||
#define ID_MENU_EXIT 3001
|
||||
@@ -495,7 +495,7 @@ bool app_init(void)
|
||||
// always flush stderr
|
||||
setbuf(stderr, NULL);
|
||||
|
||||
delayInit();
|
||||
windowsSetTimerResolution();
|
||||
|
||||
// get the performance frequency for spinlocks
|
||||
QueryPerformanceFrequency(&app.perfFreq);
|
||||
|
Reference in New Issue
Block a user