mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
perf(uucore): call rt_sigaction once not 62 times
`./coreutils true` becomes 6% faster. For some unknown reason,
`capture_startup_state` runs 62 times, so I'll just hotfix it to
immediately return from the second time onwards.
When 2d7a3bf2e0 introduced the fcntl
calls, each group of 3 calls was repeated 4 times. Some time later, it
became 62 times. Now it runs only 1 time.
This commit is contained in:
committed by
Sylvestre Ledru
parent
0260f21974
commit
49e7a6b532
@@ -538,6 +538,9 @@ static STDERR_WAS_CLOSED: AtomicBool = AtomicBool::new(false);
|
||||
#[cfg(unix)]
|
||||
static SIGPIPE_WAS_IGNORED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[cfg(unix)]
|
||||
static STARTUP_STATE_WAS_CAPTURED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// Captures stdio and SIGPIPE state at process initialization, before main() runs.
|
||||
///
|
||||
/// # Safety
|
||||
@@ -549,6 +552,11 @@ pub unsafe extern "C" fn capture_startup_state() {
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ptr;
|
||||
|
||||
// No spinlock because we're single-threaded at this point
|
||||
if STARTUP_STATE_WAS_CAPTURED.swap(true, Ordering::Relaxed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Capture stdio state
|
||||
unsafe {
|
||||
STDIN_WAS_CLOSED.store(
|
||||
|
||||
Reference in New Issue
Block a user