Skip to content

Commit 6658079

Browse files
committed
---
yaml --- r: 6239 b: refs/heads/master c: e4f9808 h: refs/heads/master i: 6237: afff809 6235: 05d4ca7 6231: db714aa 6223: 86c510f 6207: add8616 v: v3
1 parent c18fd13 commit 6658079

File tree

6 files changed

+24
-71
lines changed

6 files changed

+24
-71
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 08d0ff38bc6efe2915b877dfec443a3d7853831b
2+
refs/heads/master: e4f980810b8787626b32fc116e491c0ff9e56ba0

trunk/src/rt/rust_builtin.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,8 @@ port_recv(uintptr_t *dptr, rust_port *port) {
538538
scoped_lock with(port->lock);
539539

540540
LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
541-
", size: 0x%" PRIxPTR ", chan_no: %d",
542-
(uintptr_t) port, (uintptr_t) dptr, port->unit_sz,
543-
port->chans.length());
541+
", size: 0x%" PRIxPTR,
542+
(uintptr_t) port, (uintptr_t) dptr, port->unit_sz);
544543

545544
if (port->receive(dptr)) {
546545
return;

trunk/src/rt/rust_chan.cpp

+7-40
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
*/
77
rust_chan::rust_chan(rust_kernel *kernel, rust_port *port,
88
size_t unit_sz)
9-
: ref_count(1),
9+
: ref_count(0),
1010
kernel(kernel),
1111
port(port),
1212
buffer(kernel, unit_sz) {
13-
if (port) {
14-
associate(port);
15-
}
1613
KLOG(kernel, comm, "new rust_chan(task=0x%" PRIxPTR
1714
", port=0x%" PRIxPTR ") -> chan=0x%" PRIxPTR,
1815
(uintptr_t) task, (uintptr_t) port, (uintptr_t) this);
16+
17+
A(kernel, port != NULL, "Port must not be null");
18+
this->task = port->task;
19+
this->task->ref();
1920
}
2021

2122
rust_chan::~rust_chan() {
@@ -26,49 +27,15 @@ rust_chan::~rust_chan() {
2627

2728
A(kernel, is_associated() == false,
2829
"Channel must be disassociated before being freed.");
29-
}
3030

31-
/**
32-
* Link this channel with the specified port.
33-
*/
34-
void rust_chan::associate(rust_port *port) {
35-
this->ref();
36-
this->port = port;
37-
scoped_lock with(port->lock);
38-
KLOG(kernel, task,
39-
"associating chan: 0x%" PRIxPTR " with port: 0x%" PRIxPTR,
40-
this, port);
41-
this->task = port->task;
42-
this->task->ref();
43-
this->port->chans.push(this);
31+
task->deref();
32+
task = NULL;
4433
}
4534

4635
bool rust_chan::is_associated() {
4736
return port != NULL;
4837
}
4938

50-
/**
51-
* Unlink this channel from its associated port.
52-
*/
53-
void rust_chan::disassociate() {
54-
A(kernel,
55-
port->lock.lock_held_by_current_thread(),
56-
"Port referent lock must be held to call rust_chan::disassociate");
57-
A(kernel, is_associated(),
58-
"Channel must be associated with a port.");
59-
KLOG(kernel, task,
60-
"disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
61-
this, port);
62-
task->deref();
63-
this->task = NULL;
64-
port->chans.swap_delete(this);
65-
66-
// Delete reference to the port.
67-
port = NULL;
68-
69-
this->deref();
70-
}
71-
7239
/**
7340
* Attempt to send data to the associated port.
7441
*/

trunk/src/rt/rust_chan.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class rust_chan : public kernel_owned<rust_chan>,
1616
size_t idx;
1717
circular_buffer buffer;
1818

19-
void associate(rust_port *port);
20-
void disassociate();
2119
bool is_associated();
2220

2321
void send(void *sptr);

trunk/src/rt/rust_port.cpp

+14-24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
rust_port::rust_port(rust_task *task, size_t unit_sz)
77
: ref_count(1), kernel(task->kernel), task(task),
8-
unit_sz(unit_sz), writers(task), chans(task) {
8+
unit_sz(unit_sz), writers(task) {
99

1010
LOG(task, comm,
1111
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
@@ -14,47 +14,37 @@ rust_port::rust_port(rust_task *task, size_t unit_sz)
1414
id = task->register_port(this);
1515
remote_chan = new (task->kernel, "rust_chan")
1616
rust_chan(task->kernel, this, unit_sz);
17+
remote_chan->ref();
18+
remote_chan->port = this;
1719
}
1820

1921
rust_port::~rust_port() {
2022
LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this);
2123

22-
// Disassociate channels from this port.
23-
while (chans.is_empty() == false) {
24+
{
2425
scoped_lock with(lock);
25-
rust_chan *chan = chans.peek();
26-
chan->disassociate();
26+
remote_chan->port = NULL;
27+
remote_chan->deref();
28+
remote_chan = NULL;
2729
}
2830

29-
remote_chan->deref();
30-
remote_chan = NULL;
31-
3231
task->release_port(id);
3332
}
3433

3534
bool rust_port::receive(void *dptr) {
36-
for (uint32_t i = 0; i < chans.length(); i++) {
37-
rust_chan *chan = chans[i];
38-
if (chan->buffer.is_empty() == false) {
39-
chan->buffer.dequeue(dptr);
40-
LOG(task, comm, "<=== read data ===");
41-
return true;
42-
}
35+
if (remote_chan->buffer.is_empty() == false) {
36+
remote_chan->buffer.dequeue(dptr);
37+
LOG(task, comm, "<=== read data ===");
38+
return true;
4339
}
4440
return false;
4541
}
4642

4743
void rust_port::log_state() {
4844
LOG(task, comm,
49-
"rust_port: 0x%" PRIxPTR ", associated channel(s): %d",
50-
this, chans.length());
51-
for (uint32_t i = 0; i < chans.length(); i++) {
52-
rust_chan *chan = chans[i];
53-
LOG(task, comm,
54-
"\tchan: 0x%" PRIxPTR ", size: %d",
55-
chan,
56-
chan->buffer.size());
57-
}
45+
"\tchan: 0x%" PRIxPTR ", size: %d",
46+
remote_chan,
47+
remote_chan->buffer.size());
5848
}
5949

6050
//

trunk/src/rt/rust_port.h

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class rust_port : public kernel_owned<rust_port>, public rust_cond {
1212
rust_chan *remote_chan;
1313
size_t unit_sz;
1414
ptr_vec<rust_token> writers;
15-
ptr_vec<rust_chan> chans;
1615

1716
lock_and_signal lock;
1817

0 commit comments

Comments
 (0)