diff --git a/src/mzscheme/gc2/compact.c b/src/mzscheme/gc2/compact.c index dafb6f1509..aa034d904a 100644 --- a/src/mzscheme/gc2/compact.c +++ b/src/mzscheme/gc2/compact.c @@ -10,6 +10,7 @@ #include #include #include +#include "platforms.h" #include "gc2.h" #define NUMBER_OF_TAGS 512 @@ -160,7 +161,7 @@ unsigned long (*GC_get_thread_stack_base)(void); void (*GC_mark_xtagged)(void *obj); void (*GC_fixup_xtagged)(void *obj); -void **GC_variable_stack; +THREAD_LOCAL void **GC_variable_stack; void **GC_get_variable_stack() { return GC_variable_stack; } void GC_set_variable_stack(void **p) { GC_variable_stack = p; } diff --git a/src/mzscheme/gc2/gc2.h b/src/mzscheme/gc2/gc2.h index dbf7251cb3..3c27e79b35 100644 --- a/src/mzscheme/gc2/gc2.h +++ b/src/mzscheme/gc2/gc2.h @@ -262,7 +262,7 @@ GC2_EXTERN void GC_finalization_weak_ptr(void **p, int offset); /* Cooperative GC */ /***************************************************************************/ -GC2_EXTERN void **GC_variable_stack; +GC2_EXTERN THREAD_LOCAL void **GC_variable_stack; /* See the general overview in README. */ diff --git a/src/mzscheme/gc2/newgc.c b/src/mzscheme/gc2/newgc.c index 3177dc6ac7..c295befc38 100644 --- a/src/mzscheme/gc2/newgc.c +++ b/src/mzscheme/gc2/newgc.c @@ -354,8 +354,8 @@ int GC_is_allocated(void *p) The size count helps us trigger collection quickly when we're running out of space; see the test in allocate_big. */ -unsigned long GC_gen0_alloc_page_ptr = 0; -unsigned long GC_gen0_alloc_page_end = 0; +THREAD_LOCAL unsigned long GC_gen0_alloc_page_ptr = 0; +THREAD_LOCAL unsigned long GC_gen0_alloc_page_end = 0; /* miscellaneous variables */ static const char *zero_sized[4]; /* all 0-sized allocs get this */ @@ -888,7 +888,7 @@ static void *get_backtrace(struct mpage *page, void *ptr) /* With the exception of the "traverse" macro and resultant simplification, */ /* this code is entirely lifted from compact.c */ /*****************************************************************************/ -void **GC_variable_stack; +THREAD_LOCAL void **GC_variable_stack; void **GC_get_variable_stack() { @@ -1155,7 +1155,7 @@ typedef struct MarkSegment { void **stop_here; /* this is only used for its address */ } MarkSegment; -static MarkSegment *mark_stack = NULL; +static THREAD_LOCAL MarkSegment *mark_stack = NULL; inline static MarkSegment* mark_stack_create_frame() { MarkSegment *mark_frame = (MarkSegment*)malloc(STACK_PART_SIZE); @@ -1188,7 +1188,7 @@ inline static void push_ptr(void *ptr) } } - /* at this point, we're guaranteed to be good to push a pointers */ + /* at this point, we're guaranteed to be good to push pointers */ *(mark_stack->top++) = ptr; } @@ -1199,8 +1199,7 @@ inline static int pop_ptr(void **ptr) /* if there is a previous page, go to it */ mark_stack = mark_stack->prev; } else { - /* if there isn't a previous page, then we've hit the bottom of the - stack */ + /* if there isn't a previous page, then we've hit the bottom of the stack */ return 0; } } @@ -2497,16 +2496,15 @@ static void garbage_collect(int force_full) while(gc->run_queue) { struct finalizer *f; - void **gcs; + void **saved_gc_variable_stack; f = gc->run_queue; gc->run_queue = gc->run_queue->next; if(!gc->run_queue) gc->last_in_queue = NULL; - GCDEBUG((DEBUGOUTF, "Running finalizers %p for pointer %p (lvl %i)\n", - f, f->p, f->eager_level)); - gcs = GC_variable_stack; + GCDEBUG((DEBUGOUTF, "Running finalizers %p for pointer %p (lvl %i)\n", f, f->p, f->eager_level)); + saved_gc_variable_stack = GC_variable_stack; f->f(f->p, f->data); - GC_variable_stack = gcs; + GC_variable_stack = saved_gc_variable_stack; } run_account_hooks(); running_finalizers = 0; diff --git a/src/mzscheme/gc2/newgc_internal.h b/src/mzscheme/gc2/newgc_internal.h index f155453416..7446bb1fe6 100644 --- a/src/mzscheme/gc2/newgc_internal.h +++ b/src/mzscheme/gc2/newgc_internal.h @@ -66,7 +66,6 @@ typedef struct Gen0 { struct mpage *curr_alloc_page; struct mpage *pages; struct mpage *big_pages; - unsigned long GC_gen0_alloc_page_ptr; unsigned long current_size; unsigned long max_size; } Gen0; diff --git a/src/mzscheme/gc2/platforms.h b/src/mzscheme/gc2/platforms.h index 23d04884a2..6b91d5cb10 100644 --- a/src/mzscheme/gc2/platforms.h +++ b/src/mzscheme/gc2/platforms.h @@ -21,3 +21,14 @@ #ifndef GC_ALIGN_EIGHT # define GC_ALIGN_EIGHT #endif + +#ifdef MZ_USE_PLACES +# if _MSC_VER +# define THREAD_LOCAL __declspec(thread) +# else +# define THREAD_LOCAL __thread +# endif +#else +# define THREAD_LOCAL /* empty */ +#endif + diff --git a/src/mzscheme/src/jit.c b/src/mzscheme/src/jit.c index d856e88225..bd51198ad4 100644 --- a/src/mzscheme/src/jit.c +++ b/src/mzscheme/src/jit.c @@ -1094,7 +1094,7 @@ static void _jit_prolog_again(mz_jit_state *jitter, int n, int ret_addr_reg) #endif #ifdef CAN_INLINE_ALLOC -extern unsigned long GC_gen0_alloc_page_ptr; +extern THREAD_LOCAL unsigned long GC_gen0_alloc_page_ptr; long GC_initial_word(int sizeb); long GC_compute_alloc_size(long sizeb); long GC_alloc_alignment(void); diff --git a/src/mzscheme/src/schemef.h b/src/mzscheme/src/schemef.h index bae0ff0fc0..f77bb5417b 100644 --- a/src/mzscheme/src/schemef.h +++ b/src/mzscheme/src/schemef.h @@ -399,7 +399,7 @@ MZ_EXTERN void scheme_gc_ptr_ok(void *p); MZ_EXTERN void scheme_collect_garbage(void); #ifdef MZ_PRECISE_GC -MZ_EXTERN void **GC_variable_stack; +MZ_EXTERN THREAD_LOCAL void **GC_variable_stack; MZ_EXTERN void GC_register_traversers(short tag, Size_Proc size, Mark_Proc mark, Fixup_Proc fixup, int is_constant_size, int is_atomic); MZ_EXTERN void *GC_resolve(void *p);