summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-07-21 12:11:05 -0700
committerEric Holk <eholk@mozilla.com>2011-07-22 18:45:34 -0700
commit8878b128baddfa4ee38e4f9c43be75abe0edcd3d (patch)
treeaa36c8323cffd2cff75f39a26131137300b03555 /src/rt
parent8f2254b8c28c17bf7346975205b623ee92ba947c (diff)
downloadrust-8878b128baddfa4ee38e4f9c43be75abe0edcd3d.tar.gz
rust-8878b128baddfa4ee38e4f9c43be75abe0edcd3d.zip
More work on word-count.
Updated the MapReduce protocol so that it's correct more often. It's
still not perfect, but the bugs repro less often now.

Also found a race condition in channel sending. The problem is that
send and receive both need to refer to the _unread field in
circular_buffer. For now I just grabbed the port lock to send. We can
probably get around this by using atomics instead.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_builtin.cpp5
-rw-r--r--src/rt/rust_chan.cpp11
-rw-r--r--src/rt/rustrt.def.in1
3 files changed, 14 insertions, 3 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 977494f7669..6ba749b0d5c 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -850,6 +850,11 @@ unpin_task(rust_task *task) {
     task->unpin();
 }
 
+extern "C" CDECL rust_chan *
+clone_chan(rust_task *task, rust_chan *chan) {
+    return chan->clone(task);
+}
+
 //
 // Local Variables:
 // mode: C++
diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp
index 92edaa77650..d04f5ee8ff5 100644
--- a/src/rt/rust_chan.cpp
+++ b/src/rt/rust_chan.cpp
@@ -71,9 +71,16 @@ void rust_chan::disassociate() {
  * Attempt to send data to the associated port.
  */
 void rust_chan::send(void *sptr) {
+    rust_scheduler *sched = kernel->sched;
+    I(sched, !port->is_proxy());
+
+    rust_port *target_port = port->referent();
+    // TODO: We can probably avoid this lock by using atomic operations in
+    // circular_buffer.
+    scoped_lock with(target_port->lock);
+
     buffer.enqueue(sptr);
 
-    rust_scheduler *sched = kernel->sched;
     if (!is_associated()) {
         W(sched, is_associated(),
           "rust_chan::transmit with no associated port.");
@@ -88,8 +95,6 @@ void rust_chan::send(void *sptr) {
                            task->get_handle(), port->as_proxy()->handle());
         buffer.dequeue(NULL);
     } else {
-        rust_port *target_port = port->referent();
-        scoped_lock with(target_port->lock);
         if (target_port->task->blocked_on(target_port)) {
             DLOG(sched, comm, "dequeued in rendezvous_ptr");
             buffer.dequeue(target_port->task->rendezvous_ptr);
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index bdff7c86a9c..c6d31a47f4c 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -1,5 +1,6 @@
 align_of
 check_claims
+clone_chan
 debug_box
 debug_fn
 debug_obj