Skip to content
Permalink
Browse files

style: Add ToShmem impl for shared_lock::Locked.

Depends on D17192

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

/// A shared read/write lock that can protect multiple objects.
///
@@ -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)]
mod compile_time_assert {
use super::{SharedRwLockReadGuard, SharedRwLockWriteGuard};

0 comments on commit b8506e4

Please sign in to comment.
You can’t perform that action at this time.