4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Simple doubly-linked list implementation. This implementation assumes that
31 * each list element contains an embedded dt_list_t (previous and next
32 * pointers), which is typically the first member of the element struct.
33 * An additional dt_list_t is used to store the head (dl_next) and tail
34 * (dl_prev) pointers. The current head and tail list elements have their
35 * previous and next pointers set to NULL, respectively.
43 dt_list_append(dt_list_t
*dlp
, void *new)
45 dt_list_t
*p
= dlp
->dl_prev
; /* p = tail list element */
46 dt_list_t
*q
= new; /* q = new list element */
53 assert(p
->dl_next
== NULL
);
56 assert(dlp
->dl_next
== NULL
);
62 dt_list_prepend(dt_list_t
*dlp
, void *new)
64 dt_list_t
*p
= new; /* p = new list element */
65 dt_list_t
*q
= dlp
->dl_next
; /* q = head list element */
72 assert(q
->dl_prev
== NULL
);
75 assert(dlp
->dl_prev
== NULL
);
81 dt_list_insert(dt_list_t
*dlp
, void *after_me
, void *new)
83 dt_list_t
*p
= after_me
;
86 if (p
== NULL
|| p
->dl_next
== NULL
) {
87 dt_list_append(dlp
, new);
91 q
->dl_next
= p
->dl_next
;
94 q
->dl_next
->dl_prev
= q
;
98 dt_list_delete(dt_list_t
*dlp
, void *existing
)
100 dt_list_t
*p
= existing
;
102 if (p
->dl_prev
!= NULL
)
103 p
->dl_prev
->dl_next
= p
->dl_next
;
105 dlp
->dl_next
= p
->dl_next
;
107 if (p
->dl_next
!= NULL
)
108 p
->dl_next
->dl_prev
= p
->dl_prev
;
110 dlp
->dl_prev
= p
->dl_prev
;