Skip to content

Commit

Permalink
Reorganise Select traits to not expose internal runtime types. Close r…
Browse files Browse the repository at this point in the history
  • Loading branch information
bblum committed Aug 12, 2013
1 parent ee5cfb0 commit c8c09d4
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 313 deletions.
23 changes: 17 additions & 6 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 @@ -215,7 +216,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 +319,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 +352,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 +518,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 +536,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 +555,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 +569,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
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 c8c09d4

Please sign in to comment.