Merge branch 'osx_sierra_028'

This commit is contained in:
Nick Mathewson 2016-09-24 13:33:09 -07:00
commit a633baf632
4 changed files with 20 additions and 6 deletions

3
changes/ticket20241 Normal file
View File

@ -0,0 +1,3 @@
o Minor features (compilation, portability):
- Tor now compiles correctly on MacOS 10.12 (aka "Sierra"). Closes
ticket 20241.

View File

@ -999,6 +999,7 @@ AC_CHECK_HEADERS([assert.h \
sys/mman.h \ sys/mman.h \
sys/param.h \ sys/param.h \
sys/prctl.h \ sys/prctl.h \
sys/random.h \
sys/resource.h \ sys/resource.h \
sys/select.h \ sys/select.h \
sys/socket.h \ sys/socket.h \

View File

@ -200,14 +200,21 @@ tor_cond_init(tor_cond_t *cond)
return -1; return -1;
} }
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) \ #if defined(HAVE_CLOCK_GETTIME)
&& defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) #if defined(CLOCK_MONOTONIC) && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK)
/* Use monotonic time so when we timedwait() on it, any clock adjustment /* Use monotonic time so when we timedwait() on it, any clock adjustment
* won't affect the timeout value. */ * won't affect the timeout value. */
if (pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)) { if (pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)) {
return -1; return -1;
} }
#endif #define USE_COND_CLOCK CLOCK_MONOTONIC
#else /* !defined HAVE_PTHREAD_CONDATTR_SETCLOCK */
/* On OSX Sierra, there is no pthread_condattr_setclock, so we are stuck
* with the realtime clock.
*/
#define USE_COND_CLOCK CLOCK_REALTIME
#endif /* which clock to use */
#endif /* HAVE_CLOCK_GETTIME */
if (pthread_cond_init(&cond->cond, &condattr)) { if (pthread_cond_init(&cond->cond, &condattr)) {
return -1; return -1;
} }
@ -252,12 +259,12 @@ tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex, const struct timeval *tv)
struct timeval tvnow, tvsum; struct timeval tvnow, tvsum;
struct timespec ts; struct timespec ts;
while (1) { while (1) {
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) #if defined(HAVE_CLOCK_GETTIME) && defined(USE_COND_CLOCK)
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { if (clock_gettime(USE_COND_CLOCK, &ts) < 0) {
return -1; return -1;
} }
tvnow.tv_sec = ts.tv_sec; tvnow.tv_sec = ts.tv_sec;
tvnow.tv_usec = ts.tv_nsec / 1000; tvnow.tv_usec = (int)(ts.tv_nsec / 1000);
timeradd(tv, &tvnow, &tvsum); timeradd(tv, &tvnow, &tvsum);
#else #else
if (gettimeofday(&tvnow, NULL) < 0) if (gettimeofday(&tvnow, NULL) < 0)

View File

@ -67,6 +67,9 @@ ENABLE_GCC_WARNING(redundant-decls)
#ifdef HAVE_SYS_SYSCALL_H #ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h> #include <sys/syscall.h>
#endif #endif
#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
#include "torlog.h" #include "torlog.h"
#include "torint.h" #include "torint.h"