mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 09:18:04 +02:00
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:
parent
5b215136fc
commit
e51ac614c5
3 changed files with 17 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue