diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-08-04 15:42:36 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-08-04 16:03:21 -0700 |
| commit | 68bde0a07396efb415d61047c6b2a8183f47ef30 (patch) | |
| tree | 2a0d63e3153abbe4f62f15d06ee72c94c7772b2d /src/libsync/comm | |
| parent | 9de20198aedb3c3419ee503755e04bcc198d3a94 (diff) | |
| download | rust-68bde0a07396efb415d61047c6b2a8183f47ef30.tar.gz rust-68bde0a07396efb415d61047c6b2a8183f47ef30.zip | |
stabilize atomics (now atomic)
This commit stabilizes the `std::sync::atomics` module, renaming it to `std::sync::atomic` to match library precedent elsewhere, and tightening up behavior around incorrect memory ordering annotations. The vast majority of the module is now `stable`. However, the `AtomicOption` type has been deprecated, since it is essentially unused and is not truly a primitive atomic type. It will eventually be replaced by a higher-level abstraction like MVars. Due to deprecations, this is a: [breaking-change]
Diffstat (limited to 'src/libsync/comm')
| -rw-r--r-- | src/libsync/comm/oneshot.rs | 32 | ||||
| -rw-r--r-- | src/libsync/comm/shared.rs | 90 | ||||
| -rw-r--r-- | src/libsync/comm/stream.rs | 62 | ||||
| -rw-r--r-- | src/libsync/comm/sync.rs | 12 |
4 files changed, 98 insertions, 98 deletions
diff --git a/src/libsync/comm/oneshot.rs b/src/libsync/comm/oneshot.rs index c9782db5c24..188bea83ac8 100644 --- a/src/libsync/comm/oneshot.rs +++ b/src/libsync/comm/oneshot.rs @@ -39,7 +39,7 @@ use core::mem; use rustrt::local::Local; use rustrt::task::{Task, BlockedTask}; -use atomics; +use atomic; use comm::Receiver; // Various states you can find a port in. @@ -49,7 +49,7 @@ static DISCONNECTED: uint = 2; pub struct Packet<T> { // Internal state of the chan/port pair (stores the blocked task as well) - state: atomics::AtomicUint, + state: atomic::AtomicUint, // One-shot data slot location data: Option<T>, // when used for the second time, a oneshot channel must be upgraded, and @@ -86,7 +86,7 @@ impl<T: Send> Packet<T> { Packet { data: None, upgrade: NothingSent, - state: atomics::AtomicUint::new(EMPTY), + state: atomic::AtomicUint::new(EMPTY), } } @@ -100,7 +100,7 @@ impl<T: Send> Packet<T> { self.data = Some(t); self.upgrade = SendUsed; - match self.state.swap(DATA, atomics::SeqCst) { + match self.state.swap(DATA, atomic::SeqCst) { // Sent the data, no one was waiting EMPTY => Ok(()), @@ -136,11 +136,11 @@ impl<T: Send> Packet<T> { pub fn recv(&mut self) -> Result<T, Failure<T>> { // Attempt to not block the task (it's a little expensive). If it looks // like we're not empty, then immediately go through to `try_recv`. - if self.state.load(atomics::SeqCst) == EMPTY { + if self.state.load(atomic::SeqCst) == EMPTY { let t: Box<Task> = Local::take(); t.deschedule(1, |task| { let n = unsafe { task.cast_to_uint() }; - match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) { + match self.state.compare_and_swap(EMPTY, n, atomic::SeqCst) { // Nothing on the channel, we legitimately block EMPTY => Ok(()), @@ -160,7 +160,7 @@ impl<T: Send> Packet<T> { } pub fn try_recv(&mut self) -> Result<T, Failure<T>> { - match self.state.load(atomics::SeqCst) { + match self.state.load(atomic::SeqCst) { EMPTY => Err(Empty), // We saw some data on the channel, but the channel can be used @@ -170,7 +170,7 @@ impl<T: Send> Packet<T> { // the state changes under our feet we'd rather just see that state // change. DATA => { - self.state.compare_and_swap(DATA, EMPTY, atomics::SeqCst); + self.state.compare_and_swap(DATA, EMPTY, atomic::SeqCst); match self.data.take() { Some(data) => Ok(data), None => unreachable!(), @@ -207,7 +207,7 @@ impl<T: Send> Packet<T> { }; self.upgrade = GoUp(up); - match self.state.swap(DISCONNECTED, atomics::SeqCst) { + match self.state.swap(DISCONNECTED, atomic::SeqCst) { // If the channel is empty or has data on it, then we're good to go. // Senders will check the data before the upgrade (in case we // plastered over the DATA state). @@ -223,7 +223,7 @@ impl<T: Send> Packet<T> { } pub fn drop_chan(&mut self) { - match self.state.swap(DISCONNECTED, atomics::SeqCst) { + match self.state.swap(DISCONNECTED, atomic::SeqCst) { DATA | DISCONNECTED | EMPTY => {} // If someone's waiting, we gotta wake them up @@ -235,7 +235,7 @@ impl<T: Send> Packet<T> { } pub fn drop_port(&mut self) { - match self.state.swap(DISCONNECTED, atomics::SeqCst) { + match self.state.swap(DISCONNECTED, atomic::SeqCst) { // An empty channel has nothing to do, and a remotely disconnected // channel also has nothing to do b/c we're about to run the drop // glue @@ -258,7 +258,7 @@ impl<T: Send> Packet<T> { // If Ok, the value is whether this port has data, if Err, then the upgraded // port needs to be checked instead of this one. pub fn can_recv(&mut self) -> Result<bool, Receiver<T>> { - match self.state.load(atomics::SeqCst) { + match self.state.load(atomic::SeqCst) { EMPTY => Ok(false), // Welp, we tried DATA => Ok(true), // we have some un-acquired data DISCONNECTED if self.data.is_some() => Ok(true), // we have data @@ -283,7 +283,7 @@ impl<T: Send> Packet<T> { // because there is data, or fail because there is an upgrade pending. pub fn start_selection(&mut self, task: BlockedTask) -> SelectionResult<T> { let n = unsafe { task.cast_to_uint() }; - match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) { + match self.state.compare_and_swap(EMPTY, n, atomic::SeqCst) { EMPTY => SelSuccess, DATA => SelCanceled(unsafe { BlockedTask::cast_from_uint(n) }), DISCONNECTED if self.data.is_some() => { @@ -317,7 +317,7 @@ impl<T: Send> Packet<T> { // // The return value indicates whether there's data on this port. pub fn abort_selection(&mut self) -> Result<bool, Receiver<T>> { - let state = match self.state.load(atomics::SeqCst) { + let state = match self.state.load(atomic::SeqCst) { // Each of these states means that no further activity will happen // with regard to abortion selection s @ EMPTY | @@ -326,7 +326,7 @@ impl<T: Send> Packet<T> { // If we've got a blocked task, then use an atomic to gain ownership // of it (may fail) - n => self.state.compare_and_swap(n, EMPTY, atomics::SeqCst) + n => self.state.compare_and_swap(n, EMPTY, atomic::SeqCst) }; // Now that we've got ownership of our state, figure out what to do @@ -367,6 +367,6 @@ impl<T: Send> Packet<T> { #[unsafe_destructor] impl<T: Send> Drop for Packet<T> { fn drop(&mut self) { - assert_eq!(self.state.load(atomics::SeqCst), DISCONNECTED); + assert_eq!(self.state.load(atomic::SeqCst), DISCONNECTED); } } diff --git a/src/libsync/comm/shared.rs b/src/libsync/comm/shared.rs index d13b2c32978..979b0ebcf8f 100644 --- a/src/libsync/comm/shared.rs +++ b/src/libsync/comm/shared.rs @@ -28,7 +28,7 @@ use rustrt::mutex::NativeMutex; use rustrt::task::{Task, BlockedTask}; use rustrt::thread::Thread; -use atomics; +use atomic; use mpsc = mpsc_queue; static DISCONNECTED: int = int::MIN; @@ -40,17 +40,17 @@ static MAX_STEALS: int = 1 << 20; pub struct Packet<T> { queue: mpsc::Queue<T>, - cnt: atomics::AtomicInt, // How many items are on this channel + cnt: atomic::AtomicInt, // How many items are on this channel steals: int, // How many times has a port received without blocking? - to_wake: atomics::AtomicUint, // Task to wake up + to_wake: atomic::AtomicUint, // Task to wake up // The number of channels which are currently using this packet. - channels: atomics::AtomicInt, + channels: atomic::AtomicInt, // See the discussion in Port::drop and the channel send methods for what // these are used for - port_dropped: atomics::AtomicBool, - sender_drain: atomics::AtomicInt, + port_dropped: atomic::AtomicBool, + sender_drain: atomic::AtomicInt, // this lock protects various portions of this implementation during // select() @@ -68,12 +68,12 @@ impl<T: Send> Packet<T> { pub fn new() -> Packet<T> { let p = Packet { queue: mpsc::Queue::new(), - cnt: atomics::AtomicInt::new(0), + cnt: atomic::AtomicInt::new(0), steals: 0, - to_wake: atomics::AtomicUint::new(0), - channels: atomics::AtomicInt::new(2), - port_dropped: atomics::AtomicBool::new(false), - sender_drain: atomics::AtomicInt::new(0), + to_wake: atomic::AtomicUint::new(0), + channels: atomic::AtomicInt::new(2), + port_dropped: atomic::AtomicBool::new(false), + sender_drain: atomic::AtomicInt::new(0), select_lock: unsafe { NativeMutex::new() }, }; return p; @@ -96,11 +96,11 @@ impl<T: Send> Packet<T> { pub fn inherit_blocker(&mut self, task: Option<BlockedTask>) { match task { Some(task) => { - assert_eq!(self.cnt.load(atomics::SeqCst), 0); - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.cnt.load(atomic::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); self.to_wake.store(unsafe { task.cast_to_uint() }, - atomics::SeqCst); - self.cnt.store(-1, atomics::SeqCst); + atomic::SeqCst); + self.cnt.store(-1, atomic::SeqCst); // This store is a little sketchy. What's happening here is // that we're transferring a blocker from a oneshot or stream @@ -138,7 +138,7 @@ impl<T: Send> Packet<T> { pub fn send(&mut self, t: T) -> Result<(), T> { // See Port::drop for what's going on - if self.port_dropped.load(atomics::SeqCst) { return Err(t) } + if self.port_dropped.load(atomic::SeqCst) { return Err(t) } // Note that the multiple sender case is a little trickier // semantically than the single sender case. The logic for @@ -165,12 +165,12 @@ impl<T: Send> Packet<T> { // preflight check serves as the definitive "this will never be // received". Once we get beyond this check, we have permanently // entered the realm of "this may be received" - if self.cnt.load(atomics::SeqCst) < DISCONNECTED + FUDGE { + if self.cnt.load(atomic::SeqCst) < DISCONNECTED + FUDGE { return Err(t) } self.queue.push(t); - match self.cnt.fetch_add(1, atomics::SeqCst) { + match self.cnt.fetch_add(1, atomic::SeqCst) { -1 => { self.take_to_wake().wake().map(|t| t.reawaken()); } @@ -187,9 +187,9 @@ impl<T: Send> Packet<T> { n if n < DISCONNECTED + FUDGE => { // see the comment in 'try' for a shared channel for why this // window of "not disconnected" is ok. - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); - if self.sender_drain.fetch_add(1, atomics::SeqCst) == 0 { + if self.sender_drain.fetch_add(1, atomic::SeqCst) == 0 { loop { // drain the queue, for info on the thread yield see the // discussion in try_recv @@ -202,7 +202,7 @@ impl<T: Send> Packet<T> { } // maybe we're done, if we're not the last ones // here, then we need to go try again. - if self.sender_drain.fetch_sub(1, atomics::SeqCst) == 1 { + if self.sender_drain.fetch_sub(1, atomic::SeqCst) == 1 { break } } @@ -242,15 +242,15 @@ impl<T: Send> Packet<T> { // Essentially the exact same thing as the stream decrement function. fn decrement(&mut self, task: BlockedTask) -> Result<(), BlockedTask> { - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); let n = unsafe { task.cast_to_uint() }; - self.to_wake.store(n, atomics::SeqCst); + self.to_wake.store(n, atomic::SeqCst); let steals = self.steals; self.steals = 0; - match self.cnt.fetch_sub(1 + steals, atomics::SeqCst) { - DISCONNECTED => { self.cnt.store(DISCONNECTED, atomics::SeqCst); } + match self.cnt.fetch_sub(1 + steals, atomic::SeqCst) { + DISCONNECTED => { self.cnt.store(DISCONNECTED, atomic::SeqCst); } // If we factor in our steals and notice that the channel has no // data, we successfully sleep n => { @@ -259,7 +259,7 @@ impl<T: Send> Packet<T> { } } - self.to_wake.store(0, atomics::SeqCst); + self.to_wake.store(0, atomic::SeqCst); Err(unsafe { BlockedTask::cast_from_uint(n) }) } @@ -311,9 +311,9 @@ impl<T: Send> Packet<T> { // might decrement steals. Some(data) => { if self.steals > MAX_STEALS { - match self.cnt.swap(0, atomics::SeqCst) { + match self.cnt.swap(0, atomic::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); } n => { let m = cmp::min(n, self.steals); @@ -330,7 +330,7 @@ impl<T: Send> Packet<T> { // See the discussion in the stream implementation for why we try // again. None => { - match self.cnt.load(atomics::SeqCst) { + match self.cnt.load(atomic::SeqCst) { n if n != DISCONNECTED => Err(Empty), _ => { match self.queue.pop() { @@ -348,20 +348,20 @@ impl<T: Send> Packet<T> { // Prepares this shared packet for a channel clone, essentially just bumping // a refcount. pub fn clone_chan(&mut self) { - self.channels.fetch_add(1, atomics::SeqCst); + self.channels.fetch_add(1, atomic::SeqCst); } // Decrement the reference count on a channel. This is called whenever a // Chan is dropped and may end up waking up a receiver. It's the receiver's // responsibility on the other end to figure out that we've disconnected. pub fn drop_chan(&mut self) { - match self.channels.fetch_sub(1, atomics::SeqCst) { + match self.channels.fetch_sub(1, atomic::SeqCst) { 1 => {} n if n > 1 => return, n => fail!("bad number of channels left {}", n), } - match self.cnt.swap(DISCONNECTED, atomics::SeqCst) { + match self.cnt.swap(DISCONNECTED, atomic::SeqCst) { -1 => { self.take_to_wake().wake().map(|t| t.reawaken()); } DISCONNECTED => {} n => { assert!(n >= 0); } @@ -371,11 +371,11 @@ impl<T: Send> Packet<T> { // See the long discussion inside of stream.rs for why the queue is drained, // and why it is done in this fashion. pub fn drop_port(&mut self) { - self.port_dropped.store(true, atomics::SeqCst); + self.port_dropped.store(true, atomic::SeqCst); let mut steals = self.steals; while { let cnt = self.cnt.compare_and_swap( - steals, DISCONNECTED, atomics::SeqCst); + steals, DISCONNECTED, atomic::SeqCst); cnt != DISCONNECTED && cnt != steals } { // See the discussion in 'try_recv' for why we yield @@ -391,8 +391,8 @@ impl<T: Send> Packet<T> { // Consumes ownership of the 'to_wake' field. fn take_to_wake(&mut self) -> BlockedTask { - let task = self.to_wake.load(atomics::SeqCst); - self.to_wake.store(0, atomics::SeqCst); + let task = self.to_wake.load(atomic::SeqCst); + self.to_wake.store(0, atomic::SeqCst); assert!(task != 0); unsafe { BlockedTask::cast_from_uint(task) } } @@ -407,15 +407,15 @@ impl<T: Send> Packet<T> { // This is different than the stream version because there's no need to peek // at the queue, we can just look at the local count. pub fn can_recv(&mut self) -> bool { - let cnt = self.cnt.load(atomics::SeqCst); + let cnt = self.cnt.load(atomic::SeqCst); cnt == DISCONNECTED || cnt - self.steals > 0 } // increment the count on the channel (used for selection) fn bump(&mut self, amt: int) -> int { - match self.cnt.fetch_add(amt, atomics::SeqCst) { + match self.cnt.fetch_add(amt, atomic::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); DISCONNECTED } n => n @@ -460,13 +460,13 @@ impl<T: Send> Packet<T> { // the channel count and figure out what we should do to make it // positive. let steals = { - let cnt = self.cnt.load(atomics::SeqCst); + let cnt = self.cnt.load(atomic::SeqCst); if cnt < 0 && cnt != DISCONNECTED {-cnt} else {0} }; let prev = self.bump(steals + 1); if prev == DISCONNECTED { - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); true } else { let cur = prev + steals + 1; @@ -474,7 +474,7 @@ impl<T: Send> Packet<T> { if prev < 0 { self.take_to_wake().trash(); } else { - while self.to_wake.load(atomics::SeqCst) != 0 { + while self.to_wake.load(atomic::SeqCst) != 0 { Thread::yield_now(); } } @@ -495,8 +495,8 @@ impl<T: Send> Drop for Packet<T> { // disconnection, but also a proper fence before the read of // `to_wake`, so this assert cannot be removed with also removing // the `to_wake` assert. - assert_eq!(self.cnt.load(atomics::SeqCst), DISCONNECTED); - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); - assert_eq!(self.channels.load(atomics::SeqCst), 0); + assert_eq!(self.cnt.load(atomic::SeqCst), DISCONNECTED); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); + assert_eq!(self.channels.load(atomic::SeqCst), 0); } } diff --git a/src/libsync/comm/stream.rs b/src/libsync/comm/stream.rs index f8a28b7600f..11c563301e0 100644 --- a/src/libsync/comm/stream.rs +++ b/src/libsync/comm/stream.rs @@ -26,7 +26,7 @@ use rustrt::local::Local; use rustrt::task::{Task, BlockedTask}; use rustrt::thread::Thread; -use atomics; +use atomic; use comm::Receiver; use spsc = spsc_queue; @@ -39,11 +39,11 @@ static MAX_STEALS: int = 1 << 20; pub struct Packet<T> { queue: spsc::Queue<Message<T>>, // internal queue for all message - cnt: atomics::AtomicInt, // How many items are on this channel + cnt: atomic::AtomicInt, // How many items are on this channel steals: int, // How many times has a port received without blocking? - to_wake: atomics::AtomicUint, // Task to wake up + to_wake: atomic::AtomicUint, // Task to wake up - port_dropped: atomics::AtomicBool, // flag if the channel has been destroyed. + port_dropped: atomic::AtomicBool, // flag if the channel has been destroyed. } pub enum Failure<T> { @@ -76,11 +76,11 @@ impl<T: Send> Packet<T> { Packet { queue: unsafe { spsc::Queue::new(128) }, - cnt: atomics::AtomicInt::new(0), + cnt: atomic::AtomicInt::new(0), steals: 0, - to_wake: atomics::AtomicUint::new(0), + to_wake: atomic::AtomicUint::new(0), - port_dropped: atomics::AtomicBool::new(false), + port_dropped: atomic::AtomicBool::new(false), } } @@ -89,7 +89,7 @@ impl<T: Send> Packet<T> { // If the other port has deterministically gone away, then definitely // must return the data back up the stack. Otherwise, the data is // considered as being sent. - if self.port_dropped.load(atomics::SeqCst) { return Err(t) } + if self.port_dropped.load(atomic::SeqCst) { return Err(t) } match self.do_send(Data(t)) { UpSuccess | UpDisconnected => {}, @@ -100,14 +100,14 @@ impl<T: Send> Packet<T> { pub fn upgrade(&mut self, up: Receiver<T>) -> UpgradeResult { // If the port has gone away, then there's no need to proceed any // further. - if self.port_dropped.load(atomics::SeqCst) { return UpDisconnected } + if self.port_dropped.load(atomic::SeqCst) { return UpDisconnected } self.do_send(GoUp(up)) } fn do_send(&mut self, t: Message<T>) -> UpgradeResult { self.queue.push(t); - match self.cnt.fetch_add(1, atomics::SeqCst) { + match self.cnt.fetch_add(1, atomic::SeqCst) { // As described in the mod's doc comment, -1 == wakeup -1 => UpWoke(self.take_to_wake()), // As as described before, SPSC queues must be >= -2 @@ -121,7 +121,7 @@ impl<T: Send> Packet<T> { // will never remove this data. We can only have at most one item to // drain (the port drains the rest). DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); let first = self.queue.pop(); let second = self.queue.pop(); assert!(second.is_none()); @@ -140,8 +140,8 @@ impl<T: Send> Packet<T> { // Consumes ownership of the 'to_wake' field. fn take_to_wake(&mut self) -> BlockedTask { - let task = self.to_wake.load(atomics::SeqCst); - self.to_wake.store(0, atomics::SeqCst); + let task = self.to_wake.load(atomic::SeqCst); + self.to_wake.store(0, atomic::SeqCst); assert!(task != 0); unsafe { BlockedTask::cast_from_uint(task) } } @@ -150,15 +150,15 @@ impl<T: Send> Packet<T> { // back if it shouldn't sleep. Note that this is the location where we take // steals into account. fn decrement(&mut self, task: BlockedTask) -> Result<(), BlockedTask> { - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); let n = unsafe { task.cast_to_uint() }; - self.to_wake.store(n, atomics::SeqCst); + self.to_wake.store(n, atomic::SeqCst); let steals = self.steals; self.steals = 0; - match self.cnt.fetch_sub(1 + steals, atomics::SeqCst) { - DISCONNECTED => { self.cnt.store(DISCONNECTED, atomics::SeqCst); } + match self.cnt.fetch_sub(1 + steals, atomic::SeqCst) { + DISCONNECTED => { self.cnt.store(DISCONNECTED, atomic::SeqCst); } // If we factor in our steals and notice that the channel has no // data, we successfully sleep n => { @@ -167,7 +167,7 @@ impl<T: Send> Packet<T> { } } - self.to_wake.store(0, atomics::SeqCst); + self.to_wake.store(0, atomic::SeqCst); Err(unsafe { BlockedTask::cast_from_uint(n) }) } @@ -214,9 +214,9 @@ impl<T: Send> Packet<T> { // adding back in whatever we couldn't factor into steals. Some(data) => { if self.steals > MAX_STEALS { - match self.cnt.swap(0, atomics::SeqCst) { + match self.cnt.swap(0, atomic::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); } n => { let m = cmp::min(n, self.steals); @@ -234,7 +234,7 @@ impl<T: Send> Packet<T> { } None => { - match self.cnt.load(atomics::SeqCst) { + match self.cnt.load(atomic::SeqCst) { n if n != DISCONNECTED => Err(Empty), // This is a little bit of a tricky case. We failed to pop @@ -263,7 +263,7 @@ impl<T: Send> Packet<T> { pub fn drop_chan(&mut self) { // Dropping a channel is pretty simple, we just flag it as disconnected // and then wakeup a blocker if there is one. - match self.cnt.swap(DISCONNECTED, atomics::SeqCst) { + match self.cnt.swap(DISCONNECTED, atomic::SeqCst) { -1 => { self.take_to_wake().wake().map(|t| t.reawaken()); } DISCONNECTED => {} n => { assert!(n >= 0); } @@ -290,7 +290,7 @@ impl<T: Send> Packet<T> { // sends are gated on this flag, so we're immediately guaranteed that // there are a bounded number of active sends that we'll have to deal // with. - self.port_dropped.store(true, atomics::SeqCst); + self.port_dropped.store(true, atomic::SeqCst); // Now that we're guaranteed to deal with a bounded number of senders, // we need to drain the queue. This draining process happens atomically @@ -303,7 +303,7 @@ impl<T: Send> Packet<T> { let mut steals = self.steals; while { let cnt = self.cnt.compare_and_swap( - steals, DISCONNECTED, atomics::SeqCst); + steals, DISCONNECTED, atomic::SeqCst); cnt != DISCONNECTED && cnt != steals } { loop { @@ -348,9 +348,9 @@ impl<T: Send> Packet<T> { // increment the count on the channel (used for selection) fn bump(&mut self, amt: int) -> int { - match self.cnt.fetch_add(amt, atomics::SeqCst) { + match self.cnt.fetch_add(amt, atomic::SeqCst) { DISCONNECTED => { - self.cnt.store(DISCONNECTED, atomics::SeqCst); + self.cnt.store(DISCONNECTED, atomic::SeqCst); DISCONNECTED } n => n @@ -400,7 +400,7 @@ impl<T: Send> Packet<T> { // of time until the data is actually sent. if was_upgrade { assert_eq!(self.steals, 0); - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); return Ok(true) } @@ -413,7 +413,7 @@ impl<T: Send> Packet<T> { // If we were previously disconnected, then we know for sure that there // is no task in to_wake, so just keep going let has_data = if prev == DISCONNECTED { - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); true // there is data, that data is that we're disconnected } else { let cur = prev + steals + 1; @@ -436,7 +436,7 @@ impl<T: Send> Packet<T> { if prev < 0 { self.take_to_wake().trash(); } else { - while self.to_wake.load(atomics::SeqCst) != 0 { + while self.to_wake.load(atomic::SeqCst) != 0 { Thread::yield_now(); } } @@ -475,7 +475,7 @@ impl<T: Send> Drop for Packet<T> { // disconnection, but also a proper fence before the read of // `to_wake`, so this assert cannot be removed with also removing // the `to_wake` assert. - assert_eq!(self.cnt.load(atomics::SeqCst), DISCONNECTED); - assert_eq!(self.to_wake.load(atomics::SeqCst), 0); + assert_eq!(self.cnt.load(atomic::SeqCst), DISCONNECTED); + assert_eq!(self.to_wake.load(atomic::SeqCst), 0); } } diff --git a/src/libsync/comm/sync.rs b/src/libsync/comm/sync.rs index e872952d9ee..aef02f654c1 100644 --- a/src/libsync/comm/sync.rs +++ b/src/libsync/comm/sync.rs @@ -44,12 +44,12 @@ use rustrt::local::Local; use rustrt::mutex::{NativeMutex, LockGuard}; use rustrt::task::{Task, BlockedTask}; -use atomics; +use atomic; pub struct Packet<T> { /// Only field outside of the mutex. Just done for kicks, but mainly because /// the other shared channel already had the code implemented - channels: atomics::AtomicUint, + channels: atomic::AtomicUint, /// The state field is protected by this mutex lock: NativeMutex, @@ -131,7 +131,7 @@ fn wakeup(task: BlockedTask, guard: LockGuard) { impl<T: Send> Packet<T> { pub fn new(cap: uint) -> Packet<T> { Packet { - channels: atomics::AtomicUint::new(1), + channels: atomic::AtomicUint::new(1), lock: unsafe { NativeMutex::new() }, state: UnsafeCell::new(State { disconnected: false, @@ -303,12 +303,12 @@ impl<T: Send> Packet<T> { // Prepares this shared packet for a channel clone, essentially just bumping // a refcount. pub fn clone_chan(&self) { - self.channels.fetch_add(1, atomics::SeqCst); + self.channels.fetch_add(1, atomic::SeqCst); } pub fn drop_chan(&self) { // Only flag the channel as disconnected if we're the last channel - match self.channels.fetch_sub(1, atomics::SeqCst) { + match self.channels.fetch_sub(1, atomic::SeqCst) { 1 => {} _ => return } @@ -411,7 +411,7 @@ impl<T: Send> Packet<T> { #[unsafe_destructor] impl<T: Send> Drop for Packet<T> { fn drop(&mut self) { - assert_eq!(self.channels.load(atomics::SeqCst), 0); + assert_eq!(self.channels.load(atomic::SeqCst), 0); let (_g, state) = self.lock(); assert!(state.queue.dequeue().is_none()); assert!(state.canceled.is_none()); |
