xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::linux::CpuSet Class Referencefinal

A CPU set for use with sched_setaffinity(2) or pthread_setaffinity_np(3). More...

#include <xentara/utils/linux/CpuSet.hpp>

Public Member Functions

constexpr CpuSet ()=default
 Default constructor.
 
auto capacity () -> int
 Gets the capacity of the set.
 
auto reserve (int maximumCpuIndex) -> void
 Reserve space for a certain number of CPUs.
 
auto add (int cpuIndex) -> void
 Adds a CPU.
 
auto remove (int cpuIndex) -> void
 Removes a CPU.
 
auto clear () -> void
 Removes all CPUs.
 
auto count () const -> int
 Counts the number of CPUs added to the set.
 
 operator const cpu_set_t * () const noexcept
 Conversion to a cpu_set_t pointer.
 
 operator cpu_set_t * () noexcept
 Conversion to a cpu_set_t pointer.
 
auto data () const noexcept -> const cpu_set_t *
 Gets the data.
 
auto data () noexcept -> cpu_set_t *
 Gets the data.
 
auto dataSize () const noexcept -> std::size_t
 Get the size of the data in bytes.
 

Detailed Description

A CPU set for use with sched_setaffinity(2) or pthread_setaffinity_np(3).

Note
This class is only available under Linux

Constructor & Destructor Documentation

◆ CpuSet()

constexpr xentara::utils::linux::CpuSet::CpuSet ( )
constexprdefault

Default constructor.

Member Function Documentation

◆ add()

auto xentara::utils::linux::CpuSet::add ( int  cpuIndex) -> void

Adds a CPU.

Parameters
cpuIndexThe 0-based index of the CPU to add. The CPU set is automatically expanded to be able to hold the given CPU index, if necessary. The CPU index must not be less than 0.

◆ capacity()

auto xentara::utils::linux::CpuSet::capacity ( ) -> int

Gets the capacity of the set.

Returns
The maximum CPU index that can be added without a reallocation taking place.

◆ clear()

auto xentara::utils::linux::CpuSet::clear ( ) -> void

Removes all CPUs.

◆ count()

auto xentara::utils::linux::CpuSet::count ( ) const -> int

Counts the number of CPUs added to the set.

◆ data() [1/2]

auto xentara::utils::linux::CpuSet::data ( ) const -> const cpu_set_t *
noexcept

Gets the data.

◆ data() [2/2]

auto xentara::utils::linux::CpuSet::data ( ) -> cpu_set_t *
noexcept

Gets the data.

◆ dataSize()

auto xentara::utils::linux::CpuSet::dataSize ( ) const -> std::size_t
noexcept

Get the size of the data in bytes.

Returns
The size of the set, in bytes. This is the size that needs to be passed to sched_setaffinity(2) or pthread_setaffinity_np(3), for example.

◆ operator const cpu_set_t *()

xentara::utils::linux::CpuSet::operator const cpu_set_t * ( ) const
noexcept

Conversion to a cpu_set_t pointer.

◆ operator cpu_set_t *()

xentara::utils::linux::CpuSet::operator cpu_set_t * ( )
noexcept

Conversion to a cpu_set_t pointer.

◆ remove()

auto xentara::utils::linux::CpuSet::remove ( int  cpuIndex) -> void

Removes a CPU.

Parameters
cpuIndexThe 0-based index of the CPU to add. It is safe to specify a CPU index that is greater than the current capacity. The CPU index must not be less than 0.

◆ reserve()

auto xentara::utils::linux::CpuSet::reserve ( int  maximumCpuIndex) -> void

Reserve space for a certain number of CPUs.

The CPU set is expanded if necessary. The set is never made smaller, however. Due to the way the kernel stores CPU sets, the actual resulting capacity can be larger that the value specified.

Parameters
maximumCpuIndexThe maximum CPU index that can be added without a reallocation taking place. must not be less than 0.

Member Data Documentation

◆ _longData

cpu_set_t* xentara::utils::linux::CpuSet::_longData

The long data.

◆ _shortData

cpu_set_t xentara::utils::linux::CpuSet::_shortData

The short data.