Off-by-one error when calculating tv_nsec.

When calling pthread_cond_timedwait, tv_nsec must not equal or exceed
10e9, as this will immediately make pthread_cond_timedwait return
EINVAL. Several of the conditional wait loops check for ETIMEDOUT but
not EINVAL, which means that this causes infinite loops in some rare
cases.

Basically, this happens in only one in a billion cases, but over the
past few days I've had it happen quite a few times.