about summary refs log tree commit diff
path: root/src/rt/circular_buffer.cpp
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-07-07 18:18:52 -0700
committerEric Holk <eholk@mozilla.com>2011-07-07 18:22:27 -0700
commit4739953b84b814de3b2b80f273f6292c33e33010 (patch)
tree6d8a7753de5404b18ecfcae5a8080b5820ddc2ce /src/rt/circular_buffer.cpp
parent2d57b25f6b3803ec505ba4909302bebb2cad4afd (diff)
downloadrust-4739953b84b814de3b2b80f273f6292c33e33010.tar.gz
rust-4739953b84b814de3b2b80f273f6292c33e33010.zip
Fixed two races.
The first is that the memory_region destructor would complain there is
still an outstanding allocation. This is because circular_buffer from
rust_chan wasn't refing its task, so the task was being destructed too
soon.

The second was where the program could deadlock while joining a
task. The target task would die in the time between checking whether
the task should block and then actually blocking. The fix is to use
the target task's lock.
Diffstat (limited to 'src/rt/circular_buffer.cpp')
-rw-r--r--src/rt/circular_buffer.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index 191ec7c5756..98746d62f15 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -20,6 +20,7 @@ circular_buffer::circular_buffer(rust_task *task, size_t unit_sz) :
          _buffer_sz, _unread, this);
 
     A(sched, _buffer, "Failed to allocate buffer.");
+    task->ref();
 }
 
 circular_buffer::~circular_buffer() {
@@ -28,6 +29,7 @@ circular_buffer::~circular_buffer() {
     W(sched, _unread == 0,
       "freeing circular_buffer with %d unread bytes", _unread);
     task->free(_buffer);
+    --task->ref_count;
 }
 
 size_t