mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
Build out of collector_trace
Implementation may not be optimal, but should be good enough to prove collector works
This commit is contained in:
parent
2b2a96c84d
commit
cfcce37982
1 changed files with 19 additions and 6 deletions
25
gc.c
25
gc.c
|
@ -480,6 +480,13 @@ void gc_mut_update()
|
||||||
// TODO: when is this called, is this good enough, etc??
|
// TODO: when is this called, is this good enough, etc??
|
||||||
void gc_mut_cooperate(gc_thread_data *thd)
|
void gc_mut_cooperate(gc_thread_data *thd)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// !!!!
|
||||||
|
// TODO: think about what else needs to be done here. for example,
|
||||||
|
// would want to reset last read/write at some point, to conserve
|
||||||
|
// amount of memory being used by the mark buffers
|
||||||
|
|
||||||
|
|
||||||
if (thd->gc_mut_status == gc_status_col) { // TODO: synchronization of var access
|
if (thd->gc_mut_status == gc_status_col) { // TODO: synchronization of var access
|
||||||
if (thd->gc_mut_status == STATUS_SYNC2) { // TODO: more sync??
|
if (thd->gc_mut_status == STATUS_SYNC2) { // TODO: more sync??
|
||||||
// Since everything is on the stack, at this point probably only need
|
// Since everything is on the stack, at this point probably only need
|
||||||
|
@ -518,6 +525,7 @@ void gc_mark_gray(gc_thread_data *thd, object obj)
|
||||||
|
|
||||||
void gc_collector_trace()
|
void gc_collector_trace()
|
||||||
{
|
{
|
||||||
|
gc_thread_data *m;
|
||||||
int clean = 0, i;
|
int clean = 0, i;
|
||||||
while (!clean) {
|
while (!clean) {
|
||||||
clean = 1;
|
clean = 1;
|
||||||
|
@ -525,13 +533,18 @@ void gc_collector_trace()
|
||||||
// the collector thread is the only one that is using these
|
// the collector thread is the only one that is using these
|
||||||
// fields.
|
// fields.
|
||||||
for (i = 0; i < Cyc_num_mutators; i++) {
|
for (i = 0; i < Cyc_num_mutators; i++) {
|
||||||
|
m = Cyc_mutators[i];
|
||||||
|
// TODO: ideally, want to use a lock-free data structure to prevent
|
||||||
|
// having to use a mutex here. see corresponding code in gc_mark_gray
|
||||||
|
pthread_mutex_lock(&(m->lock));
|
||||||
|
while (m->last_read < m->last_write) {
|
||||||
|
clean = 0;
|
||||||
|
(m->last_read)++;
|
||||||
|
gc_mark_black((m->mark_buffer)[m->last_read]);
|
||||||
|
gc_empty_collector_stack();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&(m->lock));
|
||||||
}
|
}
|
||||||
// For each m in mutators
|
|
||||||
// while (lastread[m] < lastwrite[m]) // TODO: use atomic sub to compare?
|
|
||||||
// clean = FALSE
|
|
||||||
// lastread[m] = lastread[m] + 1 // TODO: atomic increment
|
|
||||||
// markBlack(markbuffer[m][lastread[m]])
|
|
||||||
// EmptyCollectorStack()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue