Skip to content

Commit

Permalink
core: Replace uses of 'drop' in task module with 'finally'. #5379
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Apr 29, 2013
1 parent 3290110 commit c1fdace
Showing 1 changed file with 21 additions and 56 deletions.
77 changes: 21 additions & 56 deletions src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use result;
use task::rt::{task_id, sched_id, rust_task};
use util;
use util::replace;
use unstable::finally::Finally;

#[cfg(test)] use comm::SharedChan;

Expand Down Expand Up @@ -591,76 +592,40 @@ pub fn get_scheduler() -> Scheduler {
* ~~~
*/
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
struct AllowFailure {
t: *rust_task,
drop {
unsafe {
rt::rust_task_allow_kill(self.t);
}
}
}

fn AllowFailure(t: *rust_task) -> AllowFailure{
AllowFailure {
t: t
}
}

let t = rt::rust_get_task();
let _allow_failure = AllowFailure(t);
rt::rust_task_inhibit_kill(t);
f()
do (|| {
rt::rust_task_inhibit_kill(t);
f()
}).finally {
rt::rust_task_allow_kill(t);
}
}

/// The inverse of unkillable. Only ever to be used nested in unkillable().
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
struct DisallowFailure {
t: *rust_task,
drop {
unsafe {
rt::rust_task_inhibit_kill(self.t);
}
}
}

fn DisallowFailure(t: *rust_task) -> DisallowFailure {
DisallowFailure {
t: t
}
}

let t = rt::rust_get_task();
let _allow_failure = DisallowFailure(t);
rt::rust_task_allow_kill(t);
f()
do (|| {
rt::rust_task_allow_kill(t);
f()
}).finally {
rt::rust_task_inhibit_kill(t);
}
}

/**
* A stronger version of unkillable that also inhibits scheduling operations.
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
struct DeferInterrupts {
t: *rust_task,
drop {
unsafe {
rt::rust_task_allow_yield(self.t);
rt::rust_task_allow_kill(self.t);
}
}
}

fn DeferInterrupts(t: *rust_task) -> DeferInterrupts {
DeferInterrupts {
t: t
}
}

let t = rt::rust_get_task();
let _interrupts = DeferInterrupts(t);
rt::rust_task_inhibit_kill(t);
rt::rust_task_inhibit_yield(t);
f()
do (|| {
rt::rust_task_inhibit_kill(t);
rt::rust_task_inhibit_yield(t);
f()
}).finally {
rt::rust_task_allow_yield(t);
rt::rust_task_allow_kill(t);
}
}

#[test] #[should_fail] #[ignore(cfg(windows))]
Expand Down

9 comments on commit c1fdace

@bors
Copy link
Contributor

@bors bors commented on c1fdace Apr 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from graydon
at brson@c1fdace

@bors
Copy link
Contributor

@bors bors commented on c1fdace Apr 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging brson/rust/task-drop = c1fdace into auto

@bors
Copy link
Contributor

@bors bors commented on c1fdace Apr 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brson/rust/task-drop = c1fdace merged ok, testing candidate = 59178731

@bors
Copy link
Contributor

@bors bors commented on c1fdace Apr 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c1fdace May 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from graydon
at brson@c1fdace

@bors
Copy link
Contributor

@bors bors commented on c1fdace May 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging brson/rust/task-drop = c1fdace into auto

@bors
Copy link
Contributor

@bors bors commented on c1fdace May 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brson/rust/task-drop = c1fdace merged ok, testing candidate = c1ea72d

@bors
Copy link
Contributor

@bors bors commented on c1fdace May 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c1fdace May 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = c1ea72d

Please sign in to comment.