home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / GC / INCLUDE / GC_INL.H < prev    next >
C/C++ Source or Header  |  1994-05-19  |  3KB  |  96 lines

  1. /* 
  2.  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3.  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  4.  *
  5.  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  6.  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  7.  *
  8.  * Permission is hereby granted to use or copy this program
  9.  * for any purpose,  provided the above notices are retained on all copies.
  10.  * Permission to modify the code and to distribute modified code is granted,
  11.  * provided the above notices are retained, and a notice that the code was
  12.  * modified is included with the above copyright notice.
  13.  */
  14. /* Boehm, May 19, 1994 2:12 pm PDT */
  15.  
  16. # ifndef GC_PRIVATE_H
  17. #   include "gc_priv.h"
  18. # endif
  19.  
  20. /* Allocate n words (NOT BYTES).  X is made to point to the result.    */
  21. /* It is assumed that n < MAXOBJSZ, and                    */
  22. /* that n > 0.  On machines requiring double word alignment of some    */
  23. /* data, we also assume that n is 1 or even.  This bypasses the        */
  24. /* MERGE_SIZES mechanism.  In order to minimize the number of distinct    */
  25. /* free lists that are maintained, the caller should ensure that a     */
  26. /* small number of distinct values of n are used.  (The MERGE_SIZES    */
  27. /* mechanism normally does this by ensuring that only the leading three    */
  28. /* bits of n may be nonzero.  See misc.c for details.)  We really     */
  29. /* recommend this only in cases in which n is a constant, and no    */
  30. /* locking is required.                            */
  31. /* In that case it may allow the compiler to perform substantial    */
  32. /* additional optimizations.                        */
  33. # define GC_MALLOC_WORDS(result,n) \
  34. {    \
  35.     register ptr_t op;    \
  36.     register ptr_t *opp;    \
  37.     DCL_LOCK_STATE;    \
  38.     \
  39.     opp = &(GC_objfreelist[n]);    \
  40.     FASTLOCK();    \
  41.     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {    \
  42.         FASTUNLOCK();    \
  43.         (result) = GC_generic_malloc_words_small((n), NORMAL);    \
  44.     } else {     \
  45.         *opp = obj_link(op);    \
  46.         obj_link(op) = 0;    \
  47.         GC_words_allocd += (n);    \
  48.         FASTUNLOCK();    \
  49.         (result) = (extern_ptr_t) op;    \
  50.     }    \
  51. }
  52.  
  53.  
  54. /* The same for atomic objects:    */
  55. # define GC_MALLOC_ATOMIC_WORDS(result,n) \
  56. {    \
  57.     register ptr_t op;    \
  58.     register ptr_t *opp;    \
  59.     DCL_LOCK_STATE;    \
  60.     \
  61.     opp = &(GC_aobjfreelist[n]);    \
  62.     FASTLOCK();    \
  63.     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {    \
  64.         FASTUNLOCK();    \
  65.         (result) = GC_generic_malloc_words_small((n), PTRFREE);    \
  66.     } else {     \
  67.         *opp = obj_link(op);    \
  68.         obj_link(op) = 0;    \
  69.         GC_words_allocd += (n);    \
  70.         FASTUNLOCK();    \
  71.         (result) = (extern_ptr_t) op;    \
  72.     }    \
  73. }
  74.  
  75. /* And once more for two word initialized objects: */
  76. # define GC_CONS(result, first, second) \
  77. {    \
  78.     register ptr_t op;    \
  79.     register ptr_t *opp;    \
  80.     DCL_LOCK_STATE;    \
  81.     \
  82.     opp = &(GC_objfreelist[2]);    \
  83.     FASTLOCK();    \
  84.     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {    \
  85.         FASTUNLOCK();    \
  86.         op = GC_generic_malloc_words_small(2, NORMAL);    \
  87.     } else {    \
  88.         *opp = obj_link(op);    \
  89.         GC_words_allocd += 2;    \
  90.         FASTUNLOCK();    \
  91.     } \
  92.     ((word *)op)[0] = (word)(first);    \
  93.     ((word *)op)[1] = (word)(second);    \
  94.     (result) = (extern_ptr_t) op;    \
  95. }
  96.