mirror of
https://github.com/girlbossceo/jemallocator.git
synced 2024-11-25 22:46:30 +00:00
07764999bd
* rename bg_thread feature to background_threads_runtime_support * add background_threads option to enable background threads at run-time
36 lines
1 KiB
Rust
36 lines
1 KiB
Rust
//! Test background threads run-time default settings.
|
|
extern crate jemallocator;
|
|
extern crate libc;
|
|
|
|
use jemallocator::Jemalloc;
|
|
|
|
#[global_allocator]
|
|
static A: Jemalloc = Jemalloc;
|
|
|
|
// Returns true if background threads are enabled.
|
|
fn background_threads() -> bool {
|
|
unsafe {
|
|
let mut v: bool = false;
|
|
jemallocator::mallctl_fetch(b"opt.background_thread\0", &mut v).unwrap();
|
|
v
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn background_threads_runtime_defaults() {
|
|
if !cfg!(feature = "background_threads_runtime_support") {
|
|
// If the crate was compiled without background thread support,
|
|
// then background threads are always disabled at run-time by default:
|
|
assert_eq!(background_threads(), false);
|
|
return;
|
|
}
|
|
|
|
if cfg!(feature = "background_threads") {
|
|
// The crate was compiled with background-threads enabled by default:
|
|
assert_eq!(background_threads(), true);
|
|
} else {
|
|
// The crate was compiled with background-threads disabled by default:
|
|
assert_eq!(background_threads(), false);
|
|
}
|
|
}
|