]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_misc.c
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / netat / adsp_misc.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #include <sys/errno.h>
23 #include <sys/types.h>
24 #include <sys/param.h>
25 #include <machine/spl.h>
26 #include <sys/systm.h>
27 #include <sys/kernel.h>
28 #include <sys/proc.h>
29 #include <sys/filedesc.h>
30 #include <sys/fcntl.h>
31 #include <sys/mbuf.h>
32 #include <sys/socket.h>
33
34 #include <netat/sysglue.h>
35 #include <netat/appletalk.h>
36 #include <netat/at_pcb.h>
37 #include <netat/debug.h>
38 #include <netat/adsp.h>
39 #include <netat/adsp_internal.h>
40
41 /*
42 * These function replace the Mk68 assembly routines found in qAddToEnd.s and
43 * q????.s
44 * Modified for MP, 1996 by Tuyen Nguyen
45 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
46 */
47
48
49 struct qlink {
50 struct qlink *qlinkp;
51 };
52
53 /* ----------------------------------------------------------------------
54 * void qAddToEnd(void *qhead, void *qelem)
55 *
56 * INPUTS:
57 * Ptr to ptr to 1st item in queue
58 * Ptr to item to add to end of queue
59 * OUTPUTS:
60 * none
61 *
62 * Assumptions: The link field is the FIRST field of the qelem structure.
63 * ----------------------------------------------------------------------
64 */
65 int qAddToEnd(qhead, qelem)
66 struct qlink **qhead;
67 struct qlink *qelem;
68 {
69 /* define our own type to access the next field. NOTE THAT THE "NEXT"
70 * FIELD IS ASSUMED TO BE THE FIRST FIELD OF THE STRUCTURE
71 */
72
73 register struct qlink *q;
74
75 /* Scan the linked list to the end and update the previous
76 * element next field. (do that protocted).
77 */
78
79 q = *qhead;
80 if (q) {
81 while (q->qlinkp) {
82 /* are we about to link to ourself */
83 if (q == qelem)
84 goto breakit;
85 q = q->qlinkp;
86 }
87 q->qlinkp = qelem;
88 }
89 else {
90 *qhead = qelem;
91 }
92 qelem->qlinkp = (struct qlink *) 0;
93 breakit:
94 #ifdef NOTDEF
95 DPRINTF("%s: qhead=%x added elem=%x\n","qAddToEnd", qhead, qelem);
96 #endif
97 return 0;
98 }
99
100
101
102 /* ----------------------------------------------------------------------
103 * qfind_m
104 * void* qfind_m(void *qhead, void NPTR match, ProcPtr compare_fnx)
105 *
106 * Hunt down a linked list of queue elements calling the compare
107 * function on each item. When the compare function returns true,
108 * return ptr to the queue element.
109 *
110 *
111 * INPUTS:
112 * qhead Address of ptr to first item in queue
113 * match
114 * compare_fnx
115 * OUTPUTS:
116 * D0 & A0 Ptr to queue element or NIL
117 * REGISTERS:
118 * D0,D1,A0,A1
119 * ----------------------------------------------------------------------
120 */
121 void* qfind_m(qhead, match, compare_fnx)
122 CCBPtr qhead;
123 void *match;
124 ProcPtr compare_fnx;
125 {
126 CCBPtr queue_item = qhead;
127
128 while (queue_item) {
129 if ((*compare_fnx)(queue_item,match))
130 break;
131
132 queue_item = queue_item->ccbLink;
133 }
134
135 return (queue_item);
136 }