]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_TimerElem.c
   2  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. The rights granted to you under the License 
  10  * may not be used to create, or enable the creation or redistribution of, 
  11  * unlawful or unlicensed copies of an Apple operating system, or to 
  12  * circumvent, violate, or enable the circumvention or violation of, any 
  13  * terms of an Apple operating system software license agreement. 
  15  * Please obtain a copy of the License at 
  16  * http://www.opensource.apple.com/apsl/ and read it before using this file. 
  18  * The Original Code and all software distributed under the License are 
  19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  23  * Please see the License for the specific language governing rights and 
  24  * limitations under the License. 
  26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 
  31  * From v01.00  04/15/90 mbs 
  32  *    Modified for MP, 1996 by Tuyen Nguyen 
  33  *   Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. 
  36 #include <sys/errno.h> 
  37 #include <sys/types.h> 
  38 #include <sys/param.h> 
  39 #include <machine/spl.h> 
  40 #include <sys/systm.h> 
  41 #include <sys/kernel.h> 
  43 #include <sys/filedesc.h> 
  44 #include <sys/fcntl.h> 
  46 #include <sys/socket.h> 
  48 #include <netat/sysglue.h> 
  49 #include <netat/appletalk.h> 
  50 #include <netat/at_pcb.h> 
  51 #include <netat/debug.h> 
  52 #include <netat/adsp.h> 
  53 #include <netat/adsp_internal.h> 
  56 extern  void DoTimerElem(TimerElemPtr
); /* (TimerElemPtr t);   
  57                                  * External routine called to  
  58                                  * process each one. */ 
  64  *      qhead           Address of ptr to first item in list 
  65  *      t               timer element to link in 
  66  *      vbl             timer value to use 
  70 void InsertTimerElem(qhead
, t
, val
) 
  71     /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */ 
  72     TimerElemPtr 
*qhead
, t
; 
  75     TimerElemPtr p
;             /* parent pointer */ 
  76     TimerElemPtr n
;             /* current */ 
  80                 * someone else beat us to the punch and put this 
  81                 * element back on the queue, just return in this case 
  85     p 
= (TimerElemPtr
)qhead
; 
  87     while ((n 
= p
->link
)) { 
  88         if (val 
<= n
->timer
)    /* Do we go in front of this? */ 
  90             n
->timer 
-= val
;    /* Yes, adjust his delta */ 
  91             break;              /* and go link us in */ 
  93         val 
-= n
->timer
;        /* No, subtract off delta from our value */ 
  97     /* It must go after item pointed to by p and in front of item  
 100     t
->onQ 
= 1; /* we're linked in now */ 
 101     p
->link 
= t
;                /* parent points to us */ 
 102     t
->timer 
= val
;             /* this is our value */ 
 103     t
->link 
= n
;                /* we point to n */ 
 112  *      qhead           Address of ptr to first item in list 
 113  *      t               timer element to link in 
 117 void RemoveTimerElem(qhead
, t
)  /* (TimerElemPtr *qhead, TimerElemPtr t) */ 
 118     TimerElemPtr 
*qhead
, t
; 
 120     TimerElemPtr p
;             /* parent pointer */ 
 121     TimerElemPtr n
;             /* current */ 
 125                 * someone else beat us to the punch and took this 
 126                 * element off of the queue, just return in this case 
 130     p 
= (TimerElemPtr
)qhead
; 
 132     while ((n 
= p
->link
))       /* Get next item in queue */ 
 134         if (n 
== t
)             /* Is it us? */ 
 136             if ((p
->link 
= n
->link
)) /* Link our parent to our child */ 
 138                 n
->link
->timer 
+= t
->timer
; /* and update child's timer */ 
 140             n
->onQ 
= 0;         /* Not on linked list anymore */ 
 153  *      qhead           Address of ptr to first item in list 
 158 void TimerQueueTick(qhead
)      /* (TimerElemPtr *qhead) */ 
 161     TimerElemPtr p
;             /* parent pointer */ 
 162     TimerElemPtr n
;             /* current */ 
 164     p 
= (TimerElemPtr
)qhead
; 
 165     if (p
->link
) {              /* Is anything on queue? */ 
 166         p
->link
->timer
--;       /* Yes, decrement by a tick */ 
 167         while ((n 
= p
->link
) &&  
 168                (n
->timer 
== 0)) /* Next guy needs to be serviced */ 
 170                 p
->link 
= n
->link
;      /* Unlink us */ 
 175                 p 
= (TimerElemPtr
)qhead
;