startup collector thread

This commit is contained in:
Justin Ethier 2015-11-11 21:33:30 -05:00
parent 6e6f079430
commit c9d24c9a02
3 changed files with 22 additions and 1 deletions

21
gc.c
View file

@ -731,11 +731,30 @@ void gc_collector()
//sweep : //sweep :
max_freed = gc_sweep(Cyc_get_heap(), &freed); max_freed = gc_sweep(Cyc_get_heap(), &freed);
#if GC_DEBUG_CONCISE_PRINTFS #if GC_DEBUG_CONCISE_PRINTFS
printf("sweep done, freed = %d, max_freed = %d, elapsed = %ld\n", freed, max_freed, time(NULL) - sweep_start); printf("sweep done, freed = %d, max_freed = %d, elapsed = %ld\n",
freed, max_freed, time(NULL) - sweep_start);
#endif #endif
gc_stage = STAGE_RESTING; gc_stage = STAGE_RESTING;
} }
void *collector_main(void *arg)
{
while (1) {
gc_collector();
sleep(1); // TODO: how to schedule this thread?
}
}
static pthread_t collector_thread;
void gc_start_collector()
{
if (pthread_create(&collector_thread, NULL, collector_main, &collector_thread)) {
fprintf(stderr, "Error creating collector thread\n");
exit(1);
}
}
///////////////////////////////////////////// /////////////////////////////////////////////
// END tri-color marking section // END tri-color marking section
///////////////////////////////////////////// /////////////////////////////////////////////

View file

@ -29,6 +29,7 @@ static void Cyc_heap_init(long heap_size)
#endif #endif
Cyc_heap = gc_heap_create(heap_size / 2, 0, 0); Cyc_heap = gc_heap_create(heap_size / 2, 0, 0);
gc_init_mutators(); gc_init_mutators();
gc_start_collector();
} }
#endif /* CYCLONE_RUNTIME_MAIN_H */ #endif /* CYCLONE_RUNTIME_MAIN_H */

View file

@ -150,6 +150,7 @@ void gc_empty_collector_stack();
void gc_handshake(gc_status_type s); void gc_handshake(gc_status_type s);
void gc_post_handshake(gc_status_type s); void gc_post_handshake(gc_status_type s);
void gc_wait_handshake(); void gc_wait_handshake();
void gc_start_collector();
gc_heap *Cyc_get_heap(); gc_heap *Cyc_get_heap();
///////////////////////////////////////////// /////////////////////////////////////////////