rusticl/ptr: add a few APIs to TrackedPointers

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30082>
(cherry picked from commit 00180933ad)
This commit is contained in:
Karol Herbst 2024-07-08 10:33:25 +02:00 committed by Eric Engestrom
parent 5b215136fc
commit e51ac614c5
3 changed files with 17 additions and 5 deletions

View file

@ -1104,7 +1104,7 @@
"description": "rusticl/ptr: add a few APIs to TrackedPointers",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -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(

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)
}
}