Skip to content

Commit a10f52c

Browse files
committed
Revert linked failure (rust_port locking)
This reverts commit 343e9de.
1 parent 5724c64 commit a10f52c

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

src/rt/rust_port.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ 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);
3229
if (task->blocked_on(&detach_cond)) {
33-
task->wakeup_inner(&detach_cond);
30+
// The port owner is waiting for the port to be detached
31+
task->wakeup(&detach_cond);
3432
}
3533
}
3634
}
@@ -66,15 +64,12 @@ void rust_port::send(void *sptr) {
6664
assert(!buffer.is_empty() &&
6765
"rust_chan::transmit with nothing to send.");
6866

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-
}
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;
7873
}
7974
}
8075

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

8580
rust_port_selector *port_selector = task->get_port_selector();
86-
// The port selector will check if the task is blocked, not us.
87-
port_selector->msg_sent_on(this);
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+
}
8886
}
8987
}
9088

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(task->lifecycle_lock);
78+
scoped_lock with(rendezvous_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_inner(this);
88+
task->wakeup(this);
8989
return;
9090
}
9191
}

src/rt/rust_port_selector.h

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

1314
public:
1415
rust_port_selector();

src/rt/rust_task.cpp

Lines changed: 4 additions & 3 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 (#2875): clean this up
246+
// FIXME (#2787): clean this up
247247
if (must_fail_from_being_killed()) {
248248
{
249249
scoped_lock with(lifecycle_lock);
@@ -346,11 +346,12 @@ void rust_task::assert_is_running()
346346
assert(state == task_state_running);
347347
}
348348

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

src/rt/rust_task.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ 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;
231229
bool block_inner(rust_cond *on, const char* name);
232230
void wakeup_inner(rust_cond *from);
233-
bool blocked_on(rust_cond *cond);
234231

235232
public:
236233

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

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

438436
bool had_reentered_rust_stack = reentered_rust_stack;
439437
{
440-
// FIXME (#2875) This must be racy. Figure it out.
438+
// FIXME (#2787) This must be racy. Figure it out.
441439
scoped_lock with(lifecycle_lock);
442440
reentered_rust_stack = true;
443441
}

0 commit comments

Comments
 (0)