mirror of
https://github.com/rui314/mold.git
synced 2024-10-05 17:17:40 +03:00
Refactor
This commit is contained in:
parent
3936134823
commit
c6b54532e9
@ -375,11 +375,9 @@ int elf_main(int argc, char **argv) {
|
||||
<< ": " << errno_string();
|
||||
|
||||
// Fork a subprocess unless --no-fork is given.
|
||||
std::function<void()> on_complete;
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
if (ctx.arg.fork)
|
||||
on_complete = fork_child();
|
||||
fork_child();
|
||||
#endif
|
||||
|
||||
acquire_global_lock();
|
||||
@ -706,8 +704,8 @@ int elf_main(int argc, char **argv) {
|
||||
std::cout << std::flush;
|
||||
std::cerr << std::flush;
|
||||
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
if (ctx.arg.fork)
|
||||
notify_parent();
|
||||
|
||||
release_global_lock();
|
||||
|
||||
|
@ -1367,7 +1367,8 @@ void print_map(Context<E> &ctx);
|
||||
// subprocess.cc
|
||||
//
|
||||
|
||||
std::function<void()> fork_child();
|
||||
void fork_child();
|
||||
void notify_parent();
|
||||
|
||||
template <typename E>
|
||||
[[noreturn]]
|
||||
|
@ -14,10 +14,12 @@
|
||||
namespace mold::elf {
|
||||
|
||||
#ifdef MOLD_X86_64
|
||||
static int pipe_write_fd = -1;
|
||||
|
||||
// Exiting from a program with large memory usage is slow --
|
||||
// it may take a few hundred milliseconds. To hide the latency,
|
||||
// we fork a child and let it do the actual linking work.
|
||||
std::function<void()> fork_child() {
|
||||
void fork_child() {
|
||||
int pipefd[2];
|
||||
if (pipe(pipefd) == -1) {
|
||||
perror("pipe");
|
||||
@ -50,12 +52,16 @@ std::function<void()> fork_child() {
|
||||
|
||||
// Child
|
||||
close(pipefd[0]);
|
||||
pipe_write_fd = pipefd[1];
|
||||
}
|
||||
|
||||
return [=] {
|
||||
char buf[] = {1};
|
||||
[[maybe_unused]] int n = write(pipefd[1], buf, 1);
|
||||
assert(n == 1);
|
||||
};
|
||||
void notify_parent() {
|
||||
if (pipe_write_fd == -1)
|
||||
return;
|
||||
|
||||
char buf[] = {1};
|
||||
[[maybe_unused]] int n = write(pipe_write_fd, buf, 1);
|
||||
assert(n == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user