rusticl/ptr: add a few APIs to TrackedPointers

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30082>
This commit is contained in:
Karol Herbst
2024-07-08 10:33:25 +02:00
committed by Marge Bot
parent d28ab687bb
commit 00180933ad
2 changed files with 16 additions and 4 deletions
@@ -200,7 +200,7 @@ impl Context {
}
pub fn remove_svm_ptr(&self, ptr: usize) -> Option<Layout> {
self.svm_ptrs.lock().unwrap().remove(&ptr)
self.svm_ptrs.lock().unwrap().remove(ptr)
}
pub fn import_gl_buffer(
+15 -3
View File
@@ -1,6 +1,6 @@
use std::{
alloc::Layout,
collections::BTreeMap,
collections::{btree_map::Entry, BTreeMap},
hash::{Hash, Hasher},
mem,
ops::{Add, Deref},
@@ -162,6 +162,14 @@ impl<P, T: AllocSize<P>> TrackedPointers<P, T>
where
P: Ord + Add<Output = P> + Copy,
{
pub fn contains_key(&self, ptr: P) -> bool {
self.ptrs.contains_key(&ptr)
}
pub fn entry(&mut self, ptr: P) -> Entry<P, T> {
self.ptrs.entry(ptr)
}
pub fn find_alloc(&self, ptr: P) -> Option<(P, &T)> {
if let Some((&base, val)) = self.ptrs.range(..=ptr).next_back() {
let size = val.size();
@@ -174,12 +182,16 @@ where
None
}
pub fn find_alloc_precise(&self, ptr: P) -> Option<&T> {
self.ptrs.get(&ptr)
}
pub fn insert(&mut self, ptr: P, val: T) -> Option<T> {
self.ptrs.insert(ptr, val)
}
pub fn remove(&mut self, ptr: &P) -> Option<T> {
self.ptrs.remove(ptr)
pub fn remove(&mut self, ptr: P) -> Option<T> {
self.ptrs.remove(&ptr)
}
}