From cc36d6459d104b54937427b63831c253fd09a6ec Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 22 Dec 2015 22:49:55 -0500 Subject: [PATCH] Added collector_cooperated flag --- gc.c | 12 +++++++++++- include/cyclone/types.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 636368a6..d038794f 100644 --- a/gc.c +++ b/gc.c @@ -1335,6 +1335,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon thd->last_read = 0; thd->mark_buffer_len = 128; thd->mark_buffer = vpbuffer_realloc(thd->mark_buffer, &(thd->mark_buffer_len)); + thd->collector_cooperated = 0; if (pthread_mutex_init(&(thd->lock), NULL) != 0) { fprintf(stderr, "Unable to initialize thread mutex\n"); exit(1); @@ -1373,7 +1374,16 @@ void gc_mutator_thread_runnable(gc_thread_data *thd, object result) ATOMIC_SET_IF_EQ(&(thd->thread_state), CYC_THREAD_STATE_BLOCKED, CYC_THREAD_STATE_RUNNABLE); - (((closure)(thd->gc_cont))->fn)(thd, 1, thd->gc_cont, result); + if (ATOMIC_GET(&(thd->collector_cooperated))) { + // TODO: + // wait for thd->lock + // unset async flag + // transport result to heap, if necessary (IE, is not a value type) + // set gc_args[0] to result + // longjmp. assumes gc_cont already set by collector + } else { + (((closure)(thd->gc_cont))->fn)(thd, 1, thd->gc_cont, result); + } } //// Unit testing: diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 64d0f9a1..5a13bec3 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -85,6 +85,7 @@ struct gc_thread_data_t { void **mark_buffer; int mark_buffer_len; pthread_mutex_t lock; + int collector_cooperated; // Data needed for call history char **stack_traces; int stack_trace_idx;