Skip to content

Commit ebd20b7

Browse files
committed
Rename dec/inc_weak_task_count to inc/dec_live_count and remove register_task/unregister_task. Closes #4768
1 parent 0c2b4ed commit ebd20b7

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed

src/libcore/private/weak_task.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
4040
let task = get_task_id();
4141
// Expect the weak task service to be alive
4242
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
43-
unsafe { rust_inc_weak_task_count(); }
43+
unsafe { rust_inc_kernel_live_count(); }
4444
do fn&() {
4545
let shutdown_port = swap_unwrap(&mut *shutdown_port);
4646
f(shutdown_port)
4747
}.finally || {
48-
unsafe { rust_dec_weak_task_count(); }
48+
unsafe { rust_dec_kernel_live_count(); }
4949
// Service my have already exited
5050
service.send(UnregisterWeakTask(task));
5151
}
@@ -78,11 +78,11 @@ fn create_global_service() -> ~WeakTaskService {
7878
let port = swap_unwrap(&mut *port);
7979
// The weak task service is itself a weak task
8080
debug!("weakening the weak service task");
81-
unsafe { rust_inc_weak_task_count(); }
81+
unsafe { rust_inc_kernel_live_count(); }
8282
run_weak_task_service(port);
8383
}.finally {
8484
debug!("unweakening the weak service task");
85-
unsafe { rust_dec_weak_task_count(); }
85+
unsafe { rust_dec_kernel_live_count(); }
8686
}
8787
}
8888

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

128128
extern {
129-
unsafe fn rust_inc_weak_task_count();
130-
unsafe fn rust_dec_weak_task_count();
129+
unsafe fn rust_inc_kernel_live_count();
130+
unsafe fn rust_dec_kernel_live_count();
131131
}
132132

133133
#[test]

src/rt/rust_builtin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,15 @@ rust_get_global_data_ptr() {
945945
}
946946

947947
extern "C" void
948-
rust_inc_weak_task_count() {
948+
rust_inc_kernel_live_count() {
949949
rust_task *task = rust_get_current_task();
950-
task->kernel->inc_weak_task_count();
950+
task->kernel->inc_live_count();
951951
}
952952

953953
extern "C" void
954-
rust_dec_weak_task_count() {
954+
rust_dec_kernel_live_count() {
955955
rust_task *task = rust_get_current_task();
956-
task->kernel->dec_weak_task_count();
956+
task->kernel->dec_live_count();
957957
}
958958

959959
//

src/rt/rust_kernel.cpp

Lines changed: 10 additions & 27 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,6 @@ rust_raw_thread_start
189189
rust_raw_thread_join_delete
190190
rust_register_exit_function
191191
rust_get_global_data_ptr
192-
rust_inc_weak_task_count
193-
rust_dec_weak_task_count
192+
rust_inc_kernel_live_count
193+
rust_dec_kernel_live_count
194194
rust_get_exchange_count_ptr

0 commit comments

Comments
 (0)