From 74e12fcef682acdbec6c3f4a3fb29b7583e7d1b6 Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Wed, 11 Aug 2010 16:08:26 -0700 Subject: [PATCH] Ignore upcall_flush for channels that are disassociated from ports. This makes task-comm-10 break a little less hard, but it still leaks because messages pending in the channel are never freed. --- src/rt/circular_buffer.cpp | 5 +++++ src/rt/circular_buffer.h | 1 + src/rt/rust_port.cpp | 4 ++-- src/rt/rust_upcall.cpp | 8 ++++++++ src/test/run-pass/task-comm-10.rs | 3 +-- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp index dbf5059bf22..caa9535907e 100644 --- a/src/rt/circular_buffer.cpp +++ b/src/rt/circular_buffer.cpp @@ -142,3 +142,8 @@ bool circular_buffer::is_empty() { return _unread == 0; } + +size_t +circular_buffer::size() { + return _unread; +} diff --git a/src/rt/circular_buffer.h b/src/rt/circular_buffer.h index 732ba329dac..9ddaba42dc9 100644 --- a/src/rt/circular_buffer.h +++ b/src/rt/circular_buffer.h @@ -21,6 +21,7 @@ public: void dequeue(void *dst); uint8_t *peek(); bool is_empty(); + size_t size(); private: // Size of the buffer in bytes, should always be a power of two so that diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp index c97b5d4170a..fa7790b6025 100644 --- a/src/rt/rust_port.cpp +++ b/src/rt/rust_port.cpp @@ -54,9 +54,9 @@ void rust_port::log_state() { for (uint32_t i = 0; i < chans.length(); i++) { rust_chan *chan = chans[i]; task->log(rust_log::COMM, - "\tchan: 0x%" PRIxPTR ", data pending: %s, remote: %s", + "\tchan: 0x%" PRIxPTR ", size: %d, remote: %s", chan, - !chan->buffer.is_empty() ? "yes" : "no", + chan->buffer.size(), chan == remote_channel ? "yes" : "no"); } } diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 90d6f6d9037..01eaf744843 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -116,6 +116,14 @@ upcall_flush_chan(rust_task *task, rust_chan *chan) { return; } + // We cannot flush if the target port was dropped. + if (chan->is_associated() == false) { + return; + } + + A(dom, chan->is_associated(), + "Channel should be associated to a port."); + A(dom, chan->port->is_proxy() == false, "Channels to remote ports should be flushed automatically."); diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 529ef6f51d8..4cdcf18b9ce 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -2,8 +2,7 @@ let port[str] p = port(); c <| chan(p); auto a <- p; - auto b <- p; - // Never read the second string. + // auto b <- p; // Never read the second string. } io fn main() {