Skip to content

Commit b2cf04a

Browse files
committed
---
yaml --- r: 149278 b: refs/heads/try2 c: 6fe775e h: refs/heads/master v: v3
1 parent a3ecc47 commit b2cf04a

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 58678dc229a8e2db141314a17e7bc0ea09b8a08a
8+
refs/heads/try2: 6fe775e2b5eaa77dd49c1d9a234c67d52e5f9087
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/comm/shared.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/// module. You'll also note that the implementation of the shared and stream
1919
/// channels are quite similar, and this is no coincidence!
2020
21+
use cmp;
2122
use int;
2223
use iter::Iterator;
2324
use kinds::Send;
@@ -35,6 +36,9 @@ use mpsc = sync::mpsc_queue;
3536

3637
static DISCONNECTED: int = int::MIN;
3738
static FUDGE: int = 1024;
39+
#[cfg(test)]
40+
static MAX_STEALS: int = 5;
41+
#[cfg(not(test))]
3842
static MAX_STEALS: int = 1 << 20;
3943

4044
pub struct Packet<T> {
@@ -307,7 +311,11 @@ impl<T: Send> Packet<T> {
307311
DISCONNECTED => {
308312
self.cnt.store(DISCONNECTED, atomics::SeqCst);
309313
}
310-
n => { self.steals -= n; }
314+
n => {
315+
let m = cmp::min(n, self.steals);
316+
self.steals -= m;
317+
self.cnt.fetch_add(n - m, atomics::SeqCst);
318+
}
311319
}
312320
assert!(self.steals >= 0);
313321
}

branches/try2/src/libstd/comm/stream.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/// High level implementation details can be found in the comment of the parent
1818
/// module.
1919
20+
use cmp;
2021
use comm::Port;
2122
use int;
2223
use iter::Iterator;
@@ -32,6 +33,9 @@ use sync::atomics;
3233
use vec::OwnedVector;
3334

3435
static DISCONNECTED: int = int::MIN;
36+
#[cfg(test)]
37+
static MAX_STEALS: int = 5;
38+
#[cfg(not(test))]
3539
static MAX_STEALS: int = 1 << 20;
3640

3741
pub struct Packet<T> {
@@ -198,19 +202,28 @@ impl<T: Send> Packet<T> {
198202
pub fn try_recv(&mut self) -> Result<T, Failure<T>> {
199203
match self.queue.pop() {
200204
// If we stole some data, record to that effect (this will be
201-
// factored into cnt later on). Note that we don't allow steals to
202-
// grow without bound in order to prevent eventual overflow of
203-
// either steals or cnt as an overflow would have catastrophic
204-
// results. Also note that we don't unconditionally set steals to 0
205-
// because it can be true that steals > cnt.
205+
// factored into cnt later on).
206+
//
207+
// Note that we don't allow steals to grow without bound in order to
208+
// prevent eventual overflow of either steals or cnt as an overflow
209+
// would have catastrophic results. Sometimes, steals > cnt, but
210+
// other times cnt > steals, so we don't know the relation between
211+
// steals and cnt. This code path is executed only rarely, so we do
212+
// a pretty slow operation, of swapping 0 into cnt, taking steals
213+
// down as much as possible (without going negative), and then
214+
// adding back in whatever we couldn't factor into steals.
206215
Some(data) => {
207216
self.steals += 1;
208217
if self.steals > MAX_STEALS {
209218
match self.cnt.swap(0, atomics::SeqCst) {
210219
DISCONNECTED => {
211220
self.cnt.store(DISCONNECTED, atomics::SeqCst);
212221
}
213-
n => { self.steals -= n; }
222+
n => {
223+
let m = cmp::min(n, self.steals);
224+
self.steals -= m;
225+
self.cnt.fetch_add(n - m, atomics::SeqCst);
226+
}
214227
}
215228
assert!(self.steals >= 0);
216229
}

branches/try2/src/libstd/num/f32.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,6 @@ impl num::FromStrRadix for f32 {
867867
#[cfg(test)]
868868
mod tests {
869869
use f32::*;
870-
use prelude::*;
871870

872871
use num::*;
873872
use num;

branches/try2/src/libstd/num/f64.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,6 @@ impl num::FromStrRadix for f64 {
869869
#[cfg(test)]
870870
mod tests {
871871
use f64::*;
872-
use prelude::*;
873872

874873
use num::*;
875874
use num;

branches/try2/src/libstd/task.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use rt::task::Task;
6565
use str::{Str, SendStr, IntoMaybeOwned};
6666

6767
#[cfg(test)] use any::{AnyOwnExt, AnyRefExt};
68-
#[cfg(test)] use ptr;
6968
#[cfg(test)] use result;
7069

7170
/// Indicates the manner in which a task exited.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// verify that an error is raised when trying to move out of a
12+
// borrowed path.
13+
14+
fn main() {
15+
let a = ~~2;
16+
let b = &a;
17+
18+
let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
19+
}

0 commit comments

Comments
 (0)