diff options
author | David Goulet <dgoulet@torproject.org> | 2024-10-10 09:55:57 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2024-10-10 09:55:57 -0400 |
commit | 0577b630e190647939752d05a92b241960086b3b (patch) | |
tree | b9c144b9c7b988862247b41643f0f7d5ac2c4856 /src/core | |
parent | cd04eee7e5024d08acfbac66f63d88d701c57285 (diff) | |
parent | 6feaea8fa44d4594388232f4e104a7c656013e19 (diff) | |
download | tor-0577b630e190647939752d05a92b241960086b3b.tar.gz tor-0577b630e190647939752d05a92b241960086b3b.zip |
Merge branch 'maint-0.4.8'
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/mainloop/cpuworker.c | 47 | ||||
-rw-r--r-- | src/core/mainloop/cpuworker.h | 3 |
2 files changed, 26 insertions, 24 deletions
diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c index a42dbb528d..b12879a178 100644 --- a/src/core/mainloop/cpuworker.c +++ b/src/core/mainloop/cpuworker.c @@ -1,6 +1,6 @@ /* Copyright (c) 2003-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. - * Copyright (c) 2007-2021, The Tor Project, Inc. */ + * Copyright (c) 2007-2024, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** @@ -74,7 +74,6 @@ worker_state_free_void(void *arg) worker_state_free_(arg); } -static replyqueue_t *replyqueue = NULL; static threadpool_t *threadpool = NULL; static uint32_t total_pending_tasks = 0; @@ -120,31 +119,33 @@ cpuworker_consensus_has_changed(const networkstatus_t *ns) void cpuworker_init(void) { - if (!replyqueue) { - replyqueue = replyqueue_new(0); - } - if (!threadpool) { - /* - In our threadpool implementation, half the threads are permissive and - half are strict (when it comes to running lower-priority tasks). So we - always make sure we have at least two threads, so that there will be at - least one thread of each kind. - */ - const int n_threads = MAX(get_num_cpus(get_options()), 2); - threadpool = threadpool_new(n_threads, - replyqueue, - worker_state_new, - worker_state_free_void, - NULL); - - int r = threadpool_register_reply_event(threadpool, NULL); - - tor_assert(r == 0); - } + /* + In our threadpool implementation, half the threads are permissive and + half are strict (when it comes to running lower-priority tasks). So we + always make sure we have at least two threads, so that there will be at + least one thread of each kind. + */ + const int n_threads = MAX(get_num_cpus(get_options()), 2); + threadpool = threadpool_new(n_threads, + replyqueue_new(0), + worker_state_new, + worker_state_free_void, + NULL); + + int r = threadpool_register_reply_event(threadpool, NULL); + + tor_assert(r == 0); set_max_pending_tasks(NULL); } +/** Free all resources allocated by cpuworker. */ +void +cpuworker_free_all(void) +{ + threadpool_free(threadpool); +} + /** Return the number of threads configured for our CPU worker. */ unsigned int cpuworker_get_n_threads(void) diff --git a/src/core/mainloop/cpuworker.h b/src/core/mainloop/cpuworker.h index 7821f5612f..7f00f363fe 100644 --- a/src/core/mainloop/cpuworker.h +++ b/src/core/mainloop/cpuworker.h @@ -1,7 +1,7 @@ /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. - * Copyright (c) 2007-2021, The Tor Project, Inc. */ + * Copyright (c) 2007-2024, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** @@ -13,6 +13,7 @@ #define TOR_CPUWORKER_H void cpuworker_init(void); +void cpuworker_free_all(void); void cpuworkers_rotate_keyinfo(void); void cpuworker_consensus_has_changed(const networkstatus_t *ns); |