mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-20 10:12:15 +01:00
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.
This commit is contained in:
parent
544ab27a94
commit
9cf335c9a5
2
.gitignore
vendored
2
.gitignore
vendored
@ -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
|
||||
|
@ -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 \
|
||||
|
@ -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) */
|
||||
|
@ -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 \
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
6
src/lib/thread/.may_include
Normal file
6
src/lib/thread/.may_include
Normal file
@ -0,0 +1,6 @@
|
||||
orconfig.h
|
||||
lib/cc/*.h
|
||||
lib/lock/*.h
|
||||
lib/log/*.h
|
||||
lib/testsupport/*.h
|
||||
lib/thread/*.h
|
@ -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.
|
@ -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 *
|
@ -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
|
25
src/lib/thread/include.am
Normal file
25
src/lib/thread/include.am
Normal file
@ -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
|
@ -15,6 +15,8 @@
|
||||
#include <stdatomic.h>
|
||||
#endif
|
||||
|
||||
struct timeval;
|
||||
|
||||
int spawn_func(void (*func)(void *), void *data);
|
||||
void spawn_exit(void) ATTR_NORETURN;
|
||||
|
@ -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");
|
||||
|
@ -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. */
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user