rt: Move receive code into rust_port
This commit is contained in:
parent
77295c56c5
commit
e08f46db68
3 changed files with 24 additions and 28 deletions
|
@ -544,29 +544,7 @@ rust_task_yield(rust_task *task, bool *killed) {
|
||||||
|
|
||||||
extern "C" CDECL void
|
extern "C" CDECL void
|
||||||
port_recv(uintptr_t *dptr, rust_port *port, uintptr_t *yield) {
|
port_recv(uintptr_t *dptr, rust_port *port, uintptr_t *yield) {
|
||||||
*yield = false;
|
port->receive(dptr, yield);
|
||||||
rust_task *task = rust_task_thread::get_task();
|
|
||||||
{
|
|
||||||
scoped_lock with(port->lock);
|
|
||||||
|
|
||||||
LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
|
|
||||||
", size: 0x%" PRIxPTR,
|
|
||||||
(uintptr_t) port, (uintptr_t) dptr, port->unit_sz);
|
|
||||||
|
|
||||||
if (port->receive(dptr)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No data was buffered on any incoming channel, so block this task on
|
|
||||||
// the port. Remember the rendezvous location so that any sender task
|
|
||||||
// can write to it before waking up this task.
|
|
||||||
|
|
||||||
LOG(task, comm, "<=== waiting for rendezvous data ===");
|
|
||||||
task->rendezvous_ptr = dptr;
|
|
||||||
task->block(port, "waiting for rendezvous data");
|
|
||||||
}
|
|
||||||
*yield = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
extern "C" CDECL void
|
||||||
|
|
|
@ -63,14 +63,32 @@ void rust_port::send(void *sptr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rust_port::receive(void *dptr) {
|
void rust_port::receive(void *dptr, uintptr_t *yield) {
|
||||||
I(task->thread, lock.lock_held_by_current_thread());
|
I(task->thread, !lock.lock_held_by_current_thread());
|
||||||
|
|
||||||
|
LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
|
||||||
|
", size: 0x%" PRIxPTR,
|
||||||
|
(uintptr_t) this, (uintptr_t) dptr, unit_sz);
|
||||||
|
|
||||||
|
scoped_lock with(lock);
|
||||||
|
|
||||||
|
*yield = false;
|
||||||
|
|
||||||
if (buffer.is_empty() == false) {
|
if (buffer.is_empty() == false) {
|
||||||
buffer.dequeue(dptr);
|
buffer.dequeue(dptr);
|
||||||
LOG(task, comm, "<=== read data ===");
|
LOG(task, comm, "<=== read data ===");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
// No data was buffered on any incoming channel, so block this task on
|
||||||
|
// the port. Remember the rendezvous location so that any sender task
|
||||||
|
// can write to it before waking up this task.
|
||||||
|
|
||||||
|
LOG(task, comm, "<=== waiting for rendezvous data ===");
|
||||||
|
task->rendezvous_ptr = (uintptr_t*) dptr;
|
||||||
|
task->block(this, "waiting for rendezvous data");
|
||||||
|
|
||||||
|
*yield = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t rust_port::size() {
|
size_t rust_port::size() {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
~rust_port();
|
~rust_port();
|
||||||
void log_state();
|
void log_state();
|
||||||
void send(void *sptr);
|
void send(void *sptr);
|
||||||
bool receive(void *dptr);
|
void receive(void *dptr, uintptr_t *yield);
|
||||||
size_t size();
|
size_t size();
|
||||||
void detach();
|
void detach();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue