aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_port.cpp
diff options
context:
space:
mode:
authorMichael Bebenita <[email protected]>2010-08-09 08:15:34 -0700
committerMichael Bebenita <[email protected]>2010-08-09 08:15:34 -0700
commit97d6342bf08e55f8d2b4f8df5c4b5a099df0191c (patch)
treebfed15fefbc032deba1c34908f25c1562d88aa6b /src/rt/rust_port.cpp
parentFixed deadlock in the scheduler caused by condition variables. (diff)
downloadrust-97d6342bf08e55f8d2b4f8df5c4b5a099df0191c.tar.xz
rust-97d6342bf08e55f8d2b4f8df5c4b5a099df0191c.zip
Synthesize a flush_chan upcall right before a channel's ref_count drops to zero. This should only happen in the Rust code and not in the drop glue, or on the unwind path. This change allows the task owning the channel to block on a flush and delete its own channel. This change also cleans up some code around rust_port and rust_chan.
Diffstat (limited to 'src/rt/rust_port.cpp')
-rw-r--r--src/rt/rust_port.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp
index bd9af6f9..c97b5d41 100644
--- a/src/rt/rust_port.cpp
+++ b/src/rt/rust_port.cpp
@@ -21,14 +21,32 @@ rust_port::~rust_port() {
// Disassociate channels from this port.
while (chans.is_empty() == false) {
- chans.pop()->disassociate();
+ rust_chan *chan = chans.peek();
+ chan->disassociate();
}
- // We're the only ones holding a reference to the remote channel, so
- // clean it up.
delete remote_channel;
}
+bool rust_port::receive(void *dptr) {
+ for (uint32_t i = 0; i < chans.length(); i++) {
+ rust_chan *chan = chans[i];
+ if (chan->buffer.is_empty() == false) {
+ chan->buffer.dequeue(dptr);
+ if (chan->buffer.is_empty() && chan->task->blocked()) {
+ task->log(rust_log::COMM,
+ "chan: 0x%" PRIxPTR
+ " is flushing, wakeup task: 0x%" PRIxPTR,
+ chan, chan->task);
+ chan->task->wakeup(this);
+ }
+ task->log(rust_log::COMM, "<=== read data ===");
+ return true;
+ }
+ }
+ return false;
+}
+
void rust_port::log_state() {
task->log(rust_log::COMM,
"rust_port: 0x%" PRIxPTR ", associated channel(s): %d",