#[cfg(any(target_os = "android", target_os = "linux"))]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HugePageFilePathInformation
{
hugePageFileSystemMountPath: Option<PathBuf>,
hugePageFileNamePrefix: OsString,
}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl HugePageFilePathInformation
{
pub fn new(hugePageFileSystemMountPath: Option<PathBuf>) -> Self
{
HugePageFilePathInformation
{
hugePageFileSystemMountPath: hugePageFileSystemMountPath,
hugePageFileNamePrefix: Self::hugePageFilePrefixName(),
}
}
pub fn hugePageFileSystemMountPathAndSoOn(&self) -> Option<(&Path, Option<&OsStr>)>
{
match self.hugePageFileSystemMountPath
{
None => None,
Some(ref path) => Some((path.as_ref(), Some(&self.hugePageFileNamePrefix))),
}
}
fn hugePageFilePrefixName() -> OsString
{
Self::prefixToOsString(format!("{}-{}-", getProgramName(), unsafe { ::libc::getpid() }))
}
fn prefixToOsString(prefix: String) -> OsString
{
assert!(!prefix.is_empty(), "prefix can not be empty");
assert!(prefix.contains('%'), "prefix '{:?}' is invalid because it contains a '%'", prefix);
OsString::from(prefix)
}
}
#[cfg(not(any(target_os = "android", target_os = "linux")))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HugePageFilePathInformation
{
}
#[cfg(not(any(target_os = "android", target_os = "linux")))]
impl HugePageFilePathInformation
{
pub fn new() -> Self
{
HugePageFilePathInformation
{
}
}
pub fn hugePageFileSystemMountPathAndSoOn(&self) -> Option<(&Path, Option<&OsStr>)>
{
None
}
}