diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-01-15 13:26:44 -0500 |
---|---|---|
committer | Glenn Watson <gw@intuitionlibrary.com> | 2015-01-28 10:16:49 +1000 |
commit | 95fc29fa0db21959df99d81cdbb9561226321d2f (patch) | |
tree | a48e171165ec155062ef13c550b2c0f72d127425 /components/script/dom/bindings/refcounted.rs | |
parent | ff8cbff81016c157373c1675f3eee69dd70ae544 (diff) | |
download | servo-95fc29fa0db21959df99d81cdbb9561226321d2f.tar.gz servo-95fc29fa0db21959df99d81cdbb9561226321d2f.zip |
Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.
Diffstat (limited to 'components/script/dom/bindings/refcounted.rs')
-rw-r--r-- | components/script/dom/bindings/refcounted.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index 05dd4fb43ad..5a23e7f2027 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -32,15 +32,17 @@ use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot, JSContext}; use libc; use std::cell::RefCell; -use std::collections::hash_map::{HashMap, Vacant, Occupied}; +use std::collections::hash_map::HashMap; +use std::collections::hash_map::Entry::{Vacant, Occupied}; use std::rc::Rc; use std::sync::{Arc, Mutex}; -thread_local!(pub static LIVE_REFERENCES: Rc<RefCell<Option<LiveDOMReferences>>> = Rc::new(RefCell::new(None))) +thread_local!(pub static LIVE_REFERENCES: Rc<RefCell<Option<LiveDOMReferences>>> = Rc::new(RefCell::new(None))); /// A pointer to a Rust DOM object that needs to be destroyed. pub struct TrustedReference(*const libc::c_void); +unsafe impl Send for TrustedReference {} /// A safe wrapper around a raw pointer to a DOM object that can be /// shared among tasks for use in asynchronous operations. The underlying @@ -55,6 +57,8 @@ pub struct Trusted<T> { owner_thread: *const libc::c_void, } +unsafe impl<T: Reflectable> Send for Trusted<T> {} + impl<T: Reflectable> Trusted<T> { /// Create a new `Trusted<T>` instance from an existing DOM pointer. The DOM object will /// be prevented from being GCed for the duration of the resulting `Trusted<T>` object's @@ -91,7 +95,7 @@ impl<T: Reflectable> Trusted<T> { impl<T: Reflectable> Clone for Trusted<T> { fn clone(&self) -> Trusted<T> { { - let mut refcount = self.refcount.lock(); + let mut refcount = self.refcount.lock().unwrap(); *refcount += 1; } @@ -107,7 +111,7 @@ impl<T: Reflectable> Clone for Trusted<T> { #[unsafe_destructor] impl<T: Reflectable> Drop for Trusted<T> { fn drop(&mut self) { - let mut refcount = self.refcount.lock(); + let mut refcount = self.refcount.lock().unwrap(); assert!(*refcount > 0); *refcount -= 1; if *refcount == 0 { @@ -139,7 +143,7 @@ impl LiveDOMReferences { match table.entry(ptr as *const libc::c_void) { Occupied(mut entry) => { let refcount = entry.get_mut(); - *refcount.lock() += 1; + *refcount.lock().unwrap() += 1; refcount.clone() } Vacant(entry) => { @@ -148,7 +152,7 @@ impl LiveDOMReferences { JS_AddObjectRoot(cx, rootable); } let refcount = Arc::new(Mutex::new(1)); - entry.set(refcount.clone()); + entry.insert(refcount.clone()); refcount } } @@ -164,7 +168,7 @@ impl LiveDOMReferences { let mut table = live_references.table.borrow_mut(); match table.entry(raw_reflectable) { Occupied(entry) => { - if *entry.get().lock() != 0 { + if *entry.get().lock().unwrap() != 0 { // there could have been a new reference taken since // this message was dispatched. return; @@ -173,7 +177,7 @@ impl LiveDOMReferences { unsafe { JS_RemoveObjectRoot(cx, (*reflectable).rootable()); } - let _ = entry.take(); + let _ = entry.remove(); } Vacant(_) => { // there could be a cleanup message dispatched, then a new |