The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / deps / liboi / oi_queue.h @ 40c0f755
History | View | Annotate | Download (2.8 KB)
1 | 40c0f755 | Ryan | /* Copyright (C) 2002-2009 Igor Sysoev
|
---|---|---|---|
2 | *
|
||
3 | * Redistribution and use in source and binary forms, with or without
|
||
4 | * modification, are permitted provided that the following conditions
|
||
5 | * are met:
|
||
6 | * 1. Redistributions of source code must retain the above copyright
|
||
7 | * notice, this list of conditions and the following disclaimer.
|
||
8 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
9 | * notice, this list of conditions and the following disclaimer in the
|
||
10 | * documentation and/or other materials provided with the distribution.
|
||
11 | *
|
||
12 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||
13 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
14 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
15 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||
16 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
17 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
18 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
20 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
21 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
22 | * SUCH DAMAGE.
|
||
23 | */
|
||
24 | #ifndef oi_queue_h
|
||
25 | #define oi_queue_h
|
||
26 | #ifdef __cplusplus
|
||
27 | extern "C" { |
||
28 | #endif
|
||
29 | |||
30 | #include <stddef.h> /* offsetof() */ |
||
31 | |||
32 | typedef struct oi_queue oi_queue; |
||
33 | struct oi_queue {
|
||
34 | oi_queue *prev; |
||
35 | oi_queue *next; |
||
36 | }; |
||
37 | |||
38 | #define oi_queue_init(q) \
|
||
39 | (q)->prev = q; \ |
||
40 | (q)->next = q |
||
41 | |||
42 | #define oi_queue_empty(h) \
|
||
43 | (h == (h)->prev) |
||
44 | |||
45 | #define oi_queue_insert_head(h, x) \
|
||
46 | (x)->next = (h)->next; \ |
||
47 | (x)->next->prev = x; \ |
||
48 | (x)->prev = h; \ |
||
49 | (h)->next = x |
||
50 | |||
51 | #define oi_queue_head(h) \
|
||
52 | (h)->next |
||
53 | |||
54 | #define oi_queue_last(h) \
|
||
55 | (h)->prev |
||
56 | |||
57 | #define oi_queue_remove(x) \
|
||
58 | (x)->next->prev = (x)->prev; \ |
||
59 | (x)->prev->next = (x)->next; \ |
||
60 | (x)->prev = NULL; \
|
||
61 | (x)->next = NULL
|
||
62 | |||
63 | #define oi_queue_data(q, type, link) \
|
||
64 | (type *) ((unsigned char *) q - offsetof(type, link)) |
||
65 | |||
66 | #ifdef __cplusplus
|
||
67 | } |
||
68 | #endif
|
||
69 | #endif // oi_queue_h |