From 8ebdb37fd24435d08451625656cc53ebc814c3fa Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Mon, 5 Aug 2013 19:58:10 -0400 Subject: [PATCH] fix recv_ready for Port to take &self and not need to return a tuple. Close #8192. --- src/libstd/rt/comm.rs | 29 +++++++++++++++++++++++++---- src/libstd/rt/select.rs | 4 +--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 0cf223f3029..6dc44dd1193 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -508,7 +508,11 @@ fn peek(&self) -> bool { } } -impl Select for Port { +// XXX: Kind of gross. A Port should be selectable so you can make an array +// of them, but a &Port should also be selectable so you can select2 on it +// alongside a PortOne without passing the port by value in recv_ready. + +impl<'self, T> Select for &'self Port { #[inline] fn optimistic_check(&mut self) -> bool { do self.next.with_mut_ref |pone| { pone.optimistic_check() } @@ -526,12 +530,29 @@ fn unblock_from(&mut self) -> bool { } } -impl SelectPort<(T, Port)> for Port { - fn recv_ready(self) -> Option<(T, Port)> { +impl Select for Port { + #[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 for &'self Port { + fn recv_ready(self) -> Option { match self.next.take().recv_ready() { Some(StreamPayload { val, next }) => { self.next.put_back(next); - Some((val, self)) + Some(val) } None => None } diff --git a/src/libstd/rt/select.rs b/src/libstd/rt/select.rs index 006b777b71b..84ce36c3e6b 100644 --- a/src/libstd/rt/select.rs +++ b/src/libstd/rt/select.rs @@ -199,9 +199,7 @@ fn select_stream() { // 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); } } } -- 2.44.0