windows: move uv_hrtime() to util.c
* It has nothing to do with timer handles, so it doesn't belong in timer.c * uv_hrtime_init() was merged into uv__util_init()
This commit is contained in:
parent
ec95a07d00
commit
d21fc6c333
@ -27,15 +27,6 @@
|
||||
#include "tree.h"
|
||||
|
||||
|
||||
#undef NANOSEC
|
||||
#define NANOSEC 1000000000
|
||||
|
||||
|
||||
/* The resolution of the high-resolution clock. */
|
||||
static uint64_t uv_hrtime_frequency_ = 0;
|
||||
static uv_once_t uv_hrtime_init_guard_ = UV_ONCE_INIT;
|
||||
|
||||
|
||||
void uv_update_time(uv_loop_t* loop) {
|
||||
DWORD ticks = GetTickCount();
|
||||
|
||||
@ -58,43 +49,6 @@ int64_t uv_now(uv_loop_t* loop) {
|
||||
}
|
||||
|
||||
|
||||
static void uv_hrtime_init(void) {
|
||||
LARGE_INTEGER frequency;
|
||||
|
||||
if (!QueryPerformanceFrequency(&frequency)) {
|
||||
uv_hrtime_frequency_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uv_hrtime_frequency_ = frequency.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
LARGE_INTEGER counter;
|
||||
|
||||
uv_once(&uv_hrtime_init_guard_, uv_hrtime_init);
|
||||
|
||||
/* If the performance frequency is zero, there's no support. */
|
||||
if (!uv_hrtime_frequency_) {
|
||||
/* uv__set_sys_error(loop, ERROR_NOT_SUPPORTED); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!QueryPerformanceCounter(&counter)) {
|
||||
/* uv__set_sys_error(loop, GetLastError()); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Because we have no guarantee about the order of magnitude of the */
|
||||
/* performance counter frequency, and there may not be much headroom to */
|
||||
/* multiply by NANOSEC without overflowing, we use 128-bit math instead. */
|
||||
return ((uint64_t) counter.LowPart * NANOSEC / uv_hrtime_frequency_) +
|
||||
(((uint64_t) counter.HighPart * NANOSEC / uv_hrtime_frequency_)
|
||||
<< 32);
|
||||
}
|
||||
|
||||
|
||||
static int uv_timer_compare(uv_timer_t* a, uv_timer_t* b) {
|
||||
if (a->due < b->due)
|
||||
return -1;
|
||||
|
||||
@ -47,11 +47,18 @@
|
||||
*/
|
||||
#define MAX_TITLE_LENGTH 8192
|
||||
|
||||
/* The number of nanoseconds in one second. */
|
||||
#undef NANOSEC
|
||||
#define NANOSEC 1000000000
|
||||
|
||||
|
||||
/* Cached copy of the process title, plus a mutex guarding it. */
|
||||
static char *process_title;
|
||||
static CRITICAL_SECTION process_title_lock;
|
||||
|
||||
/* The tick frequency of the high-resolution clock. */
|
||||
static uint64_t hrtime_frequency_ = 0;
|
||||
|
||||
|
||||
/*
|
||||
* One-time intialization code for functionality defined in util.c.
|
||||
@ -59,6 +66,10 @@ static CRITICAL_SECTION process_title_lock;
|
||||
void uv__util_init() {
|
||||
/* Initialize process title access mutex. */
|
||||
InitializeCriticalSection(&process_title_lock);
|
||||
|
||||
/* Retrieve high-resolution timer frequency. */
|
||||
if (!QueryPerformanceFrequency((LARGE_INTEGER*) &hrtime_frequency_))
|
||||
hrtime_frequency_ = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -375,6 +386,31 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
LARGE_INTEGER counter;
|
||||
|
||||
uv__once_init();
|
||||
|
||||
/* If the performance frequency is zero, there's no support. */
|
||||
if (!hrtime_frequency_) {
|
||||
/* uv__set_sys_error(loop, ERROR_NOT_SUPPORTED); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!QueryPerformanceCounter(&counter)) {
|
||||
/* uv__set_sys_error(loop, GetLastError()); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Because we have no guarantee about the order of magnitude of the */
|
||||
/* performance counter frequency, and there may not be much headroom to */
|
||||
/* multiply by NANOSEC without overflowing, we use 128-bit math instead. */
|
||||
return ((uint64_t) counter.LowPart * NANOSEC / hrtime_frequency_) +
|
||||
(((uint64_t) counter.HighPart * NANOSEC / hrtime_frequency_)
|
||||
<< 32);
|
||||
}
|
||||
|
||||
|
||||
uv_err_t uv_resident_set_memory(size_t* rss) {
|
||||
HANDLE current_process;
|
||||
PROCESS_MEMORY_COUNTERS pmc;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user