|
|
@ -108,6 +108,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) { |
|
|
|
now.clock_type = clock; |
|
|
|
now.clock_type = clock; |
|
|
|
switch (clock) { |
|
|
|
switch (clock) { |
|
|
|
case GPR_CLOCK_REALTIME: |
|
|
|
case GPR_CLOCK_REALTIME: |
|
|
|
|
|
|
|
// gettimeofday(...) function may return with a value whose tv_usec is
|
|
|
|
|
|
|
|
// greater than 1e6 on iOS The case is resolved with the guard at end of
|
|
|
|
|
|
|
|
// this function.
|
|
|
|
gettimeofday(&now_tv, nullptr); |
|
|
|
gettimeofday(&now_tv, nullptr); |
|
|
|
now.tv_sec = now_tv.tv_sec; |
|
|
|
now.tv_sec = now_tv.tv_sec; |
|
|
|
now.tv_nsec = now_tv.tv_usec * 1000; |
|
|
|
now.tv_nsec = now_tv.tv_usec * 1000; |
|
|
@ -124,6 +127,16 @@ static gpr_timespec now_impl(gpr_clock_type clock) { |
|
|
|
abort(); |
|
|
|
abort(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Guard the tv_nsec field in valid range for all clock types
|
|
|
|
|
|
|
|
while (GPR_UNLIKELY(now.tv_nsec >= 1e9)) { |
|
|
|
|
|
|
|
now.tv_sec++; |
|
|
|
|
|
|
|
now.tv_nsec -= 1e9; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while (GPR_UNLIKELY(now.tv_nsec < 0)) { |
|
|
|
|
|
|
|
now.tv_sec--; |
|
|
|
|
|
|
|
now.tv_nsec += 1e9; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return now; |
|
|
|
return now; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|