use crate::TCMalloc;
use libtcmalloc_sys::{NeedsProcessBackgroundActions, ProcessBackgroundActions};
#[cfg(feature = "std")]
use std::thread;
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "extension")]
#[cfg_attr(docsrs, doc(cfg(feature = "extension")))]
impl TCMalloc {
#[inline]
pub fn needs_process_background_actions() -> bool {
unsafe { NeedsProcessBackgroundActions() }
}
#[inline]
pub fn process_background_actions() {
unsafe { ProcessBackgroundActions() };
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn process_background_actions_thread() -> Option<thread::JoinHandle<()>> {
if Self::needs_process_background_actions() {
Some(thread::spawn(|| {
Self::process_background_actions();
}))
} else {
None
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg(target_os = "linux")]
fn test_needs_process_background_actions() {
assert!(!TCMalloc::needs_process_background_actions());
}
#[test]
#[cfg(feature = "std")]
fn test_process_background_actions() {
TCMalloc::process_background_actions_thread();
}
}