]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMinformeeList.cpp
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #include <IOKit/pwr_mgt/IOPM.h>
23 #include <IOKit/pwr_mgt/IOPMinformeeList.h>
24 #include <IOKit/pwr_mgt/IOPMinformee.h>
26 #define super OSObject
27 OSDefineMetaClassAndStructors(IOPMinformeeList
,OSObject
)
29 //*********************************************************************************
32 //*********************************************************************************
33 void IOPMinformeeList::initialize ( void )
39 //******************************************************************************
40 // getSharedRecursiveLock
42 //******************************************************************************
43 IORecursiveLock
*IOPMinformeeList::getSharedRecursiveLock( void )
45 static IORecursiveLock
*sharedListLock
= NULL
;
47 /* A running system could have 50-60+ instances of IOPMInformeeList.
48 * They'll share this lock, since list insertion and removal is relatively
49 * rare, and generally tied to major events like device discovery.
51 * getSharedRecursiveLock() is called from IOStartIOKit to initialize
52 * the sharedListLock before any IOPMinformeeLists are instantiated.
54 * The IOPMinformeeList class will be around for the lifetime of the system,
55 * we don't worry about freeing this lock.
58 if ( NULL
== sharedListLock
)
60 sharedListLock
= IORecursiveLockAlloc();
62 return sharedListLock
;
65 //*********************************************************************************
68 //*********************************************************************************
70 IOReturn
IOPMinformeeList::addToList ( IOPMinformee
* newInformee
)
72 IOPMinformee
* nextInformee
;
73 IORecursiveLock
*listLock
= getSharedRecursiveLock();
76 return kIOReturnError
;
78 IORecursiveLockLock(listLock
);
79 nextInformee
= firstItem
;
81 // Is new object already in the list?
82 while ( nextInformee
!= NULL
)
84 if ( nextInformee
->whatObject
== newInformee
->whatObject
)
86 // object is present; just exit
89 nextInformee
= nextInList(nextInformee
);
92 // add it to the front of the list
93 newInformee
->nextInList
= firstItem
;
94 firstItem
= newInformee
;
98 IORecursiveLockUnlock(listLock
);
103 //*********************************************************************************
106 // Find the item in the list, unlink it, and free it.
107 //*********************************************************************************
109 IOReturn
IOPMinformeeList::removeFromList ( IOService
* theItem
)
111 IOPMinformee
* item
= firstItem
;
113 IORecursiveLock
*listLock
= getSharedRecursiveLock();
118 return kIOReturnError
;
120 IORecursiveLockLock( listLock
);
122 if ( item
->whatObject
== theItem
)
124 firstItem
= item
->nextInList
;
127 goto unlock_and_exit
;
130 while ( item
->nextInList
!= NULL
)
132 if ( item
->nextInList
->whatObject
== theItem
)
134 temp
= item
->nextInList
;
135 item
->nextInList
= temp
->nextInList
;
138 goto unlock_and_exit
;
140 item
= item
->nextInList
;
144 IORecursiveLockUnlock(listLock
);
149 //*********************************************************************************
152 //*********************************************************************************
154 IOPMinformee
* IOPMinformeeList::firstInList ( void )
159 //*********************************************************************************
162 //*********************************************************************************
164 IOPMinformee
* IOPMinformeeList::nextInList ( IOPMinformee
* currentItem
)
166 if ( currentItem
!= NULL
) {
167 return (currentItem
->nextInList
);
172 //*********************************************************************************
175 //*********************************************************************************
177 unsigned long IOPMinformeeList::numberOfItems ( void )
182 //*********************************************************************************
185 // Look through the list for the one which points to the object identified
186 // by the parameter. Return a pointer to the list item or NULL.
187 //*********************************************************************************
189 IOPMinformee
* IOPMinformeeList::findItem ( IOService
* driverOrChild
)
191 IOPMinformee
* nextObject
;
193 nextObject
= firstInList();
194 while ( nextObject
!= NULL
) {
195 if ( nextObject
->whatObject
== driverOrChild
) {
198 nextObject
= nextInList(nextObject
);
205 //*********************************************************************************
208 // Free all items in the list, and then free the list itself
209 //*********************************************************************************
211 void IOPMinformeeList::free (void )
213 IOPMinformee
* next
= firstItem
;
215 while ( next
!= NULL
) {
216 firstItem
= next
->nextInList
;