Skip to content

Commit aeb69b4

Browse files
committed
---
yaml --- r: 31189 b: refs/heads/dist-snap c: 62575d9 h: refs/heads/master i: 31187: a7345b3 v: v3
1 parent edb00e9 commit aeb69b4

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: aad184cc5737671c9c61c774ff4eb3908620857b
10+
refs/heads/dist-snap: 62575d9c4a26eb2fa0bd1a1dbf1580633a886dce
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/rt/rust_port.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ void rust_port::deref() {
2626
scoped_lock with(ref_lock);
2727
ref_count--;
2828
if (!ref_count) {
29+
// The port owner is waiting for the port to be detached (if it
30+
// hasn't already been killed)
31+
scoped_lock with(task->lifecycle_lock);
2932
if (task->blocked_on(&detach_cond)) {
30-
// The port owner is waiting for the port to be detached
31-
task->wakeup(&detach_cond);
33+
task->wakeup_inner(&detach_cond);
3234
}
3335
}
3436
}
@@ -64,12 +66,15 @@ void rust_port::send(void *sptr) {
6466
assert(!buffer.is_empty() &&
6567
"rust_chan::transmit with nothing to send.");
6668

67-
if (task->blocked_on(this)) {
68-
KLOG(kernel, comm, "dequeued in rendezvous_ptr");
69-
buffer.dequeue(task->rendezvous_ptr);
70-
task->rendezvous_ptr = 0;
71-
task->wakeup(this);
72-
did_rendezvous = true;
69+
{
70+
scoped_lock with(task->lifecycle_lock);
71+
if (task->blocked_on(this)) {
72+
KLOG(kernel, comm, "dequeued in rendezvous_ptr");
73+
buffer.dequeue(task->rendezvous_ptr);
74+
task->rendezvous_ptr = 0;
75+
task->wakeup_inner(this);
76+
did_rendezvous = true;
77+
}
7378
}
7479
}
7580

@@ -78,11 +83,8 @@ void rust_port::send(void *sptr) {
7883
// it may be waiting on a group of ports
7984

8085
rust_port_selector *port_selector = task->get_port_selector();
81-
// This check is not definitive. The port selector will take a lock
82-
// and check again whether the task is still blocked.
83-
if (task->blocked_on(port_selector)) {
84-
port_selector->msg_sent_on(this);
85-
}
86+
// The port selector will check if the task is blocked, not us.
87+
port_selector->msg_sent_on(this);
8688
}
8789
}
8890

branches/dist-snap/src/rt/rust_port_selector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ rust_port_selector::msg_sent_on(rust_port *port) {
7575

7676
// Prevent two ports from trying to wake up the task
7777
// simultaneously
78-
scoped_lock with(rendezvous_lock);
78+
scoped_lock with(task->lifecycle_lock);
7979

8080
if (task->blocked_on(this)) {
8181
for (size_t i = 0; i < n_ports; i++) {
@@ -85,7 +85,7 @@ rust_port_selector::msg_sent_on(rust_port *port) {
8585
n_ports = 0;
8686
*task->rendezvous_ptr = (uintptr_t) port;
8787
task->rendezvous_ptr = NULL;
88-
task->wakeup(this);
88+
task->wakeup_inner(this);
8989
return;
9090
}
9191
}

branches/dist-snap/src/rt/rust_port_selector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class rust_port_selector : public rust_cond {
99
private:
1010
rust_port **ports;
1111
size_t n_ports;
12-
lock_and_signal rendezvous_lock;
1312

1413
public:
1514
rust_port_selector();

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ rust_task::must_fail_from_being_killed_inner() {
243243
// Only run this on the rust stack
244244
void
245245
rust_task::yield(bool *killed) {
246-
// FIXME (#2787): clean this up
246+
// FIXME (#2875): clean this up
247247
if (must_fail_from_being_killed()) {
248248
{
249249
scoped_lock with(lifecycle_lock);
@@ -346,12 +346,11 @@ void rust_task::assert_is_running()
346346
assert(state == task_state_running);
347347
}
348348

349-
// FIXME (#2851, #2787): This is only used by rust_port/rust_port selector,
350-
// and is inherently racy. Get rid of it.
349+
// FIXME (#2851) Remove this code when rust_port goes away?
351350
bool
352351
rust_task::blocked_on(rust_cond *on)
353352
{
354-
scoped_lock with(lifecycle_lock);
353+
lifecycle_lock.must_have_lock();
355354
return cond == on;
356355
}
357356

branches/dist-snap/src/rt/rust_task.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ rust_task : public kernel_owned<rust_task>
226226
char const *file,
227227
size_t line);
228228

229+
friend class rust_port;
230+
friend class rust_port_selector;
229231
bool block_inner(rust_cond *on, const char* name);
230232
void wakeup_inner(rust_cond *from);
233+
bool blocked_on(rust_cond *cond);
231234

232235
public:
233236

@@ -243,7 +246,6 @@ rust_task : public kernel_owned<rust_task>
243246
void *args);
244247
void start();
245248
void assert_is_running();
246-
bool blocked_on(rust_cond *cond); // FIXME (#2851) Get rid of this.
247249

248250
void *malloc(size_t sz, const char *tag, type_desc *td=0);
249251
void *realloc(void *data, size_t sz);
@@ -435,7 +437,7 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
435437

436438
bool had_reentered_rust_stack = reentered_rust_stack;
437439
{
438-
// FIXME (#2787) This must be racy. Figure it out.
440+
// FIXME (#2875) This must be racy. Figure it out.
439441
scoped_lock with(lifecycle_lock);
440442
reentered_rust_stack = true;
441443
}

0 commit comments

Comments
 (0)