macros.h
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* 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_ */