r15304@tombo: nickm | 2008-04-23 16:31:40 -0400

Forward-port: I had apparently broken OSX and Freebsd by not initializing threading before we initialize the logging system.  This patch should do so, and fix bug 671.


svn:r14430
This commit is contained in:
Nick Mathewson
2008-04-23 20:32:31 +00:00
parent 5dc8062afa
commit 05b184de01
3 changed files with 10 additions and 6 deletions
+8 -4
View File
@@ -1736,12 +1736,15 @@ struct tor_mutex_t {
pthread_mutex_t mutex;
};
static pthread_mutexattr_t attr_reentrant;
static int threads_initialized = 0;
/** Allocate and return new lock. */
tor_mutex_t *
tor_mutex_new(void)
{
int err;
tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t));
if (PREDICT_UNLIKELY(!threads_initialized))
tor_threads_init();
err = pthread_mutex_init(&mutex->mutex, &attr_reentrant);
if (PREDICT_UNLIKELY(err)) {
log_err(LD_GENERAL, "Error %d creating a mutex.", err);
@@ -1858,10 +1861,11 @@ tor_cond_signal_all(tor_cond_t *cond)
void
tor_threads_init(void)
{
#ifdef USE_PTHREADS
pthread_mutexattr_init(&attr_reentrant);
pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
#endif
if (!threads_initialized) {
pthread_mutexattr_init(&attr_reentrant);
pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
threads_initialized = 1;
}
}
#elif defined(USE_WIN32_THREADS)
#if 0
+1 -2
View File
@@ -1781,8 +1781,6 @@ tor_init(int argc, char *argv[])
/* Have the log set up with our application name. */
tor_snprintf(buf, sizeof(buf), "Tor %s", get_version());
log_set_application_name(buf);
/* Initialize threading. */
tor_threads_init();
/* Initialize the history structures. */
rep_hist_init();
/* Initialize the service cache. */
@@ -1988,6 +1986,7 @@ int
tor_main(int argc, char *argv[])
{
int result = 0;
tor_threads_init();
init_logging();
#ifdef USE_DMALLOC
int r = CRYPTO_set_mem_ex_functions(_tor_malloc, _tor_realloc,
+1
View File
@@ -3991,6 +3991,7 @@ main(int c, char**v)
int verbose = 0, any_selected = 0;
int loglevel = LOG_ERR;
tor_threads_init();
init_logging();
for (i = 1; i < c; ++i) {