use crate::{arc, cf, define_cf_type};
define_cf_type!(
#[doc(alias = "CMMemoryPool")]
MemPool(cf::Type)
);
unsafe impl Send for MemPool {}
impl MemPool {
#[doc(alias = "CMMemoryPoolCreate")]
#[inline]
pub fn new() -> arc::R<Self> {
Self::with_opts(None)
}
#[doc(alias = "CMMemoryPoolCreate")]
#[inline]
pub fn with_opts(options: Option<&cf::Dictionary>) -> arc::R<MemPool> {
unsafe { CMMemoryPoolCreate(options) }
}
#[inline]
pub fn with_age(duration: std::time::Duration) -> arc::R<Self> {
let opts = cf::Dictionary::with_keys_values(
&[keys::age_out_period()],
&[&cf::Number::from_f64(duration.as_secs_f64())],
);
Self::with_opts(opts.as_deref())
}
#[doc(alias = "CMMemoryPoolGetAllocator")]
#[inline]
pub fn pool_allocator(&self) -> &cf::Allocator {
unsafe { CMMemoryPoolGetAllocator(self) }
}
#[doc(alias = "CMMemoryPoolFlush")]
#[inline]
pub fn flush(&mut self) {
unsafe { CMMemoryPoolFlush(self) }
}
#[doc(alias = "CMMemoryPoolInvalidate")]
#[inline]
pub fn invalidate(&mut self) {
unsafe { CMMemoryPoolInvalidate(self) }
}
}
pub mod keys {
use crate::cf;
#[doc(alias = "kCMMemoryPoolOption_AgeOutPeriod")]
#[inline]
pub fn age_out_period() -> &'static cf::String {
unsafe { kCMMemoryPoolOption_AgeOutPeriod }
}
unsafe extern "C" {
static kCMMemoryPoolOption_AgeOutPeriod: &'static cf::String;
}
}
unsafe extern "C-unwind" {
fn CMMemoryPoolCreate(options: Option<&cf::Dictionary>) -> arc::R<MemPool>;
fn CMMemoryPoolGetAllocator(pool: &MemPool) -> &cf::Allocator;
fn CMMemoryPoolFlush(pool: &MemPool);
fn CMMemoryPoolInvalidate(pool: &MemPool);
}