diff options
Diffstat (limited to 'src/rt/rust_port.cpp')
| -rw-r--r-- | src/rt/rust_port.cpp | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp index a68b4417110..5daf5e40033 100644 --- a/src/rt/rust_port.cpp +++ b/src/rt/rust_port.cpp @@ -1,61 +1,47 @@ #include "rust_internal.h" #include "rust_port.h" -#include "rust_chan.h" rust_port::rust_port(rust_task *task, size_t unit_sz) : ref_count(1), kernel(task->kernel), task(task), - unit_sz(unit_sz) { + unit_sz(unit_sz), buffer(kernel, unit_sz) { LOG(task, comm, "new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%" PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this); + task->ref(); id = task->register_port(this); - remote_chan = new (task->kernel, "rust_chan") - rust_chan(task->kernel, this, unit_sz); - remote_chan->ref(); - remote_chan->port = this; } rust_port::~rust_port() { LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this); - { - scoped_lock with(lock); - remote_chan->port = NULL; - remote_chan->deref(); - remote_chan = NULL; - } - task->release_port(id); + task->deref(); } void rust_port::send(void *sptr) { - if (!remote_chan->is_associated()) { - W(kernel, remote_chan->is_associated(), - "rust_chan::transmit with no associated port."); - return; - } - + // FIXME: Is this lock really necessary? Why do we send with the lock + // but not receive with the lock? scoped_lock with(lock); - remote_chan->buffer.enqueue(sptr); + buffer.enqueue(sptr); - A(kernel, !remote_chan->buffer.is_empty(), + A(kernel, !buffer.is_empty(), "rust_chan::transmit with nothing to send."); if (task->blocked_on(this)) { KLOG(kernel, comm, "dequeued in rendezvous_ptr"); - remote_chan->buffer.dequeue(task->rendezvous_ptr); + buffer.dequeue(task->rendezvous_ptr); task->rendezvous_ptr = 0; task->wakeup(this); } } bool rust_port::receive(void *dptr) { - if (remote_chan->buffer.is_empty() == false) { - remote_chan->buffer.dequeue(dptr); + if (buffer.is_empty() == false) { + buffer.dequeue(dptr); LOG(task, comm, "<=== read data ==="); return true; } @@ -64,9 +50,8 @@ bool rust_port::receive(void *dptr) { void rust_port::log_state() { LOG(task, comm, - "\tchan: 0x%" PRIxPTR ", size: %d", - remote_chan, - remote_chan->buffer.size()); + "port size: %d", + buffer.size()); } // |
