Skip to content

Commit

Permalink
[upstream_utils] Revert removal of uv_clock_gettime()
Browse files Browse the repository at this point in the history
GetSystemTimePreciseAsFileTime() is supposed to be available, and
wpiutil already uses it.
  • Loading branch information
calcmogul committed Oct 3, 2023
1 parent 4831277 commit 420c5e1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <[email protected]>
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

See
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")

This file was deleted.

2 changes: 1 addition & 1 deletion upstream_utils/update_libuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions wpinet/src/main/native/thirdparty/libuv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion wpinet/src/main/native/thirdparty/libuv/include/uv/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# define _WIN32_WINNT 0x0A00
#endif

#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
Expand Down
31 changes: 31 additions & 0 deletions wpinet/src/main/native/thirdparty/libuv/src/win/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 420c5e1

Please sign in to comment.