diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-27 20:45:07 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-27 20:45:07 -0800 |
| commit | f10feb5b243b979e554db87ef07bcd10786474c2 (patch) | |
| tree | 7fdc7ff2536c10c7db9747667bf9e5eab71d18cd /src/platform/posix/posix_synch.c | |
| parent | ca74e80e9b0695a1c374840058025e567189dd14 (diff) | |
| download | nng-f10feb5b243b979e554db87ef07bcd10786474c2.tar.gz nng-f10feb5b243b979e554db87ef07bcd10786474c2.tar.bz2 nng-f10feb5b243b979e554db87ef07bcd10786474c2.zip | |
Condvars on MacOS X (even 10.12) don't work with monotonic times.
Diffstat (limited to 'src/platform/posix/posix_synch.c')
| -rw-r--r-- | src/platform/posix/posix_synch.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c index 0526eb7c..d9fed53f 100644 --- a/src/platform/posix/posix_synch.c +++ b/src/platform/posix/posix_synch.c @@ -121,17 +121,28 @@ nni_cond_wait(nni_cond *c) int -nni_cond_waituntil(nni_cond *c, uint64_t usec) +nni_cond_waituntil(nni_cond *c, nni_time usec) { struct timespec ts; int rv; + nni_duration delta = usec - nni_clock(); - ts.tv_sec = usec / 1000000; - ts.tv_nsec = (usec % 1000000) * 1000; - rv = pthread_cond_timedwait(&c->cv, c->mx, &ts); + if (usec != NNI_TIME_NEVER) { + ts.tv_sec = usec / 1000000; + ts.tv_nsec = (usec % 1000000) * 1000; + + rv = pthread_cond_timedwait(&c->cv, c->mx, &ts); + } else { + rv = pthread_cond_wait(&c->cv, c->mx); + } if (rv == ETIMEDOUT) { + if (nni_clock() < usec) { + // This only happens if the implementation + // is buggy. + nni_panic("Premature wakupe!"); + } return (NNG_ETIMEDOUT); } else if (rv != 0) { nni_panic("pthread_cond_timedwait returned %d", rv); |
