~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Moved the last of the libdrizzleclient calls into Protocol.

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
List utilities
 
21
 
 
22
Created 9/10/1995 Heikki Tuuri
 
23
***********************************************************************/
 
24
 
 
25
#ifndef ut0lst_h
 
26
#define ut0lst_h
 
27
 
 
28
#include "univ.i"
 
29
 
 
30
/* This module implements the two-way linear list which should be used
 
31
if a list is used in the database. Note that a single struct may belong
 
32
to two or more lists, provided that the list are given different names.
 
33
An example of the usage of the lists can be found in fil0fil.c. */
 
34
 
 
35
/***********************************************************************
 
36
This macro expands to the unnamed type definition of a struct which acts
 
37
as the two-way list base node. The base node contains pointers
 
38
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
 
 
41
#define UT_LIST_BASE_NODE_T(TYPE)\
 
42
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 */\
 
46
}\
 
47
 
 
48
/***********************************************************************
 
49
This macro expands to the unnamed type definition of a struct which
 
50
should be embedded in the nodes of the list, the node type must be a struct.
 
51
This struct contains the pointers to next and previous nodes in the list.
 
52
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
 
 
55
typedef struct LRU_node_struct  LRU_node_t;
 
56
struct LRU_node_struct {
 
57
        UT_LIST_NODE_T(LRU_node_t)      LRU_list;
 
58
        ...
 
59
}
 
60
The example implements an LRU list of name LRU_list. Its nodes are of type
 
61
LRU_node_t.
 
62
*/
 
63
 
 
64
#define UT_LIST_NODE_T(TYPE)\
 
65
struct {\
 
66
        TYPE *  prev;   /* pointer to the previous node,\
 
67
                        NULL if start of list */\
 
68
        TYPE *  next;   /* pointer to next node, NULL if end of list */\
 
69
}\
 
70
 
 
71
/***********************************************************************
 
72
Initializes the base node of a two-way list. */
 
73
 
 
74
#define UT_LIST_INIT(BASE)\
 
75
{\
 
76
        (BASE).count = 0;\
 
77
        (BASE).start = NULL;\
 
78
        (BASE).end   = NULL;\
 
79
}\
 
80
 
 
81
/***********************************************************************
 
82
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
 
 
86
#define UT_LIST_ADD_FIRST(NAME, BASE, N)\
 
87
{\
 
88
        ut_ad(N);\
 
89
        ((BASE).count)++;\
 
90
        ((N)->NAME).next = (BASE).start;\
 
91
        ((N)->NAME).prev = NULL;\
 
92
        if (UNIV_LIKELY((BASE).start != NULL)) {\
 
93
                ut_ad((BASE).start != (N));\
 
94
                (((BASE).start)->NAME).prev = (N);\
 
95
        }\
 
96
        (BASE).start = (N);\
 
97
        if (UNIV_UNLIKELY((BASE).end == NULL)) {\
 
98
                (BASE).end = (N);\
 
99
        }\
 
100
}\
 
101
 
 
102
/***********************************************************************
 
103
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
#define UT_LIST_ADD_LAST(NAME, BASE, N)\
 
108
{\
 
109
        ut_ad(N);\
 
110
        ((BASE).count)++;\
 
111
        ((N)->NAME).prev = (BASE).end;\
 
112
        ((N)->NAME).next = NULL;\
 
113
        if ((BASE).end != NULL) {\
 
114
                ut_ad((BASE).end != (N));\
 
115
                (((BASE).end)->NAME).next = (N);\
 
116
        }\
 
117
        (BASE).end = (N);\
 
118
        if ((BASE).start == NULL) {\
 
119
                (BASE).start = (N);\
 
120
        }\
 
121
}\
 
122
 
 
123
/***********************************************************************
 
124
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
 
 
128
#define UT_LIST_INSERT_AFTER(NAME, BASE, NODE1, NODE2)\
 
129
{\
 
130
        ut_ad(NODE1);\
 
131
        ut_ad(NODE2);\
 
132
        ut_ad((NODE1) != (NODE2));\
 
133
        ((BASE).count)++;\
 
134
        ((NODE2)->NAME).prev = (NODE1);\
 
135
        ((NODE2)->NAME).next = ((NODE1)->NAME).next;\
 
136
        if (((NODE1)->NAME).next != NULL) {\
 
137
                ((((NODE1)->NAME).next)->NAME).prev = (NODE2);\
 
138
        }\
 
139
        ((NODE1)->NAME).next = (NODE2);\
 
140
        if ((BASE).end == (NODE1)) {\
 
141
                (BASE).end = (NODE2);\
 
142
        }\
 
143
}\
 
144
 
 
145
/* Invalidate the pointers in a list node. */
 
146
#ifdef UNIV_LIST_DEBUG
 
147
# define UT_LIST_REMOVE_CLEAR(NAME, N)          \
 
148
((N)->NAME.prev = (N)->NAME.next = (void*) -1)
 
149
#else
 
150
# define UT_LIST_REMOVE_CLEAR(NAME, N)
 
151
#endif
 
152
 
 
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
 
 
158
#define UT_LIST_REMOVE(NAME, BASE, N)                                   \
 
159
do {                                                                    \
 
160
        ut_ad(N);                                                       \
 
161
        ut_a((BASE).count > 0);                                         \
 
162
        ((BASE).count)--;                                               \
 
163
        if (((N)->NAME).next != NULL) {                                 \
 
164
                ((((N)->NAME).next)->NAME).prev = ((N)->NAME).prev;     \
 
165
        } else {                                                        \
 
166
                (BASE).end = ((N)->NAME).prev;                          \
 
167
        }                                                               \
 
168
        if (((N)->NAME).prev != NULL) {                                 \
 
169
                ((((N)->NAME).prev)->NAME).next = ((N)->NAME).next;     \
 
170
        } else {                                                        \
 
171
                (BASE).start = ((N)->NAME).next;                        \
 
172
        }                                                               \
 
173
        UT_LIST_REMOVE_CLEAR(NAME, N);                                  \
 
174
} while (0)
 
175
 
 
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
 
 
180
#define UT_LIST_GET_NEXT(NAME, N)\
 
181
        (((N)->NAME).next)
 
182
 
 
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
 
 
187
#define UT_LIST_GET_PREV(NAME, N)\
 
188
        (((N)->NAME).prev)
 
189
 
 
190
/************************************************************************
 
191
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
 
 
194
#define UT_LIST_GET_LEN(BASE)\
 
195
        (BASE).count
 
196
 
 
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
 
 
201
#define UT_LIST_GET_FIRST(BASE)\
 
202
        (BASE).start
 
203
 
 
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
 
 
208
#define UT_LIST_GET_LAST(BASE)\
 
209
        (BASE).end
 
210
 
 
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
 
 
241
 
 
242
#endif
 
243