From d158420c945fcd0c898003a4677f3e564fafb8aa Mon Sep 17 00:00:00 2001 From: Kevin Tew Date: Wed, 5 Nov 2008 21:06:21 +0000 Subject: [PATCH] Moved immobile boxes to their own c file, moved immobile_boxes to NewGC struct svn: r12269 --- src/mzscheme/gc2/commongc_internal.h | 7 ++++ src/mzscheme/gc2/immobile_boxes.c | 49 +++++++++++++++++++++++++ src/mzscheme/gc2/newgc.c | 53 +--------------------------- src/mzscheme/gc2/newgc_internal.h | 1 + 4 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 src/mzscheme/gc2/immobile_boxes.c diff --git a/src/mzscheme/gc2/commongc_internal.h b/src/mzscheme/gc2/commongc_internal.h index 24f54799d6..b65714840b 100644 --- a/src/mzscheme/gc2/commongc_internal.h +++ b/src/mzscheme/gc2/commongc_internal.h @@ -44,3 +44,10 @@ typedef struct GC_Ephemeron { /* The rest is up to us: */ struct GC_Ephemeron *next; } GC_Ephemeron; + +typedef struct GC_Immobile_Box { + void *p; /* this must be first or mred dies */ + struct GC_Immobile_Box *next; + struct GC_Immobile_Box *prev; +} GC_Immobile_Box; + diff --git a/src/mzscheme/gc2/immobile_boxes.c b/src/mzscheme/gc2/immobile_boxes.c new file mode 100644 index 0000000000..8be1559d06 --- /dev/null +++ b/src/mzscheme/gc2/immobile_boxes.c @@ -0,0 +1,49 @@ +/*****************************************************************************/ +/* immobile boxes */ +/*****************************************************************************/ +void **GC_malloc_immobile_box(void *p) +{ + GC_Immobile_Box *ib = malloc(sizeof(GC_Immobile_Box)); + if(!ib) GCERR((GCOUTF, "Couldn't allocate space for immobile box!\n")); + ib->p = p; + ib->next = GC->immobile_boxes; + ib->prev = NULL; + if(ib->next) ib->next->prev = ib; + GC->immobile_boxes = ib; + return (void**)ib; +} + +void GC_free_immobile_box(void **b) +{ + GC_Immobile_Box *ib; + + for(ib = GC->immobile_boxes; ib; ib = ib->next) + if(PPTR(ib) == b) { + if(ib->prev) ib->prev->next = ib->next; + if(!ib->prev) GC->immobile_boxes = ib->next; + if(ib->next) ib->next->prev = ib->prev; + free(ib); + return; + } + GCWARN((GCOUTF, "Attempted free of non-existent immobile box %p\n", b)); +} + +#define traverse_immobiles(gcMUCK, set_bt_src) { \ + GC_Immobile_Box *ib; \ + for(ib = GC->immobile_boxes; ib; ib = ib->next) { \ + set_bt_src(ib, BT_IMMOBILE); \ + gcMUCK(ib->p); \ + } \ + } + +inline static void mark_immobiles(void) +{ + traverse_immobiles(gcMARK, set_backtrace_source); +} + +inline static void repair_immobiles(void) +{ + traverse_immobiles(gcFIXUP, two_arg_no_op); +} + + diff --git a/src/mzscheme/gc2/newgc.c b/src/mzscheme/gc2/newgc.c index 094b774b0e..a7b7607511 100644 --- a/src/mzscheme/gc2/newgc.c +++ b/src/mzscheme/gc2/newgc.c @@ -943,58 +943,7 @@ inline static void repair_roots() traverse_roots(gcFIXUP, two_arg_no_op); } -/*****************************************************************************/ -/* immobile boxes */ -/*****************************************************************************/ -struct immobile_box { - void *p; /* this must be first or mred dies */ - struct immobile_box *next, *prev; -}; - -static struct immobile_box *immobile_boxes = NULL; - -void **GC_malloc_immobile_box(void *p) -{ - struct immobile_box *ib = malloc(sizeof(struct immobile_box)); - if (!ib) out_of_memory(); - ib->p = p; ib->next = immobile_boxes; ib->prev = NULL; - if(ib->next) ib->next->prev = ib; - immobile_boxes = ib; - return (void**)ib; -} - -void GC_free_immobile_box(void **b) -{ - struct immobile_box *ib; - - for(ib = immobile_boxes; ib; ib = ib->next) - if(PPTR(ib) == b) { - if(ib->prev) ib->prev->next = ib->next; - if(!ib->prev) immobile_boxes = ib->next; - if(ib->next) ib->next->prev = ib->prev; - free(ib); - return; - } - GCWARN((GCOUTF, "Attempted free of non-existent immobile box %p\n", b)); -} - -#define traverse_immobiles(gcMUCK, set_bt_src) { \ - struct immobile_box *ib; \ - for(ib = immobile_boxes; ib; ib = ib->next) { \ - set_bt_src(ib, BT_IMMOBILE); \ - gcMUCK(ib->p); \ - } \ - } - -inline static void mark_immobiles(void) -{ - traverse_immobiles(gcMARK, set_backtrace_source); -} - -inline static void repair_immobiles(void) -{ - traverse_immobiles(gcFIXUP, two_arg_no_op); -} +#include "immobile_boxes.c" /*****************************************************************************/ /* finalizers */ diff --git a/src/mzscheme/gc2/newgc_internal.h b/src/mzscheme/gc2/newgc_internal.h index 5e07191dd8..433ca4f3fe 100644 --- a/src/mzscheme/gc2/newgc_internal.h +++ b/src/mzscheme/gc2/newgc_internal.h @@ -114,6 +114,7 @@ typedef struct NewGC { GC_Weak_Box *weak_boxes; GC_Ephemeron *ephemerons; int num_last_seen_ephemerons; + GC_Immobile_Box *immobile_boxes; } NewGC; void NewGC_initialize(NewGC *newgc) {