#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LogicalCores(BTreeSet<LogicalCoreIdentifier>);
impl From<LogicalCoreIdentifier> for LogicalCores
{
#[inline(always)]
fn from(core_index: LogicalCoreIdentifier) -> Self
{
let mut logical_cores = BTreeSet::new();
logical_cores.insert(core_index);
Self(logical_cores)
}
}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl From<HyperThread> for LogicalCores
{
#[inline(always)]
fn from(hyper_thread: HyperThread) -> Self
{
let logical_core_identifier: LogicalCoreIdentifier = hyper_thread.into();
Self::from(logical_core_identifier)
}
}
impl From<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn from(logical_cores: BTreeSet<LogicalCoreIdentifier>) -> Self
{
Self(logical_cores)
}
}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl From<BTreeSet<HyperThread>> for LogicalCores
{
#[inline(always)]
fn from(hyper_threads: BTreeSet<HyperThread>) -> Self
{
unsafe { transmute(hyper_threads) }
}
}
impl Into<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn into(self) -> BTreeSet<LogicalCoreIdentifier>
{
self.0
}
}
impl Deref for LogicalCores
{
type Target = BTreeSet<LogicalCoreIdentifier>;
#[inline(always)]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl DerefMut for LogicalCores
{
#[inline(always)]
fn deref_mut(&mut self) -> &mut Self::Target
{
&mut self.0
}
}
impl AsRef<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn as_ref(&self) -> &BTreeSet<LogicalCoreIdentifier>
{
&self.0
}
}
impl AsMut<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn as_mut(&mut self) -> &mut BTreeSet<LogicalCoreIdentifier>
{
&mut self.0
}
}
impl Borrow<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn borrow(&self) -> &BTreeSet<LogicalCoreIdentifier>
{
&self.0
}
}
impl BorrowMut<BTreeSet<LogicalCoreIdentifier>> for LogicalCores
{
#[inline(always)]
fn borrow_mut(&mut self) -> &mut BTreeSet<LogicalCoreIdentifier>
{
&mut self.0
}
}
impl LogicalCores
{
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn valid_logical_cores_for_the_current_process() -> Self
{
Self::from(HyperThread::valid_hyper_threads_for_the_current_process(&ProcPath::default()))
}
#[inline(always)]
pub fn empty_per_logical_core_data<PerLogicalCore>(&self) -> PerLogicalCoreData<PerLogicalCore>
{
PerLogicalCoreData::empty(self)
}
#[inline(always)]
pub fn populate_per_logical_core_data<PerLogicalCore>(&self, constructor: impl FnMut(LogicalCoreIdentifier) -> PerLogicalCore) -> PerLogicalCoreData<PerLogicalCore>
{
PerLogicalCoreData::new(self, constructor)
}
#[inline(always)]
pub fn set_current_thread_affinity_for_only_logical_core(logical_core_identifier: LogicalCoreIdentifier) -> Result<(), io::Error>
{
Self::from(logical_core_identifier).set_current_thread_affinity()
}
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuschia", target_os = "linux"))]
#[inline(always)]
pub fn for_current_logical_core() -> Self
{
Self::from(Self::current_logical_core())
}
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuschia", target_os = "linux"))]
#[inline(always)]
pub fn current_logical_core() -> LogicalCoreIdentifier
{
HyperThread::current_hyper_thread().into()
}
pub const IsSettingProcessAffinitySupported: bool = Self::_IsSettingProcessAffinitySupported;
pub const IsSettingThreadAffinitySupported: bool = Self::_IsSettingThreadAffinitySupported;
#[inline(always)]
pub fn set_current_process_affinity(&self) -> io::Result<()>
{
self._set_process_affinity(Self::current_process_identifier())
}
#[inline(always)]
pub fn set_process_affinity(&self, process_identifier: ProcessIdentifier) -> io::Result<()>
{
self._set_process_affinity(process_identifier)
}
#[inline(always)]
pub fn set_current_thread_affinity(&self) -> io::Result<()>
{
self._set_thread_affinity(Self::current_thread_identifier())
}
#[inline(always)]
pub fn set_thread_affinity(&self, thread_identifier: ThreadIdentifier) -> io::Result<()>
{
self._set_thread_affinity(thread_identifier)
}
#[cfg(unix)]
const fn current_process_identifier() -> ProcessIdentifier
{
0
}
#[cfg(windows)]
fn current_process_identifier() -> ProcessIdentifier
{
unsafe { ::kernel32::GetCurrentProcess() }
}
#[cfg(unix)]
fn current_thread_identifier() -> ThreadIdentifier
{
unsafe { pthread_self() }
}
#[cfg(windows)]
fn current_thread_identifier() -> ThreadIdentifier
{
unsafe { ::kernel32::GetCurrentThread() }
}
#[allow(dead_code)]
#[inline(always)]
fn last_os_error() -> io::Error
{
io::Error::last_os_error()
}
}
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuschia", target_os = "linux", target_env = "uclibc"))] include!("LogicalCores.android-emscripten-fuschia-linux-uclibc.rs");
#[cfg(target_os = "dragonfly")] include!("LogicalCores.dragonfly.rs");
#[cfg(target_os = "freebsd")] include!("LogicalCores.freebsd.rs");
#[cfg(any(target_os = "ios", target_os = "macos"))] include!("LogicalCores.ios_macos.rs");
#[cfg(target_os = "netbsd")] include!("LogicalCores.netbsd.rs");
#[cfg(not(any(target_os = "android", target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", target_os = "fuschia", target_os = "ios", target_os = "linux", target_os = "macos", target_os = "netbsd", target_env = "uclibc", windows)))] include!("LogicalCores.others.rs");
#[cfg(windows)] include!("LogicalCores.windows.rs");