about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-06-24 15:56:12 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-06-28 16:12:33 -0700
commitc6d83248301b4aed366b9bef682d200381324c01 (patch)
tree12d0f6b3abed022825454c21d6fdfb60e81492f3
parent1c852ac9c0d14b38bc956e3938256273980577b7 (diff)
downloadrust-c6d83248301b4aed366b9bef682d200381324c01.tar.gz
rust-c6d83248301b4aed366b9bef682d200381324c01.zip
There is only one domain per kernel now.
-rw-r--r--src/comp/back/upcall.rs6
-rw-r--r--src/rt/rust.cpp5
-rw-r--r--src/rt/rust_kernel.cpp41
-rw-r--r--src/rt/rust_kernel.h20
-rw-r--r--src/rt/rust_upcall.cpp80
-rw-r--r--src/rt/rustrt.def.in2
6 files changed, 21 insertions, 133 deletions
diff --git a/src/comp/back/upcall.rs b/src/comp/back/upcall.rs
index 1a5a9a8d254..1ed0d4bbf9c 100644
--- a/src/comp/back/upcall.rs
+++ b/src/comp/back/upcall.rs
@@ -55,8 +55,6 @@ type upcalls =
         ValueRef get_type_desc,
         ValueRef new_task,
         ValueRef start_task,
-        ValueRef new_thread,
-        ValueRef start_thread,
         ValueRef ivec_resize,
         ValueRef ivec_spill);
 
@@ -118,10 +116,6 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
              start_task=d("start_task",
                           [T_taskptr(tn), T_int(), T_int(), T_size_t()],
                           T_taskptr(tn)),
-             new_thread=d("new_thread", [T_ptr(T_i8())], T_taskptr(tn)),
-             start_thread=d("start_thread",
-                            [T_taskptr(tn), T_int(), T_int(), T_int(),
-                             T_size_t()], T_taskptr(tn)),
              ivec_resize=d("ivec_resize", [T_ptr(T_opaque_ivec()), T_int()],
                            T_void()),
              ivec_spill=d("ivec_spill", [T_ptr(T_opaque_ivec()), T_int()],
diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp
index 093656b77d2..1de1685692d 100644
--- a/src/rt/rust.cpp
+++ b/src/rt/rust.cpp
@@ -96,8 +96,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
     rust_srv *srv = new rust_srv();
     rust_kernel *kernel = new rust_kernel(srv);
     kernel->start();
-    rust_handle<rust_dom> *handle = kernel->create_domain("main");
-    rust_dom *dom = handle->referent();
+    rust_dom *dom = kernel->get_domain();
     command_line_args *args = new (dom) command_line_args(dom, argc, argv);
 
     DLOG(dom, dom, "startup: %d args in 0x%" PRIxPTR,
@@ -114,8 +113,6 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
 
     int ret = dom->start_main_loops(num_threads);
     delete args;
-    kernel->destroy_domain(dom);
-    kernel->join_all_domains();
     delete kernel;
     delete srv;
 
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp
index f72da483c35..9af5f9e2b41 100644
--- a/src/rt/rust_kernel.cpp
+++ b/src/rt/rust_kernel.cpp
@@ -11,11 +11,12 @@ rust_kernel::rust_kernel(rust_srv *srv) :
     _region(&srv->local_region),
     _log(srv, NULL),
     _srv(srv),
-    _interrupt_kernel_loop(FALSE) {
-    // Nop.
+    _interrupt_kernel_loop(FALSE) 
+{
+    dom = create_domain("main");
 }
 
-rust_handle<rust_dom> *
+rust_dom *
 rust_kernel::create_domain(const char *name) {
     _kernel_lock.lock();
     rust_message_queue *message_queue =
@@ -25,21 +26,19 @@ rust_kernel::create_domain(const char *name) {
         new (this) rust_dom(this, message_queue, srv, name);
     rust_handle<rust_dom> *handle = internal_get_dom_handle(dom);
     message_queue->associate(handle);
-    domains.append(dom);
     message_queues.append(message_queue);
-    KLOG("created domain: " PTR ", name: %s, index: %d, domains %d",
-         dom, name, dom->list_index, domains.length());
+    KLOG("created domain: " PTR ", name: %s, index: %d",
+         dom, name, dom->list_index);
     _kernel_lock.signal_all();
     _kernel_lock.unlock();
-    return handle;
+    return dom;
 }
 
 void
-rust_kernel::destroy_domain(rust_dom *dom) {
+rust_kernel::destroy_domain() {
     _kernel_lock.lock();
-    KLOG("deleting domain: " PTR ", name: %s, index: %d, domains %d",
-        dom, dom->name, dom->list_index, domains.length());
-    domains.remove(dom);
+    KLOG("deleting domain: " PTR ", name: %s, index: %d",
+        dom, dom->name, dom->list_index);
     dom->message_queue->disassociate();
     rust_srv *srv = dom->srv;
     delete dom;
@@ -97,21 +96,9 @@ rust_kernel::get_port_handle(rust_port *port) {
 }
 
 void
-rust_kernel::join_all_domains() {
-    _kernel_lock.lock();
-    while (domains.length() > 0) {
-        _kernel_lock.wait();
-    }
-    _kernel_lock.unlock();
-    KLOG("joined domains");
-}
-
-void
 rust_kernel::log_all_domain_state() {
-    KLOG("log_all_domain_state: %d domains", domains.length());
-    for (uint32_t i = 0; i < domains.length(); i++) {
-        domains[i]->log_state();
-    }
+    KLOG("log_all_domain_state");
+    dom->log_state();
 }
 
 /**
@@ -172,9 +159,7 @@ rust_kernel::terminate_kernel_loop() {
 }
 
 rust_kernel::~rust_kernel() {
-    K(_srv, domains.length() == 0,
-      "Kernel has %d live domain(s), join all domains before killing "
-       "the kernel.", domains.length());
+    destroy_domain();
 
     terminate_kernel_loop();
 
diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h
index 0c3df20358a..70495d029bc 100644
--- a/src/rt/rust_kernel.h
+++ b/src/rt/rust_kernel.h
@@ -44,6 +44,8 @@ class rust_kernel : public rust_thread {
     rust_log _log;
     rust_srv *_srv;
 
+    rust_dom *dom;
+
     /**
      * Task proxy objects are kernel owned handles to Rust objects.
      */
@@ -64,12 +66,10 @@ class rust_kernel : public rust_thread {
 
     rust_handle<rust_dom> *internal_get_dom_handle(rust_dom *dom);
 
-public:
+    rust_dom *create_domain(const char *name);
+    void destroy_domain();
 
-    /**
-     * List of domains that are currently executing.
-     */
-    indexed_list<rust_dom> domains;
+public:
 
     /**
      * Message queues are kernel objects and are associated with domains.
@@ -86,9 +86,6 @@ public:
 
     rust_kernel(rust_srv *srv);
 
-    rust_handle<rust_dom> *create_domain(const char *name);
-    void destroy_domain(rust_dom *dom);
-
     bool is_deadlocked();
 
     void signal_kernel_lock();
@@ -101,17 +98,14 @@ public:
     void
     notify_message_enqueued(rust_message_queue *queue, rust_message *message);
 
-    /**
-     * Blocks until all domains have terminated.
-     */
-    void join_all_domains();
-
     void log_all_domain_state();
     void log(uint32_t level, char const *fmt, ...);
     virtual ~rust_kernel();
 
     void *malloc(size_t size);
     void free(void *mem);
+
+    inline rust_dom *get_domain() const { return dom; }
 };
 
 inline void *operator new(size_t size, rust_kernel *kernel) {
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 0947c44b2c9..a769051b7eb 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -557,86 +557,6 @@ upcall_start_task(rust_task *spawner,
 }
 
 /**
- * Called whenever a new domain is created.
- */
-extern "C" CDECL maybe_proxy<rust_task> *
-upcall_new_thread(rust_task *task, const char *name) {
-    I(task->dom, false);
-    LOG_UPCALL_ENTRY(task);
-    rust_dom *parent_dom = task->dom;
-    rust_kernel *kernel = parent_dom->kernel;
-    rust_handle<rust_dom> *child_dom_handle =
-        kernel->create_domain(name);
-    rust_handle<rust_task> *child_task_handle =
-        kernel->get_task_handle(child_dom_handle->referent()->root_task);
-    LOG(task, mem, "child name: %s, child_dom_handle: " PTR
-        ", child_task_handle: " PTR,
-        name, child_dom_handle, child_task_handle);
-    rust_proxy<rust_task> *child_task_proxy =
-        new rust_proxy<rust_task> (child_task_handle);
-    return child_task_proxy;
-}
-
-#if 0 /* FIXME: this code will be re-enabled once we have multithreading. */
-
-#if defined(__WIN32__)
-static DWORD WINAPI rust_thread_start(void *ptr)
-#elif defined(__GNUC__)
-static void *rust_thread_start(void *ptr)
-#else
-#error "Platform not supported"
-#endif
-{
-    // We were handed the domain we are supposed to run.
-    rust_dom *dom = (rust_dom *) ptr;
-
-    // Start a new rust main loop for this thread.
-    dom->start_main_loop();
-
-    // Destroy the domain.
-    dom->kernel->destroy_domain(dom);
-
-    return 0;
-}
-
-#endif
-
-/**
- * Called after a new domain is created. Here we create a new thread and
- * and start the domain main loop.
- */
-extern "C" CDECL maybe_proxy<rust_task> *
-upcall_start_thread(rust_task *task,
-                    rust_proxy<rust_task> *child_task_proxy,
-                    uintptr_t spawnee_fn,
-                    size_t callsz) {
-    I(task->dom, false);
-    LOG_UPCALL_ENTRY(task);
-#if 0
-    rust_dom *parenet_dom = task->dom;
-    rust_handle<rust_task> *child_task_handle = child_task_proxy->handle();
-    LOG(task, task,
-              "spawnee_fn " PTR
-              ", callsz %" PRIdPTR ")",
-              spawnee_fn, callsz);
-    rust_task *child_task = child_task_handle->referent();
-    child_task->start(spawnee_fn,
-                      task->rust_sp, callsz);
-#if defined(__WIN32__)
-    HANDLE thread;
-    thread = CreateThread(NULL, 0, rust_thread_start, child_task->dom, 0,
-                          NULL);
-    parenet_dom->win32_require("CreateThread", thread != NULL);
-#else
-    pthread_t thread;
-    pthread_create(&thread, &parenet_dom->attr, rust_thread_start,
-                   (void *) child_task->dom);
-#endif
-#endif // 0
-    return child_task_proxy;
-}
-
-/**
  * Resizes an interior vector that has been spilled to the heap.
  */
 extern "C" CDECL void
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 17b4ba9817d..f3212bbeb00 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -67,13 +67,11 @@ upcall_new_chan
 upcall_new_port
 upcall_new_str
 upcall_new_task
-upcall_new_thread
 upcall_new_vec
 upcall_recv
 upcall_send
 upcall_sleep
 upcall_start_task
-upcall_start_thread
 upcall_trace_str
 upcall_trace_word
 upcall_vec_append