pub trait c_voidConstExt
{
#[inline(always)]
fn isPersistentMemoryThatSupportsFlushingWithPersist(self, length: usize) -> bool;
#[inline(always)]
fn persist(self, length: usize);
#[deprecated(note = "Avoid this as it adds substantial overhead for persistent memory")]
#[inline(always)]
fn persistOrMsyncRegardlessOfWhetherSelfIsPersistentOrNonPersistentMemory(self, length: usize);
#[inline(always)]
fn flush(self, length: usize);
#[deprecated(note = "Always false, and not useful to know as a fence is still needed, ie calls to drainAfterFlush() can not be avoided")]
#[inline(always)]
fn hasHardwareDrainInstruction() -> bool
{
let result = unsafe { pmem_has_hw_drain() };
if likely(result == 0)
{
false
}
else if likely(result == 1)
{
true
}
else
{
panic!("pmem_has_hw_drain() returned value '{}', not 0 or 1", result);
}
}
}
macro_rules! debug_assert_self_is_not_null
{
($self: ident) =>
{
debug_assert!(!$self.is_null(), "self (address) can not be null");
}
}
impl c_voidConstExt for *const c_void
{
#[inline(always)]
fn isPersistentMemoryThatSupportsFlushingWithPersist(self, length: usize) -> bool
{
debug_assert_self_is_not_null!(self);
let result = unsafe { pmem_is_pmem(self, length) };
if likely(result == 1)
{
true
}
else if likely(result == 0)
{
false
}
else
{
panic!("pmem_is_pmem() returned value '{}', not 1 or 0", result);
}
}
#[inline(always)]
fn persist(self, length: usize)
{
debug_assert_self_is_not_null!(self);
unsafe { pmem_persist(self, length) }
}
#[inline(always)]
fn persistOrMsyncRegardlessOfWhetherSelfIsPersistentOrNonPersistentMemory(self, length: usize)
{
debug_assert_self_is_not_null!(self);
if length == 0
{
return;
}
let result = unsafe { pmem_msync(self, length) };
if likely(result == 0)
{
return;
}
else if likely(result == -1)
{
match errno().0
{
E::ENOMEM => panic!("Address range and length is not fully-backed by either persistent memory or a memory-mapped file"),
E::EBUSY => panic!("EBUSY should be impossible for pmem_sync()"),
E::EINVAL => panic!("EINVAL should be impossible for pmem_sync()"),
illegal @ _ => panic!("Error number '{}' should not occur for pmem_sync()", illegal),
}
}
else
{
panic!("pmem_msync() returned value '{}', not 0 or -1", result);
}
}
#[inline(always)]
fn flush(self, length: usize)
{
debug_assert_self_is_not_null!(self);
unsafe { pmem_flush(self, length) }
}
}
impl c_voidConstExt for *mut c_void
{
#[inline(always)]
fn isPersistentMemoryThatSupportsFlushingWithPersist(self, length: usize) -> bool
{
(self as *const _).isPersistentMemoryThatSupportsFlushingWithPersist(length)
}
#[inline(always)]
fn persist(self, length: usize)
{
(self as *const _).persist(length)
}
#[allow(deprecated)]
#[inline(always)]
fn persistOrMsyncRegardlessOfWhetherSelfIsPersistentOrNonPersistentMemory(self, length: usize)
{
(self as *const _).persistOrMsyncRegardlessOfWhetherSelfIsPersistentOrNonPersistentMemory(length)
}
#[inline(always)]
fn flush(self, length: usize)
{
(self as *const _).flush(length)
}
}