Annotation of XNU/bsd/netat/adsp_TimerElem.c, revision 1.1

1.1     ! root        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: /* 
        !            23:  * TimerElem.c 
        !            24:  *
        !            25:  * From v01.00  04/15/90 mbs
        !            26:  *    Modified for MP, 1996 by Tuyen Nguyen
        !            27:  *   Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
        !            28: */
        !            29: 
        !            30: #include <sys/errno.h>
        !            31: #include <sys/types.h>
        !            32: #include <sys/param.h>
        !            33: #include <machine/spl.h>
        !            34: #include <sys/systm.h>
        !            35: #include <sys/kernel.h>
        !            36: #include <sys/proc.h>
        !            37: #include <sys/filedesc.h>
        !            38: #include <sys/fcntl.h>
        !            39: #include <sys/mbuf.h>
        !            40: #include <sys/socket.h>
        !            41: 
        !            42: #include <netat/sysglue.h>
        !            43: #include <netat/appletalk.h>
        !            44: #include <netat/at_pcb.h>
        !            45: #include <netat/debug.h>
        !            46: #include <netat/adsp.h>
        !            47: #include <netat/adsp_internal.h>
        !            48: 
        !            49: atlock_t adsptmr_lock;
        !            50: 
        !            51: extern void DoTimerElem();     /* (TimerElemPtr t);  
        !            52:                                 * External routine called to 
        !            53:                                 * process each one. */
        !            54: 
        !            55: /*
        !            56:  * InsertTimerElem
        !            57:  * 
        !            58:  * INPUTS:
        !            59:  *     qhead           Address of ptr to first item in list
        !            60:  *     t               timer element to link in
        !            61:  *     vbl             timer value to use
        !            62:  * OUTPUTS:
        !            63:  *     void
        !            64:  */
        !            65: void InsertTimerElem(qhead, t, val)
        !            66:     /* (TimerElemPtr *qhead, TimerElemPtr t, word val) */
        !            67:     TimerElemPtr *qhead, t;
        !            68:     int val;
        !            69: {
        !            70:     TimerElemPtr p;            /* parent pointer */
        !            71:     TimerElemPtr n;            /* current */
        !            72:     int        s;
        !            73:        
        !            74:     ATDISABLE(s, adsptmr_lock);
        !            75:        
        !            76:     if (t->onQ) {
        !            77:         /*
        !            78:         * someone else beat us to the punch and put this
        !            79:         * element back on the queue, just return in this case
        !            80:         */
        !            81:         ATENABLE(s, adsptmr_lock);
        !            82:        return;
        !            83:     }
        !            84:     p = (TimerElemPtr)qhead;
        !            85: 
        !            86:     while (n = p->link) {
        !            87:        if (val <= n->timer)    /* Do we go in front of this? */
        !            88:        {
        !            89:            n->timer -= val;    /* Yes, adjust his delta */
        !            90:            break;              /* and go link us in */
        !            91:        }
        !            92:        val -= n->timer;        /* No, subtract off delta from our value */
        !            93:        p = n;
        !            94:     }                          /* while */
        !            95:        
        !            96:     /* It must go after item pointed to by p and in front of item 
        !            97:      * pointed to by n */
        !            98: 
        !            99:     t->onQ = 1;        /* we're linked in now */
        !           100:     p->link = t;               /* parent points to us */
        !           101:     t->timer = val;            /* this is our value */
        !           102:     t->link = n;               /* we point to n */
        !           103:     
        !           104:     ATENABLE(s, adsptmr_lock);
        !           105: }
        !           106: 
        !           107: 
        !           108: /*
        !           109:  * RemoveTimerElem
        !           110:  * 
        !           111:  * INPUTS:
        !           112:  *     qhead           Address of ptr to first item in list
        !           113:  *     t               timer element to link in
        !           114:  * OUTPUTS:
        !           115:  *     void
        !           116:  */
        !           117: void RemoveTimerElem(qhead, t) /* (TimerElemPtr *qhead, TimerElemPtr t) */
        !           118:     TimerElemPtr *qhead, t;
        !           119: {
        !           120:     TimerElemPtr p;            /* parent pointer */
        !           121:     TimerElemPtr n;            /* current */
        !           122:     int        s;
        !           123:        
        !           124:     ATDISABLE(s, adsptmr_lock);
        !           125:        
        !           126:     if ( !t->onQ) {
        !           127:         /*
        !           128:         * someone else beat us to the punch and took this
        !           129:         * element off of the queue, just return in this case
        !           130:         */
        !           131:         ATENABLE(s, adsptmr_lock);
        !           132:        return;
        !           133:     }
        !           134:     p = (TimerElemPtr)qhead;
        !           135: 
        !           136:     while (n = p->link)        /* Get next item in queue */
        !           137:     {
        !           138:        if (n == t)             /* Is it us? */
        !           139:        {
        !           140:            if (p->link = n->link) /* Link our parent to our child */
        !           141:            {
        !           142:                n->link->timer += t->timer; /* and update child's timer */
        !           143:            }
        !           144:            n->onQ = 0;         /* Not on linked list anymore */
        !           145:            break;
        !           146:        }
        !           147:        p = n;
        !           148:     }                          /* while */
        !           149:        
        !           150:     ATENABLE(s, adsptmr_lock);
        !           151: }
        !           152: 
        !           153: 
        !           154: /*
        !           155:  * TimerQueueTick
        !           156:  * 
        !           157:  * INPUTS:
        !           158:  *     qhead           Address of ptr to first item in list
        !           159:  *     
        !           160:  * OUTPUTS:
        !           161:  *     void
        !           162:  */
        !           163: void TimerQueueTick(qhead)     /* (TimerElemPtr *qhead) */
        !           164:     TimerElemPtr *qhead;
        !           165: {
        !           166:     TimerElemPtr p;            /* parent pointer */
        !           167:     TimerElemPtr n;            /* current */
        !           168:     int        s;
        !           169:        
        !           170:     ATDISABLE(s, adsptmr_lock);
        !           171:        
        !           172:     p = (TimerElemPtr)qhead;
        !           173:     if (p->link)               /* Is anything on queue? */
        !           174:        p->link->timer--;       /* Yes, decrement by a tick */
        !           175:     else
        !           176:        goto done;              /* No, we're outta' here */
        !           177:                
        !           178:     while ((n = p->link) && 
        !           179:           (n->timer == 0)) /* Next guy needs to be serviced */
        !           180:     {
        !           181:        p->link = n->link;      /* Unlink us */
        !           182:        n->onQ  = 0;
        !           183: 
        !           184:        ATENABLE(s, adsptmr_lock);
        !           185:        DoTimerElem(n);
        !           186:        ATDISABLE(s, adsptmr_lock);
        !           187: 
        !           188:        p = (TimerElemPtr)qhead;
        !           189:     }                          /* while */
        !           190:        
        !           191: done:
        !           192:     ATENABLE(s, adsptmr_lock);
        !           193: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.