Skip to content

Commit ad484c5

Browse files
committed
---
yaml --- r: 11966 b: refs/heads/master c: 05466c6 h: refs/heads/master v: v3
1 parent 229c118 commit ad484c5

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0201a03203b1961c96499c20025bf752a1b3ea6a
2+
refs/heads/master: 05466c61380366cfd1969bb9f4eb26cff2acaedd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_task.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern "C" CDECL void
6161
record_sp(void *limit);
6262

6363
// Tasks
64-
rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
64+
rust_task::rust_task(rust_task_thread *thread, rust_task_state state,
6565
rust_task *spawner, const char *name,
6666
size_t init_stack_sz) :
6767
ref_count(1),
@@ -231,7 +231,7 @@ rust_task::start(spawn_fn spawnee_fn,
231231

232232
void rust_task::start()
233233
{
234-
transition(&thread->newborn_tasks, &thread->running_tasks, NULL, "none");
234+
transition(task_state_newborn, task_state_running, NULL, "none");
235235
}
236236

237237
bool
@@ -350,14 +350,14 @@ bool
350350
rust_task::running()
351351
{
352352
scoped_lock with(state_lock);
353-
return state == &thread->running_tasks;
353+
return state == task_state_running;
354354
}
355355

356356
bool
357357
rust_task::blocked()
358358
{
359359
scoped_lock with(state_lock);
360-
return state == &thread->blocked_tasks;
360+
return state == task_state_blocked;
361361
}
362362

363363
bool
@@ -371,7 +371,7 @@ bool
371371
rust_task::dead()
372372
{
373373
scoped_lock with(state_lock);
374-
return state == &thread->dead_tasks;
374+
return state == task_state_dead;
375375
}
376376

377377
void *
@@ -393,13 +393,13 @@ rust_task::free(void *p)
393393
}
394394

395395
void
396-
rust_task::transition(rust_task_list *src, rust_task_list *dst,
396+
rust_task::transition(rust_task_state src, rust_task_state dst,
397397
rust_cond *cond, const char* cond_name) {
398398
thread->transition(this, src, dst, cond, cond_name);
399399
}
400400

401401
void
402-
rust_task::set_state(rust_task_list *state,
402+
rust_task::set_state(rust_task_state state,
403403
rust_cond *cond, const char* cond_name) {
404404
scoped_lock with(state_lock);
405405
this->state = state;
@@ -421,7 +421,7 @@ rust_task::block(rust_cond *on, const char* name) {
421421
A(thread, cond == NULL, "Cannot block an already blocked task.");
422422
A(thread, on != NULL, "Cannot block on a NULL object.");
423423

424-
transition(&thread->running_tasks, &thread->blocked_tasks, on, name);
424+
transition(task_state_running, task_state_blocked, on, name);
425425

426426
return true;
427427
}
@@ -433,12 +433,12 @@ rust_task::wakeup(rust_cond *from) {
433433
(uintptr_t) cond, (uintptr_t) from);
434434
A(thread, cond == from, "Cannot wake up blocked task on wrong condition.");
435435

436-
transition(&thread->blocked_tasks, &thread->running_tasks, NULL, "none");
436+
transition(task_state_blocked, task_state_running, NULL, "none");
437437
}
438438

439439
void
440440
rust_task::die() {
441-
transition(&thread->running_tasks, &thread->dead_tasks, NULL, "none");
441+
transition(task_state_running, task_state_dead, NULL, "none");
442442
}
443443

444444
void

trunk/src/rt/rust_task.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
9090

9191
// Protects state, cond, cond_name
9292
lock_and_signal state_lock;
93-
rust_task_list *state;
93+
rust_task_state state;
9494
rust_cond *cond;
9595
const char *cond_name;
9696

@@ -121,7 +121,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
121121

122122
void return_c_stack();
123123

124-
void transition(rust_task_list *src, rust_task_list *dst,
124+
void transition(rust_task_state src, rust_task_state dst,
125125
rust_cond *cond, const char* cond_name);
126126

127127
bool must_fail_from_being_killed_unlocked();
@@ -134,7 +134,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
134134

135135
// Only a pointer to 'name' is kept, so it must live as long as this task.
136136
rust_task(rust_task_thread *thread,
137-
rust_task_list *state,
137+
rust_task_state state,
138138
rust_task *spawner,
139139
const char *name,
140140
size_t init_stack_sz);
@@ -152,7 +152,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
152152
void *realloc(void *data, size_t sz);
153153
void free(void *p);
154154

155-
void set_state(rust_task_list *state,
155+
void set_state(rust_task_state state,
156156
rust_cond *cond, const char* cond_name);
157157

158158
bool block(rust_cond *on, const char* name);
@@ -206,7 +206,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
206206

207207
rust_port_selector *get_port_selector() { return &port_selector; }
208208

209-
rust_task_list *get_state() { return state; }
209+
rust_task_state get_state() { return state; }
210210
rust_cond *get_cond() { return cond; }
211211
const char *get_cond_name() { return cond_name; }
212212
};

trunk/src/rt/rust_task_thread.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
2727
id(id),
2828
should_exit(false),
2929
cached_c_stack(NULL),
30-
kernel(sched->kernel),
31-
sched(sched),
32-
srv(srv),
3330
newborn_tasks(this, "newborn"),
3431
running_tasks(this, "running"),
3532
blocked_tasks(this, "blocked"),
3633
dead_tasks(this, "dead"),
34+
kernel(sched->kernel),
35+
sched(sched),
36+
srv(srv),
3737
log_lvl(log_debug),
3838
min_stack_size(kernel->env->min_stack_size),
3939
env(kernel->env),
@@ -248,7 +248,7 @@ rust_task_thread::start_main_loop() {
248248
", state: %s",
249249
scheduled_task->name,
250250
(uintptr_t)scheduled_task,
251-
scheduled_task->get_state()->name);
251+
state_list(scheduled_task->get_state())->name);
252252

253253
place_task_in_tls(scheduled_task);
254254

@@ -262,7 +262,7 @@ rust_task_thread::start_main_loop() {
262262
" in state '%s', worker id=%d" PRIxPTR,
263263
scheduled_task->name,
264264
(uintptr_t)scheduled_task,
265-
scheduled_task->get_state()->name,
265+
state_list(scheduled_task->get_state())->name,
266266
id);
267267

268268
reap_dead_tasks();
@@ -289,7 +289,7 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
289289
size_t init_stack_sz) {
290290
rust_task *task =
291291
new (this->kernel, "rust_task")
292-
rust_task (this, &newborn_tasks, spawner, name, init_stack_sz);
292+
rust_task (this, task_state_newborn, spawner, name, init_stack_sz);
293293
DLOG(this, task, "created task: " PTR ", spawner: %s, name: %s",
294294
task, spawner ? spawner->name : "null", name);
295295

@@ -302,18 +302,34 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
302302
return task;
303303
}
304304

305+
rust_task_list *
306+
rust_task_thread::state_list(rust_task_state state) {
307+
switch (state) {
308+
case task_state_newborn:
309+
return &newborn_tasks;
310+
case task_state_running:
311+
return &running_tasks;
312+
case task_state_blocked:
313+
return &blocked_tasks;
314+
case task_state_dead:
315+
return &dead_tasks;
316+
}
317+
}
318+
305319
void
306320
rust_task_thread::transition(rust_task *task,
307-
rust_task_list *src, rust_task_list *dst,
321+
rust_task_state src, rust_task_state dst,
308322
rust_cond *cond, const char* cond_name) {
309323
scoped_lock with(lock);
324+
rust_task_list *src_list = state_list(src);
325+
rust_task_list *dst_list = state_list(dst);
310326
DLOG(this, task,
311327
"task %s " PTR " state change '%s' -> '%s' while in '%s'",
312-
name, (uintptr_t)this, src->name, dst->name,
313-
task->get_state()->name);
328+
name, (uintptr_t)this, src_list->name, dst_list->name,
329+
state_list(task->get_state())->name);
314330
I(this, task->get_state() == src);
315-
src->remove(task);
316-
dst->append(task);
331+
src_list->remove(task);
332+
dst_list->append(task);
317333
task->set_state(dst, cond, cond_name);
318334

319335
lock.signal();

trunk/src/rt/rust_task_thread.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RUST_TASK_THREAD_H
22
#define RUST_TASK_THREAD_H
33

4+
#include "rust_internal.h"
45
#include "sync/rust_thread.h"
56
#include "rust_stack.h"
67
#include "context.h"
@@ -11,6 +12,13 @@
1112
#include <windows.h>
1213
#endif
1314

15+
enum rust_task_state {
16+
task_state_newborn,
17+
task_state_running,
18+
task_state_blocked,
19+
task_state_dead
20+
};
21+
1422
struct rust_task_thread : public kernel_owned<rust_task_thread>,
1523
rust_thread
1624
{
@@ -37,19 +45,21 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
3745
stk_seg *cached_c_stack;
3846
stk_seg *extra_c_stack;
3947

48+
rust_task_list newborn_tasks;
49+
rust_task_list running_tasks;
50+
rust_task_list blocked_tasks;
51+
rust_task_list dead_tasks;
52+
4053
void prepare_c_stack(rust_task *task);
4154
void unprepare_c_stack();
4255

56+
rust_task_list *state_list(rust_task_state state);
57+
4358
public:
4459
rust_kernel *kernel;
4560
rust_scheduler *sched;
4661
rust_srv *srv;
4762

48-
rust_task_list newborn_tasks;
49-
rust_task_list running_tasks;
50-
rust_task_list blocked_tasks;
51-
rust_task_list dead_tasks;
52-
5363
// NB: this is used to filter *runtime-originating* debug
5464
// logging, on a per-scheduler basis. It's not likely what
5565
// you want to expose to the user in terms of per-task
@@ -90,7 +100,7 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
90100
size_t init_stack_sz);
91101

92102
void transition(rust_task *task,
93-
rust_task_list *src, rust_task_list *dst,
103+
rust_task_state src, rust_task_state dst,
94104
rust_cond *cond, const char* cond_name);
95105

96106
virtual void run();

0 commit comments

Comments
 (0)