about summary refs log tree commit diff
path: root/src/rt/rust_message.cpp
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@mozilla.com>2010-07-28 16:24:50 -0700
committerGraydon Hoare <graydon@mozilla.com>2010-07-28 20:30:29 -0700
commit4ff8e15128f90d4e9e57897c48280c6f82bb8343 (patch)
tree86c3808e729b4f596c3c23e228738d3d25b108bc /src/rt/rust_message.cpp
parentdefd8a66eade4cb11960cf6de2b45c2f42ec3388 (diff)
downloadrust-4ff8e15128f90d4e9e57897c48280c6f82bb8343.tar.gz
rust-4ff8e15128f90d4e9e57897c48280c6f82bb8343.zip
Move notification-messages out into their own file and unify into notify_message, make them use proxies, cache task proxies in dom.
Diffstat (limited to 'src/rt/rust_message.cpp')
-rw-r--r--src/rt/rust_message.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/rt/rust_message.cpp b/src/rt/rust_message.cpp
new file mode 100644
index 00000000000..22f8ffe51b1
--- /dev/null
+++ b/src/rt/rust_message.cpp
@@ -0,0 +1,75 @@
+#include "rust_internal.h"
+#include "rust_message.h"
+
+rust_message::
+rust_message(const char* label, rust_task *source, rust_task *target) :
+             dom(target->dom), label(label),
+             _source(source),
+             _target(target) {
+}
+
+rust_message::~rust_message() {
+}
+
+void rust_message::process() {
+    I(dom, false);
+}
+
+rust_proxy<rust_task> *
+rust_message::get_source_proxy() {
+    return dom->get_task_proxy(_source);
+}
+
+notify_message::
+notify_message(notification_type type, const char* label,
+               rust_task *source,
+               rust_task *target) :
+               rust_message(label, source, target), type(type) {
+}
+
+/**
+ * Sends a message to the target task via a proxy. The message is allocated
+ * in the target task domain along with a proxy which points back to the
+ * source task.
+ */
+void notify_message::
+send(notification_type type, const char* label, rust_task *source,
+     rust_proxy<rust_task> *target) {
+    rust_task *target_task = target->delegate();
+    rust_dom *target_domain = target_task->dom;
+    notify_message *message = new (target_domain)
+        notify_message(type, label, source, target_task);
+    target_domain->send_message(message);
+}
+
+void notify_message::process() {
+    rust_task *task = _target;
+    switch (type) {
+    case KILL:
+        task->ref_count--;
+        task->kill();
+        break;
+    case JOIN: {
+        if (task->dead() == false) {
+            task->tasks_waiting_to_join.append(get_source_proxy());
+        } else {
+            send(WAKEUP, "wakeup", task, get_source_proxy());
+        }
+        break;
+    }
+    case WAKEUP:
+        task->wakeup(get_source_proxy()->delegate());
+        break;
+    }
+}
+
+//
+// Local Variables:
+// mode: C++
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+//