~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0lst.h

  • Committer: Monty Taylor
  • Date: 2009-08-12 06:25:19 UTC
  • mto: (1114.1.1 innodb-plugin-merge)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090812062519-cij02mrrunvnxblt
Tags: innodb-plugin-1.0.4
InnoDB Plugin 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**********************************************************************
 
19
/******************************************************************//**
 
20
@file include/ut0lst.h
20
21
List utilities
21
22
 
22
23
Created 9/10/1995 Heikki Tuuri
32
33
to two or more lists, provided that the list are given different names.
33
34
An example of the usage of the lists can be found in fil0fil.c. */
34
35
 
35
 
/***********************************************************************
 
36
/*******************************************************************//**
36
37
This macro expands to the unnamed type definition of a struct which acts
37
38
as the two-way list base node. The base node contains pointers
38
39
to both ends of the list and a count of nodes in the list (excluding
39
 
the base node from the count). TYPE should be the list node type name. */
40
 
 
 
40
the base node from the count).
 
41
@param TYPE     the name of the list node data type */
41
42
#define UT_LIST_BASE_NODE_T(TYPE)\
42
43
struct {\
43
 
        ulint   count;  /* count of nodes in list */\
44
 
        TYPE *  start;  /* pointer to list start, NULL if empty */\
45
 
        TYPE *  end;    /* pointer to list end, NULL if empty */\
 
44
        ulint   count;  /*!< count of nodes in list */\
 
45
        TYPE *  start;  /*!< pointer to list start, NULL if empty */\
 
46
        TYPE *  end;    /*!< pointer to list end, NULL if empty */\
46
47
}\
47
48
 
48
 
/***********************************************************************
 
49
/*******************************************************************//**
49
50
This macro expands to the unnamed type definition of a struct which
50
51
should be embedded in the nodes of the list, the node type must be a struct.
51
52
This struct contains the pointers to next and previous nodes in the list.
52
53
The name of the field in the node struct should be the name given
53
 
to the list. TYPE should be the list node type name. Example of usage:
54
 
 
 
54
to the list.
 
55
@param TYPE     the list node type name */
 
56
/* Example:
55
57
typedef struct LRU_node_struct  LRU_node_t;
56
58
struct LRU_node_struct {
57
59
        UT_LIST_NODE_T(LRU_node_t)      LRU_list;
58
60
        ...
59
61
}
60
62
The example implements an LRU list of name LRU_list. Its nodes are of type
61
 
LRU_node_t.
62
 
*/
 
63
LRU_node_t. */
63
64
 
64
65
#define UT_LIST_NODE_T(TYPE)\
65
66
struct {\
66
 
        TYPE *  prev;   /* pointer to the previous node,\
 
67
        TYPE *  prev;   /*!< pointer to the previous node,\
67
68
                        NULL if start of list */\
68
 
        TYPE *  next;   /* pointer to next node, NULL if end of list */\
 
69
        TYPE *  next;   /*!< pointer to next node, NULL if end of list */\
69
70
}\
70
71
 
71
 
/***********************************************************************
72
 
Initializes the base node of a two-way list. */
73
 
 
 
72
/*******************************************************************//**
 
73
Initializes the base node of a two-way list.
 
74
@param BASE     the list base node
 
75
*/
74
76
#define UT_LIST_INIT(BASE)\
75
77
{\
76
78
        (BASE).count = 0;\
78
80
        (BASE).end   = NULL;\
79
81
}\
80
82
 
81
 
/***********************************************************************
 
83
/*******************************************************************//**
82
84
Adds the node as the first element in a two-way linked list.
83
 
BASE has to be the base node (not a pointer to it). N has to be
84
 
the pointer to the node to be added to the list. NAME is the list name. */
85
 
 
 
85
@param NAME     list name
 
86
@param BASE     the base node (not a pointer to it)
 
87
@param N        pointer to the node to be added to the list.
 
88
*/
86
89
#define UT_LIST_ADD_FIRST(NAME, BASE, N)\
87
90
{\
88
91
        ut_ad(N);\
99
102
        }\
100
103
}\
101
104
 
102
 
/***********************************************************************
 
105
/*******************************************************************//**
103
106
Adds the node as the last element in a two-way linked list.
104
 
BASE has to be the base node (not a pointer to it). N has to be
105
 
the pointer to the node to be added to the list. NAME is the list name. */
106
 
 
 
107
@param NAME     list name
 
108
@param BASE     the base node (not a pointer to it)
 
109
@param N        pointer to the node to be added to the list
 
110
*/
107
111
#define UT_LIST_ADD_LAST(NAME, BASE, N)\
108
112
{\
109
113
        ut_ad(N);\
120
124
        }\
121
125
}\
122
126
 
123
 
/***********************************************************************
 
127
/*******************************************************************//**
124
128
Inserts a NODE2 after NODE1 in a list.
125
 
BASE has to be the base node (not a pointer to it). NAME is the list
126
 
name, NODE1 and NODE2 are pointers to nodes. */
127
 
 
 
129
@param NAME     list name
 
130
@param BASE     the base node (not a pointer to it)
 
131
@param NODE1    pointer to node after which NODE2 is inserted
 
132
@param NODE2    pointer to node being inserted after NODE1
 
133
*/
128
134
#define UT_LIST_INSERT_AFTER(NAME, BASE, NODE1, NODE2)\
129
135
{\
130
136
        ut_ad(NODE1);\
142
148
        }\
143
149
}\
144
150
 
145
 
/* Invalidate the pointers in a list node. */
146
151
#ifdef UNIV_LIST_DEBUG
 
152
/** Invalidate the pointers in a list node.
 
153
@param NAME     list name
 
154
@param N        pointer to the node that was removed */
147
155
# define UT_LIST_REMOVE_CLEAR(NAME, N)          \
148
156
((N)->NAME.prev = (N)->NAME.next = (void*) -1)
149
157
#else
 
158
/** Invalidate the pointers in a list node.
 
159
@param NAME     list name
 
160
@param N        pointer to the node that was removed */
150
161
# define UT_LIST_REMOVE_CLEAR(NAME, N) while (0)
151
162
#endif
152
163
 
153
 
/***********************************************************************
154
 
Removes a node from a two-way linked list. BASE has to be the base node
155
 
(not a pointer to it). N has to be the pointer to the node to be removed
156
 
from the list. NAME is the list name. */
157
 
 
 
164
/*******************************************************************//**
 
165
Removes a node from a two-way linked list.
 
166
@param NAME     list name
 
167
@param BASE     the base node (not a pointer to it)
 
168
@param N        pointer to the node to be removed from the list
 
169
*/
158
170
#define UT_LIST_REMOVE(NAME, BASE, N)                                   \
159
171
do {                                                                    \
160
172
        ut_ad(N);                                                       \
173
185
        UT_LIST_REMOVE_CLEAR(NAME, N);                                  \
174
186
} while (0)
175
187
 
176
 
/************************************************************************
177
 
Gets the next node in a two-way list. NAME is the name of the list
178
 
and N is pointer to a node. */
179
 
 
 
188
/********************************************************************//**
 
189
Gets the next node in a two-way list.
 
190
@param NAME     list name
 
191
@param N        pointer to a node
 
192
@return         the successor of N in NAME, or NULL */
180
193
#define UT_LIST_GET_NEXT(NAME, N)\
181
194
        (((N)->NAME).next)
182
195
 
183
 
/************************************************************************
184
 
Gets the previous node in a two-way list. NAME is the name of the list
185
 
and N is pointer to a node. */
186
 
 
 
196
/********************************************************************//**
 
197
Gets the previous node in a two-way list.
 
198
@param NAME     list name
 
199
@param N        pointer to a node
 
200
@return         the predecessor of N in NAME, or NULL */
187
201
#define UT_LIST_GET_PREV(NAME, N)\
188
202
        (((N)->NAME).prev)
189
203
 
190
 
/************************************************************************
 
204
/********************************************************************//**
191
205
Alternative macro to get the number of nodes in a two-way list, i.e.,
192
 
its length. BASE is the base node (not a pointer to it). */
193
 
 
 
206
its length.
 
207
@param BASE     the base node (not a pointer to it).
 
208
@return         the number of nodes in the list */
194
209
#define UT_LIST_GET_LEN(BASE)\
195
210
        (BASE).count
196
211
 
197
 
/************************************************************************
198
 
Gets the first node in a two-way list, or returns NULL,
199
 
if the list is empty. BASE is the base node (not a pointer to it). */
200
 
 
 
212
/********************************************************************//**
 
213
Gets the first node in a two-way list.
 
214
@param BASE     the base node (not a pointer to it)
 
215
@return         first node, or NULL if the list is empty */
201
216
#define UT_LIST_GET_FIRST(BASE)\
202
217
        (BASE).start
203
218
 
204
 
/************************************************************************
205
 
Gets the last node in a two-way list, or returns NULL,
206
 
if the list is empty. BASE is the base node (not a pointer to it). */
207
 
 
 
219
/********************************************************************//**
 
220
Gets the last node in a two-way list.
 
221
@param BASE     the base node (not a pointer to it)
 
222
@return         last node, or NULL if the list is empty */
208
223
#define UT_LIST_GET_LAST(BASE)\
209
224
        (BASE).end
210
225
 
211
 
/************************************************************************
212
 
Checks the consistency of a two-way list. NAME is the name of the list,
213
 
TYPE is the node type, and BASE is the base node (not a pointer to it). */
214
 
 
215
 
#define UT_LIST_VALIDATE(NAME, TYPE, BASE)\
216
 
{\
217
 
        ulint   ut_list_i_313;\
218
 
        TYPE *  ut_list_node_313;\
219
 
\
220
 
        ut_list_node_313 = (BASE).start;\
221
 
\
222
 
        for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
223
 
                                                ut_list_i_313++) {\
224
 
                ut_a(ut_list_node_313);\
225
 
                ut_list_node_313 = (ut_list_node_313->NAME).next;\
226
 
        }\
227
 
\
228
 
        ut_a(ut_list_node_313 == NULL);\
229
 
\
230
 
        ut_list_node_313 = (BASE).end;\
231
 
\
232
 
        for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
233
 
                                                ut_list_i_313++) {\
234
 
                ut_a(ut_list_node_313);\
235
 
                ut_list_node_313 = (ut_list_node_313->NAME).prev;\
236
 
        }\
237
 
\
238
 
        ut_a(ut_list_node_313 == NULL);\
239
 
}\
240
 
 
 
226
/********************************************************************//**
 
227
Checks the consistency of a two-way list.
 
228
@param NAME             the name of the list
 
229
@param TYPE             node type
 
230
@param BASE             base node (not a pointer to it)
 
231
@param ASSERTION        a condition on ut_list_node_313 */
 
232
#define UT_LIST_VALIDATE(NAME, TYPE, BASE, ASSERTION)                   \
 
233
do {                                                                    \
 
234
        ulint   ut_list_i_313;                                          \
 
235
        TYPE*   ut_list_node_313;                                       \
 
236
                                                                        \
 
237
        ut_list_node_313 = (BASE).start;                                \
 
238
                                                                        \
 
239
        for (ut_list_i_313 = (BASE).count; ut_list_i_313--; ) {         \
 
240
                ut_a(ut_list_node_313);                                 \
 
241
                ASSERTION;                                              \
 
242
                ut_ad((ut_list_node_313->NAME).next || !ut_list_i_313); \
 
243
                ut_list_node_313 = (ut_list_node_313->NAME).next;       \
 
244
        }                                                               \
 
245
                                                                        \
 
246
        ut_a(ut_list_node_313 == NULL);                                 \
 
247
                                                                        \
 
248
        ut_list_node_313 = (BASE).end;                                  \
 
249
                                                                        \
 
250
        for (ut_list_i_313 = (BASE).count; ut_list_i_313--; ) {         \
 
251
                ut_a(ut_list_node_313);                                 \
 
252
                ASSERTION;                                              \
 
253
                ut_ad((ut_list_node_313->NAME).prev || !ut_list_i_313); \
 
254
                ut_list_node_313 = (ut_list_node_313->NAME).prev;       \
 
255
        }                                                               \
 
256
                                                                        \
 
257
        ut_a(ut_list_node_313 == NULL);                                 \
 
258
} while (0)
241
259
 
242
260
#endif
243
261