Remove old comm-based weak task interface

This commit is contained in:
Brian Anderson 2013-01-21 19:22:55 -08:00
parent a3e087cefa
commit cc9ab2c033
5 changed files with 0 additions and 165 deletions

View File

@ -39,8 +39,6 @@ pub mod weak_task;
extern mod rustrt {
#[legacy_exports];
unsafe fn rust_task_weaken(ch: rust_port_id);
unsafe fn rust_task_unweaken(ch: rust_port_id);
unsafe fn rust_create_little_lock() -> rust_little_lock;
unsafe fn rust_destroy_little_lock(lock: rust_little_lock);
@ -92,111 +90,11 @@ fn test_run_in_bare_thread() unsafe {
}
}
#[allow(non_camel_case_types)] // runtime type
type rust_port_id = uint;
fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
let old = rusti::atomic_cxchg(address, oldval, newval);
old == oldval
}
/**
* Convert the current task to a 'weak' task temporarily
*
* As a weak task it will not be counted towards the runtime's set
* of live tasks. When there are no more outstanding live (non-weak) tasks
* the runtime will send an exit message on the provided channel.
*
* This function is super-unsafe. Do not use.
*
* # Safety notes
*
* * Weak tasks must either die on their own or exit upon receipt of
* the exit message. Failure to do so will cause the runtime to never
* exit
* * Tasks must not call `weaken_task` multiple times. This will
* break the kernel's accounting of live tasks.
* * Weak tasks must not be supervised. A supervised task keeps
* a reference to its parent, so the parent will not die.
*/
pub unsafe fn weaken_task(f: fn(oldcomm::Port<()>)) {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
unsafe {
rustrt::rust_task_weaken(cast::reinterpret_cast(&ch));
}
let _unweaken = Unweaken(ch);
f(po);
struct Unweaken {
ch: oldcomm::Chan<()>,
drop unsafe {
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
}
}
fn Unweaken(ch: oldcomm::Chan<()>) -> Unweaken {
Unweaken {
ch: ch
}
}
}
#[test]
pub fn test_weaken_task_then_unweaken() {
do task::try {
unsafe {
do weaken_task |_po| {
}
}
};
}
#[test]
pub fn test_weaken_task_wait() {
do task::spawn_unlinked {
unsafe {
do weaken_task |po| {
oldcomm::recv(po);
}
}
}
}
#[test]
pub fn test_weaken_task_stress() {
// Create a bunch of weak tasks
for iter::repeat(100u) {
do task::spawn {
unsafe {
do weaken_task |_po| {
}
}
}
do task::spawn_unlinked {
unsafe {
do weaken_task |po| {
// Wait for it to tell us to die
oldcomm::recv(po);
}
}
}
}
}
#[test]
#[ignore(cfg(windows))]
pub fn test_weaken_task_fail() {
let res = do task::try {
unsafe {
do weaken_task |_po| {
fail;
}
}
};
assert result::is_err(&res);
}
/****************************************************************************
* Shared state & exclusive ARC
****************************************************************************/

View File

@ -858,18 +858,6 @@ rust_compare_and_swap_ptr(intptr_t *address,
return sync::compare_and_swap(address, oldval, newval);
}
extern "C" CDECL void
rust_task_weaken(rust_port_id chan) {
rust_task *task = rust_get_current_task();
task->kernel->weaken_task(chan);
}
extern "C" CDECL void
rust_task_unweaken(rust_port_id chan) {
rust_task *task = rust_get_current_task();
task->kernel->unweaken_task(chan);
}
extern "C" void
rust_task_inhibit_kill(rust_task *task) {
task->inhibit_kill();

View File

@ -368,30 +368,6 @@ rust_kernel::unregister_task() {
}
}
void
rust_kernel::weaken_task(rust_port_id chan) {
{
scoped_lock with(weak_task_lock);
KLOG_("Weakening task with channel %" PRIdPTR, chan);
weak_task_chans.push_back(chan);
}
inc_weak_task_count();
}
void
rust_kernel::unweaken_task(rust_port_id chan) {
dec_weak_task_count();
{
scoped_lock with(weak_task_lock);
KLOG_("Unweakening task with channel %" PRIdPTR, chan);
std::vector<rust_port_id>::iterator iter =
std::find(weak_task_chans.begin(), weak_task_chans.end(), chan);
if (iter != weak_task_chans.end()) {
weak_task_chans.erase(iter);
}
}
}
void
rust_kernel::inc_weak_task_count() {
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
@ -407,23 +383,6 @@ rust_kernel::dec_weak_task_count() {
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
}
void
rust_kernel::end_weak_tasks() {
std::vector<rust_port_id> chancopies;
{
scoped_lock with(weak_task_lock);
chancopies = weak_task_chans;
weak_task_chans.clear();
}
while (!chancopies.empty()) {
rust_port_id chan = chancopies.back();
chancopies.pop_back();
KLOG_("Notifying weak task " PRIdPTR, chan);
uintptr_t token = 0;
send_to_port(chan, &token);
}
}
void
rust_kernel::begin_shutdown() {
{
@ -439,7 +398,6 @@ rust_kernel::begin_shutdown() {
run_exit_functions();
allow_scheduler_exit();
end_weak_tasks();
}
bool

View File

@ -119,14 +119,9 @@ class rust_kernel {
// An atomically updated count of the live, 'non-weak' tasks
uintptr_t non_weak_tasks;
// Protects weak_task_chans
lock_and_signal weak_task_lock;
// A list of weak tasks that need to be told when to exit
std::vector<rust_port_id> weak_task_chans;
rust_scheduler* get_scheduler_by_id_nolock(rust_sched_id id);
void allow_scheduler_exit();
void end_weak_tasks();
void begin_shutdown();
lock_and_signal at_exit_lock;
@ -180,8 +175,6 @@ public:
void register_task();
void unregister_task();
void weaken_task(rust_port_id chan);
void unweaken_task(rust_port_id chan);
void inc_weak_task_count();
void dec_weak_task_count();

View File

@ -61,8 +61,6 @@ rust_task_yield
rust_task_is_unwinding
rust_get_task
rust_get_stack_segment
rust_task_weaken
rust_task_unweaken
rust_log_str
start_task
vec_reserve_shared_actual