core: Channels are just port ids
This commit is contained in:
parent
c414b78afe
commit
561511e628
@ -38,9 +38,8 @@ enum rust_port {}
|
|||||||
|
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
native mod rustrt {
|
native mod rustrt {
|
||||||
fn get_task_id() -> task_id;
|
fn rust_port_id_send<T: send>(t: *sys::type_desc,
|
||||||
fn chan_id_send<T: send>(t: *sys::type_desc,
|
target_port: port_id,
|
||||||
target_task: task_id, target_port: port_id,
|
|
||||||
data: T) -> libc::uintptr_t;
|
data: T) -> libc::uintptr_t;
|
||||||
|
|
||||||
fn new_port(unit_sz: libc::size_t) -> *rust_port;
|
fn new_port(unit_sz: libc::size_t) -> *rust_port;
|
||||||
@ -63,7 +62,6 @@ fn rust_port_select(dptr: **rust_port, ports: **rust_port,
|
|||||||
fn call_with_retptr<T: send>(&&f: fn@(*uint)) -> T;
|
fn call_with_retptr<T: send>(&&f: fn@(*uint)) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
type task_id = int;
|
|
||||||
type port_id = int;
|
type port_id = int;
|
||||||
|
|
||||||
// It's critical that this only have one variant, so it has a record
|
// It's critical that this only have one variant, so it has a record
|
||||||
@ -79,7 +77,7 @@ fn rust_port_select(dptr: **rust_port, ports: **rust_port,
|
|||||||
themselves transmitted over other channels.
|
themselves transmitted over other channels.
|
||||||
"]
|
"]
|
||||||
enum chan<T: send> {
|
enum chan<T: send> {
|
||||||
chan_t(task_id, port_id)
|
chan_t(port_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource port_ptr<T: send>(po: *rust_port) {
|
resource port_ptr<T: send>(po: *rust_port) {
|
||||||
@ -119,8 +117,8 @@ enum port<T: send> { port_t(@port_ptr<T>) }
|
|||||||
whereupon the caller loses access to it.
|
whereupon the caller loses access to it.
|
||||||
"]
|
"]
|
||||||
fn send<T: send>(ch: chan<T>, -data: T) {
|
fn send<T: send>(ch: chan<T>, -data: T) {
|
||||||
let chan_t(t, p) = ch;
|
let chan_t(p) = ch;
|
||||||
let res = rustrt::chan_id_send(sys::get_type_desc::<T>(), t, p, data);
|
let res = rustrt::rust_port_id_send(sys::get_type_desc::<T>(), p, data);
|
||||||
if res != 0u unsafe {
|
if res != 0u unsafe {
|
||||||
// Data sent successfully
|
// Data sent successfully
|
||||||
unsafe::leak(data);
|
unsafe::leak(data);
|
||||||
@ -217,7 +215,7 @@ fn peek<T: send>(p: port<T>) -> bool {
|
|||||||
construct it.
|
construct it.
|
||||||
"]
|
"]
|
||||||
fn chan<T: send>(p: port<T>) -> chan<T> {
|
fn chan<T: send>(p: port<T>) -> chan<T> {
|
||||||
chan_t(rustrt::get_task_id(), rustrt::get_port_id(***p))
|
chan_t(rustrt::get_port_id(***p))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -444,8 +444,8 @@ rust_new_task_in_sched(rust_sched_id id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
extern "C" CDECL void
|
||||||
rust_task_config_notify(rust_task *target, chan_handle *chan) {
|
rust_task_config_notify(rust_task *target, rust_port_id *port) {
|
||||||
target->config_notify(*chan);
|
target->config_notify(*port);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" rust_task *
|
extern "C" rust_task *
|
||||||
@ -503,13 +503,11 @@ get_port_id(rust_port *port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL uintptr_t
|
extern "C" CDECL uintptr_t
|
||||||
chan_id_send(type_desc *t, rust_task_id target_task_id,
|
rust_port_id_send(type_desc *t, rust_port_id target_port_id, void *sptr) {
|
||||||
rust_port_id target_port_id, void *sptr) {
|
|
||||||
bool sent = false;
|
bool sent = false;
|
||||||
rust_task *task = rust_task_thread::get_task();
|
rust_task *task = rust_task_thread::get_task();
|
||||||
|
|
||||||
LOG(task, comm, "chan_id_send task: 0x%" PRIxPTR
|
LOG(task, comm, "rust_port_id*_send port: 0x%" PRIxPTR,
|
||||||
" port: 0x%" PRIxPTR, (uintptr_t) target_task_id,
|
|
||||||
(uintptr_t) target_port_id);
|
(uintptr_t) target_port_id);
|
||||||
|
|
||||||
rust_port *port = task->kernel->get_port_by_id(target_port_id);
|
rust_port *port = task->kernel->get_port_by_id(target_port_id);
|
||||||
|
@ -475,7 +475,7 @@ rust_task::notify(bool success) {
|
|||||||
// FIXME (1078) Do this in rust code
|
// FIXME (1078) Do this in rust code
|
||||||
if(notify_enabled) {
|
if(notify_enabled) {
|
||||||
rust_port *target_port =
|
rust_port *target_port =
|
||||||
kernel->get_port_by_id(notify_chan.port);
|
kernel->get_port_by_id(notify_port);
|
||||||
if(target_port) {
|
if(target_port) {
|
||||||
task_notification msg;
|
task_notification msg;
|
||||||
msg.id = id;
|
msg.id = id;
|
||||||
@ -719,9 +719,9 @@ rust_task::delete_all_stacks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rust_task::config_notify(chan_handle chan) {
|
rust_task::config_notify(rust_port_id port) {
|
||||||
notify_enabled = true;
|
notify_enabled = true;
|
||||||
notify_chan = chan;
|
notify_port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
#include "rust_stack.h"
|
#include "rust_stack.h"
|
||||||
#include "rust_port_selector.h"
|
#include "rust_port_selector.h"
|
||||||
|
|
||||||
// Corresponds to the rust chan (currently _chan) type.
|
|
||||||
struct chan_handle {
|
|
||||||
rust_task_id task;
|
|
||||||
rust_port_id port;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct rust_box;
|
struct rust_box;
|
||||||
|
|
||||||
struct frame_glue_fns {
|
struct frame_glue_fns {
|
||||||
@ -56,7 +50,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
|||||||
|
|
||||||
rust_task_id id;
|
rust_task_id id;
|
||||||
bool notify_enabled;
|
bool notify_enabled;
|
||||||
chan_handle notify_chan;
|
rust_port_id notify_port;
|
||||||
|
|
||||||
context ctx;
|
context ctx;
|
||||||
stk_seg *stk;
|
stk_seg *stk;
|
||||||
@ -209,7 +203,7 @@ public:
|
|||||||
void check_stack_canary();
|
void check_stack_canary();
|
||||||
void delete_all_stacks();
|
void delete_all_stacks();
|
||||||
|
|
||||||
void config_notify(chan_handle chan);
|
void config_notify(rust_port_id port);
|
||||||
|
|
||||||
void call_on_c_stack(void *args, void *fn_ptr);
|
void call_on_c_stack(void *args, void *fn_ptr);
|
||||||
void call_on_rust_stack(void *args, void *fn_ptr);
|
void call_on_rust_stack(void *args, void *fn_ptr);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
chan_id_send
|
|
||||||
check_claims
|
check_claims
|
||||||
debug_box
|
debug_box
|
||||||
debug_fn
|
debug_fn
|
||||||
@ -16,6 +15,7 @@ new_port
|
|||||||
new_task
|
new_task
|
||||||
port_recv
|
port_recv
|
||||||
precise_time_ns
|
precise_time_ns
|
||||||
|
rust_port_id_send
|
||||||
rust_port_select
|
rust_port_select
|
||||||
rand_free
|
rand_free
|
||||||
rand_new
|
rand_new
|
||||||
|
Loading…
Reference in New Issue
Block a user