diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-04-08 09:58:14 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-04-08 09:58:14 -0700 |
commit | 818efa6741d33fed9a9ecbb03d5df8ec1112683c (patch) | |
tree | c91de92783cda0a70e03e96d53fe6e121b542809 /src | |
parent | c3d5f16d7577c3b3273c24342462e61387442e31 (diff) |
Implement gpr_sleep_until for Windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/support/time_win32.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index f221cb5790..539470bccf 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -39,6 +39,7 @@ #include <grpc/support/time.h> #include <sys/timeb.h> +#include <windows.h> 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 */ |