void gpr_sleep_until(gpr_timespec until) { gpr_timespec now; gpr_timespec delta; struct timespec delta_ts; for (;;) { /* We could simplify by using clock_nanosleep instead, but it might be * slightly less portable. */ now = gpr_now(GPR_CLOCK_REALTIME); if (gpr_time_cmp(until, now) <= 0) { return; } delta = gpr_time_sub(until, now); delta_ts = timespec_from_gpr(delta); if (nanosleep(&delta_ts, NULL) == 0) { break; } } }
void gpr_sleep_until(gpr_timespec until) { gpr_timespec now; gpr_timespec delta; struct timespec delta_ts; int ns_result; for (;;) { /* We could simplify by using clock_nanosleep instead, but it might be * slightly less portable. */ now = gpr_now(until.clock_type); if (gpr_time_cmp(until, now) <= 0) { return; } delta = gpr_time_sub(until, now); delta_ts = timespec_from_gpr(delta); GRPC_SCHEDULING_START_BLOCKING_REGION; ns_result = nanosleep(&delta_ts, NULL); GRPC_SCHEDULING_END_BLOCKING_REGION; if (ns_result == 0) { break; } } }