Skip to content

Commit 98d253c

Browse files
committed
---
yaml --- r: 14655 b: refs/heads/try c: f057f00 h: refs/heads/master i: 14653: cd8fb03 14651: 25be79d 14647: 13b4fe0 14639: 31c4c2b 14623: 8c55a30 14591: b754f0a v: v3
1 parent 885594c commit 98d253c

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 8efe4b89137646c5315677b029d4158424c126cc
5+
refs/heads/try: f057f003009fc84e2e80b3df7673eb9cae7f4810
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rt/rust_task_thread.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,26 @@ rust_task_thread::number_of_live_tasks() {
122122
void
123123
rust_task_thread::reap_dead_tasks() {
124124
I(this, lock.lock_held_by_current_thread());
125+
125126
if (dead_tasks.length() == 0) {
126127
return;
127128
}
128129

130+
A(this, dead_tasks.length() == 1,
131+
"Only one task should die during a single turn of the event loop");
132+
129133
// First make a copy of the dead_task list with the lock held
130-
size_t dead_tasks_len = dead_tasks.length();
131-
rust_task **dead_tasks_copy = (rust_task**)
132-
srv->malloc(sizeof(rust_task*) * dead_tasks_len);
133-
for (size_t i = 0; i < dead_tasks_len; ++i) {
134-
dead_tasks_copy[i] = dead_tasks.pop_value();
135-
}
134+
rust_task *dead_task = dead_tasks.pop_value();
136135

137-
// Now unlock again because we have to actually free the dead tasks,
138-
// and that may end up wanting to lock the kernel lock. We have
139-
// a kernel lock -> scheduler lock locking order that we need
140-
// to maintain.
136+
// Dereferencing the task will probably cause it to be released
137+
// from the scheduler, which may end up trying to take this lock
141138
lock.unlock();
142139

143-
for (size_t i = 0; i < dead_tasks_len; ++i) {
144-
rust_task *task = dead_tasks_copy[i];
145-
// Release the task from the kernel so nobody else can get at it
146-
kernel->release_task_id(task->id);
147-
task->delete_all_stacks();
148-
// Deref the task, which may cause it to request us to release it
149-
task->deref();
150-
}
151-
srv->free(dead_tasks_copy);
140+
// Release the task from the kernel so nobody else can get at it
141+
kernel->release_task_id(dead_task->id);
142+
dead_task->delete_all_stacks();
143+
// Deref the task, which may cause it to request us to release it
144+
dead_task->deref();
152145

153146
lock.lock();
154147
}

0 commit comments

Comments
 (0)