1
1
mirror of https://github.com/rui314/mold.git synced 2024-07-14 16:20:34 +03:00
This commit is contained in:
Rui Ueyama 2024-03-18 15:30:13 +09:00
parent 8375741489
commit e7dc90dadc
6 changed files with 38 additions and 38 deletions

View File

@ -305,7 +305,6 @@ list(APPEND MOLD_ELF_TEMPLATE_FILES
elf/icf.cc
elf/input-files.cc
elf/input-sections.cc
elf/jobs.cc
elf/linker-script.cc
elf/lto.cc
elf/main.cc
@ -378,6 +377,12 @@ target_sources(mold PRIVATE
third-party/rust-demangle/rust-demangle.c
)
if(WIN32)
target_sources(mold PRIVATE common/jobs-win32.cc)
else()
target_sources(mold PRIVATE common/jobs-unix.cc)
endif()
# Add frequently included header files for pre-compiling.
# target_precompile_headers is supported by CMake 3.16.0 or newer.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")

View File

@ -885,6 +885,13 @@ std::filesystem::path to_abs_path(std::filesystem::path path);
std::optional<std::string_view> demangle_cpp(std::string_view name);
std::optional<std::string_view> demangle_rust(std::string_view name);
//
// jbos.cc
//
void acquire_global_lock();
void release_global_lock();
//
// compress.cc
//

View File

@ -9,21 +9,20 @@
// mold processes to just 1 for each user. It is intended to be used as
// `MOLD_JOBS=1 ninja` or `MOLD_JOBS=1 make -j$(nproc)`.
#include "mold.h"
#include "common.h"
#ifndef _WIN32
# include <fcntl.h>
# include <pwd.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <unistd.h>
#endif
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
namespace mold::elf {
namespace mold {
template <typename E>
void acquire_global_lock(Context<E> &ctx) {
#ifndef _WIN32
static int lock_fd = -1;
void acquire_global_lock() {
char *jobs = getenv("MOLD_JOBS");
if (!jobs || jobs != "1"s)
return;
@ -40,22 +39,12 @@ void acquire_global_lock(Context<E> &ctx) {
if (lockf(fd, F_LOCK, 0) == -1)
return;
ctx.global_lock_fd = fd;
#endif
lock_fd = fd;
}
template <typename E>
void release_global_lock(Context<E> &ctx) {
#ifndef _WIN32
if (ctx.global_lock_fd)
close(*ctx.global_lock_fd);
#endif
void release_global_lock() {
if (lock_fd != -1)
close(lock_fd);
}
using E = MOLD_TARGET;
template void acquire_global_lock(Context<E> &);
template void release_global_lock(Context<E> &);
} // namespace mold::elf
} // namespace mold

6
common/jobs-win32.cc Normal file
View File

@ -0,0 +1,6 @@
namespace mold {
void acquire_global_lock() {}
void release_global_lock() {}
} // namespace mold

View File

@ -364,7 +364,7 @@ int elf_main(int argc, char **argv) {
on_complete = fork_child();
#endif
acquire_global_lock(ctx);
acquire_global_lock();
tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism,
ctx.arg.thread_count);
@ -682,10 +682,11 @@ int elf_main(int argc, char **argv) {
std::cout << std::flush;
std::cerr << std::flush;
if (on_complete)
on_complete();
release_global_lock(ctx);
release_global_lock();
if (ctx.arg.quick_exit)
_exit(0);

View File

@ -1343,13 +1343,6 @@ template <typename E>
[[noreturn]]
void process_run_subcommand(Context<E> &ctx, int argc, char **argv);
//
// jobs.cc
//
template <typename E> void acquire_global_lock(Context<E> &ctx);
template <typename E> void release_global_lock(Context<E> &ctx);
//
// cmdline.cc
//
@ -1770,7 +1763,6 @@ struct Context {
std::vector<DynamicPattern> dynamic_list_patterns;
i64 default_version = VER_NDX_UNSPECIFIED;
i64 page_size = E::page_size;
std::optional<int> global_lock_fd;
// Reader context
bool as_needed = false;