Skip to content

Commit 7c9d089

Browse files
committed
pipes: use finally to fix pipes::try_recv
1 parent e7a3bbd commit 7c9d089

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/libcore/pipes.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use kinds::Owned;
8888
use libc;
8989
use ops::Drop;
9090
use option::{None, Option, Some};
91+
use unstable::finally::Finally;
9192
use unstable::intrinsics;
9293
use ptr;
9394
use task;
@@ -396,28 +397,22 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
396397
let p_ = p.unwrap();
397398
let p = unsafe { &*p_ };
398399
399-
struct DropState<'self> {
400-
p: &'self PacketHeader,
401-
}
402-
403-
#[unsafe_destructor]
404-
impl<'self> Drop for DropState<'self> {
405-
fn finalize(&self) {
406-
unsafe {
407-
if task::failing() {
408-
self.p.state = Terminated;
409-
let old_task = swap_task(&mut self.p.blocked_task,
410-
ptr::null());
411-
if !old_task.is_null() {
412-
rustrt::rust_task_deref(old_task);
413-
}
400+
do (|| {
401+
try_recv_(p)
402+
}).finally {
403+
unsafe {
404+
if task::failing() {
405+
p.header.state = Terminated;
406+
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
407+
if !old_task.is_null() {
408+
rustrt::rust_task_deref(old_task);
414409
}
415410
}
416411
}
417412
}
413+
}
418414
419-
let _drop_state = DropState { p: &p.header };
420-
415+
fn try_recv_<T:Owned>(p: &Packet<T>) -> Option<T> {
421416
// optimistic path
422417
match p.header.state {
423418
Full => {
@@ -454,7 +449,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
454449
Blocked);
455450
match old_state {
456451
Empty => {
457-
debug!("no data available on %?, going to sleep.", p_);
452+
debug!("no data available on %?, going to sleep.", p);
458453
if count == 0 {
459454
wait_event(this);
460455
}

0 commit comments

Comments
 (0)