Skip to content

Commit

Permalink
core: Turn task::unkillable, etc. into no-ops in newsched. rust-lang#…
Browse files Browse the repository at this point in the history
…6377

Not necessary just yet but they make ARC not work.
  • Loading branch information
brson committed May 13, 2013
1 parent b51bae1 commit 2dd9ea8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/libcore/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ mod local_heap;
pub mod logging;

/// Tools for testing the runtime
#[cfg(test)]
pub mod test;

/// Reference counting
Expand Down
50 changes: 33 additions & 17 deletions src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use task::rt::{task_id, sched_id};
use util;
use util::replace;
use unstable::finally::Finally;
use rt::{context, OldTaskContext};

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

Expand Down Expand Up @@ -558,23 +559,33 @@ pub fn get_scheduler() -> Scheduler {
* ~~~
*/
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
let t = rt::rust_get_task();
do (|| {
rt::rust_task_inhibit_kill(t);
if context() == OldTaskContext {
let t = rt::rust_get_task();
do (|| {
rt::rust_task_inhibit_kill(t);
f()
}).finally {
rt::rust_task_allow_kill(t);
}
} else {
// FIXME #6377
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 {
let t = rt::rust_get_task();
do (|| {
rt::rust_task_allow_kill(t);
if context() == OldTaskContext {
let t = rt::rust_get_task();
do (|| {
rt::rust_task_allow_kill(t);
f()
}).finally {
rt::rust_task_inhibit_kill(t);
}
} else {
// FIXME #6377
f()
}).finally {
rt::rust_task_inhibit_kill(t);
}
}
Expand All @@ -583,14 +594,19 @@ pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
let t = rt::rust_get_task();
do (|| {
rt::rust_task_inhibit_kill(t);
rt::rust_task_inhibit_yield(t);
if context() == OldTaskContext {
let t = rt::rust_get_task();
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);
}
} else {
// FIXME #6377
f()
}).finally {
rt::rust_task_allow_yield(t);
rt::rust_task_allow_kill(t);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/libcore/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,24 @@ mod tests {
assert!(*one == 1);
}
}

#[test]
fn newsched_shared_mutable_state() {
use task::spawn;
use rt::test::*;
use super::*;

do run_in_newsched_task {
unsafe {
let v = shared_mutable_state(10);
let vclone = clone_shared_mutable_state(&v);
do spawn {
unsafe {
let v = get_shared_immutable_state(&vclone);
assert!(*v == 10);
}
}
}
}
}
}

0 comments on commit 2dd9ea8

Please sign in to comment.