|
|
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: ! 26: #include <adsp_local.h> ! 27: atlock_t adsptmr_lock; ! 28: ! 29: extern void DoTimerElem(); /* (TimerElemPtr t); ! 30: * External routine called to ! 31: * process each one. */ ! 32: ! 33: /* ! 34: * InsertTimerElem ! 35: * ! 36: * INPUTS: ! 37: * qhead Address of ptr to first item in list ! 38: * t timer element to link in ! 39: * vbl timer value to use ! 40: * OUTPUTS: ! 41: * void ! 42: */ ! 43: void InsertTimerElem(qhead, t, val) ! 44: /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */ ! 45: TimerElemPtr *qhead, t; ! 46: int val; ! 47: { ! 48: TimerElemPtr p; /* parent pointer */ ! 49: TimerElemPtr n; /* current */ ! 50: int s; ! 51: ! 52: ATDISABLE(s, adsptmr_lock); ! 53: ! 54: if (t->onQ) { ! 55: /* ! 56: * someone else beat us to the punch and put this ! 57: * element back on the queue, just return in this case ! 58: */ ! 59: ATENABLE(s, adsptmr_lock); ! 60: return; ! 61: } ! 62: p = (TimerElemPtr)qhead; ! 63: ! 64: while (n = p->link) { ! 65: if (val <= n->timer) /* Do we go in front of this? */ ! 66: { ! 67: n->timer -= val; /* Yes, adjust his delta */ ! 68: break; /* and go link us in */ ! 69: } ! 70: val -= n->timer; /* No, subtract off delta from our value */ ! 71: p = n; ! 72: } /* while */ ! 73: ! 74: /* It must go after item pointed to by p and in front of item ! 75: * pointed to by n */ ! 76: ! 77: t->onQ = 1; /* we're linked in now */ ! 78: p->link = t; /* parent points to us */ ! 79: t->timer = val; /* this is our value */ ! 80: t->link = n; /* we point to n */ ! 81: ! 82: ATENABLE(s, adsptmr_lock); ! 83: } ! 84: ! 85: ! 86: /* ! 87: * RemoveTimerElem ! 88: * ! 89: * INPUTS: ! 90: * qhead Address of ptr to first item in list ! 91: * t timer element to link in ! 92: * OUTPUTS: ! 93: * void ! 94: */ ! 95: void RemoveTimerElem(qhead, t) /* (TimerElemPtr *qhead, TimerElemPtr t) */ ! 96: TimerElemPtr *qhead, t; ! 97: { ! 98: TimerElemPtr p; /* parent pointer */ ! 99: TimerElemPtr n; /* current */ ! 100: int s; ! 101: ! 102: ATDISABLE(s, adsptmr_lock); ! 103: ! 104: if ( !t->onQ) { ! 105: /* ! 106: * someone else beat us to the punch and took this ! 107: * element off of the queue, just return in this case ! 108: */ ! 109: ATENABLE(s, adsptmr_lock); ! 110: return; ! 111: } ! 112: p = (TimerElemPtr)qhead; ! 113: ! 114: while (n = p->link) /* Get next item in queue */ ! 115: { ! 116: if (n == t) /* Is it us? */ ! 117: { ! 118: if (p->link = n->link) /* Link our parent to our child */ ! 119: { ! 120: n->link->timer += t->timer; /* and update child's timer */ ! 121: } ! 122: n->onQ = 0; /* Not on linked list anymore */ ! 123: break; ! 124: } ! 125: p = n; ! 126: } /* while */ ! 127: ! 128: ATENABLE(s, adsptmr_lock); ! 129: } ! 130: ! 131: ! 132: /* ! 133: * TimerQueueTick ! 134: * ! 135: * INPUTS: ! 136: * qhead Address of ptr to first item in list ! 137: * ! 138: * OUTPUTS: ! 139: * void ! 140: */ ! 141: void TimerQueueTick(qhead) /* (TimerElemPtr *qhead) */ ! 142: TimerElemPtr *qhead; ! 143: { ! 144: TimerElemPtr p; /* parent pointer */ ! 145: TimerElemPtr n; /* current */ ! 146: int s; ! 147: ! 148: ATDISABLE(s, adsptmr_lock); ! 149: ! 150: p = (TimerElemPtr)qhead; ! 151: if (p->link) /* Is anything on queue? */ ! 152: p->link->timer--; /* Yes, decrement by a tick */ ! 153: else ! 154: goto done; /* No, we're outta' here */ ! 155: ! 156: while ((n = p->link) && ! 157: (n->timer == 0)) /* Next guy needs to be serviced */ ! 158: { ! 159: p->link = n->link; /* Unlink us */ ! 160: n->onQ = 0; ! 161: ! 162: ATENABLE(s, adsptmr_lock); ! 163: DoTimerElem(n); ! 164: ATDISABLE(s, adsptmr_lock); ! 165: ! 166: p = (TimerElemPtr)qhead; ! 167: } /* while */ ! 168: ! 169: done: ! 170: ATENABLE(s, adsptmr_lock); ! 171: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.