Back to index

plt-scheme  4.2.1
immobile_boxes.c
Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /* immobile boxes                                                            */
00003 /*****************************************************************************/
00004 void **GC_malloc_immobile_box(void *p)
00005 {
00006   GCTYPE *gc = GC_get_GC();
00007   GC_Immobile_Box *ib = ofm_malloc(sizeof(GC_Immobile_Box));
00008   if(!ib) GCERR((GCOUTF, "Couldn't allocate space for immobile box!\n"));
00009   ib->p     = p; 
00010   ib->next  = gc->immobile_boxes;
00011   ib->prev  = NULL;
00012   if(ib->next) ib->next->prev = ib;
00013   gc->immobile_boxes = ib;
00014   return (void**)ib;
00015 }
00016 
00017 void GC_free_immobile_box(void **b) 
00018 {
00019   GCTYPE *gc = GC_get_GC();
00020   GC_Immobile_Box *ib;
00021 
00022   for(ib = gc->immobile_boxes; ib; ib = ib->next)
00023     if(PPTR(ib) == b) {
00024       if(ib->prev) ib->prev->next = ib->next;
00025       if(!ib->prev) gc->immobile_boxes = ib->next;
00026       if(ib->next) ib->next->prev = ib->prev;
00027       free(ib);
00028       return;
00029     }
00030   GCWARN((GCOUTF, "Attempted free of non-existent immobile box %p\n", b));
00031 }
00032 
00033 #define traverse_immobiles(gcMUCK, set_bt_src) {                 \
00034     GC_Immobile_Box *ib;                                \
00035     for(ib = gc->immobile_boxes; ib; ib = ib->next) {          \
00036       set_bt_src(ib, BT_IMMOBILE);                                         \
00037       gcMUCK(ib->p);                                    \
00038     }                                                   \
00039   }
00040 
00041 inline static void mark_immobiles(GCTYPE *gc)
00042 {
00043   traverse_immobiles(gcMARK, set_backtrace_source);
00044 }
00045 
00046 inline static void repair_immobiles(GCTYPE *gc)
00047 {
00048   traverse_immobiles(gcFIXUP, two_arg_no_op);
00049 }
00050 
00051