home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / GC / PCR_INTF.C < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  143 lines

  1. /* 
  2.  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  3.  *
  4.  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  5.  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  6.  *
  7.  * Permission is hereby granted to use or copy this program
  8.  * for any purpose,  provided the above notices are retained on all copies.
  9.  * Permission to modify the code and to distribute modified code is granted,
  10.  * provided the above notices are retained, and a notice that the code was
  11.  * modified is included with the above copyright notice.
  12.  */
  13. /* Boehm, March 28, 1994 1:58 pm PST */
  14. # include "gc_priv.h"
  15.  
  16. # ifdef PCR
  17. /*
  18.  * Note that POSIX PCR requires an ANSI C compiler.  Hence we are allowed
  19.  * to make the same assumption here.
  20.  * We wrap all of the allocator functions to avoid questions of
  21.  * compatibility between the prototyped and nonprototyped versions of the f
  22.  */
  23. # include "config/PCR_StdTypes.h"
  24. # include "mm/PCR_MM.h"
  25. # include <errno.h>
  26.  
  27. # define MY_MAGIC 17L
  28.  
  29. void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
  30. {
  31.     if (ptrFree) {
  32.         void * result = (void *)GC_malloc_atomic(size);
  33.         if (clear && result != 0) BZERO(result, size);
  34.         return(result);
  35.     } else {
  36.         return((void *)GC_malloc(size));
  37.     }
  38. }
  39.  
  40. # define GC_ReallocProc GC_realloc
  41.  
  42. # define GC_FreeProc GC_free
  43.  
  44. typedef struct {
  45.   PCR_ERes (*ed_proc)(void *p, size_t size, PCR_Any data);
  46.   bool ed_pointerfree;
  47.   PCR_ERes ed_fail_code;
  48.   PCR_Any ed_client_data;
  49. } enumerate_data;
  50.  
  51. void GC_enumerate_block(h, ed)
  52. register struct hblk *h;
  53. enumerate_data * ed;
  54. {
  55.     register hdr * hhdr;
  56.     register int sz;
  57.     word *p;
  58.     word * lim;
  59.     
  60.     hhdr = HDR(h);
  61.     sz = hhdr -> hb_sz;
  62.     if (sz >= 0 && ed -> ed_pointerfree
  63.         || sz <= 0 && !(ed -> ed_pointerfree)) return;
  64.     if (sz < 0) sz = -sz;
  65.     lim = (word *)(h+1) - sz;
  66.     p = (word *)h;
  67.     do {
  68.         if (PCR_ERes_IsErr(ed -> ed_fail_code)) return;
  69.         ed -> ed_fail_code =
  70.             (*(ed -> ed_proc))(p, WORDS_TO_BYTES(sz), ed -> ed_client_data);
  71.         p+= sz;
  72.     } while (p <= lim);
  73. }
  74.  
  75. struct PCR_MM_ProcsRep * GC_old_allocator = 0;
  76.  
  77. PCR_ERes GC_EnumerateProc(
  78.     PCR_Bool ptrFree,
  79.     PCR_ERes (*proc)(void *p, size_t size, PCR_Any data),
  80.     PCR_Any data
  81. )
  82. {
  83.     enumerate_data ed;
  84.     
  85.     ed.ed_proc = proc;
  86.     ed.ed_pointerfree = ptrFree;
  87.     ed.ed_fail_code = PCR_ERes_okay;
  88.     ed.ed_client_data = data;
  89.     GC_apply_to_all_blocks(GC_enumerate_block, &ed);
  90.     if (ed.ed_fail_code != PCR_ERes_okay) {
  91.         return(ed.ed_fail_code);
  92.     } else {
  93.         /* Also enumerate objects allocated by my predecessors */
  94.         return((*(GC_old_allocator->mmp_enumerate))(ptrFree, proc, data));
  95.     }
  96. }
  97.  
  98. void GC_DummyFreeProc(void *p) {};
  99.  
  100. void GC_DummyShutdownProc(void) {};
  101.  
  102. struct PCR_MM_ProcsRep GC_Rep = {
  103.     MY_MAGIC,
  104.     GC_AllocProc,
  105.     GC_ReallocProc,
  106.     GC_DummyFreeProc,      /* mmp_free */
  107.     GC_FreeProc,          /* mmp_unsafeFree */
  108.     GC_EnumerateProc,
  109.     GC_DummyShutdownProc    /* mmp_shutdown */
  110. };
  111.  
  112. void GC_pcr_install()
  113. {
  114.     PCR_MM_Install(&GC_Rep, &GC_old_allocator);
  115. }
  116.  
  117. PCR_ERes
  118. PCR_GC_Setup(void)
  119. {
  120.     return PCR_ERes_okay;
  121. }
  122.  
  123. PCR_ERes
  124. PCR_GC_Run(void)
  125. {
  126.  
  127.     if( !PCR_Base_TestPCRArg("-nogc") ) {
  128.         GC_quiet = ( PCR_Base_TestPCRArg("-gctrace") ? 0 : 1 );
  129.         GC_init();
  130.         if( !PCR_Base_TestPCRArg("-nogc_incremental") ) {
  131.             /*
  132.              * awful hack to test whether VD is implemented ...
  133.              */
  134.             if( PCR_VD_Start( 0, NIL, 0) != PCR_ERes_FromErr(ENOSYS) ) {
  135.             GC_enable_incremental();
  136.         }
  137.     }
  138.     }
  139.     return PCR_ERes_okay;
  140. }
  141.  
  142. # endif
  143.