Skip to content

Commit

Permalink
style: Add ToShmem impl for shared_lock::Locked.
Browse files Browse the repository at this point in the history
Depends on D17192

Differential Revision: https://phabricator.services.mozilla.com/D17193
  • Loading branch information
heycam authored and emilio committed Apr 12, 2019
1 parent 8c007ad commit b8506e4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions components/style/shared_lock.rs
Expand Up @@ -16,7 +16,10 @@ use std::fmt;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use std::mem; use std::mem;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use std::mem::ManuallyDrop;
#[cfg(feature = "gecko")]
use std::ptr; use std::ptr;
use to_shmem::{SharedMemoryBuilder, ToShmem};


/// A shared read/write lock that can protect multiple objects. /// A shared read/write lock that can protect multiple objects.
/// ///
Expand Down Expand Up @@ -238,6 +241,26 @@ impl<T> Locked<T> {
} }
} }


#[cfg(feature = "gecko")]
impl<T: ToShmem> ToShmem for Locked<T> {
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
let guard = self.shared_lock.read();
ManuallyDrop::new(Locked {
shared_lock: SharedRwLock::read_only(),
data: UnsafeCell::new(ManuallyDrop::into_inner(
self.read_with(&guard).to_shmem(builder),
)),
})
}
}

#[cfg(feature = "servo")]
impl<T: ToShmem> ToShmem for Locked<T> {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
panic!("ToShmem not supported in Servo currently")
}
}

#[allow(dead_code)] #[allow(dead_code)]
mod compile_time_assert { mod compile_time_assert {
use super::{SharedRwLockReadGuard, SharedRwLockWriteGuard}; use super::{SharedRwLockReadGuard, SharedRwLockWriteGuard};
Expand Down

0 comments on commit b8506e4

Please sign in to comment.