Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
win: make uv_hrtime() thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Sep 11, 2011
1 parent 2c96ad2 commit c5a489b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/win/timer.c
Expand Up @@ -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) {
Expand All @@ -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); */
Expand Down

0 comments on commit c5a489b

Please sign in to comment.