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.
This commit is contained in:
Brian Anderson
2012-02-04 00:03:45 -08:00
parent 21d783c338
commit 9fa950ec53
2 changed files with 8 additions and 5 deletions

View File

@@ -84,25 +84,27 @@ rust_kernel::fail() {
void void
rust_kernel::register_task(rust_task *task) { rust_kernel::register_task(rust_task *task) {
int new_live_tasks;
{ {
scoped_lock with(task_lock); scoped_lock with(task_lock);
task->user.id = max_task_id++; task->user.id = max_task_id++;
task_table.put(task->user.id, task); task_table.put(task->user.id, task);
new_live_tasks = ++live_tasks;
} }
K(srv, task->user.id != INTPTR_MAX, "Hit the maximum task id"); K(srv, task->user.id != INTPTR_MAX, "Hit the maximum task id");
KLOG_("Registered task %" PRIdPTR, task->user.id); KLOG_("Registered task %" PRIdPTR, task->user.id);
int new_live_tasks = sync::increment(live_tasks);
KLOG_("Total outstanding tasks: %d", new_live_tasks); KLOG_("Total outstanding tasks: %d", new_live_tasks);
} }
void void
rust_kernel::release_task_id(rust_task_id id) { rust_kernel::release_task_id(rust_task_id id) {
KLOG_("Releasing task %" PRIdPTR, id); KLOG_("Releasing task %" PRIdPTR, id);
int new_live_tasks;
{ {
scoped_lock with(task_lock); scoped_lock with(task_lock);
task_table.remove(id); task_table.remove(id);
new_live_tasks = --live_tasks;
} }
int new_live_tasks = sync::decrement(live_tasks);
KLOG_("Total outstanding tasks: %d", new_live_tasks); KLOG_("Total outstanding tasks: %d", new_live_tasks);
if (new_live_tasks == 0) { if (new_live_tasks == 0) {
// There are no more tasks and there never will be. // There are no more tasks and there never will be.

View File

@@ -22,12 +22,13 @@ public:
private: private:
rust_scheduler *sched; rust_scheduler *sched;
// Protects live_tasks, max_task_id and task_table
lock_and_signal task_lock;
// Tracks the number of tasks that are being managed by // Tracks the number of tasks that are being managed by
// schedulers. When this hits 0 we will tell all schedulers // schedulers. When this hits 0 we will tell all schedulers
// to exit. // to exit.
volatile int live_tasks; int live_tasks;
// Protects max_task_id and task_table // The next task id
lock_and_signal task_lock;
rust_task_id max_task_id; rust_task_id max_task_id;
hash_map<rust_task_id, rust_task *> task_table; hash_map<rust_task_id, rust_task *> task_table;