/* 
 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
 * Copyright (c) 1991, 1992 by Xerox Corporation.  All rights reserved.
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 * Permission is hereby granted to copy this garbage collector for any purpose,
 * provided the above notices are retained on all copies.
 */
 
# ifndef GC←PRIVATE←H
#   include "gc←private.h"
# endif

/* Allocate n words (NOT BYTES).  X is made to point to the result.	*/
/* It is assumed that n < MAXOBJSZ, and					*/
/* that n > 0.  On machines requiring double word alignment of some	*/
/* data, we also assume that n is 1 or even.  This bypasses the		*/
/* MERGE←SIZES mechanism.  In order to minimize the number of distinct	*/
/* free lists that are maintained, the caller should ensure that a 	*/
/* small number of distinct values of n are used.  (The MERGE←SIZES	*/
/* mechanism normally does this by ensuring that only the leading three	*/
/* bits of n may be nonzero.  See misc.c for details.)  We really 	*/
/* recommend this only in cases in which n is a constant, and no	*/
/* locking is required.							*/
/* In that case it may allow the compiler to perform substantial	*/
/* additional optimizations.						*/
# define GC←MALLOC←WORDS(result,n) \
{	\
    register ptr←t op;	\
    register ptr←t *opp;	\
    DCL←LOCK←STATE;	\
	\
    opp = &(GC←objfreelist[n]);	\
    FASTLOCK();	\
    if( !FASTLOCK←SUCCEEDED() || (op = *opp) == 0 ) {	\
        FASTUNLOCK();	\
        (result) = GC←generic←malloc←words←small((n), NORMAL);	\
    } else { 	\
        *opp = obj←link(op);	\
        obj←link(op) = 0;	\
        GC←words←allocd += (n);	\
        FASTUNLOCK();	\
        (result) = (extern←ptr←t) op;	\
    }	\
}


/* The same for atomic objects:	*/
# define GC←MALLOC←ATOMIC←WORDS(result,n) \
{	\
    register ptr←t op;	\
    register ptr←t *opp;	\
    DCL←LOCK←STATE;	\
	\
    opp = &(GC←aobjfreelist[n]);	\
    FASTLOCK();	\
    if( !FASTLOCK←SUCCEEDED() || (op = *opp) == 0 ) {	\
        FASTUNLOCK();	\
        (result) = GC←generic←malloc←words←small((n), PTRFREE);	\
    } else { 	\
        *opp = obj←link(op);	\
        obj←link(op) = 0;	\
        GC←words←allocd += (n);	\
        FASTUNLOCK();	\
        (result) = (extern←ptr←t) op;	\
    }	\
}

/* And once more for two word initialized objects: */
# define GC←CONS(result, first, second) \
{	\
    register ptr←t op;	\
    register ptr←t *opp;	\
    DCL←LOCK←STATE;	\
	\
    opp = &(GC←objfreelist[2]);	\
    FASTLOCK();	\
    if( !FASTLOCK←SUCCEEDED() || (op = *opp) == 0 ) {	\
        FASTUNLOCK();	\
        op = GC←generic←malloc←words←small(2, NORMAL);	\
    } else {	\
        *opp = obj←link(op);	\
        GC←words←allocd += 2;	\
        FASTUNLOCK();	\
    } \
    ((word *)op)[0] = (word)(first);	\
    ((word *)op)[1] = (word)(second);	\
    (result) = (extern←ptr←t) op;	\
}