Back to index

plt-scheme  4.2.1
gc_inl.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
00004  *
00005  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00006  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00007  *
00008  * Permission is hereby granted to use or copy this program
00009  * for any purpose,  provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  */
00014 /* Boehm, October 3, 1995 2:07 pm PDT */
00015  
00016 # ifndef GC_PRIVATE_H
00017 #   include "private/gc_priv.h"
00018 # endif
00019 
00020 /* USE OF THIS FILE IS NOT RECOMMENDED unless GC_all_interior_pointers       */
00021 /* is always set, or the collector has been built with                */
00022 /* -DDONT_ADD_BYTE_AT_END, or the specified size includes a pointerfree      */
00023 /* word at the end.  In the standard collector configuration,         */
00024 /* the final word of each object may not be scanned.                  */
00025 /* This iinterface is most useful for compilers that generate C.      */
00026 /* Manual use is hereby discouraged.                                  */
00027 
00028 /* Allocate n words (NOT BYTES).  X is made to point to the result.   */
00029 /* It is assumed that n < MAXOBJSZ, and                               */
00030 /* that n > 0.  On machines requiring double word alignment of some   */
00031 /* data, we also assume that n is 1 or even.                          */
00032 /* If the collector is built with -DUSE_MARK_BYTES or -DPARALLEL_MARK,       */
00033 /* the n = 1 case is also disallowed.                                 */
00034 /* Effectively this means that portable code should make sure n is even.*/
00035 /* This bypasses the                                           */
00036 /* MERGE_SIZES mechanism.  In order to minimize the number of distinct       */
00037 /* free lists that are maintained, the caller should ensure that a    */
00038 /* small number of distinct values of n are used.  (The MERGE_SIZES   */
00039 /* mechanism normally does this by ensuring that only the leading three      */
00040 /* bits of n may be nonzero.  See misc.c for details.)  We really     */
00041 /* recommend this only in cases in which n is a constant, and no      */
00042 /* locking is required.                                               */
00043 /* In that case it may allow the compiler to perform substantial      */
00044 /* additional optimizations.                                          */
00045 # define GC_MALLOC_WORDS(result,n) \
00046 {      \
00047     register ptr_t op;      \
00048     register ptr_t *opp;    \
00049     DCL_LOCK_STATE;  \
00050        \
00051     opp = &(GC_objfreelist[n]);    \
00052     FASTLOCK();      \
00053     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00054         FASTUNLOCK();       \
00055         (result) = GC_generic_malloc_words_small((n), NORMAL); \
00056     } else {  \
00057         *opp = obj_link(op);       \
00058         obj_link(op) = 0;   \
00059         GC_words_allocd += (n);    \
00060         FASTUNLOCK();       \
00061         (result) = (GC_PTR) op;    \
00062     }  \
00063 }
00064 
00065 
00066 /* The same for atomic objects:    */
00067 # define GC_MALLOC_ATOMIC_WORDS(result,n) \
00068 {      \
00069     register ptr_t op;      \
00070     register ptr_t *opp;    \
00071     DCL_LOCK_STATE;  \
00072        \
00073     opp = &(GC_aobjfreelist[n]);   \
00074     FASTLOCK();      \
00075     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00076         FASTUNLOCK();       \
00077         (result) = GC_generic_malloc_words_small((n), PTRFREE);       \
00078     } else {  \
00079         *opp = obj_link(op);       \
00080         obj_link(op) = 0;   \
00081         GC_words_allocd += (n);    \
00082         FASTUNLOCK();       \
00083         (result) = (GC_PTR) op;    \
00084     }  \
00085 }
00086 
00087 /* And once more for two word initialized objects: */
00088 # define GC_CONS(result, first, second) \
00089 {      \
00090     register ptr_t op;      \
00091     register ptr_t *opp;    \
00092     DCL_LOCK_STATE;  \
00093        \
00094     opp = &(GC_objfreelist[2]);    \
00095     FASTLOCK();      \
00096     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00097         FASTUNLOCK();       \
00098         op = GC_generic_malloc_words_small(2, NORMAL);  \
00099     } else {  \
00100         *opp = obj_link(op);       \
00101         GC_words_allocd += 2;      \
00102         FASTUNLOCK();       \
00103     } \
00104     ((word *)op)[0] = (word)(first);      \
00105     ((word *)op)[1] = (word)(second);     \
00106     (result) = (GC_PTR) op; \
00107 }