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-20 16:47:59 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-09-20 16:49:31 -0700
commite26b1883dd1321ee66549c5e7854af0f86ed2a84 (patch)
tree15b6006f2ba16de7cf0e88a43309d574aeb5b2a4 /src/rt/rust_cc.cpp
parentc61691110a521bc070ee792fc87919cb75bd97c5 (diff)
downloadrust-e26b1883dd1321ee66549c5e7854af0f86ed2a84.tar.gz
rust-e26b1883dd1321ee66549c5e7854af0f86ed2a84.zip
rt: Stub code for the cycle collector
Diffstat (limited to 'src/rt/rust_cc.cpp')
-rw-r--r--src/rt/rust_cc.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/rt/rust_cc.cpp b/src/rt/rust_cc.cpp
new file mode 100644
index 00000000000..8129f60fc7c
--- /dev/null
+++ b/src/rt/rust_cc.cpp
@@ -0,0 +1,57 @@
+// Rust cycle collector. Temporary, but will probably stick around for some
+// time until LLVM's GC infrastructure is more mature.
+
+#include <cstdio>
+#include <cstdlib>
+#include <map>
+#include <vector>
+#include "rust_gc.h"
+#include "rust_internal.h"
+#include "rust_shape.h"
+#include "rust_task.h"
+
+#undef DPRINT
+#define DPRINT(fmt,...)     fprintf(stderr, fmt, ##__VA_ARGS__)
+
+namespace cc {
+
+void
+do_cc(rust_task *task) {
+    std::map<void *,type_desc *>::iterator begin(task->local_allocs.begin());
+    std::map<void *,type_desc *>::iterator end(task->local_allocs.end());
+    while (begin != end) {
+        void *p = begin->first;
+        type_desc *tydesc = begin->second;
+
+        DPRINT("marking allocation: %p, tydesc=%p\n", p, tydesc);
+
+        // Prevents warnings for now
+        (void)p;
+        (void)tydesc;
+#if 0
+        shape::arena arena;
+        shape::type_param *params =
+            shape::type_param::from_tydesc(tydesc, arena);
+        mark mark(task, true, tydesc->shape, params, tydesc->shape_tables, p);
+        mark.walk();
+#endif
+
+        ++begin;
+    }
+}
+
+void
+maybe_cc(rust_task *task) {
+    // FIXME: We ought to lock this.
+    static int zeal = -1;
+    if (zeal == -1) {
+        char *ev = getenv("RUST_CC_ZEAL");
+        zeal = ev && ev[0] != '\0' && ev[0] != '0';
+    }
+
+    if (zeal)
+        do_cc(task);
+}
+
+}   // end namespace cc
+