Annotation of XNU/iokit/Kernel/IOPMchangeNoteList.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1998-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: #include <IOKit/pwr_mgt/IOPM.h>
        !            23: #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
        !            24: 
        !            25: #define super OSObject
        !            26: OSDefineMetaClassAndStructors(IOPMchangeNoteList,OSObject)
        !            27: 
        !            28: //*********************************************************************************
        !            29: // init
        !            30: //
        !            31: //*********************************************************************************
        !            32: void IOPMchangeNoteList::initialize ( void )
        !            33: {
        !            34:     long i;
        !            35: 
        !            36:     firstInList = 0;
        !            37:     firstUnused = 0;
        !            38:     for ( i = 0; i < IOPMMaxChangeNotes; i++ ) {
        !            39:         changeNote[i].flags = IOPMNotInUse;
        !            40:     }
        !            41: }
        !            42: 
        !            43: //*********************************************************************************
        !            44: // createChangeNote
        !            45: //
        !            46: //*********************************************************************************
        !            47: 
        !            48: long IOPMchangeNoteList::createChangeNote ( void )
        !            49: {
        !            50:     unsigned long i, j;
        !            51: 
        !            52:     i = increment(firstUnused);
        !            53:     if ( firstInList == i ) {
        !            54:         return -1;
        !            55:     }
        !            56:     j = firstUnused;
        !            57:     firstUnused = i;
        !            58: 
        !            59:     return j;
        !            60: }
        !            61: 
        !            62: //*********************************************************************************
        !            63: // currentChange
        !            64: //
        !            65: // Return the ordinal of the first change note in the list.
        !            66: // If the list is empty, return -1.
        !            67: //*********************************************************************************
        !            68: 
        !            69: long IOPMchangeNoteList::currentChange ( void )
        !            70: {
        !            71:     if ( firstUnused == firstInList ) {
        !            72:         return -1;
        !            73:     }
        !            74:     else {
        !            75:         return firstInList;
        !            76:     }
        !            77: }
        !            78: 
        !            79: //*********************************************************************************
        !            80: // latestChange
        !            81: //
        !            82: // Return the ordinal of the last change note in the list.
        !            83: // If the list is empty, return -1.
        !            84: //*********************************************************************************
        !            85: 
        !            86: long IOPMchangeNoteList::latestChange ( void )
        !            87: {
        !            88:     if ( firstUnused == firstInList ) {
        !            89:         return -1;
        !            90:     }
        !            91:     else {
        !            92:         return decrement(firstUnused);
        !            93:     }
        !            94: }
        !            95: 
        !            96: //*********************************************************************************
        !            97: // releaseHeadChangeNote
        !            98: //
        !            99: // Mark the head node unused.
        !           100: // This happens when the first change in the list is completely processed.
        !           101: // That is, all interested parties have acknowledged it, and power is settled
        !           102: // at the new level.
        !           103: //*********************************************************************************
        !           104: 
        !           105: IOReturn IOPMchangeNoteList::releaseHeadChangeNote ( void )
        !           106: {
        !           107:     changeNote[firstInList].flags = IOPMNotInUse;
        !           108:     firstInList = increment(firstInList);
        !           109:     return IOPMNoErr;
        !           110: }
        !           111: 
        !           112: //*********************************************************************************
        !           113: // releaseTailChangeNote
        !           114: //
        !           115: // Mark the tail node unused.
        !           116: // This happens when a power change is queued up after another which has
        !           117: // not yet been started, and the second one supercedes the first.  The data in
        !           118: // the second is copied into the first and the the second is released.  This
        !           119: // collapses the first change out of the list.
        !           120: //*********************************************************************************
        !           121: 
        !           122: IOReturn IOPMchangeNoteList::releaseTailChangeNote ( void )
        !           123: {
        !           124:     firstUnused = decrement(firstUnused);
        !           125:     changeNote[firstUnused].flags = IOPMNotInUse;
        !           126:     return IOPMNoErr;
        !           127: }
        !           128: 
        !           129: //*********************************************************************************
        !           130: // changeNoteInUse
        !           131: //
        !           132: //*********************************************************************************
        !           133: 
        !           134: bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal )
        !           135: {
        !           136:     if ( changeNote[ordinal].flags == IOPMNotInUse ) {
        !           137:         return false;
        !           138:     }
        !           139:     else {
        !           140:         return true;
        !           141:     }
        !           142: }
        !           143: 
        !           144: //*********************************************************************************
        !           145: // nextChangeNote
        !           146: //
        !           147: // If the parameter corresponds to the most recent power change notification
        !           148: // passed to drivers and children, return -1.  Otherwise, return the array
        !           149: // position of the next notification in the circular list.
        !           150: //*********************************************************************************
        !           151: 
        !           152: long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal )
        !           153: {
        !           154:     unsigned long i;
        !           155: 
        !           156:     i = increment(ordinal);
        !           157:     if ( i == firstUnused)  {
        !           158:         return -1;
        !           159:     }
        !           160:     return ( i );
        !           161: }
        !           162: 
        !           163: //*********************************************************************************
        !           164: // increment
        !           165: //
        !           166: // Increment the parameter mod the circular list size and return it.
        !           167: //*********************************************************************************
        !           168: 
        !           169: unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal )
        !           170: {
        !           171:     if ( ordinal == (IOPMMaxChangeNotes - 1) ) {
        !           172:         return 0;
        !           173:     }
        !           174:     else {
        !           175:         return ordinal + 1;
        !           176:     }
        !           177: }
        !           178: 
        !           179: //*********************************************************************************
        !           180: // decrement
        !           181: //
        !           182: // Decrement the parameter mod the circular list size and return it.
        !           183: //*********************************************************************************
        !           184: 
        !           185: unsigned long IOPMchangeNoteList::decrement ( unsigned long  ordinal )
        !           186: {
        !           187:     if ( ordinal == 0 ) {
        !           188:         return IOPMMaxChangeNotes - 1;
        !           189:     }
        !           190:     else {
        !           191:         return ordinal - 1;
        !           192:     }
        !           193: }
        !           194: 
        !           195: //*********************************************************************************
        !           196: // previousChangeNote
        !           197: //
        !           198: // If the parameter corresponds to the oldest power change notification
        !           199: // passed to drivers and children, return -1.  Otherwise, return the array
        !           200: // position of the previous notification in the circular list.
        !           201: //*********************************************************************************
        !           202: 
        !           203: long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal )
        !           204: {
        !           205:     if ( ordinal == firstInList )  {
        !           206:         return -1;
        !           207:     }
        !           208:     return decrement(ordinal);
        !           209: }
        !           210: 
        !           211: //*********************************************************************************
        !           212: // listEmpty
        !           213: //
        !           214: //*********************************************************************************
        !           215: 
        !           216: bool IOPMchangeNoteList::listEmpty ( void )
        !           217: {
        !           218:     return ( firstInList == firstUnused ) ;
        !           219: }

unix.superglobalmegacorp.com

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