2010-07-28 16:46:13 -07:00
|
|
|
#include "rust_internal.h"
|
|
|
|
#include "rust_port.h"
|
|
|
|
|
2011-07-13 15:44:09 -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-07-07 11:53:08 -07:00
|
|
|
unit_sz(unit_sz), writers(task), chans(task) {
|
2010-07-28 16:46:13 -07:00
|
|
|
|
2011-04-19 12:21:57 +02:00
|
|
|
LOG(task, comm,
|
|
|
|
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
|
|
|
|
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
|
2010-07-28 16:46:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
rust_port::~rust_port() {
|
2011-04-19 12:21:57 +02:00
|
|
|
LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this);
|
2010-07-28 16:46:13 -07:00
|
|
|
|
|
|
|
// Disassociate channels from this port.
|
|
|
|
while (chans.is_empty() == false) {
|
2011-07-29 11:00:44 -07:00
|
|
|
scoped_lock with(lock);
|
2010-08-09 08:15:34 -07:00
|
|
|
rust_chan *chan = chans.peek();
|
|
|
|
chan->disassociate();
|
2010-07-28 16:46:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 08:15:34 -07:00
|
|
|
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);
|
2011-04-19 12:21:57 +02:00
|
|
|
LOG(task, comm, "<=== read data ===");
|
2010-08-09 08:15:34 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-09 07:52:07 -07:00
|
|
|
void rust_port::log_state() {
|
2011-04-19 12:21:57 +02:00
|
|
|
LOG(task, comm,
|
2010-08-09 07:52:07 -07: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];
|
2011-04-19 12:21:57 +02:00
|
|
|
LOG(task, comm,
|
2011-08-05 15:16:48 -07:00
|
|
|
"\tchan: 0x%" PRIxPTR ", size: %d",
|
2010-08-09 07:52:07 -07:00
|
|
|
chan,
|
2011-08-05 15:16:48 -07:00
|
|
|
chan->buffer.size());
|
2010-08-09 07:52:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 16:46:13 -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'";
|
2010-07-28 16:46:13 -07:00
|
|
|
// End:
|
|
|
|
//
|