Fix an apparent race in pipes.

Also removed some unsafety in pipes and added vec::consume_mut.
This commit is contained in:
Eric Holk
2012-08-02 18:55:31 -07:00
parent 110ff312df
commit bd195518c7
2 changed files with 35 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ import libc::size_t;
export append;
export append_one;
export consume;
export consume, consume_mut;
export init_op;
export is_empty;
export is_not_empty;
@@ -490,6 +490,17 @@ fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe {
unsafe::set_len(v, 0);
}
fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +T)) unsafe {
do as_buf(v) |p, ln| {
for uint::range(0, ln) |i| {
let x <- *ptr::offset(p, i);
f(i, x);
}
}
unsafe::set_len(v, 0);
}
/// Remove the last element from a vector and return it
fn pop<T>(&v: ~[const T]) -> T {
let ln = len(v);