Skip to content

Commit

Permalink
auto merge of #8411 : bblum/rust/assorted-fixes, r=brson
Browse files Browse the repository at this point in the history
Each commit is pretty much what it says on the tin. r anybody.
  • Loading branch information
bors committed Aug 13, 2013
2 parents c99b2b9 + 5ac8c57 commit f02cc6b
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 479 deletions.
16 changes: 8 additions & 8 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#[missing_doc];

use cast::transmute_mut;
use unstable::finally::Finally;
use prelude::*;

/*
Expand Down Expand Up @@ -65,18 +66,17 @@ impl<T> Cell<T> {

/// Calls a closure with a reference to the value.
pub fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);
r
do self.with_mut_ref |ptr| { op(ptr) }
}

/// Calls a closure with a mutable reference to the value.
pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
let mut v = self.take();
let r = op(&mut v);
self.put_back(v);
r
let mut v = Some(self.take());
do (|| {
op(v.get_mut_ref())
}).finally {
self.put_back(v.take_unwrap());
}
}
}

Expand Down
27 changes: 20 additions & 7 deletions src/libstd/rt/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use kinds::Send;
use rt;
use rt::sched::Scheduler;
use rt::local::Local;
use rt::select::{Select, SelectPort};
use rt::select::{SelectInner, SelectPortInner};
use select::{Select, SelectPort};
use unstable::atomics::{AtomicUint, AtomicOption, Acquire, Relaxed, SeqCst};
use unstable::sync::UnsafeAtomicRcBox;
use util::Void;
Expand Down Expand Up @@ -113,7 +114,9 @@ impl<T> ChanOne<T> {
// 'do_resched' configures whether the scheduler immediately switches to
// the receiving task, or leaves the sending task still running.
fn try_send_inner(self, val: T, do_resched: bool) -> bool {
rtassert!(!rt::in_sched_context());
if do_resched {
rtassert!(!rt::in_sched_context());
}

let mut this = self;
let mut recvr_active = true;
Expand Down Expand Up @@ -215,7 +218,7 @@ impl<T> PortOne<T> {
}
}

impl<T> Select for PortOne<T> {
impl<T> SelectInner for PortOne<T> {
#[inline] #[cfg(not(test))]
fn optimistic_check(&mut self) -> bool {
unsafe { (*self.packet()).state.load(Acquire) == STATE_ONE }
Expand Down Expand Up @@ -318,7 +321,9 @@ impl<T> Select for PortOne<T> {
}
}

impl<T> SelectPort<T> for PortOne<T> {
impl<T> Select for PortOne<T> { }

impl<T> SelectPortInner<T> for PortOne<T> {
fn recv_ready(self) -> Option<T> {
let mut this = self;
let packet = this.packet();
Expand Down Expand Up @@ -349,6 +354,8 @@ impl<T> SelectPort<T> for PortOne<T> {
}
}

impl<T> SelectPort<T> for PortOne<T> { }

impl<T> Peekable<T> for PortOne<T> {
fn peek(&self) -> bool {
unsafe {
Expand Down Expand Up @@ -513,7 +520,7 @@ impl<T> Peekable<T> for Port<T> {
// of them, but a &Port<T> should also be selectable so you can select2 on it
// alongside a PortOne<U> without passing the port by value in recv_ready.

impl<'self, T> Select for &'self Port<T> {
impl<'self, T> SelectInner for &'self Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
do self.next.with_mut_ref |pone| { pone.optimistic_check() }
Expand All @@ -531,7 +538,9 @@ impl<'self, T> Select for &'self Port<T> {
}
}

impl<T> Select for Port<T> {
impl<'self, T> Select for &'self Port<T> { }

impl<T> SelectInner for Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
(&*self).optimistic_check()
Expand All @@ -548,7 +557,9 @@ impl<T> Select for Port<T> {
}
}

impl<'self, T> SelectPort<T> for &'self Port<T> {
impl<T> Select for Port<T> { }

impl<'self, T> SelectPortInner<T> for &'self Port<T> {
fn recv_ready(self) -> Option<T> {
match self.next.take().recv_ready() {
Some(StreamPayload { val, next }) => {
Expand All @@ -560,6 +571,8 @@ impl<'self, T> SelectPort<T> for &'self Port<T> {
}
}

impl<'self, T> SelectPort<T> for &'self Port<T> { }

pub struct SharedChan<T> {
// Just like Chan, but a shared AtomicOption instead of Cell
priv next: UnsafeAtomicRcBox<AtomicOption<StreamChanOne<T>>>
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/rt/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ impl Death {
rtassert!(self.unkillable == 0);
self.unkillable = 1;

// FIXME(#7544): See corresponding fixme at the callsite in task.rs.
// NB(#8192): Doesn't work with "let _ = ..."
// NB. See corresponding comment at the callsite in task.rs.
// FIXME(#8192): Doesn't work with "let _ = ..."
{ use util; util::ignore(group); }

// Step 1. Decide if we need to collect child failures synchronously.
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ pub mod tube;
/// Simple reimplementation of core::comm
pub mod comm;

/// Routines for select()ing on pipes.
pub mod select;
mod select;

// FIXME #5248 shouldn't be pub
/// The runtime needs to be able to put a pointer into thread-local storage.
Expand Down
Loading

0 comments on commit f02cc6b

Please sign in to comment.