From 04af99ecb0dee1cb3df0032f7e7ba08ffc6c5bd4 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 8 Aug 2011 18:09:42 -0700 Subject: [PATCH] First step towards port handles. --- src/rt/rust_internal.h | 1 + src/rt/rust_port.cpp | 4 ++++ src/rt/rust_port.h | 5 ++++- src/rt/rust_task.cpp | 23 +++++++++++++++++++++-- src/rt/rust_task.h | 7 +++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h index 798087a9d54..2c4db3e0b31 100644 --- a/src/rt/rust_internal.h +++ b/src/rt/rust_internal.h @@ -65,6 +65,7 @@ struct type_desc; struct frame_glue_fns; typedef intptr_t rust_task_id; +typedef intptr_t rust_port_id; #ifndef __i386__ #error "Target CPU not supported." diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp index 62ee80cb1b7..448babfbdee 100644 --- a/src/rt/rust_port.cpp +++ b/src/rt/rust_port.cpp @@ -8,6 +8,8 @@ rust_port::rust_port(rust_task *task, size_t unit_sz) LOG(task, comm, "new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%" PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this); + + id = task->register_port(this); } rust_port::~rust_port() { @@ -19,6 +21,8 @@ rust_port::~rust_port() { rust_chan *chan = chans.peek(); chan->disassociate(); } + + task->release_port(id); } bool rust_port::receive(void *dptr) { diff --git a/src/rt/rust_port.h b/src/rt/rust_port.h index 46ace6942e1..9dac42244ef 100644 --- a/src/rt/rust_port.h +++ b/src/rt/rust_port.h @@ -2,10 +2,13 @@ #define RUST_PORT_H class rust_port : public kernel_owned, public rust_cond { - public: RUST_REFCOUNTED(rust_port); +private: + rust_port_id id; + +public: rust_kernel *kernel; rust_task *task; size_t unit_sz; diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index fbee8896590..26ffcb307a5 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -75,6 +75,7 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state, cond_name("none"), supervisor(spawner), list_index(-1), + next_port_id(0), rendezvous_ptr(0), running_on(-1), pinned_on(-1), @@ -105,8 +106,6 @@ rust_task::~rust_task() del_stk(this, stk); } -extern "C" void rust_new_exit_task_glue(); - struct spawn_args { rust_task *task; uintptr_t a3; @@ -495,6 +494,26 @@ void rust_task::on_wakeup(rust_task::wakeup_callback *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: // mode: C++ diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index be7a774db92..4286aaa8b41 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -59,6 +59,7 @@ rust_task : public kernel_owned, rust_cond size_t gc_alloc_accum; rust_task_id id; + rust_port_id next_port_id; // Keeps track of the last time this task yielded. timer yield_timer; @@ -96,6 +97,8 @@ rust_task : public kernel_owned, rust_cond lock_and_signal lock; + hash_map port_table; + // Only a pointer to 'name' is kept, so it must live as long as this task. rust_task(rust_scheduler *sched, rust_task_list *state, @@ -161,6 +164,10 @@ rust_task : public kernel_owned, rust_cond void unpin(); 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); }; //