Skip to content

Misc task-and-comm-related cleanup #8383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/libstd/rt/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ impl<T> Peekable<T> for Port<T> {
}
}

impl<T> Select for Port<T> {
// XXX: Kind of gross. A Port<T> should be selectable so you can make an array
// 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> {
#[inline]
fn optimistic_check(&mut self) -> bool {
do self.next.with_mut_ref |pone| { pone.optimistic_check() }
Expand All @@ -526,12 +530,29 @@ impl<T> Select for Port<T> {
}
}

impl<T> SelectPort<(T, Port<T>)> for Port<T> {
fn recv_ready(self) -> Option<(T, Port<T>)> {
impl<T> Select for Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
(&*self).optimistic_check()
}

#[inline]
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
(&*self).block_on(sched, task)
}

#[inline]
fn unblock_from(&mut self) -> bool {
(&*self).unblock_from()
}
}

impl<'self, T> SelectPort<T> for &'self Port<T> {
fn recv_ready(self) -> Option<T> {
match self.next.take().recv_ready() {
Some(StreamPayload { val, next }) => {
self.next.put_back(next);
Some((val, self))
Some(val)
}
None => None
}
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/rt/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ impl Death {
#[inline]
pub fn assert_may_sleep(&self) {
if self.wont_sleep != 0 {
rtabort!("illegal atomic-sleep: can't deschedule inside atomically()");
rtabort!("illegal atomic-sleep: attempt to reschedule while \
using an Exclusive or LittleLock");
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/rt/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ mod test {
// get it back out
util::swap(port.get_mut_ref(), &mut ports[index]);
// NB. Not recv(), because optimistic_check randomly fails.
let (data, new_port) = port.take_unwrap().recv_ready().unwrap();
assert!(data == 31337);
port = Some(new_port);
assert!(port.get_ref().recv_ready().unwrap() == 31337);
}
}
}
Expand Down