Skip to content

Commit

Permalink
Make DmabufMapping implement Send/Sync
Browse files Browse the repository at this point in the history
It is no more unsafe to access this in multiple threads than in one. The
caller should assume another process may be mutating the buffer.
  • Loading branch information
ids1024 authored and Drakulix committed Dec 9, 2024
1 parent 48f5ba4 commit da9cc23
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backend/allocator/dmabuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ impl DmabufMapping {
}
}

// SAFETY: The caller is responsible for accessing the data without assuming
// another process isn't mutating it, regardless of how many threads this is
// referenced in.
unsafe impl Send for DmabufMapping {}
unsafe impl Sync for DmabufMapping {}

impl Drop for DmabufMapping {
fn drop(&mut self) {
let _ = unsafe { rustix::mm::munmap(self.ptr, self.len) };
Expand Down

0 comments on commit da9cc23

Please sign in to comment.