Bypass lifecycle_lock in inhibit_kill/allow_kill for 3% to 5% speedup. Close #3213.

This commit is contained in:
Ben Blum 2012-08-21 18:03:41 -04:00
parent 0229bc4def
commit 47cca22d54
2 changed files with 10 additions and 4 deletions

View File

@ -1473,9 +1473,13 @@ extern mod rustrt {
fn rust_task_is_unwinding(task: *rust_task) -> bool;
fn rust_osmain_sched_id() -> sched_id;
#[rust_stack]
fn rust_task_inhibit_kill(t: *rust_task);
#[rust_stack]
fn rust_task_allow_kill(t: *rust_task);
#[rust_stack]
fn rust_task_inhibit_yield(t: *rust_task);
#[rust_stack]
fn rust_task_allow_yield(t: *rust_task);
fn rust_task_kill_other(task: *rust_task);
fn rust_task_kill_all(task: *rust_task);

View File

@ -631,27 +631,29 @@ rust_task::on_rust_stack() {
}
}
// NB: In inhibit_kill and allow_kill, helgrind would complain that we need to
// hold lifecycle_lock while accessing disallow_kill. Even though another
// killing task may access disallow_kill concurrently, this is not racy
// because the killer only cares if this task is blocking, and block() already
// uses proper locking. See https://github.com/mozilla/rust/issues/3213 .
void
rust_task::inhibit_kill() {
scoped_lock with(lifecycle_lock);
// Here might be good, though not mandatory, to check if we have to die.
disallow_kill++;
}
void
rust_task::allow_kill() {
scoped_lock with(lifecycle_lock);
assert(disallow_kill > 0 && "Illegal allow_kill(): already killable!");
disallow_kill--;
}
void rust_task::inhibit_yield() {
scoped_lock with(lifecycle_lock);
disallow_yield++;
}
void rust_task::allow_yield() {
scoped_lock with(lifecycle_lock);
assert(disallow_yield > 0 && "Illegal allow_yield(): already yieldable!");
disallow_yield--;
}