macros.h 1.43 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */

#ifndef _MACROS_H_
#define _MACROS_H_

/*
 * Definitions of inline macros for queue manipulation and
 * memory management of fixed-size structs using free lists
 */

#include "queue.h"

#define INLINE_INIT_Q(Q) \
((Q)->next = Q, (Q)->prev = Q)

#define Q_EMPTY(Q) ((Q)->next == Q)
    
#define INLINE_REMOVE(T) \
((T)->next->prev = (T)->prev, (T)->prev->next = (T)->next)

#define INLINE_ENQUEUE(Q,T) \
((T)->next=(Q), (T)->prev=(Q)->prev, (Q)->prev->next=(T), (Q)->prev=(T))

#define INLINE_INSERT_AFTER(Q,T) \
((T)->next=(Q)->next, (T)->prev=(Q), (Q)->next->prev=(T), (Q)->next=(T))

#define INLINE_INSERT_BEFORE(Q,T) \
((T)->next=(Q), (T)->prev=(Q)->prev, (Q)->prev->next=(T), (Q)->prev=(T))

#define INLINE_DEQUEUE(Q,T) \
((T)=(Q)->next, (T)==(Q)?(T)=NULL:((Q)->next=(T)->next, (T)->next->prev=(Q)))

#ifndef NITEMS
#define NITEMS 100
#endif

#define NEW_ITEM(FREE_ITEM_PTR, ITEM_SIZE, NEW_PTR, NAME) NEW_PTR\
    = (void *) new_item(&(FREE_ITEM_PTR), ITEM_SIZE, NAME) 

#define NEW_ZITEM(FREE_ITEM_PTR, ITEM_SIZE, NEW_PTR, NAME) NEW_PTR\
    = (void *) new_zitem(&(FREE_ITEM_PTR), ITEM_SIZE,  NAME)

#define FREE_ITEM(FREE_ITEM_PTR, ITEM_PTR)\
    free_item(&(FREE_ITEM_PTR), ITEM_PTR) 

#endif /* _MACROS_H_ */