about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-09-23 18:30:22 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-09-26 16:59:15 -0700
commit5c973142df3661a23a085bfb655300c08ca19764 (patch)
tree109a3daf071a74120b3e0357c6a0291691fe0e47 /src/rt
parentad19ab4c6fdf3ea74ac0ff3688d040a852f30760 (diff)
rt: Turn on cycle collection at task death; add a test case
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_cc.cpp18
-rw-r--r--src/rt/rust_task.cpp4
-rw-r--r--src/rt/rust_task.h1
3 files changed, 20 insertions, 3 deletions
diff --git a/src/rt/rust_cc.cpp b/src/rt/rust_cc.cpp
index c53ec1aa51c..70bb5aab1ed 100644
--- a/src/rt/rust_cc.cpp
+++ b/src/rt/rust_cc.cpp
@@ -17,6 +17,10 @@
 #undef DPRINT
 #define DPRINT(fmt,...)     fprintf(stderr, fmt, ##__VA_ARGS__)
 
+// The number of allocations Rust code performs before performing cycle
+// collection.
+#define RUST_CC_FREQUENCY   5000
+
 namespace cc {
 
 // Internal reference count computation
@@ -417,7 +421,7 @@ sweep(rust_task *task, const std::set<void *> &marked) {
         if (marked.find(alloc) == marked.end()) {
             const type_desc *tydesc = begin->second;
 
-            DPRINT("object is part of a cycle: %p\n", alloc);
+            //DPRINT("object is part of a cycle: %p\n", alloc);
 
             // Run the destructor.
             // TODO: What if it fails?
@@ -453,8 +457,18 @@ do_cc(rust_task *task) {
 void
 maybe_cc(rust_task *task) {
     static debug::flag zeal("RUST_CC_ZEAL");
-    if (*zeal)
+    if (*zeal) {
         do_cc(task);
+        return;
+    }
+
+    // FIXME: Needs a snapshot.
+#if 0
+    if (task->cc_counter++ > RUST_CC_FREQUENCY) {
+        task->cc_counter = 0;
+        do_cc(task);
+    }
+#endif
 }
 
 }   // end namespace cc
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index f2c866263cf..97d68e6be39 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -1,5 +1,6 @@
 
 #include "rust_internal.h"
+#include "rust_cc.h"
 
 #include "valgrind.h"
 #include "memcheck.h"
@@ -75,7 +76,8 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
     failed(false),
     killed(false),
     propagate_failure(true),
-    dynastack(this)
+    dynastack(this),
+    cc_counter(0)
 {
     LOGPTR(sched, "new task", (uintptr_t)this);
     DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h
index f364d2a67f7..fe19e06e657 100644
--- a/src/rt/rust_task.h
+++ b/src/rt/rust_task.h
@@ -125,6 +125,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
     rust_obstack dynastack;
 
     std::map<void *,const type_desc *> local_allocs;
+    uint32_t cc_counter;
 
     debug::task_debug_info debug;