rust/src/rt/rust_port.cpp

70 lines
1.8 KiB
C++
Raw Normal View History

#include "rust_internal.h"
#include "rust_port.h"
2011-08-10 01:07:49 +02:00
extern "C" CDECL rust_chan*
new_chan(rust_task *task, rust_port *port);
rust_port::rust_port(rust_task *task, size_t unit_sz)
2011-07-29 20:00:44 +02:00
: ref_count(1), kernel(task->kernel), task(task),
unit_sz(unit_sz), writers(task), chans(task) {
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-09 03:09:42 +02:00
id = task->register_port(this);
2011-08-10 01:07:49 +02:00
remote_chan = new_chan(task, this);
}
rust_port::~rust_port() {
LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this);
// Disassociate channels from this port.
while (chans.is_empty() == false) {
2011-07-29 20:00:44 +02:00
scoped_lock with(lock);
rust_chan *chan = chans.peek();
chan->disassociate();
}
2011-08-09 03:09:42 +02:00
2011-08-10 01:07:49 +02:00
remote_chan->deref();
remote_chan = NULL;
2011-08-09 03:09:42 +02:00
task->release_port(id);
}
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);
LOG(task, comm, "<=== read data ===");
return true;
}
}
return false;
}
2010-08-09 16:52:07 +02:00
void rust_port::log_state() {
LOG(task, comm,
2010-08-09 16:52:07 +02:00
"rust_port: 0x%" PRIxPTR ", associated channel(s): %d",
this, chans.length());
for (uint32_t i = 0; i < chans.length(); i++) {
rust_chan *chan = chans[i];
LOG(task, comm,
2011-08-06 00:16:48 +02:00
"\tchan: 0x%" PRIxPTR ", size: %d",
2010-08-09 16:52:07 +02:00
chan,
2011-08-06 00:16:48 +02:00
chan->buffer.size());
2010-08-09 16:52:07 +02: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 22:51:20 +02:00
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//