about summary refs log tree commit diff
path: root/src/rt/rust_cc.cpp
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/rust_cc.cpp
parentad19ab4c6fdf3ea74ac0ff3688d040a852f30760 (diff)
downloadrust-5c973142df3661a23a085bfb655300c08ca19764.tar.gz
rust-5c973142df3661a23a085bfb655300c08ca19764.zip
rt: Turn on cycle collection at task death; add a test case
Diffstat (limited to 'src/rt/rust_cc.cpp')
-rw-r--r--src/rt/rust_cc.cpp18
1 files changed, 16 insertions, 2 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