[wpinet] Revert removal of uv_clock_gettime() (#5723)

GetSystemTimePreciseAsFileTime() is supposed to be available, and
wpiutil already uses it.
This commit is contained in:
Tyler Veness
2023-10-03 20:39:09 -07:00
committed by GitHub
parent cb1bd0a3be
commit 0960f11eba
6 changed files with 76 additions and 81 deletions

View File

@@ -0,0 +1,42 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Fri, 14 Jul 2023 16:40:18 -0700
Subject: [PATCH 10/10] Add pragmas for missing libraries and set _WIN32_WINNT
to Windows 10
This makes GetSystemTimePreciseAsFileTime() available.
The #define value is from
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt.
---
include/uv/win.h | 2 +-
src/win/util.c | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/uv/win.h b/include/uv/win.h
index 6d0afe69e7dd4caf4c9459e548fe75cf0c51b501..613065df435d813cd517efbc138b13ee46f01f2d 100644
--- a/include/uv/win.h
+++ b/include/uv/win.h
@@ -20,7 +20,7 @@
*/
#ifndef _WIN32_WINNT
-# define _WIN32_WINNT 0x0600
+# define _WIN32_WINNT 0x0A00
#endif
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
diff --git a/src/win/util.c b/src/win/util.c
index 9324992ec521cc3496e3e9304e600963a3f20897..4b76417fcbac2480725471740c037deb859e17ca 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -73,7 +73,9 @@ static char *process_title;
static CRITICAL_SECTION process_title_lock;
#pragma comment(lib, "Advapi32.lib")
+#pragma comment(lib, "Dbghelp.lib")
#pragma comment(lib, "IPHLPAPI.lib")
+#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "Userenv.lib")
#pragma comment(lib, "kernel32.lib")

View File

@@ -1,79 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Fri, 14 Jul 2023 16:40:18 -0700
Subject: [PATCH 10/10] Remove uv_clock_gettime() and add pragmas for missing
libraries
The Win32 function GetSystemTimePreciseAsFileTime() is missing, which
causes compilation errors in uv_clock_gettime(). However, neither WPILib
nor libuv use uv_clock_gettime(), so removing it works around the
problem.
---
include/uv.h | 1 -
src/win/util.c | 33 ++-------------------------------
2 files changed, 2 insertions(+), 32 deletions(-)
diff --git a/include/uv.h b/include/uv.h
index d5342b0d52232bbf83825948cc6bc09e5d74a4c7..9adcf955e143bb323363c9d96da51ccdb618261a 100644
--- a/include/uv.h
+++ b/include/uv.h
@@ -1755,7 +1755,6 @@ UV_EXTERN uint64_t uv_get_total_memory(void);
UV_EXTERN uint64_t uv_get_constrained_memory(void);
UV_EXTERN uint64_t uv_get_available_memory(void);
-UV_EXTERN int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts);
UV_EXTERN uint64_t uv_hrtime(void);
UV_EXTERN void uv_sleep(unsigned int msec);
diff --git a/src/win/util.c b/src/win/util.c
index 9324992ec521cc3496e3e9304e600963a3f20897..4ea2eada07f8d7e664bee22e74b20c705a0eb9a3 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -73,7 +73,9 @@ static char *process_title;
static CRITICAL_SECTION process_title_lock;
#pragma comment(lib, "Advapi32.lib")
+#pragma comment(lib, "Dbghelp.lib")
#pragma comment(lib, "IPHLPAPI.lib")
+#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "Userenv.lib")
#pragma comment(lib, "kernel32.lib")
@@ -513,37 +515,6 @@ int uv_get_process_title(char* buffer, size_t size) {
}
-/* https://github.com/libuv/libuv/issues/1674 */
-int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts) {
- FILETIME ft;
- int64_t t;
-
- if (ts == NULL)
- return UV_EFAULT;
-
- switch (clock_id) {
- case UV_CLOCK_MONOTONIC:
- uv__once_init();
- t = uv__hrtime(UV__NANOSEC);
- ts->tv_sec = t / 1000000000;
- ts->tv_nsec = t % 1000000000;
- return 0;
- case UV_CLOCK_REALTIME:
- GetSystemTimePreciseAsFileTime(&ft);
- /* In 100-nanosecond increments from 1601-01-01 UTC because why not? */
- t = (int64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
- /* Convert to UNIX epoch, 1970-01-01. Still in 100 ns increments. */
- t -= 116444736000000000ll;
- /* Now convert to seconds and nanoseconds. */
- ts->tv_sec = t / 10000000;
- ts->tv_nsec = t % 10000000 * 100;
- return 0;
- }
-
- return UV_EINVAL;
-}
-
-
uint64_t uv_hrtime(void) {
uv__once_init();
return uv__hrtime(UV__NANOSEC);

View File

@@ -29,7 +29,7 @@ def main():
"0007-Fix-Win32-warning-suppression-pragma.patch",
"0008-Use-C-atomics.patch",
"0009-Remove-static-from-array-indices.patch",
"0010-Remove-uv_clock_gettime-and-add-pragmas-for-missing-.patch",
"0010-Add-pragmas-for-missing-libraries-and-set-_WIN32_WIN.patch",
]:
git_am(os.path.join(wpilib_root, "upstream_utils/libuv_patches", f))

View File

@@ -1755,6 +1755,7 @@ UV_EXTERN uint64_t uv_get_total_memory(void);
UV_EXTERN uint64_t uv_get_constrained_memory(void);
UV_EXTERN uint64_t uv_get_available_memory(void);
UV_EXTERN int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts);
UV_EXTERN uint64_t uv_hrtime(void);
UV_EXTERN void uv_sleep(unsigned int msec);

View File

@@ -20,7 +20,7 @@
*/
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# define _WIN32_WINNT 0x0A00
#endif
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)

View File

@@ -515,6 +515,37 @@ int uv_get_process_title(char* buffer, size_t size) {
}
/* https://github.com/libuv/libuv/issues/1674 */
int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts) {
FILETIME ft;
int64_t t;
if (ts == NULL)
return UV_EFAULT;
switch (clock_id) {
case UV_CLOCK_MONOTONIC:
uv__once_init();
t = uv__hrtime(UV__NANOSEC);
ts->tv_sec = t / 1000000000;
ts->tv_nsec = t % 1000000000;
return 0;
case UV_CLOCK_REALTIME:
GetSystemTimePreciseAsFileTime(&ft);
/* In 100-nanosecond increments from 1601-01-01 UTC because why not? */
t = (int64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
/* Convert to UNIX epoch, 1970-01-01. Still in 100 ns increments. */
t -= 116444736000000000ll;
/* Now convert to seconds and nanoseconds. */
ts->tv_sec = t / 10000000;
ts->tv_nsec = t % 10000000 * 100;
return 0;
}
return UV_EINVAL;
}
uint64_t uv_hrtime(void) {
uv__once_init();
return uv__hrtime(UV__NANOSEC);