mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-22 07:09:17 +02:00
WIP
This commit is contained in:
parent
60d55e8974
commit
1becf84a47
2 changed files with 33 additions and 2 deletions
27
gc.c
27
gc.c
|
@ -461,6 +461,7 @@ static int gc_stage;
|
|||
// Does not need sync, only used by collector thread
|
||||
static void **mark_stack = NULL;
|
||||
static int mark_stack_len = 128;
|
||||
static int mark_stack_i = 0;
|
||||
|
||||
// GC functions called by the Mutator threads
|
||||
|
||||
|
@ -490,12 +491,34 @@ void gc_mut_cooperate(gc_thread_data *thd)
|
|||
}
|
||||
|
||||
// Collector functions
|
||||
void gc_mark_gray(object obj)
|
||||
void gc_mark_gray(gc_thread_data *thd, object obj)
|
||||
{
|
||||
if (is_object_type(obj) && mark(obj) == gc_color_clear) { // TODO: sync??
|
||||
// TODO: mark buffer, last write
|
||||
// TODO: lock mark buffer (not ideal, but a possible first step)?
|
||||
// pthread_mutex_lock
|
||||
thd->mark_buffer = vpbuffer_add(thd->mark_buffer,
|
||||
&(thd->mark_buffer_len),
|
||||
thd->last_write,
|
||||
obj);
|
||||
// pthread_mutex_unlock
|
||||
// unlock mark buffer
|
||||
ATOMIC_INC(&(thd->last_write));
|
||||
}
|
||||
}
|
||||
|
||||
void gc_col_mark_gray(object obj)
|
||||
{
|
||||
if (is_object_type(obj) && mark(obj) == gc_color_clear) { // TODO: sync??
|
||||
mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, obj);
|
||||
}
|
||||
}
|
||||
|
||||
void gc_col_empty_collector_stack()
|
||||
{
|
||||
// TODO:
|
||||
// while (!markstack.empty())
|
||||
// markBlack(markstack.pop())
|
||||
}
|
||||
// GC Collection cycle
|
||||
|
||||
// END tri-color marking section
|
||||
|
|
|
@ -359,5 +359,13 @@ typedef union {
|
|||
double_type double_t;
|
||||
} common_type;
|
||||
|
||||
// Atomics section
|
||||
// TODO: this is all compiler dependent, need to use different macros depending
|
||||
// upon the compiler (and arch)
|
||||
// TODO: relocate this to its own header?
|
||||
#define ATOMIC_INC(ptr) __sync_fetch_and_add((ptr),1)
|
||||
#define ATOMIC_DEC(ptr) __sync_fetch_and_sub((ptr),1)
|
||||
#define ATOMIC_GET(ptr) __sync_fetch_and_add((ptr),0)
|
||||
#define ATOMIC_SET_IF_EQ(ptr, oldv, newv) __sync_val_compare_and_swap(ptr, oldv, newv)
|
||||
|
||||
#endif /* CYCLONE_TYPES_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue