Skip to content

Commit

Permalink
Make device clonable
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Apr 19, 2021
1 parent bb589f1 commit 6c0fdb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ pub struct Device<T: AsRawFd + 'static> {
ffi: Ptr<::ffi::gbm_device>,
}

impl<T: AsRawFd + Clone + 'static> Clone for Device<T> {
fn clone(&self) -> Device<T> {
Device {
fd: self.fd.clone(),
ffi: self.ffi.clone(),
}
}
}

unsafe impl Send for Ptr<::ffi::gbm_device> {}

impl<T: AsRawFd + 'static> AsRawFd for Device<T> {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl<T> Drop for PtrDrop<T> {
}
}

#[derive(Clone)]
pub(crate) struct Ptr<T>(Arc<PtrDrop<T>>);

impl<T> Ptr<T> {
Expand Down Expand Up @@ -180,4 +181,4 @@ mod test {
fn unmapped_bo_is_send() {
is_send::<super::BufferObject<()>>();
}
}
}

0 comments on commit 6c0fdb0

Please sign in to comment.