diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index 832cdca12f0..0884c46ee84 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -305,7 +305,6 @@ impl Packet { // See the discussion in the stream implementation for why we we // might decrement steals. Some(data) => { - self.steals += 1; if self.steals > MAX_STEALS { match self.cnt.swap(0, atomics::SeqCst) { DISCONNECTED => { @@ -314,11 +313,12 @@ impl Packet { n => { let m = cmp::min(n, self.steals); self.steals -= m; - self.cnt.fetch_add(n - m, atomics::SeqCst); + self.bump(n - m); } } assert!(self.steals >= 0); } + self.steals += 1; Ok(data) } diff --git a/src/libstd/comm/stream.rs b/src/libstd/comm/stream.rs index f1988dbbeed..0bacf1e1d28 100644 --- a/src/libstd/comm/stream.rs +++ b/src/libstd/comm/stream.rs @@ -213,7 +213,6 @@ impl Packet { // down as much as possible (without going negative), and then // adding back in whatever we couldn't factor into steals. Some(data) => { - self.steals += 1; if self.steals > MAX_STEALS { match self.cnt.swap(0, atomics::SeqCst) { DISCONNECTED => { @@ -222,11 +221,12 @@ impl Packet { n => { let m = cmp::min(n, self.steals); self.steals -= m; - self.cnt.fetch_add(n - m, atomics::SeqCst); + self.bump(n - m); } } assert!(self.steals >= 0); } + self.steals += 1; match data { Data(t) => Ok(t), GoUp(up) => Err(Upgraded(up)),