unix,win: introduce uv_timeval64_t

Fixes: https://github.com/libuv/libuv/issues/2243
PR-URL: https://github.com/libuv/libuv/pull/2246
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
cjihrig 2019-04-07 20:09:03 -04:00
parent 38bb0f5f5f
commit 2e090c8f2c
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
5 changed files with 14 additions and 9 deletions

View File

@ -579,7 +579,7 @@ API
.. versionadded:: 1.25.0 .. versionadded:: 1.25.0
.. c:function:: int uv_gettimeofday(uv_timeval_t* tv) .. c:function:: int uv_gettimeofday(uv_timeval64_t* tv)
Cross-platform implementation of :man:`gettimeofday(2)`. The timezone Cross-platform implementation of :man:`gettimeofday(2)`. The timezone
argument to `gettimeofday()` is not supported, as it is considered obsolete. argument to `gettimeofday()` is not supported, as it is considered obsolete.

View File

@ -1099,6 +1099,11 @@ typedef struct {
long tv_usec; long tv_usec;
} uv_timeval_t; } uv_timeval_t;
typedef struct {
int64_t tv_sec;
int32_t tv_usec;
} uv_timeval64_t;
typedef struct { typedef struct {
uv_timeval_t ru_utime; /* user CPU time used */ uv_timeval_t ru_utime; /* user CPU time used */
uv_timeval_t ru_stime; /* system CPU time used */ uv_timeval_t ru_stime; /* system CPU time used */
@ -1609,7 +1614,7 @@ UV_EXTERN void uv_key_delete(uv_key_t* key);
UV_EXTERN void* uv_key_get(uv_key_t* key); UV_EXTERN void* uv_key_get(uv_key_t* key);
UV_EXTERN void uv_key_set(uv_key_t* key, void* value); UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
UV_EXTERN int uv_gettimeofday(uv_timeval_t* tv); UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
typedef void (*uv_thread_cb)(void* arg); typedef void (*uv_thread_cb)(void* arg);

View File

@ -1431,7 +1431,7 @@ int uv__getsockpeername(const uv_handle_t* handle,
return 0; return 0;
} }
int uv_gettimeofday(uv_timeval_t* tv) { int uv_gettimeofday(uv_timeval64_t* tv) {
struct timeval time; struct timeval time;
if (tv == NULL) if (tv == NULL)
@ -1440,7 +1440,7 @@ int uv_gettimeofday(uv_timeval_t* tv) {
if (gettimeofday(&time, NULL) != 0) if (gettimeofday(&time, NULL) != 0)
return UV__ERR(errno); return UV__ERR(errno);
tv->tv_sec = time.tv_sec; tv->tv_sec = (int64_t) time.tv_sec;
tv->tv_usec = time.tv_usec; tv->tv_usec = (int32_t) time.tv_usec;
return 0; return 0;
} }

View File

@ -1779,7 +1779,7 @@ error:
return r; return r;
} }
int uv_gettimeofday(uv_timeval_t* tv) { int uv_gettimeofday(uv_timeval64_t* tv) {
/* Based on https://doxygen.postgresql.org/gettimeofday_8c_source.html */ /* Based on https://doxygen.postgresql.org/gettimeofday_8c_source.html */
const uint64_t epoch = (uint64_t) 116444736000000000ULL; const uint64_t epoch = (uint64_t) 116444736000000000ULL;
FILETIME file_time; FILETIME file_time;
@ -1791,7 +1791,7 @@ int uv_gettimeofday(uv_timeval_t* tv) {
GetSystemTimeAsFileTime(&file_time); GetSystemTimeAsFileTime(&file_time);
ularge.LowPart = file_time.dwLowDateTime; ularge.LowPart = file_time.dwLowDateTime;
ularge.HighPart = file_time.dwHighDateTime; ularge.HighPart = file_time.dwHighDateTime;
tv->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); tv->tv_sec = (int64_t) ((ularge.QuadPart - epoch) / 10000000L);
tv->tv_usec = (long) (((ularge.QuadPart - epoch) % 10000000L) / 10); tv->tv_usec = (int32_t) (((ularge.QuadPart - epoch) % 10000000L) / 10);
return 0; return 0;
} }

View File

@ -23,7 +23,7 @@
#include "task.h" #include "task.h"
TEST_IMPL(gettimeofday) { TEST_IMPL(gettimeofday) {
uv_timeval_t tv; uv_timeval64_t tv;
int r; int r;
tv.tv_sec = 0; tv.tv_sec = 0;