Skip to content

Commit

Permalink
Bypass lifecycle_lock in inhibit_kill/allow_kill for 3% to 5% speedup.
Browse files Browse the repository at this point in the history
…Close #3213.
  • Loading branch information
bblum committed Aug 21, 2012
1 parent 0229bc4 commit 47cca22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/libcore/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/rt/rust_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down

0 comments on commit 47cca22

Please sign in to comment.