Skip to content

Commit 9fa950e

Browse files
committed
rt: Stop using atomic ops on rust_kernel::live_tasks
These ops are all done within spitting distance of a suitable lock, so just protect it with the lock.
1 parent 21d783c commit 9fa950e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/rt/rust_kernel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,27 @@ rust_kernel::fail() {
8484

8585
void
8686
rust_kernel::register_task(rust_task *task) {
87+
int new_live_tasks;
8788
{
8889
scoped_lock with(task_lock);
8990
task->user.id = max_task_id++;
9091
task_table.put(task->user.id, task);
92+
new_live_tasks = ++live_tasks;
9193
}
9294
K(srv, task->user.id != INTPTR_MAX, "Hit the maximum task id");
9395
KLOG_("Registered task %" PRIdPTR, task->user.id);
94-
int new_live_tasks = sync::increment(live_tasks);
9596
KLOG_("Total outstanding tasks: %d", new_live_tasks);
9697
}
9798

9899
void
99100
rust_kernel::release_task_id(rust_task_id id) {
100101
KLOG_("Releasing task %" PRIdPTR, id);
102+
int new_live_tasks;
101103
{
102104
scoped_lock with(task_lock);
103105
task_table.remove(id);
106+
new_live_tasks = --live_tasks;
104107
}
105-
int new_live_tasks = sync::decrement(live_tasks);
106108
KLOG_("Total outstanding tasks: %d", new_live_tasks);
107109
if (new_live_tasks == 0) {
108110
// There are no more tasks and there never will be.

src/rt/rust_kernel.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ class rust_kernel {
2222
private:
2323
rust_scheduler *sched;
2424

25+
// Protects live_tasks, max_task_id and task_table
26+
lock_and_signal task_lock;
2527
// Tracks the number of tasks that are being managed by
2628
// schedulers. When this hits 0 we will tell all schedulers
2729
// to exit.
28-
volatile int live_tasks;
29-
// Protects max_task_id and task_table
30-
lock_and_signal task_lock;
30+
int live_tasks;
31+
// The next task id
3132
rust_task_id max_task_id;
3233
hash_map<rust_task_id, rust_task *> task_table;
3334

0 commit comments

Comments
 (0)