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 (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <mdb/mdb_list.h>
30 #include <mdb/mdb_debug.h>
34 * Simple doubly-linked list implementation. This implementation assumes that
35 * each list element contains an embedded mdb_list_t (previous and next
36 * pointers), which is typically the first member of the element struct.
37 * An additional mdb_list_t is used to store the head (ml_next) and tail
38 * (ml_prev) pointers. The current head and tail list elements have their
39 * previous and next pointers set to NULL, respectively.
43 mdb_list_append(mdb_list_t
*mlp
, void *new)
45 mdb_list_t
*p
= mlp
->ml_prev
; /* p = tail list element */
46 mdb_list_t
*q
= new; /* q = new list element */
53 ASSERT(p
->ml_next
== NULL
);
56 ASSERT(mlp
->ml_next
== NULL
);
62 mdb_list_prepend(mdb_list_t
*mlp
, void *new)
64 mdb_list_t
*p
= new; /* p = new list element */
65 mdb_list_t
*q
= mlp
->ml_next
; /* q = head list element */
72 ASSERT(q
->ml_prev
== NULL
);
75 ASSERT(mlp
->ml_prev
== NULL
);
81 mdb_list_insert(mdb_list_t
*mlp
, void *after_me
, void *new)
83 mdb_list_t
*p
= after_me
;
86 if (p
== NULL
|| p
->ml_next
== NULL
) {
87 mdb_list_append(mlp
, new);
91 q
->ml_next
= p
->ml_next
;
94 q
->ml_next
->ml_prev
= q
;
98 mdb_list_delete(mdb_list_t
*mlp
, void *existing
)
100 mdb_list_t
*p
= existing
;
102 if (p
->ml_prev
!= NULL
)
103 p
->ml_prev
->ml_next
= p
->ml_next
;
105 mlp
->ml_next
= p
->ml_next
;
107 if (p
->ml_next
!= NULL
)
108 p
->ml_next
->ml_prev
= p
->ml_prev
;
110 mlp
->ml_prev
= p
->ml_prev
;
114 mdb_list_move(mdb_list_t
*src
, mdb_list_t
*dst
)
116 dst
->ml_prev
= src
->ml_prev
;
117 dst
->ml_next
= src
->ml_next
;