Skip to content

Commit 615886b

Browse files
committed
---
yaml --- r: 8065 b: refs/heads/snap-stage3 c: 12fa908 h: refs/heads/master i: 8063: 71d5518 v: v3
1 parent a14ea89 commit 615886b

File tree

7 files changed

+50
-43
lines changed

7 files changed

+50
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e7f00b64933b85289921f641b2658f41eeb338ec
4+
refs/heads/snap-stage3: 12fa90888e56c81088e30edd26d1bc404b3e334d
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rt/rust_kernel.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) :
1111
_region(srv, true),
1212
_log(srv, NULL),
1313
srv(srv),
14-
max_id(0),
15-
rval(0),
1614
live_tasks(0),
15+
max_task_id(0),
16+
rval(0),
1717
env(srv->env)
1818
{
1919
sched = new (this, "rust_scheduler")
@@ -84,14 +84,35 @@ rust_kernel::fail() {
8484

8585
void
8686
rust_kernel::register_task(rust_task *task) {
87-
scoped_lock with(_kernel_lock);
88-
task->user.id = max_id++;
89-
task_table.put(task->user.id, task);
87+
{
88+
scoped_lock with(task_lock);
89+
task->user.id = max_task_id++;
90+
task_table.put(task->user.id, task);
91+
}
92+
KLOG_("Registered task %" PRIdPTR, task->user.id);
93+
int new_live_tasks = sync::increment(live_tasks);
94+
KLOG_("Total outstanding tasks: %d", new_live_tasks);
95+
}
96+
97+
void
98+
rust_kernel::release_task_id(rust_task_id id) {
99+
KLOG_("Releasing task %" PRIdPTR, id);
100+
{
101+
scoped_lock with(task_lock);
102+
task_table.remove(id);
103+
}
104+
int new_live_tasks = sync::decrement(live_tasks);
105+
KLOG_("Total outstanding tasks: %d", new_live_tasks);
106+
if (new_live_tasks == 0) {
107+
// There are no more tasks and there never will be.
108+
// Tell all the schedulers to exit.
109+
sched->exit();
110+
}
90111
}
91112

92113
rust_task *
93114
rust_kernel::get_task_by_id(rust_task_id id) {
94-
scoped_lock with(_kernel_lock);
115+
scoped_lock with(task_lock);
95116
rust_task *task = NULL;
96117
// get leaves task unchanged if not found.
97118
task_table.get(id, &task);
@@ -109,16 +130,6 @@ rust_kernel::get_task_by_id(rust_task_id id) {
109130
return task;
110131
}
111132

112-
void
113-
rust_kernel::release_task_id(rust_task_id id) {
114-
scoped_lock with(_kernel_lock);
115-
task_table.remove(id);
116-
}
117-
118-
void rust_kernel::exit_schedulers() {
119-
sched->exit();
120-
}
121-
122133
#ifdef __WIN32__
123134
void
124135
rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {
@@ -140,7 +151,7 @@ rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {
140151

141152
void
142153
rust_kernel::set_exit_status(int code) {
143-
scoped_lock with(_kernel_lock);
154+
scoped_lock with(rval_lock);
144155
// If we've already failed then that's the code we're going to use
145156
if (rval != PROC_FAIL_CODE) {
146157
rval = code;

branches/snap-stage3/src/rt/rust_kernel.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@ class rust_kernel {
2020
public:
2121
rust_srv *srv;
2222
private:
23-
lock_and_signal _kernel_lock;
2423
rust_scheduler *sched;
2524

26-
rust_task_id max_id;
25+
// Tracks the number of tasks that are being managed by
26+
// schedulers. When this hits 0 we will tell all schedulers
27+
// to exit.
28+
volatile int live_tasks;
29+
// Protects max_task_id and task_table
30+
lock_and_signal task_lock;
31+
rust_task_id max_task_id;
2732
hash_map<rust_task_id, rust_task *> task_table;
33+
34+
lock_and_signal rval_lock;
2835
int rval;
2936

3037
public:
3138

32-
volatile int live_tasks;
3339
struct rust_env *env;
3440

3541
rust_kernel(rust_srv *srv, size_t num_threads);
36-
37-
void exit_schedulers();
42+
~rust_kernel();
3843

3944
void log(uint32_t level, char const *fmt, ...);
4045
void fatal(char const *fmt, ...);
41-
virtual ~rust_kernel();
4246

4347
void *malloc(size_t size, const char *tag);
4448
void *realloc(void *mem, size_t size);

branches/snap-stage3/src/rt/rust_scheduler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ rust_scheduler::create_task(rust_task *spawner, const char *name,
8787
thread_no = isaac_rand(&rctx) % num_threads;
8888
}
8989
rust_task_thread *thread = threads[thread_no];
90-
rust_task *t = thread->create_task(spawner, name, init_stack_sz);
91-
kernel->register_task(t);
92-
return t->user.id;
90+
return thread->create_task(spawner, name, init_stack_sz);
9391
}
9492

9593
rust_task_id

branches/snap-stage3/src/rt/rust_task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,19 @@ rust_task::~rust_task()
275275
DLOG(thread, task, "~rust_task %s @0x%" PRIxPTR ", refcnt=%d",
276276
name, (uintptr_t)this, ref_count);
277277

278+
// FIXME: We should do this when the task exits, not in the destructor
278279
if (supervisor) {
279280
supervisor->deref();
280281
}
281282

282-
kernel->release_task_id(user.id);
283-
284283
/* FIXME: tighten this up, there are some more
285284
assertions that hold at task-lifecycle events. */
286285
I(thread, ref_count == 0); // ||
287286
// (ref_count == 1 && this == sched->root_task));
288287

289288
// Delete all the stacks. There may be more than one if the task failed
290289
// and no landing pads stopped to clean up.
290+
// FIXME: We should do this when the task exits, not in the destructor
291291
while (stk != NULL) {
292292
del_stk(this, stk);
293293
}

branches/snap-stage3/src/rt/rust_task_thread.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,8 @@ rust_task_thread::reap_dead_tasks() {
137137
for (size_t i = 0; i < dead_tasks_len; ++i) {
138138
rust_task *task = dead_tasks_copy[i];
139139
if (task) {
140+
kernel->release_task_id(task->user.id);
140141
task->deref();
141-
int live_tasks = sync::decrement(kernel->live_tasks);
142-
if (live_tasks == 0) {
143-
// There are no more tasks and there never will be.
144-
// Tell all the schedulers to exit.
145-
kernel->exit_schedulers();
146-
}
147142
}
148143
}
149144
srv->free(dead_tasks_copy);
@@ -219,8 +214,8 @@ rust_task_thread::start_main_loop() {
219214
DLOG(this, dom, "started domain loop %d", id);
220215

221216
while (!should_exit) {
222-
DLOG(this, dom, "worker %d, number_of_live_tasks = %d, total = %d",
223-
id, number_of_live_tasks(), kernel->live_tasks);
217+
DLOG(this, dom, "worker %d, number_of_live_tasks = %d",
218+
id, number_of_live_tasks());
224219

225220
rust_task *scheduled_task = schedule_task();
226221

@@ -281,7 +276,7 @@ rust_task_thread::get_cache() {
281276
return &cache;
282277
}
283278

284-
rust_task *
279+
rust_task_id
285280
rust_task_thread::create_task(rust_task *spawner, const char *name,
286281
size_t init_stack_sz) {
287282
rust_task *task =
@@ -295,9 +290,8 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
295290
newborn_tasks.append(task);
296291
}
297292

298-
sync::increment(kernel->live_tasks);
299-
300-
return task;
293+
kernel->register_task(task);
294+
return task->user.id;
301295
}
302296

303297
void rust_task_thread::run() {

branches/snap-stage3/src/rt/rust_task_thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
112112

113113
void kill_all_tasks();
114114

115-
rust_task *create_task(rust_task *spawner, const char *name,
116-
size_t init_stack_sz);
115+
rust_task_id create_task(rust_task *spawner, const char *name,
116+
size_t init_stack_sz);
117117

118118
virtual void run();
119119

0 commit comments

Comments
 (0)