diff --git a/gc.c b/gc.c index 66556041..e1137c01 100644 --- a/gc.c +++ b/gc.c @@ -1215,6 +1215,9 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon (1 - STACK_GROWS_DOWNWARD)); exit(1); } + thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *)); + thd->stack_trace_idx = 0; + thd->stack_prev_frame = NULL; //thd->mutator_num = mut_num; thd->jmp_start = malloc(sizeof(jmp_buf)); thd->gc_args = malloc(sizeof(object) * NUM_GC_ANS); @@ -1236,10 +1239,18 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon void gc_thread_data_free(gc_thread_data *thd) { if (thd) { + if (pthread_mutex_destroy(&thd->lock) != 0) { + // TODO: can only destroy the lock if it is unlocked. need to make sure we + // can guarantee that is the case prior to making this call + // On the other hand, can we just use sleep and a loop to retry?? + fprintf(stderr, "Thread mutex is locked, unable to free\n"); + exit(1); + } if (thd->jmp_start) free(thd->jmp_start); if (thd->gc_args) free(thd->gc_args); if (thd->moveBuf) free(thd->moveBuf); if (thd->mark_buffer) free(thd->mark_buffer); + if (thd->stack_traces) free(thd->stack_traces); free(thd); } } diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 3d423096..1c375c81 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -31,6 +31,19 @@ // Size of a "page" on the heap (the second generation), in bytes. #define HEAP_SIZE 6000000 +// Number of functions to save for printing call history +#define MAX_STACK_TRACES 10 + +// GC debugging flags +#define GC_DEBUG_TRACE 0 +#define GC_DEBUG_VERBOSE 0 + +/* Additional runtime checking of the GC system. + This is here because these checks should not be + necessary if GC is working correctly. */ +#define GC_SAFETY_CHECKS 1 + + /* Define general object type. */ typedef void *object; @@ -186,15 +199,6 @@ gc_heap *gc_get_heap(); // TODO: //void gc_collector() -/* GC debugging flags */ -#define GC_DEBUG_TRACE 0 -#define GC_DEBUG_VERBOSE 0 - -/* Additional runtime checking of the GC system. - This is here because these checks should not be - necessary if GC is working correctly. */ -#define GC_SAFETY_CHECKS 1 - /* Show diagnostic information for the GC when program terminates */ #define DEBUG_SHOW_DIAG 0 diff --git a/runtime.c b/runtime.c index 401e96a6..32b4caf4 100644 --- a/runtime.c +++ b/runtime.c @@ -188,8 +188,6 @@ static symbol_type Cyc_void_symbol = {{0}, symbol_tag, "", nil}; const object quote_void = &Cyc_void_symbol; /* Stack Traces */ -static const int MAX_STACK_TRACES = 10; - void Cyc_st_add(void *data, char *frame) { gc_thread_data *thd = (gc_thread_data *)data; // Do not allow recursion to remove older frames @@ -2479,13 +2477,6 @@ void Cyc_apply_from_buf(void *data, int argc, object prim, object *buf) { void Cyc_start_thread(gc_thread_data *thd) { - thd->stack_trace_idx = 0; - thd->stack_prev_frame = NULL; - // TODO: may need to relocate the calloc to another function that - // initializes thread objects, rather than here that just calls them. - // at a minimum, should initialize it to NULL so we can test for that here. - thd->stack_traces = calloc(MAX_STACK_TRACES, sizeof(char *)); - /* Tank, load the jump program... */ setjmp(*(thd->jmp_start));