diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index f221cb57903..539470bccfe 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -39,6 +39,7 @@ #include #include +#include gpr_timespec gpr_now(void) { gpr_timespec now_tv; @@ -49,4 +50,23 @@ gpr_timespec gpr_now(void) { return now_tv; } +void gpr_sleep_until(gpr_timespec until) { + gpr_timespec now; + gpr_timespec delta; + DWORD sleep_millis; + + for (;;) { + /* We could simplify by using clock_nanosleep instead, but it might be + * slightly less portable. */ + now = gpr_now(); + if (gpr_time_cmp(until, now) <= 0) { + return; + } + + delta = gpr_time_sub(until, now); + sleep_millis = delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; + Sleep(sleep_millis); + } +} + #endif /* GPR_WIN32 */