diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-01-21 12:18:11 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-21 12:18:11 -0500 |
commit | ac5b70c700b211008853b5f212100a867f508dfd (patch) | |
tree | 53e83027711dd6f7dd4328a960efc615294dc926 /src/common/compat_pthreads.c | |
parent | a52e549124adb09ad0b49b7d2b5b3fb79bfe7aeb (diff) | |
download | tor-ac5b70c700b211008853b5f212100a867f508dfd.tar.gz tor-ac5b70c700b211008853b5f212100a867f508dfd.zip |
handle EINTR in compat_*threads.c
Diffstat (limited to 'src/common/compat_pthreads.c')
-rw-r--r-- | src/common/compat_pthreads.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index f43480539f..188a91f68d 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -196,23 +196,37 @@ tor_cond_uninit(tor_cond_t *cond) int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex, const struct timeval *tv) { + int r; if (tv == NULL) { - return pthread_cond_wait(&cond->cond, &mutex->mutex) ? -1 : 0; + while (1) { + r = pthread_cond_wait(&cond->cond, &mutex->mutex); + if (r == EINTR) { + /* EINTR should be impossible according to POSIX, but POSIX, like the + * Pirate's Code, is apparently treated "more like what you'd call + * guidelines than actual rules." */ + continue; + } + return r ? -1 : 0; + } } else { struct timespec ts; struct timeval tvnow, tvsum; - int r; - gettimeofday(&tvnow, NULL); - timeradd(tv, &tvnow, &tvsum); - ts.tv_sec = tvsum.tv_sec; - ts.tv_nsec = tvsum.tv_usec * 1000; - r = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &ts); - if (r == 0) - return 0; - else if (r == ETIMEDOUT) - return 1; - else - return -1; + while (1) { + gettimeofday(&tvnow, NULL); + timeradd(tv, &tvnow, &tvsum); + ts.tv_sec = tvsum.tv_sec; + ts.tv_nsec = tvsum.tv_usec * 1000; + + r = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &ts); + if (r == 0) + return 0; + else if (r == ETIMEDOUT) + return 1; + else if (r == EINTR) + continue; + else + return -1; + } } } /** Wake up one of the waiters on <b>cond</b>. */ |