Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

win: make uv_hrtime() thread-safe

  • Loading branch information...
piscisaureus committed Sep 11, 2011
1 parent 2c96ad2 commit c5a489b01cb0a5c643c4f517de143b39b66f98f7
Showing with 15 additions and 15 deletions.
  1. +15 −15 src/win/timer.c
@@ -33,7 +33,7 @@
/* The resolution of the high-resolution clock. */
static int64_t uv_ticks_per_msec_ = 0;
static uint64_t uv_hrtime_frequency_ = 0;
static char uv_hrtime_initialized_ = 0;
static uv_once_t uv_hrtime_init_guard_ = UV_ONCE_INIT;


void uv_update_time(uv_loop_t* loop) {
@@ -57,24 +57,24 @@ int64_t uv_now(uv_loop_t* loop) {
return loop->time;
}

/* TODO: thread safety */
uint64_t uv_hrtime(void) {
LARGE_INTEGER counter;

/* When called for the first time, obtain the high-resolution clock */
/* frequency. */
if (!uv_hrtime_initialized_) {
uv_hrtime_initialized_ = 1;

if (!QueryPerformanceFrequency(&counter)) {
uv_hrtime_frequency_ = 0;
/* uv_set_sys_error(loop, GetLastError()); */
return 0;
}
static void uv_hrtime_init(void) {
LARGE_INTEGER frequency;

uv_hrtime_frequency_ = counter.QuadPart;
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); */

0 comments on commit c5a489b

Please sign in to comment.
You can’t perform that action at this time.