Skip to content

Commit

Permalink
Hold thread join handle
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Apr 8, 2021
1 parent 0c616bf commit 056b38b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/malloc_ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ edition = "2018"
lighthouse_metrics = { path = "../lighthouse_metrics" }
lazy_static = "1.4.0"
libc = "0.2.79"
parking_lot = "0.11.0"
7 changes: 6 additions & 1 deletion common/malloc_ctl/src/glibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use lazy_static::lazy_static;
use libc;
use lighthouse_metrics::*;
use parking_lot::Mutex;
use std::env;
use std::os::raw::{c_int, c_ulong};
use std::result::Result;
Expand Down Expand Up @@ -47,6 +48,10 @@ const OPTIMAL_TRIM_INTERVAL: Duration = Duration::from_secs(60 * 5);
const ENV_VAR_ARENA_MAX: &str = "MALLOC_ARENA_MAX";
const ENV_VAR_MMAP_THRESHOLD: &str = "MALLOC_MMAP_THRESHOLD_";

lazy_static! {
pub static ref TRIMMER_THREAD_HANDLE: Mutex<Option<thread::JoinHandle<()>>> = <_>::default();
}

// Metrics for the malloc. For more information, see:
//
// https://man7.org/linux/man-pages/man3/mallinfo.3.html
Expand Down Expand Up @@ -122,7 +127,7 @@ pub fn configure_glibc_malloc() -> Result<(), String> {
}
}

spawn_trimmer_thread(OPTIMAL_TRIM_INTERVAL, OPTIMAL_TRIM);
*TRIMMER_THREAD_HANDLE.lock() = Some(spawn_trimmer_thread(OPTIMAL_TRIM_INTERVAL, OPTIMAL_TRIM));

Ok(())
}
Expand Down

0 comments on commit 056b38b

Please sign in to comment.