commit b8c50eabfee1bd9f5ed03f8ec569cc53b980f1d1 Author: Nick Mathewson nickm@torproject.org Date: Thu Nov 1 13:14:43 2018 -0400
Add a subsystem for our threading support --- src/app/main/main.c | 1 - src/app/main/subsystem_list.c | 2 ++ src/lib/thread/.may_include | 1 + src/lib/thread/compat_threads.c | 16 ++++++++++++++++ src/lib/thread/include.am | 5 +++-- src/lib/thread/thread_sys.h | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/src/app/main/main.c b/src/app/main/main.c index 1e4cd37fe..21a283278 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -1397,7 +1397,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg) init_protocol_warning_severity_level();
update_approx_time(time(NULL)); - tor_threads_init(); tor_compress_init(); init_logging(0); monotime_init(); diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c index 0f7d5d2cc..c3b731ca3 100644 --- a/src/app/main/subsystem_list.c +++ b/src/app/main/subsystem_list.c @@ -10,6 +10,7 @@
#include "lib/err/torerr_sys.h" #include "lib/process/winprocess_sys.h" +#include "lib/thread/thread_sys.h"
#include <stddef.h>
@@ -19,6 +20,7 @@ const subsys_fns_t *tor_subsystems[] = { &sys_winprocess, &sys_torerr, + &sys_threads, };
const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems); diff --git a/src/lib/thread/.may_include b/src/lib/thread/.may_include index 93ad0cd73..c26a42692 100644 --- a/src/lib/thread/.may_include +++ b/src/lib/thread/.may_include @@ -2,5 +2,6 @@ orconfig.h lib/cc/*.h lib/lock/*.h lib/log/*.h +lib/subsys/*.h lib/testsupport/*.h lib/thread/*.h diff --git a/src/lib/thread/compat_threads.c b/src/lib/thread/compat_threads.c index 7f1970af4..3d41faa8c 100644 --- a/src/lib/thread/compat_threads.c +++ b/src/lib/thread/compat_threads.c @@ -14,9 +14,11 @@ #include "orconfig.h" #include <stdlib.h> #include "lib/thread/threads.h" +#include "lib/thread/thread_sys.h"
#include "lib/log/log.h" #include "lib/log/util_bug.h" +#include "lib/subsys/subsys.h"
#include <string.h>
@@ -109,3 +111,17 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval) return oldval; } #endif /* !defined(HAVE_WORKING_STDATOMIC) */ + +static int +sys_threads_initialize(void) +{ + tor_threads_init(); + return 0; +} + +const subsys_fns_t sys_threads = { + .name = "threads", + .supported = true, + .level = -95, + .initialize = sys_threads_initialize, +}; diff --git a/src/lib/thread/include.am b/src/lib/thread/include.am index 9ec23d166..695795a2c 100644 --- a/src/lib/thread/include.am +++ b/src/lib/thread/include.am @@ -23,5 +23,6 @@ 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 \ - src/lib/thread/numcpus.h + src/lib/thread/numcpus.h \ + src/lib/thread/thread_sys.h \ + src/lib/thread/threads.h diff --git a/src/lib/thread/thread_sys.h b/src/lib/thread/thread_sys.h new file mode 100644 index 000000000..984abe88e --- /dev/null +++ b/src/lib/thread/thread_sys.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file threads_sys.h + * \brief Declare subsystem object for threads library + **/ + +#ifndef TOR_THREADS_SYS_H +#define TOR_THREADS_SYS_H + +extern const struct subsys_fns_t sys_threads; + +#endif /* !defined(TOR_THREADS_SYS_H) */
tor-commits@lists.torproject.org