|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: #include <adsp_local.h>
26: extern atlock_t adspgen_lock;
27:
28:
29: struct qlink {
30: struct qlink *qlinkp;
31: };
32:
33: /* ----------------------------------------------------------------------
34: * void qAddToEnd(void *qhead, void *qelem)
35: *
36: * INPUTS:
37: * Ptr to ptr to 1st item in queue
38: * Ptr to item to add to end of queue
39: * OUTPUTS:
40: * none
41: *
42: * Assumptions: The link field is the FIRST field of the qelem structure.
43: * ----------------------------------------------------------------------
44: */
45: int qAddToEnd(qhead, qelem)
46: struct qlink **qhead;
47: struct qlink *qelem;
48: {
49: /* define our own type to access the next field. NOTE THAT THE "NEXT"
50: * FIELD IS ASSUMED TO BE THE FIRST FIELD OF THE STRUCTURE
51: */
52:
53:
54: int dummy = 0;
55: register struct qlink *q;
56:
57: /* Scan the linked list to the end and update the previous
58: * element next field. (do that protocted).
59: */
60:
61: q = *qhead;
62: if (q) {
63: while (q->qlinkp) {
64: /* are we about to link to ourself */
65: if (q == qelem)
66: goto breakit;
67: q = q->qlinkp;
68: }
69: q->qlinkp = qelem;
70: }
71: else {
72: *qhead = qelem;
73: }
74: qelem->qlinkp = (struct qlink *) 0;
75: breakit:
76: #ifdef NOTDEF
77: DPRINTF("%s: qhead=%x added elem=%x\n","qAddToEnd", qhead, qelem);
78: #endif
79: return 0;
80: }
81:
82:
83:
84: /* ----------------------------------------------------------------------
85: * qfind_m
86: * void* qfind_m(void *qhead, void NPTR match, ProcPtr compare_fnx)
87: *
88: * Hunt down a linked list of queue elements calling the compare
89: * function on each item. When the compare function returns true,
90: * return ptr to the queue element.
91: *
92: *
93: * INPUTS:
94: * qhead Address of ptr to first item in queue
95: * match
96: * compare_fnx
97: * OUTPUTS:
98: * D0 & A0 Ptr to queue element or NIL
99: * REGISTERS:
100: * D0,D1,A0,A1
101: * ----------------------------------------------------------------------
102: */
103: void* qfind_m(qhead, match, compare_fnx)
104: CCBPtr qhead;
105: void *match;
106: ProcPtr compare_fnx;
107: {
108: int s;
109: CCBPtr queue_item = qhead;
110:
111: ATDISABLE(s, adspgen_lock);
112: while (queue_item) {
113: if ((*compare_fnx)(queue_item,match))
114: break;
115:
116: queue_item = queue_item->ccbLink;
117: }
118: ATENABLE(s, adspgen_lock);
119:
120: return (queue_item);
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.