]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerStateQueue.cpp
2 * Copyright (c) 2001-2002 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@
23 #include "IOPMPowerStateQueue.h"
24 #include "IOKit/IOLocks.h"
26 #define super IOEventSource
27 OSDefineMetaClassAndStructors(IOPMPowerStateQueue
, IOEventSource
);
29 #ifdef __i386__ /* ppc does this right and doesn't need these routines */
31 void * OSDequeueAtomic(void ** inList
, SInt32 inOffset
)
37 oldListHead
= *inList
;
38 if (oldListHead
== NULL
) {
42 newListHead
= *(void **) (((char *) oldListHead
) + inOffset
);
43 } while (! OSCompareAndSwap((UInt32
)oldListHead
,
44 (UInt32
)newListHead
, (UInt32
*)inList
));
49 void OSEnqueueAtomic(void ** inList
, void * inNewLink
, SInt32 inOffset
)
52 void * newListHead
= inNewLink
;
53 void ** newLinkNextPtr
= (void **) (((char *) inNewLink
) + inOffset
);
56 oldListHead
= *inList
;
57 *newLinkNextPtr
= oldListHead
;
58 } while (! OSCompareAndSwap((UInt32
)oldListHead
, (UInt32
)newListHead
,
64 IOPMPowerStateQueue
*IOPMPowerStateQueue::PMPowerStateQueue(OSObject
*inOwner
)
66 IOPMPowerStateQueue
*me
= new IOPMPowerStateQueue
;
68 if(me
&& !me
->init(inOwner
, 0) )
77 bool IOPMPowerStateQueue::init(OSObject
*owner
, Action action
)
79 if(!(super::init(owner
, (IOEventSource::Action
) action
))) return false;
81 // Queue of powerstate changes
84 if (!(tmpLock
= IOLockAlloc())) panic("IOPMPowerStateQueue::init can't alloc lock");
90 bool IOPMPowerStateQueue::unIdleOccurred(IOService
*inTarget
, unsigned long inState
)
92 PowerChangeEntry
*new_one
= NULL
;
94 new_one
= (PowerChangeEntry
*)IOMalloc(sizeof(PowerChangeEntry
));
95 if(!new_one
) return false;
97 new_one
->actionType
= IOPMPowerStateQueue::kUnIdle
;
98 new_one
->state
= inState
;
99 new_one
->target
= inTarget
;
105 OSEnqueueAtomic((void **)&changes
, (void *)new_one
, 0);
107 IOLockUnlock(tmpLock
);
109 signalWorkAvailable();
114 // checkForWork() is called in a gated context
115 bool IOPMPowerStateQueue::checkForWork()
117 PowerChangeEntry
*theNode
;
119 IOService
*theTarget
;
122 // Dequeue and process the state change request
126 if((theNode
= (PowerChangeEntry
*)OSDequeueAtomic((void **)&changes
, 0)))
129 IOLockUnlock(tmpLock
);
131 theState
= theNode
->state
;
132 theTarget
= theNode
->target
;
133 theAction
= theNode
->actionType
;
134 IOFree((void *)theNode
, sizeof(PowerChangeEntry
));
139 theTarget
->command_received((void *)theState
, 0, 0, 0);
145 IOLockUnlock(tmpLock
);
148 // Return true if there's more work to be done
149 if(changes
) return true;