fix background thread examples

This commit is contained in:
gnzlbg 2018-11-09 14:32:09 +01:00 committed by gnzlbg
parent 192af49771
commit 346c9dea5e
2 changed files with 35 additions and 12 deletions

View File

@ -152,13 +152,14 @@ option! {
/// # #[cfg(not(target_os = "macos"))] { /// # #[cfg(not(target_os = "macos"))] {
/// # /// #
/// use jemalloc_ctl::background_thread; /// use jemalloc_ctl::background_thread;
/// let s = background_thread::read().unwrap(); /// let bg = background_thread::mib().unwrap();
/// let s = bg.read().unwrap();
/// println!("background_threads enabled: {}", s); /// println!("background_threads enabled: {}", s);
/// let p = background_thread::update(!s).unwrap(); /// let p = background_thread::update(!s).unwrap();
/// println!("background_threads enabled: {} => {}", p, bg.read().unwrap());
/// assert_eq!(p, s); /// assert_eq!(p, s);
/// let s = background_thread::read().unwrap(); /// background_thread::write(s).unwrap();
/// assert_ne!(p, s); /// println!("background_threads enabled: {}", bg.read().unwrap());
/// background_thread::write(!s).unwrap();
/// assert_eq!(p, s); /// assert_eq!(p, s);
/// # /// #
/// # } // #[cfg(..)] /// # } // #[cfg(..)]
@ -184,10 +185,10 @@ option! {
/// # #[cfg(not(target_os = "macos"))] { /// # #[cfg(not(target_os = "macos"))] {
/// # /// #
/// use jemalloc_ctl::max_background_threads; /// use jemalloc_ctl::max_background_threads;
/// let n = max_background_threads::read().unwrap(); /// let m = max_background_threads::mib().unwrap();
/// println!("max_background_threads: {}", n); /// println!("max_background_threads: {}", m.read().unwrap());
/// max_background_threads::write(n + 1).unwrap(); /// m.write(0).unwrap();
/// assert_eq!(max_background_threads::read().unwrap(), n + 1); /// assert_eq!(m.read().unwrap(), 0);
/// # /// #
/// # } // #[cfg(..)] /// # } // #[cfg(..)]
/// # } /// # }

View File

@ -73,10 +73,17 @@ macro_rules! r {
_ => (), _ => (),
} }
let _ = $id::read().unwrap(); let a = $id::read().unwrap();
let mib = $id::mib().unwrap(); let mib = $id::mib().unwrap();
let _ = mib.read().unwrap(); let b = mib.read().unwrap();
println!(
concat!(
stringify!($id),
" (read): \"{}\" - \"{}\""),
a, b
);
} }
} }
}; };
@ -117,6 +124,14 @@ macro_rules! w {
let mib = $id::mib().unwrap(); let mib = $id::mib().unwrap();
let _ = mib.write($ret_ty::default()).unwrap(); let _ = mib.write($ret_ty::default()).unwrap();
println!(
concat!(
stringify!($id),
" (write): \"{}\""),
$ret_ty::default()
);
} }
} }
}; };
@ -153,10 +168,17 @@ macro_rules! u {
_ => (), _ => (),
} }
let _ = $id::update($ret_ty::default()).unwrap(); let a = $id::update($ret_ty::default()).unwrap();
let mib = $id::mib().unwrap(); let mib = $id::mib().unwrap();
let _ = mib.update($ret_ty::default()).unwrap(); let b = mib.update($ret_ty::default()).unwrap();
println!(
concat!(
stringify!($id),
" (update): (\"{}\", \"{}\") - \"{}\""),
a, b, $ret_ty::default()
);
} }
} }
}; };