]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMinformeeList.cpp
57ac0bb7f46b0aeef69352c955bed94e7965a247
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 //*********************************************************************************
39 void IOPMinformeeList::initialize ( void )
45 //******************************************************************************
46 // getSharedRecursiveLock
48 //******************************************************************************
49 IORecursiveLock
*IOPMinformeeList::getSharedRecursiveLock( void )
51 static IORecursiveLock
*sharedListLock
= NULL
;
53 /* A running system could have 50-60+ instances of IOPMInformeeList.
54 * They'll share this lock, since list insertion and removal is relatively
55 * rare, and generally tied to major events like device discovery.
57 * getSharedRecursiveLock() is called from IOStartIOKit to initialize
58 * the sharedListLock before any IOPMinformeeLists are instantiated.
60 * The IOPMinformeeList class will be around for the lifetime of the system,
61 * we don't worry about freeing this lock.
64 if ( NULL
== sharedListLock
)
66 sharedListLock
= IORecursiveLockAlloc();
68 return sharedListLock
;
71 //*********************************************************************************
74 //*********************************************************************************
76 IOReturn
IOPMinformeeList::addToList ( IOPMinformee
* newInformee
)
78 IOPMinformee
* nextInformee
;
79 IORecursiveLock
*listLock
= getSharedRecursiveLock();
82 return kIOReturnError
;
84 IORecursiveLockLock(listLock
);
85 nextInformee
= firstItem
;
87 // Is new object already in the list?
88 while ( nextInformee
!= NULL
)
90 if ( nextInformee
->whatObject
== newInformee
->whatObject
)
92 // object is present; just exit
95 nextInformee
= nextInList(nextInformee
);
98 // add it to the front of the list
99 newInformee
->nextInList
= firstItem
;
100 firstItem
= newInformee
;
104 IORecursiveLockUnlock(listLock
);
109 //*********************************************************************************
112 // Find the item in the list, unlink it, and free it.
113 //*********************************************************************************
115 IOReturn
IOPMinformeeList::removeFromList ( IOService
* theItem
)
117 IOPMinformee
* item
= firstItem
;
119 IORecursiveLock
*listLock
= getSharedRecursiveLock();
124 return kIOReturnError
;
126 IORecursiveLockLock( listLock
);
128 if ( item
->whatObject
== theItem
)
130 firstItem
= item
->nextInList
;
133 goto unlock_and_exit
;
136 while ( item
->nextInList
!= NULL
)
138 if ( item
->nextInList
->whatObject
== theItem
)
140 temp
= item
->nextInList
;
141 item
->nextInList
= temp
->nextInList
;
144 goto unlock_and_exit
;
146 item
= item
->nextInList
;
150 IORecursiveLockUnlock(listLock
);
155 //*********************************************************************************
158 //*********************************************************************************
160 IOPMinformee
* IOPMinformeeList::firstInList ( void )
165 //*********************************************************************************
168 //*********************************************************************************
170 IOPMinformee
* IOPMinformeeList::nextInList ( IOPMinformee
* currentItem
)
172 if ( currentItem
!= NULL
) {
173 return (currentItem
->nextInList
);
178 //*********************************************************************************
181 //*********************************************************************************
183 unsigned long IOPMinformeeList::numberOfItems ( void )
188 //*********************************************************************************
191 // Look through the list for the one which points to the object identified
192 // by the parameter. Return a pointer to the list item or NULL.
193 //*********************************************************************************
195 IOPMinformee
* IOPMinformeeList::findItem ( IOService
* driverOrChild
)
197 IOPMinformee
* nextObject
;
199 nextObject
= firstInList();
200 while ( nextObject
!= NULL
) {
201 if ( nextObject
->whatObject
== driverOrChild
) {
204 nextObject
= nextInList(nextObject
);
211 //*********************************************************************************
214 // Free all items in the list, and then free the list itself
215 //*********************************************************************************
217 void IOPMinformeeList::free (void )
219 IOPMinformee
* next
= firstItem
;
221 while ( next
!= NULL
) {
222 firstItem
= next
->nextInList
;