rusticl/mem: make Mem Send/Sync by storing mapping ptrs as usize
Signed-off-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26040>
This commit is contained in:
@@ -49,7 +49,7 @@ impl MappingTransfer {
|
||||
|
||||
struct Mappings {
|
||||
tx: HashMap<&'static Device, MappingTransfer>,
|
||||
maps: HashMap<*mut c_void, u32>,
|
||||
maps: HashMap<usize, u32>,
|
||||
}
|
||||
|
||||
impl Mappings {
|
||||
@@ -60,6 +60,11 @@ impl Mappings {
|
||||
})
|
||||
}
|
||||
|
||||
fn contains_ptr(&self, ptr: *mut c_void) -> bool {
|
||||
let ptr = ptr as usize;
|
||||
self.maps.contains_key(&ptr)
|
||||
}
|
||||
|
||||
fn mark_pending(&mut self, dev: &Device) {
|
||||
self.tx.get_mut(dev).unwrap().pending += 1;
|
||||
}
|
||||
@@ -71,6 +76,7 @@ impl Mappings {
|
||||
}
|
||||
|
||||
fn increase_ref(&mut self, dev: &Device, ptr: *mut c_void) -> bool {
|
||||
let ptr = ptr as usize;
|
||||
let res = self.maps.is_empty();
|
||||
*self.maps.entry(ptr).or_default() += 1;
|
||||
self.unmark_pending(dev);
|
||||
@@ -78,6 +84,7 @@ impl Mappings {
|
||||
}
|
||||
|
||||
fn decrease_ref(&mut self, ptr: *mut c_void, dev: &Device) -> (bool, Option<&PipeResource>) {
|
||||
let ptr = ptr as usize;
|
||||
if let Some(r) = self.maps.get_mut(&ptr) {
|
||||
*r -= 1;
|
||||
|
||||
@@ -1282,13 +1289,13 @@ impl Mem {
|
||||
}
|
||||
|
||||
pub fn is_mapped_ptr(&self, ptr: *mut c_void) -> bool {
|
||||
self.maps.lock().unwrap().maps.contains_key(&ptr)
|
||||
self.maps.lock().unwrap().contains_ptr(ptr)
|
||||
}
|
||||
|
||||
// TODO: only sync on unmap when the memory is not mapped for writing
|
||||
pub fn unmap(&self, q: &Arc<Queue>, ctx: &PipeContext, ptr: *mut c_void) -> CLResult<()> {
|
||||
let mut lock = self.maps.lock().unwrap();
|
||||
if !lock.maps.contains_key(&ptr) {
|
||||
if !lock.contains_ptr(ptr) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user