Skip to content

Commit bc2d147

Browse files
committed
auto merge of #4858 : z0w0/rust/rm_weak_task_count, r=graydon
2 parents 21a0d52 + 0db527e commit bc2d147

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed

src/libcore/private/weak_task.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
4141
let task = get_task_id();
4242
// Expect the weak task service to be alive
4343
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
44-
unsafe { rust_inc_weak_task_count(); }
44+
unsafe { rust_dec_kernel_live_count(); }
4545
do fn&() {
4646
let shutdown_port = swap_unwrap(&mut *shutdown_port);
4747
f(shutdown_port)
4848
}.finally || {
49-
unsafe { rust_dec_weak_task_count(); }
49+
unsafe { rust_inc_kernel_live_count(); }
5050
// Service my have already exited
5151
service.send(UnregisterWeakTask(task));
5252
}
@@ -79,11 +79,11 @@ fn create_global_service() -> ~WeakTaskService {
7979
let port = swap_unwrap(&mut *port);
8080
// The weak task service is itself a weak task
8181
debug!("weakening the weak service task");
82-
unsafe { rust_inc_weak_task_count(); }
82+
unsafe { rust_dec_kernel_live_count(); }
8383
run_weak_task_service(port);
8484
}.finally {
8585
debug!("unweakening the weak service task");
86-
unsafe { rust_dec_weak_task_count(); }
86+
unsafe { rust_inc_kernel_live_count(); }
8787
}
8888
}
8989

@@ -127,8 +127,8 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
127127
}
128128

129129
extern {
130-
unsafe fn rust_inc_weak_task_count();
131-
unsafe fn rust_dec_weak_task_count();
130+
unsafe fn rust_inc_kernel_live_count();
131+
unsafe fn rust_dec_kernel_live_count();
132132
}
133133

134134
#[test]

src/rt/rust_builtin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -939,15 +939,15 @@ rust_get_global_data_ptr() {
939939
}
940940

941941
extern "C" void
942-
rust_inc_weak_task_count() {
942+
rust_inc_kernel_live_count() {
943943
rust_task *task = rust_get_current_task();
944-
task->kernel->inc_weak_task_count();
944+
task->kernel->inc_live_count();
945945
}
946946

947947
extern "C" void
948-
rust_dec_weak_task_count() {
948+
rust_dec_kernel_live_count() {
949949
rust_task *task = rust_get_current_task();
950-
task->kernel->dec_weak_task_count();
950+
task->kernel->dec_live_count();
951951
}
952952

953953
//

src/rt/rust_kernel.cpp

+10-27
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,20 @@ rust_kernel::set_exit_status(int code) {
291291
}
292292

293293
void
294-
rust_kernel::register_task() {
295-
KLOG_("Registering task");
294+
rust_kernel::inc_live_count() {
296295
uintptr_t new_non_weak_tasks = sync::increment(non_weak_tasks);
297296
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
298297
}
299298

299+
void
300+
rust_kernel::dec_live_count() {
301+
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
302+
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
303+
if (new_non_weak_tasks == 0) {
304+
begin_shutdown();
305+
}
306+
}
307+
300308
void
301309
rust_kernel::allow_scheduler_exit() {
302310
scoped_lock with(sched_lock);
@@ -315,31 +323,6 @@ rust_kernel::allow_scheduler_exit() {
315323
osmain_sched->allow_exit();
316324
}
317325

318-
void
319-
rust_kernel::unregister_task() {
320-
KLOG_("Unregistering task");
321-
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
322-
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
323-
if (new_non_weak_tasks == 0) {
324-
begin_shutdown();
325-
}
326-
}
327-
328-
void
329-
rust_kernel::inc_weak_task_count() {
330-
uintptr_t new_non_weak_tasks = sync::decrement(non_weak_tasks);
331-
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
332-
if (new_non_weak_tasks == 0) {
333-
begin_shutdown();
334-
}
335-
}
336-
337-
void
338-
rust_kernel::dec_weak_task_count() {
339-
uintptr_t new_non_weak_tasks = sync::increment(non_weak_tasks);
340-
KLOG_("New non-weak tasks %" PRIdPTR, new_non_weak_tasks);
341-
}
342-
343326
void
344327
rust_kernel::begin_shutdown() {
345328
{

src/rt/rust_kernel.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ class rust_kernel {
160160
rust_sched_id main_sched_id() { return main_scheduler; }
161161
rust_sched_id osmain_sched_id() { return osmain_scheduler; }
162162

163-
void register_task();
164-
void unregister_task();
165-
void inc_weak_task_count();
166-
void dec_weak_task_count();
163+
void inc_live_count();
164+
void dec_live_count();
167165

168166
void register_exit_function(spawn_fn runner, fn_env_pair *f);
169167
};

src/rt/rust_scheduler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ rust_scheduler::create_task(rust_task *spawner, const char *name) {
123123
cur_thread = (thread_no + 1) % max_num_threads;
124124
}
125125
KLOG(kernel, kern, "Creating task %s, on thread %d.", name, thread_no);
126-
kernel->register_task();
126+
kernel->inc_live_count();
127127
rust_sched_launcher *thread = threads[thread_no];
128128
return thread->get_loop()->create_task(spawner, name);
129129
}
@@ -138,7 +138,7 @@ rust_scheduler::release_task() {
138138
need_exit = true;
139139
}
140140
}
141-
kernel->unregister_task();
141+
kernel->dec_live_count();
142142
if (need_exit) {
143143
exit();
144144
}

src/rt/rustrt.def.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,6 @@ rust_raw_thread_start
188188
rust_raw_thread_join_delete
189189
rust_register_exit_function
190190
rust_get_global_data_ptr
191-
rust_inc_weak_task_count
192-
rust_dec_weak_task_count
191+
rust_inc_kernel_live_count
192+
rust_dec_kernel_live_count
193193
rust_get_exchange_count_ptr

0 commit comments

Comments
 (0)