diff --git a/elf/main.cc b/elf/main.cc index c2bd7ded..e6b0ba0e 100644 --- a/elf/main.cc +++ b/elf/main.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -301,6 +302,13 @@ static void show_stats(Context &ctx) { Counter::print(); } +static i64 get_default_thread_count() { + // mold doesn't scale above 32 threads. + int n = tbb::global_control::active_value( + tbb::global_control::max_allowed_parallelism); + return std::min(n, 32); +} + template static int elf_main(int argc, char **argv) { Context ctx; @@ -336,7 +344,12 @@ static int elf_main(int argc, char **argv) { if (!ctx.arg.preload) try_resume_daemon(ctx); - set_thread_count(ctx.arg.thread_count); + i64 thread_count = ctx.arg.thread_count; + if (thread_count == 0) + thread_count = get_default_thread_count(); + tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism, + thread_count); + install_signal_handler(); if (!ctx.arg.directory.empty() && chdir(ctx.arg.directory.c_str()) == -1) diff --git a/threads.cc b/threads.cc deleted file mode 100644 index cccab2f5..00000000 --- a/threads.cc +++ /dev/null @@ -1,20 +0,0 @@ -#include "mold.h" - -#include - -namespace mold { - -static i64 get_default_thread_count() { - // mold doesn't scale above 32 threads. - int n = tbb::global_control::active_value( - tbb::global_control::max_allowed_parallelism); - return std::min(n, 32); -} - -void set_thread_count(i64 n) { - if (n == 0) - n = get_default_thread_count(); - tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism, n); -} - -} // namespace mold