rusticl/context: store SVM pointers as usize
This way Context becomes Send and Sync Signed-off-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26040>
This commit is contained in:
@@ -27,7 +27,7 @@ pub struct Context {
|
||||
pub devs: Vec<&'static Device>,
|
||||
pub properties: Properties<cl_context_properties>,
|
||||
pub dtors: Mutex<Vec<DeleteContextCB>>,
|
||||
pub svm_ptrs: Mutex<BTreeMap<*const c_void, Layout>>,
|
||||
pub svm_ptrs: Mutex<BTreeMap<usize, Layout>>,
|
||||
pub gl_ctx_manager: Option<GLCtxManager>,
|
||||
}
|
||||
|
||||
@@ -188,14 +188,15 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn add_svm_ptr(&self, ptr: *mut c_void, layout: Layout) {
|
||||
self.svm_ptrs.lock().unwrap().insert(ptr, layout);
|
||||
self.svm_ptrs.lock().unwrap().insert(ptr as usize, layout);
|
||||
}
|
||||
|
||||
pub fn find_svm_alloc(&self, ptr: *const c_void) -> Option<(*const c_void, Layout)> {
|
||||
let lock = self.svm_ptrs.lock().unwrap();
|
||||
if let Some((&base, layout)) = lock.range(..=ptr).next_back() {
|
||||
if let Some((&base, layout)) = lock.range(..=ptr as usize).next_back() {
|
||||
// SAFETY: we really just do some pointer math here...
|
||||
unsafe {
|
||||
let base = base as *const c_void;
|
||||
// we check if ptr is within [base..base+size)
|
||||
// means we can check if ptr - (base + size) < 0
|
||||
if ptr.offset_from(base.add(layout.size())) < 0 {
|
||||
@@ -207,6 +208,7 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn remove_svm_ptr(&self, ptr: *const c_void) -> Option<Layout> {
|
||||
let ptr = ptr as usize;
|
||||
self.svm_ptrs.lock().unwrap().remove(&ptr)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user