mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 09:23:05 +00:00
rt: Turn on cycle collection at task death; add a test case
This commit is contained in:
parent
ad19ab4c6f
commit
5c973142df
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
14
src/test/run-pass/cycle-collection.rs
Normal file
14
src/test/run-pass/cycle-collection.rs
Normal file
@ -0,0 +1,14 @@
|
||||
tag taggy {
|
||||
cons(@mutable taggy);
|
||||
nil;
|
||||
}
|
||||
|
||||
fn f() {
|
||||
let box = @mutable nil;
|
||||
*box = cons(box);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user