|
@@ -2076,6 +2076,7 @@ tor_threads_init(void)
|
|
|
pthread_mutexattr_init(&attr_reentrant);
|
|
|
pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
|
|
|
threads_initialized = 1;
|
|
|
+ set_main_thread();
|
|
|
}
|
|
|
}
|
|
|
#elif defined(USE_WIN32_THREADS)
|
|
@@ -2168,9 +2169,27 @@ tor_threads_init(void)
|
|
|
#if 0
|
|
|
cond_event_tls_index = TlsAlloc();
|
|
|
#endif
|
|
|
+ set_main_thread();
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
+static unsigned long main_thread_id = -1;
|
|
|
+
|
|
|
+
|
|
|
+ * no effect on anything besides in_main_thread(). */
|
|
|
+void
|
|
|
+set_main_thread(void)
|
|
|
+{
|
|
|
+ main_thread_id = tor_get_thread_id();
|
|
|
+}
|
|
|
+
|
|
|
+int
|
|
|
+in_main_thread(void)
|
|
|
+{
|
|
|
+ return main_thread_id == tor_get_thread_id();
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
* On Windows, WSAEWOULDBLOCK is not always correct: when you see it,
|
|
|
* you need to ask the socket for its actual errno. Also, you need to
|