Annotation of kernel/machdep/i386/pc_support/PCtimers.c, revision 1.1.1.1

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:  * Copyright (c) 1993 NeXT Computer, Inc.
                     27:  *
                     28:  * Timeout and tick support.
                     29:  *
                     30:  * HISTORY
                     31:  *
                     32:  * 30 Mar 1993 ? at NeXT
                     33:  *     Created.
                     34:  */
                     35: 
                     36: #import <mach/mach_types.h>
                     37: 
                     38: #import <kern/thread_call.h>
                     39: 
                     40: #import "PCprivate.h"
                     41: 
                     42: static
                     43: void PCpendTimeout(
                     44:        PCcontext_t             context);
                     45: 
                     46: static
                     47: void PCpendTick(
                     48:        PCcontext_t             context);
                     49: 
                     50: #define TVALSPEC_USEC(usec)            \
                     51:        ((tvalspec_t) { ((usec) / USEC_PER_SEC), ((usec) * NSEC_PER_USEC) } )
                     52: 
                     53: static __inline__
                     54: void
                     55: PCscheduleTimeout(
                     56:     PCcontext_t                context
                     57: )
                     58: {
                     59:     context->pendingTimers &= ~PC_CALL_TIMEOUT;
                     60: 
                     61:     if (context->expectedTimers & PC_CALL_TIMEOUT)
                     62:        thread_call_func_cancel(
                     63:                        (thread_call_func_t)PCpendTimeout, context, FALSE);
                     64:     
                     65:     if (context->runOptions & PC_RUN_TIMEOUT) {
                     66:        thread_call_func_delayed(
                     67:                (thread_call_func_t)PCpendTimeout, context,
                     68:                        deadline_from_interval(
                     69:                                TVALSPEC_USEC(context->timeout)));
                     70:     
                     71:        context->expectedTimers |= PC_CALL_TIMEOUT;
                     72:     }
                     73:     else
                     74:        context->expectedTimers &= ~PC_CALL_TIMEOUT;
                     75: }
                     76: 
                     77: static
                     78: void
                     79: PCpendTimeout(
                     80:     PCcontext_t                context
                     81: )
                     82: {
                     83:     if (context->expectedTimers & PC_CALL_TIMEOUT) {
                     84:        if (context->running)
                     85:            context->pendingTimers |= PC_CALL_TIMEOUT;
                     86:        
                     87:        context->expectedTimers &= ~PC_CALL_TIMEOUT;
                     88:     }
                     89: }
                     90: 
                     91: static __inline__
                     92: void
                     93: PCscheduleTick(
                     94:     PCcontext_t                context
                     95: )
                     96: {
                     97:     if (context->pendingTimers & PC_CALL_TICK) {
                     98:        context->pendingCallbacks |= PC_CALL_TICK;
                     99: 
                    100:        context->pendingTimers &= ~PC_CALL_TICK;
                    101:     }
                    102:     
                    103:     if (context->expectedTimers & PC_CALL_TICK)
                    104:        /* do nothing */;
                    105:     else if (context->runOptions & PC_RUN_TICK) {      
                    106:        thread_call_func_delayed(
                    107:                (thread_call_func_t)PCpendTick, context,
                    108:                        deadline_from_interval(
                    109:                                TVALSPEC_USEC(context->tick)));
                    110:        
                    111:        context->expectedTimers |= PC_CALL_TICK;
                    112:     }
                    113: }
                    114: 
                    115: static
                    116: void
                    117: PCpendTick(
                    118:     PCcontext_t                context
                    119: )
                    120: {
                    121:     if (context->expectedTimers & PC_CALL_TICK) {
                    122:        context->pendingTimers |= PC_CALL_TICK;
                    123:        
                    124:        context->expectedTimers &= ~PC_CALL_TICK;
                    125:     }
                    126: }
                    127:        
                    128: void
                    129: PCscheduleTimers(
                    130:     PCcontext_t                context
                    131: )
                    132: {
                    133:     PCscheduleTimeout(context);
                    134:        
                    135:     PCscheduleTick(context);
                    136: }
                    137: 
                    138: void
                    139: PCdeliverTimers(
                    140:     PCcontext_t                context
                    141: )
                    142: {
                    143:     context->pendingCallbacks |= 
                    144:        context->pendingTimers & (PC_CALL_TIMEOUT | PC_CALL_TICK);
                    145:        
                    146:     context->pendingTimers &= ~(PC_CALL_TIMEOUT | PC_CALL_TICK);
                    147: }
                    148: 
                    149: boolean_t
                    150: PCtimersPending(
                    151:     PCcontext_t                context
                    152: )
                    153: {
                    154:     boolean_t          pending;
                    155:     
                    156:     pending = (context->pendingTimers & (PC_CALL_TIMEOUT | PC_CALL_TICK)) != 0;
                    157:     
                    158:     return (pending);
                    159: }
                    160: 
                    161: void
                    162: PCcancelTimers(
                    163:     PCcontext_t                context
                    164: )
                    165: {
                    166:     thread_call_func_cancel(
                    167:                (thread_call_func_t)PCpendTimeout, context, FALSE);
                    168:     thread_call_func_cancel(
                    169:                (thread_call_func_t)PCpendTick, context, FALSE);
                    170: }
                    171: 
                    172: void
                    173: PCcancelAllTimers(
                    174:     thread_t           thread
                    175: )
                    176: {
                    177:     PCshared_t         shared = threadPCShared(thread);
                    178:     int                        i;
                    179:        
                    180:     for (i = 0; i < PCMAXCONTEXT; i++)
                    181:        PCcancelTimers(&shared->contexts[i]);
                    182: }

unix.superglobalmegacorp.com

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