#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PerHyperThreadCgroupStorageMap<V: Copy>
{
map_file_descriptor: Rc<MapFileDescriptor>,
maximum_entries: MaximumEntries,
number_of_possible_hyper_threads: NumberOfPossibleHyperThreads,
marker: PhantomData<V>,
}
impl<V: Copy> PerHyperThreadCgroupStorageMap<V>
{
#[inline(always)]
pub fn new_per_hyper_thread(map_file_descriptors: &mut FileDescriptorsMap<MapFileDescriptor>, map_name: &MapName, parsed_bpf_type_format_map_data: Option<&ParsedBpfTypeFormatMapData>, maximum_entries: MaximumEntries, access_permissions: AccessPermissions, number_of_possible_hyper_threads: NumberOfPossibleHyperThreads, numa_node: Option<NumaNode>) -> Result<Self, MapCreationError>
{
Self::create(map_file_descriptors, map_name, parsed_bpf_type_format_map_data, MapType::CgroupStoragePerHyperThread(Self::value_size(), access_permissions, numa_node), maximum_entries, number_of_possible_hyper_threads)
}
#[inline(always)]
pub fn capacity(&self) -> NonZeroU32
{
self.maximum_entries.0
}
#[inline(always)]
pub fn freeze(&self) -> Result<(), Errno>
{
self.map_file_descriptor.freeze()
}
#[inline(always)]
pub fn keys(&self) -> Result<KeyIterator<bpf_cgroup_storage_key>, Errno>
{
KeyIterator::new(&self.map_file_descriptor)
}
#[inline(always)]
pub unsafe fn allocate_values(&self) -> Vec<PerHyperThreadValue<V>>
{
self.number_of_possible_hyper_threads.uninitialized_per_hyper_thread_values()
}
#[inline(always)]
pub unsafe fn get_values(&self, key: &bpf_cgroup_storage_key, allocate_values: &mut Vec<PerHyperThreadValue<V>>)
{
debug_assert_eq!(allocate_values.len(), self.values_length());
let found = self.map_file_descriptor.get_variably_sized_vector(key, allocate_values);
assert!(found, "index should always exist")
}
#[inline(always)]
pub unsafe fn insert_or_set_values(&self, key: &bpf_cgroup_storage_key, allocate_values: &Vec<PerHyperThreadValue<V>>)
{
debug_assert_eq!(allocate_values.len(), self.values_length());
self.map_file_descriptor.set_variably_sized(key, &allocate_values[..]).expect("index should always exist")
}
pub fn get(&self, key: &bpf_cgroup_storage_key) -> Option<Vec<PerHyperThreadValue<V>>>
{
self.map_file_descriptor.get_variably_sized(key, self.values_length())
}
pub fn insert_or_set(&self, key: &bpf_cgroup_storage_key, initializer: &impl Fn(HyperThread) -> V) -> Result<(), ()>
{
let values = self.initialized_per_hyper_thread_values(initializer);
self.map_file_descriptor.set_variably_sized(key, &values[..])
}
#[inline(always)]
fn initialized_per_hyper_thread_values(&self, initializer: &impl Fn(HyperThread) -> V) -> Vec<PerHyperThreadValue<V>>
{
self.number_of_possible_hyper_threads.initialized_per_hyper_thread_values(initializer)
}
#[inline(always)]
fn values_length(&self) -> usize
{
self.number_of_possible_hyper_threads.length()
}
#[inline(always)]
pub fn delete(&self, key: &bpf_cgroup_storage_key) -> Result<bool, Errno>
{
self.map_file_descriptor.delete(key)
}
#[inline(always)]
fn create(map_file_descriptors: &mut FileDescriptorsMap<MapFileDescriptor>, map_name: &MapName, parsed_bpf_type_format_map_data: Option<&ParsedBpfTypeFormatMapData>, map_type: MapType, maximum_entries: MaximumEntries, number_of_possible_hyper_threads: NumberOfPossibleHyperThreads) -> Result<Self, MapCreationError>
{
MapFileDescriptor::create(map_file_descriptors, map_type, map_name, parsed_bpf_type_format_map_data).map(|map_file_descriptor| Self::new(map_file_descriptor, maximum_entries, number_of_possible_hyper_threads))
}
#[inline(always)]
const fn new(map_file_descriptor: Rc<MapFileDescriptor>, maximum_entries: MaximumEntries, number_of_possible_hyper_threads: NumberOfPossibleHyperThreads) -> Self
{
Self
{
map_file_descriptor,
maximum_entries,
number_of_possible_hyper_threads,
marker: PhantomData
}
}
#[inline(always)]
fn value_size() -> ValueSizeU16
{
ValueSizeU16::try_from_value_size::<V>().unwrap()
}
}