~ubuntu-branches/ubuntu/natty/evolution-data-server/natty

« back to all changes in this revision

Viewing changes to libdb/dbinc/shqueue.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1996-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 *
7
 
 * $Id$
8
 
 */
9
 
 
10
 
#ifndef _SYS_SHQUEUE_H_
11
 
#define _SYS_SHQUEUE_H_
12
 
 
13
 
/*
14
 
 * This file defines three types of data structures: lists, tail queues, and
15
 
 * circular queues, similarly to the include file <sys/queue.h>.
16
 
 *
17
 
 * The difference is that this set of macros can be used for structures that
18
 
 * reside in shared memory that may be mapped at different addresses in each
19
 
 * process.  In most cases, the macros for shared structures exactly mirror
20
 
 * the normal macros, although the macro calls require an additional type
21
 
 * parameter, only used by the HEAD and ENTRY macros of the standard macros.
22
 
 *
23
 
 * For details on the use of these macros, see the queue(3) manual page.
24
 
 */
25
 
 
26
 
#if defined(__cplusplus)
27
 
extern "C" {
28
 
#endif
29
 
 
30
 
/*
31
 
 * Shared list definitions.
32
 
 */
33
 
#define SH_LIST_HEAD(name)                                              \
34
 
struct name {                                                           \
35
 
        ssize_t slh_first;      /* first element */                     \
36
 
}
37
 
 
38
 
#define SH_LIST_ENTRY                                                   \
39
 
struct {                                                                \
40
 
        ssize_t sle_next;       /* relative offset next element */      \
41
 
        ssize_t sle_prev;       /* relative offset of prev element */   \
42
 
}
43
 
 
44
 
/*
45
 
 * Shared list functions.  Since we use relative offsets for pointers,
46
 
 * 0 is a valid offset.  Therefore, we use -1 to indicate end of list.
47
 
 * The macros ending in "P" return pointers without checking for end
48
 
 * of list, the others check for end of list and evaluate to either a
49
 
 * pointer or NULL.
50
 
 */
51
 
 
52
 
#define SH_LIST_FIRSTP(head, type)                                      \
53
 
        ((struct type *)(((u_int8_t *)(head)) + (head)->slh_first))
54
 
 
55
 
#define SH_LIST_FIRST(head, type)                                       \
56
 
        ((head)->slh_first == -1 ? NULL :                               \
57
 
        ((struct type *)(((u_int8_t *)(head)) + (head)->slh_first)))
58
 
 
59
 
#define SH_LIST_NEXTP(elm, field, type)                                 \
60
 
        ((struct type *)(((u_int8_t *)(elm)) + (elm)->field.sle_next))
61
 
 
62
 
#define SH_LIST_NEXT(elm, field, type)                                  \
63
 
        ((elm)->field.sle_next == -1 ? NULL :                           \
64
 
        ((struct type *)(((u_int8_t *)(elm)) + (elm)->field.sle_next)))
65
 
 
66
 
#define SH_LIST_PREV(elm, field)                                        \
67
 
        ((ssize_t *)(((u_int8_t *)(elm)) + (elm)->field.sle_prev))
68
 
 
69
 
#define SH_PTR_TO_OFF(src, dest)                                        \
70
 
        ((ssize_t)(((u_int8_t *)(dest)) - ((u_int8_t *)(src))))
71
 
 
72
 
/*
73
 
 * Take the element's next pointer and calculate what the corresponding
74
 
 * Prev pointer should be -- basically it is the negation plus the offset
75
 
 * of the next field in the structure.
76
 
 */
77
 
#define SH_LIST_NEXT_TO_PREV(elm, field)                                \
78
 
        (-(elm)->field.sle_next + SH_PTR_TO_OFF(elm, &(elm)->field.sle_next))
79
 
 
80
 
#define SH_LIST_INIT(head) (head)->slh_first = -1
81
 
 
82
 
#define SH_LIST_INSERT_AFTER(listelm, elm, field, type) do {            \
83
 
        if ((listelm)->field.sle_next != -1) {                          \
84
 
                (elm)->field.sle_next = SH_PTR_TO_OFF(elm,              \
85
 
                    SH_LIST_NEXTP(listelm, field, type));               \
86
 
                SH_LIST_NEXTP(listelm, field, type)->field.sle_prev =   \
87
 
                        SH_LIST_NEXT_TO_PREV(elm, field);               \
88
 
        } else                                                          \
89
 
                (elm)->field.sle_next = -1;                             \
90
 
        (listelm)->field.sle_next = SH_PTR_TO_OFF(listelm, elm);        \
91
 
        (elm)->field.sle_prev = SH_LIST_NEXT_TO_PREV(listelm, field);   \
92
 
} while (0)
93
 
 
94
 
#define SH_LIST_INSERT_HEAD(head, elm, field, type) do {                \
95
 
        if ((head)->slh_first != -1) {                                  \
96
 
                (elm)->field.sle_next =                         \
97
 
                    (head)->slh_first - SH_PTR_TO_OFF(head, elm);       \
98
 
                SH_LIST_FIRSTP(head, type)->field.sle_prev =            \
99
 
                        SH_LIST_NEXT_TO_PREV(elm, field);               \
100
 
        } else                                                          \
101
 
                (elm)->field.sle_next = -1;                             \
102
 
        (head)->slh_first = SH_PTR_TO_OFF(head, elm);                   \
103
 
        (elm)->field.sle_prev = SH_PTR_TO_OFF(elm, &(head)->slh_first); \
104
 
} while (0)
105
 
 
106
 
#define SH_LIST_REMOVE(elm, field, type) do {                           \
107
 
        if ((elm)->field.sle_next != -1) {                              \
108
 
                SH_LIST_NEXTP(elm, field, type)->field.sle_prev =       \
109
 
                        (elm)->field.sle_prev - (elm)->field.sle_next;  \
110
 
                *SH_LIST_PREV(elm, field) += (elm)->field.sle_next;     \
111
 
        } else                                                          \
112
 
                *SH_LIST_PREV(elm, field) = -1;                         \
113
 
} while (0)
114
 
 
115
 
/*
116
 
 * Shared tail queue definitions.
117
 
 */
118
 
#define SH_TAILQ_HEAD(name)                                             \
119
 
struct name {                                                           \
120
 
        ssize_t stqh_first;     /* relative offset of first element */  \
121
 
        ssize_t stqh_last;      /* relative offset of last's next */    \
122
 
}
123
 
 
124
 
#define SH_TAILQ_ENTRY                                                  \
125
 
struct {                                                                \
126
 
        ssize_t stqe_next;      /* relative offset of next element */   \
127
 
        ssize_t stqe_prev;      /* relative offset of prev's next */    \
128
 
}
129
 
 
130
 
/*
131
 
 * Shared tail queue functions.
132
 
 */
133
 
#define SH_TAILQ_FIRSTP(head, type)                                     \
134
 
        ((struct type *)((u_int8_t *)(head) + (head)->stqh_first))
135
 
 
136
 
#define SH_TAILQ_FIRST(head, type)                                      \
137
 
        ((head)->stqh_first == -1 ? NULL : SH_TAILQ_FIRSTP(head, type))
138
 
 
139
 
#define SH_TAILQ_NEXTP(elm, field, type)                                \
140
 
        ((struct type *)((u_int8_t *)(elm) + (elm)->field.stqe_next))
141
 
 
142
 
#define SH_TAILQ_NEXT(elm, field, type)                                 \
143
 
        ((elm)->field.stqe_next == -1 ? NULL : SH_TAILQ_NEXTP(elm, field, type))
144
 
 
145
 
#define SH_TAILQ_PREVP(elm, field)                                      \
146
 
        ((ssize_t *)((u_int8_t *)(elm) + (elm)->field.stqe_prev))
147
 
 
148
 
#define SH_TAILQ_LAST(head)                                             \
149
 
        ((ssize_t *)(((u_int8_t *)(head)) + (head)->stqh_last))
150
 
 
151
 
#define SH_TAILQ_NEXT_TO_PREV(elm, field)                               \
152
 
        (-(elm)->field.stqe_next + SH_PTR_TO_OFF(elm, &(elm)->field.stqe_next))
153
 
 
154
 
#define SH_TAILQ_INIT(head) {                                           \
155
 
        (head)->stqh_first = -1;                                        \
156
 
        (head)->stqh_last = SH_PTR_TO_OFF(head, &(head)->stqh_first);   \
157
 
}
158
 
 
159
 
#define SH_TAILQ_INSERT_HEAD(head, elm, field, type) do {               \
160
 
        if ((head)->stqh_first != -1) {                                 \
161
 
                (elm)->field.stqe_next =                                \
162
 
                    (head)->stqh_first - SH_PTR_TO_OFF(head, elm);      \
163
 
                SH_TAILQ_FIRSTP(head, type)->field.stqe_prev =          \
164
 
                        SH_TAILQ_NEXT_TO_PREV(elm, field);              \
165
 
        } else {                                                        \
166
 
                (elm)->field.stqe_next = -1;                            \
167
 
                (head)->stqh_last =                                     \
168
 
                    SH_PTR_TO_OFF(head, &(elm)->field.stqe_next);       \
169
 
        }                                                               \
170
 
        (head)->stqh_first = SH_PTR_TO_OFF(head, elm);                  \
171
 
        (elm)->field.stqe_prev =                                        \
172
 
            SH_PTR_TO_OFF(elm, &(head)->stqh_first);                    \
173
 
} while (0)
174
 
 
175
 
#define SH_TAILQ_INSERT_TAIL(head, elm, field) do {                     \
176
 
        (elm)->field.stqe_next = -1;                                    \
177
 
        (elm)->field.stqe_prev =                                        \
178
 
            -SH_PTR_TO_OFF(head, elm) + (head)->stqh_last;              \
179
 
        if ((head)->stqh_last ==                                        \
180
 
            SH_PTR_TO_OFF((head), &(head)->stqh_first))                 \
181
 
                (head)->stqh_first = SH_PTR_TO_OFF(head, elm);          \
182
 
        else                                                            \
183
 
                *SH_TAILQ_LAST(head) = -(head)->stqh_last +             \
184
 
                    SH_PTR_TO_OFF((elm), &(elm)->field.stqe_next) +     \
185
 
                    SH_PTR_TO_OFF(head, elm);                           \
186
 
        (head)->stqh_last =                                             \
187
 
            SH_PTR_TO_OFF(head, &((elm)->field.stqe_next));             \
188
 
} while (0)
189
 
 
190
 
#define SH_TAILQ_INSERT_AFTER(head, listelm, elm, field, type) do {     \
191
 
        if ((listelm)->field.stqe_next != -1) {                         \
192
 
                (elm)->field.stqe_next = (listelm)->field.stqe_next -   \
193
 
                    SH_PTR_TO_OFF(listelm, elm);                        \
194
 
                SH_TAILQ_NEXTP(listelm, field, type)->field.stqe_prev = \
195
 
                    SH_TAILQ_NEXT_TO_PREV(elm, field);                  \
196
 
        } else {                                                        \
197
 
                (elm)->field.stqe_next = -1;                            \
198
 
                (head)->stqh_last =                                     \
199
 
                    SH_PTR_TO_OFF(head, &elm->field.stqe_next);         \
200
 
        }                                                               \
201
 
        (listelm)->field.stqe_next = SH_PTR_TO_OFF(listelm, elm);       \
202
 
        (elm)->field.stqe_prev = SH_TAILQ_NEXT_TO_PREV(listelm, field); \
203
 
} while (0)
204
 
 
205
 
#define SH_TAILQ_REMOVE(head, elm, field, type) do {                    \
206
 
        if ((elm)->field.stqe_next != -1) {                             \
207
 
                SH_TAILQ_NEXTP(elm, field, type)->field.stqe_prev =     \
208
 
                    (elm)->field.stqe_prev +                            \
209
 
                    SH_PTR_TO_OFF(SH_TAILQ_NEXTP(elm,                   \
210
 
                    field, type), elm);                                 \
211
 
                *SH_TAILQ_PREVP(elm, field) += elm->field.stqe_next;    \
212
 
        } else {                                                        \
213
 
                (head)->stqh_last = (elm)->field.stqe_prev +            \
214
 
                        SH_PTR_TO_OFF(head, elm);                       \
215
 
                *SH_TAILQ_PREVP(elm, field) = -1;                       \
216
 
        }                                                               \
217
 
} while (0)
218
 
 
219
 
/*
220
 
 * Shared circular queue definitions.
221
 
 */
222
 
#define SH_CIRCLEQ_HEAD(name)                                           \
223
 
struct name {                                                           \
224
 
        ssize_t scqh_first;             /* first element */             \
225
 
        ssize_t scqh_last;              /* last element */              \
226
 
}
227
 
 
228
 
#define SH_CIRCLEQ_ENTRY                                                \
229
 
struct {                                                                \
230
 
        ssize_t scqe_next;              /* next element */              \
231
 
        ssize_t scqe_prev;              /* previous element */          \
232
 
}
233
 
 
234
 
/*
235
 
 * Shared circular queue functions.
236
 
 */
237
 
#define SH_CIRCLEQ_FIRSTP(head, type)                                   \
238
 
        ((struct type *)(((u_int8_t *)(head)) + (head)->scqh_first))
239
 
 
240
 
#define SH_CIRCLEQ_FIRST(head, type)                                    \
241
 
        ((head)->scqh_first == -1 ?                                     \
242
 
        (void *)head : SH_CIRCLEQ_FIRSTP(head, type))
243
 
 
244
 
#define SH_CIRCLEQ_LASTP(head, type)                                    \
245
 
        ((struct type *)(((u_int8_t *)(head)) + (head)->scqh_last))
246
 
 
247
 
#define SH_CIRCLEQ_LAST(head, type)                                     \
248
 
        ((head)->scqh_last == -1 ? (void *)head : SH_CIRCLEQ_LASTP(head, type))
249
 
 
250
 
#define SH_CIRCLEQ_NEXTP(elm, field, type)                              \
251
 
        ((struct type *)(((u_int8_t *)(elm)) + (elm)->field.scqe_next))
252
 
 
253
 
#define SH_CIRCLEQ_NEXT(head, elm, field, type)                         \
254
 
        ((elm)->field.scqe_next == SH_PTR_TO_OFF(elm, head) ?           \
255
 
            (void *)head : SH_CIRCLEQ_NEXTP(elm, field, type))
256
 
 
257
 
#define SH_CIRCLEQ_PREVP(elm, field, type)                              \
258
 
        ((struct type *)(((u_int8_t *)(elm)) + (elm)->field.scqe_prev))
259
 
 
260
 
#define SH_CIRCLEQ_PREV(head, elm, field, type)                         \
261
 
        ((elm)->field.scqe_prev == SH_PTR_TO_OFF(elm, head) ?           \
262
 
            (void *)head : SH_CIRCLEQ_PREVP(elm, field, type))
263
 
 
264
 
#define SH_CIRCLEQ_INIT(head) {                                         \
265
 
        (head)->scqh_first = 0;                                         \
266
 
        (head)->scqh_last = 0;                                          \
267
 
}
268
 
 
269
 
#define SH_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field, type) do {   \
270
 
        (elm)->field.scqe_prev = SH_PTR_TO_OFF(elm, listelm);           \
271
 
        (elm)->field.scqe_next = (listelm)->field.scqe_next +           \
272
 
            (elm)->field.scqe_prev;                                     \
273
 
        if (SH_CIRCLEQ_NEXTP(listelm, field, type) == (void *)head)     \
274
 
                (head)->scqh_last = SH_PTR_TO_OFF(head, elm);           \
275
 
        else                                                            \
276
 
                SH_CIRCLEQ_NEXTP(listelm,                               \
277
 
                    field, type)->field.scqe_prev =                     \
278
 
                    SH_PTR_TO_OFF(SH_CIRCLEQ_NEXTP(listelm,             \
279
 
                    field, type), elm);                                 \
280
 
        (listelm)->field.scqe_next = -(elm)->field.scqe_prev;           \
281
 
} while (0)
282
 
 
283
 
#define SH_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field, type) do {  \
284
 
        (elm)->field.scqe_next = SH_PTR_TO_OFF(elm, listelm);           \
285
 
        (elm)->field.scqe_prev = (elm)->field.scqe_next -               \
286
 
                SH_CIRCLEQ_PREVP(listelm, field, type)->field.scqe_next;\
287
 
        if (SH_CIRCLEQ_PREVP(listelm, field, type) == (void *)(head))   \
288
 
                (head)->scqh_first = SH_PTR_TO_OFF(head, elm);          \
289
 
        else                                                            \
290
 
                SH_CIRCLEQ_PREVP(listelm,                               \
291
 
                    field, type)->field.scqe_next =                     \
292
 
                    SH_PTR_TO_OFF(SH_CIRCLEQ_PREVP(listelm,             \
293
 
                    field, type), elm);                                 \
294
 
        (listelm)->field.scqe_prev = -(elm)->field.scqe_next;           \
295
 
} while (0)
296
 
 
297
 
#define SH_CIRCLEQ_INSERT_HEAD(head, elm, field, type) do {             \
298
 
        (elm)->field.scqe_prev = SH_PTR_TO_OFF(elm, head);              \
299
 
        (elm)->field.scqe_next = (head)->scqh_first +                   \
300
 
                (elm)->field.scqe_prev;                                 \
301
 
        if ((head)->scqh_last == 0)                                     \
302
 
                (head)->scqh_last = -(elm)->field.scqe_prev;            \
303
 
        else                                                            \
304
 
                SH_CIRCLEQ_FIRSTP(head, type)->field.scqe_prev =        \
305
 
                    SH_PTR_TO_OFF(SH_CIRCLEQ_FIRSTP(head, type), elm);  \
306
 
        (head)->scqh_first = -(elm)->field.scqe_prev;                   \
307
 
} while (0)
308
 
 
309
 
#define SH_CIRCLEQ_INSERT_TAIL(head, elm, field, type) do {             \
310
 
        (elm)->field.scqe_next = SH_PTR_TO_OFF(elm, head);              \
311
 
        (elm)->field.scqe_prev = (head)->scqh_last +                    \
312
 
            (elm)->field.scqe_next;                                     \
313
 
        if ((head)->scqh_first == 0)                                    \
314
 
                (head)->scqh_first = -(elm)->field.scqe_next;           \
315
 
        else                                                            \
316
 
                SH_CIRCLEQ_LASTP(head, type)->field.scqe_next = \
317
 
                    SH_PTR_TO_OFF(SH_CIRCLEQ_LASTP(head, type), elm);   \
318
 
        (head)->scqh_last = -(elm)->field.scqe_next;                    \
319
 
} while (0)
320
 
 
321
 
#define SH_CIRCLEQ_REMOVE(head, elm, field, type) do {                  \
322
 
        if (SH_CIRCLEQ_NEXTP(elm, field, type) == (void *)(head))       \
323
 
                (head)->scqh_last += (elm)->field.scqe_prev;            \
324
 
        else                                                            \
325
 
                SH_CIRCLEQ_NEXTP(elm, field, type)->field.scqe_prev +=  \
326
 
                    (elm)->field.scqe_prev;                             \
327
 
        if (SH_CIRCLEQ_PREVP(elm, field, type) == (void *)(head))       \
328
 
                (head)->scqh_first += (elm)->field.scqe_next;           \
329
 
        else                                                            \
330
 
                SH_CIRCLEQ_PREVP(elm, field, type)->field.scqe_next +=  \
331
 
                    (elm)->field.scqe_next;                             \
332
 
} while (0)
333
 
 
334
 
#if defined(__cplusplus)
335
 
}
336
 
#endif
337
 
#endif  /* !_SYS_SHQUEUE_H_ */