diff --git a/src/lib.rs b/src/lib.rs index 7d0c8cf..968d3f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,9 +136,11 @@ impl Drop for PtrDrop { #[derive(Clone)] pub(crate) struct Ptr(Arc>); -// SAFETY: The types used with Ptr in this crate are all Send (namely gbm_device, gbm_surface and gbm_bo). +// SAFETY: The types used with Ptr in this crate are all Send and Sync (namely gbm_device, gbm_surface and gbm_bo). +// Reference counting is implemented with the thread-safe atomic `Arc`-wrapper. // The type is private and can thus not be used unsoundly by other crates. unsafe impl Send for Ptr {} +unsafe impl Sync for Ptr {} impl Ptr { fn new(ptr: *mut T, destructor: F) -> Ptr { @@ -183,12 +185,14 @@ impl fmt::Pointer for WeakPtr { } unsafe impl Send for WeakPtr where Ptr: Send {} +unsafe impl Sync for WeakPtr where Ptr: Sync {} #[cfg(test)] mod test { use std::os::unix::io::OwnedFd; fn is_send() {} + fn is_sync() {} #[test] fn device_is_send() { @@ -196,14 +200,31 @@ mod test { is_send::>(); } + #[test] + fn device_is_sync() { + is_sync::>(); + is_sync::>(); + } + #[test] fn surface_is_send() { is_send::>(); is_send::>(); } + #[test] + fn surface_is_sync() { + is_sync::>(); + is_sync::>(); + } + #[test] fn unmapped_bo_is_send() { is_send::>(); } + + #[test] + fn unmapped_bo_is_sync() { + is_sync::>(); + } }