• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Test enabling / disabling background threads at run-time if the
2 //! library was compiled with background thread run-time support.
3 #![cfg(feature = "background_threads_runtime_support")]
4 #![cfg(not(feature = "unprefixed_malloc_on_supported_platforms"))]
5 #![cfg(not(target_env = "musl"))]
6 
7 use tikv_jemallocator::Jemalloc;
8 
9 #[global_allocator]
10 static A: Jemalloc = Jemalloc;
11 
12 union U {
13     x: &'static u8,
14     y: &'static libc::c_char,
15 }
16 
17 // Even if background threads are not enabled at run-time by default
18 // at configuration time, this enables them.
19 #[allow(non_upper_case_globals)]
20 #[export_name = "_rjem_malloc_conf"]
21 pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
22     U {
23         x: &b"background_thread:true\0"[0],
24     }
25     .y
26 });
27 
28 #[test]
background_threads_enabled()29 fn background_threads_enabled() {
30     // Background threads are unconditionally enabled at run-time by default.
31     assert!(tikv_jemalloc_ctl::opt::background_thread::read().unwrap(),);
32 }
33