Skip to content

Commit 793da65

Browse files
committed
rt: Move rust_chan::send to rust_port::send
1 parent 371574f commit 793da65

File tree

7 files changed

+33
-36
lines changed

7 files changed

+33
-36
lines changed

src/rt/rust_aio.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct socket_data : public task_owned<socket_data> {
4141
}
4242

4343
void send_result(void *data) {
44-
chan->send(&data);
44+
chan->port->send(&data);
4545
chan->deref();
4646
chan = NULL;
4747
}
@@ -138,7 +138,7 @@ static void read_progress(uv_stream_t *socket, ssize_t nread, uv_buf_t buf) {
138138
v->fill = nread;
139139
break;
140140
}
141-
data->reader->send(v);
141+
data->reader->port->send(v);
142142
}
143143

144144
static void new_connection(uv_stream_t *socket, int status) {
@@ -156,7 +156,7 @@ static void new_connection(uv_stream_t *socket, int status) {
156156
server->task->fail();
157157
return;
158158
}
159-
server->chan->send(&client);
159+
server->chan->port->send(&client);
160160
}
161161

162162
extern "C" CDECL socket_data *aio_serve(const char *ip, int port,
@@ -201,7 +201,7 @@ static void free_socket(uv_handle_t *handle) {
201201
bool closed = true;
202202
I(data->task->sched, data->chan != NULL);
203203
data->task->kill();
204-
data->chan->send(&closed);
204+
data->chan->port->send(&closed);
205205
}
206206
delete data;
207207
}
@@ -221,7 +221,7 @@ extern "C" CDECL void aio_close_server(socket_data *server,
221221
// XXX: hax until rust_task::kill
222222
// send null and the receiver knows to call back into native code to check
223223
void* null_client = NULL;
224-
server->chan->send(&null_client);
224+
server->chan->port->send(&null_client);
225225
server->chan->deref();
226226
server->chan = chan->clone(iotask);
227227
aio_close_socket(server);

src/rt/rust_builtin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
498498
if(target_task) {
499499
rust_port *port = target_task->get_port_by_id(target_port_id);
500500
if(port) {
501-
port->remote_chan->send(sptr);
501+
port->send(sptr);
502502
}
503503
target_task->deref();
504504
}

src/rt/rust_chan.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,6 @@ bool rust_chan::is_associated() {
3636
return port != NULL;
3737
}
3838

39-
/**
40-
* Attempt to send data to the associated port.
41-
*/
42-
void rust_chan::send(void *sptr) {
43-
if (!is_associated()) {
44-
W(kernel, is_associated(),
45-
"rust_chan::transmit with no associated port.");
46-
return;
47-
}
48-
49-
I(kernel, port != NULL);
50-
scoped_lock with(port->lock);
51-
52-
buffer.enqueue(sptr);
53-
54-
A(kernel, !buffer.is_empty(),
55-
"rust_chan::transmit with nothing to send.");
56-
57-
if (port->task->blocked_on(port)) {
58-
KLOG(kernel, comm, "dequeued in rendezvous_ptr");
59-
buffer.dequeue(port->task->rendezvous_ptr);
60-
port->task->rendezvous_ptr = 0;
61-
port->task->wakeup(port);
62-
}
63-
}
64-
6539
rust_chan *rust_chan::clone(rust_task *target) {
6640
return new (target->kernel, "cloned chan")
6741
rust_chan(kernel, port, buffer.unit_sz);

src/rt/rust_chan.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class rust_chan : public kernel_owned<rust_chan>,
1818

1919
bool is_associated();
2020

21-
void send(void *sptr);
22-
2321
rust_chan *clone(rust_task *target);
2422
};
2523

src/rt/rust_port.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ rust_port::~rust_port() {
3131
task->release_port(id);
3232
}
3333

34+
void rust_port::send(void *sptr) {
35+
if (!remote_chan->is_associated()) {
36+
W(kernel, remote_chan->is_associated(),
37+
"rust_chan::transmit with no associated port.");
38+
return;
39+
}
40+
41+
scoped_lock with(lock);
42+
43+
remote_chan->buffer.enqueue(sptr);
44+
45+
A(kernel, !remote_chan->buffer.is_empty(),
46+
"rust_chan::transmit with nothing to send.");
47+
48+
if (task->blocked_on(this)) {
49+
KLOG(kernel, comm, "dequeued in rendezvous_ptr");
50+
remote_chan->buffer.dequeue(task->rendezvous_ptr);
51+
task->rendezvous_ptr = 0;
52+
task->wakeup(this);
53+
}
54+
}
55+
3456
bool rust_port::receive(void *dptr) {
3557
if (remote_chan->buffer.is_empty() == false) {
3658
remote_chan->buffer.dequeue(dptr);

src/rt/rust_port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class rust_port : public kernel_owned<rust_port>, public rust_cond {
1717
rust_port(rust_task *task, size_t unit_sz);
1818
~rust_port();
1919
void log_state();
20+
void send(void *sptr);
2021
bool receive(void *dptr);
2122
};
2223

src/rt/rust_task.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ rust_task::~rust_task()
133133
msg.id = user.id;
134134
msg.result = failed ? tr_failure : tr_success;
135135

136-
target->send(&msg);
137-
target->deref();
136+
if (target->is_associated()) {
137+
target->port->send(&msg);
138+
target->deref();
139+
}
138140
}
139141
}
140142

0 commit comments

Comments
 (0)