mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Express unique ownership of arc in StyleStructRef, add vacated state
MozReview-Commit-ID: GwOw0HaC9S7
This commit is contained in:
parent
c85aae4abd
commit
dd3159f2f5
2 changed files with 79 additions and 7 deletions
|
@ -31,7 +31,7 @@ use std::convert::From;
|
|||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::atomic;
|
||||
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release};
|
||||
|
||||
|
@ -71,6 +71,40 @@ pub struct Arc<T: ?Sized> {
|
|||
ptr: *mut ArcInner<T>,
|
||||
}
|
||||
|
||||
/// An Arc that is known to be uniquely owned
|
||||
///
|
||||
/// This lets us build arcs that we can mutate before
|
||||
/// freezing, without needing to change the allocation
|
||||
pub struct UniqueArc<T: ?Sized>(Arc<T>);
|
||||
|
||||
impl<T> UniqueArc<T> {
|
||||
#[inline]
|
||||
/// Construct a new UniqueArc
|
||||
pub fn new(data: T) -> Self {
|
||||
UniqueArc(Arc::new(data))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Convert to a shareable Arc<T> once we're done using it
|
||||
pub fn shareable(self) -> Arc<T> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for UniqueArc<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for UniqueArc<T> {
|
||||
fn deref_mut(&mut self) -> &mut T {
|
||||
// We know this to be uniquely owned
|
||||
unsafe { &mut (*self.0.ptr).data }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: ?Sized + Sync + Send> Send for Arc<T> {}
|
||||
unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue