Skip to main content

ProcessorSet

Struct ProcessorSet 

Source
pub struct ProcessorSet { /* private fields */ }
Expand description

A set of logical processors, correctly spanning more than one processor group.

A Windows thread’s affinity is a GROUP_AFFINITY – one group and a bitmask within it – because a group is a hard boundary: no single mask can name processors in two different groups. A type that silently flattened to one 64-bit mask would misrepresent any topology wider than one group, which is exactly the class of bug this type exists to prevent. ProcessorSet keeps each group’s mask separate instead.

Implementations§

Source§

impl ProcessorSet

Source

pub fn empty() -> Self

A set naming no processors.

Source

pub fn from_group_mask(group: u16, mask: usize) -> Self

A set naming every bit set in mask within group.

Source

pub fn can_represent(number: u8) -> bool

Whether a processor number fits this platform’s group width.

A ProcessorSet holds one bit per processor in a usize, so the ceiling is usize::BITS – 64 on x86-64, 32 on i686-pc-windows-msvc. ProcessorId::number is a u8 and its field is public, so a caller can build an id this set cannot hold; Self::insert asserts on one, and this is how a caller asks before rather than being aborted.

Source

pub fn insert(&mut self, group: u16, number: u8)

Add number within group to the set.

§Panics

Panics if number is MAX_PROCESSORS_PER_GROUP or greater: a processor group cannot hold more processors than a mask has bits. Self::can_represent is how a caller holding a publicly-constructed crate::ProcessorId asks first – the panic is for a caller building a set it controls, not a way to reject a query’s argument.

Source

pub fn is_empty(&self) -> bool

Whether the set names no processors.

Source

pub fn len(&self) -> usize

How many processors the set names, across every group.

Source

pub fn contains(&self, group: u16, number: u8) -> bool

Whether group/number is a member of this set.

Source

pub fn group_mask(&self, group: u16) -> usize

The raw mask for a single group, or 0 if the group has no members here.

Source

pub fn group_masks(&self) -> impl Iterator<Item = (u16, usize)> + '_

Iterate over (group, mask) pairs, one per group with any member here, in ascending group order.

Source

pub fn iter(&self) -> impl Iterator<Item = (u16, u8)> + '_

Iterate over every (group, number) member, in ascending order.

Source

pub fn intersection(&self, other: &Self) -> Self

The set of processors present in both self and other.

Source

pub fn union(&self, other: &Self) -> Self

The set of processors present in either self or other.

Source

pub fn is_disjoint(&self, other: &Self) -> bool

Whether self and other share no processors.

Source

pub fn is_subset(&self, other: &Self) -> bool

Whether every processor in self is also in other.

This is the comparison the granularity order is built on (M2+.2): inclusion is checkable against the memberships the platform actually reported, where a firmware level number is only asserted. The empty set is a subset of everything, which follows from the definition and is not a special case.

Trait Implementations§

Source§

impl Clone for ProcessorSet

Source§

fn clone(&self) -> ProcessorSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProcessorSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProcessorSet

Source§

fn default() -> ProcessorSet

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ProcessorSet

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ProcessorSet

Source§

impl FromIterator<(u16, u8)> for ProcessorSet

Source§

fn from_iter<T: IntoIterator<Item = (u16, u8)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for ProcessorSet

Source§

fn eq(&self, other: &ProcessorSet) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ProcessorSet

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ProcessorSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.