Skip to content

Commit c414b78

Browse files
committed
rt: Remove the kernel task table
1 parent 1366d65 commit c414b78

File tree

3 files changed

+7
-54
lines changed

3 files changed

+7
-54
lines changed

src/rt/rust_kernel.cpp

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -166,51 +166,11 @@ rust_kernel::fail() {
166166
}
167167
}
168168

169-
void
170-
rust_kernel::register_task(rust_task *task) {
171-
uintptr_t new_live_tasks;
172-
{
173-
scoped_lock with(task_lock);
174-
task->id = max_task_id++;
175-
task_table.put(task->id, task);
176-
new_live_tasks = task_table.count();
177-
}
178-
K(srv, task->id != INTPTR_MAX, "Hit the maximum task id");
179-
KLOG_("Registered task %" PRIdPTR, task->id);
180-
KLOG_("Total outstanding tasks: %d", new_live_tasks);
181-
}
182-
183-
void
184-
rust_kernel::release_task_id(rust_task_id id) {
185-
KLOG_("Releasing task %" PRIdPTR, id);
186-
uintptr_t new_live_tasks;
187-
{
188-
scoped_lock with(task_lock);
189-
task_table.remove(id);
190-
new_live_tasks = task_table.count();
191-
}
192-
KLOG_("Total outstanding tasks: %d", new_live_tasks);
193-
}
194-
195-
rust_task *
196-
rust_kernel::get_task_by_id(rust_task_id id) {
197-
scoped_lock with(task_lock);
198-
rust_task *task = NULL;
199-
// get leaves task unchanged if not found.
200-
task_table.get(id, &task);
201-
if(task) {
202-
if(task->get_ref_count() == 0) {
203-
// FIXME: I don't think this is possible.
204-
// this means the destructor is running, since the destructor
205-
// grabs the kernel lock to unregister the task. Pretend this
206-
// doesn't actually exist.
207-
return NULL;
208-
}
209-
else {
210-
task->ref();
211-
}
212-
}
213-
return task;
169+
rust_task_id
170+
rust_kernel::generate_task_id() {
171+
rust_task_id id = sync::increment(max_task_id);
172+
K(srv, id != INTPTR_MAX, "Hit the maximum task id");
173+
return id;
214174
}
215175

216176
rust_port_id

src/rt/rust_kernel.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ class rust_kernel {
2424
public:
2525
rust_srv *srv;
2626
private:
27-
// Protects max_task_id and task_table
28-
lock_and_signal task_lock;
2927
// The next task id
3028
rust_task_id max_task_id;
31-
hash_map<rust_task_id, rust_task *> task_table;
3229

3330
// Protects max_port_id and port_table
3431
lock_and_signal port_lock;
@@ -75,9 +72,7 @@ class rust_kernel {
7572
void win32_require(LPCTSTR fn, BOOL ok);
7673
#endif
7774

78-
void register_task(rust_task *task);
79-
rust_task *get_task_by_id(rust_task_id id);
80-
void release_task_id(rust_task_id tid);
75+
rust_task_id generate_task_id();
8176

8277
rust_port_id register_port(rust_port *port);
8378
rust_port *get_port_by_id(rust_port_id id);

src/rt/rust_task_thread.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ rust_task_thread::reap_dead_tasks() {
146146
// from the scheduler, which may end up trying to take this lock
147147
lock.unlock();
148148

149-
// Release the task from the kernel so nobody else can get at it
150-
kernel->release_task_id(dead_task->id);
151149
dead_task->delete_all_stacks();
152150
// Deref the task, which may cause it to request us to release it
153151
dead_task->deref();
@@ -316,7 +314,7 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
316314
newborn_tasks.append(task);
317315
}
318316

319-
kernel->register_task(task);
317+
task->id = kernel->generate_task_id();
320318
return task;
321319
}
322320

0 commit comments

Comments
 (0)