mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
auto merge of #4858 : z0w0/rust/rm_weak_task_count, r=graydon
This commit is contained in:
commit
bc2d147847
@ -41,12 +41,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));
|
||||
}
|
||||
@ -79,11 +79,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(); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,8 +127,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]
|
||||
|
@ -939,15 +939,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();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -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);
|
||||
@ -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() {
|
||||
{
|
||||
|
@ -160,10 +160,8 @@ public:
|
||||
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);
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
@ -138,7 +138,7 @@ rust_scheduler::release_task() {
|
||||
need_exit = true;
|
||||
}
|
||||
}
|
||||
kernel->unregister_task();
|
||||
kernel->dec_live_count();
|
||||
if (need_exit) {
|
||||
exit();
|
||||
}
|
||||
|
@ -188,6 +188,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
|
||||
|
Loading…
Reference in New Issue
Block a user