diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-28 09:14:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-28 09:14:42 -0400 |
commit | 9cf335c9a5fe6767e90cc5cfdc1f5c95465edb10 (patch) | |
tree | 04e771dcb1c0c577b221a5a4f4b11ffa677972af | |
parent | 544ab27a949406628809869111b7288017a5bcb1 (diff) | |
download | tor-9cf335c9a5fe6767e90cc5cfdc1f5c95465edb10.tar.gz tor-9cf335c9a5fe6767e90cc5cfdc1f5c95465edb10.zip |
Extract threading code into a new library.
Note that the workqueue code does *not* go here: it is logically at
a higher level, since it needs to use libevent and the networking
stack.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/common/compat.h | 2 | ||||
-rw-r--r-- | src/common/include.am | 10 | ||||
-rw-r--r-- | src/common/workqueue.c | 2 | ||||
-rw-r--r-- | src/include.am | 1 | ||||
-rw-r--r-- | src/lib/thread/.may_include | 6 | ||||
-rw-r--r-- | src/lib/thread/compat_pthreads.c (renamed from src/common/compat_pthreads.c) | 11 | ||||
-rw-r--r-- | src/lib/thread/compat_threads.c (renamed from src/common/compat_threads.c) | 5 | ||||
-rw-r--r-- | src/lib/thread/compat_winthreads.c (renamed from src/common/compat_winthreads.c) | 5 | ||||
-rw-r--r-- | src/lib/thread/include.am | 25 | ||||
-rw-r--r-- | src/lib/thread/threads.h (renamed from src/common/compat_threads.h) | 2 | ||||
-rw-r--r-- | src/rust/build.rs | 1 | ||||
-rw-r--r-- | src/test/test_threads.c | 2 | ||||
-rw-r--r-- | src/test/test_workqueue.c | 2 |
15 files changed, 55 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore index 5198daf4f4..65c9fb83fc 100644 --- a/.gitignore +++ b/.gitignore @@ -195,6 +195,8 @@ uptime-*.json /src/lib/libtor-string-testing.a /src/lib/libtor-smartlist-core.a /src/lib/libtor-smartlist-core-testing.a +/src/lib/libtor-thread.a +/src/lib/libtor-thread-testing.a /src/lib/libtor-tls.a /src/lib/libtor-tls-testing.a /src/lib/libtor-trace.a diff --git a/Makefile.am b/Makefile.am index c016310a68..be645194aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,6 +45,7 @@ TOR_UTIL_LIBS = \ src/lib/libtor-sandbox.a \ src/lib/libtor-container.a \ src/lib/libtor-net.a \ + src/lib/libtor-thread.a \ src/lib/libtor-log.a \ src/lib/libtor-lock.a \ src/lib/libtor-fdio.a \ @@ -65,6 +66,7 @@ TOR_UTIL_TESTING_LIBS = \ src/lib/libtor-sandbox-testing.a \ src/lib/libtor-container-testing.a \ src/lib/libtor-net-testing.a \ + src/lib/libtor-thread-testing.a \ src/lib/libtor-log-testing.a \ src/lib/libtor-lock-testing.a \ src/lib/libtor-fdio-testing.a \ diff --git a/src/common/compat.h b/src/common/compat.h index 95447d3b84..574dc57201 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -190,6 +190,6 @@ int tor_mlockall(void); ssize_t tor_getpass(const char *prompt, char *output, size_t buflen); /* This needs some of the declarations above so we include it here. */ -#include "common/compat_threads.h" +#include "lib/thread/threads.h" #endif /* !defined(TOR_COMPAT_H) */ diff --git a/src/common/include.am b/src/common/include.am index 14e7dcb9fc..9ed5b30d3a 100644 --- a/src/common/include.am +++ b/src/common/include.am @@ -17,13 +17,6 @@ else libor_extra_source= endif -if THREADS_PTHREADS -threads_impl_source=src/common/compat_pthreads.c -endif -if THREADS_WIN32 -threads_impl_source=src/common/compat_winthreads.c -endif - if BUILD_READPASSPHRASE_C readpassphrase_source=src/ext/readpassphrase.c else @@ -34,7 +27,6 @@ LIBOR_A_SRC = \ src/common/address_set.c \ src/common/buffers.c \ src/common/compat.c \ - src/common/compat_threads.c \ src/common/compat_time.c \ src/common/conffile.c \ src/common/memarea.c \ @@ -44,7 +36,6 @@ LIBOR_A_SRC = \ src/common/token_bucket.c \ src/common/workqueue.c \ $(libor_extra_source) \ - $(threads_impl_source) \ $(readpassphrase_source) src/common/src_common_libor_testing_a-log.$(OBJEXT) \ @@ -77,7 +68,6 @@ COMMONHEADERS = \ src/common/buffers.h \ src/common/compat.h \ src/common/compat_libevent.h \ - src/common/compat_threads.h \ src/common/compat_time.h \ src/common/conffile.h \ src/common/handles.h \ diff --git a/src/common/workqueue.c b/src/common/workqueue.c index fd31ccd7fd..4735aadd73 100644 --- a/src/common/workqueue.c +++ b/src/common/workqueue.c @@ -26,7 +26,7 @@ #include "orconfig.h" #include "common/compat.h" #include "common/compat_libevent.h" -#include "common/compat_threads.h" +#include "lib/thread/threads.h" #include "lib/crypt_ops/crypto_rand.h" #include "common/util.h" #include "common/workqueue.h" diff --git a/src/include.am b/src/include.am index c83ec0d579..0a8af38b02 100644 --- a/src/include.am +++ b/src/include.am @@ -20,6 +20,7 @@ include src/lib/sandbox/include.am include src/lib/string/include.am include src/lib/smartlist_core/include.am include src/lib/testsupport/include.am +include src/lib/thread/include.am include src/lib/tls/include.am include src/lib/trace/include.am include src/lib/wallclock/include.am diff --git a/src/lib/thread/.may_include b/src/lib/thread/.may_include new file mode 100644 index 0000000000..93ad0cd734 --- /dev/null +++ b/src/lib/thread/.may_include @@ -0,0 +1,6 @@ +orconfig.h +lib/cc/*.h +lib/lock/*.h +lib/log/*.h +lib/testsupport/*.h +lib/thread/*.h diff --git a/src/common/compat_pthreads.c b/src/lib/thread/compat_pthreads.c index e345cfef0f..246c6254bb 100644 --- a/src/common/compat_pthreads.c +++ b/src/lib/thread/compat_pthreads.c @@ -11,13 +11,16 @@ */ #include "orconfig.h" +#include "lib/thread/threads.h" +#include "lib/log/torlog.h" +#include "lib/log/util_bug.h" + +#include <sys/time.h> #include <pthread.h> #include <signal.h> #include <time.h> - -#include "common/compat.h" -#include "lib/log/torlog.h" -#include "common/util.h" +#include <errno.h> +#include <string.h> /** Wraps a void (*)(void*) function and its argument so we can * invoke them in a way pthreads would expect. diff --git a/src/common/compat_threads.c b/src/lib/thread/compat_threads.c index 87833c6cfa..1d685b2c3e 100644 --- a/src/common/compat_threads.c +++ b/src/lib/thread/compat_threads.c @@ -13,11 +13,10 @@ #include "orconfig.h" #include <stdlib.h> -#include "common/compat.h" -#include "common/compat_threads.h" +#include "lib/thread/threads.h" -#include "common/util.h" #include "lib/log/torlog.h" +#include "lib/log/util_bug.h" /** Allocate and return a new condition variable. */ tor_cond_t * diff --git a/src/common/compat_winthreads.c b/src/lib/thread/compat_winthreads.c index d082af31c9..7f9877d21e 100644 --- a/src/common/compat_winthreads.c +++ b/src/lib/thread/compat_winthreads.c @@ -12,11 +12,12 @@ #ifdef _WIN32 -#include "common/compat.h" #include <windows.h> #include <process.h> -#include "common/util.h" +#include "lib/thread/threads.h" #include "lib/log/torlog.h" +#include "lib/log/util_bug.h" +#include "lib/log/win32err.h" /* This value is more or less total cargo-cult */ #define SPIN_COUNT 2000 diff --git a/src/lib/thread/include.am b/src/lib/thread/include.am new file mode 100644 index 0000000000..0eac7edeeb --- /dev/null +++ b/src/lib/thread/include.am @@ -0,0 +1,25 @@ + +noinst_LIBRARIES += src/lib/libtor-thread.a + +if UNITTESTS_ENABLED +noinst_LIBRARIES += src/lib/libtor-thread-testing.a +endif + +if THREADS_PTHREADS +threads_impl_source=src/lib/thread/compat_pthreads.c +endif +if THREADS_WIN32 +threads_impl_source=src/lib/thread/compat_winthreads.c +endif + +src_lib_libtor_thread_a_SOURCES = \ + src/lib/thread/compat_threads.c \ + $(threads_impl_source) + +src_lib_libtor_thread_testing_a_SOURCES = \ + $(src_lib_libtor_thread_a_SOURCES) +src_lib_libtor_thread_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS) +src_lib_libtor_thread_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) + +noinst_HEADERS += \ + src/lib/thread/threads.h diff --git a/src/common/compat_threads.h b/src/lib/thread/threads.h index 69350421b5..fcccc643d5 100644 --- a/src/common/compat_threads.h +++ b/src/lib/thread/threads.h @@ -15,6 +15,8 @@ #include <stdatomic.h> #endif +struct timeval; + int spawn_func(void (*func)(void *), void *data); void spawn_exit(void) ATTR_NORETURN; diff --git a/src/rust/build.rs b/src/rust/build.rs index 36f847d2e2..e17f9e5df2 100644 --- a/src/rust/build.rs +++ b/src/rust/build.rs @@ -154,6 +154,7 @@ pub fn main() { cfg.component("tor-sandbox"); cfg.component("tor-encoding-testing"); cfg.component("tor-net"); + cfg.component("tor-thread-testing"); cfg.component("tor-log"); cfg.component("tor-lock"); cfg.component("tor-fdio"); diff --git a/src/test/test_threads.c b/src/test/test_threads.c index 11f41a0444..e698e4f618 100644 --- a/src/test/test_threads.c +++ b/src/test/test_threads.c @@ -5,7 +5,7 @@ #include "orconfig.h" #include "or/or.h" -#include "common/compat_threads.h" +#include "lib/thread/threads.h" #include "test/test.h" /** mutex for thread test to stop the threads hitting data at the same time. */ diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c index 7c525aa28c..5cda99b58e 100644 --- a/src/test/test_workqueue.c +++ b/src/test/test_workqueue.c @@ -4,7 +4,7 @@ /* See LICENSE for licensing information */ #include "or/or.h" -#include "common/compat_threads.h" +#include "lib/thread/threads.h" #include "or/onion.h" #include "common/workqueue.h" #include "lib/crypt_ops/crypto_curve25519.h" |