]>
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_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@
28 #include <IOKit/pwr_mgt/IOPM.h>
29 #include <IOKit/pwr_mgt/IOPMinformeeList.h>
30 #include <IOKit/pwr_mgt/IOPMinformee.h>
32 #define super OSObject
33 OSDefineMetaClassAndStructors(IOPMinformeeList
, OSObject
)
35 //*********************************************************************************
38 //*********************************************************************************
40 IOPMinformeeList::initialize( void )
46 //******************************************************************************
47 // getSharedRecursiveLock
49 //******************************************************************************
51 IOPMinformeeList::getSharedRecursiveLock( void )
53 static IORecursiveLock
*sharedListLock
= NULL
;
55 /* A running system could have 50-60+ instances of IOPMInformeeList.
56 * They'll share this lock, since list insertion and removal is relatively
57 * rare, and generally tied to major events like device discovery.
59 * getSharedRecursiveLock() is called from IOStartIOKit to initialize
60 * the sharedListLock before any IOPMinformeeLists are instantiated.
62 * The IOPMinformeeList class will be around for the lifetime of the system,
63 * we don't worry about freeing this lock.
66 if (NULL
== sharedListLock
) {
67 sharedListLock
= IORecursiveLockAlloc();
69 return sharedListLock
;
72 //*********************************************************************************
75 //*********************************************************************************
77 IOPMinformeeList::appendNewInformee( IOService
* newObject
)
79 IOPMinformee
* newInformee
;
85 newInformee
= IOPMinformee::withObject(newObject
);
91 if (IOPMNoErr
== addToList(newInformee
)) {
99 //*********************************************************************************
101 // *OBSOLETE* do not call from outside of this file.
102 // Try appendNewInformee() instead
103 //*********************************************************************************
105 IOPMinformeeList::addToList( IOPMinformee
* newInformee
)
107 IOPMinformee
* nextInformee
;
108 IORecursiveLock
*listLock
= getSharedRecursiveLock();
111 return kIOReturnError
;
114 IORecursiveLockLock(listLock
);
115 nextInformee
= firstItem
;
117 // Is new object already in the list?
118 while (nextInformee
!= NULL
) {
119 if (nextInformee
->whatObject
== newInformee
->whatObject
) {
120 // object is present; just exit
121 goto unlock_and_exit
;
123 nextInformee
= nextInList(nextInformee
);
126 // add it to the front of the list
127 newInformee
->nextInList
= firstItem
;
128 firstItem
= newInformee
;
132 IORecursiveLockUnlock(listLock
);
137 //*********************************************************************************
140 // Find the item in the list, unlink it, and free it.
141 //*********************************************************************************
144 IOPMinformeeList::removeFromList( IOService
* theItem
)
146 IOPMinformee
* item
= firstItem
;
148 IORecursiveLock
*listLock
= getSharedRecursiveLock();
154 return kIOReturnError
;
157 IORecursiveLockLock( listLock
);
159 if (item
->whatObject
== theItem
) {
160 firstItem
= item
->nextInList
;
163 goto unlock_and_exit
;
166 while (item
->nextInList
!= NULL
) {
167 if (item
->nextInList
->whatObject
== theItem
) {
168 temp
= item
->nextInList
;
169 item
->nextInList
= temp
->nextInList
;
172 goto unlock_and_exit
;
174 item
= item
->nextInList
;
178 IORecursiveLockUnlock(listLock
);
183 //*********************************************************************************
186 //*********************************************************************************
189 IOPMinformeeList::firstInList( void )
194 //*********************************************************************************
197 //*********************************************************************************
200 IOPMinformeeList::nextInList( IOPMinformee
* currentItem
)
202 if (currentItem
!= NULL
) {
203 return currentItem
->nextInList
;
208 //*********************************************************************************
211 //*********************************************************************************
214 IOPMinformeeList::numberOfItems( void )
219 //*********************************************************************************
222 // Look through the list for the one which points to the object identified
223 // by the parameter. Return a pointer to the list item or NULL.
224 //*********************************************************************************
227 IOPMinformeeList::findItem( IOService
* driverOrChild
)
229 IOPMinformee
* nextObject
;
231 nextObject
= firstInList();
232 while (nextObject
!= NULL
) {
233 if (nextObject
->whatObject
== driverOrChild
) {
236 nextObject
= nextInList(nextObject
);
243 //*********************************************************************************
246 // Free all items in the list, and then free the list itself
247 //*********************************************************************************
250 IOPMinformeeList::free(void )
252 IOPMinformee
* next
= firstItem
;
254 while (next
!= NULL
) {
255 firstItem
= next
->nextInList
;