HG util: avoid hg_time_get_current() calls when the ms timeout is 0
@@ -108,11 +108,13 @@ int
hg_request_wait(
hg_request_t *request, unsigned int timeout_ms, unsigned int *flag)
{
- hg_time_t deadline, now, remaining = hg_time_from_ms(timeout_ms);
+ hg_time_t deadline, remaining = hg_time_from_ms(timeout_ms);
+ hg_time_t now = hg_time_from_ms(0);
hg_util_int32_t completed = HG_UTIL_FALSE;
int ret = HG_UTIL_SUCCESS;
- hg_time_get_current_ms(&now);
+ if (timeout_ms != 0)
+ hg_time_get_current(&now);
deadline = hg_time_add(now, remaining);
do {
@@ -150,6 +152,7 @@ hg_request_wait(
hg_thread_mutex_unlock(&request->request_class->progress_mutex);
next:
+ if (timeout_ms != 0)
hg_time_get_current(&now);
remaining = hg_time_subtract(deadline, now);
} while (hg_time_less(now, deadline));
