8acadb17c2
Ports and channels have been moved to the kernel pool, since they've been known to outlive their associated task. This probably isn't the right thing to do, the life cycle needs fixed instead. Some refactorying in memory_region.cpp. Added a helper function to increment and decrement the allocation counter. This makes it easier to switch between atomic and non-atomic increments. Using atomic increments for now, although this still does not fix the problem.
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#include "rust_internal.h"
|
|
#include "rust_port.h"
|
|
|
|
rust_port::rust_port(rust_task *task, size_t unit_sz)
|
|
: maybe_proxy<rust_port>(this), 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);
|
|
|
|
// Allocate a remote channel, for remote channel data.
|
|
remote_channel = new (task->kernel) rust_chan(task, this, unit_sz);
|
|
}
|
|
|
|
rust_port::~rust_port() {
|
|
LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this);
|
|
|
|
// log_state();
|
|
|
|
// Disassociate channels from this port.
|
|
while (chans.is_empty() == false) {
|
|
rust_chan *chan = chans.peek();
|
|
chan->disassociate();
|
|
|
|
if (chan->ref_count == 0) {
|
|
LOG(task, comm,
|
|
"chan: 0x%" PRIxPTR " is dormant, freeing", chan);
|
|
delete chan;
|
|
}
|
|
}
|
|
|
|
delete remote_channel;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void rust_port::log_state() {
|
|
LOG(task, comm,
|
|
"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,
|
|
"\tchan: 0x%" PRIxPTR ", size: %d, remote: %s",
|
|
chan,
|
|
chan->buffer.size(),
|
|
chan == remote_channel ? "yes" : "no");
|
|
}
|
|
}
|
|
|
|
//
|
|
// Local Variables:
|
|
// mode: C++
|
|
// fill-column: 78;
|
|
// indent-tabs-mode: nil
|
|
// c-basic-offset: 4
|
|
// buffer-file-coding-system: utf-8-unix
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
// End:
|
|
//
|