rust/src/rt/rust_port.cpp

82 lines
2.0 KiB
C++
Raw Normal View History

#include "rust_internal.h"
#include "rust_port.h"
2011-11-10 15:59:31 -08:00
#include "rust_chan.h"
2011-08-09 16:07:49 -07:00
rust_port::rust_port(rust_task *task, size_t unit_sz)
2011-07-29 11:00:44 -07:00
: ref_count(1), kernel(task->kernel), task(task),
2011-11-10 17:35:21 -08:00
unit_sz(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);
2011-08-08 18:09:42 -07:00
id = task->register_port(this);
2011-11-10 15:59:31 -08:00
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);
{
2011-07-29 11:00:44 -07:00
scoped_lock with(lock);
remote_chan->port = NULL;
remote_chan->deref();
remote_chan = NULL;
}
2011-08-08 18:09:42 -07:00
task->release_port(id);
}
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;
}
scoped_lock with(lock);
remote_chan->buffer.enqueue(sptr);
A(kernel, !remote_chan->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);
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);
LOG(task, comm, "<=== read data ===");
return true;
}
return false;
}
2010-08-09 07:52:07 -07:00
void rust_port::log_state() {
LOG(task, comm,
"\tchan: 0x%" PRIxPTR ", size: %d",
remote_chan,
remote_chan->buffer.size());
2010-08-09 07:52:07 -07:00
}
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
2011-07-13 13:51:20 -07:00
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//