diff --git a/Cargo.lock b/Cargo.lock index 77ebe5633f7..8a99d247fc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2992,6 +2992,7 @@ version = "0.0.1" dependencies = [ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "nonzero 0.0.1", ] [[package]] diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index 2d659bd4342..b9d6177273b 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -9,6 +9,9 @@ publish = false name = "constellation" path = "lib.rs" +[features] +unstable = ["servo_remutex/unstable"] + [dependencies] backtrace = "0.3" bluetooth_traits = { path = "../bluetooth_traits" } diff --git a/components/remutex/Cargo.toml b/components/remutex/Cargo.toml index 8bb165d40df..b3937587a62 100644 --- a/components/remutex/Cargo.toml +++ b/components/remutex/Cargo.toml @@ -9,6 +9,10 @@ publish = false name = "servo_remutex" path = "lib.rs" +[features] +unstable = ["nonzero/unstable"] + [dependencies] lazy_static = "0.2" log = "0.3.5" +nonzero = {path = "../nonzero"} diff --git a/components/remutex/lib.rs b/components/remutex/lib.rs index 8f97da8351f..6793429bf1e 100644 --- a/components/remutex/lib.rs +++ b/components/remutex/lib.rs @@ -10,13 +10,13 @@ //! It provides the same interface as https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/remutex.rs //! so if those types are ever exported, we should be able to replace this implemtation. -#![feature(nonzero)] +#![cfg_attr(feature = "unstable", feature(nonzero))] -extern crate core; +extern crate nonzero; #[macro_use] extern crate lazy_static; #[macro_use] extern crate log; -use core::nonzero::NonZero; +use nonzero::NonZeroUsize; use std::cell::{Cell, UnsafeCell}; use std::ops::Deref; use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult}; @@ -27,7 +27,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; // TODO: can we use the thread-id crate for this? #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct ThreadId(NonZero); +pub struct ThreadId(NonZeroUsize); lazy_static!{ static ref THREAD_COUNT: AtomicUsize = AtomicUsize::new(1); } @@ -35,7 +35,7 @@ impl ThreadId { #[allow(unsafe_code)] fn new() -> ThreadId { let number = THREAD_COUNT.fetch_add(1, Ordering::SeqCst); - ThreadId(NonZero::new(number).unwrap()) + ThreadId(NonZeroUsize::new(number).unwrap()) } pub fn current() -> ThreadId { THREAD_ID.with(|tls| tls.clone()) @@ -59,13 +59,13 @@ impl AtomicOptThreadId { #[allow(unsafe_code)] pub fn load(&self, ordering: Ordering) -> Option { let number = self.0.load(ordering); - NonZero::new(number).map(ThreadId) + NonZeroUsize::new(number).map(ThreadId) } #[allow(unsafe_code)] pub fn swap(&self, value: Option, ordering: Ordering) -> Option { let number = value.map(|id| id.0.get()).unwrap_or(0); let number = self.0.swap(number, ordering); - NonZero::new(number).map(ThreadId) + NonZeroUsize::new(number).map(ThreadId) } } diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index ddfb938850b..55225482b46 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -22,7 +22,8 @@ unstable = [ "euclid/unstable", "layout_thread/unstable", "msg/unstable", - "compositing/unstable" + "compositing/unstable", + "constellation/unstable", ] [dependencies]