1 /* 2 * CDDL HEADER START 3 * 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 7 * with the License. 8 * 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. 13 * 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] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * Yet another list implementation 29 * This is a multipurpose double-linked list. It requires that the first 30 * two structure members of each item are the 'next' and 'prev' pointers. 31 * This works for mblk's and other data types utilized by av1394. 32 * 33 * Locking is provided by the caller. 34 */ 35 36 #include <sys/1394/targets/av1394/av1394_impl.h> 37 38 #define ITEM(i) ((av1394_list_item_t *)(i)) 39 40 /* 41 * av1394_list_init() 42 * Initializes the list 43 */ 44 void av1394_list_init(av1394_list_t * lp)45av1394_list_init(av1394_list_t *lp) 46 { 47 lp->l_head = lp->l_tail = NULL; 48 lp->l_cnt = 0; 49 } 50 51 /* 52 * av1394_list_head() 53 * Returns pointer to the first item in the list (but does not remove it) 54 */ 55 void * av1394_list_head(av1394_list_t * lp)56av1394_list_head(av1394_list_t *lp) 57 { 58 return (lp->l_head); 59 } 60 61 62 /* 63 * av1394_list_put_tail() 64 * Adds item to the end of the list 65 */ 66 void av1394_list_put_tail(av1394_list_t * lp,void * item)67av1394_list_put_tail(av1394_list_t *lp, void *item) 68 { 69 ITEM(item)->i_next = NULL; 70 ITEM(item)->i_prev = lp->l_tail; 71 if (lp->l_tail == NULL) { 72 ASSERT(lp->l_head == 0); 73 ASSERT(lp->l_cnt == 0); 74 lp->l_head = lp->l_tail = item; 75 } else { 76 lp->l_tail->i_next = item; 77 lp->l_tail = item; 78 } 79 lp->l_cnt++; 80 } 81 82 /* 83 * av1394_list_put_head() 84 * Inserts item in the front of the list 85 */ 86 void av1394_list_put_head(av1394_list_t * lp,void * item)87av1394_list_put_head(av1394_list_t *lp, void *item) 88 { 89 ITEM(item)->i_next = lp->l_head; 90 ITEM(item)->i_prev = NULL; 91 if (lp->l_head == NULL) { 92 ASSERT(lp->l_tail == 0); 93 ASSERT(lp->l_cnt == 0); 94 lp->l_head = lp->l_tail = item; 95 } else { 96 lp->l_head->i_prev = item; 97 lp->l_head = item; 98 } 99 lp->l_cnt++; 100 } 101 102 /* 103 * av1394_list_get_head() 104 * Removes and returns an item from the front of the list 105 */ 106 void * av1394_list_get_head(av1394_list_t * lp)107av1394_list_get_head(av1394_list_t *lp) 108 { 109 av1394_list_item_t *item; 110 111 item = lp->l_head; 112 if (item != NULL) { 113 lp->l_head = item->i_next; 114 if (item == lp->l_tail) { 115 ASSERT(lp->l_cnt == 1); 116 ASSERT(lp->l_head == NULL); 117 lp->l_tail = NULL; 118 lp->l_cnt = 0; 119 } else { 120 ASSERT(lp->l_cnt > 1); 121 item->i_next->i_prev = item->i_prev; 122 lp->l_cnt--; 123 } 124 item->i_next = item->i_prev = NULL; 125 } 126 return (item); 127 } 128