From e26b1883dd1321ee66549c5e7854af0f86ed2a84 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 20 Sep 2011 16:47:59 -0700 Subject: rt: Stub code for the cycle collector --- src/rt/rust_cc.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/rt/rust_cc.cpp (limited to 'src/rt/rust_cc.cpp') 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 +#include +#include +#include +#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::iterator begin(task->local_allocs.begin()); + std::map::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 + -- cgit 1.4.1-3-g733a5