summaryrefslogtreecommitdiffstats
path: root/platform/windows/os_windows.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows/os_windows.cpp')
-rw-r--r--platform/windows/os_windows.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index d7a97a3b2d..7ff14cc1e1 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -45,6 +45,7 @@
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
#include "drivers/windows/file_access_windows_pipe.h"
+#include "drivers/windows/ip_windows.h"
#include "drivers/windows/net_socket_winsock.h"
#include "main/main.h"
#include "servers/audio_server.h"
@@ -71,6 +72,7 @@
extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
+__declspec(dllexport) void NoHotPatch() {} // Disable Nahimic code injection.
}
// Workaround mingw-w64 < 4.0 bug
@@ -276,7 +278,7 @@ void OS_Windows::initialize() {
current_pi.pi.hProcess = GetCurrentProcess();
process_map->insert(GetCurrentProcessId(), current_pi);
- IPUnix::make_default();
+ IPWindows::make_default();
main_loop = nullptr;
HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown **>(&dwrite_factory));
@@ -817,10 +819,22 @@ double OS_Windows::get_unix_time() const {
}
void OS_Windows::delay_usec(uint32_t p_usec) const {
- if (p_usec < 1000) {
- Sleep(1);
- } else {
- Sleep(p_usec / 1000);
+ constexpr uint32_t tolerance = 1000 + 20;
+
+ uint64_t t0 = get_ticks_usec();
+ uint64_t target_time = t0 + p_usec;
+
+ // Calculate sleep duration with a tolerance for fine-tuning.
+ if (p_usec > tolerance) {
+ uint32_t coarse_sleep_usec = p_usec - tolerance;
+ if (coarse_sleep_usec >= 1000) {
+ Sleep(coarse_sleep_usec / 1000);
+ }
+ }
+
+ // Spin-wait until we reach the precise target time.
+ while (get_ticks_usec() < target_time) {
+ YieldProcessor();
}
}