First step towards port handles.
This commit is contained in:
parent
a21ebb2f5e
commit
04af99ecb0
5 changed files with 37 additions and 3 deletions
|
@ -65,6 +65,7 @@ struct type_desc;
|
||||||
struct frame_glue_fns;
|
struct frame_glue_fns;
|
||||||
|
|
||||||
typedef intptr_t rust_task_id;
|
typedef intptr_t rust_task_id;
|
||||||
|
typedef intptr_t rust_port_id;
|
||||||
|
|
||||||
#ifndef __i386__
|
#ifndef __i386__
|
||||||
#error "Target CPU not supported."
|
#error "Target CPU not supported."
|
||||||
|
|
|
@ -8,6 +8,8 @@ rust_port::rust_port(rust_task *task, size_t unit_sz)
|
||||||
LOG(task, comm,
|
LOG(task, comm,
|
||||||
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
|
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
|
||||||
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
|
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
|
||||||
|
|
||||||
|
id = task->register_port(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
rust_port::~rust_port() {
|
rust_port::~rust_port() {
|
||||||
|
@ -19,6 +21,8 @@ rust_port::~rust_port() {
|
||||||
rust_chan *chan = chans.peek();
|
rust_chan *chan = chans.peek();
|
||||||
chan->disassociate();
|
chan->disassociate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task->release_port(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rust_port::receive(void *dptr) {
|
bool rust_port::receive(void *dptr) {
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
#define RUST_PORT_H
|
#define RUST_PORT_H
|
||||||
|
|
||||||
class rust_port : public kernel_owned<rust_port>, public rust_cond {
|
class rust_port : public kernel_owned<rust_port>, public rust_cond {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RUST_REFCOUNTED(rust_port);
|
RUST_REFCOUNTED(rust_port);
|
||||||
|
|
||||||
|
private:
|
||||||
|
rust_port_id id;
|
||||||
|
|
||||||
|
public:
|
||||||
rust_kernel *kernel;
|
rust_kernel *kernel;
|
||||||
rust_task *task;
|
rust_task *task;
|
||||||
size_t unit_sz;
|
size_t unit_sz;
|
||||||
|
|
|
@ -75,6 +75,7 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
|
||||||
cond_name("none"),
|
cond_name("none"),
|
||||||
supervisor(spawner),
|
supervisor(spawner),
|
||||||
list_index(-1),
|
list_index(-1),
|
||||||
|
next_port_id(0),
|
||||||
rendezvous_ptr(0),
|
rendezvous_ptr(0),
|
||||||
running_on(-1),
|
running_on(-1),
|
||||||
pinned_on(-1),
|
pinned_on(-1),
|
||||||
|
@ -105,8 +106,6 @@ rust_task::~rust_task()
|
||||||
del_stk(this, stk);
|
del_stk(this, stk);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void rust_new_exit_task_glue();
|
|
||||||
|
|
||||||
struct spawn_args {
|
struct spawn_args {
|
||||||
rust_task *task;
|
rust_task *task;
|
||||||
uintptr_t a3;
|
uintptr_t a3;
|
||||||
|
@ -495,6 +494,26 @@ void rust_task::on_wakeup(rust_task::wakeup_callback *callback) {
|
||||||
_on_wakeup = callback;
|
_on_wakeup = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust_port_id rust_task::register_port(rust_port *port) {
|
||||||
|
scoped_lock with(lock);
|
||||||
|
|
||||||
|
rust_port_id id = next_port_id++;
|
||||||
|
port_table.put(id, port);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rust_task::release_port(rust_port_id id) {
|
||||||
|
scoped_lock with(lock);
|
||||||
|
port_table.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
rust_port *rust_task::get_port_by_id(rust_port_id id) {
|
||||||
|
scoped_lock with(lock);
|
||||||
|
rust_port *port = NULL;
|
||||||
|
port_table.get(id, &port);
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: C++
|
// mode: C++
|
||||||
|
|
|
@ -59,6 +59,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||||
size_t gc_alloc_accum;
|
size_t gc_alloc_accum;
|
||||||
|
|
||||||
rust_task_id id;
|
rust_task_id id;
|
||||||
|
rust_port_id next_port_id;
|
||||||
|
|
||||||
// Keeps track of the last time this task yielded.
|
// Keeps track of the last time this task yielded.
|
||||||
timer yield_timer;
|
timer yield_timer;
|
||||||
|
@ -96,6 +97,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||||
|
|
||||||
lock_and_signal lock;
|
lock_and_signal lock;
|
||||||
|
|
||||||
|
hash_map<rust_port_id, rust_port *> port_table;
|
||||||
|
|
||||||
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
// Only a pointer to 'name' is kept, so it must live as long as this task.
|
||||||
rust_task(rust_scheduler *sched,
|
rust_task(rust_scheduler *sched,
|
||||||
rust_task_list *state,
|
rust_task_list *state,
|
||||||
|
@ -161,6 +164,10 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||||
void unpin();
|
void unpin();
|
||||||
|
|
||||||
void on_wakeup(wakeup_callback *callback);
|
void on_wakeup(wakeup_callback *callback);
|
||||||
|
|
||||||
|
rust_port_id register_port(rust_port *port);
|
||||||
|
void release_port(rust_port_id id);
|
||||||
|
rust_port *get_port_by_id(rust_port_id id);
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue