Skip to content

Commit b31ce6b

Browse files
committed
---
yaml --- r: 22473 b: refs/heads/master c: 08c40c5 h: refs/heads/master i: 22471: aa993ad v: v3
1 parent ffc8c4b commit b31ce6b

File tree

4 files changed

+48
-39
lines changed

4 files changed

+48
-39
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: 3b159c6d5ba48643e8982e7cadbc1745e9f29f62
2+
refs/heads/master: 08c40c5eb7bda79850f725308b72c1451fb67a86
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rt/rust_sched_loop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ rust_sched_loop::run_single_turn() {
208208
return sched_loop_state_block;
209209
}
210210

211-
scheduled_task->assert_is_running();
211+
assert(scheduled_task->running());
212212

213213
DLOG(this, task,
214214
"activating task %s 0x%" PRIxPTR

trunk/src/rt/rust_task.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ cleanup_task(cleanup_args *args) {
114114
rust_task *task = a->task;
115115

116116
{
117-
scoped_lock with(task->lifecycle_lock);
117+
scoped_lock with(task->kill_lock);
118118
if (task->killed && !threw_exception) {
119119
LOG(task, task, "Task killed during termination");
120120
threw_exception = true;
@@ -230,25 +230,21 @@ void rust_task::start()
230230

231231
bool
232232
rust_task::must_fail_from_being_killed() {
233-
scoped_lock with(lifecycle_lock);
233+
scoped_lock with(kill_lock);
234234
return must_fail_from_being_killed_unlocked();
235235
}
236236

237237
bool
238238
rust_task::must_fail_from_being_killed_unlocked() {
239-
lifecycle_lock.must_have_lock();
239+
kill_lock.must_have_lock();
240240
return killed && !reentered_rust_stack && disallow_kill == 0;
241241
}
242242

243243
// Only run this on the rust stack
244244
void
245245
rust_task::yield(bool *killed) {
246-
// FIXME (#2787): clean this up
247246
if (must_fail_from_being_killed()) {
248-
{
249-
scoped_lock with(lifecycle_lock);
250-
assert(!(state == task_state_blocked));
251-
}
247+
assert(!blocked());
252248
*killed = true;
253249
}
254250

@@ -262,7 +258,7 @@ rust_task::yield(bool *killed) {
262258

263259
void
264260
rust_task::kill() {
265-
scoped_lock with(lifecycle_lock);
261+
scoped_lock with(kill_lock);
266262

267263
// XXX: bblum: kill/kill race
268264

@@ -274,9 +270,8 @@ rust_task::kill() {
274270
killed = true;
275271
// Unblock the task so it can unwind.
276272

277-
if (state == task_state_blocked &&
278-
must_fail_from_being_killed_unlocked()) {
279-
wakeup_locked(cond);
273+
if (blocked() && must_fail_from_being_killed_unlocked()) {
274+
wakeup(cond);
280275
}
281276

282277
LOG(this, task, "preparing to unwind task: 0x%" PRIxPTR, this);
@@ -340,21 +335,34 @@ rust_task::get_frame_glue_fns(uintptr_t fp) {
340335
return *((frame_glue_fns**) fp);
341336
}
342337

343-
void rust_task::assert_is_running()
338+
bool
339+
rust_task::running()
340+
{
341+
scoped_lock with(state_lock);
342+
return state == task_state_running;
343+
}
344+
345+
bool
346+
rust_task::blocked()
344347
{
345-
scoped_lock with(lifecycle_lock);
346-
assert(state == task_state_running);
348+
scoped_lock with(state_lock);
349+
return state == task_state_blocked;
347350
}
348351

349-
// FIXME (#2851, #2787): This is only used by rust_port/rust_port selector,
350-
// and is inherently racy. Get rid of it.
351352
bool
352353
rust_task::blocked_on(rust_cond *on)
353354
{
354-
scoped_lock with(lifecycle_lock);
355+
scoped_lock with(state_lock);
355356
return cond == on;
356357
}
357358

359+
bool
360+
rust_task::dead()
361+
{
362+
scoped_lock with(state_lock);
363+
return state == task_state_dead;
364+
}
365+
358366
void *
359367
rust_task::malloc(size_t sz, const char *tag, type_desc *td)
360368
{
@@ -376,28 +384,28 @@ rust_task::free(void *p)
376384
void
377385
rust_task::transition(rust_task_state src, rust_task_state dst,
378386
rust_cond *cond, const char* cond_name) {
379-
scoped_lock with(lifecycle_lock);
387+
scoped_lock with(state_lock);
380388
transition_locked(src, dst, cond, cond_name);
381389
}
382390

383391
void rust_task::transition_locked(rust_task_state src, rust_task_state dst,
384392
rust_cond *cond, const char* cond_name) {
385-
lifecycle_lock.must_have_lock();
393+
state_lock.must_have_lock();
386394
sched_loop->transition(this, src, dst, cond, cond_name);
387395
}
388396

389397
void
390398
rust_task::set_state(rust_task_state state,
391399
rust_cond *cond, const char* cond_name) {
392-
lifecycle_lock.must_have_lock();
400+
state_lock.must_have_lock();
393401
this->state = state;
394402
this->cond = cond;
395403
this->cond_name = cond_name;
396404
}
397405

398406
bool
399407
rust_task::block(rust_cond *on, const char* name) {
400-
scoped_lock with(lifecycle_lock);
408+
scoped_lock with(kill_lock);
401409
return block_locked(on, name);
402410
}
403411

@@ -420,7 +428,7 @@ rust_task::block_locked(rust_cond *on, const char* name) {
420428

421429
void
422430
rust_task::wakeup(rust_cond *from) {
423-
scoped_lock with(lifecycle_lock);
431+
scoped_lock with(state_lock);
424432
wakeup_locked(from);
425433
}
426434

@@ -668,27 +676,26 @@ rust_task::on_rust_stack() {
668676

669677
void
670678
rust_task::inhibit_kill() {
671-
scoped_lock with(lifecycle_lock);
672-
// FIXME (#1868) Check here if we have to die
679+
scoped_lock with(kill_lock);
673680
disallow_kill++;
674681
}
675682

676683
void
677684
rust_task::allow_kill() {
678-
scoped_lock with(lifecycle_lock);
685+
scoped_lock with(kill_lock);
679686
assert(disallow_kill > 0 && "Illegal allow_kill(): already killable!");
680687
disallow_kill--;
681688
}
682689

683690
void *
684691
rust_task::wait_event(bool *killed) {
685-
scoped_lock with(lifecycle_lock);
692+
scoped_lock with(state_lock);
686693

687694
if(!event_reject) {
688695
block_locked(&event_cond, "waiting on event");
689-
lifecycle_lock.unlock();
696+
state_lock.unlock();
690697
yield(killed);
691-
lifecycle_lock.lock();
698+
state_lock.lock();
692699
}
693700

694701
event_reject = false;
@@ -697,7 +704,7 @@ rust_task::wait_event(bool *killed) {
697704

698705
void
699706
rust_task::signal_event(void *event) {
700-
scoped_lock with(lifecycle_lock);
707+
scoped_lock with(state_lock);
701708

702709
this->event = event;
703710
event_reject = true;

trunk/src/rt/rust_task.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ rust_task : public kernel_owned<rust_task>
170170
private:
171171

172172
// Protects state, cond, cond_name
173-
// Protects the killed flag, disallow_kill flag, reentered_rust_stack
174-
lock_and_signal lifecycle_lock;
173+
lock_and_signal state_lock;
175174
rust_task_state state;
176175
rust_cond *cond;
177176
const char *cond_name;
@@ -180,6 +179,8 @@ rust_task : public kernel_owned<rust_task>
180179
rust_cond event_cond;
181180
void *event;
182181

182+
// Protects the killed flag, disallow_kill flag, reentered_rust_stack
183+
lock_and_signal kill_lock;
183184
// Indicates that the task was killed and needs to unwind
184185
bool killed;
185186
// Indicates that we've called back into Rust from C
@@ -242,8 +243,10 @@ rust_task : public kernel_owned<rust_task>
242243
rust_opaque_box *env,
243244
void *args);
244245
void start();
245-
void assert_is_running();
246-
bool blocked_on(rust_cond *cond); // FIXME (#2851) Get rid of this.
246+
bool running();
247+
bool blocked();
248+
bool blocked_on(rust_cond *cond);
249+
bool dead();
247250

248251
void *malloc(size_t sz, const char *tag, type_desc *td=0);
249252
void *realloc(void *data, size_t sz);
@@ -435,8 +438,7 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
435438

436439
bool had_reentered_rust_stack = reentered_rust_stack;
437440
{
438-
// FIXME (#2787) This must be racy. Figure it out.
439-
scoped_lock with(lifecycle_lock);
441+
scoped_lock with(kill_lock);
440442
reentered_rust_stack = true;
441443
}
442444

@@ -451,7 +453,7 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
451453

452454
next_c_sp = prev_c_sp;
453455
{
454-
scoped_lock with(lifecycle_lock);
456+
scoped_lock with(kill_lock);
455457
reentered_rust_stack = had_reentered_rust_stack;
456458
}
457459

0 commit comments

Comments
 (0)