~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/******************************************************************//**
20
 
@file include/ut0lst.h
 
1
/**********************************************************************
21
2
List utilities
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 9/10/1995 Heikki Tuuri
24
7
***********************************************************************/
25
8
 
33
16
to two or more lists, provided that the list are given different names.
34
17
An example of the usage of the lists can be found in fil0fil.c. */
35
18
 
36
 
/*******************************************************************//**
 
19
/***********************************************************************
37
20
This macro expands to the unnamed type definition of a struct which acts
38
21
as the two-way list base node. The base node contains pointers
39
22
to both ends of the list and a count of nodes in the list (excluding
40
 
the base node from the count).
41
 
@param TYPE     the name of the list node data type */
 
23
the base node from the count). TYPE should be the list node type name. */
 
24
 
42
25
#define UT_LIST_BASE_NODE_T(TYPE)\
43
26
struct {\
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 */\
 
27
        ulint   count;  /* count of nodes in list */\
 
28
        TYPE *  start;  /* pointer to list start, NULL if empty */\
 
29
        TYPE *  end;    /* pointer to list end, NULL if empty */\
47
30
}\
48
31
 
49
 
/*******************************************************************//**
 
32
/***********************************************************************
50
33
This macro expands to the unnamed type definition of a struct which
51
34
should be embedded in the nodes of the list, the node type must be a struct.
52
35
This struct contains the pointers to next and previous nodes in the list.
53
36
The name of the field in the node struct should be the name given
54
 
to the list.
55
 
@param TYPE     the list node type name */
56
 
/* Example:
 
37
to the list. TYPE should be the list node type name. Example of usage:
 
38
 
57
39
typedef struct LRU_node_struct  LRU_node_t;
58
40
struct LRU_node_struct {
59
41
        UT_LIST_NODE_T(LRU_node_t)      LRU_list;
60
42
        ...
61
43
}
62
44
The example implements an LRU list of name LRU_list. Its nodes are of type
63
 
LRU_node_t. */
 
45
LRU_node_t.
 
46
*/
64
47
 
65
48
#define UT_LIST_NODE_T(TYPE)\
66
49
struct {\
67
 
        TYPE *  prev;   /*!< pointer to the previous node,\
 
50
        TYPE *  prev;   /* pointer to the previous node,\
68
51
                        NULL if start of list */\
69
 
        TYPE *  next;   /*!< pointer to next node, NULL if end of list */\
 
52
        TYPE *  next;   /* pointer to next node, NULL if end of list */\
70
53
}\
71
54
 
72
 
/*******************************************************************//**
73
 
Initializes the base node of a two-way list.
74
 
@param BASE     the list base node
75
 
*/
 
55
/***********************************************************************
 
56
Initializes the base node of a two-way list. */
 
57
 
76
58
#define UT_LIST_INIT(BASE)\
77
59
{\
78
60
        (BASE).count = 0;\
80
62
        (BASE).end   = NULL;\
81
63
}\
82
64
 
83
 
/*******************************************************************//**
 
65
/***********************************************************************
84
66
Adds the node as the first element in a two-way linked list.
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
 
*/
 
67
BASE has to be the base node (not a pointer to it). N has to be
 
68
the pointer to the node to be added to the list. NAME is the list name. */
 
69
 
89
70
#define UT_LIST_ADD_FIRST(NAME, BASE, N)\
90
71
{\
91
72
        ut_ad(N);\
102
83
        }\
103
84
}\
104
85
 
105
 
/*******************************************************************//**
 
86
/***********************************************************************
106
87
Adds the node as the last element in a two-way linked list.
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
 
*/
 
88
BASE has to be the base node (not a pointer to it). N has to be
 
89
the pointer to the node to be added to the list. NAME is the list name. */
 
90
 
111
91
#define UT_LIST_ADD_LAST(NAME, BASE, N)\
112
92
{\
113
93
        ut_ad(N);\
124
104
        }\
125
105
}\
126
106
 
127
 
/*******************************************************************//**
 
107
/***********************************************************************
128
108
Inserts a NODE2 after NODE1 in a list.
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
 
*/
 
109
BASE has to be the base node (not a pointer to it). NAME is the list
 
110
name, NODE1 and NODE2 are pointers to nodes. */
 
111
 
134
112
#define UT_LIST_INSERT_AFTER(NAME, BASE, NODE1, NODE2)\
135
113
{\
136
114
        ut_ad(NODE1);\
148
126
        }\
149
127
}\
150
128
 
 
129
/* Invalidate the pointers in a list node. */
151
130
#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 */
155
131
# define UT_LIST_REMOVE_CLEAR(NAME, N)          \
156
132
((N)->NAME.prev = (N)->NAME.next = (void*) -1)
157
133
#else
158
 
/** Invalidate the pointers in a list node.
159
 
@param NAME     list name
160
 
@param N        pointer to the node that was removed */
161
 
# define UT_LIST_REMOVE_CLEAR(NAME, N)
 
134
# define UT_LIST_REMOVE_CLEAR(NAME, N) while (0)
162
135
#endif
163
136
 
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
 
*/
 
137
/***********************************************************************
 
138
Removes a node from a two-way linked list. BASE has to be the base node
 
139
(not a pointer to it). N has to be the pointer to the node to be removed
 
140
from the list. NAME is the list name. */
 
141
 
170
142
#define UT_LIST_REMOVE(NAME, BASE, N)                                   \
171
143
do {                                                                    \
172
144
        ut_ad(N);                                                       \
185
157
        UT_LIST_REMOVE_CLEAR(NAME, N);                                  \
186
158
} while (0)
187
159
 
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 */
 
160
/************************************************************************
 
161
Gets the next node in a two-way list. NAME is the name of the list
 
162
and N is pointer to a node. */
 
163
 
193
164
#define UT_LIST_GET_NEXT(NAME, N)\
194
165
        (((N)->NAME).next)
195
166
 
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 */
 
167
/************************************************************************
 
168
Gets the previous node in a two-way list. NAME is the name of the list
 
169
and N is pointer to a node. */
 
170
 
201
171
#define UT_LIST_GET_PREV(NAME, N)\
202
172
        (((N)->NAME).prev)
203
173
 
204
 
/********************************************************************//**
 
174
/************************************************************************
205
175
Alternative macro to get the number of nodes in a two-way list, i.e.,
206
 
its length.
207
 
@param BASE     the base node (not a pointer to it).
208
 
@return         the number of nodes in the list */
 
176
its length. BASE is the base node (not a pointer to it). */
 
177
 
209
178
#define UT_LIST_GET_LEN(BASE)\
210
179
        (BASE).count
211
180
 
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 */
 
181
/************************************************************************
 
182
Gets the first node in a two-way list, or returns NULL,
 
183
if the list is empty. BASE is the base node (not a pointer to it). */
 
184
 
216
185
#define UT_LIST_GET_FIRST(BASE)\
217
186
        (BASE).start
218
187
 
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 */
 
188
/************************************************************************
 
189
Gets the last node in a two-way list, or returns NULL,
 
190
if the list is empty. BASE is the base node (not a pointer to it). */
 
191
 
223
192
#define UT_LIST_GET_LAST(BASE)\
224
193
        (BASE).end
225
194
 
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)
 
195
/************************************************************************
 
196
Checks the consistency of a two-way list. NAME is the name of the list,
 
197
TYPE is the node type, and BASE is the base node (not a pointer to it). */
 
198
 
 
199
#define UT_LIST_VALIDATE(NAME, TYPE, BASE)\
 
200
{\
 
201
        ulint   ut_list_i_313;\
 
202
        TYPE *  ut_list_node_313;\
 
203
\
 
204
        ut_list_node_313 = (BASE).start;\
 
205
\
 
206
        for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
 
207
                                                ut_list_i_313++) {\
 
208
                ut_a(ut_list_node_313);\
 
209
                ut_list_node_313 = (ut_list_node_313->NAME).next;\
 
210
        }\
 
211
\
 
212
        ut_a(ut_list_node_313 == NULL);\
 
213
\
 
214
        ut_list_node_313 = (BASE).end;\
 
215
\
 
216
        for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
 
217
                                                ut_list_i_313++) {\
 
218
                ut_a(ut_list_node_313);\
 
219
                ut_list_node_313 = (ut_list_node_313->NAME).prev;\
 
220
        }\
 
221
\
 
222
        ut_a(ut_list_node_313 == NULL);\
 
223
}\
 
224
 
259
225
 
260
226
#endif
261
227