Skip to content

Rename dec/inc_weak_task_count to inc/dec_live_count, remove register/unregister_task #4858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/libcore/private/weak_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
let task = get_task_id();
// Expect the weak task service to be alive
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
unsafe { rust_inc_weak_task_count(); }
unsafe { rust_dec_kernel_live_count(); }
do fn&() {
let shutdown_port = swap_unwrap(&mut *shutdown_port);
f(shutdown_port)
}.finally || {
unsafe { rust_dec_weak_task_count(); }
unsafe { rust_inc_kernel_live_count(); }
// Service my have already exited
service.send(UnregisterWeakTask(task));
}
Expand Down Expand Up @@ -78,11 +78,11 @@ fn create_global_service() -> ~WeakTaskService {
let port = swap_unwrap(&mut *port);
// The weak task service is itself a weak task
debug!("weakening the weak service task");
unsafe { rust_inc_weak_task_count(); }
unsafe { rust_dec_kernel_live_count(); }
run_weak_task_service(port);
}.finally {
debug!("unweakening the weak service task");
unsafe { rust_dec_weak_task_count(); }
unsafe { rust_inc_kernel_live_count(); }
}
}

Expand Down Expand Up @@ -126,8 +126,8 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
}

extern {
unsafe fn rust_inc_weak_task_count();
unsafe fn rust_dec_weak_task_count();
unsafe fn rust_inc_kernel_live_count();
unsafe fn rust_dec_kernel_live_count();
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,15 @@ rust_get_global_data_ptr() {
}

extern "C" void
rust_inc_weak_task_count() {
rust_inc_kernel_live_count() {
rust_task *task = rust_get_current_task();
task->kernel->inc_weak_task_count();
task->kernel->inc_live_count();
}

extern "C" void
rust_dec_weak_task_count() {
rust_dec_kernel_live_count() {
rust_task *task = rust_get_current_task();
task->kernel->dec_weak_task_count();
task->kernel->dec_live_count();
}

//
Expand Down
37 changes: 10 additions & 27 deletions src/rt/rust_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,20 @@ rust_kernel::set_exit_status(int code) {
}

void
rust_kernel::register_task() {
KLOG_("Registering task");
rust_kernel::inc_live_count() {
uintptr_t new_non_weak_tasks = sync::increment(non_weak_tasks);
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
}

void
rust_kernel::dec_live_count() {
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
if (new_non_weak_tasks == 0) {
begin_shutdown();
}
}

void
rust_kernel::allow_scheduler_exit() {
scoped_lock with(sched_lock);
Expand All @@ -315,31 +323,6 @@ rust_kernel::allow_scheduler_exit() {
osmain_sched->allow_exit();
}

void
rust_kernel::unregister_task() {
KLOG_("Unregistering task");
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
if (new_non_weak_tasks == 0) {
begin_shutdown();
}
}

void
rust_kernel::inc_weak_task_count() {
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
if (new_non_weak_tasks == 0) {
begin_shutdown();
}
}

void
rust_kernel::dec_weak_task_count() {
uintptr_t new_non_weak_tasks = sync::increment(non_weak_tasks);
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
}

void
rust_kernel::begin_shutdown() {
{
Expand Down
6 changes: 2 additions & 4 deletions src/rt/rust_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ class rust_kernel {
rust_sched_id main_sched_id() { return main_scheduler; }
rust_sched_id osmain_sched_id() { return osmain_scheduler; }

void register_task();
void unregister_task();
void inc_weak_task_count();
void dec_weak_task_count();
void inc_live_count();
void dec_live_count();

void register_exit_function(spawn_fn runner, fn_env_pair *f);
};
Expand Down
4 changes: 2 additions & 2 deletions src/rt/rust_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ rust_scheduler::create_task(rust_task *spawner, const char *name) {
cur_thread = (thread_no + 1) % max_num_threads;
}
KLOG(kernel, kern, "Creating task %s, on thread %d.", name, thread_no);
kernel->register_task();
kernel->inc_live_count();
rust_sched_launcher *thread = threads[thread_no];
return thread->get_loop()->create_task(spawner, name);
}
Expand All @@ -138,7 +138,7 @@ rust_scheduler::release_task() {
need_exit = true;
}
}
kernel->unregister_task();
kernel->dec_live_count();
if (need_exit) {
exit();
}
Expand Down
4 changes: 2 additions & 2 deletions src/rt/rustrt.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ rust_raw_thread_start
rust_raw_thread_join_delete
rust_register_exit_function
rust_get_global_data_ptr
rust_inc_weak_task_count
rust_dec_weak_task_count
rust_inc_kernel_live_count
rust_dec_kernel_live_count
rust_get_exchange_count_ptr