Commit 58f42007 authored by Nick Mathewson's avatar Nick Mathewson 🦞
Browse files

Thread support is now required

Long ago we supported systems where there was no support for
threads, or where the threading library was broken. We shouldn't
have do that any more: on every OS that matters, threads exist, and
the OS supports running threads across multiple CPUs.

This resolves tickets 9495 and 12439.  It's a prerequisite to making
our workqueue code work better, since sensible workqueue
implementations don't split across multiple processes.
parent 5b4ee475
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
  o Removed features:
    - Tor no longer supports systems without threading support.
      When we began working on Tor, there were several systems that didn't
      have threads, or where the thread support wasn't able to run the
      threads of a single process on multiple CPUs. That no longer holds:
      every system where Tor needs to run well now has threading support.
      Resolves ticket 12439.

  o Minor features:
    - Threads are no longer disabled by default on Solaris; we believe that
      the versions of Solaris with broken threading support are all obsolete
      by now. Resolves ticket 9495.
+3 −25
Original line number Diff line number Diff line
@@ -107,26 +107,6 @@ AC_ARG_ENABLE(upnp,
        * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
      esac], [upnp=false])


AC_ARG_ENABLE(threads,
     AS_HELP_STRING(--disable-threads, disable multi-threading support))

if test x$enable_threads = x; then
   case $host in
    *-*-solaris* )
     # Don't try multithreading on solaris -- cpuworkers seem to lock.
     AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
cpu workers lock up here, so I will disable threads.])
     enable_threads="no";;
    *)
     enable_threads="yes";;
   esac
fi

if test "$enable_threads" = "yes"; then
  AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
fi

case $host in
   *-*-solaris* )
     AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
@@ -326,10 +306,8 @@ if test "$LIBS" != "$saved_LIBS"; then
   have_rt=yes
fi

if test "$enable_threads" = "yes"; then
AC_SEARCH_LIBS(pthread_create, [pthread])
AC_SEARCH_LIBS(pthread_detach, [pthread])
fi

dnl -------------------------------------------------------------------
dnl Check for functions before libevent, since libevent-1.2 apparently
@@ -372,7 +350,7 @@ AC_CHECK_FUNCS(
	_vscprintf
)

if test "$enable_threads" = "yes"; then
if test "$bwin32" != true; then
  AC_CHECK_HEADERS(pthread.h)
  AC_CHECK_FUNCS(pthread_create)
fi
+1 −3
Original line number Diff line number Diff line
@@ -2722,7 +2722,7 @@ tor_gettimeofday(struct timeval *timeval)
  return;
}

#if defined(TOR_IS_MULTITHREADED) && !defined(_WIN32)
#if !defined(_WIN32)
/** Defined iff we need to add locks when defining fake versions of reentrant
 * versions of time-related functions. */
#define TIME_FNS_NEED_LOCKS
@@ -2982,7 +2982,6 @@ tor_get_thread_id(void)
}
#endif

#ifdef TOR_IS_MULTITHREADED
/** Return a newly allocated, ready-for-use mutex. */
tor_mutex_t *
tor_mutex_new(void)
@@ -3000,7 +2999,6 @@ tor_mutex_free(tor_mutex_t *m)
  tor_mutex_uninit(m);
  tor_free(m);
}
#endif

/* Conditions. */
#ifdef USE_PTHREADS
+3 −19
Original line number Diff line number Diff line
@@ -633,15 +633,12 @@ int get_total_system_memory(size_t *mem_out);
int spawn_func(void (*func)(void *), void *data);
void spawn_exit(void) ATTR_NORETURN;

#if defined(ENABLE_THREADS) && defined(_WIN32)
#if defined(_WIN32)
#define USE_WIN32_THREADS
#define TOR_IS_MULTITHREADED 1
#elif (defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) && \
       defined(HAVE_PTHREAD_CREATE))
#elif defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_CREATE)
#define USE_PTHREADS
#define TOR_IS_MULTITHREADED 1
#else
#undef TOR_IS_MULTITHREADED
#error "No threading system was found"
#endif

int compute_num_cpus(void);
@@ -667,7 +664,6 @@ typedef struct tor_mutex_t {

int tor_mlockall(void);

#ifdef TOR_IS_MULTITHREADED
tor_mutex_t *tor_mutex_new(void);
void tor_mutex_init(tor_mutex_t *m);
void tor_mutex_acquire(tor_mutex_t *m);
@@ -676,21 +672,10 @@ void tor_mutex_free(tor_mutex_t *m);
void tor_mutex_uninit(tor_mutex_t *m);
unsigned long tor_get_thread_id(void);
void tor_threads_init(void);
#else
#define tor_mutex_new() ((tor_mutex_t*)tor_malloc(sizeof(int)))
#define tor_mutex_init(m) STMT_NIL
#define tor_mutex_acquire(m) STMT_VOID(m)
#define tor_mutex_release(m) STMT_NIL
#define tor_mutex_free(m) STMT_BEGIN tor_free(m); STMT_END
#define tor_mutex_uninit(m) STMT_NIL
#define tor_get_thread_id() (1UL)
#define tor_threads_init() STMT_NIL
#endif

void set_main_thread(void);
int in_main_thread(void);

#ifdef TOR_IS_MULTITHREADED
#if 0
typedef struct tor_cond_t tor_cond_t;
tor_cond_t *tor_cond_new(void);
@@ -699,7 +684,6 @@ int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex);
void tor_cond_signal_one(tor_cond_t *cond);
void tor_cond_signal_all(tor_cond_t *cond);
#endif
#endif

/** Macros for MIN/MAX.  Never use these when the arguments could have
 * side-effects.
+2 −13
Original line number Diff line number Diff line
@@ -75,12 +75,10 @@
/** Macro: is k a valid RSA private key? */
#define PRIVATE_KEY_OK(k) ((k) && (k)->key && (k)->key->p)

#ifdef TOR_IS_MULTITHREADED
/** A number of preallocated mutexes for use by OpenSSL. */
static tor_mutex_t **openssl_mutexes_ = NULL;
/** How many mutexes have we allocated for use by OpenSSL? */
static int n_openssl_mutexes_ = 0;
#endif

/** A public key, or a public/private key-pair. */
struct crypto_pk_t
@@ -3090,8 +3088,6 @@ memwipe(void *mem, uint8_t byte, size_t sz)
  memset(mem, byte, sz);
}

#ifdef TOR_IS_MULTITHREADED

#ifndef OPENSSL_THREADS
#error OpenSSL has been built without thread support. Tor requires an \
 OpenSSL library with thread support enabled.
@@ -3178,13 +3174,6 @@ setup_openssl_threading(void)
  CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy_cb_);
  return 0;
}
#else
static int
setup_openssl_threading(void)
{
  return 0;
}
#endif

/** Uninitialize the crypto library. Return 0 on success, -1 on failure.
 */
@@ -3208,7 +3197,7 @@ crypto_global_cleanup(void)

  CONF_modules_unload(1);
  CRYPTO_cleanup_all_ex_data();
#ifdef TOR_IS_MULTITHREADED

  if (n_openssl_mutexes_) {
    int n = n_openssl_mutexes_;
    tor_mutex_t **ms = openssl_mutexes_;
@@ -3220,7 +3209,7 @@ crypto_global_cleanup(void)
    }
    tor_free(ms);
  }
#endif

  tor_free(crypto_openssl_version_str);
  tor_free(crypto_openssl_header_version_str);
  return 0;
Loading