diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-05-01 07:49:10 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-05-01 07:50:13 -0700 |
| commit | 7c9d089ee732c2930898574d9ecedbb01efe0eb9 (patch) | |
| tree | 84b3529a067a5494e490ec4612cb3ccf987d7aa4 | |
| parent | e7a3bbd76c77fa7a878ecd86dcb5c772164cbb51 (diff) | |
| download | rust-7c9d089ee732c2930898574d9ecedbb01efe0eb9.tar.gz rust-7c9d089ee732c2930898574d9ecedbb01efe0eb9.zip | |
pipes: use finally to fix pipes::try_recv
| -rw-r--r-- | src/libcore/pipes.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 82dc598c750..145997fcb4b 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -88,6 +88,7 @@ use kinds::Owned; use libc; use ops::Drop; use option::{None, Option, Some}; +use unstable::finally::Finally; use unstable::intrinsics; use ptr; use task; @@ -396,28 +397,22 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>) let p_ = p.unwrap(); let p = unsafe { &*p_ }; - struct DropState<'self> { - p: &'self PacketHeader, - } - - #[unsafe_destructor] - impl<'self> Drop for DropState<'self> { - fn finalize(&self) { - unsafe { - if task::failing() { - self.p.state = Terminated; - let old_task = swap_task(&mut self.p.blocked_task, - ptr::null()); - if !old_task.is_null() { - rustrt::rust_task_deref(old_task); - } + do (|| { + try_recv_(p) + }).finally { + unsafe { + if task::failing() { + p.header.state = Terminated; + let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); + if !old_task.is_null() { + rustrt::rust_task_deref(old_task); } } } } +} - let _drop_state = DropState { p: &p.header }; - +fn try_recv_<T:Owned>(p: &Packet<T>) -> Option<T> { // optimistic path match p.header.state { Full => { @@ -454,7 +449,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>) Blocked); match old_state { Empty => { - debug!("no data available on %?, going to sleep.", p_); + debug!("no data available on %?, going to sleep.", p); if count == 0 { wait_event(this); } |
