Skip to main content
summaryrefslogtreecommitdiffstats
blob: aed67a2145feefdd635e2f04aa3a298f140d0309 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 * You may elect to redistribute this code under either of these licenses.
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/

/*
 * Double linked list support.
 */

#ifndef D_link
#define D_link

#include <stddef.h>

typedef struct LINK LINK;

struct LINK {
    LINK * next;
    LINK * prev;
};


#define TCF_LIST_INIT(list)  {&(list), &(list)}

#define list_init(list) { \
            (list)->next = (list)->prev = (list); \
        }

#define list_is_empty(list) ((list)->next == (list) || (list)->next == NULL)

#define list_remove(item) { \
            LINK * _l_ = item; \
            _l_->prev->next = _l_->next; \
            _l_->next->prev = _l_->prev; \
            _l_->next = _l_->prev = _l_; \
        }

#define list_add_first(item,list) { \
            (item)->next = (list)->next; (item)->prev = (list); \
            (list)->next->prev = (item); (list)->next = (item); \
        }

#define list_add_last(item,list) { \
            (item)->next = (list); (item)->prev = (list)->prev; \
            (list)->prev->next = (item); (list)->prev = (item); \
        }

#define list_concat(item,list) { \
            if (!list_is_empty(list)) { \
                (item)->prev->next = (list)->next; \
                (list)->next->prev = (item)->prev; \
                (item)->prev = (list)->prev; \
                (list)->prev->next = (item); \
            } \
        }

#define list_foreach(trav,list) \
	for (trav = (list)->next; trav != list; trav = trav->next)

#endif /* D_link */

Back to the top