about summary refs log tree commit diff
path: root/src/rt/rust_kernel.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-03-14 17:24:19 -0700
committerBrian Anderson <banderson@mozilla.com>2012-03-15 11:10:52 -0700
commitb278d675a231fdfe825c72e499d59e8a3d07ffaa (patch)
tree426a39a89561d56ac72e328aecc64c045a578e18 /src/rt/rust_kernel.cpp
parent337d860a8777a761267daaad9b561787b10e7c87 (diff)
downloadrust-b278d675a231fdfe825c72e499d59e8a3d07ffaa.tar.gz
rust-b278d675a231fdfe825c72e499d59e8a3d07ffaa.zip
rt: Look up ports through a single port table
Instead of a two-level lookup, just use one big table
Diffstat (limited to 'src/rt/rust_kernel.cpp')
-rw-r--r--src/rt/rust_kernel.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp
index b0c93c315ed..e32f4d6dda8 100644
--- a/src/rt/rust_kernel.cpp
+++ b/src/rt/rust_kernel.cpp
@@ -18,6 +18,7 @@ rust_kernel::rust_kernel(rust_srv *srv) :
     _log(srv, NULL),
     srv(srv),
     max_task_id(0),
+    max_port_id(0),
     rval(0),
     max_sched_id(0),
     env(srv->env)
@@ -212,6 +213,46 @@ rust_kernel::get_task_by_id(rust_task_id id) {
     return task;
 }
 
+rust_port_id
+rust_kernel::register_port(rust_port *port) {
+    uintptr_t new_live_ports;
+    rust_port_id new_port_id;
+    {
+        scoped_lock with(port_lock);
+        new_port_id = max_port_id++;
+        port_table.put(new_port_id, port);
+        new_live_ports = port_table.count();
+    }
+    K(srv, new_port_id != INTPTR_MAX, "Hit the maximum port id");
+    KLOG_("Registered port %" PRIdPTR, new_port_id);
+    KLOG_("Total outstanding ports: %d", new_live_ports);
+    return new_port_id;
+}
+
+void
+rust_kernel::release_port_id(rust_port_id id) {
+    KLOG_("Releasing port %" PRIdPTR, id);
+    uintptr_t new_live_ports;
+    {
+        scoped_lock with(port_lock);
+        port_table.remove(id);
+        new_live_ports = port_table.count();
+    }
+    KLOG_("Total outstanding ports: %d", new_live_ports);
+}
+
+rust_port *
+rust_kernel::get_port_by_id(rust_port_id id) {
+    scoped_lock with(port_lock);
+    rust_port *port = NULL;
+    // get leaves port unchanged if not found.
+    port_table.get(id, &port);
+    if(port) {
+        port->ref();
+    }
+    return port;
+}
+
 #ifdef __WIN32__
 void
 rust_kernel::win32_require(LPCTSTR fn, BOOL ok) {